LCOV - code coverage report
Current view: top level - src/mfem/executioners - MFEMTransient.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 67 68 98.5 %
Date: 2025-07-17 01:28:37 Functions: 6 6 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 MFEM_ENABLED
      11             : 
      12             : #include "MFEMTransient.h"
      13             : #include "MFEMProblem.h"
      14             : #include "TimeDomainEquationSystemProblemOperator.h"
      15             : 
      16             : registerMooseObject("MooseApp", MFEMTransient);
      17             : 
      18             : InputParameters
      19        8678 : MFEMTransient::validParams()
      20             : {
      21        8678 :   InputParameters params = MFEMExecutioner::validParams();
      22        8678 :   params.addClassDescription("Executioner for transient MFEM problems.");
      23        8678 :   params.addParam<Real>("start_time", 0.0, "The start time of the simulation");
      24        8678 :   params.addParam<Real>("end_time", 1.0e30, "The end time of the simulation");
      25        8678 :   params.addParam<Real>("dt", 1., "The timestep size between solves");
      26       26034 :   params.addParam<unsigned int>(
      27       17356 :       "visualisation_steps", 1, "The number of timesteps in a transient run");
      28        8678 :   return params;
      29           0 : }
      30             : 
      31          24 : MFEMTransient::MFEMTransient(const InputParameters & params)
      32             :   : MFEMExecutioner(params),
      33          24 :     _t_step(getParam<Real>("dt")),
      34          24 :     _t_initial(getParam<Real>("start_time")),
      35          24 :     _t_final(getParam<Real>("end_time")),
      36          24 :     _t(_mfem_problem.time()),
      37          24 :     _it(0),
      38          24 :     _vis_steps(params.get<unsigned int>("visualisation_steps")),
      39          48 :     _last_step(false)
      40             : {
      41          24 :   _app.setStartTime(_t_initial);
      42          24 :   _t = _t_initial;
      43          24 :   _mfem_problem.transient(true);
      44          24 : }
      45             : 
      46             : void
      47          24 : MFEMTransient::constructProblemOperator()
      48             : {
      49          24 :   _problem_data.eqn_system = std::make_shared<Moose::MFEM::TimeDependentEquationSystem>();
      50             :   auto problem_operator =
      51          24 :       std::make_unique<Moose::MFEM::TimeDomainEquationSystemProblemOperator>(_problem_data);
      52          24 :   _problem_operator.reset();
      53          24 :   _problem_operator = std::move(problem_operator);
      54          24 : }
      55             : 
      56             : void
      57          68 : MFEMTransient::step(double dt, int) const
      58             : {
      59             :   // Check if current time step is final
      60          68 :   if (_t + dt >= _t_final - dt / 2)
      61             :   {
      62          24 :     _last_step = true;
      63             :   }
      64             : 
      65             :   // Advance time step.
      66          68 :   _problem_data.ode_solver->Step(_problem_data.f, _t, dt);
      67             : 
      68             :   // Synchonise time dependent GridFunctions with updated DoF data.
      69          68 :   _problem_operator->SetTestVariablesFromTrueVectors();
      70             : 
      71             :   // Sync Host/Device
      72          68 :   _problem_data.f.HostRead();
      73             : 
      74             :   // Execute user objects at timestep end
      75          68 :   _mfem_problem.execute(EXEC_TIMESTEP_END);
      76             :   // Perform the output of the current time step
      77          68 :   _mfem_problem.outputStep(EXEC_TIMESTEP_END);
      78          68 : }
      79             : 
      80             : void
      81          24 : MFEMTransient::init()
      82             : {
      83          24 :   _mfem_problem.execute(EXEC_PRE_MULTIAPP_SETUP);
      84          24 :   _mfem_problem.initialSetup();
      85             : 
      86             :   // Set up initial conditions
      87          24 :   _problem_data.eqn_system->Init(
      88          24 :       _problem_data.gridfunctions,
      89          24 :       _problem_data.fespaces,
      90          48 :       getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>());
      91             : 
      92          24 :   _problem_operator->SetGridFunctions();
      93          24 :   _problem_operator->Init(_problem_data.f);
      94             : 
      95             :   // Set timestepper
      96          24 :   _problem_data.ode_solver = std::make_unique<mfem::BackwardEulerSolver>();
      97          24 :   _problem_data.ode_solver->Init(*(_problem_operator));
      98          24 :   _problem_operator->SetTime(0.0);
      99          24 : }
     100             : 
     101             : void
     102          24 : MFEMTransient::execute()
     103             : {
     104          24 :   _mfem_problem.outputStep(EXEC_INITIAL);
     105          24 :   preExecute();
     106             : 
     107          92 :   while (_last_step != true)
     108             :   {
     109          68 :     _it++;
     110          68 :     step(_t_step, _it);
     111             :   }
     112             : 
     113          24 :   _mfem_problem.finishMultiAppStep(EXEC_MULTIAPP_FIXED_POINT_BEGIN,
     114             :                                    /*recurse_through_multiapp_levels=*/true);
     115          24 :   _mfem_problem.finishMultiAppStep(EXEC_TIMESTEP_BEGIN, /*recurse_through_multiapp_levels=*/true);
     116          24 :   _mfem_problem.finishMultiAppStep(EXEC_TIMESTEP_END, /*recurse_through_multiapp_levels=*/true);
     117          24 :   _mfem_problem.finishMultiAppStep(EXEC_MULTIAPP_FIXED_POINT_END,
     118             :                                    /*recurse_through_multiapp_levels=*/true);
     119             : 
     120          24 :   TIME_SECTION("final", 1, "Executing Final Objects");
     121          24 :   _mfem_problem.execMultiApps(EXEC_FINAL);
     122          24 :   _mfem_problem.finalizeMultiApps();
     123          24 :   _mfem_problem.execute(EXEC_FINAL);
     124          24 :   _mfem_problem.outputStep(EXEC_FINAL);
     125          24 :   _mfem_problem.postExecute();
     126             : 
     127          24 :   postExecute();
     128          24 : }
     129             : 
     130             : #endif

Generated by: LCOV version 1.14