diff --git a/grid/src/Cabana_Grid_HypreSemiStructuredSolver.hpp b/grid/src/Cabana_Grid_HypreSemiStructuredSolver.hpp index b551ea60c..9db313018 100644 --- a/grid/src/Cabana_Grid_HypreSemiStructuredSolver.hpp +++ b/grid/src/Cabana_Grid_HypreSemiStructuredSolver.hpp @@ -482,7 +482,7 @@ class HypreSemiStructuredSolver auto error = HYPRE_SStructMatrixAssemble( _A ); checkHypreError( error ); - this->setupImpl( _A, _b, _x ); + this->setupImpl(); } /*! @@ -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 ) @@ -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; @@ -645,6 +643,13 @@ class HypreSemiStructuredSolver } } + //! Matrix for the problem Ax = b. + HYPRE_SStructMatrix _A; + //! Forcing term for the problem Ax = b. + HYPRE_SStructVector _b; + //! Solution to the problem Ax = b. + HYPRE_SStructVector _x; + private: MPI_Comm _comm; bool _is_preconditioner; @@ -655,9 +660,6 @@ class HypreSemiStructuredSolver HYPRE_SStructGraph _graph; std::vector _stencil_size; std::vector> _stencil_index; - HYPRE_SStructMatrix _A; - HYPRE_SStructVector _b; - HYPRE_SStructVector _x; std::shared_ptr> _preconditioner; }; @@ -670,12 +672,13 @@ class HypreSemiStructPCG { public: //! Base HYPRE semi-structured solver type. - using Base = HypreSemiStructuredSolver; + using base_type = + HypreSemiStructuredSolver; //! Constructor template 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( @@ -743,17 +746,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 ); } @@ -787,6 +788,9 @@ class HypreSemiStructPCG private: HYPRE_SStructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -797,12 +801,13 @@ class HypreSemiStructGMRES { public: //! Base HYPRE semi-structured solver type. - using Base = HypreSemiStructuredSolver; + using base_type = + HypreSemiStructuredSolver; //! Constructor template 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( @@ -867,17 +872,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 ); } @@ -911,6 +914,9 @@ class HypreSemiStructGMRES private: HYPRE_SStructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -921,13 +927,14 @@ class HypreSemiStructBiCGSTAB { public: //! Base HYPRE semi-structured solver type. - using Base = HypreSemiStructuredSolver; + using base_type = + HypreSemiStructuredSolver; //! Constructor template 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( @@ -985,17 +992,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 ); } @@ -1030,6 +1035,9 @@ class HypreSemiStructBiCGSTAB private: HYPRE_SStructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -1040,13 +1048,14 @@ class HypreSemiStructDiagonal { public: //! Base HYPRE semi-structured solver type. - using Base = HypreSemiStructuredSolver; + using base_type = + HypreSemiStructuredSolver; //! Constructor template 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( @@ -1082,15 +1091,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" ); diff --git a/grid/src/Cabana_Grid_HypreStructuredSolver.hpp b/grid/src/Cabana_Grid_HypreStructuredSolver.hpp index 79d962158..f8a8f7941 100644 --- a/grid/src/Cabana_Grid_HypreStructuredSolver.hpp +++ b/grid/src/Cabana_Grid_HypreStructuredSolver.hpp @@ -346,7 +346,7 @@ class HypreStructuredSolver throw std::logic_error( "Cannot call setup() on preconditioners" ); // FIXME: appears to be a memory issue in the call to this function - this->setupImpl( _A, _b, _x ); + this->setupImpl(); } /*! @@ -407,7 +407,7 @@ class HypreStructuredSolver checkHypreError( error ); // Solve the problem - this->solveImpl( _A, _b, _x ); + this->solveImpl(); // Extract the solution from the LHS error = HYPRE_StructVectorGetBoxValues( @@ -448,12 +448,10 @@ class HypreStructuredSolver virtual void setPrintLevelImpl( const int print_level ) = 0; //! Setup implementation. - virtual void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) = 0; + virtual void setupImpl() = 0; //! Solver implementation. - virtual void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) = 0; + virtual void solveImpl() = 0; //! Get the number of iterations taken on the last solve. virtual int getNumIterImpl() = 0; @@ -481,6 +479,14 @@ class HypreStructuredSolver } } + protected: + //! Matrix for the problem Ax = b. + HYPRE_StructMatrix _A; + //! Forcing term for the problem Ax = b. + HYPRE_StructVector _b; + //! Solution to the problem Ax = b. + HYPRE_StructVector _x; + private: MPI_Comm _comm; bool _is_preconditioner; @@ -489,9 +495,6 @@ class HypreStructuredSolver std::vector _upper; HYPRE_StructStencil _stencil; unsigned _stencil_size; - HYPRE_StructMatrix _A; - HYPRE_StructVector _b; - HYPRE_StructVector _x; std::shared_ptr> _preconditioner; }; @@ -504,12 +507,12 @@ class HypreStructPCG { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructPCG( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { if ( is_preconditioner ) throw std::logic_error( @@ -577,17 +580,15 @@ class HypreStructPCG this->checkHypreError( error ); } - void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void setupImpl() override { - auto error = HYPRE_StructPCGSetup( _solver, A, b, x ); + auto error = HYPRE_StructPCGSetup( _solver, _A, _b, _x ); this->checkHypreError( error ); } - void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void solveImpl() override { - auto error = HYPRE_StructPCGSolve( _solver, A, b, x ); + auto error = HYPRE_StructPCGSolve( _solver, _A, _b, _x ); this->checkHypreError( error ); } @@ -621,6 +622,9 @@ class HypreStructPCG private: HYPRE_StructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -631,12 +635,12 @@ class HypreStructGMRES { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructGMRES( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { if ( is_preconditioner ) throw std::logic_error( @@ -701,17 +705,15 @@ class HypreStructGMRES this->checkHypreError( error ); } - void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void setupImpl() override { - auto error = HYPRE_StructGMRESSetup( _solver, A, b, x ); + auto error = HYPRE_StructGMRESSetup( _solver, _A, _b, _x ); this->checkHypreError( error ); } - void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void solveImpl() override { - auto error = HYPRE_StructGMRESSolve( _solver, A, b, x ); + auto error = HYPRE_StructGMRESSolve( _solver, _A, _b, _x ); this->checkHypreError( error ); } @@ -745,6 +747,9 @@ class HypreStructGMRES private: HYPRE_StructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -755,12 +760,12 @@ class HypreStructBiCGSTAB { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructBiCGSTAB( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { if ( is_preconditioner ) throw std::logic_error( @@ -818,17 +823,15 @@ class HypreStructBiCGSTAB this->checkHypreError( error ); } - void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void setupImpl() override { - auto error = HYPRE_StructBiCGSTABSetup( _solver, A, b, x ); + auto error = HYPRE_StructBiCGSTABSetup( _solver, _A, _b, _x ); this->checkHypreError( error ); } - void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void solveImpl() override { - auto error = HYPRE_StructBiCGSTABSolve( _solver, A, b, x ); + auto error = HYPRE_StructBiCGSTABSolve( _solver, _A, _b, _x ); this->checkHypreError( error ); } @@ -862,6 +865,9 @@ class HypreStructBiCGSTAB private: HYPRE_StructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -872,12 +878,12 @@ class HypreStructPFMG { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructPFMG( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { auto error = HYPRE_StructPFMGCreate( layout.localGrid()->globalGrid().comm(), &_solver ); @@ -1006,17 +1012,15 @@ class HypreStructPFMG this->checkHypreError( error ); } - void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void setupImpl() override { - auto error = HYPRE_StructPFMGSetup( _solver, A, b, x ); + auto error = HYPRE_StructPFMGSetup( _solver, _A, _b, _x ); this->checkHypreError( error ); } - void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void solveImpl() override { - auto error = HYPRE_StructPFMGSolve( _solver, A, b, x ); + auto error = HYPRE_StructPFMGSolve( _solver, _A, _b, _x ); this->checkHypreError( error ); } @@ -1046,6 +1050,9 @@ class HypreStructPFMG private: HYPRE_StructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -1056,12 +1063,12 @@ class HypreStructSMG { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructSMG( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { auto error = HYPRE_StructSMGCreate( layout.localGrid()->globalGrid().comm(), &_solver ); @@ -1136,17 +1143,15 @@ class HypreStructSMG this->checkHypreError( error ); } - void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void setupImpl() override { - auto error = HYPRE_StructSMGSetup( _solver, A, b, x ); + auto error = HYPRE_StructSMGSetup( _solver, _A, _b, _x ); this->checkHypreError( error ); } - void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void solveImpl() override { - auto error = HYPRE_StructSMGSolve( _solver, A, b, x ); + auto error = HYPRE_StructSMGSolve( _solver, _A, _b, _x ); this->checkHypreError( error ); } @@ -1176,6 +1181,9 @@ class HypreStructSMG private: HYPRE_StructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -1186,12 +1194,12 @@ class HypreStructJacobi { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructJacobi( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { auto error = HYPRE_StructJacobiCreate( layout.localGrid()->globalGrid().comm(), &_solver ); @@ -1234,17 +1242,15 @@ class HypreStructJacobi // The Jacobi solver does not support a print level. } - void setupImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void setupImpl() override { - auto error = HYPRE_StructJacobiSetup( _solver, A, b, x ); + auto error = HYPRE_StructJacobiSetup( _solver, _A, _b, _x ); this->checkHypreError( error ); } - void solveImpl( HYPRE_StructMatrix A, HYPRE_StructVector b, - HYPRE_StructVector x ) override + void solveImpl() override { - auto error = HYPRE_StructJacobiSolve( _solver, A, b, x ); + auto error = HYPRE_StructJacobiSolve( _solver, _A, _b, _x ); this->checkHypreError( error ); } @@ -1274,6 +1280,9 @@ class HypreStructJacobi private: HYPRE_StructSolver _solver; + using base_type::_A; + using base_type::_b; + using base_type::_x; }; //---------------------------------------------------------------------------// @@ -1284,12 +1293,12 @@ class HypreStructDiagonal { public: //! Base HYPRE structured solver type. - using Base = HypreStructuredSolver; + using base_type = HypreStructuredSolver; //! Constructor template HypreStructDiagonal( const ArrayLayout_t& layout, const bool is_preconditioner = false ) - : Base( layout, is_preconditioner ) + : base_type( layout, is_preconditioner ) { if ( !is_preconditioner ) throw std::logic_error( @@ -1325,15 +1334,13 @@ class HypreStructDiagonal "Diagonal preconditioner cannot be used as a solver" ); } - void setupImpl( HYPRE_StructMatrix, HYPRE_StructVector, - HYPRE_StructVector ) override + void setupImpl() override { throw std::logic_error( "Diagonal preconditioner cannot be used as a solver" ); } - void solveImpl( HYPRE_StructMatrix, HYPRE_StructVector, - HYPRE_StructVector ) override + void solveImpl() override { throw std::logic_error( "Diagonal preconditioner cannot be used as a solver" );