https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 "FEProblemBase.h"
16#include "Console.h"
17
18// libMesh
19#include "libmesh/mesh_tools.h"
20
22
25{
27 params.addClassDescription("Performs a complete simulation during each execution.");
28 params.addParam<bool>(
29 "keep_full_output_history",
30 false,
31 "Whether or not to keep the full output history when this multiapp has multiple entries");
32 params.addParam<bool>("ignore_solve_not_converge",
33 false,
34 "True to continue main app even if a sub app's solve does not converge.");
35 params.addParam<bool>("update_old_solution_when_keeping_solution_during_restore",
36 true,
37 "Whether to update the old solution vector (to the previous fixed point "
38 "iteration solution) when keeping the solution during restore.");
39 return params;
40}
41
43 : MultiApp(parameters),
44 _ignore_diverge(getParam<bool>("ignore_solve_not_converge")),
45 _update_old_state_when_keeping_solution_during_restore(
46 getParam<bool>("update_old_solution_when_keeping_solution_during_restore"))
47{
48 // You could end up with some dirty hidden behavior if you do this. We could remove this check,
49 // but I don't think that it's sane to do so.
51 paramError("no_restore", "The parent app is restarting, restoration cannot be disabled");
52 // Force the user to make a decision on updating or not the old state of variables
54 !isParamSetByUser("update_old_solution_when_keeping_solution_during_restore"))
55 paramError("update_old_solution_when_keeping_solution_during_restore",
56 "Due to 'keep_solution_during_restore' parameter being true, which is an "
57 "optimization for fixed point iterations, the "
58 "unrestored solution will be kept as the starting solution for the next solve "
59 "of the MultiApp. You must set this parameter to decide if this solution should "
60 "be copied as the old solution at the beginning of the next time step, "
61 "or not. If the MultiApp is running a transient, you likely want to set this to "
62 "true. If the MultiApp is a quasi-static simulation, you likely want to set "
63 "this to false. If you don't know what this error message means, please set "
64 "'keep_solution_during_restore' to false and no need to set "
65 "'update_old_solution_when_keeping_solution_during_restore'.");
66 if (isParamSetByUser("update_old_solution_when_keeping_solution_during_restore") &&
68 paramError("update_old_solution_when_keeping_solution_during_restore",
69 "Should not be set if not keeping the solution during restore "
70 "(keep_solution_during_restore=false)");
71}
72
73void
75{
76 if (!_no_restore)
77 MultiApp::restore(force);
78}
79
80void
82{
84
85 if (_has_an_app)
86 {
88
90
91 // Grab Executioner from each app
92 for (unsigned int i = 0; i < _my_num_apps; i++)
93 {
94 auto & app = _apps[i];
95 Executioner * ex = app->getExecutioner();
96
97 if (!ex)
98 mooseError("Executioner does not exist!");
99
100 if (_ignore_diverge)
101 {
102 TransientBase * tex = dynamic_cast<TransientBase *>(ex);
103 if (tex && tex->parameters().get<bool>("error_on_dtmin"))
104 mooseError("Requesting to ignore failed solutions, but 'Executioner/error_on_dtmin' is "
105 "true in sub-application. Set this parameter to false in sub-application to "
106 "avoid an error if Transient solve fails.");
107 }
108
109 ex->init();
110
112 (appProblemBase(_first_local_app + i).getMaterialPropertyStorage().hasStatefulProperties()
113#ifdef KOKKOS_ENABLED
115 .getKokkosMaterialPropertyStorage()
116 .hasStatefulProperties()
117#endif
118 ))
120 "update_old_solution_when_keeping_solution_during_restore",
121 "While we are updating old solutions using the solution from the previous fixed "
122 "point iteration, we are not updating the old stateful material properties as "
123 "well. This is not consistent. We recommend you consider using the 'no_restore' "
124 "parameter instead of 'keep_solution_during_restore', or stop using the latter.");
127 .hasSolutionState(2, Moose::SolutionIterationType::Time))
128 mooseDoOnce(paramWarning(
129 "keep_solution_during_restore",
130 "This FullSolveMultiApp simulation(s) uses older time step variable states (notably "
131 "from two time steps prior in transients). Due to 'keep_solution_during_restore' "
132 "parameter being true, which is an optimization for fixed point iterations, the "
133 "unrestored solution will be kept as the starting solution. It would normally be "
134 "copied onto the 'old' state at the beginning of the first time step. This copy can be "
135 "skipped using 'update_old_solution_when_keeping_solution_during_restore', while the "
136 "copy of the old state onto the 'older' state and the stateful material properties "
137 "state updates do not have such an option at this time. This warning relates to this "
138 "inconsistency. If you suspect this is a problem, please set "
139 "'keep_solution_during_restore' to false"));
140
141 _executioners[i] = ex;
142 }
143 }
144}
145
146bool
147FullSolveMultiApp::solveStep(Real /*dt*/, Real /*target_time*/, bool auto_advance)
148{
149 if (!auto_advance)
150 mooseError("FullSolveMultiApp is not compatible with auto_advance=false");
151
152 if (!_has_an_app)
153 return true;
154
155 TIME_SECTION(_solve_step_timer);
156
158
159 int rank;
160 int ierr;
161 ierr = MPI_Comm_rank(_communicator.get(), &rank);
162 mooseCheckMPIErr(ierr);
163
164 bool last_solve_converged = true;
165 for (unsigned int i = 0; i < _my_num_apps; i++)
166 {
167 // reset output system if desired
168 if (!getParam<bool>("keep_full_output_history"))
169 _apps[i]->getOutputWarehouse().reset();
170 // Prevent the copy of the post-FP iteration solution state onto the old vector
173
174 Executioner * ex = _executioners[i];
175 ex->execute();
176
177 last_solve_converged = last_solve_converged && ex->lastSolveConverged();
178
180 }
181
182 return last_solve_converged || _ignore_diverge;
183}
184
185void
187{
189 _apps[i]->getOutputWarehouse().getOutputs<Console>().size() > 0)
190 return;
191 else if (!_executioners[i]->lastSolveConverged())
192 _console << COLOR_RED << "Subapp " << _apps[i]->name() << " solve Did NOT Converge!"
193 << COLOR_DEFAULT << std::endl;
194 else
195 _console << COLOR_GREEN << "Subapp " << _apps[i]->name() << " solve converged!" << COLOR_DEFAULT
196 << std::endl;
197}
registerMooseObject("MooseApp", FullSolveMultiApp)
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
An output object for writing to the console (screen)
Definition Console.h:19
Executioners are objects that do the actual work of solving your problem.
Definition Executioner.h:37
virtual void execute()=0
Pure virtual execute function MUST be overridden by children classes.
virtual bool lastSolveConverged() const =0
Whether or not the last solve converged.
virtual void init()
Initialize the executioner.
Definition Executioner.h:62
bool verboseMultiApps() const
Whether or not to use verbose printing for MultiApps.
void skipNextForwardSolutionCopyToOld()
Prevents the copy of the solution vector to the old solution vector in each system.
This type of MultiApp will do a full solve when it is asked to take a step.
const bool _update_old_state_when_keeping_solution_during_restore
Switch to tell the systems or not to update the old solution using the unrestored solution (the one w...
const bool _ignore_diverge
Switch to tell executioner to keep going despite app solve not converging.
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false.
FullSolveMultiApp(const InputParameters &parameters)
virtual void restore(bool force=true) override
Restore the state of every Sub App.
static InputParameters validParams()
virtual void showStatusMessage(unsigned int i) const
This function is called after each sub-application solve and is meant to display information about th...
std::vector< Executioner * > _executioners
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
Re-solve all of the Apps.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
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.
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition MooseApp.C:1680
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
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 ...
Definition MooseBase.h:457
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
Definition MooseBase.h:205
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition MultiApp.h:140
FEProblemBase & appProblemBase(unsigned int app)
Get the FEProblemBase for the global app desired.
Definition MultiApp.C:1048
virtual void restore(bool force=true)
Restore the state of every Sub App.
Definition MultiApp.C:806
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:462
MPI_Comm & _my_comm
The MPI communicator this object is going to use.
Definition MultiApp.h:571
unsigned int _first_local_app
The number of the first app on this processor.
Definition MultiApp.h:562
bool _has_an_app
Whether or not this processor as an App at all
Definition MultiApp.h:634
const PerfID _solve_step_timer
Timers.
Definition MultiApp.h:671
const bool _no_restore
Whether or not to skip restoring completely.
Definition MultiApp.h:649
bool _keep_solution_during_restore
Flag indicates if or not restart from the latest solution.
Definition MultiApp.h:643
static InputParameters validParams()
Definition MultiApp.C:51
FEProblemBase & _fe_problem
The FEProblemBase this MultiApp is part of.
Definition MultiApp.h:523
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
Definition MultiApp.h:586
unsigned int _my_num_apps
The number of apps this object is involved in simulating.
Definition MultiApp.h:559
void paramWarning(const std::string &param, Args... args) const
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
const Parallel::Communicator & _communicator