28#include "libmesh/simple_range.h"
30std::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)
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");
225 std::shared_ptr<MooseObjectAction> moa = std::dynamic_pointer_cast<MooseObjectAction>(action);
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;
268const std::vector<std::shared_ptr<Action>> &
274const 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;
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(),
404 oss << COLOR_MAGENTA << (difference.empty() ?
"" :
", ");
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());
519 tree.
insertNode(name, *tasks.begin(),
true, ¶ms);
523 if (moose_object_action)
526 tree.
insertNode(name, *tasks.begin(),
false, &obj_params);
531 out << tree.
print(
"");
534std::shared_ptr<FEProblem>
538 "ActionWarehouse::problem() is deprecated, please use ActionWarehouse::problemBase() \n");
539 return std::dynamic_pointer_cast<FEProblem>(
_problem);
564 mooseError(
"\"", task,
"\" is not a registered task.");
std::list< Action * >::iterator ActionIterator
alias to hide implementation details
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Specialized factory for generic Action System objects.
std::set< std::string > getTasksByAction(const std::string &action) const
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters ¶meters)
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.
bool isRegisteredTask(const std::string &task) const
Whether or not a task with the name task is registered.
InputParameters getValidParams(const std::string &name)
Storage for action instances.
std::mutex _completed_tasks_mutex
Mutex for preventing read/write races for _completed_tasks.
const std::string & getMooseAppName()
void checkUnsatisfiedActions() const
This method checks the actions stored in the warehouse against the list of required registered action...
void setFinalTask(const std::string &task)
void printInputFile(std::ostream &out)
This method uses the Actions in the warehouse to reproduce the input file.
std::string _final_task
Last task to run before (optional) early termination - blank means no early termination.
std::map< std::string, std::list< Action * > > _action_blocks
Pointers to the actual parsed input file blocks.
std::string _current_task
const Action * getCurrentAction() const
bool _show_actions
Whether or not the action warehouse prints the action execution information.
void clear()
This method deletes all of the Actions in the warehouse.
void buildBuildableActions(const std::string &task)
This method auto-builds all Actions that needs to be built and adds them to ActionWarehouse.
std::set< std::string > _unsatisfied_dependencies
Use to store the current list of unsatisfied dependencies.
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.
std::string getCurrentActionName() const
bool _show_action_dependencies
Whether or not the action warehouse prints the action dependency information.
const std::list< Action * > _empty_action_list
std::vector< UserObjectName > getUserObjectParamDependencies(const InputParameters ¶ms) const
bool empty() const
returns a Boolean indicating whether the warehouse is empty or not.
bool isTaskComplete(const std::string &task) const
std::shared_ptr< FEProblem > problem()
bool _generator_valid
Flag to indicate whether or not there is an active iterator on this class.
Syntax & _syntax
Reference to a "syntax" of actions.
ActionWarehouse(MooseApp &app, Syntax &syntax, ActionFactory &factory)
std::vector< std::string > _ordered_names
The container that holds the sorted action names from the DependencyResolver.
std::shared_ptr< FEProblemBase > _problem
Problem class.
void sortUserObjectActions(std::list< Action * > &actions) const
Reorder the UserObject-constructing actions actions so that a UserObject that references another (thr...
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
ActionIterator actionBlocksWithActionEnd(const std::string &task)
ActionFactory & _action_factory
The Factory that builds Actions.
std::vector< std::shared_ptr< Action > > _all_ptrs
ActionIterator actionBlocksWithActionBegin(const std::string &task)
Iterators to the Actions in the warehouse.
bool _show_parser
Whether or not to print messages when actions are inserted in the warehouse by the parser.
std::set< std::string > _completed_tasks
The completed tasks.
void build()
Builds all auto-buildable tasks.
void executeActionsWithAction(const std::string &task_name)
This method executes only the actions in the warehouse that satisfy the task passed in.
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
std::shared_ptr< MooseMesh > _displaced_mesh
Possible mesh for displaced problem.
void printActionDependencySets() const
This method is used only during debugging when show_actions is set to true.
void executeAllActions()
This method loops over all actions in the warehouse and executes them.
bool hasTask(const std::string &task) const
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
std::shared_ptr< MooseMesh > _mesh
Mesh class.
void timedAct()
The method called externally that causes the action to act()
An inteface for the _console for outputting to the Console object.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Class that represents the dependecy as a graph.
void addItem(const T &value)
Add an independent item to the set.
const std::vector< T > & getSortedValues()
This function also returns dependency resolved values but with a simpler single vector interface.
void addEdge(const T &a, const T &b)
Add an edge between nodes 'a' and 'b'.
Base class for MOOSE-based applications.
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
const InputParameters & parameters() const
Get the parameters of the object.
const std::string & type() const
Get the type of this class.
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.
Base class to help creating an entire physics.
void insertNode(std::string syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
std::string print(const std::string &search_string)
Holding syntax for parsing input files.
const std::vector< std::vector< std::string > > & getSortedTaskSet()
Get a list of serialized tasks in a correct dependency order.
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 ...
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.
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...
const std::vector< std::string > & getSortedTask()
Get a list of serialized tasks in a correct dependency order.
bool shouldAutoBuild(const std::string &task) const
Returns a Boolean indicating whether MOOSE should attempt to automatically create an Action to satisf...
bool hasTask(const std::string &task) const
Returns a Boolean indicating whether or not a task is registered with the syntax object.
GCC9 currently hits a "no type named 'value_type'" error during build if this is removed and iterator...
void usage(const std::string &progName)
std::size_t convertBytes(std::size_t bytes, MemUnits unit)
convert bytes to selected unit prefix
bool getMemoryStats(Stats &stats)
get all memory stats for the current process stats The Stats object to fill with the data
std::size_t _physical_memory