LCOV - code coverage report
Current view: top level - src/executioners - SteadyAndAdjoint.C (source / functions) Hit Total Coverage
Test: idaholab/moose optimization: #31405 (292dce) with base fef103 Lines: 42 46 91.3 %
Date: 2025-09-04 07:54:57 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      15             : InputParameters
      16         506 : SteadyAndAdjoint::validParams()
      17             : {
      18         506 :   InputParameters params = Steady::validParams();
      19         506 :   params += AdjointSolve::validParams();
      20         506 :   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        1012 :   params.set<MooseEnum>("solve_type") = "newton";
      25         506 :   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        1012 :   params.renameParam("system_names", "forward_system", "");
      33             : 
      34         506 :   return params;
      35           0 : }
      36             : 
      37         253 : SteadyAndAdjoint::SteadyAndAdjoint(const InputParameters & parameters)
      38         253 :   : Steady(parameters), _adjoint_solve(*this)
      39             : {
      40         253 : }
      41             : 
      42             : void
      43        2479 : SteadyAndAdjoint::execute()
      44             : {
      45             :   // This is basically copied from Steady (without AMR)
      46        2479 :   if (_app.isRecovering())
      47             :   {
      48          25 :     _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
      49          25 :     _last_solve_converged = true;
      50          25 :     return;
      51             :   }
      52             : 
      53        2454 :   _time_step = 0;
      54        2454 :   _time = _time_step;
      55        2454 :   _problem.outputStep(EXEC_INITIAL);
      56        2454 :   _time = _system_time;
      57             : 
      58        2454 :   preExecute();
      59             : 
      60        2454 :   _problem.advanceState();
      61        2454 :   _time_step = 1;
      62        2454 :   _problem.timestepSetup();
      63             : 
      64             :   // Solving forward and adjoint problem here (only difference from Steady)
      65        2454 :   _last_solve_converged = _fixed_point_solve->solve();
      66             : 
      67        2454 :   if (!lastSolveConverged())
      68           0 :     _console << "Forward solve did not converge." << std::endl;
      69             : 
      70        2454 :   _console << "Starting Adjoint solve" << std::endl;
      71             : 
      72             :   // this is to check that they are both true
      73        2454 :   bool adjoint_solve_converged = _adjoint_solve.solve();
      74        2452 :   _last_solve_converged &= adjoint_solve_converged;
      75             : 
      76        2452 :   if (!lastSolveConverged())
      77             :   {
      78           0 :     if (!adjoint_solve_converged)
      79           0 :       _console << "Adjoint solve did not converge." << std::endl;
      80             :   }
      81             :   else
      82             :   {
      83        2452 :     _time = _time_step;
      84        2452 :     _problem.outputStep(EXEC_TIMESTEP_END);
      85        2452 :     _time = _system_time;
      86             :   }
      87             : 
      88             :   {
      89        4904 :     TIME_SECTION("final", 1, "Executing Final Objects")
      90        2452 :     _problem.execMultiApps(EXEC_FINAL);
      91        2452 :     _problem.finalizeMultiApps();
      92        2452 :     _problem.postExecute();
      93        2452 :     _problem.execute(EXEC_FINAL);
      94        2452 :     _time = _time_step;
      95        2452 :     _problem.outputStep(EXEC_FINAL);
      96        2452 :     _time = _system_time;
      97             :   }
      98             : 
      99        2452 :   postExecute();
     100             : }

Generated by: LCOV version 1.14