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_classic::mesh::RelationIterator INVALID_RELATION_ITR;
75 namespace roster_only {
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;
195 explicit Entity(
const EntityKey & arg_key );
198 Entity & operator = (
const Entity & );
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_classic::mesh::Relation::RelationType, Entity *
const,
const unsigned,
const unsigned,
const bool, sierra::Fmwk::MeshBulkData &);
226 friend bool sierra::Fmwk::remove_relation(Entity &,
const stk_classic::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_classic::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) {
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)) {
335 return aux_relation_begin();
343 RelationIterator internal_end_relation(
const Relation::RelationType relation_type)
const {
344 if (internal_is_handled_generically(relation_type)) {
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 ;
503 return lhs_key < rhs.
key() ;
506 bool operator()(
const Entity& lhs,
const Entity* rhs)
const 508 const EntityKey rhs_key = rhs ? rhs->key() : EntityKey();
509 return lhs.key() < rhs_key ;
512 bool operator()(
const Entity* lhs,
const EntityKey & rhs)
const 514 const EntityKey lhs_key = lhs ? lhs->key() : EntityKey() ;
515 return lhs_key < rhs ;
520 const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
521 const EntityKey rhs_key = rhs.first ? rhs.first->key() : EntityKey() ;
522 return lhs_key != rhs_key ? lhs_key < rhs_key : lhs.second < rhs.second ;
527 const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
528 return lhs_key < rhs.key();
533 const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
534 const EntityKey rhs_key = rhs ? rhs->key() : EntityKey() ;
535 return lhs_key < rhs_key ;
540 const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
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
Comparison operator for entities compares the entities' keys.
PairIterEntityComm comm() const
Complete communicaiton list for this entity.
size_t synchronized_count() const
The mesh bulk data synchronized_count when this entity's part membership was most recently modified...
unsigned bucket_ordinal() const
The ordinal for this entity within its bucket.
PairIterEntityComm sharing() const
Parallel processes which share this entity.
Data for ghosting mesh entities.
Bucket & bucket() const
The bucket which holds this mesh entity's field data.
const EntityKey & key() const
The globally unique key ( entity type + identifier ) of 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.
int parallel_rank()
function parallel_rank returns the rank of this processor in the current mpi communicator.
EntityModificationLog log_query() const
Query the current state of the entity log.
bool operator()(const Entity *lhs, const Entity *rhs) const
Comparison operator.
PairIterRelation relations(EntityRank type) const
Entity relations for which this entity is a member, the other entity is of a given type...
PairIterEntityComm comm(const Ghosting &sub) const
Subset communicaiton list for this entity.
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
int parallel_size()
function parallel_size returns the number of processors in the current mpi communicator.
EntityRank entity_rank() const
The rank of this entity.
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
bool operator()(const Entity &lhs, const Entity &rhs) const
Comparison operator.
std::vector< Relation > RelationVector
Span of a sorted relations for a given domain entity.
A container for the field data of a homogeneous collection of entities.
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.