LCOV - code coverage report
Current view: top level - src/mfem/problem_operators - TimeDependentEquationSystemProblemOperator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 41 42 97.6 %
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 "TimeDependentEquationSystemProblemOperator.h"
      13             : 
      14             : namespace Moose::MFEM
      15             : {
      16             : void
      17         274 : TimeDependentEquationSystemProblemOperator::SetGridFunctions()
      18             : {
      19         274 :   _trial_var_names = GetEquationSystem()->GetTrialVarNames();
      20         274 :   _test_var_names = GetEquationSystem()->GetTestVarNames();
      21         274 :   TimeDependentProblemOperator::SetGridFunctions();
      22         274 : }
      23             : 
      24             : void
      25         274 : TimeDependentEquationSystemProblemOperator::Init(mfem::BlockVector & X)
      26             : {
      27         274 :   TimeDependentProblemOperator::Init(X);
      28             :   // Set timestepper
      29         274 :   auto & ode_solver = _problem_data.ode_solver;
      30         274 :   ode_solver = std::make_unique<mfem::BackwardEulerSolver>();
      31         274 :   ode_solver->Init(*(this));
      32         274 :   SetTime(_problem.time());
      33         274 :   SetImplicitVariableType(STATE);
      34         274 : }
      35             : 
      36             : void
      37        1048 : TimeDependentEquationSystemProblemOperator::Solve()
      38             : {
      39        1048 :   auto & dt = _problem.dt();
      40        1048 :   auto & gfs = _problem_data.gridfunctions;
      41        1048 :   auto & tdm = _problem_data.time_derivative_map;
      42             : 
      43             :   // Initialise time derivative
      44        2114 :   for (const auto & trial_var_name : _trial_var_names)
      45        1066 :     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        1048 :   _problem_data.ode_solver->Step(*_trial_true_vector, _problem.time(), dt);
      51             :   // Synchonise time dependent GridFunctions with updated DoF data.
      52        1048 :   SetTrialVariablesFromTrueVectors();
      53             : 
      54             :   // Set time derivatives
      55        2114 :   for (const auto & trial_var_name : _trial_var_names)
      56        1066 :     (gfs.GetRef(tdm.getTimeDerivativeName(trial_var_name)) -= gfs.GetRef(trial_var_name)) /= -dt;
      57        1048 : }
      58             : 
      59             : void
      60        1048 : TimeDependentEquationSystemProblemOperator::ImplicitSolve(const mfem::real_t dt,
      61             :                                                           const mfem::Vector &,
      62             :                                                           mfem::Vector & X_new)
      63             : {
      64        1048 :   _problem_data.coefficients.setTime(GetTime());
      65        1048 :   BuildEquationSystemOperator(dt);
      66             : 
      67        1048 :   if (_problem_data.jacobian_solver->isLOR() && GetEquationSystem()->GetTestVarNames().size() > 1)
      68           0 :     mooseError("LOR solve is only supported for single-variable systems");
      69        1048 :   _problem_data.jacobian_solver->updateSolver(
      70        1048 :       *GetEquationSystem()->_blfs.Get(GetEquationSystem()->GetTestVarNames().at(0)),
      71        1048 :       GetEquationSystem()->_ess_tdof_lists.at(0));
      72             : 
      73        1048 :   _problem_data.nonlinear_solver->SetPreconditioner(_problem_data.jacobian_solver->getSolver());
      74        1048 :   _problem_data.nonlinear_solver->SetOperator(*GetEquationSystem());
      75        1048 :   _problem_data.nonlinear_solver->Mult(_true_rhs, _true_x);
      76             : 
      77        1048 :   X_new = _true_x;
      78        1048 : }
      79             : 
      80             : void
      81        1048 : TimeDependentEquationSystemProblemOperator::BuildEquationSystemOperator(mfem::real_t dt)
      82             : {
      83        1048 :   GetEquationSystem()->SetTimeStep(dt);
      84        1048 :   GetEquationSystem()->BuildEquationSystem();
      85        1048 :   GetEquationSystem()->FormSystem(_true_x, _true_rhs);
      86        1048 : }
      87             : 
      88             : } // namespace Moose::MFEM
      89             : 
      90             : #endif

Generated by: LCOV version 1.14