XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
boundary.hpp
Go to the documentation of this file.
1 #ifndef BOUNDARY_HPP
2 #define BOUNDARY_HPP
3 
4 #include "field.hpp"
5 
6 struct rtype{
7  int start;
8  int end;
9 };
10 
11 template<class Device>
12 class Boundary{
13 
14  using exspace = typename Device::execution_space;
15 
16  public:
17 
18  View<rtype*,CLayout,Device> iseg;
19 
20  // Initialize by copying from a fortran pointer
21  Boundary(int nseg, rtype* bd_fort)
22  : iseg(NoInit("iseg"),nseg)
23  {
24  array_deep_copy(iseg,bd_fort);
25  }
26 
34  KOKKOS_INLINE_FUNCTION bool is_inside(int i) const {
35  bool inside = true; // - the other way would be faster -- # of inside nodes > # of boundary nodes
36 
37  for (int is=0; is<iseg.size(); is++){
38  if( iseg(is).start <= i+1 && i+1 <= iseg(is).end ){
39  inside = false;
40  break;
41  }
42  }
43  return inside;
44  }
45 
46  // Note: this only works for Device==HostType right now
47  void set_to_value(const View<double*,CLayout,Device>& view, double value) const{
48  for (int is=0; is<iseg.size(); is++){
49  Kokkos::parallel_for("get_tr_vol_and_area", Kokkos::RangePolicy<exspace>( iseg(is).start-1, iseg(is).end), KOKKOS_LAMBDA( const int i){
50  view(i) = value;
51  });
52  }
53  Kokkos::fence();
54  }
55 
56  // Note: this only works for Device==HostType right now
57  // Set to value but for Field rather than double view
58  void set_to_value(const View<Field<VarType::Scalar,PhiInterpType::None>*,CLayout,Device>& view, double value) const{
59  for (int is=0; is<iseg.size(); is++){
60  Kokkos::parallel_for("get_tr_vol_and_area", Kokkos::RangePolicy<exspace>( iseg(is).start-1, iseg(is).end), KOKKOS_LAMBDA( const int i){
61  view(i).S = value;
62  });
63  }
64  Kokkos::fence();
65  }
66 };
67 
68 #endif
void array_deep_copy(T *array, const Kokkos::View< T *, Kokkos::LayoutRight, Device > &view)
Definition: array_deep_copy.hpp:11
Definition: boundary.hpp:6
int end
Definition: boundary.hpp:8
void set_to_value(const View< Field< VarType::Scalar, PhiInterpType::None > *, CLayout, Device > &view, double value) const
Definition: boundary.hpp:58
KOKKOS_INLINE_FUNCTION bool is_inside(int i) const
Definition: boundary.hpp:34
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:67
void set_to_value(const View< double *, CLayout, Device > &view, double value) const
Definition: boundary.hpp:47
Definition: boundary.hpp:12
typename Device::execution_space exspace
Use execution space where views are allocated.
Definition: boundary.hpp:14
Boundary(int nseg, rtype *bd_fort)
Definition: boundary.hpp:21
View< rtype *, CLayout, Device > iseg
Definition: boundary.hpp:18
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
int start
Definition: boundary.hpp:7
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68