idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.62k stars 1.01k forks source link

Have input parameters required to be added before set #27597

Open joshuahansel opened 3 weeks ago

joshuahansel commented 3 weeks ago

Motivation

When you set input parameters from code instead of from the input file, you can set parameters that don't actually exist or do anything. For example,

InputParameters
MyApp::validParams()
{
  InputParameters params = MooseApp::validParams();
  params.set<bool>("bogus") = false;
  return params;
}

would not give any indication that the parameter bogus doesn't exist. This is dangerous because users can set parameters expecting them to do something, while they actually don't.

Design

This would require a parameter to be "declared" via add*Param before it is set. Perhaps this could be achieved with a new Metadata member _added, which defaults to false. The add*Param methods would set this to true, and set would throw an error if false.

Some parameters are "private", i.e., not to be seen/set in an input file, but there is a method addPrivateParam that should be called for these.

Impact

More strict input parameter behavior. We could discover some parameters that were set but never added.

GiudGiud commented 2 weeks ago

linked but not equal to #27556