-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent handling for optional input parameters without a default value #24455
Comments
@GiudGiud @lindsayad @friedmud @dschwen @permcody @loganharbour I added a runtime error for empty vector check in my PR #25245 but it breaks tons of test cases because of the new error messages. Any suggestions on how to fix those failed tests? I can simply add a default value. Or treat them differently based on objects? @loganharbour suggests to start a discussion on this issue. |
For context - if you add a parameter for anything but a |
I think adding a default is fine where it makes sense, and for others you ll want to fix the broken logic This "retrieved before being set" is the right behavior |
I would agree with you, but clearly someone else didn't:
And that's the important conversation here |
@permcody did you do this and why |
I can't recall of a specific reason for this other than making an assumption that an empty vector was harmless... I'm supportive of making the behavior consistent. |
We are relying on this behavior heavily (as the failing tests show). I'm fine with changing it, as long as fixes for all apps are part of the "service package" ;-) Adding an empty default used to be a bit cumbersome, but nowadays one can probably simply add |
…that do not have a source variable) in conservative transfers, refs idaholab#24455
…that do not have a source variable) in conservative transfers, refs idaholab#24455
Reason
In MOOSE, an optional input parameter could be provided without default values, e.g.,
params.addParam<Real>("dummy_real", "a dummy real number");
When handling such an input parameter, it is typical to check if it is valid before accessing it, e.g., the following to avoid runtime error:
_dummy_real(isParamValid("dummy_real")
<- Wrong, runtime error: The parameter "dummy_real" is being retrieved before being set.The correct example is:
_dummy_real(isParamValid("dummy_real") ? getParam<Real>("dummy_real") : 0.0)
However, if the input parameter is a std::vector, e.g.,
MOOSE won't send out a runtime error, but of course,
_dummy_vec
is an empty vector. This is inconsistent with the first case. This probably should not be categorized as a bug, would still be nice to make things consistent.Design
For the second case described above for std::vector input parameter, if no default value provided, should be handled the same way as other cases such as a real number.
Impact
Inconsistent code design; causing confusion in module/application development.
The text was updated successfully, but these errors were encountered: