https://mooseframework.inl.gov
SteadyAndAdjoint.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 "SteadyAndAdjoint.h"
11 #include "FEProblemBase.h"
12 
13 registerMooseObject("OptimizationApp", SteadyAndAdjoint);
14 
17 {
19  params += AdjointSolve::validParams();
20  params.addClassDescription(
21  "Executioner for evaluating steady-state simulations and their adjoint.");
22 
23  // We need the full matrix for the adjoint solve, so set this to NEWTON
24  params.set<MooseEnum>("solve_type") = "newton";
25  params.suppressParameter<MooseEnum>("solve_type");
26 
27  // The adjoint system (second one) is solved by _adjoint_solve
28  // This is a parameter of the MultiSystemSolveObject, which we set from here, the executioner.
29  // We seek to prevent the MultiSystemSolveObject from solving both systems
30  // This is abusing input parameters, but SolveObjects do not have their own syntax
31  // and we need to send this parameter from the executioner to the default nested SolveObject
32  params.renameParam("system_names", "forward_system", "");
33 
34  return params;
35 }
36 
38  : Steady(parameters), _adjoint_solve(*this)
39 {
40 }
41 
42 void
44 {
45  // This is basically copied from Steady (without AMR)
46  if (_app.isRecovering())
47  {
48  _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
49  _last_solve_converged = true;
50  return;
51  }
52 
53  _time_step = 0;
54  _time = _time_step;
57 
58  preExecute();
59 
61  _time_step = 1;
63 
64  // Solving forward and adjoint problem here (only difference from Steady)
66 
67  if (!lastSolveConverged())
68  _console << "Forward solve did not converge." << std::endl;
69 
70  _console << "Starting Adjoint solve" << std::endl;
71 
72  // this is to check that they are both true
73  bool adjoint_solve_converged = _adjoint_solve.solve();
74  _last_solve_converged &= adjoint_solve_converged;
75 
76  if (!lastSolveConverged())
77  {
78  if (!adjoint_solve_converged)
79  _console << "Adjoint solve did not converge." << std::endl;
80  }
81  else
82  {
83  _time = _time_step;
86  }
87 
88  {
89  TIME_SECTION("final", 1, "Executing Final Objects")
94  _time = _time_step;
97  }
98 
99  postExecute();
100 }
void finalizeMultiApps()
void renameParam(const std::string &old_name, const std::string &new_name, const std::string &new_docstring)
virtual void preExecute()
void timestepSetup() override
static InputParameters validParams()
Definition: AdjointSolve.C:27
virtual void postExecute()
Real & _time
T & set(const std::string &name, bool quiet_mode=false)
AdjointSolve _adjoint_solve
The solver which computes the adjoint system.
int & _time_step
virtual bool lastSolveConverged() const override
Copy of the functionality from Steady to keep track of whether the latest solve converged.
const ExecFlagType EXEC_TIMESTEP_END
void suppressParameter(const std::string &name)
virtual void advanceState()
Real _system_time
virtual void execute(const ExecFlagType &exec_type)
virtual void postExecute()
SteadyAndAdjoint(const InputParameters &parameters)
registerMooseObject("OptimizationApp", SteadyAndAdjoint)
virtual bool solve() override
Solve the adjoint system with the following procedure:
Definition: AdjointSolve.C:79
FEProblemBase & _problem
MooseApp & _app
static InputParameters validParams()
virtual void execute() override
This call is basically a copy from Steady without the AMR loop and with a call to the adjoint solver ...
void addClassDescription(const std::string &doc_string)
const ConsoleStream _console
static InputParameters validParams()
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
bool isRecovering() const
const ExecFlagType EXEC_FINAL
std::unique_ptr< FixedPointSolve > _fixed_point_solve
virtual void outputStep(ExecFlagType type)
const ExecFlagType EXEC_INITIAL