LCOV - code coverage report
Current view: top level - src/mfem/problem_operators - TimeDependentEquationSystemProblemOperator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fa5e60 Lines: 36 36 100.0 %
Date: 2026-06-24 08:03:36 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 "TimeDependentEquationSystemProblemOperator.h"
      13             : 
      14             : namespace Moose::MFEM
      15             : {
      16             : void
      17         321 : TimeDependentEquationSystemProblemOperator::SetGridFunctions()
      18             : {
      19         321 :   _trial_var_names = GetEquationSystem()->GetTrialVarNames();
      20         321 :   _test_var_names = GetEquationSystem()->GetTestVarNames();
      21         321 :   TimeDependentProblemOperator::SetGridFunctions();
      22         321 : }
      23             : 
      24             : void
      25         321 : TimeDependentEquationSystemProblemOperator::Init(mfem::BlockVector & X)
      26             : {
      27         321 :   TimeDependentProblemOperator::Init(X);
      28             :   // Set timestepper
      29         321 :   auto & ode_solver = _problem_data.ode_solver;
      30         321 :   ode_solver = std::make_unique<mfem::BackwardEulerSolver>();
      31         321 :   ode_solver->Init(*(this));
      32         321 :   SetTime(_problem.time());
      33         321 :   SetImplicitVariableType(STATE);
      34         321 : }
      35             : 
      36             : void
      37        1324 : TimeDependentEquationSystemProblemOperator::Solve()
      38             : {
      39        1324 :   auto & dt = _problem.dt();
      40        1324 :   auto & gfs = _problem_data.gridfunctions;
      41        1324 :   auto & tdm = _problem_data.time_derivative_map;
      42             : 
      43             :   // Initialise time derivative
      44        2666 :   for (const auto & trial_var_name : _trial_var_names)
      45        1342 :     gfs.GetRef(tdm.getTimeDerivativeName(trial_var_name)) = gfs.GetRef(trial_var_name);
      46             : 
      47             :   // Advance time step of the MFEM problem. Time is also updated here, and
      48             :   // _problem_operator->SetTime is called inside the ode_solver->Step method to
      49             :   // update the time used by time dependent (function) coefficients.
      50        1324 :   _problem_data.ode_solver->Step(*_trial_true_vector, _problem.time(), dt);
      51             :   // Synchonise time dependent GridFunctions with updated DoF data.
      52        1324 :   SetTrialVariablesFromTrueVectors();
      53             : 
      54             :   // Set time derivatives
      55        2666 :   for (const auto & trial_var_name : _trial_var_names)
      56        1342 :     (gfs.GetRef(tdm.getTimeDerivativeName(trial_var_name)) -= gfs.GetRef(trial_var_name)) /= -dt;
      57        1324 : }
      58             : 
      59             : void
      60        1324 : TimeDependentEquationSystemProblemOperator::ImplicitSolve(const mfem::real_t dt,
      61             :                                                           const mfem::Vector &,
      62             :                                                           mfem::Vector & X_new)
      63             : {
      64        1324 :   _problem_data.coefficients.setTime(GetTime());
      65        1324 :   BuildEquationSystemOperator(dt);
      66             : 
      67        1324 :   auto * const es = GetEquationSystem();
      68        1324 :   SolveWithOperator(*es, _true_rhs, _true_x);
      69             : 
      70        1324 :   X_new.MakeRef(_true_x, 0);
      71        1324 : }
      72             : 
      73             : void
      74        1324 : TimeDependentEquationSystemProblemOperator::BuildEquationSystemOperator(mfem::real_t dt)
      75             : {
      76        1324 :   GetEquationSystem()->SetTimeStep(dt);
      77        1324 :   GetEquationSystem()->BuildEquationSystem();
      78        1324 :   GetEquationSystem()->FormSystem(_true_x, _true_rhs);
      79        1324 : }
      80             : 
      81             : } // namespace Moose::MFEM
      82             : 
      83             : #endif

Generated by: LCOV version 1.14