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 "MFEMHyprePCG.h" 13 : #include "MFEMProblem.h" 14 : 15 : registerMooseObject("MooseApp", MFEMHyprePCG); 16 : 17 : InputParameters 18 2606 : MFEMHyprePCG::validParams() 19 : { 20 2606 : InputParameters params = Moose::MFEM::LORLinearSolverBase<mfem::HyprePCG>::validParams(); 21 5212 : params.addClassDescription("Hypre solver for the iterative solution of MFEM equation systems " 22 : "using the preconditioned conjugate gradient method."); 23 : 24 10424 : params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance."); 25 10424 : params.addParam<mfem::real_t>("l_abs_tol", 1e-50, "Set the absolute tolerance."); 26 10424 : params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations."); 27 10424 : params.addParam<int>("print_level", 2, "Set the solver verbosity."); 28 7818 : params.addParam<MFEMSolverName>("preconditioner", "Optional choice of preconditioner to use."); 29 : 30 2606 : return params; 31 0 : } 32 : 33 238 : MFEMHyprePCG::MFEMHyprePCG(const InputParameters & parameters) 34 238 : : Moose::MFEM::LORLinearSolverBase<mfem::HyprePCG>(parameters) 35 : { 36 238 : ConstructSolver(); 37 238 : } 38 : 39 : void 40 238 : MFEMHyprePCG::ConstructSolver() 41 : { 42 238 : auto solver = std::make_unique<mfem::HyprePCG>(getMFEMProblem().getComm()); 43 238 : SetSolverParameters(*solver); 44 238 : SetPreconditioner(*solver); 45 238 : _solver = std::move(solver); 46 238 : } 47 : 48 : void 49 240 : MFEMHyprePCG::SetSolverParameters(mfem::HyprePCG & solver) 50 : { 51 480 : solver.iterative_mode = getParam<bool>("use_initial_guess"); 52 480 : solver.SetTol(getParam<mfem::real_t>("l_tol")); 53 480 : solver.SetAbsTol(getParam<mfem::real_t>("l_abs_tol")); 54 480 : solver.SetMaxIter(getParam<int>("l_max_its")); 55 480 : solver.SetPrintLevel(getParam<int>("print_level")); 56 240 : } 57 : 58 : #endif