omega_h
Reliable mesh adaptation
Omega_h_adj.hpp
1 #ifndef OMEGA_H_ADJ_HPP
2 #define OMEGA_H_ADJ_HPP
3 
4 #include <Omega_h_few.hpp>
5 #include <Omega_h_graph.hpp>
6 #include <Omega_h_matrix.hpp>
7 #include <Omega_h_vector.hpp>
8 
9 namespace Omega_h {
10 
11 struct Adj : public Graph {
12  OMEGA_H_INLINE Adj() {}
13  explicit Adj(LOs ab2b_) : Graph(ab2b_) {}
14  Adj(LOs ab2b_, Read<I8> codes_) : Graph(ab2b_), codes(codes_) {}
15  Adj(LOs a2ab_, LOs ab2b_, Read<I8> codes_)
16  : Graph(a2ab_, ab2b_), codes(codes_) {}
17  Adj(LOs a2ab_, LOs ab2b_) : Graph(a2ab_, ab2b_) {}
18  Adj(Graph g) : Graph(g) {}
19  Read<I8> codes;
20 };
21 
22 struct Parents {
23  OMEGA_H_INLINE Parents() {}
24  Parents(LOs parent_idx_, Read<I8> codes_)
25  : parent_idx(parent_idx_), codes(codes_) {}
26  LOs parent_idx;
27  Read<I8> codes;
28 };
29 
30 struct Children : public Graph {
31  OMEGA_H_INLINE Children() {}
32  Children(LOs a2ab_, LOs ab2b_, Read<I8> codes_)
33  : Graph(a2ab_, ab2b_), codes(codes_) {}
34  Read<I8> codes;
35 };
36 
37 void find_matches(Omega_h_Family const family, Int const dim, LOs const av2v,
38  LOs const bv2v, Adj const v2b, Write<LO>* a2b_out, Write<I8>* codes_out);
39 
40 void find_matches(Topo_type const ent_type, LOs const av2v,
41  LOs const bv2v, Adj const v2b, Write<LO>* a2b_out, Write<I8>* codes_out);
42 
43 Adj reflect_down(LOs const hv2v, LOs const lv2v, Adj const v2l,
44  Omega_h_Family const family, Int const high_dim, Int const low_dim);
45 
46 Adj reflect_down(LOs const hv2v, LOs const lv2v, Adj const v2l,
47  Topo_type const high_type, Topo_type const low_type);
48 
49 Adj unmap_adjacency(LOs const a2b, Adj const b2c);
50 
51 /* Given a downward adjacency, derive its corresponding upward adjacency.
52  The list of upward adjacent entities will be sorted by the local
53  index of the upward adjacent entity */
54 Adj invert_adj(Adj const down, Int const nlows_per_high, LO const nlows,
55  Int const high_dim, Int const low_dim);
56 
57 Adj invert_adj(Adj const down, Int const nlows_per_high, LO const nlows,
58  Topo_type high_type, Topo_type low_type);
59 
60 Children invert_parents(Parents const children2parents, Int const parent_dim,
61  Int const nparent_dim_ents);
62 
63 /* given the vertex lists for high entities,
64  create vertex lists for all uses of low
65  entities by high entities */
66 LOs form_uses(LOs const hv2v, Omega_h_Family const family, Int const high_dim,
67  Int const low_dim);
68 
69 LOs form_uses(LOs const hv2v, Topo_type const high_type, Topo_type const low_type);
70 
71 LOs find_unique(LOs const hv2v, Omega_h_Family const family, Int const high_dim,
72  Int const low_dim);
73 
74 /* find_unique if not used for mixed till now because
75  multiple down adjs from and below face2edge will be created.
76  If found a way to efficiently combine these, build from elems2verts
77  can be written
78 */
79 LOs find_unique(LOs const hv2v, Topo_type const high_type, Topo_type const low_type);
80 
81 /* for each entity (or entity use), sort its vertex list
82  and express the sorting transformation as an alignment code */
83 template <typename T>
84 Read<I8> get_codes_to_canonical(Int const deg, Read<T> const ev2v);
85 
86 Read<I8> find_canonical_jumps(
87  Int const deg, LOs const canon, LOs const e_sorted2e);
88 
89 /* given entity uses and unique entities,
90  both defined by vertex lists, match
91  uses to unique entities and derive their
92  respective alignment codes.
93 
94  even though this is a downward adjacency, we'll
95  define the code as describing how to transform
96  the boundary entity into the entity use,
97  since typically data is being pulled into an element
98  from its boundary
99 */
100 template <typename T>
101 void find_matches_ex(Int const deg, LOs const a2fv, Read<T> const av2v,
102  Read<T> const bv2v, Adj const v2b, Write<LO>* a2b_out, Write<I8>* codes_out,
103  bool const allow_duplicates = false);
104 
105 /* for testing only, internally computes upward
106  adjacency */
107 Adj reflect_down(LOs const hv2v, LOs const lv2v, Omega_h_Family const family,
108  LO const nv, Int const high_dim, Int const low_dim);
109 
110 Adj transit(Adj const h2m, Adj const m2l, Omega_h_Family const family,
111  Int const high_dim, Int const low_dim);
112 
113 Adj transit(Adj const h2m, Adj const m2l, Topo_type const high_type,
114  Topo_type const low_type, Topo_type const mid_type);
115 
116 Graph verts_across_edges(Adj const e2v, Adj const v2e);
117 Graph edges_across_tris(Adj const f2e, Adj const e2f);
118 Graph edges_across_tets(Adj const r2e, Adj const e2r);
119 Graph elements_across_sides(Int const dim, Adj const elems2sides,
120  Adj const sides2elems, Read<I8> const side_is_exposed);
121 
122 template <Int nhhl>
123 OMEGA_H_DEVICE Few<LO, nhhl> gather_down(LOs const& hl2l, Int h) {
124  Few<LO, nhhl> hhl2l;
125  for (Int i = 0; i < nhhl; ++i) {
126  auto hl = h * nhhl + i;
127  hhl2l[i] = hl2l[hl];
128  }
129  return hhl2l;
130 }
131 
132 template <Int neev>
133 OMEGA_H_DEVICE Few<LO, neev> gather_verts(LOs const& ev2v, Int e) {
134  return gather_down<neev>(ev2v, e);
135 }
136 
137 template <Int neev, typename T>
138 OMEGA_H_DEVICE Few<T, neev> gather_values(Read<T> const& a, Few<LO, neev> v) {
139  Few<T, neev> x;
140  for (Int i = 0; i < neev; ++i) x[i] = a[v[i]];
141  return x;
142 }
143 
144 template <Int neev>
145 OMEGA_H_DEVICE Vector<neev> gather_scalars(
146  Read<Real> const& a, Few<LO, neev> v) {
147  Vector<neev> x;
148  for (Int i = 0; i < neev; ++i) x[i] = a[v[i]];
149  return x;
150 }
151 
152 template <Int neev, Int dim>
153 OMEGA_H_DEVICE Matrix<dim, neev> gather_vectors(
154  Reals const& a, Few<LO, neev> v) {
155  Matrix<dim, neev> x;
156  for (Int i = 0; i < neev; ++i) x[i] = get_vector<dim>(a, v[i]);
157  return x;
158 }
159 
160 template <Int neev, Int dim>
161 OMEGA_H_DEVICE Few<Matrix<dim, dim>, neev> gather_symms(
162  Reals const& a, Few<LO, neev> v) {
163  Few<Matrix<dim, dim>, neev> x;
164  for (Int i = 0; i < neev; ++i) x[i] = get_symm<dim>(a, v[i]);
165  return x;
166 }
167 
168 #define INST_DECL(T) \
169  extern template Read<I8> get_codes_to_canonical(Int deg, Read<T> ev2v); \
170  extern template void find_matches_ex(Int deg, LOs a2fv, Read<T> av2v, \
171  Read<T> bv2v, Adj v2b, Write<LO>* a2b_out, Write<I8>* codes_out, bool);
172 INST_DECL(LO)
173 INST_DECL(GO)
174 #undef INST_DECL
175 
176 } // end namespace Omega_h
177 
178 #endif
Definition: Omega_h_few.hpp:61
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_adj.hpp:11
Definition: Omega_h_adj.hpp:30
directed graph (as defined by graph theory) in compressed row format
Definition: Omega_h_graph.hpp:22
Definition: Omega_h_adj.hpp:22