16#ifndef CABANA_GRID_HYPRESEMISTRUCTUREDSOLVER_HPP
17#define CABANA_GRID_HYPRESEMISTRUCTUREDSOLVER_HPP
26#include <HYPRE_config.h>
27#include <HYPRE_sstruct_ls.h>
28#include <HYPRE_sstruct_mv.h>
29#include <HYPRE_struct_ls.h>
30#include <HYPRE_struct_mv.h>
32#include <Kokkos_Core.hpp>
33#include <Kokkos_Profiling_ScopedRegion.hpp>
50template <
class Scalar,
class EntityType,
class MemorySpace>
64 "HYPRE not compatible with solver memory space" );
73 template <
class ArrayLayout_t>
75 const bool is_preconditioner =
false )
76 : _comm( layout.localGrid()->globalGrid().comm() )
77 , _is_preconditioner( is_preconditioner )
82 "Must use an array layout" );
84 std::is_same<
typename ArrayLayout_t::entity_type,
86 "Array layout entity type mush match solver entity type" );
89 const std::size_t num_space_dim = ArrayLayout_t::num_space_dim;
96 if ( !_is_preconditioner )
99 auto error = HYPRE_SStructGridCreate( _comm, num_space_dim, n_parts,
111 auto global_space = layout.indexSpace(
Own(),
Global() );
112 _lower.resize( num_space_dim );
113 _upper.resize( num_space_dim );
114 for ( std::size_t d = 0; d < num_space_dim; ++d )
116 _lower[d] =
static_cast<HYPRE_Int
>(
117 global_space.min( num_space_dim - d - 1 ) );
118 _upper[d] =
static_cast<HYPRE_Int
>(
119 global_space.max( num_space_dim - d - 1 ) - 1 );
121 error = HYPRE_SStructGridSetExtents( _grid, part, _lower.data(),
126 const auto& global_grid = layout.localGrid()->globalGrid();
127 HYPRE_Int periodic[num_space_dim];
128 for ( std::size_t d = 0; d < num_space_dim; ++d )
129 periodic[num_space_dim - 1 - d] =
130 global_grid.isPeriodic( d )
131 ? layout.localGrid()->globalGrid().globalNumEntity(
134 error = HYPRE_SStructGridSetPeriodic( _grid, part, periodic );
138 std::vector<HYPRE_SStructVariable> vartypes;
139 vartypes.resize( n_vars );
140 for (
int i = 0; i < n_vars; ++i )
142 vartypes[i] = HYPRE_SSTRUCT_VARIABLE_CELL;
144 error = HYPRE_SStructGridSetVariables( _grid, part, n_vars,
148 error = HYPRE_SStructGridAssemble( _grid );
154 std::array<long, num_space_dim + 1> reorder_size;
155 for ( std::size_t d = 0; d < num_space_dim; ++d )
157 reorder_size[d] = global_space.extent( d );
159 reorder_size.back() = n_vars;
163 "vector_values0", reorder_space );
164 Kokkos::deep_copy( vector_values, 0.0 );
166 _stencils.resize( n_vars );
167 _stencil_size.resize( n_vars );
168 _stencil_index.resize( n_vars,
169 std::vector<unsigned>( n_vars + 1 ) );
171 error = HYPRE_SStructVectorCreate( _comm, _grid, &
_b );
175 error = HYPRE_SStructVectorInitialize(
_b );
177 for (
int i = 0; i < n_vars; ++i )
179 error = HYPRE_SStructVectorSetBoxValues(
180 _b, part, _lower.data(), _upper.data(), i,
181 vector_values.data() );
184 error = HYPRE_SStructVectorAssemble(
_b );
187 error = HYPRE_SStructVectorCreate( _comm, _grid, &
_x );
191 error = HYPRE_SStructVectorInitialize(
_x );
193 for (
int i = 0; i < n_vars; ++i )
195 error = HYPRE_SStructVectorSetBoxValues(
196 _x, part, _lower.data(), _upper.data(), i,
197 vector_values.data() );
201 error = HYPRE_SStructVectorAssemble(
_x );
210 if ( !_is_preconditioner )
212 HYPRE_SStructVectorDestroy(
_x );
213 HYPRE_SStructVectorDestroy(
_b );
214 HYPRE_SStructMatrixDestroy(
_A );
215 for ( std::size_t i = 0; i < _stencils.size(); ++i )
217 HYPRE_SStructStencilDestroy( _stencils[i] );
219 HYPRE_SStructGridDestroy( _grid );
220 HYPRE_SStructGraphDestroy( _graph );
240 std::vector<unsigned> stencil_length = { 7, 7,
244 if ( _is_preconditioner )
245 throw std::logic_error(
246 "Cannot call createMatrixStencil() on preconditioners" );
250 for (
int i = 0; i < n_vars; ++i )
252 _stencil_index[var][i] = index;
253 index += stencil_length[i];
255 _stencil_index[var][n_vars] = index;
258 _stencil_size[var] = index;
259 auto error = HYPRE_SStructStencilCreate(
260 NumSpaceDim, _stencil_size[var], &_stencils[var] );
273 template <std::
size_t NumSpaceDim>
276 int var = 0,
int dep = 0 )
279 if ( _is_preconditioner )
280 throw std::logic_error(
281 "Cannot call setMatrixStencil() on preconditioners" );
283 std::array<HYPRE_Int, NumSpaceDim> offset;
285 auto index = _stencil_index[var][dep];
286 for (
unsigned n = index; n < index + stencil.size(); ++n )
288 for ( std::size_t d = 0; d < NumSpaceDim; ++d )
289 offset[d] = stencil[n - index][d];
290 auto error = HYPRE_SStructStencilSetEntry( _stencils[var], n,
291 offset.data(), dep );
304 if ( _is_preconditioner )
305 throw std::logic_error(
306 "Cannot call setSolverGraph() on preconditioners" );
312 auto error = HYPRE_SStructGraphCreate( _comm, _grid, &_graph );
316 error = HYPRE_SStructGraphSetObjectType( _graph,
object_type );
320 for (
int i = 0; i < n_vars; ++i )
323 HYPRE_SStructGraphSetStencil( _graph, part, i, _stencils[i] );
328 error = HYPRE_SStructGraphAssemble( _graph );
332 error = HYPRE_SStructMatrixCreate( _comm, _graph, &
_A );
340 error = HYPRE_SStructMatrixInitialize(
_A );
356 template <
class Array_t>
361 std::is_same<typename Array_t::entity_type, entity_type>::value,
362 "Array entity type mush match solver entity type" );
364 std::is_same<typename Array_t::memory_space, MemorySpace>::value,
365 "Array device type and solver device type are different." );
368 std::is_same<typename Array_t::value_type, value_type>::value,
369 "Array value type and solver value type are different." );
372 if ( _is_preconditioner )
373 throw std::logic_error(
374 "Cannot call setMatrixValues() on preconditioners" );
377 _stencil_index[v_h][v_x + 1] - _stencil_index[v_h][v_x];
380 if ( values.layout()->dofsPerEntity() !=
381 static_cast<int>( index_size ) )
382 throw std::runtime_error(
383 "Number of matrix values does not match stencil size" );
386 const std::size_t num_space_dim = Array_t::num_space_dim;
392 auto owned_space = values.layout()->indexSpace(
Own(),
Local() );
393 std::array<long, num_space_dim + 1> reorder_size;
394 for ( std::size_t d = 0; d < num_space_dim; ++d )
396 reorder_size[d] = owned_space.extent( d );
399 reorder_size.back() = index_size;
403 "a_values", reorder_space );
405 auto values_subv =
createSubview( values.view(), owned_space );
406 Kokkos::deep_copy( a_values, values_subv );
409 std::vector<HYPRE_Int> indices( index_size );
410 int start = _stencil_index[v_h][v_x];
411 std::iota( indices.begin(), indices.end(), start );
412 auto error = HYPRE_SStructMatrixSetBoxValues(
413 _A, part, _lower.data(), _upper.data(), v_h, indices.size(),
414 indices.data(), a_values.data() );
424 HYPRE_SStructMatrixPrint( prefix,
_A, 0 );
433 HYPRE_SStructVectorPrint( prefix,
_x, 0 );
442 HYPRE_SStructVectorPrint( prefix,
_b, 0 );
460 Scalar, EntityType, MemorySpace>>& preconditioner )
463 if ( _is_preconditioner )
464 throw std::logic_error(
465 "Cannot call setPreconditioner() on a preconditioner" );
468 if ( !preconditioner->isPreconditioner() )
469 throw std::logic_error(
"Not a preconditioner" );
471 _preconditioner = preconditioner;
479 if ( _is_preconditioner )
480 throw std::logic_error(
"Cannot call setup() on preconditioners" );
482 auto error = HYPRE_SStructMatrixAssemble(
_A );
494 template <
class Array_t>
495 void solve(
const Array_t& b, Array_t& x,
int n_vars = 3 )
497 Kokkos::Profiling::ScopedRegion region(
498 "Cabana::Grid::HypreSemiStructuredSolver::solve" );
502 std::is_same<typename Array_t::entity_type, entity_type>::value,
503 "Array entity type mush match solver entity type" );
505 std::is_same<typename Array_t::memory_space, MemorySpace>::value,
506 "Array device type and solver device type are different." );
509 std::is_same<typename Array_t::value_type, value_type>::value,
510 "Array value type and solver value type are different." );
513 if ( _is_preconditioner )
514 throw std::logic_error(
"Cannot call solve() on preconditioners" );
517 const std::size_t num_space_dim = Array_t::num_space_dim;
522 auto owned_space = b.layout()->indexSpace(
Own(),
Local() );
523 std::array<long, num_space_dim + 1> reorder_min;
524 std::array<long, num_space_dim + 1> reorder_max;
525 for ( std::size_t d = 0; d < num_space_dim; ++d )
527 reorder_min[d] = owned_space.min( d );
528 reorder_max[d] = owned_space.max( d );
536 for (
int var = 0; var < n_vars; ++var )
538 reorder_min.back() = var;
539 reorder_max.back() = var + 1;
545 "vector_values", reorder_space );
549 Kokkos::deep_copy( b_values, b_subv );
550 error = HYPRE_SStructVectorSetBoxValues(
551 _b, part, _lower.data(), _upper.data(), var, b_values.data() );
555 error = HYPRE_SStructVectorAssemble(
_b );
562 for (
int var = 0; var < n_vars; ++var )
564 reorder_min.back() = var;
565 reorder_max.back() = var + 1;
571 "vector_values", reorder_space );
576 error = HYPRE_SStructVectorGetBoxValues(
577 _x, part, _lower.data(), _upper.data(), var, x_values.data() );
582 Kokkos::deep_copy( x_subv, x_values );
627 preconditioner ) = 0;
635 HYPRE_DescribeError( error, error_msg );
636 std::stringstream out;
637 out <<
"HYPRE semi-structured solver error: ";
638 out << error <<
" " << error_msg;
639 HYPRE_ClearError( error );
640 throw std::runtime_error( out.str() );
645 HYPRE_SStructMatrix
_A;
647 HYPRE_SStructVector
_b;
649 HYPRE_SStructVector
_x;
653 bool _is_preconditioner;
654 HYPRE_SStructGrid _grid;
655 std::vector<HYPRE_Int> _lower;
656 std::vector<HYPRE_Int> _upper;
657 std::vector<HYPRE_SStructStencil> _stencils;
658 HYPRE_SStructGraph _graph;
659 std::vector<unsigned> _stencil_size;
660 std::vector<std::vector<unsigned>> _stencil_index;
661 std::shared_ptr<HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>>
667template <
class Scalar,
class EntityType,
class MemorySpace>
676 template <
class ArrayLayout_t>
678 const bool is_preconditioner =
false )
679 :
base_type( layout, n_vars, is_preconditioner )
681 if ( is_preconditioner )
682 throw std::logic_error(
683 "HYPRE PCG cannot be used as a preconditioner" );
685 auto error = HYPRE_SStructPCGCreate(
686 layout.localGrid()->globalGrid().comm(), &_solver );
689 HYPRE_SStructPCGSetTwoNorm( _solver, 1 );
699 auto error = HYPRE_SStructPCGSetAbsoluteTol( _solver, tol );
707 auto error = HYPRE_SStructPCGSetRelChange( _solver, rel_change );
714 auto error = HYPRE_SStructPCGSetLogging( _solver, logging );
721 return HYPRE_SStructPCGSetup;
725 return HYPRE_SStructPCGSolve;
731 auto error = HYPRE_SStructPCGSetTol( _solver, tol );
737 auto error = HYPRE_SStructPCGSetMaxIter( _solver, max_iter );
743 auto error = HYPRE_SStructPCGSetPrintLevel( _solver, print_level );
749 auto error = HYPRE_SStructPCGSetup( _solver, _A, _b, _x );
755 auto error = HYPRE_SStructPCGSolve( _solver, _A, _b, _x );
762 auto error = HYPRE_SStructPCGGetNumIterations( _solver, &num_iter );
771 HYPRE_SStructPCGGetFinalRelativeResidualNorm( _solver, &norm );
778 preconditioner )
override
780 auto error = HYPRE_SStructPCGSetPrecond(
788 HYPRE_SStructSolver _solver;
796template <
class Scalar,
class EntityType,
class MemorySpace>
805 template <
class ArrayLayout_t>
807 const bool is_preconditioner =
false )
808 :
base_type( layout, n_vars, is_preconditioner )
810 if ( is_preconditioner )
811 throw std::logic_error(
812 "HYPRE GMRES cannot be used as a preconditioner" );
814 auto error = HYPRE_SStructGMRESCreate(
815 layout.localGrid()->globalGrid().comm(), &_solver );
826 auto error = HYPRE_SStructGMRESSetAbsoluteTol( _solver, tol );
833 auto error = HYPRE_SStructGMRESSetKDim( _solver, k_dim );
840 auto error = HYPRE_SStructGMRESSetLogging( _solver, logging );
847 return HYPRE_SStructGMRESSetup;
851 return HYPRE_SStructGMRESSolve;
857 auto error = HYPRE_SStructGMRESSetTol( _solver, tol );
863 auto error = HYPRE_SStructGMRESSetMaxIter( _solver, max_iter );
869 auto error = HYPRE_SStructGMRESSetPrintLevel( _solver, print_level );
875 auto error = HYPRE_SStructGMRESSetup( _solver, _A, _b, _x );
881 auto error = HYPRE_SStructGMRESSolve( _solver, _A, _b, _x );
888 auto error = HYPRE_SStructGMRESGetNumIterations( _solver, &num_iter );
897 HYPRE_SStructGMRESGetFinalRelativeResidualNorm( _solver, &norm );
904 preconditioner )
override
906 auto error = HYPRE_SStructGMRESSetPrecond(
914 HYPRE_SStructSolver _solver;
922template <
class Scalar,
class EntityType,
class MemorySpace>
931 template <
class ArrayLayout_t>
933 const bool is_preconditioner =
false,
935 :
base_type( layout, n_vars, is_preconditioner )
937 if ( is_preconditioner )
938 throw std::logic_error(
939 "HYPRE BiCGSTAB cannot be used as a preconditioner" );
941 auto error = HYPRE_SStructBiCGSTABCreate(
942 layout.localGrid()->globalGrid().comm(), &_solver );
953 auto error = HYPRE_SStructBiCGSTABSetAbsoluteTol( _solver, tol );
960 auto error = HYPRE_SStructBiCGSTABSetLogging( _solver, logging );
967 return HYPRE_SStructBiCGSTABSetup;
971 return HYPRE_SStructBiCGSTABSolve;
977 auto error = HYPRE_SStructBiCGSTABSetTol( _solver, tol );
983 auto error = HYPRE_SStructBiCGSTABSetMaxIter( _solver, max_iter );
989 auto error = HYPRE_SStructBiCGSTABSetPrintLevel( _solver, print_level );
995 auto error = HYPRE_SStructBiCGSTABSetup( _solver, _A, _b, _x );
1001 auto error = HYPRE_SStructBiCGSTABSolve( _solver, _A, _b, _x );
1009 HYPRE_SStructBiCGSTABGetNumIterations( _solver, &num_iter );
1018 HYPRE_SStructBiCGSTABGetFinalRelativeResidualNorm( _solver, &norm );
1025 preconditioner )
override
1027 auto error = HYPRE_SStructBiCGSTABSetPrecond(
1035 HYPRE_SStructSolver _solver;
1043template <
class Scalar,
class EntityType,
class MemorySpace>
1052 template <
class ArrayLayout_t>
1054 const bool is_preconditioner =
false,
1056 :
base_type( layout, n_vars, is_preconditioner )
1058 if ( !is_preconditioner )
1059 throw std::logic_error(
1060 "Diagonal preconditioner cannot be used as a solver" );
1066 return HYPRE_SStructDiagScaleSetup;
1070 return HYPRE_SStructDiagScale;
1076 throw std::logic_error(
1077 "Diagonal preconditioner cannot be used as a solver" );
1082 throw std::logic_error(
1083 "Diagonal preconditioner cannot be used as a solver" );
1088 throw std::logic_error(
1089 "Diagonal preconditioner cannot be used as a solver" );
1094 throw std::logic_error(
1095 "Diagonal preconditioner cannot be used as a solver" );
1100 throw std::logic_error(
1101 "Diagonal preconditioner cannot be used as a solver" );
1106 throw std::logic_error(
1107 "Diagonal preconditioner cannot be used as a solver" );
1112 throw std::logic_error(
1113 "Diagonal preconditioner cannot be used as a solver" );
1120 throw std::logic_error(
1121 "Diagonal preconditioner does not support preconditioning." );
1129template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1130std::shared_ptr<HypreSemiStructPCG<Scalar,
typename ArrayLayout_t::entity_type,
1133 const bool is_preconditioner =
false,
int n_vars = 3 )
1136 "Must use an array layout" );
1138 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1139 layout, n_vars, is_preconditioner );
1143template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1144std::shared_ptr<HypreSemiStructGMRES<
1145 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1147 const bool is_preconditioner =
false,
1151 "Must use an array layout" );
1153 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1154 layout, n_vars, is_preconditioner );
1158template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1159std::shared_ptr<HypreSemiStructBiCGSTAB<
1160 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1162 const bool is_preconditioner =
false,
1166 "Must use an array layout" );
1168 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1169 layout, is_preconditioner, n_vars );
1173template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1174std::shared_ptr<HypreSemiStructDiagonal<
1175 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1177 const bool is_preconditioner =
false,
1181 "Must use an array layout" );
1183 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1184 layout, is_preconditioner, n_vars );
1198template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1199std::shared_ptr<HypreSemiStructuredSolver<
1200 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1202 const ArrayLayout_t& layout,
1203 const bool is_preconditioner =
false,
1207 "Must use an array layout" );
1209 if (
"PCG" == solver_type )
1211 layout, is_preconditioner, n_vars );
1212 else if (
"GMRES" == solver_type )
1214 layout, is_preconditioner, n_vars );
1215 else if (
"BiCGSTAB" == solver_type )
1217 layout, is_preconditioner, n_vars );
1218 else if (
"Diagonal" == solver_type )
1220 layout, is_preconditioner, n_vars );
1222 throw std::runtime_error(
"Invalid solver type" );
std::shared_ptr< HypreSemiStructPCG< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreSemiStructPCG(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Create a HYPRE PCG semi-structured solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1132
std::shared_ptr< HypreSemiStructuredSolver< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreSemiStructuredSolver(const std::string &solver_type, const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Create a HYPRE semi-structured solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1201
std::shared_ptr< HypreSemiStructBiCGSTAB< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreSemiStructBiCGSTAB(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Create a HYPRE BiCGSTAB semi-structured solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1161
std::shared_ptr< HypreSemiStructGMRES< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreSemiStructGMRES(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Create a HYPRE GMRES semi-structured solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1146
std::shared_ptr< HypreSemiStructDiagonal< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreSemiStructDiagonal(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Create a HYPRE Diagonal semi-structured solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1176
HYPRE memory space handling.
KOKKOS_INLINE_FUNCTION auto createSubview(const ViewType &view, const IndexSpace< 1 > &index_space) -> decltype(Kokkos::subview(view, index_space.range(0)))
Given a view create a subview over the given index space.
Definition Cabana_Grid_IndexSpace.hpp:369
Kokkos::View< Scalar *, Params... > createView(const std::string &label, const IndexSpace< 1 > &index_space)
Given an index space create a view over the extent of that index space.
Definition Cabana_Grid_IndexSpace.hpp:235
BiCGSTAB solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:925
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:999
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1014
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:965
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:993
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:958
HypreSemiStructBiCGSTAB(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:932
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:964
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:928
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1005
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:987
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:981
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:969
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1023
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:951
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:975
Diagonal preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1046
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1049
void setMaxIterImpl(const int) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1080
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1104
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1068
void setPrintLevelImpl(const int) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1086
void setToleranceImpl(const double) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1074
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1098
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1116
HypreSemiStructDiagonal(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1053
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1110
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1063
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1092
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1064
GMRES solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:799
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:867
HypreSemiStructGMRES(const ArrayLayout_t &layout, int n_vars, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:806
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:861
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:855
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:802
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:885
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:849
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:893
void setKDim(const int k_dim)
Set the max size of the Krylov space.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:831
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:879
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:873
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:845
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:844
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:838
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:902
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:824
PCG solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:670
HypreSemiStructPCG(const ArrayLayout_t &layout, int n_vars, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:677
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:723
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:712
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:767
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:719
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:776
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:753
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:741
void setRelChange(const int rel_change)
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:705
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:735
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:718
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:747
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:697
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:673
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:759
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:729
Hypre semi-structured solver interface for scalar fields.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:52
virtual void setToleranceImpl(const double tol)=0
Set convergence tolerance implementation.
void setup()
Setup the problem.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:476
void printLHS(const char *prefix)
Print the hypre LHS to output file.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:431
const int object_type
Object Type for SStruct.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:61
void setPrintLevel(const int print_level)
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:452
int getNumIter()
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:587
void setPreconditioner(const std::shared_ptr< HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > > &preconditioner)
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:459
virtual HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const =0
Get the preconditioner setup function.
void solve(const Array_t &b, Array_t &x, int n_vars=3)
Solve the problem Ax = b for x.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:495
void setMaxIter(const int max_iter)
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:449
virtual int getNumIterImpl()=0
Get the number of iterations taken on the last solve.
HYPRE_SStructMatrix _A
Matrix for the problem Ax = b.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:645
virtual double getFinalRelativeResidualNormImpl()=0
Get the relative residual norm achieved on the last solve.
virtual void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner)=0
Set a preconditioner.
double getFinalRelativeResidualNorm()
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:590
void setMatrixValues(const Array_t &values, int v_x, int v_h)
Set the matrix values.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:357
void setTolerance(const double tol)
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:446
virtual void solveImpl()=0
Solver implementation.
virtual void setMaxIterImpl(const int max_iter)=0
Set maximum iteration implementation.
HypreSemiStructuredSolver(const ArrayLayout_t &layout, int n_vars, const bool is_preconditioner=false)
Hypre memory space compatibility check.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:74
MemorySpace memory_space
Kokkos memory space..
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:57
virtual void setPrintLevelImpl(const int print_level)=0
Set the output level.
void setSolverGraph(int n_vars)
Set the solver graph.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:301
void printRHS(const char *prefix)
Print the hypre RHS to output file.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:440
EntityType entity_type
Entity type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:55
void checkHypreError(const int error) const
Check a hypre error.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:630
virtual void setupImpl()=0
Setup implementation.
void createMatrixStencil(int NumSpaceDim, int var=0, int n_vars=3, std::vector< unsigned > stencil_length={ 7, 7, 7 })
Create the operator stencil to be filled by setMatrixStencil.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:239
void setMatrixStencil(const std::vector< std::array< int, NumSpaceDim > > &stencil, int var=0, int dep=0)
Set the operator stencil.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:275
HYPRE_SStructVector _x
Solution to the problem Ax = b.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:649
bool isPreconditioner() const
Return if this solver is a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:227
virtual HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const =0
Get the preconditioner solve function.
void printMatrix(const char *prefix)
Print the hypre matrix to output file.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:422
Scalar value_type
Scalar value type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:59
HYPRE_SStructVector _b
Forcing term for the problem Ax = b.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:647
virtual HYPRE_SStructSolver getHypreSolver() const =0
Get the preconditioner.
Structured index space.
Definition Cabana_Grid_IndexSpace.hpp:37
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
Global index tag.
Definition Cabana_Grid_Types.hpp:215
Hypre device compatibility check.
Definition Cabana_Grid_Hypre.hpp:39
Local index tag.
Definition Cabana_Grid_Types.hpp:208
Owned decomposition tag.
Definition Cabana_Grid_Types.hpp:190
Array static type checker.
Definition Cabana_Grid_Array.hpp:160
Definition Cabana_Grid_Array.hpp:322