9 #ifndef stk_mesh_base_Entity_hpp 10 #define stk_mesh_base_Entity_hpp 17 #include <stk_mesh/base/Types.hpp> 19 #include <stk_mesh/baseImpl/EntityImpl.hpp> 21 #include <boost/range.hpp> 23 #ifdef SIERRA_MIGRATION 24 #include <stk_mesh/base/Relation.hpp> 28 typedef RelationVector::const_iterator RelationIterator;
29 typedef boost::iterator_range<RelationIterator> RelationRange;
35 struct fmwk_attributes {
42 const void* shared_attr;
53 unsigned short connect_count;
63 class MeshObjSharedAttr;
66 extern const unsigned int INVALID_LOCAL_ID;
67 extern const stk::mesh::RelationIterator INVALID_RELATION_ITR;
70 bool set_attributes(
stk::mesh::Entity & ,
const int ,
const MeshObjSharedAttr*,
const int);
75 namespace roster_only {
81 bool insert_relation(
stk::mesh::Entity *
const,
const stk::mesh::Relation::RelationType,
stk::mesh::Entity *
const,
const unsigned,
const unsigned,
const bool, MeshBulkData &);
82 bool remove_relation(
stk::mesh::Entity &,
const stk::mesh::RelationIterator, MeshBulkData &);
93 class EntityRepository;
94 class BucketRepository;
128 EntityRank
entity_rank()
const {
return m_entityImpl.entity_rank(); }
133 EntityId
identifier()
const {
return m_entityImpl.identifier(); }
142 Bucket * bucket_ptr()
const {
return m_entityImpl.bucket_ptr(); }
167 PairIterRelation node_relations()
const {
return m_entityImpl.node_relations(); }
169 #ifdef SIERRA_MIGRATION 170 RelationIterator node_relation(
unsigned ordinal)
const {
return m_entityImpl.node_relation(ordinal); }
175 unsigned owner_rank()
const {
return m_entityImpl.owner_rank(); }
187 void compress_relation_capacity();
191 void set_key(
const EntityKey& arg_key) { m_entityImpl.set_key(arg_key); }
193 impl::EntityImpl m_entityImpl;
200 #ifndef DOXYGEN_COMPILE 201 friend class impl::EntityRepository ;
202 friend class impl::EntityImpl ;
217 #ifdef SIERRA_MIGRATION 219 friend class sierra::Fmwk::MeshObjRoster;
221 friend const sierra::Fmwk::MeshObjSharedAttr * sierra::Fmwk::get_shared_attr(
const Entity &);
222 friend bool sierra::Fmwk::detail::set_attributes(
Entity &,
const int,
const sierra::Fmwk::MeshObjSharedAttr *,
const int);
223 friend bool sierra::Fmwk::detail::set_attributes(
Entity &,
const sierra::Fmwk::MeshObjSharedAttr *,
const int);
224 friend void sierra::Fmwk::detail::unset_shared_attr(
Entity &);
225 friend bool sierra::Fmwk::insert_relation(
Entity *
const,
const stk::mesh::Relation::RelationType,
Entity *
const,
const unsigned,
const unsigned,
const bool, sierra::Fmwk::MeshBulkData &);
226 friend bool sierra::Fmwk::remove_relation(
Entity &,
const stk::mesh::RelationIterator, sierra::Fmwk::MeshBulkData &);
227 friend bool sierra::Fmwk::verify_relations(
const Entity &);
229 friend void sierra::Fmwk::roster_only::set_shared_attr(
stk::mesh::Entity&,
const sierra::Fmwk::MeshObjSharedAttr*);
231 typedef unsigned DerivedType;
236 enum ObjectTypeEnum {
237 NODE = 0, EDGE = 1, FACE = 2, ELEMENT = 3, CONSTRAINT = 4, NUM_TYPES = 5, BASE_CLASS = 0x00ff
239 static std::string TypeToString (ObjectTypeEnum type);
243 template <
class SharedAttr>
246 const SharedAttr* attr,
251 ThrowAssertMsg(aux_relations().capacity() == 0,
"Leftover memory found in relation vector");
253 m_fmwk_attrs->global_id = id;
254 m_fmwk_attrs->shared_attr = attr;
255 m_fmwk_attrs->owner = owner;
256 m_fmwk_attrs->connect_count = 0;
257 m_local_id = sierra::Fmwk::INVALID_LOCAL_ID;
259 if (attr->locally_owned() && owner_processor_rank() == -1) {
261 ThrowAssert(owner_processor_rank() < parallel_size);
264 internal_verify_initialization_invariant();
270 int global_id()
const {
271 return m_fmwk_attrs->global_id;
287 inline unsigned local_id()
const {
return m_local_id; }
288 void set_local_id(
unsigned int l_id) { m_local_id = l_id; }
290 int owner_processor_rank()
const {
return m_fmwk_attrs->owner; }
291 void set_owner_processor_rank(
int owner) { m_fmwk_attrs->owner = owner; }
299 unsigned size_connection()
const {
300 return m_fmwk_attrs->connect_count;
306 unsigned inc_connection() {
307 ++m_fmwk_attrs->connect_count;
308 ThrowAssert(m_fmwk_attrs->connect_count );
309 return m_fmwk_attrs->connect_count;
315 unsigned dec_connection() {
316 ThrowAssert(m_fmwk_attrs->connect_count );
317 --m_fmwk_attrs->connect_count;
318 return m_fmwk_attrs->connect_count;
321 RelationIterator aux_relation_begin()
const {
return m_fmwk_attrs->aux_relations.begin(); }
322 RelationIterator aux_relation_end()
const {
return m_fmwk_attrs->aux_relations.end(); }
324 RelationVector& aux_relations() {
return m_fmwk_attrs->aux_relations; }
330 RelationIterator internal_begin_relation(
const Relation::RelationType relation_type)
const {
331 if (internal_is_handled_generically(relation_type)) {
332 return relations().first;
335 return aux_relation_begin();
343 RelationIterator internal_end_relation(
const Relation::RelationType relation_type)
const {
344 if (internal_is_handled_generically(relation_type)) {
345 return relations().second;
348 return aux_relation_end();
352 void set_shared_attr(
const void* attr) { m_fmwk_attrs->shared_attr = attr; }
353 const void* get_shared_attr()
const {
return m_fmwk_attrs->shared_attr; }
356 void set_relation_orientation(RelationIterator rel,
unsigned orientation);
367 void reserve_relation(
const unsigned num);
377 bool update_relation(
const RelationIterator ir,
const bool back_rel_flag)
const;
379 RelationIterator find_relation(
const Relation& relation)
const;
381 void erase_and_clear_if_empty(RelationIterator rel_itr);
383 void internal_verify_meshobj_invariant()
const;
385 void internal_swap_in_real_entity(
const int globalId);
387 void internal_verify_initialization_invariant() {
390 ThrowAssert( !(m_fmwk_attrs->global_id < 0 && key().
id() == static_cast<uint64_t>(m_fmwk_attrs->global_id)) &&
391 !(m_fmwk_attrs->global_id > 0 && key().
id() != static_cast<uint64_t>(m_fmwk_attrs->global_id)) );
395 unsigned stk_entity_rank()
const {
return key().rank(); }
397 bool internal_is_handled_generically(
const Relation::RelationType relation_type)
const 399 return relation_type == Relation::USES || relation_type == Relation::USED_BY;
406 fmwk_attributes* m_fmwk_attrs;
415 #ifdef SIERRA_MIGRATION 418 Relation::RelationType
419 back_relation_type(
const Relation::RelationType relType)
424 return Relation::USED_BY;
425 case Relation::USED_BY:
426 return Relation::USES;
427 case Relation::CHILD:
428 return Relation::PARENT;
429 case Relation::PARENT:
430 return Relation::CHILD;
437 template <
class Iterator>
439 verify_relation_ordering(Iterator begin, Iterator end)
441 for (Iterator itr = begin; itr != end; ) {
446 if (itr->entity_rank() < prev->entity_rank()) {
450 if (itr->entity_rank() == prev->entity_rank()) {
452 if (itr->getRelationType() < prev->getRelationType()) {
456 if (itr->getRelationType() == prev->getRelationType()) {
458 if (itr->getOrdinal() < prev->getOrdinal()) {
468 template <
class Range>
470 verify_relation_ordering(Range range)
472 return verify_relation_ordering(boost::const_begin(range), boost::const_end(range));
487 {
return lhs.
key() < rhs.
key(); }
490 {
return lhs.
key() < rhs ; }
497 return lhs_key < rhs_key ;
500 bool operator()(
const Entity* lhs,
const Entity& rhs)
const 503 return lhs_key < rhs.
key() ;
506 bool operator()(
const Entity& lhs,
const Entity* rhs)
const 509 return lhs.
key() < rhs_key ;
515 return lhs_key < rhs ;
522 return lhs_key != rhs_key ? lhs_key < rhs_key : lhs.second < rhs.second ;
528 return lhs_key < rhs.
key();
535 return lhs_key < rhs_key ;
541 return lhs_key < rhs ;
553 return lhs_key == rhs_key;
560 return lhs_key == rhs_key;
564 std::string print_entity_key(
const Entity& entity);
566 std::string print_entity_key(
const Entity* entity);
571 #ifdef SIERRA_MIGRATION 577 Entity::Entity(
const EntityKey & arg_key )
578 : m_entityImpl( arg_key )
579 #ifdef SIERRA_MIGRATION PairIterRelation relations(EntityRank type) const
Entity relations for which this entity is a member, the other entity is of a given type...
std::vector< Relation > RelationVector
Span of a sorted relations for a given domain entity.
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.
bool operator()(const Entity *lhs, const Entity *rhs) const
Comparison operator.
PairIterEntityComm comm() const
Complete communicaiton list for this entity.
int parallel_rank()
function parallel_rank returns the rank of this processor in the current mpi communicator.
A relation between two mesh entities with a relation identifier and kind .
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
unsigned bucket_ordinal() const
The ordinal for this entity within its bucket.
A container for the field data of a homogeneous collection of entities.
const EntityKey & key() const
The globally unique key ( entity type + identifier ) of this entity.
bool operator()(const Entity &lhs, const Entity &rhs) const
Comparison operator.
Bucket & bucket() const
The bucket which holds this mesh entity's field data.
PairIterEntityComm sharing() const
Parallel processes which share this entity.
Integer type for the entity keys, which is an encoding of the entity type and entity identifier...
std::pair< Entity *, unsigned > EntityProc
Pairing of an entity with a processor rank.
EntityRank entity_rank() const
The rank of this entity.
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
size_t synchronized_count() const
The mesh bulk data synchronized_count when this entity's part membership was most recently modified...
Comparison operator for entities compares the entities' keys.
int parallel_size()
function parallel_size returns the number of processors in the current mpi communicator.
PairIterEntityComm comm(const Ghosting &sub) const
Subset communicaiton list for this entity.
EntityModificationLog log_query() const
Query the current state of the entity log.
Data for ghosting mesh entities.