Exemple #1
0
TEST(InputParameters, checkSetDocString)
{
  InputParameters params = emptyInputParameters();
  params.addParam<Real>("little_guy", "What about that little guy?");
  params.setDocString("little_guy", "That little guy, I wouldn't worry about that little_guy.");
  ASSERT_TRUE(params.getDocString("little_guy")
                  .find("That little guy, I wouldn't worry about that little_guy.") !=
              std::string::npos)
      << "retrieved doc string has unexpected value '" << params.getDocString("little_guy") << "'";
}
Exemple #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;
}
Exemple #3
0
void
CommandLine::addCommandLineOptionsFromParams(InputParameters & params)
{
  for (const auto & it : params)
  {
    Option cli_opt;
    std::vector<std::string> syntax;
    std::string orig_name = it.first;

    cli_opt.description = params.getDocString(orig_name);
    syntax = params.getSyntax(orig_name);
    cli_opt.cli_syntax = syntax;
    cli_opt.required = false;
    InputParameters::Parameter<bool> * bool_type = dynamic_cast<InputParameters::Parameter<bool>*>(it.second);
    if (bool_type)
      cli_opt.argument_type = CommandLine::NONE;
    else
      cli_opt.argument_type = CommandLine::REQUIRED;

    addOption(orig_name, cli_opt);
  }
}
Exemple #4
0
void
CommandLine::populateInputParams(InputParameters & params)
{
  for (const auto & it : params)
  {
    std::string orig_name = it.first;
    if (search(orig_name))
    {
      {
        InputParameters::Parameter<std::string> * string_type = dynamic_cast<InputParameters::Parameter<std::string>*>(it.second);
        if (string_type)
        {
          search(orig_name, params.set<std::string>(orig_name));
          continue;
        }

        InputParameters::Parameter<Real> * real_type = dynamic_cast<InputParameters::Parameter<Real>*>(it.second);
        if (real_type)
        {
          search(orig_name, params.set<Real>(orig_name));
          continue;
        }

        InputParameters::Parameter<unsigned int> * uint_type = dynamic_cast<InputParameters::Parameter<unsigned int>*>(it.second);
        if (uint_type)
        {
          search(orig_name, params.set<unsigned int>(orig_name));
          continue;
        }

        InputParameters::Parameter<int> * int_type = dynamic_cast<InputParameters::Parameter<int>*>(it.second);
        if (int_type)
        {
          search(orig_name, params.set<int>(orig_name));
          continue;
        }

        InputParameters::Parameter<bool> * bool_type = dynamic_cast<InputParameters::Parameter<bool>*>(it.second);
        if (bool_type)
        {
          search(orig_name, params.set<bool>(orig_name));
          continue;
        }
      }
    }
    else if (params.isParamRequired(orig_name))
      mooseError("Missing required command-line parameter: " << orig_name << std::endl << "Doc String: " << params.getDocString(orig_name));
  }
}
Exemple #5
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();
}