TestControl::TestControl(const InputParameters & parameters) : Control(parameters), _test_type(getParam<MooseEnum>("test_type")), _alias("this/is/alias") { if (_test_type == "real") getControllableValue<Real>("parameter"); else if (_test_type == "variable") getControllableValue<NonlinearVariableName>("parameter"); else if (_test_type == "tid_warehouse_error") _fe_problem.getControlWarehouse().initialSetup(12345); else if (_test_type == "disable_executioner") getControllableValue<bool>("parameter"); else if (_test_type == "connection") { MooseObjectParameterName master(MooseObjectName("Kernels", "diff"), "coef"); MooseObjectParameterName slave(MooseObjectName("BCs", "left"), "value"); _app.getInputParameterWarehouse().addControllableParameterConnection(master, slave); } else if (_test_type == "alias") { MooseObjectParameterName slave(MooseObjectName("BCs", "left"), "value"); _app.getInputParameterWarehouse().addControllableParameterConnection(_alias, slave); } else if (_test_type == "mult") getControllableValue<Real>("parameter"); else if (_test_type != "point") mooseError("Unknown test type."); }
InputParameters & InputParameterWarehouse::getInputParameters(const std::string & tag, const std::string & name, THREAD_ID tid) const { return getInputParameters(MooseObjectName(tag, name), tid); }
InputParameters & InputParameterWarehouse::addInputParameters(const std::string & name, InputParameters parameters, THREAD_ID tid /* =0 */) { // Error if the name contains "::" if (name.find("::") != std::string::npos) mooseError("The object name may not contain '::' in the name: " << name); // Create the actual InputParameters object that will be reference by the objects MooseSharedPointer<InputParameters> ptr(new InputParameters(parameters)); // Set the name parameter to the object being created ptr->set<std::string>("_object_name") = name; // The object name defined by the base class name, this method of storing is used for // determining the uniqueness of the name MooseObjectName unique_name(ptr->get<std::string>("_moose_base"), name); // Check that the Parameters do not already exist if (_input_parameters[tid].find(unique_name) != _input_parameters[tid].end()) mooseError("A '" << unique_name.tag() << "' object already exists with the name '" << unique_name.name() << "'.\n"); // Store the parameters according to the base name _input_parameters[tid].insert(std::pair<MooseObjectName, MooseSharedPointer<InputParameters> >(unique_name, ptr)); // Store the object according to the control tags if (ptr->isParamValid("control_tags")) { std::vector<std::string> tags = ptr->get<std::vector<std::string> >("control_tags"); for (std::vector<std::string>::const_iterator it = tags.begin(); it != tags.end(); ++it) _input_parameters[tid].insert(std::pair<MooseObjectName, MooseSharedPointer<InputParameters> >(MooseObjectName(*it, name), ptr)); } // Set the name and tid parameters ptr->addPrivateParam<THREAD_ID>("_tid", tid); ptr->allowCopy(false); // no more copies allowed // Return a reference to the InputParameters object return *ptr; }
InputParameters & InputParameterWarehouse::addInputParameters(const std::string & name, InputParameters parameters, THREAD_ID tid /* =0 */) { // Error if the name contains "::" if (name.find("::") != std::string::npos) mooseError("The object name may not contain '::' in the name: ", name); // Create the actual InputParameters object that will be reference by the objects std::shared_ptr<InputParameters> ptr = std::make_shared<InputParameters>(parameters); // The object name defined by the base class name, this method of storing is used for // determining the uniqueness of the name MooseObjectName unique_name(ptr->get<std::string>("_moose_base"), name, "::"); // Check that the Parameters do not already exist if (_input_parameters[tid].find(unique_name) != _input_parameters[tid].end()) mooseError("A '", unique_name.tag(), "' object already exists with the name '", unique_name.name(), "'.\n"); // Store the parameters according to the base name _input_parameters[tid].insert( std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(unique_name, ptr)); // Build a list of object names std::vector<MooseObjectName> object_names; object_names.push_back(unique_name); // Store the object according to the control tags if (ptr->isParamValid("control_tags")) { const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags"); for (const auto & tag : tags) { if (!tag.empty()) { _input_parameters[tid].insert(std::pair<MooseObjectName, std::shared_ptr<InputParameters>>( MooseObjectName(tag, name), ptr)); object_names.emplace_back(tag, name); } } } // Store controllable parameters using all possible names for (libMesh::Parameters::iterator map_iter = ptr->begin(); map_iter != ptr->end(); ++map_iter) { const std::string & name = map_iter->first; libMesh::Parameters::Value * value = map_iter->second; if (ptr->isControllable(name)) for (const auto & object_name : object_names) { MooseObjectParameterName param_name(object_name, name); _controllable_items[tid].emplace_back(std::make_shared<ControllableItem>( param_name, value, ptr->getControllableExecuteOnTypes(name))); } } // Set the name and tid parameters, and unique_name std::stringstream oss; oss << unique_name; ptr->addPrivateParam<std::string>("_unique_name", oss.str()); ptr->addPrivateParam<std::string>("_object_name", name); ptr->addPrivateParam<THREAD_ID>("_tid", tid); ptr->allowCopy(false); // no more copies allowed // Return a reference to the InputParameters object return *ptr; }