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 9424 : MFEMHyprePCG::validParams() 19 : { 20 9424 : InputParameters params = MFEMSolverBase::validParams(); 21 18848 : params.addClassDescription("Hypre solver for the iterative solution of MFEM equation systems " 22 : "using the preconditioned conjugate gradient method."); 23 : 24 37696 : params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance."); 25 37696 : params.addParam<mfem::real_t>("l_abs_tol", 1e-50, "Set the absolute tolerance."); 26 37696 : params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations."); 27 37696 : params.addParam<int>("print_level", 2, "Set the solver verbosity."); 28 28272 : params.addParam<UserObjectName>("preconditioner", "Optional choice of preconditioner to use."); 29 : 30 9424 : return params; 31 0 : } 32 : 33 96 : MFEMHyprePCG::MFEMHyprePCG(const InputParameters & parameters) : MFEMSolverBase(parameters) 34 : { 35 96 : constructSolver(parameters); 36 96 : } 37 : 38 : void 39 96 : MFEMHyprePCG::constructSolver(const InputParameters &) 40 : { 41 96 : auto solver = std::make_unique<mfem::patched::HyprePCG>(getMFEMProblem().getComm()); 42 192 : solver->SetTol(getParam<mfem::real_t>("l_tol")); 43 192 : solver->SetAbsTol(getParam<mfem::real_t>("l_abs_tol")); 44 192 : solver->SetMaxIter(getParam<int>("l_max_its")); 45 192 : solver->SetPrintLevel(getParam<int>("print_level")); 46 96 : setPreconditioner(*solver); 47 96 : _solver = std::move(solver); 48 96 : } 49 : 50 : void 51 530 : MFEMHyprePCG::updateSolver(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs) 52 : { 53 530 : if (_lor && _preconditioner) 54 0 : mooseError("LOR solver cannot take a preconditioner"); 55 : 56 530 : if (_preconditioner) 57 : { 58 518 : _preconditioner->updateSolver(a, tdofs); 59 518 : setPreconditioner(static_cast<mfem::HyprePCG &>(*_solver)); 60 : } 61 12 : else if (_lor) 62 : { 63 2 : checkSpectralEquivalence(a); 64 2 : mfem::ParLORDiscretization lor_disc(a, tdofs); 65 2 : auto lor_solver = new mfem::LORSolver<mfem::HyprePCG>(lor_disc, getMFEMProblem().getComm()); 66 4 : lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol")); 67 4 : lor_solver->GetSolver().SetAbsTol(getParam<mfem::real_t>("l_abs_tol")); 68 4 : lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its")); 69 4 : lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level")); 70 : 71 2 : _solver.reset(lor_solver); 72 2 : } 73 530 : } 74 : 75 : #endif