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;
172 if(es_reduced_deltaf_setup){
175 dpotsave = View<double***,CLayout, HostType>(
"dpotsave", 2, 2,
nnode);
187 bool em_mixed_variable = nlr.
get<
bool>(
"sml_em_mixed_variable",
true);
188 bool em_control_variate = nlr.
get<
bool>(
"sml_em_control_variate",
false);
189 int em_pullback_mode = nlr.
get<
int>(
"sml_em_pullback_mode",3);
190 std::string em_pullback_str = nlr.
get<std::string>(
"sml_em_pullback_method",
"Electrostatic");
191 if(em_pullback_mode==4) em_pullback_str =
"IdealMHD";
194 if (!em_mixed_variable)
195 exit_XGC(
"\nError: sml_em_mixed_variable is explicitly set to .false. which is incompatible with EXPLICIT_EM\n");
198 dpot_es = View<double*,CLayout, HostType>(
"dpot_es",
nnode);
211 if (em_control_variate){
216 if (em_mixed_variable){
226 #ifndef NO_FORTRAN_MODULES
236 const double initial_loop_vol = nlr.
get<
double>(
"src_loop_voltage",0.0);
240 for (
int inode=0; inode<
nnode; inode++){
249 template<MarkerType MT, MagneticFieldMode MFM>
262 gfpack.phi_offset = pol_decomp.
field_decomp.all_first_plane(local_pid);
263 gfpack.node_offset = pol_decomp.
field_decomp.all_first_node(local_pid);
265 gfpack.phi_offset = pol_decomp.
field_decomp.first_plane;
266 gfpack.node_offset = pol_decomp.
field_decomp.first_node;
279 int n_input_field_planes =
pot0_h.nphi();
280 bool gradient_requested =
true;
281 bool gyroaverage_requested =
false;
283 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
288 bool potential_is_requested =
false;
290 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);
317 return std::make_unique<gfp_push_type>(gfpack);
320 template<MarkerType MT, MagneticFieldMode MFM>
325 GPTLstart(
"Copy_rho_ff_fields_to_device");
334 GPTLstop(
"Copy_rho_ff_fields_to_device");
345 return std::make_unique<gfp_push_type>(gfpack);
354 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
356 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
360 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
362 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electrostatic>(sml, pol_decomp,
magnetic_field, grid, near_field);
368 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
370 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::ReducedDeltaF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
374 return copy_push_fields_to_device_drift_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
376 return copy_push_fields_to_device_gyro_kin_XGC1<MarkerType::TotalF, MagneticFieldMode::Electromagnetic>(sml, pol_decomp,
magnetic_field, grid, near_field);
400 return std::make_unique<gfp_push_type>(gfpack);
418 int n_input_field_planes =
Ah_h.nphi();
419 bool gradient_requested =
false;
420 bool gyroaverage_requested =
true;
423 GPTLstop(
"GET_AH_RHO_FF_ALLOC_VIEWS");
429 FieldArgs gpg_field_args(
Ah_h.unmanaged());
430 gpg_field_args.request_potential(
Ah);
433 GPTLstop(
"GET_AH_RHO_FF_EXCL_DESTR");
453 int n_input_field_planes =
dpot_h.nphi();
454 bool gradient_requested =
true;
455 bool gyroaverage_requested =
true;
456 if(gyroaverage_requested) species.
gyro_avg_matrices.copy_to_device_if_not_resident();
458 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
471 gpg_field_args.field00.calculate_gradient(grid, tmp.
grad_matrices);
478 if(!sml.
is_XGCa) gpg_field_args.request_potential(
pot);
479 gpg_field_args.request_gradient(
E);
482 View<double**,CLayout, DeviceType> para_grad;
486 para_grad = View<double**,CLayout, DeviceType>(
NoInit(
"para_grad"), 2, grid.
nnode);
487 gpg_field_args.request_para_grad(para_grad);
508 gpg_field_args = FieldArgs(
Ah_h.unmanaged());
509 gpg_field_args.request_potential(
Ah);
510 gpg_field_args.request_gradient(
dAh);
517 gpg_field_args = FieldArgs(
As_h.unmanaged());
518 gpg_field_args.request_potential(
As);
519 gpg_field_args.request_gradient(
dAs);
527 TIMER(
"GET_POT_APAR_CV",
535 View<double*,CLayout,HostType> Er_B2_h(
"Er_B2_h",grid.
nnode);
536 View<double*,CLayout,HostType> Ez_B2_h(
"Ez_B2_h",grid.
nnode);
537 View<double*,CLayout,HostType> u2_E_h(
"u2_E_h",grid.
nnode);
539 TIMER(
"GET_POT_SONIC",
542 gpg_field_args = FieldArgs(Er_B2_h);
543 gpg_field_args.request_gradient(
dEr_B2);
546 gpg_field_args = FieldArgs(Ez_B2_h);
547 gpg_field_args.request_gradient(
dEz_B2);
550 gpg_field_args = FieldArgs(u2_E_h);
551 gpg_field_args.request_gradient(
du2_E);
559 GPTLstop(
"GET_POT_GRAD_EXCL_DESTR");
564 int field_n_rho = nlr.
get<
int>(
"sml_grid_nrho", 6);
567 int n_fields = 3 + 1;
571 double host_field_GB_per_vertex = (53 + 8*grid.
nplanes + 11*(field_n_rho + 1))*8*
BYTES_TO_GB;
572 double cpu_memory_usage = grid.
nnode*host_field_GB_per_vertex;
574 double device_field_GB_per_vertex = std::max(n_fields*8*grid.
nplanes, n_fields*8*(field_n_rho+1))*8*
BYTES_TO_GB;
575 double gpu_memory_usage = grid.
nnode*device_field_GB_per_vertex;
577 MemoryPrediction memory_prediction{
"Collisions", cpu_memory_usage, gpu_memory_usage};
579 return memory_prediction;
Definition: boundary.hpp:83
bool decompose_fields
Whether to decompose fields.
Definition: domain_decomposition.hpp:87
FieldDecomposition< Device > field_decomp
Definition: domain_decomposition.hpp:88
int plane_index
Offset of local plane.
Definition: domain_decomposition.hpp:84
int node_offset
Offset of first mesh node belonging to this MPI rank.
Definition: domain_decomposition.hpp:91
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
@ Optional
Definition: NamelistReader.hpp:287
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:37
bool grad_psitheta
Definition: sml.hpp:89
static constexpr bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:26
bool em_control_variate
Switch for use of control variate method.
Definition: sml.hpp:67
PullbackMethod em_pullback_method
Electrostatic: mixed-variable pullback with dA_s/dt=0,.
Definition: sml.hpp:68
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:18
bool electron_on
Use kinetic electrons.
Definition: sml.hpp:55
bool em_mixed_variable
Switch for use of mixed-variable formulation.
Definition: sml.hpp:66
Definition: species.hpp:75
GyroAverageMatrices< Device > gyro_avg_matrices
Definition: species.hpp:151
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)
void exit_XGC(std::string msg)
Definition: globals.hpp:37
PullbackMethod
Definition: globals.hpp:198
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:250
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:448
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
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)
Definition: electric_field.hpp:144
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:383
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:413
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:321
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:562
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