Hipace
|
Main class handling all field data structures and operations. More...
#include <Fields.H>
Public Member Functions | |
Fields (const int nlev) | |
void | AllocData (int lev, amrex::Geometry const &geom, const amrex::BoxArray &slice_ba, const amrex::DistributionMapping &slice_dm, int bin_size) |
amrex::Vector< amrex::MultiFab > & | getSlices () |
amrex::MultiFab & | getSlices (int lev) |
const amrex::MultiFab & | getSlices (int lev) const |
amrex::MultiFab | getField (const int lev, const int islice, const std::string comp) |
amrex::MultiFab | getStagingArea (const int lev) |
amrex::Vector< amrex::FArrayBox > & | getTmpDensities () |
void | checkInit () |
void | Copy (const int lev, const int i_slice, FieldDiagnosticData &fd, const amrex::Geometry &calc_geom, MultiLaser &multi_laser) |
Copy between the full FArrayBox and slice MultiFab. More... | |
void | InitializeSlices (int lev, int islice, const amrex::Vector< amrex::Geometry > &geom) |
Initialize all required fields to zero and interpolate from lev-1 to lev if needed. More... | |
void | ShiftSlices (int lev) |
Shift slices by 1 element: slices (1,2) are then stored in (2,3). More... | |
void | AddRhoIons (const int lev) |
void | SetBoundaryCondition (amrex::Vector< amrex::Geometry > const &geom, const int lev, const int which_slice, std::string component, amrex::MultiFab &&staging_area) |
Set up boundary conditions before poisson solve lev==0: leave at zero or add open boundaries lev>0: interpolate boundaries from lev-1. More... | |
void | LevelUpBoundary (amrex::Vector< amrex::Geometry > const &geom, const int lev, const int which_slice, const std::string &component, const amrex::IntVect outer_edge, const amrex::IntVect inner_edge) |
Interpolate values from coarse grid (lev-1) to the boundary of the fine grid (lev). This may include ghost cells. More... | |
void | LevelUp (amrex::Vector< amrex::Geometry > const &geom, const int lev, const int which_slice, const std::string &component) |
Interpolate the full field from the coarse grid (lev-1) to the fine grid (lev). More... | |
void | SolvePoissonPsiExmByEypBxEzBz (amrex::Vector< amrex::Geometry > const &geom, const int current_N_level) |
Compute Psi, ExmBy, EypBx, Ez and Bz on the slice container from J by solving three poisson equations. ExmBy and EypBx computed from grad(-Psi). This function does all the necessary boundary interpolation between MR levels. More... | |
void | SolvePoissonEz (amrex::Vector< amrex::Geometry > const &geom, const int current_N_level, const int which_slice=WhichSlice::This) |
Compute Ez on the slice container from J by solving a Poisson equation. This function does all the necessary boundary interpolation between MR levels. More... | |
void | SolvePoissonBxBy (amrex::Vector< amrex::Geometry > const &geom, const int current_N_level, const int which_slice) |
Compute Bx and By on the slice container from J by solving two Poisson equations. This function does all the necessary boundary interpolation between MR levels. More... | |
void | SymmetrizeFields (int field_comp, const int lev, const int symm_x, const int symm_y) |
Symmetrize fields by averaging over (x,y), symm_x*(-x,y), symm_y*(x,-y) and symm_x*symm_y*(-x,-y) where symm_x and symm_y can be 1 or -1. More... | |
void | InitialBfieldGuess (const amrex::Real relative_Bfield_error, const amrex::Real predcorr_B_error_tolerance, const int lev) |
Sets the initial guess of the B field from the two previous slices. More... | |
void | MixAndShiftBfields (const amrex::Real relative_Bfield_error, const amrex::Real relative_Bfield_error_prev_iter, const amrex::Real predcorr_B_mixing_factor, const int lev) |
Mixes the B field with the calculated current and previous iteration of it and shifts the current to the previous iteration afterwards. This modifies component Bx or By of slice 1 in m_fields.m_slices. More... | |
amrex::Real | ComputeRelBFieldError (const int which_slice, const int which_slice_iter, const amrex::Vector< amrex::Geometry > &geom, const int current_N_level) |
Function to calculate the relative B field error used in the predictor corrector loop. More... | |
void | InSituComputeDiags (int step, amrex::Real time, int islice, const amrex::Geometry &geom3D, int max_step, amrex::Real max_time) |
void | InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry &geom3D, int max_step, amrex::Real max_time) |
template<class... Args> | |
void | setVal (const amrex::Real val, const int lev, const int islice, Args...comps) |
set all selected fields to a value More... | |
template<class... Args> | |
void | mult (const amrex::Real val, const int lev, const int islice, Args...comps) |
multiply all selected fields with a value More... | |
template<class... Args> | |
void | shift (const int lev, const int islice_dst, const int islice_src, Args...comps) |
copy all selected fields between slices More... | |
template<int ncomps> | |
void | duplicate (const int lev, const int islice_dst, const char *const (&comps_dst)[ncomps], const int islice_src, const char *const (&comps_src)[ncomps]) |
copy all selected fields between slices or on the same slice Uses references to C-arrays as argument so that ncomps can be deduced More... | |
template<int ncomps> | |
void | add (const int lev, const int islice_dst, const char *const (&comps_dst)[ncomps], const int islice_src, const char *const (&comps_src)[ncomps]) |
add all selected fields between slices or on the same slice Uses references to C-arrays as argument so that ncomps can be deduced More... | |
template<class... Args> | |
void | FillBoundary (const amrex::Periodicity &period, const int lev, const int islice, Args...comps) |
call amrex FillBoundary for multiple fields More... | |
Public Attributes | |
amrex::Vector< std::unique_ptr< FFTPoissonSolver > > | m_poisson_solver |
bool | m_extended_solve = false |
bool | m_do_symmetrize = false |
Static Public Attributes | |
static amrex::IntVect | m_slices_nguards {-1, -1, -1} |
static amrex::IntVect | m_poisson_nguards {-1, -1, -1} |
Private Attributes | |
amrex::Vector< amrex::MultiFab > | m_slices |
bool | m_do_dirichlet_poisson = true |
amrex::Vector< amrex::FArrayBox > | m_tmp_densities |
amrex::Gpu::DeviceVector< amrex::Real > | m_rel_z_vec |
amrex::Gpu::PinnedVector< amrex::Real > | m_rel_z_vec_cpu |
amrex::IntVect | m_exmby_eypbx_nguard |
amrex::IntVect | m_source_nguard |
bool | m_open_boundary = false |
bool | m_explicit = false |
bool | m_any_neutral_background = false |
int | m_insitu_period {0} |
amrex::Vector< amrex::Real > | m_insitu_rdata |
amrex::Vector< amrex::Real > | m_insitu_sum_rdata |
std::string | m_insitu_file_prefix = "diags/field_insitu" |
Static Private Attributes | |
static constexpr int | m_insitu_nrp = 10 |
Main class handling all field data structures and operations.
This is a fundamental class of Hipace, handling initialization of the fields, operations on arrays, exchanges between the 3D array and 2D slices.
|
explicit |
Constructor
|
inline |
add all selected fields between slices or on the same slice Uses references to C-arrays as argument so that ncomps can be deduced
[in] | lev | level of fields |
[in] | islice_dst | destination slice |
[in] | comps_dst | array of destination component names |
[in] | islice_src | source slice |
[in] | comps_src | array of source component names |
void Fields::AddRhoIons | ( | const int | lev | ) |
add rho of the ions to rho (this slice)
void Fields::AllocData | ( | int | lev, |
amrex::Geometry const & | geom, | ||
const amrex::BoxArray & | slice_ba, | ||
const amrex::DistributionMapping & | slice_dm, | ||
int | bin_size | ||
) |
Allocate MultiFabs for the 3D array and the 2D slices and define the BoxArrays and DistributionMappings.
[in] | lev | MR level |
[in] | geom | Geometry |
[in] | slice_ba | BoxArray for the slice |
[in] | slice_dm | DistributionMapping for the slice |
[in] | bin_size | size of plasma tiles, for tmp arrays |
|
inline |
check whether the fields are initialized correctly
amrex::Real Fields::ComputeRelBFieldError | ( | const int | which_slice, |
const int | which_slice_iter, | ||
const amrex::Vector< amrex::Geometry > & | geom, | ||
const int | current_N_level | ||
) |
Function to calculate the relative B field error used in the predictor corrector loop.
[in] | which_slice | slice of Bx and By field |
[in] | which_slice_iter | slice of Bx and By field from the previous iteration |
[in] | geom | Geometry of the problem |
[in] | current_N_level | number of MR levels active on the current slice |
void Fields::Copy | ( | const int | lev, |
const int | i_slice, | ||
FieldDiagnosticData & | fd, | ||
const amrex::Geometry & | calc_geom, | ||
MultiLaser & | multi_laser | ||
) |
Copy between the full FArrayBox and slice MultiFab.
[in] | lev | MR level |
[in] | i_slice | z slice in which to write the data |
[in,out] | fd | data for field diagnostics |
[in] | calc_geom | main geometry |
[in] | multi_laser | MultiLaser object |
|
inline |
copy all selected fields between slices or on the same slice Uses references to C-arrays as argument so that ncomps can be deduced
[in] | lev | level of fields |
[in] | islice_dst | destination slice |
[in] | comps_dst | array of destination component names |
[in] | islice_src | source slice |
[in] | comps_src | array of source component names |
|
inline |
call amrex FillBoundary for multiple fields
[in] | period | periodicity of the fields |
[in] | lev | level of fields |
[in] | islice | slice of fields |
[in] | comps | names of fields like "Ez", "Bx", "By", "Bz" |
|
inline |
get amrex::MultiFab of a field in a slice
[in] | lev | MR level |
[in] | islice | slice index |
[in] | comp | component name of field (see Comps) |
|
inline |
get function for the 2D slices
|
inline |
get function for the 2D slices
[in] | lev | MR level |
|
inline |
get function for the 2D slices (const version)
[in] | lev | MR level |
|
inline |
get amrex::MultiFab of the poisson staging area
[in] | lev | MR level |
|
inline |
Return reference to density tile arrays
void Fields::InitialBfieldGuess | ( | const amrex::Real | relative_Bfield_error, |
const amrex::Real | predcorr_B_error_tolerance, | ||
const int | lev | ||
) |
Sets the initial guess of the B field from the two previous slices.
This modifies component Bx or By of slice 1 in m_fields.m_slices
[in] | relative_Bfield_error | relative B field error used to determine the mixing factor |
[in] | predcorr_B_error_tolerance | relative B field error tolerance in the predcorr loop |
[in] | lev | current level |
void Fields::InitializeSlices | ( | int | lev, |
int | islice, | ||
const amrex::Vector< amrex::Geometry > & | geom | ||
) |
Initialize all required fields to zero and interpolate from lev-1 to lev if needed.
[in] | lev | the MR level |
[in] | islice | current slice index |
[in] | geom | 3D Geometry |
void Fields::InSituComputeDiags | ( | int | step, |
amrex::Real | time, | ||
int | islice, | ||
const amrex::Geometry & | geom3D, | ||
int | max_step, | ||
amrex::Real | max_time | ||
) |
Compute in-situ field diagnostics of current slice, store in member variable
[in] | step | current time step |
[in] | time | physical time |
[in] | islice | current slice, on which diags are computed. |
[in] | geom3D | Geometry of the problem |
[in] | max_step | maximum time step of simulation |
[in] | max_time | maximum time of simulation |
void Fields::InSituWriteToFile | ( | int | step, |
amrex::Real | time, | ||
const amrex::Geometry & | geom3D, | ||
int | max_step, | ||
amrex::Real | max_time | ||
) |
Dump in-situ reduced diagnostics to file.
[in] | step | current time step |
[in] | time | physical time |
[in] | geom3D | Geometry object for the whole domain |
[in] | max_step | maximum time step of simulation |
[in] | max_time | maximum time of simulation |
void Fields::LevelUp | ( | amrex::Vector< amrex::Geometry > const & | geom, |
const int | lev, | ||
const int | which_slice, | ||
const std::string & | component | ||
) |
Interpolate the full field from the coarse grid (lev-1) to the fine grid (lev).
[in] | geom | Geometry |
[in] | lev | current level |
[in] | which_slice | slice of the field to interpolate |
[in] | component | which can be jx_beam or jy_beam etc. |
void Fields::LevelUpBoundary | ( | amrex::Vector< amrex::Geometry > const & | geom, |
const int | lev, | ||
const int | which_slice, | ||
const std::string & | component, | ||
const amrex::IntVect | outer_edge, | ||
const amrex::IntVect | inner_edge | ||
) |
Interpolate values from coarse grid (lev-1) to the boundary of the fine grid (lev). This may include ghost cells.
[in] | geom | Geometry |
[in] | lev | current level |
[in] | which_slice | slice of the field to interpolate |
[in] | component | which can be Psi or rho etc. |
[in] | outer_edge | start writing interpolated values at domain + outer_edge |
[in] | inner_edge | stop writing interpolated values at domain + inner_edge |
void Fields::MixAndShiftBfields | ( | const amrex::Real | relative_Bfield_error, |
const amrex::Real | relative_Bfield_error_prev_iter, | ||
const amrex::Real | predcorr_B_mixing_factor, | ||
const int | lev | ||
) |
Mixes the B field with the calculated current and previous iteration of it and shifts the current to the previous iteration afterwards. This modifies component Bx or By of slice 1 in m_fields.m_slices.
[in] | relative_Bfield_error | relative B field error used to determine the mixing factor |
[in] | relative_Bfield_error_prev_iter | relative B field error of the previous iteration |
[in] | predcorr_B_mixing_factor | mixing factor for B fields in predcorr loop |
[in] | lev | current level |
|
inline |
multiply all selected fields with a value
[in] | val | value |
[in] | lev | level of fields |
[in] | islice | slice of fields |
[in] | comps | names of fields like "Ez", "Bx", "By", "Bz" |
void Fields::SetBoundaryCondition | ( | amrex::Vector< amrex::Geometry > const & | geom, |
const int | lev, | ||
const int | which_slice, | ||
std::string | component, | ||
amrex::MultiFab && | staging_area | ||
) |
Set up boundary conditions before poisson solve lev==0: leave at zero or add open boundaries lev>0: interpolate boundaries from lev-1.
[in] | geom | Geometry |
[in] | lev | current level |
[in] | which_slice | slice of the field |
[in] | component | which can be Psi, Ez, By, Bx ... |
[in,out] | staging_area | Target MultiFab where the boundary condition is applied |
|
inline |
set all selected fields to a value
[in] | val | value |
[in] | lev | level of fields |
[in] | islice | slice of fields |
[in] | comps | names of fields like "Ez", "Bx", "By", "Bz" |
|
inline |
copy all selected fields between slices
[in] | lev | level of fields |
[in] | islice_dst | destination slice |
[in] | islice_src | source slice |
[in] | comps | names of fields like "Ez", "Bx", "By", "Bz" |
void Fields::ShiftSlices | ( | int | lev | ) |
Shift slices by 1 element: slices (1,2) are then stored in (2,3).
When looping over slices from head to tail, the same slice MultiFabs are used to compute each slice. The current slice is always stored in index 1. Hence, after one slice is computed, slices must be shifted by 1 element.
[in] | lev | the MR level |
void Fields::SolvePoissonBxBy | ( | amrex::Vector< amrex::Geometry > const & | geom, |
const int | current_N_level, | ||
const int | which_slice | ||
) |
Compute Bx and By on the slice container from J by solving two Poisson equations. This function does all the necessary boundary interpolation between MR levels.
[in] | geom | Geometry |
[in] | current_N_level | number of MR levels active on the current slice |
[in] | which_slice | slice to put the result into |
void Fields::SolvePoissonEz | ( | amrex::Vector< amrex::Geometry > const & | geom, |
const int | current_N_level, | ||
const int | which_slice = WhichSlice::This |
||
) |
Compute Ez on the slice container from J by solving a Poisson equation. This function does all the necessary boundary interpolation between MR levels.
[in] | geom | Geometry |
[in] | current_N_level | number of MR levels active on the current slice |
[in] | which_slice | defines if this or the salame slice is handled |
void Fields::SolvePoissonPsiExmByEypBxEzBz | ( | amrex::Vector< amrex::Geometry > const & | geom, |
const int | current_N_level | ||
) |
Compute Psi, ExmBy, EypBx, Ez and Bz on the slice container from J by solving three poisson equations. ExmBy and EypBx computed from grad(-Psi). This function does all the necessary boundary interpolation between MR levels.
[in] | geom | Geometry |
[in] | current_N_level | number of MR levels active on the current slice |
Symmetrize fields by averaging over (x,y), symm_x*(-x,y), symm_y*(x,-y) and symm_x*symm_y*(-x,-y) where symm_x and symm_y can be 1 or -1.
[in] | field_comp | component index of the filed |
[in] | lev | current level |
[in] | symm_x | type of reflection in x direction |
[in] | symm_y | type of reflection in y direction |
|
private |
If any plasma species has a neutralizing background
|
private |
Whether to use Dirichlet BC for the Poisson solver. Otherwise, periodic
bool Fields::m_do_symmetrize = false |
Whether the currents should be symmetrized for the field solve
|
private |
Number of guard cells where ExmBy and EypBx are calculated
|
private |
If the explicit solver is being used
bool Fields::m_extended_solve = false |
If the poisson solver should include the guard cells
|
private |
Prefix/path for the output files
|
staticconstexprprivate |
Number of real field properties for in-situ per-slice reduced diagnostics.
|
private |
How often the insitu field diagnostics should be computed and written Default is 0, meaning no output
|
private |
All per-slice real field properties
|
private |
Sum of all per-slice real field properties
|
private |
If lev_0 should be solved with open boundary conditions
|
inlinestatic |
Number of guard cells for poisson solver MultiFab
amrex::Vector<std::unique_ptr<FFTPoissonSolver> > Fields::m_poisson_solver |
Class to handle transverse FFT Poisson solver on 1 slice
|
private |
Stores temporary values for z interpolation in Fields::Copy
|
private |
Stores temporary values for z interpolation in Fields::Copy on the CPU
|
private |
Vector over levels of all required fields to compute current slice
|
inlinestatic |
Number of guard cells for slices MultiFab
|
private |
Number of guard cells where sources for poisson equation are included
|
private |
Temporary density arrays. one per OpenMP thread, used when tiling is on.