1 #ifndef ELECTRIC_FIELD_HPP
2 #define ELECTRIC_FIELD_HPP
19 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
21 ,
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::Planes>* As_rho_ff,
Field<VarType::Vector,PhiInterpType::Planes>* dAs_rho_ff,
Field<VarType::Scalar,PhiInterpType::Planes>* E_para_em_rho_ff
35 template<
class Device>
111 dpot_ff_h(
"dpot_ff_h",
nnode),
129 bool em_mixed_variable = nlr.
get<
bool>(
"sml_em_mixed_variable",
true);
130 bool em_control_variate = nlr.
get<
bool>(
"sml_em_control_variate",
false);
131 int em_pullback_mode = nlr.
get<
int>(
"sml_em_pullback_mode",3);
133 if (!em_mixed_variable)
134 exit_XGC(
"\nError: sml_em_mixed_variable is explicitly set to .false. which is incompatible with EXPLICIT_EM\n");
145 if (em_control_variate){
149 if (em_mixed_variable){
152 if (em_pullback_mode==4){
186 void copy_to_pack(T& device_grid_field,
const T& host_grid_field)
const{
187 device_grid_field = host_grid_field;
191 template<
typename T1,
typename T2>
192 void copy_to_pack(T1& device_grid_field,
const T2& host_grid_field)
const{
194 device_grid_field = T1(
"grid_field",host_grid_field.nphi(), host_grid_field.nrhop1()-1, host_grid_field.nnode());
196 Kokkos::deep_copy(device_grid_field.f, host_grid_field.f);
200 template<PhiInterpType PIT>
231 bool potential_is_requested =
false;
233 pfg.
calculate_phi_ff_on_device(sml,grid, magnetic_field,
my_subview(
dpot_h.f, 2),
pot0_h, gfpack.E_phi_ff, unused_pot, potential_is_requested, use_field00, ignore_poloidal_dpot);
253 GPTLstart(
"Copy_rho_ff_fields_to_device");
262 GPTLstop(
"Copy_rho_ff_fields_to_device");
277 template<PhiInterpType PIT>
287 template<PhiInterpType PIT>
303 template<PhiInterpType PIT>
309 const int PLANE_ZERO=0;
330 int n_input_field_planes =
dpot_h.nphi();
331 bool gyroaverage_requested =
true;
333 GPTLstop(
"GET_POT_GRAD_ALLOC_VIEWS");
356 if(!sml.
is_XGCa) gpg_field_args.request_potential(
pot);
357 gpg_field_args.request_gradient(
E);
360 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
372 gpg_field_args.request_potential(
Ah);
373 gpg_field_args.request_gradient(
dAh);
374 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
382 gpg_field_args.request_potential(
As);
383 gpg_field_args.request_gradient(
dAs);
384 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
391 TIMER(
"GET_POT_APAR_CV",
399 View<double*,CLayout,HostType> Er_B2_h(
"Er_B2_h",grid.
nnode);
400 View<double*,CLayout,HostType> Ez_B2_h(
"Ez_B2_h",grid.
nnode);
401 View<double*,CLayout,HostType> u2_E_h(
"u2_E_h",grid.
nnode);
403 TIMER(
"GET_POT_SONIC",
407 gpg_field_args.request_gradient(dEr_B2);
408 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
411 gpg_field_args.request_gradient(dEz_B2);
412 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
415 gpg_field_args.request_gradient(du2_E);
416 get_field_grad(grid, pol_decomp, magnetic_field, gpg_field_args, tmp);
421 GPTLstop(
"GET_POT_GRAD_EXCL_DESTR");
bool decompose_fields
Whether to decompose fields.
Definition: domain_decomposition.hpp:35
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > pot
Definition: electric_field.hpp:69
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
int first_plane
First plane belonging to this rank, including ghost planes.
Definition: field_decomposition.hpp:35
void copy_to_pack(T1 &device_grid_field, const T2 &host_grid_field) const
Definition: electric_field.hpp:192
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:325
const bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:29
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAh
Definition: electric_field.hpp:59
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:372
Definition: field.hpp:244
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > Ah
Definition: electric_field.hpp:60
Definition: field.hpp:139
bool em_mixed_variable
Switch for use of mixed-variable formulation.
Definition: sml.hpp:68
GridField< HostType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > E00_ff_h
Radial electric field from <phi> in field-following format.
Definition: electric_field.hpp:54
double inv_drho
Definition: electric_field.hpp:44
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > As_h
Definition: electric_field.hpp:61
int plane_index
Offset of local plane.
Definition: domain_decomposition.hpp:33
Definition: globals.hpp:82
Definition: plane_field_gatherer.hpp:9
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:76
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:43
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:88
Definition: magnetic_field.hpp:12
Definition: get_potential_grad.hpp:248
int phi_offset
Offset for phi_ff field decomposition.
Definition: grid_field_pack.hpp:29
Definition: electric_field.hpp:36
GridField< Device, vec2d_if_axisym< PIT >), PIT, TorType::OnePlane, KinType::GyroKin > E_rho
Definition: grid_field_pack.hpp:58
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > pot0_h
Definition: electric_field.hpp:81
int nplanes
Number of planes.
Definition: grid.hpp:217
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:288
Definition: grid_field_pack.hpp:20
int node_offset
Offset of first mesh node belonging to this MPI rank.
Definition: domain_decomposition.hpp:39
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:75
void calculate_phi_ff_on_device(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, 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 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:428
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > Epar_em
Definition: electric_field.hpp:65
int em_pullback_mode
Definition: sml.hpp:70
bool grad_psitheta
Definition: sml.hpp:84
void get_field_Ah_cv_ff(Field< VarType::Scalar, PIT_GLOBAL > *psn_Ah_cv_ff)
ElectricField()
Definition: electric_field.hpp:84
#define TIMER(N, F)
Definition: timer_macro.hpp:24
void copy_to_pack(T &device_grid_field, const T &host_grid_field) const
Definition: electric_field.hpp:186
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > ddpotdt
Time derivative of phi-<phi> - Not field-following?
Definition: electric_field.hpp:55
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:354
void set_rho_pointers(int nrho, int n, Field< VarType::Scalar, PhiInterpType::None > *pot0, Field< VarType::Scalar, PhiInterpType::None > *dpot, Field< VarType::Vector2D, PhiInterpType::None > *E_rho)
constexpr PhiInterpType PIT_GLOBAL
Definition: globals.hpp:98
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > Ah_cv
Definition: electric_field.hpp:64
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:203
Definition: globals.hpp:83
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:201
GridField< HostType, vec2d_if_axisym< PIT_GLOBAL >), PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > dAs
Definition: electric_field.hpp:62
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Ah_h
Definition: electric_field.hpp:58
bool E00_efield
Flux-surface averaged potential not used for calculating the electric field if .false.
Definition: electric_field.hpp:51
int node_offset
Offset for phi_ff field decomposition.
Definition: grid_field_pack.hpp:30
KinType
Definition: globals.hpp:81
GridField< Device, VarType::Scalar, PIT, TorType::OnePlane, KinType::DriftKin > dpot
Definition: grid_field_pack.hpp:59
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:350
bool electron_on
Use kinetic electrons.
Definition: sml.hpp:54
const bool reduced_deltaf
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:23
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:47
void exit_XGC(std::string msg)
Definition: globals.hpp:36
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:50
int nphi
Definition: electric_field.hpp:40
const bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:15
GridField< HostType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > As
Definition: electric_field.hpp:63
int nnode
Definition: electric_field.hpp:39
FieldDecomposition< Device > field_decomp
Definition: domain_decomposition.hpp:36
GyroAverageMatrices< HostType > gyro_avg_matrices
Definition: species.hpp:126
Definition: species.hpp:72
GridFieldPack< Device, PIT > copy_dpot_to_device(KinType kintype_in) const
Definition: electric_field.hpp:304
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:278
void calculate_gradient(const Grid< DeviceType > &grid, const GradientMatrices< DeviceType > &grad_matrices)
Definition: get_potential_grad.hpp:143
GridField< HostType, VarType::Scalar, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > dpot_h
Definition: electric_field.hpp:80
int nnode
Number of grid nodes.
Definition: grid.hpp:216
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:69
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:70
Definition: field.hpp:207
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10
Definition: get_potential_grad.hpp:54