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 #include "vertex_list.hpp"
6 #include "grid.hpp"
7 
9  double in_bd_psi;
10  double out_bd_psi;
14  bool excl_inner;
15  bool excl_outer;
18  bool excl_wall;
20 
21  void extend(double inner_ext, double outer_ext){
22  in_bd_psi += inner_ext;
23  out_bd_psi -= outer_ext;
24  out_bd_psi_priv1 += outer_ext;
25  out_bd_psi_priv2 += outer_ext;
26  }
27 };
28 
29 static KOKKOS_INLINE_FUNCTION bool exclude_node(const MagneticField<DeviceType>& magnetic_field, const Grid<DeviceType>& grid,
30  const View<int*,CLayout,DeviceType>& num_t_node, const View<int**,CLayout,DeviceType>& tr_node,
31  const BoundarySettings& s, int i){
32  constexpr double epsilon = 1.0e-8;
33  if(s.excl_inner && grid.psi(i) - epsilon < s.in_bd_psi) return true;
34 
35  if(s.excl_outer && grid.psi(i) > s.out_bd_psi) return true;
36 
37  double r,z;
38  grid.get_rz_coordinates(i, r, z);
39 
40  if((s.excl_private
41  || (grid.psi(i) < s.out_bd_psi_priv1 && z < magnetic_field.equil.xpt.z )
42  || (grid.psi(i) < s.out_bd_psi_priv2 && z > magnetic_field.equil.xpt2.z && magnetic_field.equil.set_xpt2) )
43  && !grid.node_is_in_region_1_or_2_no_wall(i) ) return true;
44 
45  // Use this condition only if the private region is also excluded
46  constexpr double epsilon2 = 1.0e-5;
47  if(s.excl_sep_leg
48  && (grid.node_is_in_region_1_or_2_no_wall(i) && grid.node_is_in_region_2_or_3_no_wall(i)) // is_in_region_2
49  && (-(r-magnetic_field.equil.xpt.r)*magnetic_field.equil.xpt_slope + (z-magnetic_field.equil.xpt.z) < 0.0)
50  && (grid.psi(i) < (magnetic_field.equil.xpt_psi*(1.0 + epsilon2)))) return true;
51 
52  if(s.excl_near_wall){
53  // check if i-node is connected to wall
54  for (int j=0; j<num_t_node(i); j++){
55  int itr = tr_node(j,i) + 1;
56  for(int ip=0; ip<3; ip++){
57  int i_nd = grid.get_node_index(itr, ip);
58  if(grid.midplane.node_is_on_wall(i_nd)) return true;
59  }
60  }
61 #ifndef XGCA
62  // check if i-node is near wall (bd_ext_near_wall)
63  if(s.bd_ext_near_wall>0.0){
64  for(int j=0; j<grid.nwall; j++){
65  RZPair x2 = grid.get_wall_rz(j);
66  double dist = grid.midplane.get_dist2_from_node(i, x2.r, x2.z);
67  if(dist < s.bd_ext_near_wall*s.bd_ext_near_wall){
68  return true;
69  }
70  }
71  }
72 #endif
73  } else if(s.excl_wall && grid.midplane.node_is_on_wall(i)) return true;
74 
75  return false;
76 }
77 
78 inline VertexList get_excluded_vertex_list(const MagneticField<DeviceType>& magnetic_field, const Grid<DeviceType>& grid, const View<int*,CLayout,DeviceType>& num_t_node, const View<int**,CLayout,DeviceType>& tr_node, const BoundarySettings& settings){
79  // Create vertex list that excludes the boundary
80  return VertexList(grid.nnode, KOKKOS_LAMBDA(const int i){
81  return exclude_node(magnetic_field, grid, num_t_node, tr_node, settings, i);
82  });
83 }
84 
85 class Boundary : public VertexList{
86 
87  public:
88 
90 
91  Boundary(const MagneticField<DeviceType>& magnetic_field, const Grid<DeviceType>& grid, const View<int*,CLayout,DeviceType>& num_t_node, const View<int**,CLayout,DeviceType>& tr_node, const BoundarySettings& settings)
92  : VertexList(get_excluded_vertex_list(magnetic_field, grid, num_t_node, tr_node, settings)){}
93 };
94 
95 #endif
KOKKOS_INLINE_FUNCTION RZPair get_wall_rz(int i_wall) const
Definition: grid.tpp:294
VertexList get_excluded_vertex_list(const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, const View< int *, CLayout, DeviceType > &num_t_node, const View< int **, CLayout, DeviceType > &tr_node, const BoundarySettings &settings)
Definition: boundary.hpp:78
double out_bd_psi_priv1
Definition: boundary.hpp:11
RZPair xpt2
coordinates of 2nd X-point
Definition: equil.hpp:93
Definition: magnetic_field.hpp:12
Equilibrium equil
The object containing information about the magnetic equilibrium.
Definition: magnetic_field.hpp:44
bool excl_sep_leg
Definition: boundary.hpp:19
double out_bd_psi_priv2
Definition: boundary.hpp:12
double z
Definition: grid_structs.hpp:30
int nwall
Definition: grid.hpp:164
Definition: grid_structs.hpp:28
bool set_xpt2
Whether to use a 2nd X-point.
Definition: equil.hpp:92
Definition: boundary.hpp:85
bool excl_wall
Definition: boundary.hpp:18
bool excl_near_wall
Definition: boundary.hpp:17
bool excl_private
Definition: boundary.hpp:16
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi
An array of psi coordinates.
Definition: grid.hpp:170
KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const int inode, double &r, double &z) const
Definition: grid.tpp:284
Definition: boundary.hpp:8
Boundary()
Definition: boundary.hpp:89
KOKKOS_INLINE_FUNCTION bool node_is_on_wall(const int inode) const
Definition: plane.tpp:816
KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const
Definition: grid.tpp:158
double out_bd_psi
Definition: boundary.hpp:10
double in_bd_psi
Definition: boundary.hpp:9
void extend(double inner_ext, double outer_ext)
Definition: boundary.hpp:21
double xpt_slope
Slope (which slope?) at 1st X-point.
Definition: equil.hpp:91
KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2_no_wall(const int inode) const
Definition: grid.tpp:202
bool excl_inner
Definition: boundary.hpp:14
RZPair xpt
coordinates of 1st X-point
Definition: equil.hpp:90
double r
Definition: grid_structs.hpp:29
Definition: magnetic_field.F90:1
Definition: vertex_list.hpp:53
bool excl_outer
Definition: boundary.hpp:15
Boundary(const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, const View< int *, CLayout, DeviceType > &num_t_node, const View< int **, CLayout, DeviceType > &tr_node, const BoundarySettings &settings)
Definition: boundary.hpp:91
static KOKKOS_INLINE_FUNCTION bool exclude_node(const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, const View< int *, CLayout, DeviceType > &num_t_node, const View< int **, CLayout, DeviceType > &tr_node, const BoundarySettings &s, int i)
Definition: boundary.hpp:29
Plane< Device > midplane
Definition: grid.hpp:154
int nnode
Number of grid nodes.
Definition: grid.hpp:159
KOKKOS_INLINE_FUNCTION double get_dist2_from_node(const int inode, const double r, const double z) const
Definition: plane.tpp:886
KOKKOS_INLINE_FUNCTION bool node_is_in_region_2_or_3_no_wall(const int inode) const
Definition: grid.tpp:207
double xpt_psi
Psi coordinate of 1st X-point.
Definition: equil.hpp:87
double bd_ext_near_wall
Definition: boundary.hpp:13