예제 #1
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));
  }
}
예제 #2
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();
}