Exemplo n.º 1
0
void
InputParameters::applyParameters(const InputParameters & common)
{
  // Loop through the common parameters
  for (InputParameters::const_iterator it = common.begin(); it != common.end(); ++it)
  {
    // Common parameter name
    const std::string & common_name = it->first;

    // Extract the properties from the local parameter for the current common parameter name
    bool local_exist = _values.find(common_name) != _values.end();
    bool local_set   = _set_by_add_param.find(common_name) == _set_by_add_param.end();
    bool local_priv  = isPrivate(common_name);
    bool local_valid = isParamValid(common_name);

    // Extract the properties from the common parameter
    bool common_valid = common.isParamValid(common_name);
    bool common_priv  = common.isPrivate(common_name);

    /* 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) Neither may be private
     */
    if ( local_exist && common_valid && (!local_valid || !local_set) && (!common_priv || !local_priv))
    {
      delete _values[common_name];
      _values[common_name] = it->second->clone();
      set_attributes(common_name, false);
    }
  }
}
Exemplo n.º 2
0
void
InputParameters::applyParameters(const InputParameters & common)
{
  // Disable the display of deprecated message when applying common parameters, this avoids a dump of messages
  _show_deprecated_message = false;

  // Loop through the common parameters
  for (InputParameters::const_iterator it = common.begin(); it != common.end(); ++it)
  {
    // Common parameter name
    const std::string & common_name = it->first;

    // Extract the properties from the local parameter for the current common parameter name
    bool local_exist = _values.find(common_name) != _values.end();
    bool local_set   = _set_by_add_param.find(common_name) == _set_by_add_param.end();
    bool local_priv  = isPrivate(common_name);
    bool local_valid = isParamValid(common_name);

    // Extract the properties from the common parameter
    bool common_valid = common.isParamValid(common_name);
    bool common_priv  = common.isPrivate(common_name);

    /* 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) Neither may be private
     */
    if ( local_exist && common_valid && (!local_valid || !local_set) && (!common_priv || !local_priv))
    {
      delete _values[common_name];
      _values[common_name] = it->second->clone();
      set_attributes(common_name, false);
    }
  }

  // Loop through the coupled variables
  for (std::set<std::string>::const_iterator it = common.coupledVarsBegin(); it != common.coupledVarsEnd(); ++it)
  {
    // If the local parameters has a coupled variable, populate it with the value from the common parameters
    const std::string var_name = *it;
    if (hasCoupledValue(var_name))
    {
      if (common.hasDefaultCoupledValue(var_name))
        addCoupledVar(var_name, common.defaultCoupledValue(var_name), common.getDocString(var_name));
      else
        addCoupledVar(var_name, common.getDocString(var_name));
    }
  }

  // Enable deprecated message printing
  _show_deprecated_message = true;
}
Exemplo n.º 3
0
std::string
YAMLFormatter::printParams(const std::string & prefix,
                           const std::string & /*fully_qualified_name*/,
                           InputParameters & params,
                           short depth,
                           const std::string & search_string,
                           bool & found)
{
  std::ostringstream oss;
  std::string indent(depth * 2, ' ');

  for (auto & iter : params)
  {
    std::string name = iter.first;
    // First make sure we want to see this parameter, also block active and type
    if (params.isPrivate(iter.first) || name == "active" ||
        (search_string != "" && search_string != iter.first) || haveSeenIt(prefix, iter.first))
      continue;

    found = true;

    // Mark it as "seen"
    seenIt(prefix, iter.first);

    // Block params may be required and will have a doc string
    std::string required = params.isParamRequired(iter.first) ? "Yes" : "No";

    oss << indent << "  - name: " << name << "\n";
    oss << indent << "    required: " << required << "\n";
    oss << indent << "    default: !!str ";

    // Only output default if it has one
    if (params.isParamValid(iter.first))
    {
      // prints the value, which is the default value when dumping the tree
      // because it hasn't been changed

      // Output stream, performing special operations for writing objects such as Points and
      // RealVectorValues
      std::ostringstream toss;
      buildOutputString(toss, iter);

      // remove additional '\n' possibly generated in output (breaks YAML parsing)
      std::string tmp_str = toss.str();
      for (auto & ch : tmp_str)
        if (ch == '\n')
          ch = ' ';
      if (tmp_str == ",")
        oss << "\"" << tmp_str << "\"";
      else
        oss << tmp_str;
    }
    else if (params.hasDefaultCoupledValue(iter.first))
      oss << params.defaultCoupledValue(iter.first);

    std::string doc = params.getDocString(iter.first);
    MooseUtils::escape(doc);
    // Print the type
    oss << "\n"
        << indent << "    cpp_type: " << params.type(iter.first) << "\n"
        << indent << "    group_name: ";
    std::string group_name = params.getGroupName(iter.first);
    if (!group_name.empty())
      oss << "'" << group_name << "'";

    {
      InputParameters::Parameter<MooseEnum> * enum_type =
          dynamic_cast<InputParameters::Parameter<MooseEnum> *>(iter.second);
      if (enum_type)
        oss << "\n" << indent << "    options: " << enum_type->get().getRawNames();
    }
    {
      InputParameters::Parameter<MultiMooseEnum> * enum_type =
          dynamic_cast<InputParameters::Parameter<MultiMooseEnum> *>(iter.second);
      if (enum_type)
        oss << "\n" << indent << "    options: " << enum_type->get().getRawNames();
    }
    {
      InputParameters::Parameter<std::vector<MooseEnum>> * enum_type =
          dynamic_cast<InputParameters::Parameter<std::vector<MooseEnum>> *>(iter.second);
      if (enum_type)
        oss << "\n" << indent << "    options: " << (enum_type->get())[0].getRawNames();
    }

    oss << "\n" << indent << "    description: |\n      " << indent << doc << "\n";
  }

  return oss.str();
}