InputParameters

To simplify and unify the creation of all simulation objects in MOOSE, all input parameters must be declared and populated through a single "InputParameters" object. This ensures that every constructor in MOOSE is uniform and ensures that every object can be created through MOOSE's Factory pattern. The InputParameters object is a collection of parameters, each one with separate attributes that can be used to finely control the behavior of the underlying object. For example, parameters can be marked as required or optional, be provided with a default or not, and be used to enhance GUI interfaces that may be used to programmatically generate input files for MOOSE.

The complete list of attributes for each input parameter:

  struct Metadata
  {
    std::string _doc_string;
    /// The custom type that will be printed in the YAML dump for a parameter if supplied
    std::string _custom_type;
    /// The data pertaining to a command line parameter (empty if not a command line param)
    std::optional<CommandLineMetadata> _cl_data;
    /// The names of the parameters organized into groups
    std::string _group;
    /// The map of functions used for range checked parameters
    std::string _range_function;
    /// directions for auto build vectors (base_, 5) -> "base_0 base_1 base_2 base_3 base_4")
    std::pair<std::string, std::string> _autobuild_vecs;
    /// True for parameters that are required (i.e. will cause an abort if not supplied)
    bool _required = false;
    /**
     * Whether the parameter is either explicitly set or provided a default value when added
     * Note: We do not store MooseEnum names in valid params, instead we ask MooseEnums whether
     *       they are valid or not.
     */
    bool _valid = false;
    /// The set of parameters that will NOT appear in the the dump of the parser tree
    bool _is_private = false;
    bool _have_coupled_default = false;
    /// The default value for optionally coupled variables
    std::vector<Real> _coupled_default = {0};
    /// True if a parameters value was set by addParam, and not set again.
    bool _set_by_add_param = false;
    /// The reserved option names for a parameter
    std::set<std::string> _reserved_values;
    /// If non-empty, this parameter is deprecated.
    std::string _deprecation_message;
    /// Original location of parameter node; used for error messages
    const hit::Node * _hit_node;
    /// True if the parameters is controllable
    bool _controllable = false;
    /// Controllable execute flag restriction
    std::set<ExecFlagType> _controllable_flags;
    /// whether user setting of this parameter should be ignored
    bool _ignore = false;
  };
(framework/include/utils/InputParameters.h)

Applying or Transferring Common Parameters

When building a custom Action, it is often useful to read in several parameters that will be used to directly set parameters on objects being built by the custom Action. The InputParameters object contains a few useful methods for applying or transferring common parameters to avoid several manual lines for setting these parameters. See the utility methods and corresponding documentation here:

  // BEGIN APPLY PARAMETER METHODS
  /**
   * Method for applying common parameters
   * @param common The set of parameters to apply to the parameters stored in this object
   * @param exclude A vector of parameters to exclude
   *
   * In order to apply common parameter 4 statements must be satisfied
   *   (1) A local parameter must exist with the same name as common parameter
   *   (2) Common parameter must valid
   *   (3) Local parameter must be invalid OR not have been set from its default
   *   (4) Both cannot be private (unless \p allow_private = true)
   *
   * Output objects have a set of common parameters that are passed
   * down to each of the output objects created. This method is used for
   * applying those common parameters.
   *
   * @see CommonOutputAction AddOutputAction
   */
  void applyParameters(const InputParameters & common,
                       const std::vector<std::string> & exclude = {},
                       const bool allow_private = false);

  /**
   * Method for applying common parameters
   * @param common The set of parameters to apply to the parameters stored in this object
   * @param include A vector of parameters to apply
   *
   * In order to apply common parameter 4 statements must be satisfied
   *   (1) A local parameter must exist with the same name as common parameter
   *   (2) Common parameter must valid
   *   (3) Local parameter must be invalid OR not have been set from its default
   *   (4) Both cannot be private
   *
   * Output objects have a set of common parameters that are passed
   * down to each of the output objects created. This method is used for
   * applying those common parameters.
   *
   * @see CommonOutputAction AddOutputAction
   */
  void applySpecificParameters(const InputParameters & common,
                               const std::vector<std::string> & include,
                               bool allow_private = false);

  /**
   * Apply values from a single parameter in common, to a single parameter stored in this object
   * @param common The set of InputParameters from which to extract parameters from
   * @param common_name The name within common from which to get the parameter values
   *
   * In order to apply common parameter 4 statements must be satisfied
   *   (1) A local parameter must exist with the same name as common parameter
   *   (2) Common parameter must valid
   *   (3) Local parameter must be invalid OR not have been set from its default
   *   (4) Both cannot be private
   */
  void applyParameter(const InputParameters & common,
                      const std::string & common_name,
                      bool allow_private = false);
(framework/include/utils/InputParameters.h)

Range Checked Parameters

The InputParameters object supports parsed expressions for various bounds checking of the user input so that custom logic does not need to be implemented in every end-user object. The range checking expression is always the second to last parameter right before the doc string.

  // BEGIN RANGE CHECKED PARAMETER METHODS
  /**
   * These methods add an range checked parameters. A lower and upper bound can be supplied and the
   * supplied parameter will be checked to fall within that range.
   */
  template <typename T>
  void addRequiredRangeCheckedParam(const std::string & name,
                                    const std::string & parsed_function,
                                    const std::string & doc_string);
  template <typename T>
  void addRangeCheckedParam(const std::string & name,
                            const T & value,
                            const std::string & parsed_function,
                            const std::string & doc_string);
  template <typename T>
  void addRangeCheckedParam(const std::string & name,
                            const std::string & parsed_function,
                            const std::string & doc_string);
(framework/include/utils/InputParameters.h)

Deprecating coupled variables

The InputParameters class provides a convenient method for deprecating coupled variable names called addDeprecatedCoupledVar. The method takes three arguments. The first corresponds to the deprecated name; the second argument is the new, blessed name that users should use. This name should have a corresponding params.addCoupledVar('blessed_name', 'blessed_name_doc_string') in the relevant Class::validParams() block. The final optional argument is the date that the deprecated variable name will be removed.