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 must 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 must 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 "Cabana::Grid::HypreSemiStructuredSolver::setMatrixValues: "
384 "Number of matrix values does not match stencil size" );
387 const std::size_t num_space_dim = Array_t::num_space_dim;
393 auto owned_space = values.layout()->indexSpace(
Own(),
Local() );
394 std::array<long, num_space_dim + 1> reorder_size;
395 for ( std::size_t d = 0; d < num_space_dim; ++d )
397 reorder_size[d] = owned_space.extent( d );
400 reorder_size.back() = index_size;
404 "a_values", reorder_space );
406 auto values_subv =
createSubview( values.view(), owned_space );
407 Kokkos::deep_copy( a_values, values_subv );
410 std::vector<HYPRE_Int> indices( index_size );
411 int start = _stencil_index[v_h][v_x];
412 std::iota( indices.begin(), indices.end(), start );
413 auto error = HYPRE_SStructMatrixSetBoxValues(
414 _A, part, _lower.data(), _upper.data(), v_h, indices.size(),
415 indices.data(), a_values.data() );
425 HYPRE_SStructMatrixPrint( prefix,
_A, 0 );
434 HYPRE_SStructVectorPrint( prefix,
_x, 0 );
443 HYPRE_SStructVectorPrint( prefix,
_b, 0 );
461 Scalar, EntityType, MemorySpace>>& preconditioner )
464 if ( _is_preconditioner )
465 throw std::logic_error(
466 "Cannot call setPreconditioner() on a preconditioner" );
469 if ( !preconditioner->isPreconditioner() )
470 throw std::logic_error(
"Not a preconditioner" );
472 _preconditioner = preconditioner;
480 if ( _is_preconditioner )
481 throw std::logic_error(
"Cannot call setup() on preconditioners" );
483 auto error = HYPRE_SStructMatrixAssemble(
_A );
495 template <
class Array_t>
496 void solve(
const Array_t& b, Array_t& x,
int n_vars = 3 )
498 Kokkos::Profiling::ScopedRegion region(
499 "Cabana::Grid::HypreSemiStructuredSolver::solve" );
503 std::is_same<typename Array_t::entity_type, entity_type>::value,
504 "Array entity type must match solver entity type" );
506 std::is_same<typename Array_t::memory_space, MemorySpace>::value,
507 "Array device type and solver device type are different." );
510 std::is_same<typename Array_t::value_type, value_type>::value,
511 "Array value type and solver value type are different." );
514 if ( _is_preconditioner )
515 throw std::logic_error(
"Cannot call solve() on preconditioners" );
518 const std::size_t num_space_dim = Array_t::num_space_dim;
523 auto owned_space = b.layout()->indexSpace(
Own(),
Local() );
524 std::array<long, num_space_dim + 1> reorder_min;
525 std::array<long, num_space_dim + 1> reorder_max;
526 for ( std::size_t d = 0; d < num_space_dim; ++d )
528 reorder_min[d] = owned_space.min( d );
529 reorder_max[d] = owned_space.max( d );
537 for (
int var = 0; var < n_vars; ++var )
539 reorder_min.back() = var;
540 reorder_max.back() = var + 1;
546 "vector_values", reorder_space );
550 Kokkos::deep_copy( b_values, b_subv );
551 error = HYPRE_SStructVectorSetBoxValues(
552 _b, part, _lower.data(), _upper.data(), var, b_values.data() );
556 error = HYPRE_SStructVectorAssemble(
_b );
563 for (
int var = 0; var < n_vars; ++var )
565 reorder_min.back() = var;
566 reorder_max.back() = var + 1;
572 "vector_values", reorder_space );
577 error = HYPRE_SStructVectorGetBoxValues(
578 _x, part, _lower.data(), _upper.data(), var, x_values.data() );
583 Kokkos::deep_copy( x_subv, x_values );
628 preconditioner ) = 0;
636 HYPRE_DescribeError( error, error_msg );
637 std::stringstream out;
638 out <<
"HYPRE semi-structured solver error: ";
639 out << error <<
" " << error_msg;
640 HYPRE_ClearError( error );
641 throw std::runtime_error( out.str() );
646 HYPRE_SStructMatrix
_A;
648 HYPRE_SStructVector
_b;
650 HYPRE_SStructVector
_x;
654 bool _is_preconditioner;
655 HYPRE_SStructGrid _grid;
656 std::vector<HYPRE_Int> _lower;
657 std::vector<HYPRE_Int> _upper;
658 std::vector<HYPRE_SStructStencil> _stencils;
659 HYPRE_SStructGraph _graph;
660 std::vector<unsigned> _stencil_size;
661 std::vector<std::vector<unsigned>> _stencil_index;
662 std::shared_ptr<HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>>
668template <
class Scalar,
class EntityType,
class MemorySpace>
677 template <
class ArrayLayout_t>
679 const bool is_preconditioner =
false )
680 :
base_type( layout, n_vars, is_preconditioner )
682 if ( is_preconditioner )
683 throw std::logic_error(
684 "HYPRE PCG cannot be used as a preconditioner" );
686 auto error = HYPRE_SStructPCGCreate(
687 layout.localGrid()->globalGrid().comm(), &_solver );
690 HYPRE_SStructPCGSetTwoNorm( _solver, 1 );
700 auto error = HYPRE_SStructPCGSetAbsoluteTol( _solver, tol );
708 auto error = HYPRE_SStructPCGSetRelChange( _solver, rel_change );
715 auto error = HYPRE_SStructPCGSetLogging( _solver, logging );
722 return HYPRE_SStructPCGSetup;
726 return HYPRE_SStructPCGSolve;
732 auto error = HYPRE_SStructPCGSetTol( _solver, tol );
738 auto error = HYPRE_SStructPCGSetMaxIter( _solver, max_iter );
744 auto error = HYPRE_SStructPCGSetPrintLevel( _solver, print_level );
750 auto error = HYPRE_SStructPCGSetup( _solver, _A, _b, _x );
756 auto error = HYPRE_SStructPCGSolve( _solver, _A, _b, _x );
763 auto error = HYPRE_SStructPCGGetNumIterations( _solver, &num_iter );
772 HYPRE_SStructPCGGetFinalRelativeResidualNorm( _solver, &norm );
779 preconditioner )
override
781 auto error = HYPRE_SStructPCGSetPrecond(
789 HYPRE_SStructSolver _solver;
797template <
class Scalar,
class EntityType,
class MemorySpace>
806 template <
class ArrayLayout_t>
808 const bool is_preconditioner =
false )
809 :
base_type( layout, n_vars, is_preconditioner )
811 if ( is_preconditioner )
812 throw std::logic_error(
813 "HYPRE GMRES cannot be used as a preconditioner" );
815 auto error = HYPRE_SStructGMRESCreate(
816 layout.localGrid()->globalGrid().comm(), &_solver );
827 auto error = HYPRE_SStructGMRESSetAbsoluteTol( _solver, tol );
834 auto error = HYPRE_SStructGMRESSetKDim( _solver, k_dim );
841 auto error = HYPRE_SStructGMRESSetLogging( _solver, logging );
848 return HYPRE_SStructGMRESSetup;
852 return HYPRE_SStructGMRESSolve;
858 auto error = HYPRE_SStructGMRESSetTol( _solver, tol );
864 auto error = HYPRE_SStructGMRESSetMaxIter( _solver, max_iter );
870 auto error = HYPRE_SStructGMRESSetPrintLevel( _solver, print_level );
876 auto error = HYPRE_SStructGMRESSetup( _solver, _A, _b, _x );
882 auto error = HYPRE_SStructGMRESSolve( _solver, _A, _b, _x );
889 auto error = HYPRE_SStructGMRESGetNumIterations( _solver, &num_iter );
898 HYPRE_SStructGMRESGetFinalRelativeResidualNorm( _solver, &norm );
905 preconditioner )
override
907 auto error = HYPRE_SStructGMRESSetPrecond(
915 HYPRE_SStructSolver _solver;
923template <
class Scalar,
class EntityType,
class MemorySpace>
932 template <
class ArrayLayout_t>
934 const bool is_preconditioner =
false,
936 :
base_type( layout, n_vars, is_preconditioner )
938 if ( is_preconditioner )
939 throw std::logic_error(
940 "HYPRE BiCGSTAB cannot be used as a preconditioner" );
942 auto error = HYPRE_SStructBiCGSTABCreate(
943 layout.localGrid()->globalGrid().comm(), &_solver );
954 auto error = HYPRE_SStructBiCGSTABSetAbsoluteTol( _solver, tol );
961 auto error = HYPRE_SStructBiCGSTABSetLogging( _solver, logging );
968 return HYPRE_SStructBiCGSTABSetup;
972 return HYPRE_SStructBiCGSTABSolve;
978 auto error = HYPRE_SStructBiCGSTABSetTol( _solver, tol );
984 auto error = HYPRE_SStructBiCGSTABSetMaxIter( _solver, max_iter );
990 auto error = HYPRE_SStructBiCGSTABSetPrintLevel( _solver, print_level );
996 auto error = HYPRE_SStructBiCGSTABSetup( _solver, _A, _b, _x );
1002 auto error = HYPRE_SStructBiCGSTABSolve( _solver, _A, _b, _x );
1010 HYPRE_SStructBiCGSTABGetNumIterations( _solver, &num_iter );
1019 HYPRE_SStructBiCGSTABGetFinalRelativeResidualNorm( _solver, &norm );
1026 preconditioner )
override
1028 auto error = HYPRE_SStructBiCGSTABSetPrecond(
1036 HYPRE_SStructSolver _solver;
1044template <
class Scalar,
class EntityType,
class MemorySpace>
1053 template <
class ArrayLayout_t>
1055 const bool is_preconditioner =
false,
1057 :
base_type( layout, n_vars, is_preconditioner )
1059 if ( !is_preconditioner )
1060 throw std::logic_error(
1061 "Diagonal preconditioner cannot be used as a solver" );
1067 return HYPRE_SStructDiagScaleSetup;
1071 return HYPRE_SStructDiagScale;
1077 throw std::logic_error(
1078 "Diagonal preconditioner cannot be used as a solver" );
1083 throw std::logic_error(
1084 "Diagonal preconditioner cannot be used as a solver" );
1089 throw std::logic_error(
1090 "Diagonal preconditioner cannot be used as a solver" );
1095 throw std::logic_error(
1096 "Diagonal preconditioner cannot be used as a solver" );
1101 throw std::logic_error(
1102 "Diagonal preconditioner cannot be used as a solver" );
1107 throw std::logic_error(
1108 "Diagonal preconditioner cannot be used as a solver" );
1113 throw std::logic_error(
1114 "Diagonal preconditioner cannot be used as a solver" );
1121 throw std::logic_error(
1122 "Diagonal preconditioner does not support preconditioning." );
1130template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1131std::shared_ptr<HypreSemiStructPCG<Scalar,
typename ArrayLayout_t::entity_type,
1134 const bool is_preconditioner =
false,
int n_vars = 3 )
1137 "Must use an array layout" );
1139 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1140 layout, n_vars, is_preconditioner );
1144template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1145std::shared_ptr<HypreSemiStructGMRES<
1146 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1148 const bool is_preconditioner =
false,
1152 "Must use an array layout" );
1154 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1155 layout, n_vars, is_preconditioner );
1159template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1160std::shared_ptr<HypreSemiStructBiCGSTAB<
1161 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1163 const bool is_preconditioner =
false,
1167 "Must use an array layout" );
1169 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1170 layout, is_preconditioner, n_vars );
1174template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1175std::shared_ptr<HypreSemiStructDiagonal<
1176 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1178 const bool is_preconditioner =
false,
1182 "Must use an array layout" );
1184 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>(
1185 layout, is_preconditioner, n_vars );
1199template <
class Scalar,
class MemorySpace,
class ArrayLayout_t>
1200std::shared_ptr<HypreSemiStructuredSolver<
1201 Scalar,
typename ArrayLayout_t::entity_type, MemorySpace>>
1203 const ArrayLayout_t& layout,
1204 const bool is_preconditioner =
false,
1208 "Must use an array layout" );
1210 if (
"PCG" == solver_type )
1212 layout, is_preconditioner, n_vars );
1213 else if (
"GMRES" == solver_type )
1215 layout, is_preconditioner, n_vars );
1216 else if (
"BiCGSTAB" == solver_type )
1218 layout, is_preconditioner, n_vars );
1219 else if (
"Diagonal" == solver_type )
1221 layout, is_preconditioner, n_vars );
1223 throw std::runtime_error(
1224 "Cabana::Grid::createHypreSemiStructuredSolver: Invalid solver "
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:1133
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:1202
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:1162
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:1147
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:1177
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:926
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1000
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1015
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:966
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:994
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:959
HypreSemiStructBiCGSTAB(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:933
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:965
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:929
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1006
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:988
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:982
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:970
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1024
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:952
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:976
Diagonal preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1047
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1050
void setMaxIterImpl(const int) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1081
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1105
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1069
void setPrintLevelImpl(const int) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1087
void setToleranceImpl(const double) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1075
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1099
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1117
HypreSemiStructDiagonal(const ArrayLayout_t &layout, const bool is_preconditioner=false, int n_vars=3)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1054
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1111
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1064
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1093
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:1065
GMRES solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:800
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:868
HypreSemiStructGMRES(const ArrayLayout_t &layout, int n_vars, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:807
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:862
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:856
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:803
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:886
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:850
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:894
void setKDim(const int k_dim)
Set the max size of the Krylov space.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:832
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:880
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:874
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:846
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:845
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:839
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:903
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:825
PCG solver.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:671
HypreSemiStructPCG(const ArrayLayout_t &layout, int n_vars, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:678
HYPRE_PtrToSStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:724
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:713
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:768
HYPRE_PtrToSStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:720
void setPreconditionerImpl(const HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:777
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:754
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:742
void setRelChange(const int rel_change)
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:706
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:736
HYPRE_SStructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:719
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:748
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:698
HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE semi-structured solver type.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:674
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:760
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:730
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:477
void printLHS(const char *prefix)
Print the hypre LHS to output file.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:432
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:453
int getNumIter()
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:588
void setPreconditioner(const std::shared_ptr< HypreSemiStructuredSolver< Scalar, EntityType, MemorySpace > > &preconditioner)
Set a preconditioner.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:460
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:496
void setMaxIter(const int max_iter)
Set maximum iteration implementation.
Definition Cabana_Grid_HypreSemiStructuredSolver.hpp:450
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:646
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:591
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:447
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:441
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:631
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:650
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:423
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:648
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:324