Interface Documentation
Version: invalid
utils.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Los Alamos National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include "flecsi/util/common.hh"
20 #include <flecsi/flog.hh>
21 
22 #include <vector>
23 
24 namespace flecsi {
25 namespace topo {
26 
27 template<size_t I, class T, size_t DIM, size_t DOM>
28 struct find_entity {
29 
40  static constexpr size_t find() {
41  // grab current types
42  using E = typename std::tuple_element<I - 1, T>::type;
43  using D1 = typename std::tuple_element<1, E>::type;
44  using T1 = typename std::tuple_element<2, E>::type;
45 
46  // Check match for domain and dimension and return
47  // index if matched or recurse if not matched.
48  return D1::value == DOM && T1::dimension == DIM
49  ? I
51  }
52 
53 }; // find_entity
54 
55 //-----------------------------------------------------------------//
58 //-----------------------------------------------------------------//
59 
60 template<class T, size_t DIM, size_t DOM>
61 struct find_entity<0, T, DIM, DOM> {
62 
71  static constexpr size_t find() {
72  return 1;
73  } // find
74 
75 }; // struct find_entity
76 
77 //-----------------------------------------------------------------//
83 //-----------------------------------------------------------------//
84 
85 template<class MESH_TYPE, size_t DIM, size_t DOM>
86 struct find_entity_ {
87 
88  using entity_types = typename MESH_TYPE::entity_types;
89 
90  using pair_ = typename std::tuple_element<
92  find() -
93  1,
94  entity_types>::type;
95 
102 };
103 
104 template<size_t INDEX, class TUPLE, class ENTITY>
106 
107  //--------------------------------------------------------------------------//
110  //--------------------------------------------------------------------------//
111 
112  //--------------------------------------------------------------------------//
119  //--------------------------------------------------------------------------//
120 
121  static constexpr size_t find() {
122  // grab current types
123  using TUPLE_ELEMENT = typename std::tuple_element<INDEX - 1, TUPLE>::type;
124  using INDEX_SPACE = typename std::tuple_element<0, TUPLE_ELEMENT>::type;
125  using ELEMENT_ENTITY = typename std::tuple_element<2, TUPLE_ELEMENT>::type;
126 
127  // Check match for domain and dimension and return
128  // index if matched or recurse if not matched.
129  return std::is_same<ELEMENT_ENTITY, ENTITY>::value
130  ? INDEX_SPACE::value
132  }
133 
134 }; // find_index_space
135 
136 //-----------------------------------------------------------------//
139 //-----------------------------------------------------------------//
140 
141 template<class TUPLE, class ENTITY>
142 struct find_index_space<0, TUPLE, ENTITY> {
143 
144  //-----------------------------------------------------------------//
150  //-----------------------------------------------------------------//
151  static constexpr size_t find() {
152  assert(false && "failed to find index space");
153  return 1;
154  } // find_from
155 
156 }; // struct find_index_space
157 
158 //----------------------------------------------------------------------------//
159 //----------------------------------------------------------------------------//
160 
161 template<size_t INDEX, typename TUPLE, size_t DIM, size_t DOM>
163  //--------------------------------------------------------------------------//
170  //--------------------------------------------------------------------------//
171 
172  static constexpr size_t find() {
173  // grab current types
174  using TUPLE_ELEMENT = typename std::tuple_element<INDEX - 1, TUPLE>::type;
175  using INDEX_SPACE = typename std::tuple_element<0, TUPLE_ELEMENT>::type;
176  using ENTITY_DOMAIN = typename std::tuple_element<1, TUPLE_ELEMENT>::type;
177  using ELEMENT_ENTITY = typename std::tuple_element<2, TUPLE_ELEMENT>::type;
178 
179  // Check match for dimension and return if matched, recurse otherwise.
180  return (DIM == ELEMENT_ENTITY::dimension && DOM == ENTITY_DOMAIN::value)
181  ? INDEX_SPACE::value
183  find();
184  } // find
185 
186 }; // find_index_space_from_dimension
187 
188 //----------------------------------------------------------------------------//
190 //----------------------------------------------------------------------------//
191 
192 template<typename TUPLE, size_t DIM, size_t DOM>
193 struct find_index_space_from_dimension<0, TUPLE, DIM, DOM> {
194 
195  //--------------------------------------------------------------------------//
197  //--------------------------------------------------------------------------//
198 
199  static constexpr size_t find() {
200  return 1;
201  } // find
202 
203 }; // struct find_index_space_from_dimension
204 
205 //----------------------------------------------------------------------------//
206 //----------------------------------------------------------------------------//
207 
208 template<size_t INDEX, typename TUPLE, size_t ID>
210  //--------------------------------------------------------------------------//
217  //--------------------------------------------------------------------------//
218 
219  static constexpr size_t find() {
220  // grab current types
221  using TUPLE_ELEMENT = typename std::tuple_element<INDEX - 1, TUPLE>::type;
222  using INDEX_SPACE = typename std::tuple_element<0, TUPLE_ELEMENT>::type;
223 
224  // Check match for ID and return if matched, recurse otherwise.
225  return ID == INDEX_SPACE::value
226  ? INDEX - 1
228  } // find
229 
230 }; // find_index_space_from_id
231 
232 //----------------------------------------------------------------------------//
234 //----------------------------------------------------------------------------//
235 
236 template<typename TUPLE, size_t ID>
237 struct find_index_space_from_id<0, TUPLE, ID> {
238 
239  //--------------------------------------------------------------------------//
241  //--------------------------------------------------------------------------//
242 
243  static constexpr size_t find() {
244  assert(false && "failed to find index space");
245  // why return -1 when size_t unsigned?
246  return -1;
247  } // find
248 
249 }; // struct find_index_space_from_id
250 
251 //----------------------------------------------------------------------------//
252 //----------------------------------------------------------------------------//
253 
254 template<size_t INDEX, typename TUPLE, size_t ID>
256  //--------------------------------------------------------------------------//
263  //--------------------------------------------------------------------------//
264 
265  static constexpr size_t find() {
266  // grab current types
267  using TUPLE_ELEMENT = typename std::tuple_element<INDEX - 1, TUPLE>::type;
268  using INDEX_SUBSPACE = typename std::tuple_element<1, TUPLE_ELEMENT>::type;
269 
270  // Check match for ID and return if matched, recurse otherwise.
271  return ID == INDEX_SUBSPACE::value
272  ? INDEX - 1
274  } // find
275 
276 }; // find_index_subspace_from_id
277 
278 //----------------------------------------------------------------------------//
280 //----------------------------------------------------------------------------//
281 
282 template<typename TUPLE, size_t ID>
283 struct find_index_subspace_from_id<0, TUPLE, ID> {
284 
285  //--------------------------------------------------------------------------//
287  //--------------------------------------------------------------------------//
288 
289  static constexpr size_t find() {
290  return -1;
291  } // find
292 
293 }; // struct find_index_subspace_from_id
294 
295 //----------------------------------------------------------------------------//
302 //----------------------------------------------------------------------------//
304 namespace detail {
305 
306 template<size_t I,
307  typename MESH_TYPE,
308  size_t DOM,
309  typename Array,
310  std::enable_if_t<(I == MESH_TYPE::num_dimensions)> * = nullptr>
311 void
312 find_all_index_spaces_in_domain(Array && index_spaces) {
313  std::forward<Array>(index_spaces)[I] = find_index_space_from_dimension<
314  std::tuple_size<typename MESH_TYPE::entity_types>::value,
315  typename MESH_TYPE::entity_types,
316  I,
317  DOM>::find();
318 }
319 
320 template<size_t I,
321  typename MESH_TYPE,
322  size_t DOM,
323  typename Array,
324  typename = std::enable_if_t<(
325  I<MESH_TYPE::num_dimensions && MESH_TYPE::num_dimensions> 0)>>
326 void
327 find_all_index_spaces_in_domain(Array && index_spaces) {
328  std::forward<Array>(index_spaces)[I] = find_index_space_from_dimension<
329  std::tuple_size<typename MESH_TYPE::entity_types>::value,
330  typename MESH_TYPE::entity_types,
331  I,
332  DOM>::find();
333  find_all_index_spaces_in_domain<I + 1, MESH_TYPE, DOM>(index_spaces);
334 }
335 
336 } // namespace detail
337 
338 // The main calling function
339 template<typename MESH_TYPE, size_t DOM>
340 auto
341 find_all_index_spaces_in_domain() {
342  std::array<size_t, MESH_TYPE::num_dimensions + 1> index_spaces;
343  detail::find_all_index_spaces_in_domain<0, MESH_TYPE, DOM>(index_spaces);
344  return index_spaces;
345 }
347 
348 /*----------------------------------------------------------------------------*
349  * Connectivity utilities.
350  *----------------------------------------------------------------------------*/
351 
352 //-----------------------------------------------------------------//
356 //-----------------------------------------------------------------//
357 template<size_t FIND_DOM, size_t I, class TS>
359  //-----------------------------------------------------------------//
365  //-----------------------------------------------------------------//
366  template<class DOM>
367  static int compute(DOM & mesh) {
368  static constexpr size_t size = std::tuple_size<TS>::value;
369 
370  using T = typename std::tuple_element<size - I, TS>::type;
371  using D1 = typename std::tuple_element<1, T>::type;
372  using T1 = typename std::tuple_element<2, T>::type;
373  using T2 = typename std::tuple_element<3, T>::type;
374 
375  if(D1::value == FIND_DOM) {
376  mesh.template compute_connectivity<FIND_DOM,
377  T1::dimension,
378  T2::dimension>();
379  }
380 
382  } // compute
383 
384 }; // struct compute_connectivity
385 
386 //-----------------------------------------------------------------//
390 //-----------------------------------------------------------------//
391 template<size_t FIND_DOM, class TS>
392 struct compute_connectivity<FIND_DOM, 0, TS> {
393  //-----------------------------------------------------------------//
398  //-----------------------------------------------------------------//
399  template<class DOM>
400  static int compute(DOM &) {
401  return 0;
402  } // compute
403 
404 }; // struct compute_connectivity
405 
406 /*----------------------------------------------------------------------------*
407  * Binding utilities.
408  *----------------------------------------------------------------------------*/
409 
410 //-----------------------------------------------------------------//
414 //-----------------------------------------------------------------//
415 template<size_t FIND_DOM, size_t I, class TS>
417  //-----------------------------------------------------------------//
424  //-----------------------------------------------------------------//
425  template<class DOM>
426  static int compute(DOM & mesh) {
427  static constexpr size_t size = std::tuple_size<TS>::value;
428 
429  // Get the indexed tuple
430  using T = typename std::tuple_element<size - I, TS>::type;
431 
432  // Get domains and dimension
433  using M1 = typename std::tuple_element<1, T>::type;
434  using M2 = typename std::tuple_element<2, T>::type;
435  using T1 = typename std::tuple_element<3, T>::type;
436  using T2 = typename std::tuple_element<4, T>::type;
437 
438  if(M1::value == FIND_DOM) {
439  mesh.template compute_bindings<M1::value,
440  M2::value,
441  T1::dimension,
442  T2::dimension>();
443  } // if
444 
446  } // compute
447 
448 }; // struct compute_bindings
449 
450 //-----------------------------------------------------------------//
454 //-----------------------------------------------------------------//
455 template<size_t FIND_DOM, class TS>
456 struct compute_bindings<FIND_DOM, 0, TS> {
457  //-----------------------------------------------------------------//
462  //-----------------------------------------------------------------//
463  template<class DOM>
464  static int compute(DOM &) {
465  return 0;
466  } // compute
467 
468 }; // struct compute_bindings
469 
470 template<typename T>
472 {
473 public:
474  using int_t = T;
475 
476  std::vector<int_t> offset;
477  std::vector<int_t> index;
478  std::vector<int_t> partition;
479 };
480 
481 FLECSI_MEMBER_CHECKER(index_subspaces);
482 
483 template<typename MESH_TYPE, bool HAS_SUBSPACES>
485  using type = typename MESH_TYPE::index_subspaces;
486 };
487 
488 template<typename MESH_TYPE>
489 struct index_subspaces_tuple<MESH_TYPE, false> {
490  using type = std::tuple<>;
491 };
492 
493 template<typename MESH_TYPE>
495  using type = typename index_subspaces_tuple<MESH_TYPE,
496  has_member_index_subspaces<MESH_TYPE>::value>::type;
497 };
498 
499 template<typename MESH_TYPE>
501  using type = typename get_index_subspaces<MESH_TYPE>::type;
502 
503  static constexpr size_t value = std::tuple_size<type>::value;
504 };
505 
506 } // namespace topo
507 } // namespace flecsi
compute_connectivity provides static recursion to process connectivity computation of mesh entity typ...
Definition: utils.hh:358
static int compute(DOM &mesh)
Definition: utils.hh:426
static constexpr size_t find()
Search last tuple element.
Definition: utils.hh:289
Definition: utils.hh:105
static constexpr size_t find()
Definition: utils.hh:265
static constexpr size_t find()
Definition: utils.hh:151
static constexpr size_t find()
Definition: utils.hh:121
Definition: utils.hh:500
Definition: utils.hh:494
static constexpr size_t find()
Definition: utils.hh:172
find_entity_ provides static search capabilities.
Definition: utils.hh:86
static int compute(DOM &)
Definition: utils.hh:464
static constexpr size_t find()
Definition: utils.hh:71
std::string type()
Definition: demangle.hh:44
static constexpr size_t find()
Search last tuple element.
Definition: utils.hh:199
compute_bindings provides static recursion to process binding computation of mesh entity types...
Definition: utils.hh:416
static int compute(DOM &mesh)
Definition: utils.hh:367
Definition: index.hh:64
static int compute(DOM &)
Definition: utils.hh:400
static constexpr size_t find()
Definition: utils.hh:219
find_entity provides a specialization for the root recursion.
Definition: utils.hh:28
typename std::tuple_element< 2, pair_ >::type type
Definition: utils.hh:101
Definition: utils.hh:484
#define FLECSI_MEMBER_CHECKER(X)
Macro to check if the object has a member _*.
Definition: static_verify.hh:27
static constexpr size_t find()
Search last tuple element.
Definition: utils.hh:243
static constexpr size_t find()
Definition: utils.hh:40
Definition: utils.hh:471
Definition: control.hh:31