Hipace
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
hpmg::MultiGrid Class Reference

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::Boxm_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::FArrayBoxm_acf
 
amrex::Vector< amrex::FArrayBoxm_res
 
amrex::Vector< amrex::FArrayBoxm_cor
 
amrex::Vector< amrex::FArrayBoxm_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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MultiGrid()

hpmg::MultiGrid::MultiGrid ( amrex::Real  dx,
amrex::Real  dy,
amrex::Box  a_domain 
)
explicit

Ctor.

Parameters
[in]dxCell spacing in x direction
[in]dyCell spacing in y direction
[in]a_domainBox describing a 2D slice

◆ ~MultiGrid()

hpmg::MultiGrid::~MultiGrid ( )

Dtor.

Member Function Documentation

◆ average_down_acoef()

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.

◆ bottomsolve()

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.

◆ center_box()

static amrex::Box hpmg::MultiGrid::center_box ( amrex::Box  in_box,
amrex::Box  domain 
)
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.

◆ solve1()

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.

Parameters
[in,out]solthe initial guess and final solution
[in]rhsright hand side
[in]acoefthe coefficient
[in]tol_relrelative tolerance
[in]tol_absabsolute tolerance
[in]nummaxitermaximum number of iterations
[in]verboseverbosity level

◆ solve2() [1/4]

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.

Parameters
[in,out]solthe initial guess and final solution
[in]rhsright hand side
[in]acoef_realthe array real part of the coefficient
[in]acoef_imagthe array imaginary part of the coefficient
[in]tol_relrelative tolerance
[in]tol_absabsolute tolerance
[in]nummaxitermaximum number of iterations
[in]verboseverbosity level

◆ solve2() [2/4]

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.

Parameters
[in,out]solthe initial guess and final solution
[in]rhsright hand side
[in]acoef_realthe array real part of the coefficient
[in]acoef_imagthe constant imaginary part of the coefficient
[in]tol_relrelative tolerance
[in]tol_absabsolute tolerance
[in]nummaxitermaximum number of iterations
[in]verboseverbosity level

◆ solve2() [3/4]

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.

Parameters
[in,out]solthe initial guess and final solution
[in]rhsright hand side
[in]acoef_realthe constant real part of the coefficient
[in]acoef_imagthe array imaginary part of the coefficient
[in]tol_relrelative tolerance
[in]tol_absabsolute tolerance
[in]nummaxitermaximum number of iterations
[in]verboseverbosity level

◆ solve2() [4/4]

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.

Parameters
[in,out]solthe initial guess and final solution
[in]rhsright hand side
[in]acoef_realthe constant real part of the coefficient
[in]acoef_imagthe constant imaginary part of the coefficient
[in]tol_relrelative tolerance
[in]tol_absabsolute tolerance
[in]nummaxitermaximum number of iterations
[in]verboseverbosity level

◆ solve_doit()

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.

◆ vcycle()

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.

Member Data Documentation

◆ m_acf

amrex::Vector<amrex::FArrayBox> hpmg::MultiGrid::m_acf
private

Fabs for coefficient, one for each level

◆ m_acf_a

amrex::Array4<amrex::Real> const* hpmg::MultiGrid::m_acf_a = nullptr
private

Device pointer to Array4s used by the single-block kernel at the bottom

◆ m_cor

amrex::Vector<amrex::FArrayBox> hpmg::MultiGrid::m_cor
private

Fabs for correction, one for each level

◆ m_cor_a

amrex::Array4<amrex::Real> const* hpmg::MultiGrid::m_cor_a = nullptr
private

◆ m_d_array4

amrex::Gpu::DeviceVector<amrex::Array4<amrex::Real> > hpmg::MultiGrid::m_d_array4
private

Device vector of Array4s used by the single-block kernel at the bottom

◆ m_domain

amrex::Vector<amrex::Box> hpmg::MultiGrid::m_domain
private

2D slice domain

◆ m_dx

amrex::Real hpmg::MultiGrid::m_dx
private

Cell sizes

◆ m_dy

amrex::Real hpmg::MultiGrid::m_dy
private

◆ m_h_array4

amrex::Gpu::PinnedVector<amrex::Array4<amrex::Real> > hpmg::MultiGrid::m_h_array4
private

Pinned vector as a staging area for memcpy to device

◆ m_max_level

int hpmg::MultiGrid::m_max_level
private

Bottom MG level

◆ m_num_mg_levels

int hpmg::MultiGrid::m_num_mg_levels
private

Number of MG levels

◆ m_num_single_block_levels

int hpmg::MultiGrid::m_num_single_block_levels
private

Number of single-block-kernel levels

◆ m_num_system_types

constexpr int hpmg::MultiGrid::m_num_system_types = 2
staticconstexprprivate

◆ m_res

amrex::Vector<amrex::FArrayBox> hpmg::MultiGrid::m_res
private

Fabs for residual, one for each level

◆ m_res_a

amrex::Array4<amrex::Real> const* hpmg::MultiGrid::m_res_a = nullptr
private

◆ m_rescor

amrex::Vector<amrex::FArrayBox> hpmg::MultiGrid::m_rescor
private

Fabs for residual of the residual-correction form, one for each level

◆ m_rescor_a

amrex::Array4<amrex::Real> const* hpmg::MultiGrid::m_rescor_a = nullptr
private

◆ m_rhs

amrex::FArrayBox hpmg::MultiGrid::m_rhs
private

Alias to the RHS argument passed in solve()

◆ m_single_block_level_begin

int hpmg::MultiGrid::m_single_block_level_begin
private

The level below which a single block kernel is used

◆ m_sol

amrex::FArrayBox hpmg::MultiGrid::m_sol
private

Alias to the solution argument passed in solve()

◆ m_system_type

int hpmg::MultiGrid::m_system_type = 0
private

◆ m_use_single_block_kernel

bool hpmg::MultiGrid::m_use_single_block_kernel = true
private

If the single block kernel should be used

◆ nfabvs

constexpr int hpmg::MultiGrid::nfabvs = 4
staticconstexprprivate

Number of temporary fabs needed


The documentation for this class was generated from the following files: