GEOSX
HypreMGR.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOS_LINEARALGEBRA_INTERFACES_HYPREMGRSTRATEGIES_HPP_
20 #define GEOS_LINEARALGEBRA_INTERFACES_HYPREMGRSTRATEGIES_HPP_
21 
23 
27 
28 #include <_hypre_utilities.h>
29 
30 namespace geos
31 {
32 
37 {
41 };
42 
43 namespace hypre
44 {
45 
46 namespace mgr
47 {
48 
57 template< typename STRATEGY >
59  arrayView1d< int const > const & numComponentsPerField,
60  HyprePrecWrapper & precond,
61  HypreMGRData & mgrData )
62 {
63  STRATEGY strategy( numComponentsPerField );
64  strategy.setup( params, precond, mgrData );
65 }
66 
71 template< int NLEVEL >
73 {
74 public:
75 
76  static constexpr HYPRE_Int numLevels = NLEVEL;
77 
78 protected:
79 
80  HYPRE_Int m_numBlocks{ 0 };
81 
82  std::vector< HYPRE_Int > m_labels[numLevels]{};
83  HYPRE_Int m_numLabels[numLevels]{ -1 };
84  HYPRE_Int * m_ptrLabels[numLevels]{ nullptr };
85 
87  HYPRE_Int m_levelFRelaxIters[numLevels]{ -1 };
93 
94  // TODO: the following options are currently commented out in MGR's code.
95  // Let's consider their use when re-enable in hypre
96  // HYPRE_Int m_numRestrictSweeps{ -1 }; ///< Number of restrict sweeps
97  // HYPRE_Int m_numInterpSweeps{ -1 }; ///< Number of interpolation sweeps
98 
103  explicit MGRStrategyBase( HYPRE_Int const numBlocks )
104  : m_numBlocks( numBlocks )
105  {
106  for( HYPRE_Int i = 0; i < numLevels; ++i )
107  {
113  }
114  }
115 
119  void setupLabels()
120  {
121  for( HYPRE_Int i = 0; i < numLevels; ++i )
122  {
123  m_numLabels[i] = m_labels[i].size();
124  m_ptrLabels[i] = m_labels[i].data();
125  }
126  }
127 
134  HypreMGRData & mgrData )
135 
136  {
137  // Ensure that if no F-relaxation or global smoothing is chosen the corresponding number
138  // of iteration is set to 0
139  for( HYPRE_Int i = 0; i < numLevels; ++i )
140  {
142  {
143  m_levelFRelaxIters[i] = 0;
144  }
146  {
148  }
149  }
150 
151  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetCpointsByPointMarkerArray( precond.ptr,
154  mgrData.pointMarkers.data() ) );
155  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelFRelaxType( precond.ptr, toUnderlyingPtr( m_levelFRelaxType ) ) );
156  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelNumRelaxSweeps( precond.ptr, m_levelFRelaxIters ) );
157  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelInterpType( precond.ptr, toUnderlyingPtr( m_levelInterpType ) ) );
158  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelRestrictType( precond.ptr, toUnderlyingPtr( m_levelRestrictType ) ) );
159  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetCoarseGridMethod( precond.ptr, toUnderlyingPtr( m_levelCoarseGridMethod ) ) );
160  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelSmoothType( precond.ptr, toUnderlyingPtr( m_levelGlobalSmootherType ) ) );
161  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelSmoothIters( precond.ptr, m_levelGlobalSmootherIters ) );
162  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetNonCpointsToFpoints( precond.ptr, 1 ));
163  }
164 
170  {
171  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
172  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
173  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
174  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
175  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetStrongThreshold( solver.ptr, 0.8 ) );
176  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
177 
178 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
181  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 1 ) );
182 #else
183  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
184 #endif
185 
186  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumFunctions( solver.ptr, 3 ) );
187 
188  solver.setup = HYPRE_BoomerAMGSetup;
189  solver.solve = HYPRE_BoomerAMGSolve;
190  solver.destroy = HYPRE_BoomerAMGDestroy;
191  }
192 
198  {
199  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
200  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
201  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
202  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 1 ) );
203  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggPMaxElmts( solver.ptr, 16 ) );
204  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
205 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
206  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 0 ) );
207  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetCoarsenType( solver.ptr, toUnderlying( AMGCoarseningType::PMIS ) ) );
209  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 2 ) );
210  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
211 #else
212  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
213 #endif
214 
215  solver.setup = HYPRE_BoomerAMGSetup;
216  solver.solve = HYPRE_BoomerAMGSolve;
217  solver.destroy = HYPRE_BoomerAMGDestroy;
218  }
219 
225  {
226  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
227  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
228  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
229  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 1 ) ); // TODO: keep or not 1 aggressive level?
230  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggPMaxElmts( solver.ptr, 16 ) );
231  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
232  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumFunctions( solver.ptr, 2 ) ); // pressure and temperature (CPTR)
233 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
234  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 0 ) );
235  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetCoarsenType( solver.ptr, toUnderlying( AMGCoarseningType::PMIS ) ) );
237  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 2 ) );
238  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
239 #else
240  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
241 #endif
242 
243  solver.setup = HYPRE_BoomerAMGSetup;
244  solver.solve = HYPRE_BoomerAMGSolve;
245  solver.destroy = HYPRE_BoomerAMGDestroy;
246  }
247 
257  HypreMGRData & mgrData )
258  {
259  setDisplacementAMG( mgrData.mechSolver );
260  HYPRE_MGRSetFSolver( precond.ptr, mgrData.mechSolver.solve, mgrData.mechSolver.setup, mgrData.mechSolver.ptr );
261  }
262 
263 };
264 
272 void createMGR( LinearSolverParameters const & params,
273  DofManager const * const dofManager,
274  HyprePrecWrapper & precond,
275  HypreMGRData & mgrData );
276 
277 } // namespace mgr
278 
279 } // namespace hypre
280 
281 } // namespace geos
282 
283 #endif /*GEOS_LINEARALGEBRA_INTERFACES_HYPREMGRSTRATEGIES_HPP_*/
void createMGR(LinearSolverParameters const &params, DofManager const *const dofManager, HyprePrecWrapper &precond, HypreMGRData &mgrData)
Create the MGR preconditioner object.
void setStrategy(LinearSolverParameters::MGR const &params, arrayView1d< int const > const &numComponentsPerField, HyprePrecWrapper &precond, HypreMGRData &mgrData)
Helper to simplify MGR setup.
Definition: HypreMGR.hpp:58
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Definition: DofManager.hpp:43
Helper struct for strategies that provides some basic parameter arrays needed by MGR.
Definition: HypreMGR.hpp:73
MGRCoarseGridMethod m_levelCoarseGridMethod[numLevels]
Coarse grid method for each level.
Definition: HypreMGR.hpp:90
HYPRE_Int m_numBlocks
Number of different matrix blocks treated separately.
Definition: HypreMGR.hpp:80
MGRInterpolationType m_levelInterpType[numLevels]
Interpolation type for each level.
Definition: HypreMGR.hpp:88
MGRStrategyBase(HYPRE_Int const numBlocks)
Constructor.
Definition: HypreMGR.hpp:103
std::vector< HYPRE_Int > m_labels[numLevels]
Dof labels kept at each level.
Definition: HypreMGR.hpp:82
void setPressureTemperatureAMG(HyprePrecWrapper &solver)
Set up BoomerAMG to perform the solve for the pressure/temperature system.
Definition: HypreMGR.hpp:224
static constexpr HYPRE_Int numLevels
Number of levels.
Definition: HypreMGR.hpp:76
void setupLabels()
Call this after populating lv_cindexes.
Definition: HypreMGR.hpp:119
HYPRE_Int m_levelFRelaxIters[numLevels]
Number of F-relaxation iterations for each level.
Definition: HypreMGR.hpp:87
void setDisplacementAMG(HyprePrecWrapper &solver)
Set up BoomerAMG to perform the solve for the displacement system.
Definition: HypreMGR.hpp:169
void setPressureAMG(HyprePrecWrapper &solver)
Set up BoomerAMG to perform the solve for the pressure system.
Definition: HypreMGR.hpp:197
void setReduction(HyprePrecWrapper &precond, HypreMGRData &mgrData)
Helper function that sets the reduction features common to all mgr strategies.
Definition: HypreMGR.hpp:133
MGRFRelaxationType m_levelFRelaxType[numLevels]
F-relaxation type for each level.
Definition: HypreMGR.hpp:86
HYPRE_Int * m_ptrLabels[numLevels]
Pointers to each level's labels, as consumed by MGR.
Definition: HypreMGR.hpp:84
HYPRE_Int m_levelGlobalSmootherIters[numLevels]
Number of global smoother iterations for each level.
Definition: HypreMGR.hpp:92
MGRGlobalSmootherType m_levelGlobalSmootherType[numLevels]
Global smoother type for each level.
Definition: HypreMGR.hpp:91
HYPRE_Int m_numLabels[numLevels]
Number of dof labels kept.
Definition: HypreMGR.hpp:83
MGRRestrictionType m_levelRestrictType[numLevels]
Restriction type for each level.
Definition: HypreMGR.hpp:89
void setMechanicsFSolver(HyprePrecWrapper &precond, HypreMGRData &mgrData)
Set up BoomerAMG to perform the mechanics F-solve for the first F-relaxation.
Definition: HypreMGR.hpp:256
#define GEOS_LAI_CHECK_ERROR(call)
Definition: common.hpp:117
MGRCoarseGridMethod
This enum class specifies the strategy for level coarse grid computation in MGR.
Definition: HypreUtils.hpp:510
@ galerkin
Galerkin coarse grid computation using RAP.
MGRRestrictionType
This enum class specifies the strategy for computing the level restriction operator in MGR.
Definition: HypreUtils.hpp:496
MGRFRelaxationType
This enum class specifies the F-relaxation type.
Definition: HypreUtils.hpp:528
@ none
no F-relaxation if performed
HYPRE_Int getAMGRelaxationType(LinearSolverParameters::AMG::SmootherType const &type)
Returns hypre's identifier of the AMG smoother type.
Definition: HypreUtils.hpp:306
@ PMIS
Parallel coarsening algorithm using independent sets.
HYPRE_Int getAMGCoarseningType(LinearSolverParameters::AMG::CoarseningType const &type)
Returns hypre's identifier of the AMG coarsening type.
Definition: HypreUtils.hpp:410
MGRInterpolationType
This enum class specifies the strategy for computing the level intepolation operator in MGR.
Definition: HypreUtils.hpp:481
MGRGlobalSmootherType
This enum class specifies the global smoother type.
Definition: HypreUtils.hpp:550
@ none
no global smoothing is performed (default)
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:220
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:216
Container for hypre preconditioner auxiliary data for MGR.
Definition: HypreMGR.hpp:37
HyprePrecWrapper mechSolver
MGR mechanics fine solver pointer and functions.
Definition: HypreMGR.hpp:40
HyprePrecWrapper coarseSolver
MGR coarse solver pointer and functions.
Definition: HypreMGR.hpp:39
array1d< HYPRE_Int > pointMarkers
array1d of unique tags for local degrees of freedom
Definition: HypreMGR.hpp:38
Container for hypre preconditioner function pointers.
Definition: HypreUtils.hpp:53
HYPRE_Solver ptr
pointer to preconditioner
Definition: HypreUtils.hpp:63
SetupFunc setup
pointer to setup function
Definition: HypreUtils.hpp:64
DestroyFunc destroy
pointer to destroy function
Definition: HypreUtils.hpp:66
SolveFunc solve
pointer to apply function
Definition: HypreUtils.hpp:65
@ chebyshev
Chebyshev polynomial smoothing.
@ PMIS
Parallel coarsening as CLJP but with lower complexities (GPU support)
Multigrid reduction parameters.
Set of parameters for a linear solver or preconditioner.