28 #include "libmesh/simple_range.h" 30 std::vector<UserObjectName>
33 std::vector<UserObjectName> dependencies;
34 for (
const auto & [_, param] : params)
36 if (
const auto dependency =
39 const auto & uo_name = dependency->get();
41 dependencies.push_back(uo_name);
43 else if (
const auto vector_dependency =
46 for (
const auto & uo_name : vector_dependency->get())
48 dependencies.push_back(uo_name);
59 std::map<std::string, Action *> action_for_uo_name;
60 for (
const auto act : actions)
61 if (dynamic_cast<MooseObjectAction *>(act))
62 action_for_uo_name.emplace(act->name(), act);
66 else if (
const auto physics = dynamic_cast<const PhysicsBase *>(act))
67 for (
const auto & uo_name : physics->getSuppliedUserObjects())
68 action_for_uo_name.emplace(uo_name, act);
73 for (
const auto act : actions)
76 for (
const auto act : actions)
82 const auto & relevant_params =
83 moose_object_action ? moose_object_action->
getObjectParams() : act->parameters();
86 const auto it = action_for_uo_name.find(dep_name);
87 if (it != action_for_uo_name.end() && it->second != act)
89 resolver.
addEdge(it->second, act);
102 actions.assign(sorted.begin(), sorted.end());
113 _action_factory(factory),
114 _generator_valid(false),
115 _show_action_dependencies(false),
116 _show_actions(false),
118 _current_action(nullptr),
120 _displaced_mesh(nullptr)
130 mooseError(
"cannot use unregistered task '", task,
"' as final task");
170 std::string registered_identifier =
171 action->parameters().get<std::string>(
"registered_identifier");
172 std::set<std::string> tasks;
175 Moose::err << COLOR_DEFAULT <<
"Parsing Syntax: " << COLOR_GREEN << action->name()
177 << COLOR_DEFAULT <<
"Building Action: " << COLOR_DEFAULT << action->type()
179 << COLOR_DEFAULT <<
"Registered Identifier: " << COLOR_GREEN << registered_identifier
181 << COLOR_DEFAULT <<
"Specific Task: " << COLOR_CYAN
182 << action->specificTaskName() << std::endl;
204 if (action->specificTaskName() !=
"")
205 tasks.insert(action->specificTaskName());
206 else if (registered_identifier ==
"" &&
209 std::set<std::string> local_tasks = action->getAllTasks();
210 mooseAssert(local_tasks.size() == 1,
"More than one task inside of the " << action->name());
211 tasks.insert(*local_tasks.begin());
217 for (
const auto & task : tasks)
221 mooseError(
"A(n) ", task,
" is not a registered task");
232 const std::string & base = mparams.
getBase();
234 mooseError(
"Task ", task,
" is not registered to build ", base,
" derived objects");
237 mooseError(
"Unable to locate registered base parameter for ", moa->getMooseObjectType());
241 action->appendTask(task);
244 Moose::err << COLOR_YELLOW <<
"Adding Action: " << COLOR_DEFAULT << action->type()
245 <<
" (" << COLOR_YELLOW << task << COLOR_DEFAULT <<
")" << std::endl;
253 Moose::err << std::endl;
268 const std::vector<std::shared_ptr<Action>> &
274 const std::list<Action *> &
296 bool ret_value =
false;
298 for (
const auto & action_pair :
as_range(it_pair))
300 const auto & type = action_pair.second;
304 std::string
name =
"auto_" + type;
306 name.begin(),
name.end(),
name.begin(), [](
const auto v) {
return std::tolower(v); });
310 params.
set<std::string>(
"registered_identifier") =
"(AutoBuilt)";
324 std::stringstream oss;
342 "The following unsatisfied actions where found while setting up the MOOSE problem:\n") +
358 std::ostringstream oss;
361 for (
const auto & task_vector : ordered_names)
363 oss <<
"[DBG][ACT] (" << COLOR_YELLOW;
365 task_vector.begin(), task_vector.end(), infix_ostream_iterator<std::string>(oss,
", "));
366 oss << COLOR_DEFAULT <<
")\n";
368 std::set<std::string> task_set(task_vector.begin(), task_vector.end());
369 for (
const auto & task : task_set)
377 if (act->name() !=
"")
378 oss <<
"[DBG][ACT]\t" << COLOR_GREEN << act->name() << COLOR_DEFAULT <<
'\n';
381 oss <<
"[DBG][ACT]\t" << act->type();
382 const std::set<std::string> tasks = act->getAllTasks();
383 if (tasks.size() > 1)
388 std::set<std::string> intersection, difference;
389 std::set_intersection(tasks.begin(),
393 std::inserter(intersection, intersection.end()));
394 std::set_difference(tasks.begin(),
396 intersection.begin(),
398 std::inserter(difference, difference.end()));
401 std::copy(intersection.begin(),
403 infix_ostream_iterator<std::string>(oss,
", "));
404 oss << COLOR_MAGENTA << (difference.empty() ?
"" :
", ");
406 difference.begin(), difference.end(), infix_ostream_iterator<std::string>(oss,
", "));
407 oss << COLOR_DEFAULT <<
")";
425 _console <<
"[DBG][ACT] Action Dependency Sets:\n";
428 _console <<
"\n[DBG][ACT] Executing actions:" << std::endl;
446 _console <<
"[DBG][ACT] Finished executing all actions with memory usage " <<
usage <<
"MB\n" 460 if (task ==
"add_user_object")
474 <<
"TASK (" << COLOR_YELLOW << std::setw(24) << task << COLOR_DEFAULT <<
") " 476 << COLOR_DEFAULT <<
") " 478 << COLOR_DEFAULT <<
") Memory usage " <<
usage <<
"MB" << std::endl;
492 std::map<std::string, std::vector<Action *>>::iterator iter;
494 std::vector<Action *> ordered_actions;
496 for (
const auto & act : block.second)
497 ordered_actions.push_back(act);
499 for (
const auto & act : ordered_actions)
502 if (act->parameters().blockFullpath() !=
"")
503 name = act->parameters().blockFullpath();
506 const std::set<std::string> & tasks = act->getAllTasks();
507 mooseAssert(!tasks.empty(),
"Task list is empty");
513 InputParameters & params = *(all_params.find(act->uniqueActionName())->second.get());
523 if (moose_object_action)
534 std::shared_ptr<FEProblem>
538 "ActionWarehouse::problem() is deprecated, please use ActionWarehouse::problemBase() \n");
564 mooseError(
"\"", task,
"\" is not a registered task.");
std::string name(const ElemQuality q)
bool hasTask(const std::string &task) const
Returns a Boolean indicating whether or not a task is registered with the syntax object.
bool _show_parser
Whether or not to print messages when actions are inserted in the warehouse by the parser...
void checkUnsatisfiedActions() const
This method checks the actions stored in the warehouse against the list of required registered action...
unsigned int size(THREAD_ID tid=0) const
Return how many kernels we store in the current warehouse.
void executeActionsWithAction(const std::string &task_name)
This method executes only the actions in the warehouse that satisfy the task passed in...
std::list< Action * >::iterator ActionIterator
alias to hide implementation details
const Action * getCurrentAction() const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool getMemoryStats(Stats &stats)
get all memory stats for the current process stats The Stats object to fill with the data ...
InputParameters getValidParams(const std::string &name)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
std::size_t _physical_memory
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
bool isTaskComplete(const std::string &task) const
Syntax & _syntax
Reference to a "syntax" of actions.
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > getActionsByTask(const std::string &task) const
Returns begin and end iterators in a multimap from tasks to actions names.
const std::vector< T > & getSortedValues()
This function also returns dependency resolved values but with a simpler single vector interface...
const InputParameters & parameters() const
Get the parameters of the object.
std::set< std::string > getTasksByAction(const std::string &action) const
bool hasTask(const std::string &task) const
const std::string & getMooseAppName()
void setFinalTask(const std::string &task)
std::string getCurrentActionName() const
Base class for MOOSE-based applications.
Storage for action instances.
const std::vector< std::string > & getSortedTask()
Get a list of serialized tasks in a correct dependency order.
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
void printInputFile(std::ostream &out)
This method uses the Actions in the warehouse to reproduce the input file.
std::vector< UserObjectName > getUserObjectParamDependencies(const InputParameters ¶ms) const
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
void printActionDependencySets() const
This method is used only during debugging when show_actions is set to true.
void addEdge(const T &a, const T &b)
Add an edge between nodes 'a' and 'b'.
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters ¶meters)
std::string _final_task
Last task to run before (optional) early termination - blank means no early termination.
std::vector< std::string > _ordered_names
The container that holds the sorted action names from the DependencyResolver.
bool shouldAutoBuild(const std::string &task) const
Returns a Boolean indicating whether MOOSE should attempt to automatically create an Action to satisf...
void addItem(const T &value)
Add an independent item to the set.
std::vector< std::string > getNonDeprecatedSyntaxByAction(const std::string &action, const std::string &task="")
Retrieve the non-deprecated syntax associated with the passed in action type string.
const std::string & name() const
Get the name of the class.
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
bool isRegisteredTask(const std::string &task) const
Whether or not a task with the name task is registered.
bool empty() const
returns a Boolean indicating whether the warehouse is empty or not.
std::set< std::string > _completed_tasks
The completed tasks.
std::mutex _completed_tasks_mutex
Mutex for preventing read/write races for _completed_tasks.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Specialized factory for generic Action System objects.
An inteface for the _console for outputting to the Console object.
const std::vector< std::vector< std::string > > & getSortedTaskSet()
Get a list of serialized tasks in a correct dependency order.
void usage(const std::string &progName)
const std::string & type() const
Get the type of this class.
std::map< std::string, std::list< Action * > > _action_blocks
Pointers to the actual parsed input file blocks.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
std::shared_ptr< MooseMesh > _displaced_mesh
Possible mesh for displaced problem.
bool _generator_valid
Flag to indicate whether or not there is an active iterator on this class.
std::string isAssociated(const std::string &real_id, bool *is_parent, const std::map< std::string, std::set< std::string >> &alt_map={}) const
Method for determining whether a piece of syntax is associated with an Action an optional syntax map ...
void insertNode(std::string syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
const std::list< Action * > _empty_action_list
std::vector< std::shared_ptr< Action > > _all_ptrs
std::shared_ptr< FEProblemBase > _problem
Problem class.
std::string print(const std::string &search_string)
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
ActionWarehouse(MooseApp &app, Syntax &syntax, ActionFactory &factory)
std::shared_ptr< MooseMesh > _mesh
Mesh class.
bool _show_actions
Whether or not the action warehouse prints the action execution information.
MooseApp & _app
The MooseApp this Warehouse is associated with.
const std::vector< std::shared_ptr< Action > > & allActionBlocks() const
Returns a reference to all of the actions.
void build()
Builds all auto-buildable tasks.
void timedAct()
The method called externally that causes the action to act()
void sortUserObjectActions(std::list< Action *> &actions) const
Reorder the UserObject-constructing actions actions so that a UserObject that references another (thr...
Holding syntax for parsing input files.
bool verifyMooseObjectTask(const std::string &base, const std::string &task) const
Returns a Boolean indicating whether a task is associated with on of the MOOSE pluggable systems (BAS...
void executeAllActions()
This method loops over all actions in the warehouse and executes them.
ActionIterator actionBlocksWithActionEnd(const std::string &task)
std::set< std::string > _unsatisfied_dependencies
Use to store the current list of unsatisfied dependencies.
bool _show_action_dependencies
Whether or not the action warehouse prints the action dependency information.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
std::shared_ptr< FEProblem > problem()
Class that represents the dependecy as a graph.
ActionIterator actionBlocksWithActionBegin(const std::string &task)
Iterators to the Actions in the warehouse.
void clear()
This method deletes all of the Actions in the warehouse.
std::size_t convertBytes(std::size_t bytes, MemUnits unit)
convert bytes to selected unit prefix
void buildBuildableActions(const std::string &task)
This method auto-builds all Actions that needs to be built and adds them to ActionWarehouse.
ActionFactory & _action_factory
The Factory that builds Actions.
std::string _current_task