1 #ifndef GET_POTENTIAL_GRAD
2 #define GET_POTENTIAL_GRAD
23 template<
class Device>
25 View<double**,CLayout,Device>
field;
34 View<double*,CLayout, Device>
left(
int i_plane){
35 int i_left_alt = i_plane%2;
39 View<double*,CLayout, Device>
right(
int i_plane){
40 int i_right_alt = (i_plane+1)%2;
45 template<
class Device,
class DeviceOut>
73 nrho(gyroavg_requested ? gyro_avg_matrices_in.
nrho : 0),
86 if(!std::is_same<DeviceOut,Device>()){
92 if(gradient_requested){
93 #ifdef NO_FORTRAN_MODULES
94 grad_matrices = grid.gradient_matrices_h.template mirror<DeviceType>();
108 if(gradient_requested && !sml.
is_XGCa){
111 GPTLstop(
"GET_POT_GRAD_GPTX_SETUP");
115 template<
class Device>
121 View<double*,CLayout, Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
pot;
122 View<double*,CLayout, Device>
r;
123 View<double*,CLayout, Device>
z;
129 template<
class DeviceIn>
131 :
r(
NoInit(
"r"), field_in.f.extent(0)),
132 z(
NoInit(
"z"), field_in.f.extent(0)),
139 pot = View<double*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>((
double*)(
pot_managed.data()),
pot_managed.layout());
157 template<
class DeviceOut, PhiInterpType PIT>
162 View<double**,CLayout, Device> r_tmp(
NoInit(
"r_tmp"), nphi,
r.size());
163 View<double**,CLayout, Device> z_tmp(
NoInit(
"z_tmp"), nphi,
z.size());
165 for(
int iphi=0; iphi<nphi; iphi++){
176 for(
int iphi=0; iphi<nphi; iphi++){
177 Kokkos::parallel_for(
"set_field", Kokkos::RangePolicy<ExSpace>(0,field00_ff_h.extent(0)), KOKKOS_LAMBDA(
const int i ){
179 field00_ff(i).V[iphi][0]=r_tmp(iphi,i);
180 field00_ff(i).V[iphi][1]=z_tmp(iphi,i);
182 field00_ff(i).E[0]=r_tmp(iphi,i);
183 field00_ff(i).E[1]=z_tmp(iphi,i);
191 Kokkos::parallel_for(
"set_field", Kokkos::RangePolicy<typename DeviceOut::execution_space>(0,field00_ff_h.extent(0)), KOKKOS_LAMBDA(
const int i ){
193 field00_ff_h(i).V[0][0]=0.0;
194 field00_ff_h(i).V[0][1]=0.0;
195 field00_ff_h(i).V[1][0]=0.0;
196 field00_ff_h(i).V[1][1]=0.0;
198 field00_ff_h(i).E[0]=0.0;
199 field00_ff_h(i).E[1]=0.0;
206 template<
class Device,
class DeviceOut>
210 View<double**,CLayout, Device>
field;
223 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,
const Boundary& boundary,
bool gyroaverage_requested){
226 int nrhop1 = gyroaverage_requested ?
field_out.f.extent(1) : 1;
228 if(!gyroaverage_requested)
exit_XGC(
"\nError: EMParField gyroaverage_requested=false is only supported for multirate at the moment.\n");
243 View<double**,CLayout, HostType> tmp_copy(
NoInit(
"tmp"),2,grid.
nnode);
244 Kokkos::deep_copy(tmp_copy, field_para);
253 for(
int iphi=0; iphi<2; iphi++){
254 bool filt_on =
false;
255 em_field_filter(sml, magnetic_field, grid, pol_decomp, smoothing,
my_subview(tmp_copy, iphi),
my_subview(field_h, iphi), filt_on,
filter_bndry,
filter_bndry);
262 auto field_k =
field;
264 for(
int iphi=0; iphi<2; iphi++){
266 field_k(iphi, inode) *= em_pullback_dampfac_k;
275 template<
class DeviceIn,
class DeviceOut, VarType VT, PhiInterpType PIT, TorType TT, KinType KT>
277 View<double**,CLayout,DeviceIn, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
input_potential;
287 GetPotGradFieldArgs(
const View<
double**,
CLayout,DeviceIn, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& input_potential_in,
bool ignore_poloidal_dpot_in=
false)
295 GetPotGradFieldArgs(
const View<double*,CLayout,DeviceIn>& input_potential_in,
bool ignore_poloidal_dpot_in=
false)
296 :
input_potential(View<double**,
CLayout,DeviceIn,Kokkos::MemoryTraits<Kokkos::Unmanaged>>((double*)(input_potential_in.data()), 1, input_potential_in.extent(0))),
312 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,
const Boundary& boundary,
bool gyroaverage_requested){
313 E_para_em.
request(output_field, em_pullback_dampfac_in, spitzer_resistivity, boundary, gyroaverage_requested);
317 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);
319 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:29
View< double **, CLayout, Device > input_potential
Definition: get_potential_grad.hpp:53
Definition: field_following_coordinates.hpp:9
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
int nrho
Definition: get_potential_grad.hpp:49
View< double *, CLayout, Device > left(int i_plane)
Definition: get_potential_grad.hpp:34
constexpr VarType vec2d_if_axisym()
View< double *, CLayout, Device > scratch
Definition: get_potential_grad.hpp:62
int ndim
Definition: get_potential_grad.hpp:51
View< Field< VarType::Scalar, PhiInterpType::None > *, CLayout, Device > pot_managed
Definition: get_potential_grad.hpp:120
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:280
bool is_provided
Definition: get_potential_grad.hpp:117
Field00()
Definition: get_potential_grad.hpp:125
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, const Boundary &boundary, bool gyroaverage_requested)
Definition: get_potential_grad.hpp:312
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:57
FieldFollowingCoordinates ff
Definition: get_potential_grad.hpp:68
View< double **, CLayout, Device > potential
Definition: get_potential_grad.hpp:57
int nphi
Definition: get_potential_grad.hpp:50
Definition: magnetic_field.hpp:12
Definition: get_potential_grad.hpp:276
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:118
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
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 &bd_turb, const Boundary &bd_hyp_visc)
Definition: em_field_filter.cpp:46
Definition: get_potential_grad.hpp:116
Boundary filter_bndry
Definition: get_potential_grad.hpp:215
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:68
EMParField< DeviceType, DeviceOut > E_para_em
Definition: get_potential_grad.hpp:284
GradientMatrices< DeviceType > grad_matrices
Definition: get_potential_grad.hpp:67
GridField< DeviceOut, VT, PIT, TT, KT > gradient
Definition: get_potential_grad.hpp:278
bool potential_is_requested
Definition: get_potential_grad.hpp:281
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:121
AlternatingStorage< Device > gradient_z_alt
Definition: get_potential_grad.hpp:56
bool gradient_is_requested
Definition: get_potential_grad.hpp:282
Definition: boundary.hpp:85
View< double **, CLayout, DeviceIn, Kokkos::MemoryTraits< Kokkos::Unmanaged > > input_potential
Definition: get_potential_grad.hpp:277
View< double ***, CLayout, Device > gradient
Definition: get_potential_grad.hpp:58
PhiInterpType
Definition: globals.hpp:95
View< double ***, CLayout, Device > potential_rho
Definition: get_potential_grad.hpp:60
View< double *, CLayout, Device > right(int i_plane)
Definition: get_potential_grad.hpp:39
subroutine grid_deriv(grid, qty, qty_deriv_x, qty_deriv_y, psi_only)
Definition: search.F90:2895
constexpr PhiInterpType PIT_GLOBAL
Definition: globals.hpp:105
AlternatingStorage< Device > gradient_r_alt
Definition: get_potential_grad.hpp:55
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:211
Field00< DeviceType > field00
Definition: get_potential_grad.hpp:283
GetPotGradFieldArgs(const View< double *, CLayout, DeviceIn > &input_potential_in, bool ignore_poloidal_dpot_in=false)
Definition: get_potential_grad.hpp:295
EMParField()
Definition: get_potential_grad.hpp:219
void request_potential(const GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > &potential_in)
Definition: get_potential_grad.hpp:302
View< int *, CLayout, Device > get_view_int_not_in_list(int nnode_in) const
Definition: vertex_list.hpp:185
GyroAverageMatrices< DeviceType > gyro_avg_matrices
Definition: get_potential_grad.hpp:66
View< double *, CLayout, Device > z
Definition: get_potential_grad.hpp:123
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:130
int nnode
Definition: get_potential_grad.hpp:48
double em_pullback_dampfac
Definition: get_potential_grad.hpp:213
Definition: get_potential_grad.hpp:207
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:217
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
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, const Boundary &boundary, bool gyroaverage_requested)
Definition: get_potential_grad.hpp:223
GridField< DeviceOut, VarType::Scalar, PIT, TT, KT > potential
Definition: get_potential_grad.hpp:279
Definition: get_potential_grad.hpp:24
AlternatingStorage< Device > potential_alt
Definition: get_potential_grad.hpp:54
void get_pot_epar_em_filter(double *tmp, double *E_para_em, double *spitzer_res, int *bndry)
void request_gradient(const GridField< DeviceOut, VT, PIT, TT, KT > &gradient_in)
Definition: get_potential_grad.hpp:307
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:142
View< double **, CLayout, Device > field
Definition: get_potential_grad.hpp:210
int nnode
Number of grid nodes.
Definition: grid.hpp:159
GradParXTmp gptx
Definition: get_potential_grad.hpp:69
View< double *, CLayout, Device > r
Definition: get_potential_grad.hpp:122
View< double **, CLayout, Device > field
Definition: get_potential_grad.hpp:25
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:158
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:69
bool requested
Definition: get_potential_grad.hpp:208
GetPotGradFieldArgs(const View< double **, CLayout, DeviceIn, Kokkos::MemoryTraits< Kokkos::Unmanaged >> &input_potential_in, bool ignore_poloidal_dpot_in=false)
Definition: get_potential_grad.hpp:287
View< double ****, CLayout, Device > gradient_rho
Definition: get_potential_grad.hpp:59
View< double *, CLayout, HostType > spitzer_resistivity
Definition: get_potential_grad.hpp:214
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:237
Definition: get_potential_grad.hpp:46