LCOV - code coverage report
Current view: top level - src/mfem/executioners - MFEMSteady.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 68 72 94.4 %
Date: 2026-05-29 20:35:17 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        4272 : MFEMSteady::validParams()
      23             : {
      24        4272 :   InputParameters params = MFEMProblemSolve::validParams();
      25        4272 :   params += Executioner::validParams();
      26        8544 :   params.addClassDescription("Executioner for steady state MFEM problems.");
      27       12816 :   params.addParam<Real>("time", 0.0, "System time");
      28        4272 :   return params;
      29           0 : }
      30             : 
      31        1087 : MFEMSteady::MFEMSteady(const InputParameters & params)
      32             :   : Executioner(params),
      33        1087 :     _mfem_problem(dynamic_cast<MFEMProblem &>(feProblem())),
      34        1087 :     _mfem_problem_data(_mfem_problem.getProblemData()),
      35        1087 :     _mfem_problem_solve(*this, getProblemOperators()),
      36        2174 :     _system_time(getParam<Real>("time")),
      37        1087 :     _time_step(_mfem_problem.timeStep()),
      38        2174 :     _time([this]() -> Real & { return this->_mfem_problem.time() = this->_system_time; }()),
      39        1087 :     _last_solve_converged(false)
      40             : {
      41             :   // If no ProblemOperators have been added by the user, add a default
      42        1087 :   if (getProblemOperators().empty())
      43             :   {
      44        1087 :     if (_mfem_problem.getNumericType() == MFEMProblem::NumericType::REAL)
      45             :     {
      46        1025 :       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         999 :         _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::EquationSystem>();
      56             :         auto problem_operator =
      57         999 :             std::make_shared<Moose::MFEM::EquationSystemProblemOperator>(_mfem_problem);
      58         999 :         addProblemOperator(std::move(problem_operator));
      59         999 :       }
      60             :     }
      61          62 :     else if (_mfem_problem.getNumericType() == MFEMProblem::NumericType::COMPLEX)
      62             :     {
      63          62 :       _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::ComplexEquationSystem>();
      64             :       auto problem_operator =
      65          62 :           std::make_shared<Moose::MFEM::ComplexEquationSystemProblemOperator>(_mfem_problem);
      66          62 :       addProblemOperator(std::move(problem_operator));
      67          62 :     }
      68             :     else
      69           0 :       mooseError("Unknown numeric type. "
      70             :                  "Please set the Problem numeric type to either 'real' or 'complex'.");
      71             :   }
      72        1087 : }
      73             : 
      74             : void
      75        1087 : MFEMSteady::init()
      76             : {
      77        1087 :   _mfem_problem.execute(EXEC_PRE_MULTIAPP_SETUP);
      78        1087 :   _mfem_problem.initialSetup();
      79             : 
      80             :   // Set up initial conditions
      81        1087 :   _mfem_problem_data.eqn_system->Init(
      82        1087 :       _mfem_problem_data.gridfunctions,
      83        1087 :       _mfem_problem_data.cmplx_gridfunctions,
      84        3261 :       getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>());
      85             : 
      86        2174 :   for (const auto & problem_operator : getProblemOperators())
      87             :   {
      88        1087 :     problem_operator->SetGridFunctions();
      89        1087 :     problem_operator->Init(_mfem_problem_data.f);
      90             :   }
      91        1087 : }
      92             : 
      93             : void
      94        1087 : MFEMSteady::execute()
      95             : {
      96        1087 :   if (_app.isRecovering())
      97             :   {
      98           0 :     _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
      99           0 :     return;
     100             :   }
     101             : 
     102        1087 :   _time_step = 0;
     103        1087 :   _time = _time_step;
     104        1087 :   _mfem_problem.outputStep(EXEC_INITIAL);
     105        1087 :   _time = _system_time;
     106             : 
     107        1087 :   preExecute();
     108             : 
     109        1087 :   _mfem_problem.advanceState();
     110             : 
     111             :   // first step in any steady state solve is always 1 (preserving backwards compatibility)
     112        1087 :   _time_step = 1;
     113        1087 :   _mfem_problem.timestepSetup();
     114             : 
     115        1087 :   _last_solve_converged = _mfem_problem_solve.solve();
     116             : 
     117        1087 :   _mfem_problem.computeIndicators();
     118        1087 :   _mfem_problem.computeMarkers();
     119             : 
     120             :   // need to keep _time in sync with _time_step to get correct output
     121        1087 :   _time = _time_step;
     122        1087 :   _mfem_problem.outputStep(EXEC_TIMESTEP_END);
     123        1087 :   _time = _system_time;
     124             : 
     125             :   {
     126        5435 :     TIME_SECTION("final", 1, "Executing Final Objects")
     127        1087 :     _mfem_problem.execMultiApps(EXEC_FINAL);
     128        1087 :     _mfem_problem.finalizeMultiApps();
     129        1087 :     _mfem_problem.postExecute();
     130        1087 :     _mfem_problem.execute(EXEC_FINAL);
     131        1087 :     _time = _time_step;
     132        1087 :     _mfem_problem.outputStep(EXEC_FINAL);
     133        1087 :     _time = _system_time;
     134        1087 :   }
     135             : 
     136        1087 :   postExecute();
     137             : }
     138             : 
     139             : #endif

Generated by: LCOV version 1.14