(1 comment)

First: A HUGE thanks to Cody for doing a lot of the C++ voodoo to make all of this work!

In the Past....

MOOSE has had support for default values for parameters for ages like so:

params.addParam<Real>("my_param", 4.0, "Some docu");

With the ability to override that default value in the input file like so:

    type = SomeKernel
    my_param = 6.4

However, "coupling" type parameters (for coupled variables, Postprocessors and Functions) have never had this kind of capability which led to "ternary operator hell" like so:

SomeKernel::SomeKernel(...) :
    _coupled_pp(isParamValid("pp") ? getPostprocessorValue("pp") : 0),
    _coupled_function(isParamValid("function") ? &getFunction("function"):NULL)

Plus all sorts of isParamValid() type action in the constructor and elsewhere to deal with the case where something wasn't provided. This is icky on multiple levels (I personally really hate the fact that you have to deal with the Function as a pointer so you can set it to NULL... and then you have to check for NULL all over the place) and so we wanted to do something better...

What have we done about it?

As of today we now support:

  1. Default values for coupled values, Postprocessors and Functions
  2. Input file overrides for all three of these.

So you can now do this in validParams():

params.addCoupledVar("coupled_var", 300, "Some variable");
params.addParam<PostprocessorName>("some_pp", 27.2, "Some Postprocessor");
params.addParam<FunctionName>("function", "45*x+sin(y)", "Some Function");

Enabling your constructor to look like this:

  : _coupled_var(coupledValue("coupled_var")),

Huge improvement! Also: check out the default for a Function: it's actually the ParsedFunction syntax!

Also, overriding any of these in the input file works as well:

    type = SomeKernel
    coupled_var = 350
    pp = 42
    function = '72*y+cos(z)'

YES you can actually pass ParsedFunction syntax to any parameter expecting a FunctionName!!

Now: stop and think about what this means for coupled variables... this means that you can easily decouple equations. In the past if you wanted to decouple equations you needed to create an AuxVariable with a value in it and then couple to that. Now you don't even have to do that! You can simply pass a constant value in to use as the coupled value! This will really help during times of debugging (and for creating tests).

We are really excited to unveil this capability... it is going to help out in SO many places. I'm going to be going through and trying to eradicate many of the ternary operators through all of the MOOSE-based code I have access to... if you have time you should to!

As always, let us know on the mailing list if something doesn't make sense!

Current rating: 5


Questions 2 years, 12 months ago

Seems we always need to get a pointer for
```_coupled_pp(isParamValid("pp") ? &getPostprocessorValue("pp") : NULL),```?

Link | Reply
Currently unrated

New Comment


required (not published)


R&D 100

Recent Blog Posts

Using our new clang-format Style

1 month, 2 weeks ago

Steady State Algorithm Change

10 months, 3 weeks ago

Making an App inherit from an App

11 months ago

Changing a published API (Deprecation)

11 months, 1 week ago

DiscreteMaterial Objects

1 year, 1 month ago

Recent Posts






RSS / Atom