1 #ifndef GET_POTENTIAL_GRAD
2 #define GET_POTENTIAL_GRAD
31 template<
class Device>
33 View<double**,CLayout,Device>
field;
42 View<double*,CLayout, Device>
left(
int i_plane){
43 int i_left_alt = i_plane%2;
47 View<double*,CLayout, Device>
right(
int i_plane){
48 int i_right_alt = (i_plane+1)%2;
53 template<
class Device,
class DeviceOut>
81 nrho(gyroavg_requested ? gyro_avg_matrices_in.
nrho : 0),
94 if(!std::is_same<DeviceOut,Device>()){
112 GPTLstop(
"GET_POT_GRAD_GPTX_SETUP");
116 template<
class Device>
122 View<double*,CLayout, Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
pot;
123 View<double*,CLayout, Device>
r;
124 View<double*,CLayout, Device>
z;
130 template<
class DeviceIn>
132 :
r(
NoInit(
"r"), field_in.f.extent(0)),
133 z(
NoInit(
"z"), field_in.f.extent(0)),
140 pot = View<double*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>((
double*)(
pot_managed.data()),
pot_managed.layout());
158 template<
class DeviceOut, PhiInterpType PIT>
163 View<double**,CLayout, Device> r_tmp(
NoInit(
"r_tmp"), nphi,
r.size());
164 View<double**,CLayout, Device> z_tmp(
NoInit(
"z_tmp"), nphi,
z.size());
166 for(
int iphi=0; iphi<nphi; iphi++){
177 for(
int iphi=0; iphi<nphi; iphi++){
178 Kokkos::parallel_for(
"set_field", Kokkos::RangePolicy<ExSpace>(0,field00_ff_h.extent(0)), KOKKOS_LAMBDA(
const int i ){
180 field00_ff(i).V[iphi][0]=r_tmp(iphi,i);
181 field00_ff(i).V[iphi][1]=z_tmp(iphi,i);
183 field00_ff(i).E[0]=r_tmp(iphi,i);
184 field00_ff(i).E[1]=z_tmp(iphi,i);
192 Kokkos::parallel_for(
"set_field", Kokkos::RangePolicy<typename DeviceOut::execution_space>(0,field00_ff_h.extent(0)), KOKKOS_LAMBDA(
const int i ){
194 field00_ff_h(i).V[0][0]=0.0;
195 field00_ff_h(i).V[0][1]=0.0;
196 field00_ff_h(i).V[1][0]=0.0;
197 field00_ff_h(i).V[1][1]=0.0;
199 field00_ff_h(i).E[0]=0.0;
200 field00_ff_h(i).E[1]=0.0;
207 template<
class Device,
class DeviceOut>
211 View<double**,CLayout, Device>
field;
233 View<double**,CLayout, HostType> tmp_copy(
NoInit(
"tmp"),2,grid.
nnode);
234 Kokkos::deep_copy(tmp_copy, field_para);
247 template<
class DeviceIn,
class DeviceOut, VarType VT, PhiInterpType PIT, TorType TT, KinType KT>
249 View<double**,CLayout,DeviceIn, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
input_potential;
259 GetPotGradFieldArgs(
const View<
double**,
CLayout,DeviceIn, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& input_potential_in,
bool ignore_poloidal_dpot_in=
false)
267 GetPotGradFieldArgs(
const View<double*,CLayout,DeviceIn>& input_potential_in,
bool ignore_poloidal_dpot_in=
false)
268 :
input_potential(View<double**,
CLayout,DeviceIn,Kokkos::MemoryTraits<Kokkos::Unmanaged>>((double*)(input_potential_in.data()), 1, input_potential_in.extent(0))),
289 template<
class DeviceIn,
class DeviceOut, VarType VT, PhiInterpType PIT, TorType TT, KinType KT>
VarType
Definition: field.hpp:16
AlternatingStorage(const std::string &name, int nnode)
Definition: get_potential_grad.hpp:37
View< double **, CLayout, Device > input_potential
Definition: get_potential_grad.hpp:61
Definition: field_following_coordinates.hpp:18
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
int nrho
Definition: get_potential_grad.hpp:57
View< double *, CLayout, Device > left(int i_plane)
Definition: get_potential_grad.hpp:42
Definition: gradparx2.hpp:7
constexpr VarType vec2d_if_axisym()
View< double *, CLayout, Device > scratch
Definition: get_potential_grad.hpp:70
int ndim
Definition: get_potential_grad.hpp:59
View< Field< VarType::Scalar, PhiInterpType::None > *, CLayout, Device > pot_managed
Definition: get_potential_grad.hpp:121
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:252
void request(const GridField< DeviceOut, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > &output_field)
Definition: get_potential_grad.hpp:220
void get_pot_epar_em_filter(double *tmp, double *E_para_em)
bool is_provided
Definition: get_potential_grad.hpp:118
Field00()
Definition: get_potential_grad.hpp:126
Kokkos::Device< HostExSpace, HostMemSpace > HostType
Definition: space_settings.hpp:56
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:76
View< double **, CLayout, Device > potential
Definition: get_potential_grad.hpp:65
int * get_psn_ff_1dp_tr_loc()
int nphi
Definition: get_potential_grad.hpp:58
Definition: magnetic_field.hpp:12
Definition: get_potential_grad.hpp:248
int get_psn_pbd0_2_nseg()
bool discard_when_basis_is_one
Definition: get_potential_grad.hpp:119
Definition: gradparx2.hpp:43
Definition: get_potential_grad.hpp:117
void cnvt_grid_real2ff(const Grid< DeviceType > &grid, const View< double **, CLayout, DeviceType > &input, const View< double **, Kokkos::LayoutRight, DeviceType > &output)
Definition: field_following_coordinates.hpp:373
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:67
EMParField< DeviceType, DeviceOut > E_para_em
Definition: get_potential_grad.hpp:256
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:75
GridField< DeviceOut, VT, PIT, TT, KT > gradient
Definition: get_potential_grad.hpp:250
double * get_psn_ff_1dp_dx_loc()
bool potential_is_requested
Definition: get_potential_grad.hpp:253
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
Definition: grid_field.hpp:25
View< double *, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > pot
Definition: get_potential_grad.hpp:122
AlternatingStorage< Device > gradient_z_alt
Definition: get_potential_grad.hpp:64
bool gradient_is_requested
Definition: get_potential_grad.hpp:254
View< double **, CLayout, DeviceIn, Kokkos::MemoryTraits< Kokkos::Unmanaged > > input_potential
Definition: get_potential_grad.hpp:249
void get_field_Ah_cv_ff(Field< VarType::Scalar, PIT_GLOBAL > *psn_Ah_cv_ff)
View< double ***, CLayout, Device > gradient
Definition: get_potential_grad.hpp:66
PhiInterpType
Definition: globals.hpp:88
View< double ***, CLayout, Device > potential_rho
Definition: get_potential_grad.hpp:68
View< double *, CLayout, Device > right(int i_plane)
Definition: get_potential_grad.hpp:47
subroutine grid_deriv(grid, qty, qty_deriv_x, qty_deriv_y, psi_only)
Definition: search.F90:3994
constexpr PhiInterpType PIT_GLOBAL
Definition: globals.hpp:98
AlternatingStorage< Device > gradient_r_alt
Definition: get_potential_grad.hpp:63
double bt_sign
Whether toroidal field is reversed?
Definition: magnetic_field.hpp:19
View< double ***, CLayout, Device > field_rho
Definition: get_potential_grad.hpp:212
Field00< DeviceType > field00
Definition: get_potential_grad.hpp:255
GetPotGradFieldArgs(const View< double *, CLayout, DeviceIn > &input_potential_in, bool ignore_poloidal_dpot_in=false)
Definition: get_potential_grad.hpp:267
EMParField()
Definition: get_potential_grad.hpp:216
void request_potential(const GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > &potential_in)
Definition: get_potential_grad.hpp:274
rtype * get_psn_pbd0_2_iseg_loc()
void request_para_em(const GridField< DeviceOut, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > &output_field)
Definition: get_potential_grad.hpp:284
GyroAverageMatrices< DeviceType > gyro_avg_matrices
Definition: get_potential_grad.hpp:74
View< double *, CLayout, Device > z
Definition: get_potential_grad.hpp:124
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:131
int nnode
Definition: get_potential_grad.hpp:56
Definition: get_potential_grad.hpp:208
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
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::Device< ExSpace, MemSpace > DeviceType
Definition: space_settings.hpp:47
const bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:15
GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > potential
Definition: get_potential_grad.hpp:251
void calculate(const Grid< DeviceType > &grid, const View< double **, CLayout, Device > &field_para)
Definition: get_potential_grad.hpp:227
Definition: get_potential_grad.hpp:32
AlternatingStorage< Device > potential_alt
Definition: get_potential_grad.hpp:62
void request_gradient(const GridField< DeviceOut, VT, PIT, TT, KT > &gradient_in)
Definition: get_potential_grad.hpp:279
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:143
View< double **, CLayout, Device > field
Definition: get_potential_grad.hpp:211
GridField< DeviceOut, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > field_out
Definition: get_potential_grad.hpp:214
int nnode
Number of grid nodes.
Definition: grid.hpp:216
GradParXTmp gptx
Definition: get_potential_grad.hpp:77
View< double *, CLayout, Device > r
Definition: get_potential_grad.hpp:123
double * get_psn_ff_1dp_p_loc()
View< double **, CLayout, Device > field
Definition: get_potential_grad.hpp:33
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
bool requested
Definition: get_potential_grad.hpp:209
GetPotGradFieldArgs(const View< double **, CLayout, DeviceIn, Kokkos::MemoryTraits< Kokkos::Unmanaged >> &input_potential_in, bool ignore_poloidal_dpot_in=false)
Definition: get_potential_grad.hpp:259
View< double ****, CLayout, Device > gradient_rho
Definition: get_potential_grad.hpp:67
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10
void set_field(const Grid< DeviceType > &grid, FieldFollowingCoordinates &ff, View< Field< VarType::Vector2D, PIT > *, CLayout, DeviceOut > &field00_ff_h)
Definition: get_potential_grad.hpp:159
Definition: get_potential_grad.hpp:54