Hipace
|
Multigrid solver. More...
#include <HpMultiGrid.H>
Public Member Functions | |
MultiGrid (amrex::Real dx, amrex::Real dy, amrex::Box a_domain) | |
Ctor. More... | |
~MultiGrid () | |
Dtor. More... | |
void | solve1 (amrex::FArrayBox &sol, amrex::FArrayBox const &rhs, amrex::FArrayBox const &acoef, amrex::Real const tol_rel, amrex::Real const tol_abs, int const nummaxiter, int const verbose) |
Solve the Type I equation given the initial guess, right hand side, and the coefficient. More... | |
void | solve2 (amrex::FArrayBox &sol, amrex::FArrayBox const &rhs, amrex::Real const acoef_real, amrex::Real const acoef_imag, amrex::Real const tol_rel, amrex::Real const tol_abs, int const nummaxiter, int const verbose) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient. More... | |
void | solve2 (amrex::FArrayBox &sol, amrex::FArrayBox const &rhs, amrex::Real const acoef_real, amrex::FArrayBox const &acoef_imag, amrex::Real const tol_rel, amrex::Real const tol_abs, int const nummaxiter, int const verbose) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient. More... | |
void | solve2 (amrex::FArrayBox &sol, amrex::FArrayBox const &rhs, amrex::FArrayBox const &acoef_real, amrex::Real const acoef_imag, amrex::Real const tol_rel, amrex::Real const tol_abs, int const nummaxiter, int const verbose) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient. More... | |
void | solve2 (amrex::FArrayBox &sol, amrex::FArrayBox const &rhs, amrex::FArrayBox const &acoef_real, amrex::FArrayBox const &acoef_imag, amrex::Real const tol_rel, amrex::Real const tol_abs, int const nummaxiter, int const verbose) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient. More... | |
void | average_down_acoef () |
Average down the coefficient. Ideally, this function is not supposed to be a public function. It's made public due to a CUDA limitation. More... | |
void | vcycle () |
Perform a V-cycle. Ideally, this function is not supposed to be a public function. It's made public due to a CUDA limitation. More... | |
void | bottomsolve () |
Solve at the bottom of the V-cycle. Ideally, this function is not supposed to be a public function. It's made public due to a CUDA limitation. More... | |
void | solve_doit (amrex::FArrayBox &sol, amrex::FArrayBox const &rhs, amrex::Real const tol_rel, amrex::Real const tol_abs, int const nummaxiter, int const verbose) |
Private function used by solve1 and solve2. It's made public due to a CUDA limitation. More... | |
Static Public Member Functions | |
static amrex::Box | center_box (amrex::Box in_box, amrex::Box domain) |
Centers the input box in x and y around the domain so that only the ghost cells "overhang". Make it a slab in the z direction and set the index to 0. More... | |
Private Attributes | |
int | m_system_type = 0 |
amrex::Vector< amrex::Box > | m_domain |
amrex::Real | m_dx |
amrex::Real | m_dy |
int | m_max_level |
int | m_single_block_level_begin |
int | m_num_mg_levels |
int | m_num_single_block_levels |
bool | m_use_single_block_kernel = true |
amrex::FArrayBox | m_sol |
amrex::FArrayBox | m_rhs |
amrex::Vector< amrex::FArrayBox > | m_acf |
amrex::Vector< amrex::FArrayBox > | m_res |
amrex::Vector< amrex::FArrayBox > | m_cor |
amrex::Vector< amrex::FArrayBox > | m_rescor |
amrex::Array4< amrex::Real > const * | m_acf_a = nullptr |
amrex::Array4< amrex::Real > const * | m_res_a = nullptr |
amrex::Array4< amrex::Real > const * | m_cor_a = nullptr |
amrex::Array4< amrex::Real > const * | m_rescor_a = nullptr |
amrex::Gpu::PinnedVector< amrex::Array4< amrex::Real > > | m_h_array4 |
amrex::Gpu::DeviceVector< amrex::Array4< amrex::Real > > | m_d_array4 |
Static Private Attributes | |
static constexpr int | m_num_system_types = 2 |
static constexpr int | nfabvs = 4 |
Multigrid solver.
This solves -acoef * sol + Lap(sol) = rhs
with homogeneous Dirichlet BC on a 2D slice. It can solve two types of linear systems.
(1) sol and rhs have two components, whereas acoef has only one component. For Type I, call solve1(...).
(2) acoef, sol, rhs are complex numbers. The system is equivalent to -acoef_real * sol_real + acoef_imag * sol_imag + Lap(sol_real) = rhs_real -acoef_imag * sol_real - acoef_real * sol_imag + Lap(sol_imag) = rhs_imag For Type II, call solve2(...). Here, acoef_real and acoef_imag can be either a scalar constant or FArrayBox.
|
explicit |
Ctor.
[in] | dx | Cell spacing in x direction |
[in] | dy | Cell spacing in y direction |
[in] | a_domain | Box describing a 2D slice |
hpmg::MultiGrid::~MultiGrid | ( | ) |
Dtor.
void hpmg::MultiGrid::average_down_acoef | ( | ) |
Average down the coefficient. Ideally, this function is not supposed to be a public function. It's made public due to a CUDA limitation.
void hpmg::MultiGrid::bottomsolve | ( | ) |
Solve at the bottom of the V-cycle. Ideally, this function is not supposed to be a public function. It's made public due to a CUDA limitation.
|
inlinestatic |
Centers the input box in x and y around the domain so that only the ghost cells "overhang". Make it a slab in the z direction and set the index to 0.
void hpmg::MultiGrid::solve1 | ( | amrex::FArrayBox & | sol, |
amrex::FArrayBox const & | rhs, | ||
amrex::FArrayBox const & | acoef, | ||
amrex::Real const | tol_rel, | ||
amrex::Real const | tol_abs, | ||
int const | nummaxiter, | ||
int const | verbose | ||
) |
Solve the Type I equation given the initial guess, right hand side, and the coefficient.
[in,out] | sol | the initial guess and final solution |
[in] | rhs | right hand side |
[in] | acoef | the coefficient |
[in] | tol_rel | relative tolerance |
[in] | tol_abs | absolute tolerance |
[in] | nummaxiter | maximum number of iterations |
[in] | verbose | verbosity level |
void hpmg::MultiGrid::solve2 | ( | amrex::FArrayBox & | sol, |
amrex::FArrayBox const & | rhs, | ||
amrex::FArrayBox const & | acoef_real, | ||
amrex::FArrayBox const & | acoef_imag, | ||
amrex::Real const | tol_rel, | ||
amrex::Real const | tol_abs, | ||
int const | nummaxiter, | ||
int const | verbose | ||
) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient.
[in,out] | sol | the initial guess and final solution |
[in] | rhs | right hand side |
[in] | acoef_real | the array real part of the coefficient |
[in] | acoef_imag | the array imaginary part of the coefficient |
[in] | tol_rel | relative tolerance |
[in] | tol_abs | absolute tolerance |
[in] | nummaxiter | maximum number of iterations |
[in] | verbose | verbosity level |
void hpmg::MultiGrid::solve2 | ( | amrex::FArrayBox & | sol, |
amrex::FArrayBox const & | rhs, | ||
amrex::FArrayBox const & | acoef_real, | ||
amrex::Real const | acoef_imag, | ||
amrex::Real const | tol_rel, | ||
amrex::Real const | tol_abs, | ||
int const | nummaxiter, | ||
int const | verbose | ||
) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient.
[in,out] | sol | the initial guess and final solution |
[in] | rhs | right hand side |
[in] | acoef_real | the array real part of the coefficient |
[in] | acoef_imag | the constant imaginary part of the coefficient |
[in] | tol_rel | relative tolerance |
[in] | tol_abs | absolute tolerance |
[in] | nummaxiter | maximum number of iterations |
[in] | verbose | verbosity level |
void hpmg::MultiGrid::solve2 | ( | amrex::FArrayBox & | sol, |
amrex::FArrayBox const & | rhs, | ||
amrex::Real const | acoef_real, | ||
amrex::FArrayBox const & | acoef_imag, | ||
amrex::Real const | tol_rel, | ||
amrex::Real const | tol_abs, | ||
int const | nummaxiter, | ||
int const | verbose | ||
) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient.
[in,out] | sol | the initial guess and final solution |
[in] | rhs | right hand side |
[in] | acoef_real | the constant real part of the coefficient |
[in] | acoef_imag | the array imaginary part of the coefficient |
[in] | tol_rel | relative tolerance |
[in] | tol_abs | absolute tolerance |
[in] | nummaxiter | maximum number of iterations |
[in] | verbose | verbosity level |
void hpmg::MultiGrid::solve2 | ( | amrex::FArrayBox & | sol, |
amrex::FArrayBox const & | rhs, | ||
amrex::Real const | acoef_real, | ||
amrex::Real const | acoef_imag, | ||
amrex::Real const | tol_rel, | ||
amrex::Real const | tol_abs, | ||
int const | nummaxiter, | ||
int const | verbose | ||
) |
Solve the Type II equation given the initial guess, right hand side, and the coefficient.
[in,out] | sol | the initial guess and final solution |
[in] | rhs | right hand side |
[in] | acoef_real | the constant real part of the coefficient |
[in] | acoef_imag | the constant imaginary part of the coefficient |
[in] | tol_rel | relative tolerance |
[in] | tol_abs | absolute tolerance |
[in] | nummaxiter | maximum number of iterations |
[in] | verbose | verbosity level |
void hpmg::MultiGrid::solve_doit | ( | amrex::FArrayBox & | sol, |
amrex::FArrayBox const & | rhs, | ||
amrex::Real const | tol_rel, | ||
amrex::Real const | tol_abs, | ||
int const | nummaxiter, | ||
int const | verbose | ||
) |
Private function used by solve1 and solve2. It's made public due to a CUDA limitation.
void hpmg::MultiGrid::vcycle | ( | ) |
Perform a V-cycle. Ideally, this function is not supposed to be a public function. It's made public due to a CUDA limitation.
|
private |
Fabs for coefficient, one for each level
|
private |
Device pointer to Array4s used by the single-block kernel at the bottom
|
private |
Fabs for correction, one for each level
|
private |
|
private |
Device vector of Array4s used by the single-block kernel at the bottom
|
private |
2D slice domain
|
private |
Cell sizes
|
private |
|
private |
Pinned vector as a staging area for memcpy to device
|
private |
Bottom MG level
|
private |
Number of MG levels
|
private |
Number of single-block-kernel levels
|
staticconstexprprivate |
|
private |
Fabs for residual, one for each level
|
private |
|
private |
Fabs for residual of the residual-correction form, one for each level
|
private |
|
private |
Alias to the RHS argument passed in solve()
|
private |
The level below which a single block kernel is used
|
private |
Alias to the solution argument passed in solve()
|
private |
|
private |
If the single block kernel should be used
|
staticconstexprprivate |
Number of temporary fabs needed