Interface Documentation
Version: invalid
types.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #if !defined(__FLECSI_PRIVATE__)
19 #error Do not include this file directly!
20 #endif
21 
22 #include "../connectivity.hh"
23 #include "../utility_types.hh"
24 #include "flecsi/run/backend.hh"
27 
28 #include <array>
29 #include <cstdint>
30 #include <iostream>
31 #include <vector>
32 
33 namespace flecsi {
34 namespace topo {
35 
36 /*----------------------------------------------------------------------------*
37  * class mesh_entity_base
38  *----------------------------------------------------------------------------*/
39 
42 template<class>
43 class mesh_base;
44 
45 // Aliases for backward compatibility
47 
48 template<size_t NUM_DOMAINS>
50 
51 /*----------------------------------------------------------------------------*
52  * class mesh_entity
53  *----------------------------------------------------------------------------*/
54 
55 //-----------------------------------------------------------------//
62 //-----------------------------------------------------------------//
63 
64 template<size_t DIM, size_t NUM_DOMAINS>
65 class mesh_entity : public entity_base<NUM_DOMAINS>
66 {
67 public:
68  static constexpr size_t dimension = DIM;
69 
70  mesh_entity() {}
71  ~mesh_entity() {}
72 }; // class mesh_entity
73 
74 // Redecalre the dimension. This is redundant, and no longer needed in C++17.
75 template<size_t DIM, size_t NUM_DOMAINS>
77 
78 /*----------------------------------------------------------------------------*
79  * class domain_entity_t
80  *----------------------------------------------------------------------------*/
81 
82 //-----------------------------------------------------------------//
90 //-----------------------------------------------------------------//
91 
92 template<size_t DOM, class ENTITY_TYPE>
93 class domain_entity
94 {
95 public:
96  using id_t = typename ENTITY_TYPE::id_t;
97  using item_t = ENTITY_TYPE *;
98 
99  // implicit type conversions are evil. This one tries to convert
100  // all pointers to domain_entities
101  explicit domain_entity(ENTITY_TYPE * entity) : entity_(entity) {}
102  domain_entity & operator=(const domain_entity & e) {
103  entity_ = e.entity_;
104  return *this;
105  }
106 
107  ENTITY_TYPE * entity() {
108  return entity_;
109  }
110 
111  const ENTITY_TYPE * entity() const {
112  return entity_;
113  }
114 
115  operator ENTITY_TYPE *() {
116  return entity_;
117  }
118 
119  ENTITY_TYPE * operator->() {
120  return entity_;
121  }
122 
123  const ENTITY_TYPE * operator->() const {
124  return entity_;
125  }
126 
127  ENTITY_TYPE * operator*() {
128  return entity_;
129  }
130 
131  const ENTITY_TYPE * operator*() const {
132  return entity_;
133  }
134 
135  operator size_t() const {
136  return entity_->template id<DOM>();
137  }
138 
139  id_t global_id() const {
140  return entity_->template global_id<DOM>();
141  }
142 
143  size_t id() const {
144  return entity_->template id<DOM>();
145  }
146 
147  bool operator==(domain_entity e) const {
148  return entity_ == e.entity_;
149  }
150 
151  bool operator!=(domain_entity e) const {
152  return entity_ != e.entity_;
153  }
154 
155  bool operator<(domain_entity e) const {
156  return entity_ < e.entity_;
157  }
158 
159  id_t index_space_id() const {
160  return entity_->template global_id<DOM>();
161  }
162 
163 private:
164  ENTITY_TYPE * entity_;
165 };
166 
167 //-----------------------------------------------------------------//
170 //-----------------------------------------------------------------//
171 
172 template<size_t DIM>
174 {
175 public:
176  using id_t = util::id_t;
177 
178  void init_(size_t from_domain, size_t to_domain) {
179  from_domain_ = from_domain;
180  to_domain_ = to_domain;
181  }
182 
183  template<size_t FROM_DIM, size_t TO_DIM>
184  connectivity_t & get() {
185  static_assert(FROM_DIM <= DIM, "invalid from dimension");
186  static_assert(TO_DIM <= DIM, "invalid to dimension");
187  return conns_[FROM_DIM][TO_DIM];
188  }
189 
190  template<size_t FROM_DIM, size_t TO_DIM>
191  const connectivity_t & get() const {
192  static_assert(FROM_DIM <= DIM, "invalid from dimension");
193  static_assert(TO_DIM <= DIM, "invalid to dimension");
194  return conns_[FROM_DIM][TO_DIM];
195  }
196 
197  template<size_t FROM_DIM>
198  connectivity_t & get(size_t to_dim) {
199  static_assert(FROM_DIM <= DIM, "invalid from dimension");
200  flog_assert(to_dim <= DIM, "invalid to dimension");
201  return conns_[FROM_DIM][to_dim];
202  }
203 
204  template<size_t FROM_DIM>
205  const connectivity_t & get(size_t to_dim) const {
206  static_assert(FROM_DIM <= DIM, "invalid from dimension");
207  flog_assert(to_dim <= DIM, "invalid to dimension");
208  return conns_[FROM_DIM][to_dim];
209  }
210 
211  connectivity_t & get(size_t from_dim, size_t to_dim) {
212  flog_assert(from_dim <= DIM, "invalid from dimension");
213  flog_assert(to_dim <= DIM, "invalid to dimension");
214  return conns_[from_dim][to_dim];
215  }
216 
217  const connectivity_t & get(size_t from_dim, size_t to_dim) const {
218  flog_assert(from_dim <= DIM, "invalid from dimension");
219  flog_assert(to_dim <= DIM, "invalid to dimension");
220  return conns_[from_dim][to_dim];
221  }
222 
223  template<size_t FROM_DIM, size_t NUM_DOMAINS>
224  id_t * get_entities(mesh_entity<FROM_DIM, NUM_DOMAINS> * from_ent,
225  size_t to_dim) {
226  return get<FROM_DIM>(to_dim).get_entities(from_ent->id(from_domain_));
227  }
228 
229  template<size_t FROM_DIM, size_t NUM_DOMAINS>
230  id_t * get_entities(mesh_entity<FROM_DIM, NUM_DOMAINS> * from_ent,
231  size_t to_dim,
232  size_t & count) {
233  return get<FROM_DIM>(to_dim).get_entities(
234  from_ent->id(from_domain_), count);
235  }
236 
237  id_t * get_entities(id_t from_id, size_t to_dim) {
238  return get(from_id.dimension(), to_dim).get_entities(from_id.entity());
239  }
240 
241  id_t * get_entities(id_t from_id, size_t to_dim, size_t & count) {
242  return get(from_id.dimension(), to_dim)
243  .get_entities(from_id.entity(), count);
244  }
245 
246  template<size_t FROM_DIM, size_t NUM_DOMAINS>
247  auto get_entity_vec(mesh_entity<FROM_DIM, NUM_DOMAINS> * from_ent,
248  size_t to_dim) const {
249  auto & conn = get<FROM_DIM>(to_dim);
250  return conn.get_entity_vec(from_ent->id(from_domain_));
251  }
252 
253  auto get_entity_vec(id_t from_id, size_t to_dim) const {
254  auto & conn = get(from_id.dimension(), to_dim);
255  return conn.get_entity_vec(from_id.entity());
256  }
257 
258  std::ostream & dump(std::ostream & stream) {
259  for(size_t i = 0; i < conns_.size(); ++i) {
260  auto & ci = conns_[i];
261  for(size_t j = 0; j < ci.size(); ++j) {
262  auto & cj = ci[j];
263  stream << "------------- " << i << " -> " << j << std::endl;
264  cj.dump(stream);
265  }
266  }
267  return stream;
268  }
269 
270  void dump() {
271  dump(std::cout);
272  }
273 
274 private:
275  using conn_array_t = std::array<std::array<connectivity_t, DIM + 1>, DIM + 1>;
276 
277  conn_array_t conns_;
278  size_t from_domain_;
279  size_t to_domain_;
280 };
281 
288  using coloring = size_t;
289 };
290 
291 #if 0
292 template<class STORAGE_TYPE>
293 class mesh_base : data::data_client_t, unstructured_base
294 {
295 public:
296  using id_t = util::id_t;
297 
298  // Default constructor
299  mesh_base(STORAGE_TYPE * ms = nullptr) : ms_(ms) {}
300 
301  // Don't allow the mesh to be copied or copy constructed
302  mesh_base(const mesh_base & m) : ms_(m.ms_) {}
303 
304  mesh_base & operator=(const mesh_base &) = delete;
305 
307  mesh_base(mesh_base &&) = default;
308 
310  mesh_base & operator=(mesh_base && o) {
311  // call base_t move operator
312  data::data_client_t::operator=(std::move(o));
313  // return a reference to the object
314  return *this;
315  };
316 
317  STORAGE_TYPE * set_storage(STORAGE_TYPE * ms) {
318  ms_ = ms;
319  return ms_;
320  } // set_storage
321 
322  STORAGE_TYPE * storage() {
323  return ms_;
324  } // set_storage
325 
326  void clear_storage() {
327  ms_ = nullptr;
328  } // clear_storage
329 
330  void delete_storage() {
331  delete ms_;
332  } // delete_storage
333 
334  //-----------------------------------------------------------------//
336  //-----------------------------------------------------------------//
337  virtual size_t num_entities(size_t dim, size_t domain) const = 0;
338 
339  //-----------------------------------------------------------------//
341  //-----------------------------------------------------------------//
342  virtual size_t topological_dimension() const = 0;
343 
344  //-----------------------------------------------------------------//
346  //-----------------------------------------------------------------//
347  virtual const connectivity_t &
348  get_connectivity(size_t domain, size_t from_dim, size_t to_dim) const = 0;
349 
350  //-----------------------------------------------------------------//
352  //-----------------------------------------------------------------//
353  virtual connectivity_t &
354  get_connectivity(size_t domain, size_t from_dim, size_t to_dim) = 0;
355 
356  //-----------------------------------------------------------------//
358  //-----------------------------------------------------------------//
359  virtual const connectivity_t & get_connectivity(size_t from_domain,
360  size_t to_domain,
361  size_t from_dim,
362  size_t to_dim) const = 0;
363 
364  //-----------------------------------------------------------------//
366  //-----------------------------------------------------------------//
367  virtual connectivity_t & get_connectivity(size_t from_domain,
368  size_t to_domain,
369  size_t from_dim,
370  size_t to_dim) = 0;
371 
372  //-----------------------------------------------------------------//
376  //-----------------------------------------------------------------//
377  template<class T, size_t DOM = 0, class... S>
378  T * make(S &&... args) {
379  return ms_->template make<T, DOM>(std::forward<S>(args)...);
380  } // make
381 
382  virtual void append_to_index_space_(size_t domain,
383  size_t dimension,
384  std::vector<entity_base_ *> & ents,
385  std::vector<id_t> & ids) = 0;
386 
387 protected:
388  STORAGE_TYPE * ms_ = nullptr;
389 
390 }; // mesh_base
391 #endif
392 
393 template<class MESH_TYPE, size_t DIM, size_t DOM>
394 using entity_type_ = typename find_entity_<MESH_TYPE, DIM, DOM>::type;
395 
396 template<class STORAGE_TYPE, class MESH_TYPE, size_t NM, size_t DOM, size_t DIM>
397 void
398 unserialize_dimension_(mesh_base<STORAGE_TYPE> & mesh,
399  char * buf,
400  uint64_t & pos) {
401  uint64_t num_entities;
402  std::memcpy(&num_entities, buf + pos, sizeof(num_entities));
403  pos += sizeof(num_entities);
404 
405  using id_t = util::id_t;
406 
407  std::vector<entity_base_ *> ents;
408  std::vector<id_t> ids;
409  ents.reserve(num_entities);
410  ids.reserve(num_entities);
411 
412  auto & context_ = run::context::instance();
413 
414  size_t partition_id = context_.color();
415 
416  for(size_t local_id = 0; local_id < num_entities; ++local_id) {
417  id_t global_id = id_t::make<DIM, DOM>(local_id, partition_id);
418 
419  auto ent = new entity_type_<MESH_TYPE, DIM, DOM>();
420  ent->template set_global_id<DOM>(global_id);
421  ents.push_back(ent);
422  ids.push_back(global_id);
423  }
424 
425  mesh.append_to_index_space_(DOM, DIM, ents, ids);
426 }
427 
428 template<class STORAGE_TYPE,
429  class MESH_TYPE,
430  size_t NUM_DOMAINS,
431  size_t NUM_DIMS,
432  size_t DOM,
433  size_t DIM>
435 
436  static void
437  unserialize(mesh_base<STORAGE_TYPE> & mesh, char * buf, uint64_t & pos) {
438  unserialize_dimension_<STORAGE_TYPE, MESH_TYPE, NUM_DOMAINS, DOM, DIM>(
439  mesh, buf, pos);
440  unserialize_dimensions_<STORAGE_TYPE,
441  MESH_TYPE,
442  NUM_DOMAINS,
443  NUM_DIMS,
444  DOM,
445  DIM + 1>::unserialize(mesh, buf, pos);
446  }
447 };
448 
449 template<class STORAGE_TYPE,
450  class MESH_TYPE,
451  size_t NUM_DOMAINS,
452  size_t NUM_DIMS,
453  size_t DOM>
454 struct unserialize_dimensions_<STORAGE_TYPE,
455  MESH_TYPE,
456  NUM_DOMAINS,
457  NUM_DIMS,
458  DOM,
459  NUM_DIMS> {
460 
461  static void
462  unserialize(mesh_base<STORAGE_TYPE> & mesh, char * buf, uint64_t & pos) {
463  unserialize_dimension_<STORAGE_TYPE, MESH_TYPE, NUM_DOMAINS, DOM, NUM_DIMS>(
464  mesh, buf, pos);
465  }
466 };
467 
468 template<class STORAGE_TYPE,
469  class MESH_TYPE,
470  size_t NUM_DOMAINS,
471  size_t NUM_DIMS,
472  size_t DOM>
474 
475  static void
476  unserialize(mesh_base<STORAGE_TYPE> & mesh, char * buf, uint64_t & pos) {
477  unserialize_dimensions_<STORAGE_TYPE,
478  MESH_TYPE,
479  NUM_DOMAINS,
480  NUM_DIMS,
481  DOM,
482  0>::unserialize(mesh, buf, pos);
483  unserialize_domains_<STORAGE_TYPE,
484  MESH_TYPE,
485  NUM_DOMAINS,
486  NUM_DIMS,
487  DOM + 1>::unserialize(mesh, buf, pos);
488  }
489 };
490 
491 template<class STORAGE_TYPE,
492  class MESH_TYPE,
493  size_t NUM_DOMAINS,
494  size_t NUM_DIMS>
495 struct unserialize_domains_<STORAGE_TYPE,
496  MESH_TYPE,
497  NUM_DOMAINS,
498  NUM_DIMS,
499  NUM_DOMAINS> {
500 
501  static void unserialize(mesh_base<STORAGE_TYPE> &, char *, uint64_t &) {}
502 };
503 
504 } // namespace topo
505 } // namespace flecsi
contains methods and data about the mesh topology that do not depend on type parameterization, e.g: entity types, domains, etc.
Definition: types.hh:43
Definition: types.hh:287
Definition: id.hh:36
id_t global_id() const
Definition: utility_types.hh:113
Definition: types.hh:173
Definition: typeify.hh:31
#define flog_assert(test, message)
Definition: flog.hh:411
mesh_entity parameterizes a mesh entity base with its dimension and number of domains ...
Definition: storage.hh:35
entity_base defines a base class that stores the raw info that a topology needs, i.e: id and rank data
Definition: utility_types.hh:102
Definition: types.hh:473
domain_entity is a simple wrapper to mesh entity that associates with its a domain id ...
Definition: array_buffer.hh:24
typename std::tuple_element< 2, pair_ >::type type
Definition: utils.hh:101
Definition: utility_types.hh:95
connectivity_t provides basic connectivity information in a compressed storage format.
Definition: connectivity.hh:41
Definition: control.hh:31