GEOS
HypreMGR.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_LINEARALGEBRA_INTERFACES_HYPREMGRSTRATEGIES_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_HYPREMGRSTRATEGIES_HPP_
22 
24 
28 
29 #include <_hypre_utilities.h>
30 
31 namespace geos
32 {
33 
38 {
42 };
43 
44 namespace hypre
45 {
46 
47 namespace mgr
48 {
49 
58 template< typename STRATEGY >
60  arrayView1d< int const > const & numComponentsPerField,
61  HyprePrecWrapper & precond,
62  HypreMGRData & mgrData )
63 {
64  STRATEGY strategy( numComponentsPerField );
65  strategy.setup( params, precond, mgrData );
66 }
67 
72 template< int NLEVEL >
74 {
75 public:
76 
77  static constexpr HYPRE_Int numLevels = NLEVEL;
78 
79 protected:
80 
81  HYPRE_Int m_numBlocks{ 0 };
82 
84  HYPRE_Int m_numLabels[numLevels]{ -1 };
85  HYPRE_Int * m_ptrLabels[numLevels]{ nullptr };
86 
88  HYPRE_Int m_levelFRelaxIters[numLevels]{ -1 };
94  HYPRE_Real m_coarseGridThreshold{ 1.0e-20 };
95 
96  // TODO: the following options are currently commented out in MGR's code.
97  // Let's consider their use when re-enable in hypre
98  // HYPRE_Int m_numRestrictSweeps{ -1 }; ///< Number of restrict sweeps
99  // HYPRE_Int m_numInterpSweeps{ -1 }; ///< Number of interpolation sweeps
100 
105  explicit MGRStrategyBase( HYPRE_Int const numBlocks )
106  : m_numBlocks( numBlocks )
107  {
108  for( HYPRE_Int i = 0; i < numLevels; ++i )
109  {
115  }
116  }
117 
121  void setupLabels()
122  {
123  for( HYPRE_Int i = 0; i < numLevels; ++i )
124  {
125  m_numLabels[i] = m_labels[i].size();
126  m_ptrLabels[i] = m_labels[i].data();
127  }
128  }
129 
136  HypreMGRData & mgrData )
137 
138  {
139  // Ensure that if no F-relaxation or global smoothing is chosen the corresponding number
140  // of iteration is set to 0
141  for( HYPRE_Int i = 0; i < numLevels; ++i )
142  {
144  {
145  m_levelFRelaxIters[i] = 0;
146  }
148  {
150  }
151  }
152 
153  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetCpointsByPointMarkerArray( precond.ptr,
156  mgrData.pointMarkers.data() ) );
157  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelFRelaxType( precond.ptr, toUnderlyingPtr( m_levelFRelaxType ) ) );
158  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelNumRelaxSweeps( precond.ptr, m_levelFRelaxIters ) );
159  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelInterpType( precond.ptr, toUnderlyingPtr( m_levelInterpType ) ) );
160  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelRestrictType( precond.ptr, toUnderlyingPtr( m_levelRestrictType ) ) );
161  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetCoarseGridMethod( precond.ptr, toUnderlyingPtr( m_levelCoarseGridMethod ) ) );
162  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelSmoothType( precond.ptr, toUnderlyingPtr( m_levelGlobalSmootherType ) ) );
163  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetLevelSmoothIters( precond.ptr, m_levelGlobalSmootherIters ) );
164  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetTruncateCoarseGridThreshold( precond.ptr, m_coarseGridThreshold ) );
165  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetNonCpointsToFpoints( precond.ptr, 1 ));
166  GEOS_LAI_CHECK_ERROR( HYPRE_MGRSetNonGalerkinMaxElmts( precond.ptr, 1 ));
167  }
168 
175  integer const & separateComponents )
176  {
177  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
178  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
179  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
180  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
181  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetStrongThreshold( solver.ptr, 0.6 ) );
182  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
183 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
186  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 1 ) );
187 #else
188  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
189 #endif
190 
191  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumFunctions( solver.ptr, 3 ) );
192  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetFilterFunctions( solver.ptr, separateComponents ) );
193 
194  solver.setup = HYPRE_BoomerAMGSetup;
195  solver.solve = HYPRE_BoomerAMGSolve;
196  solver.destroy = HYPRE_BoomerAMGDestroy;
197  }
198 
204  {
205  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
206  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
207  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
208  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 1 ) );
209  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggPMaxElmts( solver.ptr, 20 ) );
211  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
212 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
216  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 2 ) );
217  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
218 #else
219  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
220 #endif
221 
222  solver.setup = HYPRE_BoomerAMGSetup;
223  solver.solve = HYPRE_BoomerAMGSolve;
224  solver.destroy = HYPRE_BoomerAMGDestroy;
225  }
226 
232  {
233  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
234  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
235  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
236  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 1 ) ); // TODO: keep or not 1 aggressive level?
237  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggPMaxElmts( solver.ptr, 16 ) );
238  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
239  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumFunctions( solver.ptr, 2 ) ); // pressure and temperature (CPTR)
240 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
241  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 0 ) );
242  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetCoarsenType( solver.ptr, toUnderlying( AMGCoarseningType::PMIS ) ) );
244  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 2 ) );
245  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
246 #else
247  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
248 #endif
249 
250  solver.setup = HYPRE_BoomerAMGSetup;
251  solver.solve = HYPRE_BoomerAMGSolve;
252  solver.destroy = HYPRE_BoomerAMGDestroy;
253  }
254 
265  HypreMGRData & mgrData,
266  integer const & separateComponents )
267  {
268  setDisplacementAMG( mgrData.mechSolver, separateComponents );
269  HYPRE_MGRSetFSolver( precond.ptr, mgrData.mechSolver.solve, mgrData.mechSolver.setup, mgrData.mechSolver.ptr );
270  }
277  {
278  /* (Required) Create ILU solver */
279  HYPRE_ILUCreate( &solver.ptr );
280 
281  /* (Recommended) General solver options */
282  int const ilu_type = 0; /* 0, 1, 10, 11, 20, 21, 30, 31, 40, 41, 50 */
283  int const max_iter = 1;
284  double const tol = 0.0;
285  int const reordering = 0; /* 0: none, 1: RCM */
286  int const print_level = 0;
287  HYPRE_ILUSetType( solver.ptr, ilu_type );
288  HYPRE_ILUSetMaxIter( solver.ptr, max_iter );
289  HYPRE_ILUSetTol( solver.ptr, tol );
290  HYPRE_ILUSetLocalReordering( solver.ptr, reordering );
291  HYPRE_ILUSetPrintLevel( solver.ptr, print_level );
292 
293  solver.setup = HYPRE_ILUSetup;
294  solver.solve = HYPRE_ILUSolve;
295  solver.destroy = HYPRE_ILUDestroy;
296  }
297 
298 };
299 
307 void createMGR( LinearSolverParameters const & params,
308  DofManager const * const dofManager,
309  HyprePrecWrapper & precond,
310  HypreMGRData & mgrData );
311 
312 } // namespace mgr
313 
314 } // namespace hypre
315 
316 } // namespace geos
317 
318 #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:59
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Definition: DofManager.hpp:44
Helper struct for strategies that provides some basic parameter arrays needed by MGR.
Definition: HypreMGR.hpp:74
MGRCoarseGridMethod m_levelCoarseGridMethod[numLevels]
Coarse grid method for each level.
Definition: HypreMGR.hpp:91
HYPRE_Int m_numBlocks
Number of different matrix blocks treated separately.
Definition: HypreMGR.hpp:81
void setDisplacementAMG(HyprePrecWrapper &solver, integer const &separateComponents)
Set up BoomerAMG to perform the solve for the displacement system.
Definition: HypreMGR.hpp:174
MGRInterpolationType m_levelInterpType[numLevels]
Interpolation type for each level.
Definition: HypreMGR.hpp:89
void setILUCoarseSolver(HyprePrecWrapper &solver)
Definition: HypreMGR.hpp:276
MGRStrategyBase(HYPRE_Int const numBlocks)
Constructor.
Definition: HypreMGR.hpp:105
void setPressureTemperatureAMG(HyprePrecWrapper &solver)
Set up BoomerAMG to perform the solve for the pressure/temperature system.
Definition: HypreMGR.hpp:231
static constexpr HYPRE_Int numLevels
Number of levels.
Definition: HypreMGR.hpp:77
stdVector< HYPRE_Int > m_labels[numLevels]
Dof labels kept at each level.
Definition: HypreMGR.hpp:83
void setMechanicsFSolver(HyprePrecWrapper &precond, HypreMGRData &mgrData, integer const &separateComponents)
Set up BoomerAMG to perform the mechanics F-solve for the first F-relaxation.
Definition: HypreMGR.hpp:264
void setupLabels()
Call this after populating lv_cindexes.
Definition: HypreMGR.hpp:121
HYPRE_Int m_levelFRelaxIters[numLevels]
Number of F-relaxation iterations for each level.
Definition: HypreMGR.hpp:88
void setPressureAMG(HyprePrecWrapper &solver)
Set up BoomerAMG to perform the solve for the pressure system.
Definition: HypreMGR.hpp:203
void setReduction(HyprePrecWrapper &precond, HypreMGRData &mgrData)
Helper function that sets the reduction features common to all mgr strategies.
Definition: HypreMGR.hpp:135
MGRFRelaxationType m_levelFRelaxType[numLevels]
F-relaxation type for each level.
Definition: HypreMGR.hpp:87
HYPRE_Int * m_ptrLabels[numLevels]
Pointers to each level's labels, as consumed by MGR.
Definition: HypreMGR.hpp:85
HYPRE_Int m_levelGlobalSmootherIters[numLevels]
Number of global smoother iterations for each level.
Definition: HypreMGR.hpp:93
HYPRE_Real m_coarseGridThreshold
Coarse grid truncation threshold.
Definition: HypreMGR.hpp:94
MGRGlobalSmootherType m_levelGlobalSmootherType[numLevels]
Global smoother type for each level.
Definition: HypreMGR.hpp:92
HYPRE_Int m_numLabels[numLevels]
Number of dof labels kept.
Definition: HypreMGR.hpp:84
MGRRestrictionType m_levelRestrictType[numLevels]
Restriction type for each level.
Definition: HypreMGR.hpp:90
#define GEOS_LAI_CHECK_ERROR(call)
Definition: common.hpp:119
MGRCoarseGridMethod
This enum class specifies the strategy for level coarse grid computation in MGR.
Definition: HypreUtils.hpp:513
@ 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:499
HYPRE_Int getAMGAggressiveInterpolationType(LinearSolverParameters::AMG::AggInterpType const &type)
Returns hypre's identifier of the AMG aggressive interpolation type.
Definition: HypreUtils.hpp:352
MGRFRelaxationType
This enum class specifies the F-relaxation type.
Definition: HypreUtils.hpp:530
@ 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:307
@ 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:413
MGRInterpolationType
This enum class specifies the strategy for computing the level intepolation operator in MGR.
Definition: HypreUtils.hpp:484
MGRGlobalSmootherType
This enum class specifies the global smoother type.
Definition: HypreUtils.hpp:552
@ none
no global smoothing is performed (default)
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:81
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:175
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
Container for hypre preconditioner auxiliary data for MGR.
Definition: HypreMGR.hpp:38
HyprePrecWrapper mechSolver
MGR mechanics fine solver pointer and functions.
Definition: HypreMGR.hpp:41
HyprePrecWrapper coarseSolver
MGR coarse solver pointer and functions.
Definition: HypreMGR.hpp:40
array1d< HYPRE_Int > pointMarkers
array1d of unique tags for local degrees of freedom
Definition: HypreMGR.hpp:39
Container for hypre preconditioner function pointers.
Definition: HypreUtils.hpp:54
HYPRE_Solver ptr
pointer to preconditioner
Definition: HypreUtils.hpp:64
SetupFunc setup
pointer to setup function
Definition: HypreUtils.hpp:65
DestroyFunc destroy
pointer to destroy function
Definition: HypreUtils.hpp:67
SolveFunc solve
pointer to apply function
Definition: HypreUtils.hpp:66
@ chebyshev
Chebyshev polynomial smoothing.
@ PMIS
Parallel coarsening as CLJP but with lower complexities (GPU support)
@ modifiedExtendedE
Modularized Extended+e (GPU support)
Multigrid reduction parameters.
Set of parameters for a linear solver or preconditioner.