https://mooseframework.inl.gov
FullSolveMultiApp.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "FullSolveMultiApp.h"
12 #include "Executioner.h"
13 #include "TransientBase.h"
14 #include "Console.h"
15 
16 // libMesh
17 #include "libmesh/mesh_tools.h"
18 
20 
23 {
25  params.addClassDescription("Performs a complete simulation during each execution.");
26  params.addParam<bool>(
27  "keep_full_output_history",
28  false,
29  "Whether or not to keep the full output history when this multiapp has multiple entries");
30  params.addParam<bool>("ignore_solve_not_converge",
31  false,
32  "True to continue main app even if a sub app's solve does not converge.");
33  return params;
34 }
35 
37  : MultiApp(parameters), _ignore_diverge(getParam<bool>("ignore_solve_not_converge"))
38 {
39  // You could end up with some dirty hidden behavior if you do this. We could remove this check,
40  // but I don't think that it's sane to do so.
42  paramError("no_restore",
43  "The parent app is restarting or recovering, restoration cannot be disabled");
44 }
45 
46 void
48 {
49  if (!_no_restore)
50  MultiApp::restore(force);
51 }
52 
53 void
55 {
57 
58  if (_has_an_app)
59  {
61 
63 
64  // Grab Executioner from each app
65  for (unsigned int i = 0; i < _my_num_apps; i++)
66  {
67  auto & app = _apps[i];
68  Executioner * ex = app->getExecutioner();
69 
70  if (!ex)
71  mooseError("Executioner does not exist!");
72 
73  if (_ignore_diverge)
74  {
75  TransientBase * tex = dynamic_cast<TransientBase *>(ex);
76  if (tex && tex->parameters().get<bool>("error_on_dtmin"))
77  mooseError("Requesting to ignore failed solutions, but 'Executioner/error_on_dtmin' is "
78  "true in sub-application. Set this parameter to false in sub-application to "
79  "avoid an error if Transient solve fails.");
80  }
81 
82  ex->init();
83 
84  _executioners[i] = ex;
85  }
86  }
87 }
88 
89 bool
90 FullSolveMultiApp::solveStep(Real /*dt*/, Real /*target_time*/, bool auto_advance)
91 {
92  if (!auto_advance)
93  mooseError("FullSolveMultiApp is not compatible with auto_advance=false");
94 
95  if (!_has_an_app)
96  return true;
97 
98  TIME_SECTION(_solve_step_timer);
99 
101 
102  int rank;
103  int ierr;
104  ierr = MPI_Comm_rank(_communicator.get(), &rank);
105  mooseCheckMPIErr(ierr);
106 
107  bool last_solve_converged = true;
108  for (unsigned int i = 0; i < _my_num_apps; i++)
109  {
110  // reset output system if desired
111  if (!getParam<bool>("keep_full_output_history"))
112  _apps[i]->getOutputWarehouse().reset();
113 
114  Executioner * ex = _executioners[i];
115  ex->execute();
116 
117  last_solve_converged = last_solve_converged && ex->lastSolveConverged();
118 
120  }
121 
122  return last_solve_converged || _ignore_diverge;
123 }
124 
125 void
127 {
128  if (!_fe_problem.verboseMultiApps() &&
129  _apps[i]->getOutputWarehouse().getOutputs<Console>().size() > 0)
130  return;
131  else if (!_executioners[i]->lastSolveConverged())
132  _console << COLOR_RED << "Subapp " << _apps[i]->name() << " solve Did NOT Converge!"
133  << COLOR_DEFAULT << std::endl;
134  else
135  _console << COLOR_GREEN << "Subapp " << _apps[i]->name() << " solve converged!" << COLOR_DEFAULT
136  << std::endl;
137 }
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false...
virtual void restore(bool force=true)
Restore the state of every Sub App.
Definition: MultiApp.C:762
bool verboseMultiApps() const
Whether or not to use verbose printing for MultiApps.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
virtual void init()
Initialize the executioner.
Definition: Executioner.h:62
An output object for writing to the console (screen)
Definition: Console.h:18
const PerfID _solve_step_timer
Timers.
Definition: MultiApp.h:625
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
Definition: MultiApp.h:541
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & _communicator
FEProblemBase & _fe_problem
The FEProblemBase this MultiApp is part of.
Definition: MultiApp.h:482
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:1801
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
const bool _ignore_diverge
Switch to tell executioner to keep going despite app solve not converging.
virtual void execute()=0
Pure virtual execute function MUST be overridden by children classes.
FullSolveMultiApp(const InputParameters &parameters)
std::vector< Executioner * > _executioners
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
Definition: TransientBase.h:26
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
static InputParameters validParams()
unsigned int _my_num_apps
The number of apps this object is involved in simulating.
Definition: MultiApp.h:514
bool _has_an_app
Whether or not this processor as an App at all
Definition: MultiApp.h:589
registerMooseObject("MooseApp", FullSolveMultiApp)
const bool _no_restore
Whether or not to skip restoring completely.
Definition: MultiApp.h:604
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false...
Definition: MultiApp.C:438
virtual void restore(bool force=true) override
Restore the state of every Sub App.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
virtual void showStatusMessage(unsigned int i) const
This function is called after each sub-application solve and is meant to display information about th...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const InputParameters & parameters() const
Get the parameters of the object.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual bool lastSolveConverged() const =0
Whether or not the last solve converged.
static InputParameters validParams()
Definition: MultiApp.C:50
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition: MultiApp.h:112
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
Re-solve all of the Apps.
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:1795
MPI_Comm & _my_comm
The MPI communicator this object is going to use.
Definition: MultiApp.h:526
This type of MultiApp will do a full solve when it is asked to take a step.