First: A HUGE thanks to Cody for doing a lot of the C++ voodoo to make all of this work!
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:
[Kernels] [./my_kernel] type = SomeKernel my_param = 6.4 [../] 
However, "coupling" type parameters (for coupled variables,
Functions) have never had this kind of capability which led to "ternary operator hell" like so:
SomeKernel::SomeKernel(...) : _coupled_var(isCoupled("coupled_var")?coupledValue("coupled_var"):_zero), _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...
As of today we now support:
So you can now do this in
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:
SomeKernel::SomeKernel(...) : _coupled_var(coupledValue("coupled_var")), _coupled_pp(getPostprocessorValue("pp")), _coupled_function(getFunction("function"))
Huge improvement! Also: check out the default for a
Function: it's actually the
Also, overriding any of these in the input file works as well:
[Kernels] [./my_kernel] type = SomeKernel coupled_var = 350 pp = 42 function = '72*y+cos(z)' [../] 
YES you can actually pass
ParsedFunction syntax to any parameter expecting a
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!Share on Twitter Share on Facebook