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