21#ifndef OPM_AMGX_PRECONDITIONER_HEADER_INCLUDED
22#define OPM_AMGX_PRECONDITIONER_HEADER_INCLUDED
24#include <opm/common/ErrorMacros.hpp>
25#include <opm/common/TimingMacros.hpp>
26#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
27#include <opm/simulators/linalg/PropertyTree.hpp>
28#include <opm/simulators/linalg/gpuistl/AmgxInterface.hpp>
30#include <dune/common/fmatrix.hh>
31#include <dune/istl/bcrsmatrix.hh>
38using AmgxInterface = Opm::gpuistl::AmgxInterface;
46 int determinism_flag = 0;
47 int print_grid_stats = 0;
48 int print_solve_stats = 0;
49 std::string solver =
"AMG";
50 std::string algorithm =
"CLASSICAL";
51 std::string interpolator =
"D2";
52 std::string selector =
"PMIS";
53 std::string smoother =
"BLOCK_JACOBI";
56 double strength_threshold = 0.5;
61 determinism_flag = prm.
get<
int>(
"determinism_flag", determinism_flag);
62 print_grid_stats = prm.
get<
int>(
"print_grid_stats", print_grid_stats);
63 print_solve_stats = prm.
get<
int>(
"print_solve_stats", print_solve_stats);
64 solver = prm.
get<std::string>(
"solver", solver);
65 algorithm = prm.
get<std::string>(
"algorithm", algorithm);
66 interpolator = prm.
get<std::string>(
"interpolator", interpolator);
67 selector = prm.
get<std::string>(
"selector", selector);
68 smoother = prm.
get<std::string>(
"smoother", smoother);
69 presweeps = prm.
get<
int>(
"presweeps", presweeps);
70 postsweeps = prm.
get<
int>(
"postsweeps", postsweeps);
71 strength_threshold = prm.
get<
double>(
"strength_threshold", strength_threshold);
72 max_iters = prm.
get<
int>(
"max_iters", max_iters);
75 std::string toString()
const {
76 return "config_version=2, "
77 "determinism_flag=" + std::to_string(determinism_flag) +
", "
78 "print_grid_stats=" + std::to_string(print_grid_stats) +
", "
79 "print_solve_stats=" + std::to_string(print_solve_stats) +
", "
80 "solver=" + solver +
", "
81 "algorithm=" + algorithm +
", "
82 "interpolator=" + interpolator +
", "
83 "selector=" + selector +
", "
84 "smoother=" + smoother +
", "
85 "presweeps=" + std::to_string(presweeps) +
", "
86 "postsweeps=" + std::to_string(postsweeps) +
", "
87 "strength_threshold=" + std::to_string(strength_threshold) +
", "
88 "max_iters=" + std::to_string(max_iters);
105template <
class M,
class X,
class Y>
120 static constexpr int block_size = 1;
132 , setup_frequency_(prm.get<int>(
"setup_frequency", 30))
135 OPM_TIMEBLOCK(prec_construct);
155 const int N = A_.N();
186 void pre(X& , Y& )
override
200 void apply(X& v,
const Y& d)
override
202 OPM_TIMEBLOCK(prec_apply);
209 AMGX_SAFE_CALL(AMGX_solver_solve(solver_, b_amgx_, x_amgx_));
233 OPM_TIMEBLOCK(prec_update);
238 if (update_counter_ == 0) {
239 AMGX_SAFE_CALL(AMGX_solver_setup(solver_, A_amgx_));
241 AMGX_SAFE_CALL(AMGX_solver_resetup(solver_, A_amgx_));
245 if (update_counter_ >= setup_frequency_) {
255 Dune::SolverCategory::Category
category()
const override
257 return Dune::SolverCategory::sequential;
277 AMGX_config_handle cfg_ =
nullptr;
278 AMGX_resources_handle rsrc_ =
nullptr;
279 AMGX_solver_handle solver_ =
nullptr;
280 AMGX_matrix_handle A_amgx_ =
nullptr;
281 AMGX_vector_handle x_amgx_ =
nullptr;
282 AMGX_vector_handle b_amgx_ =
nullptr;
283 AMGX_Mode amgx_mode_;
286 int setup_frequency_;
bool hasPerfectUpdate() const override
Checks if the preconditioner has a perfect update.
Definition AmgxPreconditioner.hpp:265
Y range_type
The range type of the preconditioner.
Definition AmgxPreconditioner.hpp:116
void update() override
Updates the preconditioner with the current matrix values.
Definition AmgxPreconditioner.hpp:231
void apply(X &v, const Y &d) override
Applies the preconditioner to a vector.
Definition AmgxPreconditioner.hpp:200
typename M::field_type matrix_field_type
The field type of the matrix.
Definition AmgxPreconditioner.hpp:112
AmgxPreconditioner(const M &A, const Opm::PropertyTree prm)
Constructor for AmgxPreconditioner.
Definition AmgxPreconditioner.hpp:130
Dune::SolverCategory::Category category() const override
Returns the solver category.
Definition AmgxPreconditioner.hpp:255
void pre(X &, Y &) override
Pre-processing step before applying the preconditioner.
Definition AmgxPreconditioner.hpp:186
X domain_type
The domain type of the preconditioner.
Definition AmgxPreconditioner.hpp:114
M matrix_type
The matrix type the preconditioner is for.
Definition AmgxPreconditioner.hpp:110
typename X::field_type vector_field_type
The field type of the vectors.
Definition AmgxPreconditioner.hpp:118
~AmgxPreconditioner()
Destructor for AmgxPreconditioner.
Definition AmgxPreconditioner.hpp:168
void post(X &) override
Post-processing step after applying the preconditioner.
Definition AmgxPreconditioner.hpp:222
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
Hierarchical collection of key/value pairs.
Definition PropertyTree.hpp:39
T get(const std::string &key) const
Retrieve property value given hierarchical property key.
Definition PropertyTree.cpp:59
static AMGX_Mode determineAmgxMode()
Determine the appropriate AMGX mode based on matrix and vector field types.
Definition AmgxInterface.hpp:613
static void destroyResources(AMGX_resources_handle resources)
Destroy an AMGX resources handle.
Definition AmgxInterface.hpp:244
static AMGX_resources_handle createResources(AMGX_config_handle config)
Create AMGX resources from a config.
Definition AmgxInterface.hpp:167
static void destroyVector(AMGX_vector_handle vector)
Destroy an AMGX vector handle.
Definition AmgxInterface.hpp:292
static AMGX_solver_handle createSolver(AMGX_resources_handle resources, AMGX_Mode mode, AMGX_config_handle config)
Create an AMGX solver.
Definition AmgxInterface.hpp:183
static void updateMatrixValues(const MatrixType &matrix, AMGX_matrix_handle amgx_matrix)
Update matrix values in AMGX.
Definition AmgxInterface.hpp:590
static void initializeVector(int N, int block_size, AMGX_vector_handle amgx_vector)
Initialize an AMGX vector with zeros.
Definition AmgxInterface.hpp:574
static void destroyConfig(AMGX_config_handle config)
Destroy an AMGX config handle.
Definition AmgxInterface.hpp:226
static AMGX_config_handle createConfig(const std::string &config_string)
Create an AMGX config handle from a configuration string.
Definition AmgxInterface.hpp:153
static void destroySolver(AMGX_solver_handle solver)
Destroy an AMGX solver handle.
Definition AmgxInterface.hpp:257
static AMGX_matrix_handle createMatrix(AMGX_resources_handle resources, AMGX_Mode mode)
Create an AMGX matrix.
Definition AmgxInterface.hpp:198
static void initializeMatrix(const MatrixType &matrix, AMGX_matrix_handle amgx_matrix)
Initialize an AMGX matrix from any matrix type (CPU or GPU).
Definition AmgxInterface.hpp:515
static AMGX_vector_handle createVector(AMGX_resources_handle resources, AMGX_Mode mode)
Create an AMGX vector.
Definition AmgxInterface.hpp:213
static void destroyMatrix(AMGX_matrix_handle amgx_matrix, const MatrixType &matrix)
Destroy an AMGX matrix handle.
Definition AmgxInterface.hpp:272
static void transferVectorToAmgx(const VectorType &vec, AMGX_vector_handle amgx_vec)
Transfer vector to AMGX from any vector type (CPU or GPU).
Definition AmgxInterface.hpp:370
static void transferVectorFromAmgx(AMGX_vector_handle amgx_vec, VectorType &vec)
Transfer vector from AMGX to any vector type (CPU or GPU).
Definition AmgxInterface.hpp:396
Configuration structure for AMGX parameters.
Definition AmgxPreconditioner.hpp:45