XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
grid_field.hpp
Go to the documentation of this file.
1 #ifndef GRID_FIELD_HPP
2 #define GRID_FIELD_HPP
3 #include "space_settings.hpp"
4 #include "NamelistReader.hpp"
5 
6 #include "globals.hpp"
7 #include "grid.hpp"
8 #include "linear_weights.hpp"
9 #include "gyro_radius.hpp"
10 #include "field.hpp"
11 
12 /* TorType specifies whether the field is a single plane or needs a plane dimension
13  * */
14 enum class TorType{
15  OnePlane,
17 };
18 
19 // General declaration
20 // 2x2 = 4 types of GridField available: With and without gyroaverage dimension, with and without plane dimension
21 template<class Device, VarType VT, PhiInterpType PIT, TorType TT, KinType KT, ScatterType ST = ScatterType::Atomic>
22 struct GridField;
23 
24 // "ScalarGridField"
25 template<class Device, VarType VT, PhiInterpType PIT>
28  using device_type = Device;
29  static constexpr KinType KT = KinType::DriftKin;
30 
31  Kokkos::View<field_type*,Kokkos::LayoutRight,Device> f;
32 
34  GridField(std::string name, int nphi, int nrho, int nnode) : f(name,nnode) {}
35  GridField(std::string name, int nnode) : f(name,nnode) {}
36  field_type* data() const {return f.data();}
37  int size() const {return f.size();}
38  int nnode() const {return f.extent(0);}
39  int nrhop1() const {return 1;}
40  int nphi() const {return 1;}
41 
42  KOKKOS_INLINE_FUNCTION bool is_allocated() const {return f.is_allocated();}
43  KOKKOS_INLINE_FUNCTION field_type& operator ()(int inode) const {return f(inode);}
44 
45  // Scatter to a node
46  KOKKOS_INLINE_FUNCTION void scatter(int node, const SimdPhiWeights<get_phi_wt_usage(PIT)>& phi_wts, int i_simd, double particle_weight) const{
47  f(node).scatter(phi_wts, i_simd, particle_weight);
48  }
49 
50  // Scatter to a triangle
51  KOKKOS_INLINE_FUNCTION void scatter(const Grid<DeviceType>& grid, int ithread, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, int i_simd, const SimdGyroWeights<DriftKin>& rho_wts, double particle_weight) const{
52  for (int j = 0; j<3; j++){
53  // Find triangle's nodes
54  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
55  double wp=grid_wts.p[j][i_simd];
56 
57  // Scatter to node
58  scatter(node, grid_wts.phi_wts, i_simd, wp*particle_weight);
59  }
60  }
61 
62  // Gather from a triangle
63  KOKKOS_INLINE_FUNCTION void gather(const Grid<Device> &grid, const SimdGridWeights<Order::One, PhiInterpType::None>& grid_wts, const Simd<double>& phi, Simd<double>& fld) const{
64  // Initialize local field to 0
65  fld = 0.0;
66 
67  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
68  if(grid_wts.is_invalid(i_simd)) continue;
69 
70  // Loop over the 3 vertices of the grid triangle and add up the contributions from each
71  for (int ip = 0; ip<3; ip++){
72  int node = grid.get_node_index(grid_wts.itr[i_simd], ip);
73  double wp = grid_wts.p[ip][i_simd];
74  f(node).gather(fld,i_simd,wp);
75  }
76  }
77  }
78 
79  // Gather from a triangle
80  KOKKOS_INLINE_FUNCTION void gather(const Grid<Device> &grid, const SimdGridWeights<Order::One, PhiInterpType::Planes>& grid_wts, const Simd<double>& phi, Simd<double>& fld) const{
81  // Initialize local field to 0
82  fld = 0.0;
83 
84  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
85  if(grid_wts.is_invalid(i_simd)) continue;
86 
87  // Loop over the 3 vertices of the grid triangle and add up the contributions from each
88  for (int ip = 0; ip<3; ip++){
89  int node = grid.get_node_index(grid_wts.itr[i_simd], ip);
90  double wp = grid_wts.p[ip][i_simd];
91  f(node).gather(fld,i_simd,wp,grid_wts.phi_wts);
92  }
93  }
94  }
95 
96  void reset_to_zero(){
97  int ndoubles_in_grid_field = f.size()*field_type::SIZE();
98  Kokkos::View<double*,Kokkos::LayoutRight,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1d_double((double*)(data()), ndoubles_in_grid_field);
99  Kokkos::deep_copy(view_1d_double, 0.0);
100  }
101 
102  // TODO: Generalize this copy and these transposes for ndim etc
103  // Fill View with transposed data where inode is the contiguous index
104  // Ultimately, there should probably be an implementation GridField that has the transposed indices
105  void copy_to_double_view(const View<double*,CLayout,Device>& dest_view) const{
106  // Make an unmanaged view around the input field
107  View<double*,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> f_unmanaged((double*)data(),nnode());
108 
109  Kokkos::deep_copy(dest_view, f_unmanaged);
110  }
111 
112  View<double*,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> unmanaged() const{
113  return View<double*,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>>((double*)(f.data()), f.layout());
114  }
115 
116  // Fill View with transposed data where inode is the contiguous index
117  // Ultimately, there should probably be an implementation GridField that has the transposed indices
118  void transpose_copy_to_double_view(const View<double**,CLayout,Device>& dest_view) const{
119  // Retrieve nphi from the Field of this GridField
120  constexpr int n_phi = field_type::NPHI();
121 
122  // Make an unmanaged view around the input field
123  View<double**,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> f_unmanaged((double*)data(),nnode(), n_phi);
124 
125  // Copy f_unmanaged into iphi = 0 and iphi = 1 of dest_view
126  Kokkos::parallel_for("var_transpose_copy", Kokkos::RangePolicy<typename Device::execution_space>( 0, nnode()), KOKKOS_LAMBDA(const int inode){
127  for(int iphi=0; iphi<n_phi; iphi++){
128  dest_view(iphi, inode) = f_unmanaged(inode, iphi);
129  }
130  });
131  Kokkos::fence();
132  }
133 
134  // Transpose and copy data from a view where inode is the contiguous index
135  void transpose_copy_from_double_view(const View<double**,CLayout,Device>& src_view) const{
136  // Retrieve nphi from the Field of this GridField
137  constexpr int n_phi = field_type::NPHI();
138 
139  // Make an unmanaged view of the data
140  View<double**,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> f_unmanaged((double*)data(),nnode(), n_phi);
141 
142  // Transpose from src_view into this gridfield
143  Kokkos::parallel_for("var_transpose_copy", Kokkos::RangePolicy<ExSpace>( 0, nnode()), KOKKOS_LAMBDA(const int inode){
144  for(int iphi=0; iphi<n_phi; iphi++){
145  f_unmanaged(inode, iphi) = src_view(iphi, inode);
146  }
147  });
148  Kokkos::fence();
149  }
150 
153  static KOKKOS_INLINE_FUNCTION void view_gather3(const Grid<DeviceType>& grid, const View<double*,CLayout,Device>& view1, const View<double*,CLayout,Device>& view2, const View<double*,CLayout,Device>& view3, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, double& val1, double& val2, double& val3, int i_simd){
154  val1=0.0;
155  val2=0.0;
156  val3=0.0;
157  for (int ip=0; ip<3; ip++){
158  int nd = grid.get_node_index(grid_wts.itr[i_simd], ip);
159  val1 += view1(nd)*grid_wts.p[ip][i_simd];
160  val2 += view2(nd)*grid_wts.p[ip][i_simd];
161  val3 += view3(nd)*grid_wts.p[ip][i_simd];
162  }
163  }
164 
165  static KOKKOS_INLINE_FUNCTION void view_gather(const Grid<DeviceType>& grid, const View<double*,CLayout,Device>& view, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, Simd<double>& val){
166  val = 0.0;
167  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
168  if(grid_wts.itr[i_simd]<=0) continue;
169  for (int ip = 0; ip < 3; ip++){
170  int node = grid.get_node_index(grid_wts.itr[i_simd], ip);
171  val[i_simd] += grid_wts.p[ip][i_simd]*view(node);
172  }
173  }
174  }
175 
176  static KOKKOS_INLINE_FUNCTION void view_vec_odim_gather(const Grid<DeviceType>& grid, const View<Field<VarType::Vector,PhiInterpType::None>**,CLayout,Device>& view, int ind, const SimdGridWeights<Order::One, PhiInterpType::None>& grid_wts, SimdVector& val, int i_simd){
177  val.r[i_simd] = 0.0;
178  val.z[i_simd] = 0.0;
179  val.phi[i_simd] = 0.0;
180  for (int ip = 0; ip<3; ip++){
181  int node = grid.get_node_index(grid_wts.itr[i_simd], ip);
182  double wp = grid_wts.p[ip][i_simd];
183  view(ind,node).gather(val, i_simd, wp);
184  }
185  }
186 
187  static KOKKOS_INLINE_FUNCTION void view_vec_odim_gather(const Grid<DeviceType>& grid, const View<Field<VarType::Vector,PhiInterpType::None>**,CLayout,Device>& view, int ind, const SimdGridWeights<Order::Zero, PhiInterpType::None>& grid_wts, SimdVector& val, int i_simd){
188  val.r[i_simd] = 0.0;
189  val.z[i_simd] = 0.0;
190  val.phi[i_simd] = 0.0;
191  int node = grid_wts.node[i_simd];
192  constexpr double wp = 1.0;
193  view(ind,node).gather(val, i_simd, wp);
194  }
195 
196  static KOKKOS_INLINE_FUNCTION void view_gyro_scatter3(const Grid<DeviceType>& grid, const View<double**,CLayout,Device>& view1, const View<double**,CLayout,Device>& view2, const View<double**,CLayout,Device>& view3, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, double val1, double val2, double val3, int i_simd, const LinearWeights& rho_wts, bool is_gyro){
197  // Scatter moments into grid array
198  for (int ip = 0; ip < 3; ip++){
199  int node = grid.get_node_index(grid_wts.itr[i_simd], ip);
200  Kokkos::atomic_add(&(view1(rho_wts.i, node)), grid_wts.p[ip][i_simd]*rho_wts.w[0]*val1);
201  Kokkos::atomic_add(&(view2(rho_wts.i, node)), grid_wts.p[ip][i_simd]*rho_wts.w[0]*val2);
202  Kokkos::atomic_add(&(view3(rho_wts.i, node)), grid_wts.p[ip][i_simd]*rho_wts.w[0]*val3);
203  if(is_gyro){
204  Kokkos::atomic_add(&(view1(rho_wts.i+1, node)), grid_wts.p[ip][i_simd]*rho_wts.w[1]*val1);
205  Kokkos::atomic_add(&(view2(rho_wts.i+1, node)), grid_wts.p[ip][i_simd]*rho_wts.w[1]*val2);
206  Kokkos::atomic_add(&(view3(rho_wts.i+1, node)), grid_wts.p[ip][i_simd]*rho_wts.w[1]*val3);
207  }
208  }
209  }
210 
211  // view with outer dimension
212  static KOKKOS_INLINE_FUNCTION void view_odim_scatter(const Grid<DeviceType>& grid, const View<double**,CLayout,Device>& view, int ind, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, double val, int i_simd){
213  for (int j = 0; j<3; j++){
214  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
215  double wp=grid_wts.p[j][i_simd];
216 
217  Kokkos::atomic_add(&(view(ind,node)), wp*val);
218  }
219  }
220 
221  static KOKKOS_INLINE_FUNCTION void view_scatter(const Grid<DeviceType>& grid, const View<double*,CLayout,Device>& view, const SimdGridWeights<Order::One, PhiInterpType::None>& grid_wts, double val, int i_simd){
222  for (int j = 0; j<3; j++){
223  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
224  double wp=grid_wts.p[j][i_simd];
225 
226  Kokkos::atomic_add(&(view(node)), wp*val);
227  }
228  }
229 
230  static KOKKOS_INLINE_FUNCTION void view_ff_scatter(const Grid<DeviceType>& grid, const View<double**,CLayout,Device>& view, const SimdGridWeights<Order::One, PhiInterpType::Planes>& grid_wts, double wphi, double val, int i_simd){
231  for (int j = 0; j<3; j++){
232  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
233  double wp=grid_wts.p[j][i_simd];
234 
235  Kokkos::atomic_add(&(view(0,node)), wp*wphi*val);
236  Kokkos::atomic_add(&(view(1,node)), wp*(1.0-wphi)*val);
237  }
238  }
239 
240  static KOKKOS_INLINE_FUNCTION void view_odim_variance(const Grid<DeviceType>& grid, const View<double**,CLayout,Device>& view, const View<double**,CLayout,Device>& variance, int ind, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, double val, int i_simd){
241  for (int j = 0; j<3; j++){
242  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
243  double wp=grid_wts.p[j][i_simd];
244 
245  double tmp = view(ind,node) - wp*val;
246  Kokkos::atomic_add(&(variance(ind,node)), tmp*tmp);
247  }
248  }
249 
250  static KOKKOS_INLINE_FUNCTION void view_rep_scatter3(const Grid<DeviceType>& grid, const View<double***,CLayout,Device>& view, int ind1, int ind2, int ind3, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, double val1, double val2, double val3, int ithread, int i_simd){
251  // Scatter moments into grid array
252  for (int ip = 0; ip < 3; ip++){
253  int node = grid.get_node_index(grid_wts.itr[i_simd], ip);
254  double wp = grid_wts.p[ip][i_simd];
255 
256  access_add(&(view(ithread,node,ind1)),wp*val1);
257  access_add(&(view(ithread,node,ind2)),wp*val2);
258  access_add(&(view(ithread,node,ind3)),wp*val3);
259  }
260  }
261 };
262 
263 template<class Device, VarType VT, PhiInterpType PIT>
266  using device_type = Device;
267  static constexpr KinType KT = KinType::GyroKin;
268 
269  Kokkos::View<field_type**,Kokkos::LayoutRight,Device> f;
270 
272  GridField(std::string name, int nphi, int nrho, int nnode) : f(name,nnode, nrho+1) {}
273  GridField(std::string name, int nrho, int nnode) : f(name,nnode, nrho+1) {}
274  field_type* data() const {return f.data();}
275  int size() const {return f.size();}
276  int nnode() const {return f.extent(0);}
277  int nrhop1() const {return f.extent(1);}
278  int nphi() const {return 1;}
279  KOKKOS_INLINE_FUNCTION bool is_allocated() const {return f.is_allocated();}
280  KOKKOS_INLINE_FUNCTION field_type& operator ()(int inode, int irho) const {return f(inode, irho);}
281 
282  // Scatter to a node
283  KOKKOS_INLINE_FUNCTION void scatter(int node, const SimdPhiWeights<get_phi_wt_usage(PIT)>& phi_wts, const SimdGyroWeights<GyroKin>& rho_wts, int i_simd, double particle_weight) const{
284  int irho = rho_wts.irho(i_simd);
285  f(node,irho).scatter(rho_wts, phi_wts, i_simd, particle_weight, f(node,irho+1));
286  }
287 
288  // Scatter to a triangle (same as for DriftKin - consolidate)
289  KOKKOS_INLINE_FUNCTION void scatter(const Grid<DeviceType>& grid, int ithread, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, int i_simd, const SimdGyroWeights<GyroKin>& rho_wts, double particle_weight) const{
290  for (int j = 0; j<3; j++){
291  // Find triangle's nodes
292  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
293  double wp=grid_wts.p[j][i_simd];
294 
295  // Scatter to node
296  scatter(node, grid_wts.phi_wts, rho_wts, i_simd, wp*particle_weight);
297  }
298  }
299 
301  int ndoubles_in_grid_field = f.size()*field_type::SIZE();
302  Kokkos::View<double*,Kokkos::LayoutRight,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1d_double((double*)(f.data()), ndoubles_in_grid_field);
303  Kokkos::deep_copy(view_1d_double, 0.0);
304  }
305 };
306 
307 /******** GridField with array replication ********/
308 template<class Device, VarType VT, PhiInterpType PIT>
311  using device_type = Device;
312  static constexpr KinType KT = KinType::DriftKin;
313 
314  Kokkos::View<field_type**,Kokkos::LayoutRight,Device> f;
315 
317  GridField(std::string name, int nphi, int nrho, int nnode) : f(name,get_num_cpu_threads(), nnode) {}
318  GridField(std::string name, int nnode) : f(name,get_num_cpu_threads(), nnode) {}
319  field_type* data() const {return f.data();}
320  int size() const {return f.size();}
321  int nnode() const {return f.extent(1);}
322  int nrhop1() const {return 1;}
323  int nphi() const {return 1;}
324  KOKKOS_INLINE_FUNCTION bool is_allocated() const {return f.is_allocated();}
325  KOKKOS_INLINE_FUNCTION field_type& operator ()(int ithread, int inode) const {return f(ithread, inode);}
326 
327  // Scatter to a node
328  KOKKOS_INLINE_FUNCTION void scatter(int ithread, int node, const SimdPhiWeights<get_phi_wt_usage(PIT)>& phi_wts, int i_simd, double particle_weight) const{
329  f(ithread,node).scatter(phi_wts, i_simd, particle_weight);
330  }
331 
332  // Scatter to a triangle
333  KOKKOS_INLINE_FUNCTION void scatter(const Grid<DeviceType>& grid, int ithread, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, int i_simd, const SimdGyroWeights<DriftKin>& rho_wts, double particle_weight) const{
334  for (int j = 0; j<3; j++){
335  // Find triangle's nodes
336  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
337  double wp=grid_wts.p[j][i_simd];
338 
339  // Scatter to node
340  scatter(ithread, node, grid_wts.phi_wts, i_simd, wp*particle_weight);
341  }
342  }
343 
345  int ndoubles_in_grid_field = f.size()*field_type::SIZE();
346  Kokkos::View<double*,Kokkos::LayoutRight,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1d_double((double*)(f.data()), ndoubles_in_grid_field);
347  Kokkos::deep_copy(view_1d_double, 0.0);
348  }
349 };
350 
351 template<class Device, VarType VT, PhiInterpType PIT>
354  using device_type = Device;
355  static constexpr KinType KT = KinType::GyroKin;
356 
357  Kokkos::View<field_type***,Kokkos::LayoutRight,Device> f;
358 
360  GridField(std::string name, int nphi, int nrho, int nnode) : f(name,get_num_cpu_threads(),nnode, nrho+1) {}
361  GridField(std::string name, int nrho, int nnode) : f(name,get_num_cpu_threads(),nnode, nrho+1) {}
362  field_type* data() const {return f.data();}
363  int size() const {return f.size();}
364  int nnode() const {return f.extent(1);}
365  int nrhop1() const {return f.extent(2);}
366  int nphi() const {return 1;}
367  KOKKOS_INLINE_FUNCTION bool is_allocated() const {return f.is_allocated();}
368  KOKKOS_INLINE_FUNCTION field_type& operator ()(int ithread, int inode, int irho) const {return f(ithread,inode, irho);}
369 
370  // Scatter to a node
371  KOKKOS_INLINE_FUNCTION void scatter(int ithread, int node, const SimdPhiWeights<get_phi_wt_usage(PIT)>& phi_wts, const SimdGyroWeights<GyroKin>& rho_wts, int i_simd, double particle_weight) const{
372  int irho = rho_wts.irho(i_simd);
373  f(ithread,node,irho).scatter(rho_wts, phi_wts, i_simd, particle_weight, f(ithread,node,irho+1));
374  }
375 
376  // Scatter to a triangle (same as for DriftKin - consolidate)
377  KOKKOS_INLINE_FUNCTION void scatter(const Grid<DeviceType>& grid, int ithread, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, int i_simd, const SimdGyroWeights<GyroKin>& rho_wts, double particle_weight) const{
378  for (int j = 0; j<3; j++){
379  // Find triangle's nodes
380  int node=grid.get_node_index(grid_wts.itr[i_simd], j);
381  double wp=grid_wts.p[j][i_simd];
382 
383  // Scatter to node
384  scatter(ithread, node, grid_wts.phi_wts, rho_wts, i_simd, wp*particle_weight);
385  }
386  }
387 
389  int ndoubles_in_grid_field = f.size()*field_type::SIZE();
390  Kokkos::View<double*,Kokkos::LayoutRight,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1d_double((double*)(f.data()), ndoubles_in_grid_field);
391  Kokkos::deep_copy(view_1d_double, 0.0);
392  }
393 };
394 /************/
395 
396 template<class Device, VarType VT, PhiInterpType PIT>
399  using device_type = Device;
400  static constexpr KinType KT = KinType::DriftKin;
401 
402  Kokkos::View<field_type**,Kokkos::LayoutRight,Device> f;
403 
405  GridField(std::string name, int nphi, int nrho, int nnode) : f(name,nphi, nnode) {}
406  GridField(std::string name, int nphi, int nnode) : f(name,nphi, nnode) {}
407  field_type* data() const {return f.data();}
408  int size() const {return f.size();}
409  int nnode() const {return f.extent(1);}
410  int nrhop1() const {return 1;}
411  int nphi() const {return f.extent(0);}
412  KOKKOS_INLINE_FUNCTION bool is_allocated() const {return f.is_allocated();}
413  KOKKOS_INLINE_FUNCTION field_type& operator ()(int iphi, int inode) const {return f(iphi, inode);}
414 
417  new_field.f = my_subview(f, subfield_idx);
418  return new_field;
419  }
420 
421  Kokkos::View<double**,Kokkos::LayoutRight,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> unmanaged() const{
422  return Kokkos::View<double**,Kokkos::LayoutRight,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>>((double*)(f.data()), f.layout());
423  }
424 };
425 
426 template<class Device, VarType VT, PhiInterpType PIT>
429  using device_type = Device;
430  static constexpr KinType KT = KinType::GyroKin;
431 
432  Kokkos::View<field_type***,Kokkos::LayoutRight,Device> f;
433 
435  GridField(std::string name, int nphi, int nrho, int nnode) : f(name,nphi, nnode, nrho+1) {}
436  field_type* data() const {return f.data();}
437  int size() const {return f.size();}
438  int nnode() const {return f.extent(1);}
439  int nrhop1() const {return f.extent(2);}
440  int nphi() const {return f.extent(0);}
441  KOKKOS_INLINE_FUNCTION bool is_allocated() const {return f.is_allocated();}
442  KOKKOS_INLINE_FUNCTION field_type& operator ()(int iphi, int inode, int irho) const {return f(iphi, inode, irho);}
443 };
444 
445 // For convenience
457 
458 
459 // Shallow copy if types are the same
460 template<typename T>
461 inline void grid_field_copy(T& dest, const T& src){
462  dest = src;
463 }
464 
465 // Allocate dest grid_field and copy data from src
466 template<typename T1, typename T2>
467 inline void grid_field_copy(T1& dest, const T2& src){
468  // Allocate device array
469  dest = T1("grid_field",src.nphi(), src.nrhop1()-1, src.nnode());
470  // Deep copy from host to device
471  Kokkos::deep_copy(dest.f, src.f);
472 }
473 
474 #endif
static KOKKOS_INLINE_FUNCTION void view_odim_scatter(const Grid< DeviceType > &grid, const View< double **, CLayout, Device > &view, int ind, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, double val, int i_simd)
Definition: grid_field.hpp:212
GridField< DeviceType, VarType::Vector2D, PhiInterpType::None, TorType::OnePlane, KinType::GyroKin > Efield2DGyroType
Definition: grid_field.hpp:454
Simd< double > r
Definition: simd.hpp:150
GridField(std::string name, int nphi, int nrho, int nnode)
Definition: grid_field.hpp:34
static KOKKOS_INLINE_FUNCTION void view_gather3(const Grid< DeviceType > &grid, const View< double *, CLayout, Device > &view1, const View< double *, CLayout, Device > &view2, const View< double *, CLayout, Device > &view3, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, double &val1, double &val2, double &val3, int i_simd)
Definition: grid_field.hpp:153
Definition: simd.hpp:149
KOKKOS_INLINE_FUNCTION void scatter(const Grid< DeviceType > &grid, int ithread, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, int i_simd, const SimdGyroWeights< DriftKin > &rho_wts, double particle_weight) const
Definition: grid_field.hpp:333
GridField(std::string name, int nphi, int nrho, int nnode)
Definition: grid_field.hpp:405
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::MultiplePlanes, KinType::DriftKin > PotType
Definition: grid_field.hpp:451
KOKKOS_INLINE_FUNCTION bool is_allocated() const
Definition: grid_field.hpp:42
GridField(std::string name, int nrho, int nnode)
Definition: grid_field.hpp:273
void transpose_copy_to_double_view(const View< double **, CLayout, Device > &dest_view) const
Definition: grid_field.hpp:118
KOKKOS_INLINE_FUNCTION int irho(int i_simd) const
Definition: gyro_radius.hpp:109
KOKKOS_INLINE_FUNCTION bool is_allocated() const
Definition: grid_field.hpp:279
static KOKKOS_INLINE_FUNCTION void view_gyro_scatter3(const Grid< DeviceType > &grid, const View< double **, CLayout, Device > &view1, const View< double **, CLayout, Device > &view2, const View< double **, CLayout, Device > &view3, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, double val1, double val2, double val3, int i_simd, const LinearWeights &rho_wts, bool is_gyro)
Definition: grid_field.hpp:196
void scatter(const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const GridFieldPack< DeviceType, PIT > &gfpack, const Species< DeviceType > &species, bool exclude_private, bool do_cv_adjustment, bool cv_full_weight, const Charge< DeviceType, KT > &charge)
Definition: scatter.cpp:239
GridField(std::string name, int nrho, int nnode)
Definition: grid_field.hpp:361
void copy_to_double_view(const View< double *, CLayout, Device > &dest_view) const
Definition: grid_field.hpp:105
static KOKKOS_INLINE_FUNCTION void view_ff_scatter(const Grid< DeviceType > &grid, const View< double **, CLayout, Device > &view, const SimdGridWeights< Order::One, PhiInterpType::Planes > &grid_wts, double wphi, double val, int i_simd)
Definition: grid_field.hpp:230
Definition: linear_weights.hpp:8
Kokkos::View< field_type **, Kokkos::LayoutRight, Device > f
Definition: grid_field.hpp:269
Definition: globals.hpp:89
Definition: grid_weights.hpp:47
KOKKOS_INLINE_FUNCTION bool is_allocated() const
Definition: grid_field.hpp:412
GridField(std::string name, int nphi, int nnode)
Definition: grid_field.hpp:406
GridField(std::string name, int nnode)
Definition: grid_field.hpp:35
Kokkos::View< double **, Kokkos::LayoutRight, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > unmanaged() const
Definition: grid_field.hpp:421
View< double *, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > unmanaged() const
Definition: grid_field.hpp:112
GridField< DeviceType, VarType::Vector2D, PhiInterpType::None, TorType::MultiplePlanes, KinType::DriftKin > Efield2DType
Definition: grid_field.hpp:450
GridField< DeviceType, VarType::Vector, PhiInterpType::Planes, TorType::MultiplePlanes, KinType::DriftKin > EfieldType
Definition: grid_field.hpp:449
KOKKOS_INLINE_FUNCTION bool is_allocated() const
Definition: grid_field.hpp:324
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:68
GridField< DeviceType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > E00Type
Definition: grid_field.hpp:452
KOKKOS_INLINE_FUNCTION bool is_allocated() const
Definition: grid_field.hpp:441
constexpr KOKKOS_INLINE_FUNCTION PhiWtUsage get_phi_wt_usage(PhiInterpType PIT)
Definition: grid_weights.hpp:15
GridField(std::string name, int nphi, int nrho, int nnode)
Definition: grid_field.hpp:317
Definition: grid_field.hpp:22
KOKKOS_INLINE_FUNCTION void gather(const Grid< Device > &grid, const SimdGridWeights< Order::One, PhiInterpType::Planes > &grid_wts, const Simd< double > &phi, Simd< double > &fld) const
Definition: grid_field.hpp:80
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > AxisymPotType
Definition: grid_field.hpp:448
KOKKOS_INLINE_FUNCTION void scatter(const Grid< DeviceType > &grid, int ithread, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, int i_simd, const SimdGyroWeights< DriftKin > &rho_wts, double particle_weight) const
Definition: grid_field.hpp:51
Definition: grid_weights.hpp:18
TorType
Definition: grid_field.hpp:14
Definition: gyro_radius.hpp:116
KOKKOS_INLINE_FUNCTION void scatter(const Grid< DeviceType > &grid, int ithread, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, int i_simd, const SimdGyroWeights< GyroKin > &rho_wts, double particle_weight) const
Definition: grid_field.hpp:289
Definition: gyro_radius.hpp:84
Kokkos::View< field_type *, Kokkos::LayoutRight, Device > f
Definition: grid_field.hpp:31
KOKKOS_INLINE_FUNCTION void scatter(int ithread, int node, const SimdPhiWeights< get_phi_wt_usage(PIT)> &phi_wts, const SimdGyroWeights< GyroKin > &rho_wts, int i_simd, double particle_weight) const
Definition: grid_field.hpp:371
KOKKOS_INLINE_FUNCTION void access_add(T *addr, T val)
Definition: access_add.hpp:40
KOKKOS_INLINE_FUNCTION void scatter(int node, const SimdPhiWeights< get_phi_wt_usage(PIT)> &phi_wts, int i_simd, double particle_weight) const
Definition: grid_field.hpp:46
static KOKKOS_INLINE_FUNCTION void view_odim_variance(const Grid< DeviceType > &grid, const View< double **, CLayout, Device > &view, const View< double **, CLayout, Device > &variance, int ind, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, double val, int i_simd)
Definition: grid_field.hpp:240
void grid_field_copy(T &dest, const T &src)
Definition: grid_field.hpp:461
void transpose_copy_from_double_view(const View< double **, CLayout, Device > &src_view) const
Definition: grid_field.hpp:135
KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const
Definition: grid.tpp:158
GridField(std::string name, int nphi, int nrho, int nnode)
Definition: grid_field.hpp:272
KOKKOS_INLINE_FUNCTION void scatter(int ithread, int node, const SimdPhiWeights< get_phi_wt_usage(PIT)> &phi_wts, int i_simd, double particle_weight) const
Definition: grid_field.hpp:328
double w[2]
Definition: linear_weights.hpp:10
Definition: globals.hpp:90
GridField< DeviceType, VarType::Scalar, PhiInterpType::None, TorType::OnePlane, KinType::DriftKin > ScalarGridField
Definition: grid_field.hpp:446
GridField< Device, VT, PIT, TorType::OnePlane, KinType::DriftKin > subfield(int subfield_idx) const
Definition: grid_field.hpp:415
static KOKKOS_INLINE_FUNCTION void view_vec_odim_gather(const Grid< DeviceType > &grid, const View< Field< VarType::Vector, PhiInterpType::None > **, CLayout, Device > &view, int ind, const SimdGridWeights< Order::One, PhiInterpType::None > &grid_wts, SimdVector &val, int i_simd)
Definition: grid_field.hpp:176
static KOKKOS_INLINE_FUNCTION void view_scatter(const Grid< DeviceType > &grid, const View< double *, CLayout, Device > &view, const SimdGridWeights< Order::One, PhiInterpType::None > &grid_wts, double val, int i_simd)
Definition: grid_field.hpp:221
Simd< double > phi
Definition: simd.hpp:152
KOKKOS_INLINE_FUNCTION void gather(const Grid< Device > &grid, const SimdGridWeights< Order::One, PhiInterpType::None > &grid_wts, const Simd< double > &phi, Simd< double > &fld) const
Definition: grid_field.hpp:63
Simd< double > z
Definition: simd.hpp:151
int i
Definition: linear_weights.hpp:9
KinType
Definition: globals.hpp:88
Definition: field.hpp:45
Kokkos::View< field_type ***, Kokkos::LayoutRight, Device > f
Definition: grid_field.hpp:432
GridField< DeviceType, VarType::Vector2D, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > E00GyroType
Definition: grid_field.hpp:456
Kokkos::View< field_type **, Kokkos::LayoutRight, Device > f
Definition: grid_field.hpp:314
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
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::GyroKin > PotGyroType
Definition: grid_field.hpp:455
KOKKOS_INLINE_FUNCTION void scatter(int node, const SimdPhiWeights< get_phi_wt_usage(PIT)> &phi_wts, const SimdGyroWeights< GyroKin > &rho_wts, int i_simd, double particle_weight) const
Definition: grid_field.hpp:283
KOKKOS_INLINE_FUNCTION bool is_allocated() const
Definition: grid_field.hpp:367
int get_num_cpu_threads()
Definition: globals.hpp:17
Kokkos::View< field_type ***, Kokkos::LayoutRight, Device > f
Definition: grid_field.hpp:357
GridField(std::string name, int nphi, int nrho, int nnode)
Definition: grid_field.hpp:435
static KOKKOS_INLINE_FUNCTION void view_gather(const Grid< DeviceType > &grid, const View< double *, CLayout, Device > &view, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, Simd< double > &val)
Definition: grid_field.hpp:165
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
GridField< DeviceType, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KinType::DriftKin > OnePlanePotType
Definition: grid_field.hpp:447
KOKKOS_INLINE_FUNCTION void scatter(const Grid< DeviceType > &grid, int ithread, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, int i_simd, const SimdGyroWeights< GyroKin > &rho_wts, double particle_weight) const
Definition: grid_field.hpp:377
GridField< DeviceType, VarType::Vector, PhiInterpType::Planes, TorType::OnePlane, KinType::GyroKin > EfieldGyroType
Definition: grid_field.hpp:453
Kokkos::View< field_type **, Kokkos::LayoutRight, Device > f
Definition: grid_field.hpp:402
GridField(std::string name, int nphi, int nrho, int nnode)
Definition: grid_field.hpp:360
static KOKKOS_INLINE_FUNCTION void view_rep_scatter3(const Grid< DeviceType > &grid, const View< double ***, CLayout, Device > &view, int ind1, int ind2, int ind3, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, double val1, double val2, double val3, int ithread, int i_simd)
Definition: grid_field.hpp:250
static KOKKOS_INLINE_FUNCTION void view_vec_odim_gather(const Grid< DeviceType > &grid, const View< Field< VarType::Vector, PhiInterpType::None > **, CLayout, Device > &view, int ind, const SimdGridWeights< Order::Zero, PhiInterpType::None > &grid_wts, SimdVector &val, int i_simd)
Definition: grid_field.hpp:187