Ejemplo n.º 1
0
MooseObjectPtr
Factory::create(const std::string & obj_name, const std::string & name, InputParameters parameters, THREAD_ID tid /* =0 */)
{
  // DEPRECATED CREATION
  if (_name_to_legacy_build_pointer.find(obj_name) != _name_to_legacy_build_pointer.end())
    return createLegacy(obj_name, name, parameters, tid);

  // Pointer to the object constructor
  std::map<std::string, buildPtr>::iterator it = _name_to_build_pointer.find(obj_name);

  // Check if the object is registered
  if (it == _name_to_build_pointer.end())
    reportUnregisteredError(obj_name);

  // Print out deprecated message, if it exists
  deprecatedMessage(obj_name);

  // Check to make sure that all required parameters are supplied
  parameters.checkParams(name);

  // Create the actual parameters object that the object will reference
  InputParameters & params = _app.getInputParameterWarehouse().addInputParameters(name, parameters, tid);

  // register type name as constructed
  _constructed_types.insert(obj_name);

  // Actually call the function pointer.  You can do this in one line,
  // but it's a bit more obvious what's happening if you do it in two...
  buildPtr & func = it->second;
  return (*func)(params);
}
Ejemplo n.º 2
0
MooseObjectPtr
Factory::create(const std::string & obj_name, const std::string & name, InputParameters parameters)
{
  std::map<std::string, buildPtr>::iterator it = _name_to_build_pointer.find(obj_name);

  // Check if the object is registered
  if (it == _name_to_build_pointer.end())
    mooseError("Object '" + obj_name + "' was not registered.");

  // Print out deprecated message, if it exists
  deprecatedMessage(obj_name);

  // Check to make sure that all required parameters are supplied
  parameters.addParam<std::string>("name", name, "The objects short name");
  parameters.addPrivateParam<MooseObjectID>("_object_id", _object_count);
  parameters.checkParams(name);

  // Increment object counter
  _object_count++;

  // Actually call the function pointer.  You can do this in one line,
  // but it's a bit more obvious what's happening if you do it in two...
  buildPtr & func = it->second;
  return (*func)(name, parameters);
}
Ejemplo n.º 3
0
InputParameters
Factory::getValidParams(const std::string & obj_name)
{
  std::map<std::string, paramsPtr>::iterator it = _name_to_params_pointer.find(obj_name);

  // Check if the object is registered
  if (it == _name_to_params_pointer.end())
    reportUnregisteredError(obj_name);

  // Print out deprecated message, if it exists
  deprecatedMessage(obj_name);

  // Return the parameters
  paramsPtr & func = it->second;
  InputParameters params = (*func)();
  params.addPrivateParam("_moose_app", &_app);

  return params;
}
Ejemplo n.º 4
0
MooseObjectPtr
Factory::create_shared_ptr(const std::string & obj_name, const std::string & name, InputParameters parameters)
{
  std::map<std::string, buildPtrShared>::iterator
    it = _name_to_build_pointer_shared.find(obj_name);

  // Check if the object is registered
  if (it == _name_to_build_pointer_shared.end())
    mooseError("Object '" + obj_name + "' was not registered.");

  // Print out deprecated message, if it exists
  deprecatedMessage(obj_name);

  // Check to make sure that all required parameters are supplied
  parameters.checkParams(name);

  // Actually call the function pointer.  You can do this in one line,
  // but it's a bit more obvious what's happening if you do it in two...
  buildPtrShared & func = it->second;
  return (*func)(name, parameters);
}
Ejemplo n.º 5
0
MooseObjectPtr
Factory::createLegacy(const std::string & obj_name, const std::string & name, InputParameters parameters, THREAD_ID tid /* =0 */)
{
  // Pointer to the object constructor
  std::map<std::string, buildLegacyPtr>::iterator it = _name_to_legacy_build_pointer.find(obj_name);

  // Check if the object is registered
  if (it == _name_to_legacy_build_pointer.end())
    mooseError("Object '" + obj_name + "' was not registered.");

  // Print out deprecated message, if it exists
  deprecatedMessage(obj_name);

  // Check to make sure that all required parameters are supplied
  parameters.set<std::string>("name") = name;
  parameters.set<THREAD_ID>("_tid") = tid;
  parameters.checkParams(name);

  // Actually call the function pointer.  You can do this in one line,
  // but it's a bit more obvious what's happening if you do it in two...
  buildLegacyPtr & func = it->second;
  return (*func)(MooseUtils::shortName(name), parameters);
}
Ejemplo n.º 6
0
MooseObjectPtr
Factory::create(const std::string & obj_name,
                const std::string & name,
                InputParameters parameters,
                THREAD_ID tid /* =0 */,
                bool print_deprecated /* =true */)
{
  if (print_deprecated)
    mooseDeprecated("Factory::create() is deprecated, please use Factory::create<T>() instead");

  // Pointer to the object constructor
  std::map<std::string, buildPtr>::iterator it = _name_to_build_pointer.find(obj_name);

  // Check if the object is registered
  if (it == _name_to_build_pointer.end())
    reportUnregisteredError(obj_name);

  // Print out deprecated message, if it exists
  deprecatedMessage(obj_name);

  // Create the actual parameters object that the object will reference
  InputParameters & params =
      _app.getInputParameterWarehouse().addInputParameters(name, parameters, tid);

  // Set the _type parameter
  params.set<std::string>("_type") = obj_name;

  // Check to make sure that all required parameters are supplied
  params.checkParams(name);

  // register type name as constructed
  _constructed_types.insert(obj_name);

  // add FEProblem pointers to object's params object
  if (_app.actionWarehouse().problemBase())
    _app.actionWarehouse().problemBase()->setInputParametersFEProblem(params);

  // call the function pointer to build the object
  buildPtr & func = it->second;
  auto obj = (*func)(params);

  auto fep = std::dynamic_pointer_cast<FEProblemBase>(obj);
  if (fep)
    _app.actionWarehouse().problemBase() = fep;

  // Make sure no unexpected parameters were added by the object's constructor or by the action
  // initiating this create call.  All parameters modified by the constructor must have already
  // been specified in the object's validParams function.
  InputParameters orig_params = getValidParams(obj_name);
  if (orig_params.n_parameters() != parameters.n_parameters())
  {
    std::set<std::string> orig, populated;
    for (const auto & it : orig_params)
      orig.emplace(it.first);
    for (const auto & it : parameters)
      populated.emplace(it.first);

    std::set<std::string> diff;
    std::set_difference(populated.begin(),
                        populated.end(),
                        orig.begin(),
                        orig.end(),
                        std::inserter(diff, diff.begin()));

    if (!diff.empty())
    {
      std::stringstream ss;
      for (const auto & name : diff)
        ss << ", " << name;
      mooseError("attempted to set unregistered parameter(s) for ",
                 obj_name,
                 " object:\n    ",
                 ss.str().substr(2));
    }
  }

  return obj;
}