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 113 : TimeDomainEquationSystemProblemOperator::SetGridFunctions() 18 : { 19 113 : _test_var_names = GetEquationSystem()->TestVarNames(); 20 113 : _trial_var_names = GetEquationSystem()->TrialVarNames(); 21 : 22 113 : TimeDomainProblemOperator::SetGridFunctions(); 23 113 : } 24 : 25 : void 26 113 : TimeDomainEquationSystemProblemOperator::Init(mfem::BlockVector & X) 27 : { 28 113 : TimeDomainProblemOperator::Init(X); 29 113 : GetEquationSystem()->BuildEquationSystem(); 30 : // Set timestepper 31 113 : auto & ode_solver = _problem_data.ode_solver; 32 113 : ode_solver = std::make_unique<mfem::BackwardEulerSolver>(); 33 113 : ode_solver->Init(*(this)); 34 113 : SetTime(_problem.time()); 35 113 : } 36 : 37 : void 38 641 : 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 641 : _problem_data.ode_solver->Step(_problem_data.f, _problem.time(), _problem.dt()); 44 : // Synchonise time dependent GridFunctions with updated DoF data. 45 641 : SetTestVariablesFromTrueVectors(); 46 641 : } 47 : 48 : void 49 641 : TimeDomainEquationSystemProblemOperator::ImplicitSolve(const double dt, 50 : const mfem::Vector & /*X*/, 51 : mfem::Vector & dX_dt) 52 : { 53 641 : dX_dt = 0.0; 54 641 : SetTestVariablesFromTrueVectors(); 55 1282 : for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind) 56 : { 57 1282 : _trial_variables.at(ind)->MakeTRef( 58 641 : _trial_variables.at(ind)->ParFESpace(), dX_dt, _block_true_offsets[ind]); 59 : } 60 641 : _problem_data.coefficients.setTime(GetTime()); 61 641 : BuildEquationSystemOperator(dt); 62 : 63 641 : 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 641 : _problem_data.jacobian_solver->updateSolver( 67 641 : *_equation_system->_blfs.Get(_equation_system->_test_var_names.at(0)), 68 641 : _equation_system->_ess_tdof_lists.at(0)); 69 : 70 641 : _problem_data.nonlinear_solver->SetSolver(_problem_data.jacobian_solver->getSolver()); 71 641 : _problem_data.nonlinear_solver->SetOperator(*GetEquationSystem()); 72 641 : _problem_data.nonlinear_solver->Mult(_true_rhs, dX_dt); 73 641 : SetTrialVariablesFromTrueVectors(); 74 641 : } 75 : 76 : void 77 641 : TimeDomainEquationSystemProblemOperator::BuildEquationSystemOperator(double dt) 78 : { 79 641 : GetEquationSystem()->SetTimeStep(dt); 80 641 : GetEquationSystem()->UpdateEquationSystem(); 81 641 : GetEquationSystem()->BuildJacobian(_true_x, _true_rhs); 82 641 : } 83 : 84 : } // namespace Moose::MFEM 85 : 86 : #endif