18 #if !defined(__FLECSI_PRIVATE__) 19 #error Do not include this file directly! 22 #include "../connectivity.hh" 23 #include "../utility_types.hh" 48 template<
size_t NUM_DOMAINS>
64 template<
size_t DIM,
size_t NUM_DOMAINS>
68 static constexpr
size_t dimension = DIM;
75 template<
size_t DIM,
size_t NUM_DOMAINS>
92 template<
size_t DOM,
class ENTITY_TYPE>
96 using id_t =
typename ENTITY_TYPE::id_t;
97 using item_t = ENTITY_TYPE *;
101 explicit domain_entity(ENTITY_TYPE * entity) : entity_(entity) {}
107 ENTITY_TYPE * entity() {
111 const ENTITY_TYPE * entity()
const {
115 operator ENTITY_TYPE *() {
119 ENTITY_TYPE * operator->() {
123 const ENTITY_TYPE * operator->()
const {
127 ENTITY_TYPE * operator*() {
131 const ENTITY_TYPE * operator*()
const {
135 operator size_t()
const {
136 return entity_->template id<DOM>();
140 return entity_->template global_id<DOM>();
144 return entity_->template id<DOM>();
148 return entity_ == e.entity_;
152 return entity_ != e.entity_;
156 return entity_ < e.entity_;
159 id_t index_space_id()
const {
160 return entity_->template global_id<DOM>();
164 ENTITY_TYPE * entity_;
178 void init_(
size_t from_domain,
size_t to_domain) {
179 from_domain_ = from_domain;
180 to_domain_ = to_domain;
183 template<
size_t FROM_DIM,
size_t TO_DIM>
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];
190 template<
size_t FROM_DIM,
size_t TO_DIM>
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];
197 template<
size_t FROM_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];
204 template<
size_t FROM_DIM>
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];
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];
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];
223 template<
size_t FROM_DIM,
size_t NUM_DOMAINS>
226 return get<FROM_DIM>(to_dim).get_entities(from_ent->id(from_domain_));
229 template<
size_t FROM_DIM,
size_t NUM_DOMAINS>
233 return get<FROM_DIM>(to_dim).get_entities(
234 from_ent->id(from_domain_), count);
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());
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);
246 template<
size_t FROM_DIM,
size_t NUM_DOMAINS>
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_));
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());
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) {
263 stream <<
"------------- " << i <<
" -> " << j << std::endl;
275 using conn_array_t = std::array<std::array<connectivity_t, DIM + 1>, DIM + 1>;
288 using coloring = size_t;
292 template<
class STORAGE_TYPE>
299 mesh_base(STORAGE_TYPE * ms =
nullptr) : ms_(ms) {}
312 data::data_client_t::operator=(std::move(o));
317 STORAGE_TYPE * set_storage(STORAGE_TYPE * ms) {
322 STORAGE_TYPE * storage() {
326 void clear_storage() {
330 void delete_storage() {
337 virtual size_t num_entities(
size_t dim,
size_t domain)
const = 0;
348 get_connectivity(
size_t domain,
size_t from_dim,
size_t to_dim)
const = 0;
354 get_connectivity(
size_t domain,
size_t from_dim,
size_t to_dim) = 0;
359 virtual const connectivity_t & get_connectivity(
size_t from_domain,
362 size_t to_dim)
const = 0;
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)...);
382 virtual void append_to_index_space_(
size_t domain,
384 std::vector<entity_base_ *> & ents,
385 std::vector<id_t> & ids) = 0;
388 STORAGE_TYPE * ms_ =
nullptr;
393 template<
class MESH_TYPE,
size_t DIM,
size_t DOM>
396 template<
class STORAGE_TYPE,
class MESH_TYPE,
size_t NM,
size_t DOM,
size_t DIM>
401 uint64_t num_entities;
402 std::memcpy(&num_entities, buf + pos,
sizeof(num_entities));
403 pos +=
sizeof(num_entities);
407 std::vector<entity_base_ *> ents;
408 std::vector<id_t> ids;
409 ents.reserve(num_entities);
410 ids.reserve(num_entities);
412 auto & context_ = run::context::instance();
414 size_t partition_id = context_.color();
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);
419 auto ent =
new entity_type_<MESH_TYPE, DIM, DOM>();
420 ent->template set_global_id<DOM>(
global_id);
422 ids.push_back(global_id);
425 mesh.append_to_index_space_(DOM, DIM, ents, ids);
428 template<
class STORAGE_TYPE,
438 unserialize_dimension_<STORAGE_TYPE, MESH_TYPE, NUM_DOMAINS, DOM, DIM>(
445 DIM + 1>::unserialize(mesh, buf, pos);
449 template<
class STORAGE_TYPE,
463 unserialize_dimension_<STORAGE_TYPE, MESH_TYPE, NUM_DOMAINS, DOM, NUM_DIMS>(
468 template<
class STORAGE_TYPE,
482 0>::unserialize(mesh, buf, pos);
487 DOM + 1>::unserialize(mesh, buf, pos);
491 template<
class STORAGE_TYPE,
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
id_t global_id() const
Definition: utility_types.hh:113
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
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