1 #ifndef GET_POTENTIAL_GRAD
2 #define GET_POTENTIAL_GRAD
30 template<
class Device>
32 View<double**,CLayout,Device>
field;
41 View<double*,CLayout, Device>
left(
int i_plane){
42 int i_left_alt = i_plane%2;
46 View<double*,CLayout, Device>
right(
int i_plane){
47 int i_right_alt = (i_plane+1)%2;
52 template<
class Device,
class DeviceOut>
80 nrho(gyroavg_requested ? gyro_avg_matrices_in.
nrho : 0),
93 if(!std::is_same<DeviceOut,Device>()){
99 if(gradient_requested){
100 #ifdef NO_FORTRAN_MODULES
101 grad_matrices = grid.gradient_matrices_h.template mirror<DeviceType>();
115 if(gradient_requested && !sml.
is_XGCa){
116 #ifdef NO_FORTRAN_MODULES
122 GPTLstop(
"GET_POT_GRAD_GPTX_SETUP");
126 template<
class Device>
132 View<double*,CLayout, Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
pot;
133 View<double*,CLayout, Device>
r;
134 View<double*,CLayout, Device>
z;
140 template<
class DeviceIn>
142 :
r(
NoInit(
"r"), field_in.f.extent(0)),
143 z(
NoInit(
"z"), field_in.f.extent(0)),
150 pot = View<double*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>((
double*)(
pot_managed.data()),
pot_managed.layout());
168 template<
class DeviceOut, PhiInterpType PIT>
173 View<double**,CLayout, Device> r_tmp(
NoInit(
"r_tmp"), nphi,
r.size());
174 View<double**,CLayout, Device> z_tmp(
NoInit(
"z_tmp"), nphi,
z.size());
176 for(
int iphi=0; iphi<nphi; iphi++){
187 for(
int iphi=0; iphi<nphi; iphi++){
188 Kokkos::parallel_for(
"set_field", Kokkos::RangePolicy<ExSpace>(0,field00_ff_h.extent(0)), KOKKOS_LAMBDA(
const int i ){
190 field00_ff(i).V[iphi][0]=r_tmp(iphi,i);
191 field00_ff(i).V[iphi][1]=z_tmp(iphi,i);
193 field00_ff(i).E[0]=r_tmp(iphi,i);
194 field00_ff(i).E[1]=z_tmp(iphi,i);
202 Kokkos::parallel_for(
"set_field", Kokkos::RangePolicy<typename DeviceOut::execution_space>(0,field00_ff_h.extent(0)), KOKKOS_LAMBDA(
const int i ){
204 field00_ff_h(i).V[0][0]=0.0;
205 field00_ff_h(i).V[0][1]=0.0;
206 field00_ff_h(i).V[1][0]=0.0;
207 field00_ff_h(i).V[1][1]=0.0;
209 field00_ff_h(i).E[0]=0.0;
210 field00_ff_h(i).E[1]=0.0;
217 template<
class Device,
class DeviceOut>
221 View<double**,CLayout, Device>
field;
236 int nrhop1 = gyroaverage_requested ?
field_out.f.extent(1) : 1;
238 if(!gyroaverage_requested)
exit_XGC(
"\nError: EMParField gyroaverage_requested=false is only supported for multirate at the moment.\n");
252 View<double**,CLayout, HostType> tmp_copy(
NoInit(
"tmp"),2,grid.
nnode);
253 Kokkos::deep_copy(tmp_copy, field_para);
262 for(
int iphi=0; iphi<2; iphi++){
263 bool filt_on =
false;
264 em_field_filter(sml, magnetic_field, grid, pol_decomp, smoothing,
my_subview(tmp_copy, iphi),
my_subview(field_h, iphi), filt_on, bd_turb);
271 auto field_k =
field;
273 for(
int iphi=0; iphi<2; iphi++){
275 field_k(iphi, inode) *= em_pullback_dampfac_k;
284 template<
class DeviceIn,
class DeviceOut, VarType VT, PhiInterpType PIT, TorType TT, KinType KT>
286 View<double**,CLayout,DeviceIn, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
input_potential;
296 GetPotGradFieldArgs(
const View<
double**,
CLayout,DeviceIn, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& input_potential_in,
bool ignore_poloidal_dpot_in=
false)
304 GetPotGradFieldArgs(
const View<double*,CLayout,DeviceIn>& input_potential_in,
bool ignore_poloidal_dpot_in=
false)
305 :
input_potential(View<double**,
CLayout,DeviceIn,Kokkos::MemoryTraits<Kokkos::Unmanaged>>((double*)(input_potential_in.data()), 1, input_potential_in.extent(0))),
322 E_para_em.
request(output_field, em_pullback_dampfac_in, spitzer_resistivity, gyroaverage_requested);
326 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);
328 template<
class DeviceIn,
class DeviceOut, VarType VT, PhiInterpType PIT, TorType TT, KinType KT>
VarType
Definition: field.hpp:11
AlternatingStorage(const std::string &name, int nnode)
Definition: get_potential_grad.hpp:36
View< double **, CLayout, Device > input_potential
Definition: get_potential_grad.hpp:60
void get_pot_epar_em_filter(double *tmp, double *E_para_em, double *spitzer_res)
Definition: field_following_coordinates.hpp:9
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
int nrho
Definition: get_potential_grad.hpp:56
View< double *, CLayout, Device > left(int i_plane)
Definition: get_potential_grad.hpp:41
void request(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_in, bool gyroaverage_requested)
Definition: get_potential_grad.hpp:233
Definition: boundary.hpp:6
constexpr VarType vec2d_if_axisym()
View< double *, CLayout, Device > scratch
Definition: get_potential_grad.hpp:69
int ndim
Definition: get_potential_grad.hpp:58
View< Field< VarType::Scalar, PhiInterpType::None > *, CLayout, Device > pot_managed
Definition: get_potential_grad.hpp:131
void mirror_copy(T1 &view_dest, const T2 &view_src)
Definition: my_mirror_view.hpp:122
bool ignore_poloidal_dpot
Definition: get_potential_grad.hpp:289
bool is_provided
Definition: get_potential_grad.hpp:128
Field00()
Definition: get_potential_grad.hpp:136
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:17
Kokkos::Device< HostExSpace, HostMemSpace > HostType
Definition: space_settings.hpp:56
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:75
View< double **, CLayout, Device > potential
Definition: get_potential_grad.hpp:64
int nphi
Definition: get_potential_grad.hpp:57
Definition: magnetic_field.hpp:12
Definition: get_potential_grad.hpp:285
int get_psn_pbd0_2_nseg()
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:142
bool discard_when_basis_is_one
Definition: get_potential_grad.hpp:129
void em_field_filter(const Simulation< DeviceType > &sml, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, Smoothing &smoothing, const View< double *, CLayout, HostType > &input, const View< double *, CLayout, HostType > &output, bool filt_on, const Boundary< HostType > &bd_turb)
Definition: em_field_filter.cpp:46
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
Definition: gradparx2.hpp:8
Definition: get_potential_grad.hpp:127
rtype * get_psn_AbdH_2_iseg_loc()
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:67
EMParField< DeviceType, DeviceOut > E_para_em
Definition: get_potential_grad.hpp:293
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:74
GridField< DeviceOut, VT, PIT, TT, KT > gradient
Definition: get_potential_grad.hpp:287
bool potential_is_requested
Definition: get_potential_grad.hpp:290
Projection< HostType > half_plane_ff
Definition: grid.hpp:179
Definition: grid_field.hpp:22
View< double *, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > pot
Definition: get_potential_grad.hpp:132
AlternatingStorage< Device > gradient_z_alt
Definition: get_potential_grad.hpp:63
bool gradient_is_requested
Definition: get_potential_grad.hpp:291
Definition: boundary.hpp:12
View< double **, CLayout, DeviceIn, Kokkos::MemoryTraits< Kokkos::Unmanaged > > input_potential
Definition: get_potential_grad.hpp:286
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, bool gyroaverage_requested)
Definition: get_potential_grad.hpp:321
View< double ***, CLayout, Device > gradient
Definition: get_potential_grad.hpp:65
PhiInterpType
Definition: globals.hpp:95
View< double ***, CLayout, Device > potential_rho
Definition: get_potential_grad.hpp:67
View< double *, CLayout, Device > right(int i_plane)
Definition: get_potential_grad.hpp:46
subroutine grid_deriv(grid, qty, qty_deriv_x, qty_deriv_y, psi_only)
Definition: search.F90:2915
constexpr PhiInterpType PIT_GLOBAL
Definition: globals.hpp:105
AlternatingStorage< Device > gradient_r_alt
Definition: get_potential_grad.hpp:62
double bt_sign
Whether toroidal field is reversed?
Definition: magnetic_field.hpp:39
Definition: smoothing.hpp:8
View< double ***, CLayout, Device > field_rho
Definition: get_potential_grad.hpp:222
Field00< DeviceType > field00
Definition: get_potential_grad.hpp:292
GetPotGradFieldArgs(const View< double *, CLayout, DeviceIn > &input_potential_in, bool ignore_poloidal_dpot_in=false)
Definition: get_potential_grad.hpp:304
EMParField()
Definition: get_potential_grad.hpp:229
void request_potential(const GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > &potential_in)
Definition: get_potential_grad.hpp:311
rtype * get_psn_pbd0_2_iseg_loc()
GyroAverageMatrices< DeviceType > gyro_avg_matrices
Definition: get_potential_grad.hpp:73
View< double *, CLayout, Device > z
Definition: get_potential_grad.hpp:134
Field00(const GridField< DeviceIn, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > &field_in, bool discard_when_basis_is_one_in)
Definition: get_potential_grad.hpp:141
int nnode
Definition: get_potential_grad.hpp:55
double em_pullback_dampfac
Definition: get_potential_grad.hpp:224
Definition: get_potential_grad.hpp:218
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
void exit_XGC(std::string msg)
Definition: globals.hpp:37
GridField< DeviceOut, VarType::Scalar, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > field_out
Definition: get_potential_grad.hpp:227
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
GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > potential
Definition: get_potential_grad.hpp:288
Definition: get_potential_grad.hpp:31
AlternatingStorage< Device > potential_alt
Definition: get_potential_grad.hpp:61
int get_psn_AbdH_2_nseg()
void request_gradient(const GridField< DeviceOut, VT, PIT, TT, KT > &gradient_in)
Definition: get_potential_grad.hpp:316
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 parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
void calculate_gradient(const Grid< DeviceType > &grid, const GradientMatrices< DeviceType > &grad_matrices)
Definition: get_potential_grad.hpp:153
View< double **, CLayout, Device > field
Definition: get_potential_grad.hpp:221
int nnode
Number of grid nodes.
Definition: grid.hpp:159
GradParXTmp gptx
Definition: get_potential_grad.hpp:76
View< double *, CLayout, Device > r
Definition: get_potential_grad.hpp:133
View< double **, CLayout, Device > field
Definition: get_potential_grad.hpp:32
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:169
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
bool requested
Definition: get_potential_grad.hpp:219
GetPotGradFieldArgs(const View< double **, CLayout, DeviceIn, Kokkos::MemoryTraits< Kokkos::Unmanaged >> &input_potential_in, bool ignore_poloidal_dpot_in=false)
Definition: get_potential_grad.hpp:296
View< double ****, CLayout, Device > gradient_rho
Definition: get_potential_grad.hpp:66
View< double *, CLayout, HostType > spitzer_resistivity
Definition: get_potential_grad.hpp:225
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10
void calculate(const Simulation< DeviceType > &sml, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, const DomainDecomposition< DeviceType > &pol_decomp, Smoothing &smoothing, const View< double **, CLayout, Device > &field_para)
Definition: get_potential_grad.hpp:246
Definition: get_potential_grad.hpp:53