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 "MFEMHypreBoomerAMG.h" 13 : #include "MFEMFESpace.h" 14 : 15 : registerMooseObject("MooseApp", MFEMHypreBoomerAMG); 16 : 17 : InputParameters 18 9710 : MFEMHypreBoomerAMG::validParams() 19 : { 20 9710 : InputParameters params = MFEMSolverBase::validParams(); 21 19420 : params.addClassDescription("Hypre BoomerAMG solver and preconditioner for the iterative solution " 22 : "of MFEM equation systems."); 23 38840 : params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance."); 24 38840 : params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations."); 25 38840 : params.addParam<int>("print_level", 2, "Set the solver verbosity."); 26 38840 : params.addParam<UserObjectName>( 27 : "fespace", "H1 FESpace to use in HypreBoomerAMG setup for elasticity problems."); 28 29130 : params.addParam<mfem::real_t>( 29 19420 : "strength_threshold", 0.25, "HypreBoomerAMG strong threshold. Defaults to 0.25."); 30 38840 : MooseEnum errmode("ignore=0 warn=1 abort=2", "abort", false); 31 29130 : params.addParam<MooseEnum>("error_mode", errmode, "Set the behavior for treating hypre errors."); 32 19420 : return params; 33 9710 : } 34 : 35 239 : MFEMHypreBoomerAMG::MFEMHypreBoomerAMG(const InputParameters & parameters) 36 : : MFEMSolverBase(parameters), 37 249 : _mfem_fespace(isParamSetByUser("fespace") ? getUserObject<MFEMFESpace>("fespace").getFESpace() 38 239 : : nullptr) 39 : { 40 239 : constructSolver(parameters); 41 239 : } 42 : 43 : void 44 239 : MFEMHypreBoomerAMG::constructSolver(const InputParameters &) 45 : { 46 239 : auto solver = std::make_unique<mfem::HypreBoomerAMG>(); 47 : 48 478 : solver->SetTol(getParam<mfem::real_t>("l_tol")); 49 478 : solver->SetMaxIter(getParam<int>("l_max_its")); 50 478 : solver->SetPrintLevel(getParam<int>("print_level")); 51 478 : solver->SetStrengthThresh(getParam<mfem::real_t>("strength_threshold")); 52 478 : solver->SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode")))); 53 : 54 239 : if (_mfem_fespace && !mfem::HypreUsingGPU()) 55 5 : solver->SetElasticityOptions(_mfem_fespace.get()); 56 : 57 239 : _solver = std::move(solver); 58 239 : } 59 : 60 : void 61 661 : MFEMHypreBoomerAMG::updateSolver(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs) 62 : { 63 661 : if (_lor) 64 : { 65 2 : checkSpectralEquivalence(a); 66 2 : auto lor_solver = new mfem::LORSolver<mfem::HypreBoomerAMG>(a, tdofs); 67 4 : lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol")); 68 4 : lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its")); 69 4 : lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level")); 70 4 : lor_solver->GetSolver().SetStrengthThresh(getParam<mfem::real_t>("strength_threshold")); 71 : 72 2 : if (_mfem_fespace && !mfem::HypreUsingGPU()) 73 0 : lor_solver->GetSolver().SetElasticityOptions(_mfem_fespace.get()); 74 : 75 2 : _solver.reset(lor_solver); 76 : } 77 661 : } 78 : 79 : #endif