25 #include "libmesh/simple_range.h" 31 _action_factory(factory),
32 _generator_valid(false),
33 _show_action_dependencies(false),
37 _displaced_mesh(nullptr)
47 mooseError(
"cannot use unregistered task '", task,
"' as final task");
87 std::string registered_identifier =
88 action->parameters().get<std::string>(
"registered_identifier");
89 std::set<std::string> tasks;
92 Moose::err << COLOR_DEFAULT <<
"Parsing Syntax: " << COLOR_GREEN << action->name()
94 << COLOR_DEFAULT <<
"Building Action: " << COLOR_DEFAULT << action->type()
96 << COLOR_DEFAULT <<
"Registered Identifier: " << COLOR_GREEN << registered_identifier
98 << COLOR_DEFAULT <<
"Specific Task: " << COLOR_CYAN
99 << action->specificTaskName() << std::endl;
121 if (action->specificTaskName() !=
"")
122 tasks.insert(action->specificTaskName());
123 else if (registered_identifier ==
"" &&
126 std::set<std::string> local_tasks = action->getAllTasks();
127 mooseAssert(local_tasks.size() == 1,
"More than one task inside of the " << action->name());
128 tasks.insert(*local_tasks.begin());
134 for (
const auto & task : tasks)
138 mooseError(
"A(n) ", task,
" is not a registered task");
149 const std::string & base = mparams.
get<std::string>(
"_moose_base");
152 mooseError(
"Task ", task,
" is not registered to build ", base,
" derived objects");
155 mooseError(
"Unable to locate registered base parameter for ", moa->getMooseObjectType());
159 action->appendTask(task);
162 Moose::err << COLOR_YELLOW <<
"Adding Action: " << COLOR_DEFAULT << action->type()
163 <<
" (" << COLOR_YELLOW << task << COLOR_DEFAULT <<
")" << std::endl;
171 Moose::err << std::endl;
186 const std::vector<std::shared_ptr<Action>> &
192 const std::list<Action *> &
214 bool ret_value =
false;
216 for (
const auto & action_pair :
as_range(it_pair))
223 params.
set<std::string>(
"registered_identifier") =
"(AutoBuilt)";
237 std::stringstream oss;
255 "The following unsatisfied actions where found while setting up the MOOSE problem:\n") +
271 std::ostringstream oss;
274 for (
const auto & task_vector : ordered_names)
276 oss <<
"[DBG][ACT] (" << COLOR_YELLOW;
278 task_vector.begin(), task_vector.end(), infix_ostream_iterator<std::string>(oss,
", "));
279 oss << COLOR_DEFAULT <<
")\n";
281 std::set<std::string> task_set(task_vector.begin(), task_vector.end());
282 for (
const auto & task : task_set)
290 if (act->name() !=
"")
291 oss <<
"[DBG][ACT]\t" << COLOR_GREEN << act->name() << COLOR_DEFAULT <<
'\n';
294 oss <<
"[DBG][ACT]\t" << act->type();
295 const std::set<std::string> tasks = act->getAllTasks();
296 if (tasks.size() > 1)
301 std::set<std::string> intersection, difference;
302 std::set_intersection(tasks.begin(),
306 std::inserter(intersection, intersection.end()));
307 std::set_difference(tasks.begin(),
309 intersection.begin(),
311 std::inserter(difference, difference.end()));
314 std::copy(intersection.begin(),
316 infix_ostream_iterator<std::string>(oss,
", "));
317 oss << COLOR_MAGENTA << (difference.empty() ?
"" :
", ");
319 difference.begin(), difference.end(), infix_ostream_iterator<std::string>(oss,
", "));
320 oss << COLOR_DEFAULT <<
")";
338 _console <<
"[DBG][ACT] Action Dependency Sets:\n";
341 _console <<
"\n[DBG][ACT] Executing actions:" << std::endl;
358 _console <<
"[DBG][ACT] Finished executing all actions with memory usage " <<
usage <<
"MB\n" 379 <<
"TASK (" << COLOR_YELLOW << std::setw(24) << task << COLOR_DEFAULT <<
") " 380 <<
"TYPE (" << COLOR_YELLOW << std::setw(32) << (*_act_iter)->type() << COLOR_DEFAULT
382 <<
"NAME (" << COLOR_YELLOW << std::setw(16) << (*_act_iter)->name() << COLOR_DEFAULT
383 <<
") Memory usage " <<
usage <<
"MB" << std::endl;
386 (*_act_iter)->timedAct();
395 std::map<std::string, std::vector<Action *>>::iterator iter;
397 std::vector<Action *> ordered_actions;
399 for (
const auto & act : block.second)
400 ordered_actions.push_back(act);
402 for (
const auto & act : ordered_actions)
405 if (act->parameters().blockFullpath() !=
"")
406 name = act->parameters().blockFullpath();
409 const std::set<std::string> & tasks = act->getAllTasks();
410 mooseAssert(!tasks.empty(),
"Task list is empty");
416 InputParameters & params = *(all_params.find(act->uniqueActionName())->second.get());
426 if (moose_object_action)
437 std::shared_ptr<FEProblem>
441 "ActionWarehouse::problem() is deprecated, please use ActionWarehouse::problemBase() \n");
448 return (*_act_iter)->parameters().blockFullpath();
467 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...
const std::string & name() const
Get the name of the object.
unsigned int size(THREAD_ID tid=0) const
Return how many kernels we store in the current warehouse.
std::list< Action * >::iterator ActionIterator
alias to hide implementation details
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
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.
void executeActionsWithAction(const std::string &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.
void printActionDependencySets() const
This method is used only during debugging when show_actions is set to true.
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...
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.
InputParameters & getObjectParams()
Retreive 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.
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)
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.
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()
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