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 : #pragma once 13 : 14 : #include "MFEMObject.h" 15 : 16 : namespace Moose::MFEM 17 : { 18 : /** 19 : * Base class for wrapping mfem::Solver-derived classes. 20 : */ 21 : class SolverBase : public MFEMObject 22 : { 23 : public: 24 : static InputParameters validParams(); 25 : 26 : SolverBase(const InputParameters & parameters); 27 : 28 : /// Returns the wrapped MFEM solver 29 : mfem::Solver & GetSolver(); 30 : 31 : /// Set the wrapped MFEM solver 32 57 : void SetSolver(mfem::Solver * solver) { _solver.reset(solver); } 33 : 34 : /// Override in derived classes to construct and set the solver options. 35 : virtual void ConstructSolver() = 0; 36 : 37 : /// Updates the solver and any associated weak form context at the operator level 38 : void SetOperator(mfem::Operator & op); 39 : 40 : /// Solve the operator for the provided right-hand side and solution vector. 41 2622 : void Mult(const mfem::Vector & rhs, mfem::Vector & x) { GetSolver().Mult(rhs, x); } 42 : 43 : protected: 44 : /// Update the solver following any changes to the weak form it is responsible for solving. 45 : /// Default no-op. 46 734 : virtual void UpdateEquationSystemContext() {} 47 : 48 : /// Updates the solver at the operator level. Default implementation sets the operator on the 49 : /// wrapped MFEM solver 50 3412 : virtual void SetOperatorImpl(mfem::Operator & op) { GetSolver().SetOperator(op); } 51 : 52 : /// Solver to be used for the problem 53 : std::unique_ptr<mfem::Solver> _solver; 54 : }; 55 : 56 : inline mfem::Solver & 57 12226 : SolverBase::GetSolver() 58 : { 59 : mooseAssert(_solver, "Attempting to retrieve solver before it's been constructed"); 60 12226 : return *_solver; 61 : } 62 : } // namespace Moose::MFEM 63 : 64 : #endif