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 Total, S.A
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 
83  std::vector< HYPRE_Int > m_labels[numLevels]{};
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 ) );
184 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
187  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 1 ) );
188 #else
189  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
190 #endif
191 
192  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumFunctions( solver.ptr, 3 ) );
193  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetFilterFunctions( solver.ptr, separateComponents ) );
194 
195  solver.setup = HYPRE_BoomerAMGSetup;
196  solver.solve = HYPRE_BoomerAMGSolve;
197  solver.destroy = HYPRE_BoomerAMGDestroy;
198  }
199 
205  {
206  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
207  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
208  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
209  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 1 ) );
210  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggPMaxElmts( solver.ptr, 20 ) );
212  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
213 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
217  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 2 ) );
218  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
219 #else
220  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
221 #endif
222 
223  solver.setup = HYPRE_BoomerAMGSetup;
224  solver.solve = HYPRE_BoomerAMGSolve;
225  solver.destroy = HYPRE_BoomerAMGDestroy;
226  }
227 
233  {
234  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGCreate( &solver.ptr ) );
235  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetPrintLevel( solver.ptr, 0 ) );
236  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxIter( solver.ptr, 1 ) );
237  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 1 ) ); // TODO: keep or not 1 aggressive level?
238  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggPMaxElmts( solver.ptr, 16 ) );
239  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetTol( solver.ptr, 0.0 ) );
240  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumFunctions( solver.ptr, 2 ) ); // pressure and temperature (CPTR)
241 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP
242  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetAggNumLevels( solver.ptr, 0 ) );
243  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetCoarsenType( solver.ptr, toUnderlying( AMGCoarseningType::PMIS ) ) );
245  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetNumSweeps( solver.ptr, 2 ) );
246  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetMaxRowSum( solver.ptr, 1.0 ) );
247 #else
248  GEOS_LAI_CHECK_ERROR( HYPRE_BoomerAMGSetRelaxOrder( solver.ptr, 1 ) );
249 #endif
250 
251  solver.setup = HYPRE_BoomerAMGSetup;
252  solver.solve = HYPRE_BoomerAMGSolve;
253  solver.destroy = HYPRE_BoomerAMGDestroy;
254  }
255 
266  HypreMGRData & mgrData,
267  integer const & separateComponents )
268  {
269  setDisplacementAMG( mgrData.mechSolver, separateComponents );
270  HYPRE_MGRSetFSolver( precond.ptr, mgrData.mechSolver.solve, mgrData.mechSolver.setup, mgrData.mechSolver.ptr );
271  }
272 
273 };
274 
282 void createMGR( LinearSolverParameters const & params,
283  DofManager const * const dofManager,
284  HyprePrecWrapper & precond,
285  HypreMGRData & mgrData );
286 
287 } // namespace mgr
288 
289 } // namespace hypre
290 
291 } // namespace geos
292 
293 #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
MGRStrategyBase(HYPRE_Int const numBlocks)
Constructor.
Definition: HypreMGR.hpp:105
std::vector< HYPRE_Int > m_labels[numLevels]
Dof labels kept at each level.
Definition: HypreMGR.hpp:83
void setPressureTemperatureAMG(HyprePrecWrapper &solver)
Set up BoomerAMG to perform the solve for the pressure/temperature system.
Definition: HypreMGR.hpp:232
static constexpr HYPRE_Int numLevels
Number of levels.
Definition: HypreMGR.hpp:77
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:265
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:204
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
HYPRE_Int getAMGInterpolationType(LinearSolverParameters::AMG::InterpType const &type)
Returns hypre's identifier of the AMG interpolation type.
Definition: HypreUtils.hpp:328
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:180
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
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
@ modifiedExtendedE
Modularized extended+e (GPU support)
@ 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.