Commit 8f6b22d6 authored by Marcel Koch's avatar Marcel Koch
Browse files

add AMG preconditioner choice

parent 6e443c35
......@@ -6,9 +6,12 @@
#include <ginkgo/core/matrix/block_matrix.hpp>
#include <ginkgo/core/matrix/identity.hpp>
#include <ginkgo/core/matrix/zero.hpp>
#include <ginkgo/core/multigrid/amgx_pgm.hpp>
#include <ginkgo/core/preconditioner/jacobi.hpp>
#include <ginkgo/core/solver/bicgstab.hpp>
#include <ginkgo/core/solver/gmres.hpp>
#include <ginkgo/core/solver/ir.hpp>
#include <ginkgo/core/solver/multigrid.hpp>
#include <ginkgo/core/stop/iteration.hpp>
#include <ginkgo/core/stop/residual_norm.hpp>
#include <hyteg/composites/petsc/P2P1TaylorHoodPetsc.hpp>
......@@ -79,13 +82,17 @@ class GinkgoBlockSolver : public Solver< OperatorType >
explicit GinkgoBlockSolver( const std::shared_ptr< PrimitiveStorage >& storage,
const uint_t& level,
std::shared_ptr< const gko::Executor > exec )
std::shared_ptr< const gko::Executor > exec,
const uint_t& velocityPreconditionerType = 1,
const uint_t& pressurePreconditionerType = 1 )
: storage_( storage )
, solver_exec_( exec )
, host_exec_( exec->get_master() )
, comm_( gko::mpi::communicator::create( storage->getSplitCommunicatorByPrimitiveDistribution() ) )
, blockPreconditioner_( storage, level, level )
, num_( "numerator", storage, level, level )
, velocityPreconditionerType_( velocityPreconditionerType )
, pressurePreconditionerType_( pressurePreconditionerType )
, printInfo_( true )
{}
......@@ -196,18 +203,70 @@ class GinkgoBlockSolver : public Solver< OperatorType >
gko::span block_v_span{ 0, global_v_size };
gko::span block_p_span{ global_v_size, global_v_size + global_p_size };
device_monolithic_pre->permute( &perm );
auto b_pre_v = gko::share(
gko::preconditioner::Jacobi< valueType >::build()
.with_max_block_size( 1u )
.on( solver_exec_ )
->generate( gko::share( device_monolithic_pre->create_submatrix( block_v_span, block_v_span ) ) ) );
auto b_pre_p = gko::share(
gko::preconditioner::Jacobi< valueType >::build()
.with_max_block_size( 1u )
.on( solver_exec_ )
->generate( gko::share( device_monolithic_pre->create_submatrix( block_p_span, block_p_span ) ) ) );
device_monolithic_pre = gko::as< csr >( device_monolithic_pre->permute( &perm ) );
std::shared_ptr< gko::LinOp > b_pre_v;
std::shared_ptr< gko::LinOp > b_pre_p;
auto jac_gen =
gko::share( gko::preconditioner::Jacobi< valueType >::build().with_max_block_size( 1u ).on( solver_exec_ ) );
if ( velocityPreconditionerType_ == 0 )
{
b_pre_v = gko::share( gko::matrix::Identity< valueType >::create(
solver_exec_, gko::dim< 2 >( block_v_span.length(), block_v_span.length() ) ) );
}
else if ( velocityPreconditionerType_ == 1 )
{
b_pre_v = gko::share(
jac_gen->generate( gko::share( device_monolithic_pre->create_submatrix( block_v_span, block_v_span ) ) ) );
}
else if ( velocityPreconditionerType_ == 2 )
{
auto smoother_gen =
gko::share( gko::solver::Ir< valueType >::build()
.with_solver( jac_gen )
.with_relaxation_factor( 0.9 )
.with_criteria( gko::stop::Iteration::build().with_max_iters( 2u ).on( solver_exec_ ) )
.on( solver_exec_ ) );
auto mg_level_gen = gko::multigrid::AmgxPgm< valueType >::build().with_deterministic( true ).on( solver_exec_ );
auto coarsest_gen =
gko::share( gko::solver::Ir< valueType >::build()
.with_solver( jac_gen )
.with_relaxation_factor( 0.9 )
.with_criteria( gko::stop::Iteration::build().with_max_iters( 4u ).on( solver_exec_ ) )
.on( solver_exec_ ) );
b_pre_v = gko::share(
gko::solver::Multigrid::build()
.with_max_levels( 9u )
.with_min_coarse_rows( 10u )
.with_pre_smoother( smoother_gen )
.with_post_uses_pre( true )
.with_mg_level( gko::share( mg_level_gen ) )
.with_coarsest_solver( coarsest_gen )
.with_zero_guess( true )
.with_criteria( gko::stop::Iteration::build().with_max_iters( 1u ).on( solver_exec_ ) )
.on( solver_exec_ )
->generate( gko::share( device_monolithic_pre->create_submatrix( block_v_span, block_v_span ) ) ) );
}
else
{
WALBERLA_ABORT( "Invalid velocity preconditioner for Ginkgo block prec BiCGStab solver." );
}
if ( pressurePreconditionerType_ == 0 )
{
b_pre_p = gko::share( gko::matrix::Identity< valueType >::create(
solver_exec_, gko::dim< 2 >( block_p_span.length(), block_p_span.length() ) ) );
}
else if ( pressurePreconditionerType_ == 1 )
{
b_pre_p = gko::share(
jac_gen->generate( gko::share( device_monolithic_pre->create_submatrix( block_p_span, block_p_span ) ) ) );
}
else
{
WALBERLA_ABORT( "Invalid pressure preconditioner for Ginkgo block prec BiCGStab solver." );
}
auto b_pre_vp = gko::share(
gko::matrix::Zero< valueType >::create( solver_exec_, gko::dim< 2 >{ global_v_size, global_p_size } ) );
......@@ -305,6 +364,9 @@ class GinkgoBlockSolver : public Solver< OperatorType >
std::vector< gko::Array< gko::distributed::global_index_type > > gather_idxs_;
uint_t velocityPreconditionerType_;
uint_t pressurePreconditionerType_;
bool printInfo_ = false;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment