LCOV - code coverage report
Current view: top level - src/mfem/executioners - MFEMSteady.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33187 (5aa0b2) with base d7c4bd Lines: 77 83 92.8 %
Date: 2026-06-30 12:18:20 Functions: 5 5 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             : #ifdef MOOSE_MFEM_ENABLED
      11             : 
      12             : #include "MFEMSteady.h"
      13             : #include "MFEMProblem.h"
      14             : #include "MFEMEigenproblem.h"
      15             : #include "EigenproblemEquationSystem.h"
      16             : #include "EquationSystemProblemOperator.h"
      17             : #include "EigenproblemESProblemOperator.h"
      18             : 
      19             : registerMooseObject("MooseApp", MFEMSteady);
      20             : 
      21             : InputParameters
      22        4382 : MFEMSteady::validParams()
      23             : {
      24        4382 :   InputParameters params = MFEMProblemSolve::validParams();
      25        4382 :   params += Executioner::validParams();
      26        8764 :   params.addClassDescription("Executioner for steady state MFEM problems.");
      27       13146 :   params.addParam<Real>("time", 0.0, "System time");
      28        4382 :   return params;
      29           0 : }
      30             : 
      31        1142 : MFEMSteady::MFEMSteady(const InputParameters & params)
      32             :   : Executioner(params),
      33        1142 :     _mfem_problem(dynamic_cast<MFEMProblem &>(feProblem())),
      34        1142 :     _mfem_problem_data(_mfem_problem.getProblemData()),
      35        1142 :     _mfem_problem_solve(*this, getProblemOperators()),
      36        2284 :     _system_time(getParam<Real>("time")),
      37        1142 :     _time_step(_mfem_problem.timeStep()),
      38        2284 :     _time([this]() -> Real & { return this->_mfem_problem.time() = this->_system_time; }()),
      39        1142 :     _last_solve_converged(false)
      40             : {
      41             :   // If no ProblemOperators have been added by the user, add a default
      42        1142 :   if (getProblemOperators().empty())
      43             :   {
      44        1142 :     if (_mfem_problem.getNumericType() == MFEMProblem::NumericType::REAL)
      45             :     {
      46        1079 :       if (dynamic_cast<MFEMEigenproblem *>(&_mfem_problem))
      47             :       {
      48          26 :         _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::EigenproblemEquationSystem>();
      49             :         auto problem_operator =
      50          26 :             std::make_shared<Moose::MFEM::EigenproblemESProblemOperator>(_mfem_problem);
      51          26 :         addProblemOperator(std::move(problem_operator));
      52          26 :       }
      53             :       else
      54             :       {
      55        1053 :         _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::EquationSystem>();
      56             :         auto problem_operator =
      57        1053 :             std::make_shared<Moose::MFEM::EquationSystemProblemOperator>(_mfem_problem);
      58        1053 :         addProblemOperator(std::move(problem_operator));
      59        1053 :       }
      60             :     }
      61          63 :     else if (_mfem_problem.getNumericType() == MFEMProblem::NumericType::COMPLEX)
      62             :     {
      63          63 :       _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::ComplexEquationSystem>();
      64             :       auto problem_operator =
      65          63 :           std::make_shared<Moose::MFEM::ComplexEquationSystemProblemOperator>(_mfem_problem);
      66          63 :       addProblemOperator(std::move(problem_operator));
      67          63 :     }
      68             :     else
      69           0 :       mooseError("Unknown numeric type. "
      70             :                  "Please set the Problem numeric type to either 'real' or 'complex'.");
      71             :   }
      72        1142 : }
      73             : 
      74             : void
      75        1142 : MFEMSteady::init()
      76             : {
      77        1142 :   _mfem_problem.execute(EXEC_PRE_MULTIAPP_SETUP);
      78        1142 :   _mfem_problem.initialSetup();
      79             : 
      80        1142 :   if (_mfem_problem_data.nonlinear_solver)
      81          18 :     _mfem_problem_data.eqn_system->SetSolverRequiresGradient(
      82          18 :         _mfem_problem_data.nonlinear_solver->RequiresGradient());
      83             : 
      84             :   // Set up initial conditions
      85        1142 :   _mfem_problem_data.eqn_system->Init(
      86        1142 :       _mfem_problem_data.gridfunctions,
      87        1142 :       _mfem_problem_data.cmplx_gridfunctions,
      88        4568 :       getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>());
      89             : 
      90        2284 :   for (const auto & problem_operator : getProblemOperators())
      91             :   {
      92        1142 :     problem_operator->SetGridFunctions();
      93        1142 :     problem_operator->Init(_mfem_problem_data.f);
      94             :   }
      95        1142 : }
      96             : 
      97             : void
      98        1142 : MFEMSteady::execute()
      99             : {
     100        1142 :   if (_app.isRecovering())
     101             :   {
     102           0 :     _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
     103           0 :     return;
     104             :   }
     105             : 
     106        1142 :   _time_step = 0;
     107        1142 :   _time = _time_step;
     108        1142 :   _mfem_problem.outputStep(EXEC_INITIAL);
     109        1142 :   _time = _system_time;
     110             : 
     111        1142 :   preExecute();
     112             : 
     113        1142 :   _mfem_problem.advanceState();
     114             : 
     115             :   // first step in any steady state solve is always 1 (preserving backwards compatibility)
     116        1142 :   _time_step = 1;
     117        1142 :   _mfem_problem.timestepSetup();
     118        1142 :   _mfem_problem.execTransfers(EXEC_TIMESTEP_BEGIN);
     119        1142 :   if (!_mfem_problem.execMultiApps(EXEC_TIMESTEP_BEGIN, true))
     120             :   {
     121           0 :     _last_solve_converged = false;
     122           0 :     return;
     123             :   }
     124        1142 :   _mfem_problem.execute(EXEC_TIMESTEP_BEGIN);
     125             : 
     126        1142 :   _last_solve_converged = _mfem_problem_solve.solve();
     127             : 
     128        1142 :   _mfem_problem.computeIndicators();
     129        1142 :   _mfem_problem.computeMarkers();
     130             : 
     131             :   // need to keep _time in sync with _time_step to get correct output
     132        1142 :   _time = _time_step;
     133        1142 :   _mfem_problem.execute(EXEC_TIMESTEP_END);
     134        1142 :   _mfem_problem.execTransfers(EXEC_TIMESTEP_END);
     135        1142 :   _mfem_problem.execMultiApps(EXEC_TIMESTEP_END, true);
     136        1142 :   _mfem_problem.outputStep(EXEC_TIMESTEP_END);
     137        1142 :   _time = _system_time;
     138             : 
     139             :   {
     140        5710 :     TIME_SECTION("final", 1, "Executing Final Objects")
     141        1142 :     _mfem_problem.execMultiApps(EXEC_FINAL);
     142        1142 :     _mfem_problem.finalizeMultiApps();
     143        1142 :     _mfem_problem.postExecute();
     144        1142 :     _mfem_problem.execute(EXEC_FINAL);
     145        1142 :     _time = _time_step;
     146        1142 :     _mfem_problem.outputStep(EXEC_FINAL);
     147        1142 :     _time = _system_time;
     148        1142 :   }
     149             : 
     150        1142 :   postExecute();
     151             : }
     152             : 
     153             : #endif

Generated by: LCOV version 1.14