www.mooseframework.org
FullSolveMultiApp.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "Transient.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  "no_backup_and_restore",
28  false,
29  "True to turn off backup/restore for this multiapp. This is useful when doing steady-state "
30  "Picard iterations where we want to use the solution of previous Picard iteration as the "
31  "initial guess of the current Picard iteration");
32  params.addParam<bool>(
33  "keep_full_output_history",
34  false,
35  "Whether or not to keep the full output history when this multiapp has multiple entries");
36  params.addParam<bool>("ignore_solve_not_converge",
37  false,
38  "True to continue main app even if a sub app's solve does not converge.");
39  return params;
40 }
41 
43  : MultiApp(parameters), _ignore_diverge(getParam<bool>("ignore_solve_not_converge"))
44 {
45 }
46 
47 void
49 {
50  if (getParam<bool>("no_backup_and_restore"))
51  return;
52  else
54 }
55 
56 void
58 {
59  if (getParam<bool>("no_backup_and_restore"))
60  return;
61  else
63 }
64 
65 void
67 {
69 
70  if (_has_an_app)
71  {
73 
75 
76  // Grab Executioner from each app
77  for (unsigned int i = 0; i < _my_num_apps; i++)
78  {
79  auto & app = _apps[i];
80  Executioner * ex = app->getExecutioner();
81 
82  if (!ex)
83  mooseError("Executioner does not exist!");
84 
85  if (_ignore_diverge)
86  {
87  Transient * tex = dynamic_cast<Transient *>(ex);
88  if (tex && tex->parameters().get<bool>("error_on_dtmin"))
89  mooseError("Requesting to ignore failed solutions, but 'Executioner/error_on_dtmin' is "
90  "true in sub-application. Set this parameter to false in sub-application to "
91  "avoid an error if Transient solve fails.");
92  }
93 
94  ex->init();
95 
96  _executioners[i] = ex;
97  }
98  }
99 }
100 
101 bool
102 FullSolveMultiApp::solveStep(Real /*dt*/, Real /*target_time*/, bool auto_advance)
103 {
104  if (!auto_advance)
105  mooseError("FullSolveMultiApp is not compatible with auto_advance=false");
106 
107  if (!_has_an_app)
108  return true;
109 
110  TIME_SECTION(_solve_step_timer);
111 
113 
114  int rank;
115  int ierr;
116  ierr = MPI_Comm_rank(_communicator.get(), &rank);
117  mooseCheckMPIErr(ierr);
118 
119  bool last_solve_converged = true;
120  for (unsigned int i = 0; i < _my_num_apps; i++)
121  {
122  // reset output system if desired
123  if (!getParam<bool>("keep_full_output_history"))
124  _apps[i]->getOutputWarehouse().reset();
125 
126  Executioner * ex = _executioners[i];
127  ex->execute();
128 
129  last_solve_converged = last_solve_converged && ex->lastSolveConverged();
130 
132  }
133 
134  return last_solve_converged || _ignore_diverge;
135 }
136 
137 void
139 {
140  if (!_fe_problem.verboseMultiApps() &&
141  _apps[i]->getOutputWarehouse().getOutputs<Console>().size() > 0)
142  return;
143  else if (!_executioners[i]->lastSolveConverged())
144  _console << COLOR_RED << "Subapp " << _apps[i]->name() << " solve Did NOT Converge!"
145  << COLOR_DEFAULT << std::endl;
146  else
147  _console << COLOR_GREEN << "Subapp " << _apps[i]->name() << " solve converged!" << COLOR_DEFAULT
148  << std::endl;
149 }
Transient executioners usually loop through a number of timesteps...
Definition: Transient.h:26
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:737
virtual void backup()
Save off the state of every Sub App.
Definition: MultiApp.C:722
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:613
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
Definition: MultiApp.h:538
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:479
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
ierr
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
virtual void backup() override
Save off the state of every Sub App.
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
static InputParameters validParams()
unsigned int _my_num_apps
The number of apps this object is involved in simulating.
Definition: MultiApp.h:511
bool _has_an_app
Whether or not this processor as an App at all
Definition: MultiApp.h:586
registerMooseObject("MooseApp", FullSolveMultiApp)
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:413
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 option 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.
MPI_Comm & _my_comm
The MPI communicator this object is going to use.
Definition: MultiApp.h:523
This type of MultiApp will do a full solve when it is asked to take a step.