XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
grid_node_tr_mapping.hpp
Go to the documentation of this file.
1 #ifndef GRID_NODE_TR_MAPPING_HPP
2 #define GRID_NODE_TR_MAPPING_HPP
3 
4 template<class Device>
5 void grid_node_tr_mapping(const Grid<Device>& grid, View<int*,CLayout,Device>& num_t_node, View<int**,CLayout,Device>& tr_node){
6  // First, get the number of triangles that each node touches
7  Kokkos::parallel_for("num_t_node_calc", Kokkos::RangePolicy<typename Device::execution_space>( 0,grid.ntriangle ), KOKKOS_LAMBDA( const int j){
8  for(int k=0; k<3; k++){
9  int ind = grid.get_node_index(j+1, k); // node tri is 1-indexed
10  Kokkos::atomic_add(&(num_t_node(ind)), 1);
11  }
12  });
13 
14  // Then, determine the max number of triangles touched by a single node
15  int maxnum=0;
16  Kokkos::parallel_reduce("max_num_t_node", Kokkos::RangePolicy<typename Device::execution_space>( 0,grid.nnode ), KOKKOS_LAMBDA( const int i_node, int& maxnum_l){
17  maxnum_l = max(maxnum_l, num_t_node(i_node));
18  }, Kokkos::Max<int,HostType>(maxnum));
19 
20  // Allocate the mapping array and reset num_t_node
21  tr_node = View<int**,CLayout,Device>("tr_node",maxnum,grid.nnode);
22  Kokkos::deep_copy(num_t_node, 0);
23 
24  // Populate mapping array while redoing num_t_node
25  Kokkos::parallel_for("tr_node_calc", Kokkos::RangePolicy<typename Device::execution_space>( 0,grid.ntriangle ), KOKKOS_LAMBDA( const int j){
26  for(int k=0; k<3; k++){
27  int ind = grid.get_node_index(j+1, k); // grid tri is 1-indexed
28  // Assign tr_node mapping and add to num_t_node
29  int local_place = Kokkos::atomic_fetch_add(&(num_t_node(ind)),1);
30  tr_node(local_place,ind)=j;
31  }
32  });
33 }
34 
35 #endif
int ntriangle
Number of grid triangles.
Definition: grid.hpp:270
Definition: grid.hpp:67
void grid_node_tr_mapping(const Grid< Device > &grid, View< int *, CLayout, Device > &num_t_node, View< int **, CLayout, Device > &tr_node)
Definition: grid_node_tr_mapping.hpp:5
KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const
Definition: grid.tpp:891
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 nnode
Number of grid nodes.
Definition: grid.hpp:271