1 #ifndef ELECTRIC_FIELD_HPP
2 #define ELECTRIC_FIELD_HPP
18 template<KinType KT, PhiInterpType PIT, MarkerType MT, MagneticFieldMode MFM>
32 template<KinType KT, MarkerType MT>
34 using t = Pack<Labeled<typename getGyroVecFldType<KT>::t,
Label::E>,
43 template<KinType KT, MarkerType MT>
45 using t = Pack<Labeled<typename getGyroVecFldType<KT>::t,
Label::E>>;
51 using t = Pack<Labeled<typename getGyroVecFldType<KT>::t,
Label::E>,
57 template<KinType KT, MarkerType MT>
60 using t = Pack<Labeled<Efield2DGyroType, Label::E>,
65 using t = Pack<Labeled<Efield2DGyroType, Label::E>>;
75 template<
class Device>
129 View<double*,CLayout, HostType>
pot0m;
152 template<MarkerType MT, MagneticFieldMode MFM>
165 gfpack.phi_offset = pol_decomp.
field_decomp.all_first_plane(local_pid);
166 gfpack.node_offset = pol_decomp.
field_decomp.all_first_node(local_pid);
168 gfpack.phi_offset = pol_decomp.
field_decomp.first_plane;
169 gfpack.node_offset = pol_decomp.
field_decomp.first_node;
182 int n_input_field_planes =
pot0_h.nphi();
183 bool gradient_requested =
true;
184 bool gyroaverage_requested =
false;
186 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
191 bool potential_is_requested =
false;
193 pfg.
calculate_phi_ff_on_device(sml,grid, 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);
220 return std::make_unique<gfp_push_type>(gfpack);
223 template<MarkerType MT, MagneticFieldMode MFM>
228 GPTLstart(
"Copy_rho_ff_fields_to_device");
237 GPTLstop(
"Copy_rho_ff_fields_to_device");
248 return std::make_unique<gfp_push_type>(gfpack);
257 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
259 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
263 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
265 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
271 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
273 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
277 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
279 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
303 return std::make_unique<gfp_push_type>(gfpack);
321 int n_input_field_planes =
Ah_h.nphi();
322 bool gradient_requested =
false;
323 bool gyroaverage_requested =
true;
326 GPTLstop(
"GET_AH_RHO_FF_ALLOC_VIEWS");
332 FieldArgs gpg_field_args(
Ah_h.unmanaged());
333 gpg_field_args.request_potential(
Ah);
336 GPTLstop(
"GET_AH_RHO_FF_EXCL_DESTR");
356 int n_input_field_planes =
dpot_h.nphi();
357 bool gradient_requested =
true;
358 bool gyroaverage_requested =
true;
359 if(gyroaverage_requested) species.
gyro_avg_matrices.copy_to_device_if_not_resident();
361 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
374 gpg_field_args.field00.calculate_gradient(grid, tmp.
grad_matrices);
381 if(!sml.
is_XGCa) gpg_field_args.request_potential(
pot);
382 gpg_field_args.request_gradient(
E);
385 View<double**,CLayout, DeviceType> para_grad;
389 para_grad = View<double**,CLayout, DeviceType>(
NoInit(
"para_grad"), 2, grid.
nnode);
390 gpg_field_args.request_para_grad(para_grad);
411 gpg_field_args = FieldArgs(
Ah_h.unmanaged());
412 gpg_field_args.request_potential(
Ah);
413 gpg_field_args.request_gradient(
dAh);
420 gpg_field_args = FieldArgs(
As_h.unmanaged());
421 gpg_field_args.request_potential(
As);
422 gpg_field_args.request_gradient(
dAs);
430 TIMER(
"GET_POT_APAR_CV",
438 View<double*,CLayout,HostType> Er_B2_h(
"Er_B2_h",grid.
nnode);
439 View<double*,CLayout,HostType> Ez_B2_h(
"Ez_B2_h",grid.
nnode);
440 View<double*,CLayout,HostType> u2_E_h(
"u2_E_h",grid.
nnode);
442 TIMER(
"GET_POT_SONIC",
445 gpg_field_args = FieldArgs(Er_B2_h);
446 gpg_field_args.request_gradient(
dEr_B2);
449 gpg_field_args = FieldArgs(Ez_B2_h);
450 gpg_field_args.request_gradient(
dEz_B2);
453 gpg_field_args = FieldArgs(u2_E_h);
454 gpg_field_args.request_gradient(
du2_E);
462 GPTLstop(
"GET_POT_GRAD_EXCL_DESTR");
467 int field_n_rho = nlr.
get<
int>(
"sml_grid_nrho", 6);
470 int n_fields = 3 + 1;
474 double host_field_GB_per_vertex = (53 + 8*grid.
nplanes + 11*(field_n_rho + 1))*8*
BYTES_TO_GB;
475 double cpu_memory_usage = grid.
nnode*host_field_GB_per_vertex;
477 double device_field_GB_per_vertex = std::max(n_fields*8*grid.
nplanes, n_fields*8*(field_n_rho+1))*8*
BYTES_TO_GB;
478 double gpu_memory_usage = grid.
nnode*device_field_GB_per_vertex;
480 MemoryPrediction memory_prediction{
"Collisions", cpu_memory_usage, gpu_memory_usage};
482 return memory_prediction;
Definition: boundary.hpp:83
bool decompose_fields
Whether to decompose fields.
Definition: domain_decomposition.hpp:91
FieldDecomposition< Device > field_decomp
Definition: domain_decomposition.hpp:92
int plane_index
Offset of local plane.
Definition: domain_decomposition.hpp:88
int node_offset
Offset of first mesh node belonging to this MPI rank.
Definition: domain_decomposition.hpp:95
Definition: field_following_coordinates.hpp:9
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
Projection< HostType > half_plane_ff
Definition: grid.hpp:194
int nplanes
Number of planes.
Definition: grid.hpp:175
int nnode
Number of grid nodes.
Definition: grid.hpp:174
Definition: magnetic_field.hpp:12
Definition: NamelistReader.hpp:193
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:386
void use_namelist(const string &namelist, Options required=Required)
Definition: NamelistReader.hpp:360
Definition: perturbed_B_field.hpp:12
Definition: plane_field_gatherer.hpp:9
void calculate_phi_ff_on_device(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, 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
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
bool reduced_deltaf
True if any species is reduced_deltaf. Will be removed.
Definition: sml.hpp:41
bool grad_psitheta
Definition: sml.hpp:91
static constexpr bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:30
bool em_control_variate
Switch for use of control variate method.
Definition: sml.hpp:69
PullbackMethod em_pullback_method
Electrostatic: mixed-variable pullback with dA_s/dt=0,.
Definition: sml.hpp:70
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:22
bool electron_on
Use kinetic electrons.
Definition: sml.hpp:57
bool em_mixed_variable
Switch for use of mixed-variable formulation.
Definition: sml.hpp:68
Definition: species.hpp:75
GyroAverageMatrices< Device > gyro_avg_matrices
Definition: species.hpp:151
Definition: xgc_io.hpp:24
constexpr double BYTES_TO_GB
Definition: constants.hpp:13
void set_rho_pointers(int n, Field< VarType::Scalar, PhiInterpType::None > *dpot)
void set_rho_ff_pointers(int n, Field< VarType::Scalar, PhiInterpType::None > *dpot, Field< VarType::Scalar, PhiInterpType::Planes > *dpot_ff)
void get_dAdt_guess(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, Smoothing &smoothing, const PerturbedBField< DeviceType > &perturbed_B_field, GetPotentialGradTemp< DeviceType, HostType > &tmp, const View< double **, CLayout, DeviceType > &field_para, const Boundary &filter_bndry, const GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > &dAdt_guess)
Definition: get_dAdt_guess.cpp:77
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:6
void get_field_grad(const Grid< DeviceType > &grid, GetPotGradFieldArgs< DeviceIn, DeviceOut, VT, PIT, TT, KT > &args, GetPotentialGradTemp< DeviceType, DeviceOut > &tmp)
Definition: get_potential_grad.cpp:389
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)
constexpr PhiInterpType PIT_GLOBAL
Definition: globals.hpp:105
KinType
Definition: globals.hpp:88
@ GyroKin
Definition: globals.hpp:90
@ DriftKin
Definition: globals.hpp:89
MarkerType
Definition: globals.hpp:110
PhiInterpType
Definition: globals.hpp:95
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > PotGyroType
Definition: grid_field.hpp:490
GridField< DeviceType, VarType::Vector, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > EfieldGyroType
Definition: grid_field.hpp:488
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::MultiplePlanes, KinType::DriftKin > PotType
Definition: grid_field.hpp:486
void grid_field_copy(T &dest, const T &src)
Definition: grid_field.hpp:496
GridField< DeviceType, VarType::Vector, PhiInterpType::Planes, TorType::MultiplePlanes, KinType::DriftKin > EfieldType
Definition: grid_field.hpp:484
std::unique_ptr< GridFieldPackGeneric > GridFieldPackPtr
Definition: grid_field_pack.hpp:21
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
Definition: magnetic_field.F90:1
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:69
Definition: electric_field.hpp:76
View< double ***, CLayout, HostType > save_dpot
Definition: electric_field.hpp:125
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAh
Definition: electric_field.hpp:100
View< double ***, CLayout, HostType > dpotsave
Definition: electric_field.hpp:126
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > dAdt_guess
Definition: electric_field.hpp:108
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, bool near_field=false) const
Definition: electric_field.hpp:153
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > dpot_h
Definition: electric_field.hpp:121
View< double *, CLayout, HostType > pot0m
n=0 component of the electrostatic potential before smoothing
Definition: electric_field.hpp:129
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 PerturbedBField< DeviceType > &perturbed_B_field, Species< DeviceType > &species)
Definition: electric_field.hpp:351
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:94
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAs
Definition: electric_field.hpp:104
Boundary AbdH
Definition: electric_field.hpp:136
void write_checkpoint_files(const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, bool loop_voltage_on, bool use_split_weight_scheme, bool em, const XGC_IO_Stream &stream)
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dEr_B2
Gradient of Er/B^2.
Definition: electric_field.hpp:116
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > Ah
Definition: electric_field.hpp:101
View< double *, CLayout, HostType > dpot_es
Definition: electric_field.hpp:127
int nnode
Definition: electric_field.hpp:79
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > As_h_backup
Definition: electric_field.hpp:103
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > As
Definition: electric_field.hpp:105
View< double *, CLayout, HostType > pot00_1d
1D flux-surface averaged potential
Definition: electric_field.hpp:130
ElectricField(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid, int nrho_in, bool es_reduced_deltaf_setup=false)
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > dpot_n0_h
Definition: electric_field.hpp:123
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, bool near_field=false) const
Definition: electric_field.hpp:286
void read_checkpoint_files(const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, bool loop_voltage_on, bool use_split_weight_scheme, bool em, const XGC_IO_Stream &stream, const XGC_IO_Stream &em_stream)
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:89
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > As_h
Definition: electric_field.hpp:102
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:118
bool E00_efield
Flux-surface averaged potential not used for calculating the electric field if .false.
Definition: electric_field.hpp:90
Boundary pbd0
Definition: electric_field.hpp:137
int nrho
Definition: electric_field.hpp:83
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dEz_B2
Gradient of Ez/B^2.
Definition: electric_field.hpp:117
void get_Ah_rho_ff(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, Species< DeviceType > &species)
Definition: electric_field.hpp:316
ElectricField()
Definition: electric_field.hpp:140
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Ah_h
Definition: electric_field.hpp:98
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > pot
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:95
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > E
Definition: electric_field.hpp:111
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Ah_cv_h
Definition: electric_field.hpp:106
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > Ah_cv
Definition: electric_field.hpp:107
bool calculate_phi_ff_on_device
Definition: electric_field.hpp:86
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > Ah_h_backup
Definition: electric_field.hpp:99
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > dpot_ff_h
Definition: electric_field.hpp:113
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > pot0_h
Definition: electric_field.hpp:122
View< double ***, CLayout, HostType > save_dpot0
Definition: electric_field.hpp:124
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, bool near_field=false) const
Definition: electric_field.hpp:224
bool n0_m_efield
Definition: electric_field.hpp:91
int nphi
Definition: electric_field.hpp:80
static MemoryPrediction estimate_memory_usage(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid)
Definition: electric_field.hpp:465
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > loop_voltage_h
Definition: electric_field.hpp:133
Definition: field.hpp:321
Definition: field.hpp:150
Definition: get_potential_grad.hpp:205
Definition: get_potential_grad.hpp:44
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:66
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:65
Definition: grid_field_pack.hpp:24
Definition: grid_field.hpp:22
Definition: memory_prediction.hpp:4
Definition: smoothing.hpp:10
Definition: electric_field.hpp:25
Definition: electric_field.hpp:21
Pack< Labeled< Efield2DGyroType, Label::E > > t
Definition: electric_field.hpp:65
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::dAdt_guess > > t
Definition: electric_field.hpp:39
Pack< Labeled< typename getGyroVecFldType< KT >::t, Label::E > > t
Definition: electric_field.hpp:45
Pack< Labeled< typename getGyroVecFldType< KT >::t, Label::E >, Labeled< E00Type, Label::E00 >, Labeled< PotType, Label::ddpotdt > > t
Definition: electric_field.hpp:53
Definition: electric_field.hpp:19
#define TIMER(N, F)
Definition: timer_macro.hpp:24
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10