https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14
17{
19 params += AdjointSolve::validParams();
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
42void
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;
50 return;
51 }
52
53 _time_step = 0;
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 {
86 }
87
88 {
89 TIME_SECTION("final", 1, "Executing Final Objects")
97 }
98
100}
const ExecFlagType EXEC_TIMESTEP_END
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_FINAL
registerMooseObject("OptimizationApp", SteadyAndAdjoint)
virtual bool solve() override
Solve the adjoint system with the following procedure:
static InputParameters validParams()
const ConsoleStream _console
virtual void preExecute()
virtual void postExecute()
std::unique_ptr< FixedPointSolve > _fixed_point_solve
virtual void advanceState()
virtual void postExecute()
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
void timestepSetup() override
void finalizeMultiApps()
virtual void execute(const ExecFlagType &exec_type)
virtual void outputStep(ExecFlagType type)
void suppressParameter(const std::string &name)
void renameParam(const std::string &old_name, const std::string &new_name, const std::string &new_docstring)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
bool isRecovering() const
MooseApp & _app
virtual bool lastSolveConverged() const override
Copy of the functionality from Steady to keep track of whether the latest solve converged.
SteadyAndAdjoint(const InputParameters &parameters)
virtual void execute() override
This call is basically a copy from Steady without the AMR loop and with a call to the adjoint solver ...
AdjointSolve _adjoint_solve
The solver which computes the adjoint system.
static InputParameters validParams()
Real & _time
Real _system_time
int & _time_step
FEProblemBase & _problem
static InputParameters validParams()