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 "TimeDomainEquationSystemProblemOperator.h" 13 : 14 : namespace Moose::MFEM 15 : { 16 : void 17 117 : TimeDomainEquationSystemProblemOperator::SetGridFunctions() 18 : { 19 117 : _test_var_names = GetEquationSystem()->TestVarNames(); 20 117 : _trial_var_names = GetEquationSystem()->TrialVarNames(); 21 : 22 117 : TimeDomainProblemOperator::SetGridFunctions(); 23 117 : } 24 : 25 : void 26 117 : TimeDomainEquationSystemProblemOperator::Init(mfem::BlockVector & X) 27 : { 28 117 : TimeDomainProblemOperator::Init(X); 29 117 : GetEquationSystem()->BuildEquationSystem(); 30 : // Set timestepper 31 117 : auto & ode_solver = _problem_data.ode_solver; 32 117 : ode_solver = std::make_unique<mfem::BackwardEulerSolver>(); 33 117 : ode_solver->Init(*(this)); 34 117 : SetTime(_problem.time()); 35 117 : } 36 : 37 : void 38 653 : TimeDomainEquationSystemProblemOperator::Solve() 39 : { 40 : // Advance time step of the MFEM problem. Time is also updated here, and 41 : // _problem_operator->SetTime is called inside the ode_solver->Step method to 42 : // update the time used by time dependent (function) coefficients. 43 653 : _problem_data.ode_solver->Step(_problem_data.f, _problem.time(), _problem.dt()); 44 : // Synchonise time dependent GridFunctions with updated DoF data. 45 653 : SetTestVariablesFromTrueVectors(); 46 653 : } 47 : 48 : void 49 653 : TimeDomainEquationSystemProblemOperator::ImplicitSolve(const mfem::real_t dt, 50 : const mfem::Vector & /*X*/, 51 : mfem::Vector & dX_dt) 52 : { 53 653 : dX_dt = 0.0; 54 653 : SetTestVariablesFromTrueVectors(); 55 1318 : for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind) 56 : { 57 1330 : _trial_variables.at(ind)->MakeTRef( 58 665 : _trial_variables.at(ind)->ParFESpace(), dX_dt, _block_true_offsets[ind]); 59 : } 60 653 : _problem_data.coefficients.setTime(GetTime()); 61 653 : BuildEquationSystemOperator(dt); 62 : 63 653 : if (_problem_data.jacobian_solver->isLOR() && _equation_system->_test_var_names.size() > 1) 64 0 : mooseError("LOR solve is only supported for single-variable systems"); 65 : 66 653 : _problem_data.jacobian_solver->updateSolver( 67 653 : *_equation_system->_blfs.Get(_equation_system->_test_var_names.at(0)), 68 653 : _equation_system->_ess_tdof_lists.at(0)); 69 : 70 653 : _problem_data.nonlinear_solver->SetSolver(_problem_data.jacobian_solver->getSolver()); 71 653 : _problem_data.nonlinear_solver->SetOperator(*GetEquationSystem()); 72 653 : _problem_data.nonlinear_solver->Mult(_true_rhs, dX_dt); 73 653 : SetTrialVariablesFromTrueVectors(); 74 653 : } 75 : 76 : void 77 653 : TimeDomainEquationSystemProblemOperator::BuildEquationSystemOperator(mfem::real_t dt) 78 : { 79 653 : GetEquationSystem()->SetTimeStep(dt); 80 653 : GetEquationSystem()->UpdateEquationSystem(); 81 653 : GetEquationSystem()->BuildJacobian(_true_x, _true_rhs); 82 653 : } 83 : 84 : } // namespace Moose::MFEM 85 : 86 : #endif