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