Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Grid_HypreStructuredSolver.hpp
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2018-2023 by the Cabana authors *
3 * All rights reserved. *
4 * *
5 * This file is part of the Cabana library. Cabana is distributed under a *
6 * BSD 3-clause license. For the licensing terms see the LICENSE file in *
7 * the top-level directory. *
8 * *
9 * SPDX-License-Identifier: BSD-3-Clause *
10 ****************************************************************************/
11
16#ifndef CABANA_GRID_HYPRESTRUCTUREDSOLVER_HPP
17#define CABANA_GRID_HYPRESTRUCTUREDSOLVER_HPP
18
19#include <Cabana_Grid_Array.hpp>
21#include <Cabana_Grid_Hypre.hpp>
24#include <Cabana_Grid_Types.hpp>
25
26#include <HYPRE_config.h>
27#include <HYPRE_struct_ls.h>
28#include <HYPRE_struct_mv.h>
29
30#include <Kokkos_Core.hpp>
31#include <Kokkos_Profiling_ScopedRegion.hpp>
32
33#include <array>
34#include <memory>
35#include <numeric>
36#include <sstream>
37#include <string>
38#include <type_traits>
39#include <vector>
40
41namespace Cabana
42{
43namespace Grid
44{
45//---------------------------------------------------------------------------//
47template <class Scalar, class EntityType, class MemorySpace>
49{
50 public:
52 using entity_type = EntityType;
54 using memory_space = MemorySpace;
56 using value_type = Scalar;
59 "HYPRE not compatible with solver memory space" );
60
67 template <class ArrayLayout_t>
68 HypreStructuredSolver( const ArrayLayout_t& layout,
69 const bool is_preconditioner = false )
70 : _comm( layout.localGrid()->globalGrid().comm() )
71 , _is_preconditioner( is_preconditioner )
72 {
73 static_assert(
75 "Cabana::Grid::HypreStructuredSolver: Must use an array layout" );
76 static_assert( std::is_same<typename ArrayLayout_t::entity_type,
77 entity_type>::value,
78 "Cabana::Grid::HypreStructuredSolver: Array layout "
79 "entity type must match solver entity type" );
80
81 // Spatial dimension.
82 const std::size_t num_space_dim = ArrayLayout_t::num_space_dim;
83
84 // Only create data structures if this is not a preconditioner.
85 if ( !_is_preconditioner )
86 {
87 // Create the grid.
88 auto error = HYPRE_StructGridCreate( _comm, num_space_dim, &_grid );
89 checkHypreError( error );
90
91 // Get the global index space spanned by the local grid on this
92 // rank. Note that the upper bound is not a bound but rather the
93 // last index as this is what Hypre wants. Note that we reordered
94 // this to KJI from IJK to be consistent with HYPRE ordering. By
95 // setting up the grid like this, HYPRE will then want layout-right
96 // data indexed as (i,j,k) or (i,j,k,l) which will allow us to
97 // directly use Kokkos::deep_copy to move data between arrays and
98 // HYPRE data structures.
99 auto global_space = layout.indexSpace( Own(), Global() );
100 _lower.resize( num_space_dim );
101 _upper.resize( num_space_dim );
102 for ( std::size_t d = 0; d < num_space_dim; ++d )
103 {
104 _lower[d] = static_cast<HYPRE_Int>(
105 global_space.min( num_space_dim - d - 1 ) );
106 _upper[d] = static_cast<HYPRE_Int>(
107 global_space.max( num_space_dim - d - 1 ) - 1 );
108 }
109 error = HYPRE_StructGridSetExtents( _grid, _lower.data(),
110 _upper.data() );
111 checkHypreError( error );
112
113 // Get periodicity. Note we invert the order of this to KJI as well.
114 const auto& global_grid = layout.localGrid()->globalGrid();
115 HYPRE_Int periodic[num_space_dim];
116 for ( std::size_t d = 0; d < num_space_dim; ++d )
117 periodic[num_space_dim - 1 - d] =
118 global_grid.isPeriodic( d )
119 ? layout.localGrid()->globalGrid().globalNumEntity(
120 EntityType(), d )
121 : 0;
122 error = HYPRE_StructGridSetPeriodic( _grid, periodic );
123 checkHypreError( error );
124
125 // Assemble the grid.
126 error = HYPRE_StructGridAssemble( _grid );
127 checkHypreError( error );
128
129 // Allocate LHS and RHS vectors and initialize to zero. Note that we
130 // are fixing the views under these vectors to layout-right.
131 std::array<long, num_space_dim> reorder_size;
132 for ( std::size_t d = 0; d < num_space_dim; ++d )
133 {
134 reorder_size[d] = global_space.extent( d );
135 }
136 IndexSpace<num_space_dim> reorder_space( reorder_size );
137 auto vector_values =
139 "vector_values", reorder_space );
140 Kokkos::deep_copy( vector_values, 0.0 );
141
142 error = HYPRE_StructVectorCreate( _comm, _grid, &_b );
143 checkHypreError( error );
144 error = HYPRE_StructVectorInitialize( _b );
145 checkHypreError( error );
146 error = HYPRE_StructVectorSetBoxValues(
147 _b, _lower.data(), _upper.data(), vector_values.data() );
148 checkHypreError( error );
149 error = HYPRE_StructVectorAssemble( _b );
150 checkHypreError( error );
151
152 error = HYPRE_StructVectorCreate( _comm, _grid, &_x );
153 checkHypreError( error );
154 error = HYPRE_StructVectorInitialize( _x );
155 checkHypreError( error );
156 error = HYPRE_StructVectorSetBoxValues(
157 _x, _lower.data(), _upper.data(), vector_values.data() );
158 checkHypreError( error );
159 error = HYPRE_StructVectorAssemble( _x );
160 checkHypreError( error );
161 }
162 }
163
164 // Destructor.
165 virtual ~HypreStructuredSolver()
166 {
167 // We only make data if this is not a preconditioner.
168 if ( !_is_preconditioner )
169 {
170 HYPRE_StructVectorDestroy( _x );
171 HYPRE_StructVectorDestroy( _b );
172 HYPRE_StructMatrixDestroy( _A );
173 HYPRE_StructStencilDestroy( _stencil );
174 HYPRE_StructGridDestroy( _grid );
175 }
176 }
177
179 bool isPreconditioner() const { return _is_preconditioner; }
180
189 template <std::size_t NumSpaceDim>
190 void
191 setMatrixStencil( const std::vector<std::array<int, NumSpaceDim>>& stencil,
192 const bool is_symmetric = false )
193 {
194 // This function is only valid for non-preconditioners.
195 if ( _is_preconditioner )
196 throw std::logic_error(
197 "Cannot call setMatrixStencil() on preconditioners" );
198
199 // Create the stencil.
200 _stencil_size = stencil.size();
201 auto error =
202 HYPRE_StructStencilCreate( NumSpaceDim, _stencil_size, &_stencil );
203 checkHypreError( error );
204 std::array<HYPRE_Int, NumSpaceDim> offset;
205 for ( unsigned n = 0; n < stencil.size(); ++n )
206 {
207 for ( std::size_t d = 0; d < NumSpaceDim; ++d )
208 offset[d] = stencil[n][d];
209 error = HYPRE_StructStencilSetElement( _stencil, n, offset.data() );
210 checkHypreError( error );
211 }
212
213 // Create the matrix object. Must be done after the stencil is setup
214 error = HYPRE_StructMatrixCreate( _comm, _grid, _stencil, &_A );
215 checkHypreError( error );
216 error = HYPRE_StructMatrixSetSymmetric( _A, is_symmetric );
217 checkHypreError( error );
218 error = HYPRE_StructMatrixInitialize( _A );
219 checkHypreError( error );
220 }
221
230 template <class Array_t>
231 void setMatrixValues( const Array_t& values )
232 {
233 static_assert( is_array<Array_t>::value, "Must use an array" );
234 static_assert(
235 std::is_same<typename Array_t::entity_type, entity_type>::value,
236 "Cabana::Grid::HypreStructuredSolver::setMatrixValues: Array "
237 "entity type must match solver entity type" );
238 static_assert(
239 std::is_same<typename Array_t::memory_space, MemorySpace>::value,
240 "Cabana::Grid::HypreStructuredSolver::setMatrixValues: Array "
241 "memory space and solver memory space are different." );
242
243 static_assert(
244 std::is_same<typename Array_t::value_type, value_type>::value,
245 "Cabana::Grid::HypreStructuredSolver::setMatrixValues: Array value "
246 "type and solver value type are different." );
247
248 // This function is only valid for non-preconditioners.
249 if ( _is_preconditioner )
250 throw std::logic_error(
251 "Cabana::Grid::HypreStructuredSolver::setMatrixValues: Cannot "
252 "call setMatrixValues() on preconditioners" );
253
254 if ( values.layout()->dofsPerEntity() !=
255 static_cast<int>( _stencil_size ) )
256 throw std::runtime_error(
257 "Cabana::Grid::HypreStructuredSolver::setMatrixValues: Number "
258 "of matrix values does not match stencil size" );
259
260 // Spatial dimension.
261 const std::size_t num_space_dim = Array_t::num_space_dim;
262
263 // Copy the matrix entries into HYPRE. The HYPRE layout is fixed as
264 // layout-right.
265 auto owned_space = values.layout()->indexSpace( Own(), Local() );
266 std::array<long, num_space_dim + 1> reorder_size;
267 for ( std::size_t d = 0; d < num_space_dim; ++d )
268 {
269 reorder_size[d] = owned_space.extent( d );
270 }
271 reorder_size.back() = _stencil_size;
272 IndexSpace<num_space_dim + 1> reorder_space( reorder_size );
273 auto a_values =
275 "a_values", reorder_space );
276 auto values_subv = createSubview( values.view(), owned_space );
277 Kokkos::deep_copy( a_values, values_subv );
278
279 // Insert values into the HYPRE matrix.
280 std::vector<HYPRE_Int> indices( _stencil_size );
281 std::iota( indices.begin(), indices.end(), 0 );
282 auto error = HYPRE_StructMatrixSetBoxValues(
283 _A, _lower.data(), _upper.data(), indices.size(), indices.data(),
284 a_values.data() );
285 checkHypreError( error );
286 error = HYPRE_StructMatrixAssemble( _A );
287 checkHypreError( error );
288 }
289
294 void printMatrix( const char* prefix )
295 {
296 HYPRE_StructMatrixPrint( prefix, _A, 0 );
297 }
298
303 void printLHS( const char* prefix )
304 {
305 HYPRE_StructVectorPrint( prefix, _x, 0 );
306 }
307
312 void printRHS( const char* prefix )
313 {
314 HYPRE_StructVectorPrint( prefix, _b, 0 );
315 }
316
318 void setTolerance( const double tol ) { this->setToleranceImpl( tol ); }
319
321 void setMaxIter( const int max_iter ) { this->setMaxIterImpl( max_iter ); }
322
324 void setPrintLevel( const int print_level )
325 {
326 this->setPrintLevelImpl( print_level );
327 }
328
330 void
332 Scalar, EntityType, MemorySpace>>& preconditioner )
333 {
334 // This function is only valid for non-preconditioners.
335 if ( _is_preconditioner )
336 throw std::logic_error(
337 "Cabana::Grid::HypreStructuredSolver::setPreconditioner: "
338 "Cannot "
339 "call setPreconditioner() on a preconditioner" );
340
341 // Only a preconditioner can be used as a preconditioner.
342 if ( !preconditioner->isPreconditioner() )
343 throw std::logic_error( "Cabana::Grid::HypreStructuredSolver:"
344 "setPreconditioner: Not a preconditioner" );
345
346 _preconditioner = preconditioner;
347 this->setPreconditionerImpl( *_preconditioner );
348 }
349
351 void setup()
352 {
353 // This function is only valid for non-preconditioners.
354 if ( _is_preconditioner )
355 throw std::logic_error(
356 "Cabana::Grid::HypreStructuredSolver::setup:"
357 " Cannot call setup() on preconditioners" );
358
359 // FIXME: appears to be a memory issue in the call to this function
360 this->setupImpl();
361 }
362
368 template <class Array_t>
369 void solve( const Array_t& b, Array_t& x )
370 {
371 Kokkos::Profiling::ScopedRegion region(
372 "Cabana::Grid::HypreStructuredSolver::solve" );
373
374 static_assert(
376 "Cabana::Grid::HypreStructuredSolver::solve: Must use an array" );
377 static_assert(
378 std::is_same<typename Array_t::entity_type, entity_type>::value,
379 "Cabana::Grid::HypreStructuredSolver::solve: Array entity type "
380 "must match solver entity type" );
381 static_assert(
382 std::is_same<typename Array_t::memory_space, MemorySpace>::value,
383 "Cabana::Grid::HypreStructuredSolver::solve: Array memory space "
384 "and solver memory space are different." );
385
386 static_assert(
387 std::is_same<typename Array_t::value_type, value_type>::value,
388 "Cabana::Grid::HypreStructuredSolver::solve: Array value type and "
389 "solver value type are different." );
390
391 // This function is only valid for non-preconditioners.
392 if ( _is_preconditioner )
393 throw std::logic_error(
394 "Cabana::Grid::HypreStructuredSolver::solve: Cannot call "
395 "solve() on preconditioners" );
396
397 if ( b.layout()->dofsPerEntity() != 1 ||
398 x.layout()->dofsPerEntity() != 1 )
399 throw std::runtime_error(
400 "Cabana::Grid::HypreStructuredSolver::solve: Structured solver "
401 "only for scalar fields" );
402
403 // Spatial dimension.
404 const std::size_t num_space_dim = Array_t::num_space_dim;
405
406 // Copy the RHS into HYPRE. The HYPRE layout is fixed as layout-right.
407 auto owned_space = b.layout()->indexSpace( Own(), Local() );
408 std::array<long, num_space_dim + 1> reorder_size;
409 for ( std::size_t d = 0; d < num_space_dim; ++d )
410 {
411 reorder_size[d] = owned_space.extent( d );
412 }
413 reorder_size.back() = 1;
414 IndexSpace<num_space_dim + 1> reorder_space( reorder_size );
415 auto vector_values =
417 "vector_values", reorder_space );
418 auto b_subv = createSubview( b.view(), owned_space );
419 Kokkos::deep_copy( vector_values, b_subv );
420
421 // Insert b values into the HYPRE vector.
422 auto error = HYPRE_StructVectorSetBoxValues(
423 _b, _lower.data(), _upper.data(), vector_values.data() );
424 checkHypreError( error );
425 error = HYPRE_StructVectorAssemble( _b );
426 checkHypreError( error );
427
428 // Solve the problem
429 this->solveImpl();
430
431 // Extract the solution from the LHS
432 error = HYPRE_StructVectorGetBoxValues(
433 _x, _lower.data(), _upper.data(), vector_values.data() );
434 checkHypreError( error );
435
436 // Copy the HYPRE solution to the LHS.
437 auto x_subv = createSubview( x.view(), owned_space );
438 Kokkos::deep_copy( x_subv, vector_values );
439 }
440
442 int getNumIter() { return this->getNumIterImpl(); }
443
446 {
448 }
449
451 virtual HYPRE_StructSolver getHypreSolver() const = 0;
453 virtual HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const = 0;
455 virtual HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const = 0;
456
457 protected:
459 virtual void setToleranceImpl( const double tol ) = 0;
460
462 virtual void setMaxIterImpl( const int max_iter ) = 0;
463
465 virtual void setPrintLevelImpl( const int print_level ) = 0;
466
468 virtual void setupImpl() = 0;
469
471 virtual void solveImpl() = 0;
472
474 virtual int getNumIterImpl() = 0;
475
478
482 preconditioner ) = 0;
483
485 void checkHypreError( const int error ) const
486 {
487 if ( error > 0 )
488 {
489 char error_msg[256];
490 HYPRE_DescribeError( error, error_msg );
491 std::stringstream out;
492 out << "HYPRE structured solver error: ";
493 out << error << " " << error_msg;
494 HYPRE_ClearError( error );
495 throw std::runtime_error( out.str() );
496 }
497 }
498
499 protected:
501 HYPRE_StructMatrix _A;
503 HYPRE_StructVector _b;
505 HYPRE_StructVector _x;
506
507 private:
508 MPI_Comm _comm;
509 bool _is_preconditioner;
510 HYPRE_StructGrid _grid;
511 std::vector<HYPRE_Int> _lower;
512 std::vector<HYPRE_Int> _upper;
513 HYPRE_StructStencil _stencil;
514 unsigned _stencil_size;
515 std::shared_ptr<HypreStructuredSolver<Scalar, EntityType, MemorySpace>>
516 _preconditioner;
517};
518
519//---------------------------------------------------------------------------//
521template <class Scalar, class EntityType, class MemorySpace>
523 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
524{
525 public:
529 template <class ArrayLayout_t>
530 HypreStructPCG( const ArrayLayout_t& layout,
531 const bool is_preconditioner = false )
532 : base_type( layout, is_preconditioner )
533 {
534 if ( is_preconditioner )
535 throw std::logic_error(
536 "HYPRE PCG cannot be used as a preconditioner" );
537
538 auto error = HYPRE_StructPCGCreate(
539 layout.localGrid()->globalGrid().comm(), &_solver );
540 this->checkHypreError( error );
541
542 HYPRE_StructPCGSetTwoNorm( _solver, 1 );
543 }
544
545 ~HypreStructPCG() { HYPRE_StructPCGDestroy( _solver ); }
546
547 // PCG SETTINGS
548
550 void setAbsoluteTol( const double tol )
551 {
552 auto error = HYPRE_StructPCGSetAbsoluteTol( _solver, tol );
553 this->checkHypreError( error );
554 }
555
558 void setRelChange( const int rel_change )
559 {
560 auto error = HYPRE_StructPCGSetRelChange( _solver, rel_change );
561 this->checkHypreError( error );
562 }
563
565 void setLogging( const int logging )
566 {
567 auto error = HYPRE_StructPCGSetLogging( _solver, logging );
568 this->checkHypreError( error );
569 }
570
571 HYPRE_StructSolver getHypreSolver() const override { return _solver; }
572 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
573 {
574 return HYPRE_StructPCGSetup;
575 }
576 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
577 {
578 return HYPRE_StructPCGSolve;
579 }
580
581 protected:
582 void setToleranceImpl( const double tol ) override
583 {
584 auto error = HYPRE_StructPCGSetTol( _solver, tol );
585 this->checkHypreError( error );
586 }
587
588 void setMaxIterImpl( const int max_iter ) override
589 {
590 auto error = HYPRE_StructPCGSetMaxIter( _solver, max_iter );
591 this->checkHypreError( error );
592 }
593
594 void setPrintLevelImpl( const int print_level ) override
595 {
596 auto error = HYPRE_StructPCGSetPrintLevel( _solver, print_level );
597 this->checkHypreError( error );
598 }
599
600 void setupImpl() override
601 {
602 auto error = HYPRE_StructPCGSetup( _solver, _A, _b, _x );
603 this->checkHypreError( error );
604 }
605
606 void solveImpl() override
607 {
608 auto error = HYPRE_StructPCGSolve( _solver, _A, _b, _x );
609 this->checkHypreError( error );
610 }
611
612 int getNumIterImpl() override
613 {
614 HYPRE_Int num_iter;
615 auto error = HYPRE_StructPCGGetNumIterations( _solver, &num_iter );
616 this->checkHypreError( error );
617 return num_iter;
618 }
619
621 {
622 HYPRE_Real norm;
623 auto error =
624 HYPRE_StructPCGGetFinalRelativeResidualNorm( _solver, &norm );
625 this->checkHypreError( error );
626 return norm;
627 }
628
631 preconditioner ) override
632 {
633 auto error = HYPRE_StructPCGSetPrecond(
634 _solver, preconditioner.getHypreSolveFunction(),
635 preconditioner.getHypreSetupFunction(),
636 preconditioner.getHypreSolver() );
637 this->checkHypreError( error );
638 }
639
640 private:
641 HYPRE_StructSolver _solver;
642 using base_type::_A;
643 using base_type::_b;
644 using base_type::_x;
645};
646
647//---------------------------------------------------------------------------//
649template <class Scalar, class EntityType, class MemorySpace>
651 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
652{
653 public:
657 template <class ArrayLayout_t>
658 HypreStructGMRES( const ArrayLayout_t& layout,
659 const bool is_preconditioner = false )
660 : base_type( layout, is_preconditioner )
661 {
662 if ( is_preconditioner )
663 throw std::logic_error(
664 "HYPRE GMRES cannot be used as a preconditioner" );
665
666 auto error = HYPRE_StructGMRESCreate(
667 layout.localGrid()->globalGrid().comm(), &_solver );
668 this->checkHypreError( error );
669 }
670
671 ~HypreStructGMRES() { HYPRE_StructGMRESDestroy( _solver ); }
672
673 // GMRES SETTINGS
674
676 void setAbsoluteTol( const double tol )
677 {
678 auto error = HYPRE_StructGMRESSetAbsoluteTol( _solver, tol );
679 this->checkHypreError( error );
680 }
681
683 void setKDim( const int k_dim )
684 {
685 auto error = HYPRE_StructGMRESSetKDim( _solver, k_dim );
686 this->checkHypreError( error );
687 }
688
690 void setLogging( const int logging )
691 {
692 auto error = HYPRE_StructGMRESSetLogging( _solver, logging );
693 this->checkHypreError( error );
694 }
695
696 HYPRE_StructSolver getHypreSolver() const override { return _solver; }
697 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
698 {
699 return HYPRE_StructGMRESSetup;
700 }
701 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
702 {
703 return HYPRE_StructGMRESSolve;
704 }
705
706 protected:
707 void setToleranceImpl( const double tol ) override
708 {
709 auto error = HYPRE_StructGMRESSetTol( _solver, tol );
710 this->checkHypreError( error );
711 }
712
713 void setMaxIterImpl( const int max_iter ) override
714 {
715 auto error = HYPRE_StructGMRESSetMaxIter( _solver, max_iter );
716 this->checkHypreError( error );
717 }
718
719 void setPrintLevelImpl( const int print_level ) override
720 {
721 auto error = HYPRE_StructGMRESSetPrintLevel( _solver, print_level );
722 this->checkHypreError( error );
723 }
724
725 void setupImpl() override
726 {
727 auto error = HYPRE_StructGMRESSetup( _solver, _A, _b, _x );
728 this->checkHypreError( error );
729 }
730
731 void solveImpl() override
732 {
733 auto error = HYPRE_StructGMRESSolve( _solver, _A, _b, _x );
734 this->checkHypreError( error );
735 }
736
737 int getNumIterImpl() override
738 {
739 HYPRE_Int num_iter;
740 auto error = HYPRE_StructGMRESGetNumIterations( _solver, &num_iter );
741 this->checkHypreError( error );
742 return num_iter;
743 }
744
746 {
747 HYPRE_Real norm;
748 auto error =
749 HYPRE_StructGMRESGetFinalRelativeResidualNorm( _solver, &norm );
750 this->checkHypreError( error );
751 return norm;
752 }
753
756 preconditioner ) override
757 {
758 auto error = HYPRE_StructGMRESSetPrecond(
759 _solver, preconditioner.getHypreSolveFunction(),
760 preconditioner.getHypreSetupFunction(),
761 preconditioner.getHypreSolver() );
762 this->checkHypreError( error );
763 }
764
765 private:
766 HYPRE_StructSolver _solver;
767 using base_type::_A;
768 using base_type::_b;
769 using base_type::_x;
770};
771
772//---------------------------------------------------------------------------//
774template <class Scalar, class EntityType, class MemorySpace>
776 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
777{
778 public:
782 template <class ArrayLayout_t>
783 HypreStructBiCGSTAB( const ArrayLayout_t& layout,
784 const bool is_preconditioner = false )
785 : base_type( layout, is_preconditioner )
786 {
787 if ( is_preconditioner )
788 throw std::logic_error(
789 "HYPRE BiCGSTAB cannot be used as a preconditioner" );
790
791 auto error = HYPRE_StructBiCGSTABCreate(
792 layout.localGrid()->globalGrid().comm(), &_solver );
793 this->checkHypreError( error );
794 }
795
796 ~HypreStructBiCGSTAB() { HYPRE_StructBiCGSTABDestroy( _solver ); }
797
798 // BiCGSTAB SETTINGS
799
801 void setAbsoluteTol( const double tol )
802 {
803 auto error = HYPRE_StructBiCGSTABSetAbsoluteTol( _solver, tol );
804 this->checkHypreError( error );
805 }
806
808 void setLogging( const int logging )
809 {
810 auto error = HYPRE_StructBiCGSTABSetLogging( _solver, logging );
811 this->checkHypreError( error );
812 }
813
814 HYPRE_StructSolver getHypreSolver() const override { return _solver; }
815 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
816 {
817 return HYPRE_StructBiCGSTABSetup;
818 }
819 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
820 {
821 return HYPRE_StructBiCGSTABSolve;
822 }
823
824 protected:
825 void setToleranceImpl( const double tol ) override
826 {
827 auto error = HYPRE_StructBiCGSTABSetTol( _solver, tol );
828 this->checkHypreError( error );
829 }
830
831 void setMaxIterImpl( const int max_iter ) override
832 {
833 auto error = HYPRE_StructBiCGSTABSetMaxIter( _solver, max_iter );
834 this->checkHypreError( error );
835 }
836
837 void setPrintLevelImpl( const int print_level ) override
838 {
839 auto error = HYPRE_StructBiCGSTABSetPrintLevel( _solver, print_level );
840 this->checkHypreError( error );
841 }
842
843 void setupImpl() override
844 {
845 auto error = HYPRE_StructBiCGSTABSetup( _solver, _A, _b, _x );
846 this->checkHypreError( error );
847 }
848
849 void solveImpl() override
850 {
851 auto error = HYPRE_StructBiCGSTABSolve( _solver, _A, _b, _x );
852 this->checkHypreError( error );
853 }
854
855 int getNumIterImpl() override
856 {
857 HYPRE_Int num_iter;
858 auto error = HYPRE_StructBiCGSTABGetNumIterations( _solver, &num_iter );
859 this->checkHypreError( error );
860 return num_iter;
861 }
862
864 {
865 HYPRE_Real norm;
866 auto error =
867 HYPRE_StructBiCGSTABGetFinalRelativeResidualNorm( _solver, &norm );
868 this->checkHypreError( error );
869 return norm;
870 }
871
874 preconditioner ) override
875 {
876 auto error = HYPRE_StructBiCGSTABSetPrecond(
877 _solver, preconditioner.getHypreSolveFunction(),
878 preconditioner.getHypreSetupFunction(),
879 preconditioner.getHypreSolver() );
880 this->checkHypreError( error );
881 }
882
883 private:
884 HYPRE_StructSolver _solver;
885 using base_type::_A;
886 using base_type::_b;
887 using base_type::_x;
888};
889
890//---------------------------------------------------------------------------//
892template <class Scalar, class EntityType, class MemorySpace>
894 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
895{
896 public:
900 template <class ArrayLayout_t>
901 HypreStructPFMG( const ArrayLayout_t& layout,
902 const bool is_preconditioner = false )
903 : base_type( layout, is_preconditioner )
904 {
905 auto error = HYPRE_StructPFMGCreate(
906 layout.localGrid()->globalGrid().comm(), &_solver );
907 this->checkHypreError( error );
908
909 if ( is_preconditioner )
910 {
911 error = HYPRE_StructPFMGSetZeroGuess( _solver );
912 this->checkHypreError( error );
913 }
914 }
915
916 ~HypreStructPFMG() { HYPRE_StructPFMGDestroy( _solver ); }
917
918 // PFMG SETTINGS
919
921 void setMaxLevels( const int max_levels )
922 {
923 auto error = HYPRE_StructPFMGSetMaxLevels( _solver, max_levels );
924 this->checkHypreError( error );
925 }
926
929 void setRelChange( const int rel_change )
930 {
931 auto error = HYPRE_StructPFMGSetRelChange( _solver, rel_change );
932 this->checkHypreError( error );
933 }
934
944 void setRelaxType( const int relax_type )
945 {
946 auto error = HYPRE_StructPFMGSetRelaxType( _solver, relax_type );
947 this->checkHypreError( error );
948 }
949
951 void setJacobiWeight( const double weight )
952 {
953 auto error = HYPRE_StructPFMGSetJacobiWeight( _solver, weight );
954 this->checkHypreError( error );
955 }
956
967 void setRAPType( const int rap_type )
968 {
969 auto error = HYPRE_StructPFMGSetRAPType( _solver, rap_type );
970 this->checkHypreError( error );
971 }
972
974 void setNumPreRelax( const int num_pre_relax )
975 {
976 auto error = HYPRE_StructPFMGSetNumPreRelax( _solver, num_pre_relax );
977 this->checkHypreError( error );
978 }
979
981 void setNumPostRelax( const int num_post_relax )
982 {
983 auto error = HYPRE_StructPFMGSetNumPostRelax( _solver, num_post_relax );
984 this->checkHypreError( error );
985 }
986
990 void setSkipRelax( const int skip_relax )
991 {
992 auto error = HYPRE_StructPFMGSetSkipRelax( _solver, skip_relax );
993 this->checkHypreError( error );
994 }
995
997 void setLogging( const int logging )
998 {
999 auto error = HYPRE_StructPFMGSetLogging( _solver, logging );
1000 this->checkHypreError( error );
1001 }
1002
1003 HYPRE_StructSolver getHypreSolver() const override { return _solver; }
1004 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
1005 {
1006 return HYPRE_StructPFMGSetup;
1007 }
1008 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
1009 {
1010 return HYPRE_StructPFMGSolve;
1011 }
1012
1013 protected:
1014 void setToleranceImpl( const double tol ) override
1015 {
1016 auto error = HYPRE_StructPFMGSetTol( _solver, tol );
1017 this->checkHypreError( error );
1018 }
1019
1020 void setMaxIterImpl( const int max_iter ) override
1021 {
1022 auto error = HYPRE_StructPFMGSetMaxIter( _solver, max_iter );
1023 this->checkHypreError( error );
1024 }
1025
1026 void setPrintLevelImpl( const int print_level ) override
1027 {
1028 auto error = HYPRE_StructPFMGSetPrintLevel( _solver, print_level );
1029 this->checkHypreError( error );
1030 }
1031
1032 void setupImpl() override
1033 {
1034 auto error = HYPRE_StructPFMGSetup( _solver, _A, _b, _x );
1035 this->checkHypreError( error );
1036 }
1037
1038 void solveImpl() override
1039 {
1040 auto error = HYPRE_StructPFMGSolve( _solver, _A, _b, _x );
1041 this->checkHypreError( error );
1042 }
1043
1044 int getNumIterImpl() override
1045 {
1046 HYPRE_Int num_iter;
1047 auto error = HYPRE_StructPFMGGetNumIterations( _solver, &num_iter );
1048 this->checkHypreError( error );
1049 return num_iter;
1050 }
1051
1053 {
1054 HYPRE_Real norm;
1055 auto error =
1056 HYPRE_StructPFMGGetFinalRelativeResidualNorm( _solver, &norm );
1057 this->checkHypreError( error );
1058 return norm;
1059 }
1060
1063 {
1064 throw std::logic_error(
1065 "HYPRE PFMG solver does not support preconditioning." );
1066 }
1067
1068 private:
1069 HYPRE_StructSolver _solver;
1070 using base_type::_A;
1071 using base_type::_b;
1072 using base_type::_x;
1073};
1074
1075//---------------------------------------------------------------------------//
1077template <class Scalar, class EntityType, class MemorySpace>
1079 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
1080{
1081 public:
1085 template <class ArrayLayout_t>
1086 HypreStructSMG( const ArrayLayout_t& layout,
1087 const bool is_preconditioner = false )
1088 : base_type( layout, is_preconditioner )
1089 {
1090 auto error = HYPRE_StructSMGCreate(
1091 layout.localGrid()->globalGrid().comm(), &_solver );
1092 this->checkHypreError( error );
1093
1094 if ( is_preconditioner )
1095 {
1096 error = HYPRE_StructSMGSetZeroGuess( _solver );
1097 this->checkHypreError( error );
1098 }
1099 }
1100
1101 ~HypreStructSMG() { HYPRE_StructSMGDestroy( _solver ); }
1102
1103 // SMG Settings
1104
1107 void setRelChange( const int rel_change )
1108 {
1109 auto error = HYPRE_StructSMGSetRelChange( _solver, rel_change );
1110 this->checkHypreError( error );
1111 }
1112
1114 void setNumPreRelax( const int num_pre_relax )
1115 {
1116 auto error = HYPRE_StructSMGSetNumPreRelax( _solver, num_pre_relax );
1117 this->checkHypreError( error );
1118 }
1119
1121 void setNumPostRelax( const int num_post_relax )
1122 {
1123 auto error = HYPRE_StructSMGSetNumPostRelax( _solver, num_post_relax );
1124 this->checkHypreError( error );
1125 }
1126
1128 void setLogging( const int logging )
1129 {
1130 auto error = HYPRE_StructSMGSetLogging( _solver, logging );
1131 this->checkHypreError( error );
1132 }
1133
1134 HYPRE_StructSolver getHypreSolver() const override { return _solver; }
1135 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
1136 {
1137 return HYPRE_StructSMGSetup;
1138 }
1139 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
1140 {
1141 return HYPRE_StructSMGSolve;
1142 }
1143
1144 protected:
1145 void setToleranceImpl( const double tol ) override
1146 {
1147 auto error = HYPRE_StructSMGSetTol( _solver, tol );
1148 this->checkHypreError( error );
1149 }
1150
1151 void setMaxIterImpl( const int max_iter ) override
1152 {
1153 auto error = HYPRE_StructSMGSetMaxIter( _solver, max_iter );
1154 this->checkHypreError( error );
1155 }
1156
1157 void setPrintLevelImpl( const int print_level ) override
1158 {
1159 auto error = HYPRE_StructSMGSetPrintLevel( _solver, print_level );
1160 this->checkHypreError( error );
1161 }
1162
1163 void setupImpl() override
1164 {
1165 auto error = HYPRE_StructSMGSetup( _solver, _A, _b, _x );
1166 this->checkHypreError( error );
1167 }
1168
1169 void solveImpl() override
1170 {
1171 auto error = HYPRE_StructSMGSolve( _solver, _A, _b, _x );
1172 this->checkHypreError( error );
1173 }
1174
1175 int getNumIterImpl() override
1176 {
1177 HYPRE_Int num_iter;
1178 auto error = HYPRE_StructSMGGetNumIterations( _solver, &num_iter );
1179 this->checkHypreError( error );
1180 return num_iter;
1181 }
1182
1184 {
1185 HYPRE_Real norm;
1186 auto error =
1187 HYPRE_StructSMGGetFinalRelativeResidualNorm( _solver, &norm );
1188 this->checkHypreError( error );
1189 return norm;
1190 }
1191
1194 {
1195 throw std::logic_error(
1196 "HYPRE SMG solver does not support preconditioning." );
1197 }
1198
1199 private:
1200 HYPRE_StructSolver _solver;
1201 using base_type::_A;
1202 using base_type::_b;
1203 using base_type::_x;
1204};
1205
1206//---------------------------------------------------------------------------//
1208template <class Scalar, class EntityType, class MemorySpace>
1210 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
1211{
1212 public:
1216 template <class ArrayLayout_t>
1217 HypreStructJacobi( const ArrayLayout_t& layout,
1218 const bool is_preconditioner = false )
1219 : base_type( layout, is_preconditioner )
1220 {
1221 auto error = HYPRE_StructJacobiCreate(
1222 layout.localGrid()->globalGrid().comm(), &_solver );
1223 this->checkHypreError( error );
1224
1225 if ( is_preconditioner )
1226 {
1227 error = HYPRE_StructJacobiSetZeroGuess( _solver );
1228 this->checkHypreError( error );
1229 }
1230 }
1231
1232 ~HypreStructJacobi() { HYPRE_StructJacobiDestroy( _solver ); }
1233
1234 HYPRE_StructSolver getHypreSolver() const override { return _solver; }
1235 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
1236 {
1237 return HYPRE_StructJacobiSetup;
1238 }
1239 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
1240 {
1241 return HYPRE_StructJacobiSolve;
1242 }
1243
1244 protected:
1245 void setToleranceImpl( const double tol ) override
1246 {
1247 auto error = HYPRE_StructJacobiSetTol( _solver, tol );
1248 this->checkHypreError( error );
1249 }
1250
1251 void setMaxIterImpl( const int max_iter ) override
1252 {
1253 auto error = HYPRE_StructJacobiSetMaxIter( _solver, max_iter );
1254 this->checkHypreError( error );
1255 }
1256
1257 void setPrintLevelImpl( const int ) override
1258 {
1259 // The Jacobi solver does not support a print level.
1260 }
1261
1262 void setupImpl() override
1263 {
1264 auto error = HYPRE_StructJacobiSetup( _solver, _A, _b, _x );
1265 this->checkHypreError( error );
1266 }
1267
1268 void solveImpl() override
1269 {
1270 auto error = HYPRE_StructJacobiSolve( _solver, _A, _b, _x );
1271 this->checkHypreError( error );
1272 }
1273
1274 int getNumIterImpl() override
1275 {
1276 HYPRE_Int num_iter;
1277 auto error = HYPRE_StructJacobiGetNumIterations( _solver, &num_iter );
1278 this->checkHypreError( error );
1279 return num_iter;
1280 }
1281
1283 {
1284 HYPRE_Real norm;
1285 auto error =
1286 HYPRE_StructJacobiGetFinalRelativeResidualNorm( _solver, &norm );
1287 this->checkHypreError( error );
1288 return norm;
1289 }
1290
1293 {
1294 throw std::logic_error(
1295 "HYPRE Jacobi solver does not support preconditioning." );
1296 }
1297
1298 private:
1299 HYPRE_StructSolver _solver;
1300 using base_type::_A;
1301 using base_type::_b;
1302 using base_type::_x;
1303};
1304
1305//---------------------------------------------------------------------------//
1307template <class Scalar, class EntityType, class MemorySpace>
1309 : public HypreStructuredSolver<Scalar, EntityType, MemorySpace>
1310{
1311 public:
1315 template <class ArrayLayout_t>
1316 HypreStructDiagonal( const ArrayLayout_t& layout,
1317 const bool is_preconditioner = false )
1318 : base_type( layout, is_preconditioner )
1319 {
1320 if ( !is_preconditioner )
1321 throw std::logic_error(
1322 "Diagonal preconditioner cannot be used as a solver" );
1323 }
1324
1325 HYPRE_StructSolver getHypreSolver() const override { return nullptr; }
1326 HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
1327 {
1328 return HYPRE_StructDiagScaleSetup;
1329 }
1330 HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
1331 {
1332 return HYPRE_StructDiagScale;
1333 }
1334
1335 protected:
1336 void setToleranceImpl( const double ) override
1337 {
1338 throw std::logic_error(
1339 "Diagonal preconditioner cannot be used as a solver" );
1340 }
1341
1342 void setMaxIterImpl( const int ) override
1343 {
1344 throw std::logic_error(
1345 "Diagonal preconditioner cannot be used as a solver" );
1346 }
1347
1348 void setPrintLevelImpl( const int ) override
1349 {
1350 throw std::logic_error(
1351 "Diagonal preconditioner cannot be used as a solver" );
1352 }
1353
1354 void setupImpl() override
1355 {
1356 throw std::logic_error(
1357 "Diagonal preconditioner cannot be used as a solver" );
1358 }
1359
1360 void solveImpl() override
1361 {
1362 throw std::logic_error(
1363 "Diagonal preconditioner cannot be used as a solver" );
1364 }
1365
1366 int getNumIterImpl() override
1367 {
1368 throw std::logic_error(
1369 "Diagonal preconditioner cannot be used as a solver" );
1370 }
1371
1373 {
1374 throw std::logic_error(
1375 "Diagonal preconditioner cannot be used as a solver" );
1376 }
1377
1380 {
1381 throw std::logic_error(
1382 "Diagonal preconditioner does not support preconditioning." );
1383 }
1384};
1385
1386//---------------------------------------------------------------------------//
1387// Builders
1388//---------------------------------------------------------------------------//
1391template <class Scalar, class MemorySpace, class ArrayLayout_t>
1392std::shared_ptr<
1393 HypreStructPCG<Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>
1394createHypreStructPCG( const ArrayLayout_t& layout,
1395 const bool is_preconditioner = false )
1396{
1398 "Must use an array layout" );
1399 return std::make_shared<HypreStructPCG<
1400 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1401 layout, is_preconditioner );
1402}
1403
1406template <class Scalar, class MemorySpace, class ArrayLayout_t>
1407std::shared_ptr<
1408 HypreStructGMRES<Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>
1409createHypreStructGMRES( const ArrayLayout_t& layout,
1410 const bool is_preconditioner = false )
1411{
1413 "Must use an array layout" );
1414 return std::make_shared<HypreStructGMRES<
1415 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1416 layout, is_preconditioner );
1417}
1418
1421template <class Scalar, class MemorySpace, class ArrayLayout_t>
1422std::shared_ptr<HypreStructBiCGSTAB<Scalar, typename ArrayLayout_t::entity_type,
1423 MemorySpace>>
1424createHypreStructBiCGSTAB( const ArrayLayout_t& layout,
1425 const bool is_preconditioner = false )
1426{
1428 "Must use an array layout" );
1429 return std::make_shared<HypreStructBiCGSTAB<
1430 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1431 layout, is_preconditioner );
1432}
1433
1436template <class Scalar, class MemorySpace, class ArrayLayout_t>
1437std::shared_ptr<
1438 HypreStructPFMG<Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>
1439createHypreStructPFMG( const ArrayLayout_t& layout,
1440 const bool is_preconditioner = false )
1441{
1443 "Must use an array layout" );
1444 return std::make_shared<HypreStructPFMG<
1445 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1446 layout, is_preconditioner );
1447}
1448
1451template <class Scalar, class MemorySpace, class ArrayLayout_t>
1452std::shared_ptr<
1453 HypreStructSMG<Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>
1454createHypreStructSMG( const ArrayLayout_t& layout,
1455 const bool is_preconditioner = false )
1456{
1458 "Must use an array layout" );
1459 return std::make_shared<HypreStructSMG<
1460 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1461 layout, is_preconditioner );
1462}
1463
1466template <class Scalar, class MemorySpace, class ArrayLayout_t>
1467std::shared_ptr<
1468 HypreStructJacobi<Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>
1469createHypreStructJacobi( const ArrayLayout_t& layout,
1470 const bool is_preconditioner = false )
1471{
1473 "Must use an array layout" );
1474 return std::make_shared<HypreStructJacobi<
1475 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1476 layout, is_preconditioner );
1477}
1478
1481template <class Scalar, class MemorySpace, class ArrayLayout_t>
1482std::shared_ptr<HypreStructDiagonal<Scalar, typename ArrayLayout_t::entity_type,
1483 MemorySpace>>
1484createHypreStructDiagonal( const ArrayLayout_t& layout,
1485 const bool is_preconditioner = false )
1486{
1488 "Must use an array layout" );
1489 return std::make_shared<HypreStructDiagonal<
1490 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>(
1491 layout, is_preconditioner );
1492}
1493
1494//---------------------------------------------------------------------------//
1495// Factory
1496//---------------------------------------------------------------------------//
1505template <class Scalar, class MemorySpace, class ArrayLayout_t>
1506std::shared_ptr<HypreStructuredSolver<
1507 Scalar, typename ArrayLayout_t::entity_type, MemorySpace>>
1508createHypreStructuredSolver( const std::string& solver_type,
1509 const ArrayLayout_t& layout,
1510 const bool is_preconditioner = false )
1511{
1513 "Must use an array layout" );
1514
1515 if ( "PCG" == solver_type )
1517 is_preconditioner );
1518 else if ( "GMRES" == solver_type )
1520 is_preconditioner );
1521 else if ( "BiCGSTAB" == solver_type )
1523 layout, is_preconditioner );
1524 else if ( "PFMG" == solver_type )
1526 is_preconditioner );
1527 else if ( "SMG" == solver_type )
1529 is_preconditioner );
1530 else if ( "Jacobi" == solver_type )
1532 layout, is_preconditioner );
1533 else if ( "Diagonal" == solver_type )
1535 layout, is_preconditioner );
1536 else
1537 throw std::runtime_error(
1538 "Cabana::Grid::createHypreStructuredSolver: Invalid solver type" );
1539}
1540
1541//---------------------------------------------------------------------------//
1542
1543} // namespace Grid
1544} // namespace Cabana
1545
1546#endif // end CABANA_GRID_HYPRESTRUCTUREDSOLVER_HPP
Grid field arrays.
std::shared_ptr< HypreStructGMRES< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructGMRES(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1409
std::shared_ptr< HypreStructJacobi< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructJacobi(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1469
std::shared_ptr< HypreStructBiCGSTAB< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructBiCGSTAB(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1424
std::shared_ptr< HypreStructDiagonal< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructDiagonal(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1484
std::shared_ptr< HypreStructPCG< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructPCG(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1394
std::shared_ptr< HypreStructPFMG< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructPFMG(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1439
std::shared_ptr< HypreStructSMG< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructSMG(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1454
std::shared_ptr< HypreStructuredSolver< Scalar, typename ArrayLayout_t::entity_type, MemorySpace > > createHypreStructuredSolver(const std::string &solver_type, const ArrayLayout_t &layout, const bool is_preconditioner=false)
Create a HYPRE structured solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1508
HYPRE memory space handling.
Logical grid indexing.
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
Grid type tags.
BiCGSTAB solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:777
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:863
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:849
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreStructuredSolver.hpp:808
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreStructuredSolver.hpp:801
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:814
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:855
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:815
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:780
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:831
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:872
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:837
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:819
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:843
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:825
HypreStructBiCGSTAB(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:783
Diagonal preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1310
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1360
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1372
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1366
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1354
void setPrintLevelImpl(const int) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1348
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1326
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1325
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1313
void setToleranceImpl(const double) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1336
HypreStructDiagonal(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1316
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1378
void setMaxIterImpl(const int) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1342
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1330
GMRES solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:652
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:707
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:731
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:655
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:697
HypreStructGMRES(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:658
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:737
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:754
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:713
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:701
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:696
void setKDim(const int k_dim)
Set the max size of the Krylov space.
Definition Cabana_Grid_HypreStructuredSolver.hpp:683
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:745
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreStructuredSolver.hpp:690
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreStructuredSolver.hpp:676
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:725
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:719
Jacobi solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1211
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1291
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1245
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1282
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1214
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1239
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1262
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1251
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1274
void setPrintLevelImpl(const int) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1257
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1235
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1268
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1234
HypreStructJacobi(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1217
PCG solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:524
void setRelChange(const int rel_change)
Definition Cabana_Grid_HypreStructuredSolver.hpp:558
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:582
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:600
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:571
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:527
HypreStructPCG(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:530
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:572
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:606
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:612
void setAbsoluteTol(const double tol)
Set the absolute tolerance.
Definition Cabana_Grid_HypreStructuredSolver.hpp:550
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:620
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:588
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:576
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:594
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreStructuredSolver.hpp:565
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:629
PFMG solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:895
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:898
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1008
void setRelaxType(const int relax_type)
Set relaxation type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:944
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1061
void setSkipRelax(const int skip_relax)
Definition Cabana_Grid_HypreStructuredSolver.hpp:990
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1026
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1052
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreStructuredSolver.hpp:997
void setNumPreRelax(const int num_pre_relax)
Set number of relaxation sweeps before coarse-grid correction.
Definition Cabana_Grid_HypreStructuredSolver.hpp:974
void setJacobiWeight(const double weight)
Set the Jacobi weight.
Definition Cabana_Grid_HypreStructuredSolver.hpp:951
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1003
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1038
HypreStructPFMG(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:901
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1004
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1032
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1044
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1020
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1014
void setRelChange(const int rel_change)
Definition Cabana_Grid_HypreStructuredSolver.hpp:929
void setNumPostRelax(const int num_post_relax)
Set number of relaxation sweeps before coarse-grid correction.
Definition Cabana_Grid_HypreStructuredSolver.hpp:981
void setMaxLevels(const int max_levels)
Set the maximum number of multigrid levels.
Definition Cabana_Grid_HypreStructuredSolver.hpp:921
void setRAPType(const int rap_type)
Set type of coarse-grid operator to use.
Definition Cabana_Grid_HypreStructuredSolver.hpp:967
SMG solver.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1080
HypreStructSMG(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Constructor.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1086
void solveImpl() override
Solver implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1169
void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &) override
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1192
void setToleranceImpl(const double tol) override
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1145
void setRelChange(const int rel_change)
Definition Cabana_Grid_HypreStructuredSolver.hpp:1107
HypreStructuredSolver< Scalar, EntityType, MemorySpace > base_type
Base HYPRE structured solver type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1083
HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const override
Get the preconditioner setup function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1135
HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const override
Get the preconditioner solve function.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1139
void setLogging(const int logging)
Set the amount of logging to do.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1128
void setMaxIterImpl(const int max_iter) override
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1151
int getNumIterImpl() override
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1175
void setPrintLevelImpl(const int print_level) override
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1157
void setupImpl() override
Setup implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1163
double getFinalRelativeResidualNormImpl() override
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1183
void setNumPostRelax(const int num_post_relax)
Set number of relaxation sweeps before coarse-grid correction.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1121
void setNumPreRelax(const int num_pre_relax)
Set number of relaxation sweeps before coarse-grid correction.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1114
HYPRE_StructSolver getHypreSolver() const override
Get the preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:1134
Hypre structured solver interface for scalar fields.
Definition Cabana_Grid_HypreStructuredSolver.hpp:49
bool isPreconditioner() const
Return if this solver is a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:179
Scalar value_type
Scalar value type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:56
virtual HYPRE_PtrToStructSolverFcn getHypreSetupFunction() const =0
Get the preconditioner setup function.
void printMatrix(const char *prefix)
Print the hypre matrix to output file.
Definition Cabana_Grid_HypreStructuredSolver.hpp:294
HYPRE_StructMatrix _A
Matrix for the problem Ax = b.
Definition Cabana_Grid_HypreStructuredSolver.hpp:501
HYPRE_StructVector _b
Forcing term for the problem Ax = b.
Definition Cabana_Grid_HypreStructuredSolver.hpp:503
double getFinalRelativeResidualNorm()
Get the relative residual norm achieved on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:445
void setup()
Setup the problem.
Definition Cabana_Grid_HypreStructuredSolver.hpp:351
virtual void setMaxIterImpl(const int max_iter)=0
Set maximum iteration implementation.
HypreStructuredSolver(const ArrayLayout_t &layout, const bool is_preconditioner=false)
Hypre memory space compatibility check.
Definition Cabana_Grid_HypreStructuredSolver.hpp:68
virtual void setPreconditionerImpl(const HypreStructuredSolver< Scalar, EntityType, MemorySpace > &preconditioner)=0
Set a preconditioner.
virtual void setToleranceImpl(const double tol)=0
Set convergence tolerance implementation.
void setMatrixStencil(const std::vector< std::array< int, NumSpaceDim > > &stencil, const bool is_symmetric=false)
Set the operator stencil.
Definition Cabana_Grid_HypreStructuredSolver.hpp:191
EntityType entity_type
Entity type.
Definition Cabana_Grid_HypreStructuredSolver.hpp:52
virtual double getFinalRelativeResidualNormImpl()=0
Get the relative residual norm achieved on the last solve.
void setPrintLevel(const int print_level)
Set the output level.
Definition Cabana_Grid_HypreStructuredSolver.hpp:324
virtual void solveImpl()=0
Solver implementation.
virtual int getNumIterImpl()=0
Get the number of iterations taken on the last solve.
MemorySpace memory_space
Kokkos memory space..
Definition Cabana_Grid_HypreStructuredSolver.hpp:54
virtual HYPRE_StructSolver getHypreSolver() const =0
Get the preconditioner.
void setMatrixValues(const Array_t &values)
Set the matrix values.
Definition Cabana_Grid_HypreStructuredSolver.hpp:231
void printLHS(const char *prefix)
Print the hypre LHS to output file.
Definition Cabana_Grid_HypreStructuredSolver.hpp:303
void printRHS(const char *prefix)
Print the hypre RHS to output file.
Definition Cabana_Grid_HypreStructuredSolver.hpp:312
void checkHypreError(const int error) const
Check a hypre error.
Definition Cabana_Grid_HypreStructuredSolver.hpp:485
int getNumIter()
Get the number of iterations taken on the last solve.
Definition Cabana_Grid_HypreStructuredSolver.hpp:442
virtual HYPRE_PtrToStructSolverFcn getHypreSolveFunction() const =0
Get the preconditioner solve function.
virtual void setupImpl()=0
Setup implementation.
HYPRE_StructVector _x
Solution to the problem Ax = b.
Definition Cabana_Grid_HypreStructuredSolver.hpp:505
void setMaxIter(const int max_iter)
Set maximum iteration implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:321
void solve(const Array_t &b, Array_t &x)
Solve the problem Ax = b for x.
Definition Cabana_Grid_HypreStructuredSolver.hpp:369
void setTolerance(const double tol)
Set convergence tolerance implementation.
Definition Cabana_Grid_HypreStructuredSolver.hpp:318
void setPreconditioner(const std::shared_ptr< HypreStructuredSolver< Scalar, EntityType, MemorySpace > > &preconditioner)
Set a preconditioner.
Definition Cabana_Grid_HypreStructuredSolver.hpp:331
virtual void setPrintLevelImpl(const int print_level)=0
Set the output level.
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