www.mooseframework.org
ActionWarehouse.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef ACTIONWAREHOUSE_H
16 #define ACTIONWAREHOUSE_H
17 
18 #include <string>
19 #include <set>
20 #include <map>
21 #include <vector>
22 #include <list>
23 #include <ostream>
24 
25 // MOOSE includes
26 #include "Action.h"
27 #include "ConsoleStreamInterface.h"
28 
30 using ActionIterator = std::list<Action *>::iterator;
31 
32 class MooseMesh;
33 class Syntax;
34 class ActionFactory;
35 class FEProblem;
36 
41 {
42 public:
43  ActionWarehouse(MooseApp & app, Syntax & syntax, ActionFactory & factory);
45 
50  void build();
51 
55  void clear();
56 
60  bool empty() const { return _action_blocks.empty(); }
61 
65  void addActionBlock(std::shared_ptr<Action> blk);
66 
72  void checkUnsatisfiedActions() const;
73 
79  void printActionDependencySets() const;
80 
87  void printInputFile(std::ostream & out);
88 
95  ActionIterator actionBlocksWithActionBegin(const std::string & task);
96  ActionIterator actionBlocksWithActionEnd(const std::string & task);
97 
101  const std::list<Action *> & getActionListByName(const std::string & task) const;
102 
107  template <class T>
108  const T & getAction(const std::string & name)
109  {
110  T * p = NULL;
111  for (auto i = beginIndex(_all_ptrs); i < _all_ptrs.size(); ++i)
112  {
113  auto act = _all_ptrs[i].get();
114  if (act->name() == name)
115  {
116  p = dynamic_cast<T *>(act);
117  if (p)
118  break;
119  }
120  }
121  if (!p)
122  mooseError("Action with name being ", name, " does not exist");
123  return *p;
124  }
125 
129  template <class T>
130  std::vector<const T *> getActions()
131  {
132  // we need to create the map first to ensure that all actions in the map are unique
133  // and the actions are sorted by their names
134  std::map<std::string, const T *> actions;
135  for (auto i = beginIndex(_all_ptrs); i < _all_ptrs.size(); ++i)
136  {
137  auto act = _all_ptrs[i].get();
138  T * p = dynamic_cast<T *>(act);
139  if (p)
140  actions.insert(std::pair<std::string, const T *>(act->name(), p));
141  }
142  // construct the vector from the map entries
143  std::vector<const T *> action_vector;
144  for (auto & pair : actions)
145  action_vector.push_back(pair.second);
146  return action_vector;
147  }
148 
152  bool hasActions(const std::string & task) const;
153 
158  void executeAllActions();
159 
164  void executeActionsWithAction(const std::string & name);
165 
171  void showActions(bool state = true) { _show_actions = state; }
172 
173  void showParser(bool state = true) { _show_parser = state; }
174 
176  Syntax & syntax() { return _syntax; }
177 
178  // We are not really using the reference counting capabilities of
179  // shared pointers here, just their memory management capability.
180  // Therefore, _mesh is actually being used more like a unique_ptr in
181  // this context. Since full support for unique_ptr is not quite
182  // available yet, we've implemented it as a std::shared_ptr.
183  std::shared_ptr<MooseMesh> & mesh() { return _mesh; }
184  std::shared_ptr<MooseMesh> & displacedMesh() { return _displaced_mesh; }
185 
186  std::shared_ptr<FEProblemBase> & problemBase() { return _problem; }
187  std::shared_ptr<FEProblem> problem();
188  MooseApp & mooseApp() { return _app; }
189  const std::string & getCurrentTaskName() const { return _current_task; }
190 
191 protected:
199  void buildBuildableActions(const std::string & task);
200 
201  std::vector<std::shared_ptr<Action>> _all_ptrs;
202 
210  std::map<std::string, std::list<Action *>> _action_blocks;
212  std::map<std::string, std::vector<Action *>> _requested_action_blocks;
214  std::vector<std::string> _ordered_names;
216  std::set<std::string> _unsatisfied_dependencies;
217 
224 
225  // DEBUGGING
228 
229  // When executing the actions in the warehouse, this string will always contain
230  // the current task name
231  std::string _current_task;
232 
233  //
234  // data created by actions
235  //
236 
238  std::shared_ptr<MooseMesh> _mesh;
239 
241  std::shared_ptr<MooseMesh> _displaced_mesh;
242 
244  std::shared_ptr<FEProblemBase> _problem;
245 };
246 
247 #endif // ACTIONWAREHOUSE_H
MooseApp & mooseApp()
void checkUnsatisfiedActions() const
This method checks the actions stored in the warehouse against the list of required registered action...
std::list< Action * >::iterator ActionIterator
alias to hide implementation details
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:30
Syntax & _syntax
Reference to a "syntax" of actions.
std::shared_ptr< MooseMesh > & displacedMesh()
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void showActions(bool state=true)
This method sets a Boolean which is used to show debugging information during various warehouse opera...
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
Storage for action instances.
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
void printInputFile(std::ostream &out)
This method uses the Actions in the warehouse to reproduce the input file.
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
void executeActionsWithAction(const std::string &name)
This method executes only the actions in the warehouse that satisfy the task passed in...
std::shared_ptr< FEProblemBase > & problemBase()
std::vector< std::string > _ordered_names
The container that holds the sorted action names from the DependencyResolver.
std::shared_ptr< MooseMesh > & mesh()
void showParser(bool state=true)
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:70
An inteface for the _console for outputting to the Console object.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
std::map< std::string, std::list< Action * > > _action_blocks
Pointers to the actual parsed input file blocks.
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::vector< std::shared_ptr< Action > > _all_ptrs
std::shared_ptr< FEProblemBase > _problem
Problem class.
ActionWarehouse(MooseApp &app, Syntax &syntax, ActionFactory &factory)
std::shared_ptr< MooseMesh > _mesh
Mesh class.
bool empty() const
returns a Boolean indicating whether the warehouse is empty or not.
MooseApp & _app
The MooseApp this Warehouse is associated with.
void build()
Builds all auto-buildable tasks.
Holding syntax for parsing input files.
Definition: Syntax.h:26
const std::string & getCurrentTaskName() const
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.
std::map< std::string, std::vector< Action * > > _requested_action_blocks
Action blocks that have been requested.
const T & getAction(const std::string &name)
Retrieve an action with its name and the desired type.
std::shared_ptr< FEProblem > problem()
std::vector< const T * > getActions()
Retrieve all actions in a specific type ordered by their names.
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.
void buildBuildableActions(const std::string &task)
This method auto-builds all Actions that needs to be built and adds them to ActionWarehouse.
void printActionDependencySets() const
This method is used only during debugging when show_actions is set to true.
ActionFactory & _action_factory
The Factory that builds Actions.
std::string _current_task