Hipace
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
Fields Class Reference

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::MultiFabgetSlices (int lev)
 
const amrex::MultiFabgetSlices (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::MultiFabm_slices
 
bool m_do_dirichlet_poisson = true
 
amrex::Vector< amrex::FArrayBoxm_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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Fields()

Fields::Fields ( const int  nlev)
explicit

Constructor

Member Function Documentation

◆ add()

template<int ncomps>
void Fields::add ( const int  lev,
const int  islice_dst,
const char *const (&)  comps_dst[ncomps],
const int  islice_src,
const char *const (&)  comps_src[ncomps] 
)
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

Parameters
[in]levlevel of fields
[in]islice_dstdestination slice
[in]comps_dstarray of destination component names
[in]islice_srcsource slice
[in]comps_srcarray of source component names

◆ AddRhoIons()

void Fields::AddRhoIons ( const int  lev)

add rho of the ions to rho (this slice)

◆ AllocData()

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.

Parameters
[in]levMR level
[in]geomGeometry
[in]slice_baBoxArray for the slice
[in]slice_dmDistributionMapping for the slice
[in]bin_sizesize of plasma tiles, for tmp arrays

◆ checkInit()

void Fields::checkInit ( )
inline

check whether the fields are initialized correctly

◆ ComputeRelBFieldError()

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.

Parameters
[in]which_sliceslice of Bx and By field
[in]which_slice_iterslice of Bx and By field from the previous iteration
[in]geomGeometry of the problem
[in]current_N_levelnumber of MR levels active on the current slice

◆ Copy()

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.

Parameters
[in]levMR level
[in]i_slicez slice in which to write the data
[in,out]fddata for field diagnostics
[in]calc_geommain geometry
[in]multi_laserMultiLaser object

◆ duplicate()

template<int ncomps>
void Fields::duplicate ( const int  lev,
const int  islice_dst,
const char *const (&)  comps_dst[ncomps],
const int  islice_src,
const char *const (&)  comps_src[ncomps] 
)
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

Parameters
[in]levlevel of fields
[in]islice_dstdestination slice
[in]comps_dstarray of destination component names
[in]islice_srcsource slice
[in]comps_srcarray of source component names

◆ FillBoundary()

template<class... Args>
void Fields::FillBoundary ( const amrex::Periodicity period,
const int  lev,
const int  islice,
Args...  comps 
)
inline

call amrex FillBoundary for multiple fields

Parameters
[in]periodperiodicity of the fields
[in]levlevel of fields
[in]isliceslice of fields
[in]compsnames of fields like "Ez", "Bx", "By", "Bz"

◆ getField()

amrex::MultiFab Fields::getField ( const int  lev,
const int  islice,
const std::string  comp 
)
inline

get amrex::MultiFab of a field in a slice

Parameters
[in]levMR level
[in]isliceslice index
[in]compcomponent name of field (see Comps)

◆ getSlices() [1/3]

amrex::Vector<amrex::MultiFab>& Fields::getSlices ( )
inline

get function for the 2D slices

◆ getSlices() [2/3]

amrex::MultiFab& Fields::getSlices ( int  lev)
inline

get function for the 2D slices

Parameters
[in]levMR level

◆ getSlices() [3/3]

const amrex::MultiFab& Fields::getSlices ( int  lev) const
inline

get function for the 2D slices (const version)

Parameters
[in]levMR level

◆ getStagingArea()

amrex::MultiFab Fields::getStagingArea ( const int  lev)
inline

get amrex::MultiFab of the poisson staging area

Parameters
[in]levMR level

◆ getTmpDensities()

amrex::Vector<amrex::FArrayBox>& Fields::getTmpDensities ( )
inline

Return reference to density tile arrays

◆ InitialBfieldGuess()

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

Parameters
[in]relative_Bfield_errorrelative B field error used to determine the mixing factor
[in]predcorr_B_error_tolerancerelative B field error tolerance in the predcorr loop
[in]levcurrent level

◆ InitializeSlices()

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.

Parameters
[in]levthe MR level
[in]islicecurrent slice index
[in]geom3D Geometry

◆ InSituComputeDiags()

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

Parameters
[in]stepcurrent time step
[in]timephysical time
[in]islicecurrent slice, on which diags are computed.
[in]geom3DGeometry of the problem
[in]max_stepmaximum time step of simulation
[in]max_timemaximum time of simulation

◆ InSituWriteToFile()

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.

Parameters
[in]stepcurrent time step
[in]timephysical time
[in]geom3DGeometry object for the whole domain
[in]max_stepmaximum time step of simulation
[in]max_timemaximum time of simulation

◆ LevelUp()

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).

Parameters
[in]geomGeometry
[in]levcurrent level
[in]which_sliceslice of the field to interpolate
[in]componentwhich can be jx_beam or jy_beam etc.

◆ LevelUpBoundary()

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.

Parameters
[in]geomGeometry
[in]levcurrent level
[in]which_sliceslice of the field to interpolate
[in]componentwhich can be Psi or rho etc.
[in]outer_edgestart writing interpolated values at domain + outer_edge
[in]inner_edgestop writing interpolated values at domain + inner_edge

◆ MixAndShiftBfields()

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.

Parameters
[in]relative_Bfield_errorrelative B field error used to determine the mixing factor
[in]relative_Bfield_error_prev_iterrelative B field error of the previous iteration
[in]predcorr_B_mixing_factormixing factor for B fields in predcorr loop
[in]levcurrent level

◆ mult()

template<class... Args>
void Fields::mult ( const amrex::Real  val,
const int  lev,
const int  islice,
Args...  comps 
)
inline

multiply all selected fields with a value

Parameters
[in]valvalue
[in]levlevel of fields
[in]isliceslice of fields
[in]compsnames of fields like "Ez", "Bx", "By", "Bz"

◆ SetBoundaryCondition()

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.

Parameters
[in]geomGeometry
[in]levcurrent level
[in]which_sliceslice of the field
[in]componentwhich can be Psi, Ez, By, Bx ...
[in,out]staging_areaTarget MultiFab where the boundary condition is applied

◆ setVal()

template<class... Args>
void Fields::setVal ( const amrex::Real  val,
const int  lev,
const int  islice,
Args...  comps 
)
inline

set all selected fields to a value

Parameters
[in]valvalue
[in]levlevel of fields
[in]isliceslice of fields
[in]compsnames of fields like "Ez", "Bx", "By", "Bz"

◆ shift()

template<class... Args>
void Fields::shift ( const int  lev,
const int  islice_dst,
const int  islice_src,
Args...  comps 
)
inline

copy all selected fields between slices

Parameters
[in]levlevel of fields
[in]islice_dstdestination slice
[in]islice_srcsource slice
[in]compsnames of fields like "Ez", "Bx", "By", "Bz"

◆ ShiftSlices()

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.

Parameters
[in]levthe MR level

◆ SolvePoissonBxBy()

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.

Parameters
[in]geomGeometry
[in]current_N_levelnumber of MR levels active on the current slice
[in]which_sliceslice to put the result into

◆ SolvePoissonEz()

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.

Parameters
[in]geomGeometry
[in]current_N_levelnumber of MR levels active on the current slice
[in]which_slicedefines if this or the salame slice is handled

◆ SolvePoissonPsiExmByEypBxEzBz()

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.

Parameters
[in]geomGeometry
[in]current_N_levelnumber of MR levels active on the current slice

◆ SymmetrizeFields()

void Fields::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.

Parameters
[in]field_compcomponent index of the filed
[in]levcurrent level
[in]symm_xtype of reflection in x direction
[in]symm_ytype of reflection in y direction

Member Data Documentation

◆ m_any_neutral_background

bool Fields::m_any_neutral_background = false
private

If any plasma species has a neutralizing background

◆ m_do_dirichlet_poisson

bool Fields::m_do_dirichlet_poisson = true
private

Whether to use Dirichlet BC for the Poisson solver. Otherwise, periodic

◆ m_do_symmetrize

bool Fields::m_do_symmetrize = false

Whether the currents should be symmetrized for the field solve

◆ m_exmby_eypbx_nguard

amrex::IntVect Fields::m_exmby_eypbx_nguard
private

Number of guard cells where ExmBy and EypBx are calculated

◆ m_explicit

bool Fields::m_explicit = false
private

If the explicit solver is being used

◆ m_extended_solve

bool Fields::m_extended_solve = false

If the poisson solver should include the guard cells

◆ m_insitu_file_prefix

std::string Fields::m_insitu_file_prefix = "diags/field_insitu"
private

Prefix/path for the output files

◆ m_insitu_nrp

constexpr int Fields::m_insitu_nrp = 10
staticconstexprprivate

Number of real field properties for in-situ per-slice reduced diagnostics.

◆ m_insitu_period

int Fields::m_insitu_period {0}
private

How often the insitu field diagnostics should be computed and written Default is 0, meaning no output

◆ m_insitu_rdata

amrex::Vector<amrex::Real> Fields::m_insitu_rdata
private

All per-slice real field properties

◆ m_insitu_sum_rdata

amrex::Vector<amrex::Real> Fields::m_insitu_sum_rdata
private

Sum of all per-slice real field properties

◆ m_open_boundary

bool Fields::m_open_boundary = false
private

If lev_0 should be solved with open boundary conditions

◆ m_poisson_nguards

amrex::IntVect Fields::m_poisson_nguards {-1, -1, -1}
inlinestatic

Number of guard cells for poisson solver MultiFab

◆ m_poisson_solver

amrex::Vector<std::unique_ptr<FFTPoissonSolver> > Fields::m_poisson_solver

Class to handle transverse FFT Poisson solver on 1 slice

◆ m_rel_z_vec

amrex::Gpu::DeviceVector<amrex::Real> Fields::m_rel_z_vec
private

Stores temporary values for z interpolation in Fields::Copy

◆ m_rel_z_vec_cpu

amrex::Gpu::PinnedVector<amrex::Real> Fields::m_rel_z_vec_cpu
private

Stores temporary values for z interpolation in Fields::Copy on the CPU

◆ m_slices

amrex::Vector<amrex::MultiFab> Fields::m_slices
private

Vector over levels of all required fields to compute current slice

◆ m_slices_nguards

amrex::IntVect Fields::m_slices_nguards {-1, -1, -1}
inlinestatic

Number of guard cells for slices MultiFab

◆ m_source_nguard

amrex::IntVect Fields::m_source_nguard
private

Number of guard cells where sources for poisson equation are included

◆ m_tmp_densities

amrex::Vector<amrex::FArrayBox> Fields::m_tmp_densities
private

Temporary density arrays. one per OpenMP thread, used when tiling is on.


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