1 #ifndef ELECTRIC_FIELD_HPP
2 #define ELECTRIC_FIELD_HPP
20 extern "C" void set_rho_ff_pointers(
int nrho,
int n,
Field<VarType::Scalar,PhiInterpType::None>* pot0,
Field<VarType::Scalar,PhiInterpType::None>* dpot,
Field<VarType::Scalar,PhiInterpType::Planes>* dpot_ff,
Field<VarType::Scalar,PhiInterpType::Planes>* pot_rho_ff,
Field<VarType::Vector,PhiInterpType::Planes>* E_rho_ff
22 ,
Field<VarType::Scalar,PhiInterpType::None>* Ah,
Field<VarType::Scalar,PhiInterpType::Planes>* Ah_rho_ff,
Field<VarType::Vector,PhiInterpType::Planes>* dAh_rho_ff,
Field<VarType::Scalar,PhiInterpType::None>* As,
Field<VarType::Scalar,PhiInterpType::None>* As_backup,
Field<VarType::Scalar,PhiInterpType::Planes>* As_rho_ff,
Field<VarType::Vector,PhiInterpType::Planes>* dAs_rho_ff,
Field<VarType::Scalar,PhiInterpType::Planes>* E_para_em_rho_ff
36 template<
class Device>
108 # if defined(DELTAF_CONV) && !defined(EXPLICIT_EM)
142 bool em_mixed_variable = nlr.
get<
bool>(
"sml_em_mixed_variable",
true);
143 bool em_control_variate = nlr.
get<
bool>(
"sml_em_control_variate",
false);
144 int em_pullback_mode = nlr.
get<
int>(
"sml_em_pullback_mode",3);
146 if (!em_mixed_variable)
147 exit_XGC(
"\nError: sml_em_mixed_variable is explicitly set to .false. which is incompatible with EXPLICIT_EM\n");
158 if (em_control_variate){
162 if (em_mixed_variable){
165 if (em_pullback_mode==4){
189 const double initial_loop_vol = nlr.
get<
double>(
"sml_loop_voltage",0.0);
191 for (
int inode=0; inode<
nnode; inode++){
202 template<PhiInterpType PIT>
230 # if defined(DELTAF_CONV) && !defined(EXPLICIT_EM)
238 int n_input_field_planes =
pot0_h.nphi();
239 bool gradient_requested =
true;
240 bool gyroaverage_requested =
false;
242 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
247 bool potential_is_requested =
false;
249 pfg.
calculate_phi_ff_on_device(sml,grid, magnetic_field, gpg_tmp,
my_subview(
dpot_h.f, 2),
pot0_h, gfpack.
E_phi_ff, unused_pot, potential_is_requested, use_field00, ignore_poloidal_dpot);
269 GPTLstart(
"Copy_rho_ff_fields_to_device");
278 GPTLstop(
"Copy_rho_ff_fields_to_device");
302 template<PhiInterpType PIT>
312 template<PhiInterpType PIT>
328 template<PhiInterpType PIT>
334 const int PLANE_ZERO=0;
354 int n_input_field_planes =
Ah_h.nphi();
355 bool gradient_requested =
false;
356 bool gyroaverage_requested =
true;
358 GPTLstop(
"GET_AH_RHO_FF_ALLOC_VIEWS");
364 FieldArgs gpg_field_args(
Ah_h.unmanaged());
365 gpg_field_args.request_potential(
Ah);
366 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
368 GPTLstop(
"GET_AH_RHO_FF_EXCL_DESTR");
386 int n_input_field_planes =
dpot_h.nphi();
387 bool gradient_requested =
true;
388 bool gyroaverage_requested =
true;
390 gyroaverage_requested =
false;
394 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
421 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
431 gpg_field_args = FieldArgs(
Ah_h.unmanaged());
436 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
442 gpg_field_args = FieldArgs(
As_h.unmanaged());
447 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
454 TIMER(
"GET_POT_APAR_CV",
462 View<double*,CLayout,HostType> Er_B2_h(
"Er_B2_h",grid.
nnode);
463 View<double*,CLayout,HostType> Ez_B2_h(
"Ez_B2_h",grid.
nnode);
464 View<double*,CLayout,HostType> u2_E_h(
"u2_E_h",grid.
nnode);
466 TIMER(
"GET_POT_SONIC",
469 gpg_field_args = FieldArgs(Er_B2_h);
471 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
473 gpg_field_args = FieldArgs(Ez_B2_h);
475 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
477 gpg_field_args = FieldArgs(u2_E_h);
479 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
484 GPTLstop(
"GET_POT_GRAD_EXCL_DESTR");
489 int field_n_rho = nlr.
get<
int>(
"sml_grid_nrho", 6);
492 int n_fields = 3 + 1;
496 double host_field_GB_per_vertex = (53 + 8*grid.
nplanes + 11*(field_n_rho + 1))*8*
BYTES_TO_GB;
497 double cpu_memory_usage = grid.
nnode*host_field_GB_per_vertex;
499 double device_field_GB_per_vertex = std::max(n_fields*8*grid.
nplanes, n_fields*8*(field_n_rho+1))*8*
BYTES_TO_GB;
500 double gpu_memory_usage = grid.
nnode*device_field_GB_per_vertex;
502 MemoryPrediction memory_prediction{
"Collisions", cpu_memory_usage, gpu_memory_usage};
504 return memory_prediction;
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > ddpotdt
Time derivative of - Not field-following?
Definition: electric_field.hpp:56
bool decompose_fields
Whether to decompose fields.
Definition: domain_decomposition.hpp:45
void get_Ah_rho_ff(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, const Species< DeviceType > &species)
Definition: electric_field.hpp:349
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > pot
Definition: electric_field.hpp:71
Definition: field_following_coordinates.hpp:9
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > jpara_diff_integral_h
Definition: electric_field.hpp:89
GridField< Device, VarType::Scalar, PIT, TorType::OnePlane, KinType::DriftKin > loop_voltage
Definition: grid_field_pack.hpp:68
int first_plane
First plane belonging to this rank, including ghost planes.
Definition: field_decomposition.hpp:35
void get_potential_grad(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, const Species< DeviceType > &species)
Definition: electric_field.hpp:381
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAh
Definition: electric_field.hpp:60
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
Definition: field.hpp:281
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:87
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > Ah
Definition: electric_field.hpp:61
Definition: field.hpp:145
bool em_mixed_variable
Switch for use of mixed-variable formulation.
Definition: sml.hpp:76
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:55
double inv_drho
Definition: electric_field.hpp:45
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:19
static constexpr bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:37
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > As_h
Definition: electric_field.hpp:62
int plane_index
Offset of local plane.
Definition: domain_decomposition.hpp:42
Definition: globals.hpp:89
Definition: plane_field_gatherer.hpp:9
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:72
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:44
Definition: NamelistReader.hpp:193
ElectricField(NLReader::NamelistReader &nlr, int nnode_in, int nplanes_in, int nrho_in, double inv_drho_in)
Definition: electric_field.hpp:96
Definition: magnetic_field.hpp:12
static MemoryPrediction estimate_memory_usage(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid)
Definition: electric_field.hpp:487
Definition: get_potential_grad.hpp:259
int phi_offset
Offset for phi_ff field decomposition.
Definition: grid_field_pack.hpp:29
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:121
Definition: electric_field.hpp:37
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > pot0_h
Definition: electric_field.hpp:83
int nplanes
Number of planes.
Definition: grid.hpp:272
GridFieldPack< Device, PIT > copy_Ah_ff_to_device(KinType kintype_in, const DomainDecomposition< DeviceType > &pol_decomp, const Grid< DeviceType > &grid) const
Definition: electric_field.hpp:313
static constexpr bool reduced_deltaf
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:25
Definition: grid_field_pack.hpp:20
int node_offset
Offset of first mesh node belonging to this MPI rank.
Definition: domain_decomposition.hpp:49
GridField< Device, vec2d_if_axisym< PIT >), PIT, TorType::MultiplePlanes, KinType::DriftKin > E_phi_ff
Definition: grid_field_pack.hpp:37
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:71
Projection< HostType > half_plane_ff
Definition: grid.hpp:316
void get_field_grad(const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, const MagneticField< DeviceType > &magnetic_field, GetPotGradFieldArgs< DeviceIn, DeviceOut, VT, PIT, TT, KT > &args, GetPotentialGradTemp< DeviceType, DeviceOut > &tmp)
Definition: get_potential_grad.cpp:454
int em_pullback_mode
Definition: sml.hpp:78
bool grad_psitheta
Definition: sml.hpp:97
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > Ah_cv
Definition: electric_field.hpp:66
ElectricField()
Definition: electric_field.hpp:92
#define TIMER(N, F)
Definition: timer_macro.hpp:24
void calculate_phi_ff_on_device(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, 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 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:63
Definition: memory_prediction.hpp:4
void grid_field_copy(T &dest, const T &src)
Definition: grid_field.hpp:452
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dEz_B2
Gradient of Ez/B^2.
Definition: electric_field.hpp:78
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:266
Definition: globals.hpp:90
GridFieldPack< Device, PIT > copy_push_fields_to_device(KinType kintype_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:203
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAs
Definition: electric_field.hpp:64
void request_potential(const GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > &potential_in)
Definition: get_potential_grad.hpp:285
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Ah_h
Definition: electric_field.hpp:59
GridField< Device, vec2d_if_axisym< PIT >), PIT, TorType::OnePlane, KinType::GyroKin > E_rho_ff
Definition: grid_field_pack.hpp:38
bool E00_efield
Flux-surface averaged potential not used for calculating the electric field if .false.
Definition: electric_field.hpp:52
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dEr_B2
Gradient of Er/B^2.
Definition: electric_field.hpp:77
int node_offset
Offset for phi_ff field decomposition.
Definition: grid_field_pack.hpp:30
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:79
KinType
Definition: globals.hpp:88
void get_field_Ah_cv_ff(const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::DriftKin > &Ah_cv_ff)
Definition: get_potential_grad.cpp:10
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > jpara_diff_previous_h
Definition: electric_field.hpp:88
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:64
GridField< HostType, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > Epar_em
Definition: electric_field.hpp:67
GridField< Device, VarType::Scalar, PIT, TorType::OnePlane, KinType::DriftKin > dpot_ff
Definition: grid_field_pack.hpp:39
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:48
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
Definition: magnetic_field.F90:1
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:51
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > dpot_ff_h
Definition: electric_field.hpp:74
int nphi
Definition: electric_field.hpp:41
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > As
Definition: electric_field.hpp:65
int nnode
Definition: electric_field.hpp:40
FieldDecomposition< Device > field_decomp
Definition: domain_decomposition.hpp:46
GyroAverageMatrices< HostType > gyro_avg_matrices
Definition: species.hpp:129
Definition: species.hpp:75
void request_gradient(const GridField< DeviceOut, VT, PIT, TT, KT > &gradient_in)
Definition: get_potential_grad.hpp:290
GridFieldPack< Device, PIT > copy_dpot_to_device(KinType kintype_in) const
Definition: electric_field.hpp:329
void request_para_em(const GridField< DeviceOut, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > &output_field, bool gyroaverage_requested)
Definition: get_potential_grad.hpp:295
GridFieldPack< Device, PIT > copy_Ah_cv_to_device_as_Ah(KinType kintype_in, const DomainDecomposition< DeviceType > &pol_decomp, const Grid< DeviceType > &grid) const
Definition: electric_field.hpp:303
void calculate_gradient(const Grid< DeviceType > &grid, const GradientMatrices< DeviceType > &grad_matrices)
Definition: get_potential_grad.hpp:150
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > dpot_h
Definition: electric_field.hpp:82
int nnode
Number of grid nodes.
Definition: grid.hpp:271
View< int *, CLayout, HostType > all_first_node
First node of each rank.
Definition: field_decomposition.hpp:41
void set_rho_ff_pointers(int nrho, int n, Field< VarType::Scalar, PhiInterpType::None > *pot0, Field< VarType::Scalar, PhiInterpType::None > *dpot, Field< VarType::Scalar, PhiInterpType::Planes > *dpot_ff, Field< VarType::Scalar, PhiInterpType::Planes > *pot_rho_ff, Field< VarType::Vector, PhiInterpType::Planes > *E_rho_ff)
bool em_control_variate
Switch for use of control variate method.
Definition: sml.hpp:77
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:72
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:166
View< double ***, CLayout, HostType > dpotsave
Definition: electric_field.hpp:84
Definition: field.hpp:216
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10
Definition: get_potential_grad.hpp:50