1 #ifndef ELECTRIC_FIELD_HPP
2 #define ELECTRIC_FIELD_HPP
21 template<KinType KT, PhiInterpType PIT, MarkerType MT, MagneticFieldMode MFM>
35 template<KinType KT, MarkerType MT>
37 using t = Pack<Labeled<typename getGyroVecFldType<KT>::t,
Label::E>,
46 template<KinType KT, MarkerType MT>
48 using t = Pack<Labeled<typename getGyroVecFldType<KT>::t,
Label::E>>;
54 using t = Pack<Labeled<typename getGyroVecFldType<KT>::t,
Label::E>,
60 template<KinType KT, MarkerType MT>
63 using t = Pack<Labeled<Efield2DGyroType, Label::E>,
68 using t = Pack<Labeled<Efield2DGyroType, Label::E>>;
86 template<
class Device>
140 View<double*,CLayout, HostType>
pot0m;
206 if(es_reduced_deltaf_setup){
209 dpotsave = View<double***,CLayout, HostType>(
"dpotsave", 2, 2,
nnode);
221 bool em_mixed_variable = nlr.
get<
bool>(
"sml_em_mixed_variable",
true);
222 bool em_control_variate = nlr.
get<
bool>(
"sml_em_control_variate",
false);
223 int em_pullback_mode = nlr.
get<
int>(
"sml_em_pullback_mode",3);
225 if (!em_mixed_variable)
226 exit_XGC(
"\nError: sml_em_mixed_variable is explicitly set to .false. which is incompatible with EXPLICIT_EM\n");
237 if (em_control_variate){
242 if (em_mixed_variable){
245 if (em_pullback_mode==4){
263 const double initial_loop_vol = nlr.
get<
double>(
"src_loop_voltage",0.0);
265 for (
int inode=0; inode<
nnode; inode++){
274 template<MarkerType MT>
306 int n_input_field_planes =
pot0_h.nphi();
307 bool gradient_requested =
true;
308 bool gyroaverage_requested =
false;
310 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
315 bool potential_is_requested =
false;
317 pfg.
calculate_phi_ff_on_device(sml,grid, magnetic_field, smoothing, gpg_tmp,
my_subview(
dpot_h.f, 2),
pot0_h, gfpack.template get<Label::E>(), unused_pot, potential_is_requested, use_field00, ignore_poloidal_dpot);
344 return std::make_unique<gfp_push_type>(gfpack);
347 template<MarkerType MT>
352 GPTLstart(
"Copy_rho_ff_fields_to_device");
361 GPTLstop(
"Copy_rho_ff_fields_to_device");
372 return std::make_unique<gfp_push_type>(gfpack);
380 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::ReducedDeltaF>(sml, pol_decomp, magnetic_field, grid, smoothing, near_field);
382 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::ReducedDeltaF>(sml, pol_decomp, magnetic_field, grid, smoothing, near_field);
386 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::TotalF>(sml, pol_decomp, magnetic_field, grid, smoothing, near_field);
388 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::TotalF>(sml, pol_decomp, magnetic_field, grid, smoothing, near_field);
411 return std::make_unique<gfp_push_type>(gfpack);
429 int n_input_field_planes =
Ah_h.nphi();
430 bool gradient_requested =
false;
431 bool gyroaverage_requested =
true;
434 GPTLstop(
"GET_AH_RHO_FF_ALLOC_VIEWS");
440 FieldArgs gpg_field_args(
Ah_h.unmanaged());
441 gpg_field_args.request_potential(
Ah);
442 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
444 GPTLstop(
"GET_AH_RHO_FF_EXCL_DESTR");
464 int n_input_field_planes =
dpot_h.nphi();
465 bool gradient_requested =
true;
466 bool gyroaverage_requested =
true;
468 gyroaverage_requested =
false;
473 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
500 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
510 gpg_field_args = FieldArgs(
Ah_h.unmanaged());
515 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
521 gpg_field_args = FieldArgs(
As_h.unmanaged());
526 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
533 TIMER(
"GET_POT_APAR_CV",
541 View<double*,CLayout,HostType> Er_B2_h(
"Er_B2_h",grid.
nnode);
542 View<double*,CLayout,HostType> Ez_B2_h(
"Ez_B2_h",grid.
nnode);
543 View<double*,CLayout,HostType> u2_E_h(
"u2_E_h",grid.
nnode);
545 TIMER(
"GET_POT_SONIC",
548 gpg_field_args = FieldArgs(Er_B2_h);
550 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
552 gpg_field_args = FieldArgs(Ez_B2_h);
554 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
556 gpg_field_args = FieldArgs(u2_E_h);
558 get_field_grad(sml, grid, pol_decomp, magnetic_field, smoothing, gpg_field_args, tmp);
565 GPTLstop(
"GET_POT_GRAD_EXCL_DESTR");
570 int field_n_rho = nlr.
get<
int>(
"sml_grid_nrho", 6);
573 int n_fields = 3 + 1;
577 double host_field_GB_per_vertex = (53 + 8*grid.
nplanes + 11*(field_n_rho + 1))*8*
BYTES_TO_GB;
578 double cpu_memory_usage = grid.
nnode*host_field_GB_per_vertex;
580 double device_field_GB_per_vertex = std::max(n_fields*8*grid.
nplanes, n_fields*8*(field_n_rho+1))*8*
BYTES_TO_GB;
581 double gpu_memory_usage = grid.
nnode*device_field_GB_per_vertex;
583 MemoryPrediction memory_prediction{
"Collisions", cpu_memory_usage, gpu_memory_usage};
585 return memory_prediction;
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > Ah_h_backup
Definition: electric_field.hpp:110
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > ddpotdt
Time derivative of - Not field-following?
Definition: electric_field.hpp:106
Boundary pbdH
Definition: electric_field.hpp:159
bool decompose_fields
Whether to decompose fields.
Definition: domain_decomposition.hpp:85
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > pot
Definition: electric_field.hpp:121
Definition: field_following_coordinates.hpp:9
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
BiasPotential bias_potential
Definition: electric_field.hpp:151
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > jpara_diff_integral_h
Definition: electric_field.hpp:148
Definition: bias_potential.hpp:7
Definition: electric_field.hpp:22
std::unique_ptr< GridFieldPackGeneric > GridFieldPackPtr
Definition: grid_field_pack.hpp:21
GridFieldPackPtr copy_push_fields_to_device(KinType kintype_in, MarkerType markertype_in, const Simulation< DeviceType > &sml, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, Smoothing &smoothing, bool near_field=false) const
Definition: electric_field.hpp:377
int first_plane
First plane belonging to this rank, including ghost planes.
Definition: field_decomposition.hpp:35
MarkerType
Definition: globals.hpp:110
void set_rho_ff_pointers(int n, Field< VarType::Scalar, PhiInterpType::None > *dpot, Field< VarType::Scalar, PhiInterpType::Planes > *dpot_ff)
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::MultiplePlanes, KinType::DriftKin > PotType
Definition: grid_field.hpp:486
void get_potential_grad(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, Smoothing &smoothing, const View< double *, CLayout, HostType > &spitzer_resistivity, Species< DeviceType > &species)
Definition: electric_field.hpp:459
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAh
Definition: electric_field.hpp:111
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
Definition: field.hpp:301
constexpr double BYTES_TO_GB
Definition: constants.hpp:12
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > loop_voltage_h
Definition: electric_field.hpp:146
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > Ah
Definition: electric_field.hpp:112
Definition: field.hpp:145
bool em_mixed_variable
Switch for use of mixed-variable formulation.
Definition: sml.hpp:66
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > E00_ff_h
Radial electric field from in field-following format.
Definition: electric_field.hpp:105
View< double *, CLayout, HostType > dpot_es
Definition: electric_field.hpp:138
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > dpot_ff_h
Definition: electric_field.hpp:124
void request_para_em(const GridField< DeviceOut, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > &output_field, double em_pullback_dampfac_in, const View< double *, CLayout, HostType > &spitzer_resistivity, const Boundary &boundary, bool gyroaverage_requested)
Definition: get_potential_grad.hpp:312
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:19
bool reduced_deltaf
True if any species is reduced_deltaf. Will be removed.
Definition: sml.hpp:36
static constexpr bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:25
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > As_h
Definition: electric_field.hpp:113
void copy_to_device_if_not_resident()
Definition: gyro_avg_mat.hpp:50
int plane_index
Offset of local plane.
Definition: domain_decomposition.hpp:82
Definition: globals.hpp:89
Definition: plane_field_gatherer.hpp:9
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:68
KOKKOS_INLINE_FUNCTION int find_domain_owner(int global_plane_index, int nplanes_total, int global_node_index, int nnodes_total) const
Definition: field_decomposition.hpp:136
int nrho
Definition: electric_field.hpp:94
void get_Ah_rho_ff(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, Smoothing &smoothing, Species< DeviceType > &species)
Definition: electric_field.hpp:424
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
static MemoryPrediction estimate_memory_usage(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid)
Definition: electric_field.hpp:568
Definition: get_potential_grad.hpp:276
Simple00Solver simple00
Definition: electric_field.hpp:143
void cnvt_grid_real2ff(const Grid< DeviceType > &grid, const View< double **, CLayout, DeviceType > &input, const View< double **, Kokkos::LayoutRight, DeviceType > &output) const
Definition: field_following_coordinates.hpp:169
Definition: electric_field.hpp:87
void get_field_grad(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, Smoothing &smoothing, GetPotGradFieldArgs< DeviceIn, DeviceOut, VT, PIT, TT, KT > &args, GetPotentialGradTemp< DeviceType, DeviceOut > &tmp)
Definition: get_potential_grad.cpp:395
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > pot0_h
Definition: electric_field.hpp:133
int nplanes
Number of planes.
Definition: grid.hpp:169
GridField< DeviceType, VarType::Vector, PhiInterpType::Planes, TorType::MultiplePlanes, KinType::DriftKin > EfieldType
Definition: grid_field.hpp:484
Definition: grid_field_pack.hpp:24
int node_offset
Offset of first mesh node belonging to this MPI rank.
Definition: domain_decomposition.hpp:89
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:67
Projection< HostType > half_plane_ff
Definition: grid.hpp:188
void deallocate_device_matrices_if_not_resident()
Definition: gyro_avg_mat.hpp:56
Boundary pbd0
Definition: electric_field.hpp:157
Definition: grid_field.hpp:22
Definition: boundary.hpp:81
View< double ***, CLayout, HostType > save_dpot
Definition: electric_field.hpp:136
int em_pullback_mode
Definition: sml.hpp:68
bool grad_psitheta
Definition: sml.hpp:89
GridFieldPackPtr copy_push_fields_to_device_gyro_kin_XGC1(const Simulation< DeviceType > &sml, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, Smoothing &smoothing, bool near_field=false) const
Definition: electric_field.hpp:348
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > Ah_cv
Definition: electric_field.hpp:118
ElectricField()
Definition: electric_field.hpp:162
PhiInterpType
Definition: globals.hpp:95
#define TIMER(N, F)
Definition: timer_macro.hpp:24
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Ah_cv_h
Definition: electric_field.hpp:117
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:355
constexpr PhiInterpType PIT_GLOBAL
Definition: globals.hpp:103
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > As_h_backup
Definition: electric_field.hpp:114
Definition: memory_prediction.hpp:4
Boundary AbdH
Definition: electric_field.hpp:155
Boundary jbdH
Definition: electric_field.hpp:154
void grid_field_copy(T &dest, const T &src)
Definition: grid_field.hpp:496
Definition: smoothing.hpp:9
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dEz_B2
Gradient of Ez/B^2.
Definition: electric_field.hpp:128
void gather_phi_ff_on_device(View< FT **, CLayout, HostType > &tmp, View< FT *, CLayout, HostType > &tmp_full, const T_h &rho_ff_h, View< FT **, CLayout, DeviceType > &phi_ff)
Definition: plane_field_gatherer.hpp:197
Field00< DeviceType > field00
Definition: get_potential_grad.hpp:283
Definition: globals.hpp:90
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAs
Definition: electric_field.hpp:115
Pack< Labeled< typename getGyroVecFldType< KT >::t, Label::E >> t
Definition: electric_field.hpp:48
void request_potential(const GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > &potential_in)
Definition: get_potential_grad.hpp:302
Pack< Labeled< Efield2DGyroType, Label::E >> t
Definition: electric_field.hpp:68
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Ah_h
Definition: electric_field.hpp:109
bool E00_efield
Flux-surface averaged potential not used for calculating the electric field if .false.
Definition: electric_field.hpp:101
Definition: simple00_solver.hpp:7
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dEr_B2
Gradient of Er/B^2.
Definition: electric_field.hpp:127
View< double *, CLayout, HostType > pot00_1d
1D flux-surface averaged potential
Definition: electric_field.hpp:141
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > du2_E
Gradient of the square (dot product) of the E x B drift.
Definition: electric_field.hpp:129
KinType
Definition: globals.hpp:88
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > jpara_diff_previous_h
Definition: electric_field.hpp:147
View< int *, CLayout, HostType > all_first_plane
First plane of each rank.
Definition: field_decomposition.hpp:43
bool namelist_present(const string &namelist)
Definition: NamelistReader.hpp:351
bool electron_on
Use kinetic electrons.
Definition: sml.hpp:54
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > Epar_em
Definition: electric_field.hpp:119
Definition: electric_field.hpp:28
void get_sonic_fields(const Grid< DeviceType > &grid, const GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >(), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > &E, View< double *, CLayout, HostType > &Er_B2_h, View< double *, CLayout, HostType > &Ez_B2_h, View< double *, CLayout, HostType > &u2_E_h)
bool calculate_phi_ff_on_device
Definition: electric_field.hpp:97
void exit_XGC(std::string msg)
Definition: globals.hpp:37
Kokkos::View< T *, Kokkos::LayoutRight, Device > my_subview(const Kokkos::View< T ****, Kokkos::LayoutRight, Device > &view, int i, int j, int k)
Definition: my_subview.hpp:8
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > PotGyroType
Definition: grid_field.hpp:490
Definition: magnetic_field.F90:1
Definition: electric_field.hpp:24
bool turb_efield
E-field calculated only with if .false., psndpot will still contain all (n=0,|m|>0) and (|n|>0...
Definition: electric_field.hpp:100
Pack< Labeled< typename getGyroVecFldType< KT >::t, Label::E >, Labeled< E00Type, Label::E00 >, Labeled< PotType, Label::ddpotdt >> t
Definition: electric_field.hpp:56
View< double *, CLayout, HostType > pot0m
n=0 component of the electrostatic potential before smoothing
Definition: electric_field.hpp:140
View< double ***, CLayout, HostType > save_dpot0
Definition: electric_field.hpp:135
int nphi
Definition: electric_field.hpp:91
Boundary cbdH
Definition: electric_field.hpp:158
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > As
Definition: electric_field.hpp:116
int nnode
Definition: electric_field.hpp:90
FieldDecomposition< Device > field_decomp
Definition: domain_decomposition.hpp:86
Definition: species.hpp:75
void request_gradient(const GridField< DeviceOut, VT, PIT, TT, KT > &gradient_in)
Definition: get_potential_grad.hpp:307
void get_field_Ah_cv_ff(const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > &Ah_cv_h, const GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > &Ah_cv_ff)
Definition: get_potential_grad.cpp:7
void calculate_gradient(const Grid< DeviceType > &grid, const GradientMatrices< DeviceType > &grad_matrices)
Definition: get_potential_grad.hpp:142
GyroAverageMatrices< Device > gyro_avg_matrices
Definition: species.hpp:147
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > dpot_h
Definition: electric_field.hpp:132
int nnode
Number of grid nodes.
Definition: grid.hpp:168
GridField< DeviceType, VarType::Vector, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > EfieldGyroType
Definition: grid_field.hpp:488
double em_pullback_dampfac
Damping term gamma on -b.grad(phi) in pullback mode 4.
Definition: sml.hpp:74
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > dpot_n0_h
Definition: electric_field.hpp:134
bool n0_m_efield
Definition: electric_field.hpp:102
View< int *, CLayout, HostType > all_first_node
First node of each rank.
Definition: field_decomposition.hpp:41
bool em_control_variate
Switch for use of control variate method.
Definition: sml.hpp:67
int first_node
First mesh node belonging to this rank, including ghost nodes.
Definition: field_decomposition.hpp:32
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > E
Definition: electric_field.hpp:122
void set_field(const Grid< DeviceType > &grid, const FieldFollowingCoordinates &ff, View< Field< VarType::Vector2D, PIT > *, CLayout, DeviceOut > &field00_ff_h)
Definition: get_potential_grad.hpp:158
View< double ***, CLayout, HostType > dpotsave
Definition: electric_field.hpp:137
void calculate_phi_ff_on_device(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Smoothing &smoothing, GetPotentialGradTemp< DeviceType, DeviceType > &tmp, const View< Field< VarType::Scalar, PhiInterpType::None > *, CLayout, HostType > &dpot_h, const GT0 &pot0_h, GT &phi_ff, GT2 &pot_phi_ff, bool potential_is_requested=true, bool use_field00=false, bool ignore_poloidal_dpot=false)
Definition: plane_field_gatherer.hpp:117
Boundary cbd0
Definition: electric_field.hpp:156
ElectricField(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid, int nrho_in, bool es_reduced_deltaf_setup=false, double dt=1.0, double psi_norm=1.0)
Definition: electric_field.hpp:166
GridFieldPackPtr copy_push_fields_to_device_drift_kin_XGC1(const Simulation< DeviceType > &sml, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, Smoothing &smoothing, bool near_field=false) const
Definition: electric_field.hpp:275
Pack< Labeled< typename getGyroVecFldType< KT >::t, Label::E >, Labeled< typename getGyroVecFldType< KT >::t, Label::dAh >, Labeled< typename getGyroVecFldType< KT >::t, Label::dAs >, Labeled< typename getGyroScaFldType< KT >::t, Label::Ah >, Labeled< typename getGyroScaFldType< KT >::t, Label::As >, Labeled< typename getGyroScaFldType< KT >::t, Label::Epar_em >> t
Definition: electric_field.hpp:42
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10
Definition: get_potential_grad.hpp:46