15 #include <stk_mesh/base/Entity.hpp> 16 #include <stk_mesh/base/BulkData.hpp> 17 #include <stk_mesh/base/MetaData.hpp> 19 #ifdef SIERRA_MIGRATION 21 static const std::vector<stk_classic::mesh::Relation> dummy_vector;
27 const unsigned int INVALID_LOCAL_ID = std::numeric_limits<unsigned int>::max();
28 const stk_classic::mesh::RelationIterator INVALID_RELATION_ITR = dummy_vector.end();
41 std::string print_entity_key(
const Entity& entity)
43 return print_entity_key(MetaData::get(entity),
47 std::string print_entity_key(
const Entity* entity)
53 return print_entity_key(*entity);
63 #ifdef SIERRA_MIGRATION 66 std::string Entity::TypeToString (Entity::ObjectTypeEnum type) {
67 if(type == NODE )
return "NODE";
68 if(type == EDGE )
return "EDGE";
69 if(type == FACE )
return "FACE";
70 if(type == ELEMENT )
return "ELMENT";
71 if(type == CONSTRAINT)
return "CONSTRANT";
72 if(type == BASE_CLASS)
return "BASE_CLASS";
80 void Entity::compress_relation_capacity()
82 m_entityImpl.compress_relation_capacity();
83 #ifdef SIERRA_MIGRATION 84 if (!m_fmwk_attrs->aux_relations.empty()) {
86 tmp.swap(m_fmwk_attrs->aux_relations);
91 void Entity::internal_swap_in_real_entity(
const int globalId)
93 ThrowRequire(globalId > 0);
94 m_fmwk_attrs->global_id = globalId;
96 BulkData::get(*this).change_entity_id(globalId, *
this);
98 internal_verify_initialization_invariant();
105 internal_verify_meshobj_invariant();
111 void Entity::reserve_relation(
const unsigned num)
113 if (num == 0 && aux_relations().empty()) {
115 aux_relations().swap(tmp);
118 aux_relations().reserve(num);
128 bool operator()(
const Relation& lhs,
const Relation& rhs)
132 if (lhs.entity_rank() != rhs.entity_rank()) {
133 result = lhs.entity_rank() < rhs.entity_rank();
135 else if (lhs.getRelationType() != rhs.getRelationType()) {
136 result = lhs.getRelationType() < rhs.getRelationType();
139 result = lhs.identifier() < rhs.identifier();
147 RelationIterator Entity::find_relation(
const Relation& relation)
const 161 const Relation::RelationType relation_type = relation.getRelationType();
163 RelationIterator rel = std::lower_bound(internal_begin_relation(relation_type),
164 internal_end_relation(relation_type),
170 while (rel != internal_end_relation(relation_type) &&
171 same_specification(*rel, relation) &&
172 rel->getMeshObj() != relation.getMeshObj())
180 bool Entity::update_relation(
181 const RelationIterator ir ,
182 const bool back_rel_flag)
const 184 const Relation::RelationType relType = ir->getRelationType();
185 ThrowAssert(verify_relation_ordering(internal_begin_relation(relType), internal_end_relation(relType)));
186 ThrowAssertMsg(!internal_is_handled_generically(relType),
187 "update_relation should not be called for STK-managed relations");
189 Entity & meshObj = *ir->getMeshObj() ;
191 const Relation::RelationType backRelType = back_relation_type(relType);
193 ThrowAssert(verify_relation_ordering(meshObj.internal_begin_relation(backRelType), meshObj.internal_end_relation(backRelType)));
196 Relation backRel_obj(const_cast<Entity*>(
this), backRelType, ir->getOrdinal(), ir->getOrientation());
197 RelationIterator backRel_itr = meshObj.find_relation(backRel_obj);
199 const bool exists = backRel_itr != meshObj.internal_end_relation(backRelType) && *backRel_itr == backRel_obj;
201 if (exists && !back_rel_flag) {
204 meshObj.erase_and_clear_if_empty(backRel_itr);
208 meshObj.inc_connection();
210 else if (!exists && back_rel_flag) {
213 const unsigned k = backRel_itr - meshObj.internal_begin_relation(backRelType) ;
215 meshObj.reserve_relation(meshObj.aux_relations().size() + 1);
217 meshObj.aux_relations().insert(meshObj.aux_relations().begin() + k, backRel_obj);
221 meshObj.dec_connection();
224 ThrowAssert(verify_relation_ordering(meshObj.internal_begin_relation(relType), meshObj.internal_end_relation(relType)));
231 void Entity::erase_and_clear_if_empty(RelationIterator rel_itr)
233 ThrowRequire(!internal_is_handled_generically(rel_itr->getRelationType()));
236 aux_relations.erase(aux_relations.begin() + (rel_itr - aux_relations.begin()));
238 if (aux_relations.empty()) {
245 void Entity::internal_verify_meshobj_invariant()
const 247 PairIterRelation stk_relations =
relations();
248 for ( ; !stk_relations.empty(); ++stk_relations ) {
249 ThrowRequireMsg(stk_relations->getMeshObj() != NULL,
"Problem with: " << *stk_relations);
253 for (RelationVector::const_iterator itr = aux_relations.begin(), end = aux_relations.end(); itr != end; ++itr) {
254 ThrowRequireMsg(itr->getMeshObj() != NULL,
"Problem with: " << *itr);
260 void Entity::set_relation_orientation(RelationIterator rel,
unsigned orientation)
262 const Relation::RelationType backRelType = back_relation_type(rel->getRelationType());
264 Entity & meshObj = *rel->getMeshObj();
265 Relation backRel_obj(const_cast<Entity*>(
this), backRelType, rel->getOrdinal(), rel->getOrientation());
266 RelationIterator backRel_itr = meshObj.find_relation(backRel_obj);
268 const bool exists = backRel_itr != meshObj.internal_end_relation(backRelType) && *backRel_itr == backRel_obj;
269 ThrowRequire(exists);
273 const_cast<Relation*
>(&*rel)->setOrientation(orientation);
274 const_cast<Relation*
>(&*backRel_itr)->setOrientation(orientation);
const EntityKey & key() const
The globally unique key ( entity type + identifier ) of 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...
std::vector< Relation > RelationVector
Span of a sorted relations for a given domain entity.