Exemple #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);
}
Exemple #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);
}
Exemple #3
0
TEST(InputParameters, checkControlParamValidError)
{
  try
  {
    InputParameters params = emptyInputParameters();
    params.declareControllable("not_valid");
    params.checkParams("");
    FAIL() << "checkParams failed to catch invalid control param";
  }
  catch (const std::exception & e)
  {
    std::string msg(e.what());
    ASSERT_TRUE(msg.find("The parameter 'not_valid'") != std::string::npos)
        << "failed with unexpected error: " << msg;
  }
}
Exemple #4
0
// This tests for the bug https://github.com/idaholab/moose/issues/8586.
// It makes sure that range-checked input file parameters comparison functions
// do absolute floating point comparisons instead of using a default epsilon.
TEST(InputParameters, checkRangeCheckedParam)
{
  try
  {
    InputParameters params = emptyInputParameters();
    params.addRangeCheckedParam<Real>("p", 1.000000000000001, "p = 1", "Some doc");
    params.checkParams("");
    FAIL() << "range checked input param failed to catch 1.000000000000001 != 1";
  }
  catch (const std::exception & e)
  {
    std::string msg(e.what());
    ASSERT_TRUE(msg.find("Range check failed for param") != std::string::npos)
        << "range check failed with unexpected error: " << msg;
  }
}
Exemple #5
0
void
InputParametersTest::checkControlParamValidError()
{
    try
    {
        InputParameters params = emptyInputParameters();
        params.declareControllable("not_valid");
        params.checkParams("");
        CPPUNIT_ASSERT( false ); // shouldn't get here
    }
    catch(const std::exception & e)
    {
        std::string msg(e.what());
        CPPUNIT_ASSERT( msg.find("The parameter 'not_valid'") != std::string::npos );
    }
}
Exemple #6
0
TEST(InputParameters, checkControlParamTypeError)
{
  try
  {
    InputParameters params = emptyInputParameters();
    params.addParam<PostprocessorName>("pp_name", "make_it_valid", "Some doc");
    params.declareControllable("pp_name");
    params.checkParams("");
    FAIL() << "checkParams failed to catch invalid control param type";
  }
  catch (const std::exception & e)
  {
    std::string msg(e.what());
    ASSERT_TRUE(msg.find("cannot be marked as controllable because its type") != std::string::npos)
        << "failed with unexpected error:" << msg;
  }
}
Exemple #7
0
TEST(InputParameters, checkControlParamPrivateError)
{
  try
  {
    InputParameters params = emptyInputParameters();
    params.addPrivateParam<Real>("private", 1);
    params.declareControllable("private");
    params.checkParams("");
    FAIL() << "checkParams failed to catch private control param";
  }
  catch (const std::exception & e)
  {
    std::string msg(e.what());
    ASSERT_TRUE(msg.find("is a private param") != std::string::npos)
        << "failed with unexpected error: " << msg;
  }
}
Exemple #8
0
void
InputParametersTest::checkControlParamTypeError()
{
    try
    {
        InputParameters params = emptyInputParameters();
        params.addParam<PostprocessorName>("pp_name", "make_it_valid", "Some doc");
        params.declareControllable("pp_name");
        params.checkParams("");
        CPPUNIT_ASSERT( false ); // shouldn't get here
    }
    catch(const std::exception & e)
    {
        std::string msg(e.what());
        CPPUNIT_ASSERT( msg.find("cannot be marked as controllable because its type") != std::string::npos );
    }
}
Exemple #9
0
void
InputParametersTest::checkControlParamPrivateError()
{
    try
    {
        InputParameters params = emptyInputParameters();
        params.addPrivateParam<Real>("private", 1);
        params.declareControllable("private");
        params.checkParams("");
        CPPUNIT_ASSERT( false ); // shouldn't get here
    }
    catch(const std::exception & e)
    {
        std::string msg(e.what());
        CPPUNIT_ASSERT( msg.find("is a private parameter") != std::string::npos );
    }
}
ReferenceResidualProblem::ReferenceResidualProblem(const std::string & name, InputParameters params) :
    FEProblem(name, params)
{
  _app.parser().extractParams("Problem", params);
  params.checkParams("Problem");

  if (params.isParamValid("solution_variables"))
    _solnVarNames = params.get<std::vector<std::string> >("solution_variables");
  if (params.isParamValid("reference_residual_variables"))
    _refResidVarNames = params.get<std::vector<std::string> >("reference_residual_variables");
  if (_solnVarNames.size() != _refResidVarNames.size() )
  {
    std::ostringstream err;
    err << "In ReferenceResidualProblem, size of solution_variables ("<<_solnVarNames.size()
        <<") != size of reference_residual_variables ("<<_refResidVarNames.size()<<")";
    mooseError(err.str());
  }
  _accept_mult = params.get<Real>("acceptable_multiplier");
  _accept_iters = params.get<int>("acceptable_iterations");
}
Exemple #11
0
MooseSharedPointer<Action>
ActionFactory::create(const std::string & action, const std::string & action_name, InputParameters parameters)
{
  parameters.addPrivateParam("_moose_app", &_app);
  parameters.addPrivateParam("action_type", action);
  std::pair<ActionFactory::iterator, ActionFactory::iterator> iters;
  BuildInfo *build_info = NULL;

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

  iters = _name_to_build_info.equal_range(action);

  // Find the Action that matches the one we have registered based on unique_id
  unsigned short count = 0;
  for (ActionFactory::iterator it = iters.first; it != iters.second; ++it)
  {
    ++count;
    if (parameters.have_parameter<unsigned int>("unique_id") && it->second._unique_id == parameters.get<unsigned int>("unique_id"))
    {
      build_info = &(it->second);
      break;
    }
  }
  // For backwards compatibility - If there is only one Action registered but it doesn't contain a unique_id that
  // matches, then surely it must still be the correct one
  if (count == 1 && !build_info)
    build_info = &(iters.first->second);

  if (!build_info)
    mooseError(std::string("Unable to find buildable Action from supplied InputParameters Object for ") + action_name);

  // Add the name to the parameters and create the object
  parameters.set<std::string>("_action_name") = action_name;
  MooseSharedPointer<Action> action_obj = (*build_info->_build_pointer)(parameters);

  if (parameters.get<std::string>("task") == "")
    action_obj->appendTask(build_info->_task);

  return action_obj;
}
Exemple #12
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);
}
Exemple #13
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);
}