Skip to content

Commit

Permalink
Use inherited hypre variables for semi-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Jan 19, 2024
1 parent c59b8cb commit 55199bb
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions grid/src/Cabana_Grid_HypreSemiStructuredSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class HypreSemiStructuredSolver
auto error = HYPRE_SStructMatrixAssemble( _A );
checkHypreError( error );

this->setupImpl( _A, _b, _x );
this->setupImpl();
}

/*!
Expand Down Expand Up @@ -556,7 +556,7 @@ class HypreSemiStructuredSolver
checkHypreError( error );

// Solve the problem
this->solveImpl( _A, _b, _x );
this->solveImpl();

// Extract the solution from the LHS
for ( int var = 0; var < n_vars; ++var )
Expand Down Expand Up @@ -612,12 +612,10 @@ class HypreSemiStructuredSolver
virtual void setPrintLevelImpl( const int print_level ) = 0;

//! Setup implementation.
virtual void setupImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) = 0;
virtual void setupImpl() = 0;

//! Solver implementation.
virtual void solveImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) = 0;
virtual void solveImpl() = 0;

//! Get the number of iterations taken on the last solve.
virtual int getNumIterImpl() = 0;
Expand Down Expand Up @@ -645,7 +643,6 @@ class HypreSemiStructuredSolver
}
}

private:
MPI_Comm _comm;
bool _is_preconditioner;
HYPRE_SStructGrid _grid;
Expand All @@ -670,12 +667,13 @@ class HypreSemiStructPCG
{
public:
//! Base HYPRE semi-structured solver type.
using Base = HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
using base_type =
HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
//! Constructor
template <class ArrayLayout_t>
HypreSemiStructPCG( const ArrayLayout_t& layout, int n_vars,
const bool is_preconditioner = false )
: Base( layout, n_vars, is_preconditioner )
: base_type( layout, n_vars, is_preconditioner )
{
if ( is_preconditioner )
throw std::logic_error(
Expand Down Expand Up @@ -743,17 +741,15 @@ class HypreSemiStructPCG
this->checkHypreError( error );
}

void setupImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) override
void setupImpl() override
{
auto error = HYPRE_SStructPCGSetup( _solver, A, b, x );
auto error = HYPRE_SStructPCGSetup( _solver, _A, _b, _x );
this->checkHypreError( error );
}

void solveImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) override
void solveImpl() override
{
auto error = HYPRE_SStructPCGSolve( _solver, A, b, x );
auto error = HYPRE_SStructPCGSolve( _solver, _A, _b, _x );
this->checkHypreError( error );
}

Expand Down Expand Up @@ -785,8 +781,10 @@ class HypreSemiStructPCG
this->checkHypreError( error );
}

private:
HYPRE_SStructSolver _solver;
using base_type::_A;
using base_type::_b;
using base_type::_x;
};

//---------------------------------------------------------------------------//
Expand All @@ -797,12 +795,13 @@ class HypreSemiStructGMRES
{
public:
//! Base HYPRE semi-structured solver type.
using Base = HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
using base_type =
HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
//! Constructor
template <class ArrayLayout_t>
HypreSemiStructGMRES( const ArrayLayout_t& layout, int n_vars,
const bool is_preconditioner = false )
: Base( layout, n_vars, is_preconditioner )
: base_type( layout, n_vars, is_preconditioner )
{
if ( is_preconditioner )
throw std::logic_error(
Expand Down Expand Up @@ -867,17 +866,15 @@ class HypreSemiStructGMRES
this->checkHypreError( error );
}

void setupImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) override
void setupImpl() override
{
auto error = HYPRE_SStructGMRESSetup( _solver, A, b, x );
auto error = HYPRE_SStructGMRESSetup( _solver, _A, _b, _x );
this->checkHypreError( error );
}

void solveImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) override
void solveImpl() override
{
auto error = HYPRE_SStructGMRESSolve( _solver, A, b, x );
auto error = HYPRE_SStructGMRESSolve( _solver, _A, _b, _x );
this->checkHypreError( error );
}

Expand Down Expand Up @@ -909,8 +906,10 @@ class HypreSemiStructGMRES
this->checkHypreError( error );
}

private:
HYPRE_SStructSolver _solver;
using base_type::_A;
using base_type::_b;
using base_type::_x;
};

//---------------------------------------------------------------------------//
Expand All @@ -921,13 +920,14 @@ class HypreSemiStructBiCGSTAB
{
public:
//! Base HYPRE semi-structured solver type.
using Base = HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
using base_type =
HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
//! Constructor
template <class ArrayLayout_t>
HypreSemiStructBiCGSTAB( const ArrayLayout_t& layout,
const bool is_preconditioner = false,
int n_vars = 3 )
: Base( layout, n_vars, is_preconditioner )
: base_type( layout, n_vars, is_preconditioner )
{
if ( is_preconditioner )
throw std::logic_error(
Expand Down Expand Up @@ -985,17 +985,15 @@ class HypreSemiStructBiCGSTAB
this->checkHypreError( error );
}

void setupImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) override
void setupImpl() override
{
auto error = HYPRE_SStructBiCGSTABSetup( _solver, A, b, x );
auto error = HYPRE_SStructBiCGSTABSetup( _solver, _A, _b, _x );
this->checkHypreError( error );
}

void solveImpl( HYPRE_SStructMatrix A, HYPRE_SStructVector b,
HYPRE_SStructVector x ) override
void solveImpl() override
{
auto error = HYPRE_SStructBiCGSTABSolve( _solver, A, b, x );
auto error = HYPRE_SStructBiCGSTABSolve( _solver, _A, _b, _x );
this->checkHypreError( error );
}

Expand Down Expand Up @@ -1028,8 +1026,10 @@ class HypreSemiStructBiCGSTAB
this->checkHypreError( error );
}

private:
HYPRE_SStructSolver _solver;
using base_type::_A;
using base_type::_b;
using base_type::_x;
};

//---------------------------------------------------------------------------//
Expand All @@ -1040,13 +1040,14 @@ class HypreSemiStructDiagonal
{
public:
//! Base HYPRE semi-structured solver type.
using Base = HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
using base_type =
HypreSemiStructuredSolver<Scalar, EntityType, MemorySpace>;
//! Constructor
template <class ArrayLayout_t>
HypreSemiStructDiagonal( const ArrayLayout_t& layout,
const bool is_preconditioner = false,
int n_vars = 3 )
: Base( layout, n_vars, is_preconditioner )
: base_type( layout, n_vars, is_preconditioner )
{
if ( !is_preconditioner )
throw std::logic_error(
Expand Down Expand Up @@ -1082,15 +1083,13 @@ class HypreSemiStructDiagonal
"Diagonal preconditioner cannot be used as a solver" );
}

void setupImpl( HYPRE_SStructMatrix, HYPRE_SStructVector,
HYPRE_SStructVector ) override
void setupImpl() override
{
throw std::logic_error(
"Diagonal preconditioner cannot be used as a solver" );
}

void solveImpl( HYPRE_SStructMatrix, HYPRE_SStructVector,
HYPRE_SStructVector ) override
void solveImpl() override
{
throw std::logic_error(
"Diagonal preconditioner cannot be used as a solver" );
Expand Down

0 comments on commit 55199bb

Please sign in to comment.