www.mooseframework.org
MultiApp.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 #ifndef MULTIAPP_H
15 #define MULTIAPP_H
16 
17 #include "MooseObject.h"
18 #include "SetupInterface.h"
19 #include "Restartable.h"
20 
21 class MultiApp;
22 class UserObject;
23 class FEProblemBase;
24 class FEProblem;
25 class Executioner;
26 class MooseApp;
27 class Backup;
28 
29 // libMesh forward declarations
30 namespace libMesh
31 {
32 class BoundingBox;
33 namespace MeshTools
34 {
35 class BoundingBox;
36 }
37 template <typename T>
38 class NumericVector;
39 }
40 
41 template <>
43 
47 class SubAppBackups : public std::vector<std::shared_ptr<Backup>>
48 {
49 };
50 
59 class MultiApp : public MooseObject, public SetupInterface, public Restartable
60 {
61 public:
62  MultiApp(const InputParameters & parameters);
63 
64  virtual void preExecute() {}
65 
66  virtual void postExecute();
67 
68  virtual void initialSetup() override;
69 
75  virtual bool isSolved() const { return false; }
76 
81  virtual void preTransfer(Real dt, Real target_time);
82 
96  virtual bool solveStep(Real dt, Real target_time, bool auto_advance = true) = 0;
97 
104  virtual void advanceStep() = 0;
105 
111  virtual void backup();
112 
118  virtual void restore();
119 
124  virtual bool needsRestoration() { return true; }
125 
130  virtual Executioner * getExecutioner(unsigned int app);
131 
141  virtual BoundingBox getBoundingBox(unsigned int app);
142 
146  FEProblemBase & problemBase() { return _fe_problem; }
147 
152  FEProblemBase & appProblemBase(unsigned int app);
153 
158  FEProblem & appProblem(unsigned int app);
159 
165  const UserObject & appUserObjectBase(unsigned int app, const std::string & name);
166 
172  Real appPostprocessorValue(unsigned int app, const std::string & name);
173 
182  virtual NumericVector<Number> & appTransferVector(unsigned int app, std::string var_name);
183 
187  unsigned int numGlobalApps() { return _total_num_apps; }
188 
192  unsigned int numLocalApps() { return _apps.size(); }
193 
197  unsigned int firstLocalApp() { return _first_local_app; }
198 
202  bool hasApp() { return _has_an_app; }
203 
209  bool hasLocalApp(unsigned int global_app);
210 
215  MooseApp * localApp(unsigned int local_app);
216 
222  Point position(unsigned int app) { return _positions[app]; }
223 
236  virtual void resetApp(unsigned int global_app, Real time = 0.0);
237 
244  virtual void moveApp(unsigned int global_app, Point p);
245 
250  virtual void parentOutputPositionChanged();
251 
256  MPI_Comm & comm() { return _my_comm; }
257 
262  bool isRootProcessor() { return _my_rank == 0; }
263 
264 protected:
268  virtual void fillPositions();
269 
276  void createApp(unsigned int i, Real start_time);
277 
283  void buildComm();
284 
292  unsigned int globalAppToLocal(unsigned int global_app);
293 
295  virtual void preRunInputFile();
296 
302  void init(unsigned int num);
303 
306 
308  std::string _app_type;
309 
311  std::vector<Point> _positions;
312 
314  const bool _use_positions;
315 
317  std::vector<FileName> _input_files;
318 
320  std::string _output_base;
321 
323  unsigned int _total_num_apps;
324 
326  unsigned int _my_num_apps;
327 
329  unsigned int _first_local_app;
330 
332  MPI_Comm _orig_comm;
333 
335  MPI_Comm _my_comm;
336 
339 
342 
344  std::string _node_name;
345 
347  int _my_rank;
348 
350  std::vector<std::shared_ptr<MooseApp>> _apps;
351 
354 
356  unsigned int _max_procs_per_app;
357 
360 
363 
365  std::vector<unsigned int> _reset_apps;
366 
369 
372 
374  std::vector<unsigned int> _move_apps;
375 
377  std::vector<Point> _move_positions;
378 
381 
384 
387 };
388 
389 template <>
390 inline void
391 dataStore(std::ostream & stream, SubAppBackups & backups, void * context)
392 {
393  MultiApp * multi_app = static_cast<MultiApp *>(context);
394 
395  multi_app->backup();
396 
397  if (!multi_app)
398  mooseError("Error storing std::vector<Backup*>");
399 
400  for (unsigned int i = 0; i < backups.size(); i++)
401  dataStore(stream, backups[i], context);
402 }
403 
404 template <>
405 inline void
406 dataLoad(std::istream & stream, SubAppBackups & backups, void * context)
407 {
408  MultiApp * multi_app = static_cast<MultiApp *>(context);
409 
410  if (!multi_app)
411  mooseError("Error loading std::vector<Backup*>");
412 
413  for (unsigned int i = 0; i < backups.size(); i++)
414  dataLoad(stream, backups[i], context);
415 
416  multi_app->restore();
417 }
418 
419 #endif // MULTIAPP_H
Point position(unsigned int app)
The physical position of a global App number.
Definition: MultiApp.h:222
std::vector< unsigned int > _reset_apps
The apps to be reset.
Definition: MultiApp.h:365
virtual void restore()
Restore the state of every Sub App.
Definition: MultiApp.C:346
A class for creating restricted objects.
Definition: Restartable.h:31
unsigned int _max_procs_per_app
Maximum number of processors to give to each app.
Definition: MultiApp.h:356
virtual void backup()
Save off the state of every Sub App.
Definition: MultiApp.C:339
const bool _use_positions
Toggle use of "positions".
Definition: MultiApp.h:314
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:30
Real _move_time
The time at which to move apps.
Definition: MultiApp.h:371
unsigned int numLocalApps()
Definition: MultiApp.h:192
int _orig_rank
The mpi "rank" of this processor in the original communicator.
Definition: MultiApp.h:341
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
Definition: MultiApp.h:350
std::vector< Point > _move_positions
The new positions for the apps to be moved.
Definition: MultiApp.h:377
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void dataLoad(std::istream &stream, SubAppBackups &backups, void *context)
Definition: MultiApp.h:406
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Real _inflation
Relative bounding box inflation.
Definition: MultiApp.h:353
FEProblemBase & _fe_problem
The FEProblemBase this MultiApp is part of.
Definition: MultiApp.h:305
bool _reset_happened
Whether or not apps have been reset.
Definition: MultiApp.h:368
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
int _orig_num_procs
The number of processors in the original comm.
Definition: MultiApp.h:338
MPI_Comm _orig_comm
The comm that was passed to us specifying our pool of processors.
Definition: MultiApp.h:332
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
bool _move_happened
Whether or not the move has happened.
Definition: MultiApp.h:380
Helper class for holding Sub-app backups.
Definition: MultiApp.h:47
InputParameters validParams< MultiApp >()
Definition: MultiApp.C:46
bool hasApp()
Whether or not this MultiApp has an app on this processor.
Definition: MultiApp.h:202
Real _reset_time
The time at which to reset apps.
Definition: MultiApp.h:362
std::string _output_base
The output file basename for each multiapp.
Definition: MultiApp.h:320
std::string _app_type
The type of application to build.
Definition: MultiApp.h:308
bool isRootProcessor()
Whether or not this processor is the "root" processor for the sub communicator.
Definition: MultiApp.h:262
std::vector< unsigned int > _move_apps
The apps to be moved.
Definition: MultiApp.h:374
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:41
unsigned int _total_num_apps
The total number of apps to simulate.
Definition: MultiApp.h:323
unsigned int numGlobalApps()
Definition: MultiApp.h:187
unsigned int _my_num_apps
The number of apps this object is involved in simulating.
Definition: MultiApp.h:326
std::string _node_name
Node Name.
Definition: MultiApp.h:344
bool _has_an_app
Whether or not this processor as an App at all
Definition: MultiApp.h:383
SubAppBackups & _backups
Backups for each local App.
Definition: MultiApp.h:386
unsigned int _first_local_app
The number of the first app on this processor.
Definition: MultiApp.h:329
Helper class to hold streams for Backup and Restore operations.
Definition: Backup.h:25
virtual void preExecute()
Definition: MultiApp.h:64
unsigned int firstLocalApp()
Definition: MultiApp.h:197
virtual bool needsRestoration()
Whether or not this MultiApp should be restored at the beginning of each Picard iteration.
Definition: MultiApp.h:124
MPI_Comm & comm()
Get the MPI communicator this MultiApp is operating on.
Definition: MultiApp.h:256
virtual bool isSolved() const
Method that reports whether the application has been fully solved or not.
Definition: MultiApp.h:75
bool _output_in_position
Whether or not to move the output of the MultiApp into position.
Definition: MultiApp.h:359
std::vector< Point > _positions
The positions of all of the apps.
Definition: MultiApp.h:311
int _my_rank
The mpi "rank" of this processor in the sub communicator.
Definition: MultiApp.h:347
std::vector< FileName > _input_files
The input file for each app&#39;s simulation.
Definition: MultiApp.h:317
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition: MultiApp.h:59
FEProblemBase & problemBase()
Get the FEProblemBase this MultiApp is part of.
Definition: MultiApp.h:146
MPI_Comm _my_comm
The MPI communicator this object is going to use.
Definition: MultiApp.h:335
Base class for user-specific data.
Definition: UserObject.h:42
void dataStore(std::ostream &stream, SubAppBackups &backups, void *context)
Definition: MultiApp.h:391