XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gradparx2.hpp
Go to the documentation of this file.
1 #ifndef GRADPARX2_HPP
2 #define GRADPARX2_HPP
3 
4 #include "globals.hpp"
5 #include "grid.hpp"
6 
7 struct rtype{
8  int start;
9  int end;
10 };
11 
12 class Boundary{
13  public:
14 
15  View<rtype*,CLayout,DeviceType> iseg;
16 
17  Boundary(int nseg, rtype* bd_fort)
18  : iseg(NoInit("iseg"),nseg)
19  {
20  array_deep_copy(iseg,bd_fort);
21  }
22 
30  KOKKOS_INLINE_FUNCTION bool is_inside(int i) const {
31  bool inside = true; // - the other way would be faster -- # of inside nodes > # of boundary nodes
32 
33  for (int is=0; is<iseg.size(); is++){
34  if( iseg(is).start <= i+1 && i+1 <= iseg(is).end ){
35  inside = false;
36  break;
37  }
38  }
39  return inside;
40  }
41 };
42 
43 struct GradParXTmp{
44  double sgn;
45  View<int**,CLayout,DeviceType> tr;
46  View<double***,CLayout,DeviceType> p;
47  View<double**,CLayout,DeviceType> dx;
48  View<bool*,CLayout,DeviceType> is_inside;
49 
51 
52  GradParXTmp(const Grid<DeviceType>& grid, int nseg, double sml_bt_sign, rtype* bd_fort)
53  : sgn(-(sml_bt_sign<0.0 ? -1.0 : 1.0)), // Reverse sign since negative gradient is desired
54  tr(NoInit("tr"),2,grid.nnode),
55  p(NoInit("p"),2,grid.nnode,3),
56  dx(NoInit("dx"),2,grid.nnode),
57  is_inside(NoInit("is_inside"),grid.nnode)
58 
59  {
60  Kokkos::deep_copy(tr,grid.one_plane_ff.tr);
61  Kokkos::deep_copy(p,grid.one_plane_ff.p);
62  Kokkos::deep_copy(dx,grid.one_plane_ff.dx);
63 
64  Boundary bd(nseg, bd_fort);
65 
66  // get is_inside for every node
68  }
69 
70  // For testing - set is_insde=.true.
71  GradParXTmp(const Grid<DeviceType>& grid, double sml_bt_sign)
72  : sgn(-(sml_bt_sign<0.0 ? -1.0 : 1.0)), // Reverse sign since negative gradient is desired
73  tr(NoInit("tr"),2,grid.nnode),
74  p(NoInit("p"),2,grid.nnode,3),
75  dx(NoInit("dx"),2,grid.nnode),
76  is_inside(NoInit("is_inside"),grid.nnode)
77 
78  {
79  Kokkos::deep_copy(tr,grid.one_plane_ff.tr);
80  Kokkos::deep_copy(p,grid.one_plane_ff.p);
81  Kokkos::deep_copy(dx,grid.one_plane_ff.dx);
82 
83  // Assume all nodes are inside
84  Kokkos::deep_copy(is_inside, true);
85  }
86 
87  void set_is_inside(const Boundary& bd, const View<bool*,CLayout,DeviceType>& is_inside_local){
88  Kokkos::parallel_for("gradparx2", Kokkos::RangePolicy<ExSpace>(0,is_inside_local.extent(0)), KOKKOS_LAMBDA( const int i ){
89  is_inside_local(i) = bd.is_inside(i);
90  });
91  }
92 };
93 
94 void negative_gradparx2(const Grid<DeviceType>& grid, const GradParXTmp& gptx, const View<double**,CLayout,DeviceType>& input, const View<double**,CLayout,DeviceType>& output);
95 
96 #endif
Projection< HostType > one_plane_ff
Definition: grid.hpp:290
void array_deep_copy(T *array, const Kokkos::View< T *, Kokkos::LayoutRight, Device > &view)
Definition: array_deep_copy.hpp:11
View< int **, CLayout, DeviceType > tr
Definition: gradparx2.hpp:45
Definition: gradparx2.hpp:7
KOKKOS_INLINE_FUNCTION bool is_inside(int i) const
Definition: gradparx2.hpp:30
int end
Definition: gradparx2.hpp:9
void set_is_inside(const Boundary &bd, const View< bool *, CLayout, DeviceType > &is_inside_local)
Definition: gradparx2.hpp:87
View< double **, CLayout, DeviceType > dx
Definition: gradparx2.hpp:47
GradParXTmp()
Definition: gradparx2.hpp:50
double sgn
Definition: gradparx2.hpp:44
Definition: gradparx2.hpp:43
GradParXTmp(const Grid< DeviceType > &grid, int nseg, double sml_bt_sign, rtype *bd_fort)
Definition: gradparx2.hpp:52
GradParXTmp(const Grid< DeviceType > &grid, double sml_bt_sign)
Definition: gradparx2.hpp:71
View< bool *, CLayout, DeviceType > is_inside
Definition: gradparx2.hpp:48
View< double ***, CLayout, Device > p
Definition: grid.hpp:54
Definition: gradparx2.hpp:12
View< rtype *, CLayout, DeviceType > iseg
Definition: gradparx2.hpp:15
View< double ***, CLayout, DeviceType > p
Definition: gradparx2.hpp:46
void negative_gradparx2(const Grid< DeviceType > &grid, const GradParXTmp &gpxt, const Kokkos::View< double **, Kokkos::LayoutRight, DeviceType > &input, const Kokkos::View< double **, Kokkos::LayoutRight, DeviceType > &output)
Definition: gradparx2.cpp:23
View< int **, CLayout, Device > tr
Definition: grid.hpp:53
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
Boundary(int nseg, rtype *bd_fort)
Definition: gradparx2.hpp:17
int start
Definition: gradparx2.hpp:8
View< double **, CLayout, Device > dx
Definition: grid.hpp:55
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68