Sierra Toolkit  Version of the Day
EntityImpl.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #ifndef stk_mesh_EntityImpl_hpp
10 #define stk_mesh_EntityImpl_hpp
11 
12 #include <stk_util/util/PairIter.hpp>
13 
14 #include <stk_util/environment/ReportHandler.hpp>
15 
16 #include <stk_mesh/base/Types.hpp>
17 #include <stk_mesh/base/Relation.hpp>
18 #include <stk_mesh/base/Trace.hpp>
19 
20 #include <algorithm>
21 
22 namespace stk_classic {
23 namespace mesh {
24 namespace impl {
25 
30 class EntityImpl {
31 public:
32 
33  EntityImpl( const EntityKey & arg_key );
34  EntityImpl();
35  ~EntityImpl(){}
36 
37  // Exposed in external interface:
38  EntityRank entity_rank() const { return stk_classic::mesh::entity_rank( m_key ); }
39  EntityId identifier() const { return stk_classic::mesh::entity_id( m_key ); }
40  const EntityKey & key() const { return m_key ; }
41  PairIterRelation relations() const { return PairIterRelation(m_relation); }
42  PairIterRelation relations( unsigned rank ) const ;
43  PairIterRelation node_relations( ) const
44  {
45  RelationVector::const_iterator i = m_relation.begin();
46  RelationVector::const_iterator e = m_relation.end();
47 
48  const Relation::raw_relation_id_type hi = Relation::raw_relation_id(1, 0);
49  e = std::lower_bound( i , e , hi , LessRelation() );
50 
51  return PairIterRelation( i , e );
52  }
53 
54  RelationVector::const_iterator node_relation(unsigned ordinal) const
55  { return m_relation.begin() + ordinal; }
56 
57  PairIterEntityComm comm() const;
58  PairIterEntityComm sharing() const;
59  PairIterEntityComm comm( const Ghosting & sub ) const;
60 
61  Bucket & bucket() const
62  {
63  ThrowAssert(m_bucket); //don't want to return a reference to a null bucket
64  return *m_bucket ;
65  }
66 
67  Bucket* bucket_ptr() const
68  {
69  return m_bucket; // allow for NULL return value
70  }
71 
72  bool is_bucket_valid() const { return m_bucket != NULL; }
73  unsigned bucket_ordinal() const { return m_bucket_ord ; }
74  unsigned owner_rank() const { return m_owner_rank ; }
75  size_t synchronized_count() const { return m_sync_count ; }
76 
77  // The two relation methods below need to be called symmetically, ideally
78  // through EntityRepository which will enforce the symmetry.
79 
80  bool destroy_relation( Entity & e_to, const RelationIdentifier local_id);
81  bool declare_relation( Entity & e_to,
82  const RelationIdentifier local_id,
83  unsigned sync_count,
84  bool is_back_relation = false);
85 
86  // Communication info access:
87  bool insert( const EntityCommInfo & val );
88  bool erase( const EntityCommInfo & val );
89  bool erase( const Ghosting & ghost );
90  void comm_clear_ghosting();
91  void comm_clear();
92 
93  void set_bucket_and_ordinal( Bucket * in_bucket, unsigned ordinal )
94  {
95  TraceIfWatching("stk_classic::mesh::impl::EntityRepository::set_bucket_and_ordinal", LOG_ENTITY, key());
96 
97  m_bucket = in_bucket;
98  m_bucket_ord = ordinal;
99  }
100 
101  // return true if entity was actually modified
102  bool set_owner_rank( unsigned in_owner_rank )
103  {
104  TraceIfWatching("stk_classic::mesh::impl::EntityRepository::set_owner_rank", LOG_ENTITY, key());
105 
106  if ( in_owner_rank != m_owner_rank ) {
107  m_owner_rank = in_owner_rank;
108  return true;
109  }
110  return false;
111  }
112 
113  void set_sync_count( size_t sync_count )
114  {
115  TraceIfWatching("stk_classic::mesh::impl::EntityRepository::set_sync_count", LOG_ENTITY, key());
116 
117  m_sync_count = sync_count;
118  }
119 
120  // Change log access:
121  EntityModificationLog log_query() const { return m_mod_log ; }
122 
123  void log_clear()
124  {
125  TraceIfWatching("stk_classic::mesh::impl::EntityRepository::log_clear", LOG_ENTITY, key());
126 
127  m_mod_log = EntityLogNoChange;
128  }
129 
130  void log_deleted()
131  {
132  TraceIfWatching("stk_classic::mesh::impl::EntityRepository::log_deleted", LOG_ENTITY, key());
133 
134  m_mod_log = EntityLogDeleted;
135  }
136 
141  void log_resurrect();
142 
150  void log_modified_and_propagate();
151 
153  void log_created_parallel_copy();
154 
155  bool marked_for_destruction() const
156  {
157  // The original implementation of this method checked bucket capacity. In
158  // order to ensure that the addition of EntityLogDeleted does not change
159  // behavior, we put error check here.
160  // ThrowErrorMsgIf((bucket().capacity() == 0) != (m_mod_log == EntityLogDeleted),
161  // "Inconsistent destruction state; " <<
162  // "destroyed entities should be in the nil bucket and vice versa.\n" <<
163  // "Problem is with entity: " <<
164  // print_entity_key( MetaData::get( bucket() ), key() ) <<
165  // "\nWas in nil bucket: " << (bucket().capacity() == 0) << ", " <<
166  // "was in destroyed state: " << (m_mod_log == EntityLogDeleted) );
167 
168  return m_mod_log == EntityLogDeleted;
169  }
170 
171  //set_key is only to be used for setting a key on a newly-constructed entity.
172  void set_key(EntityKey key);
173 
174  //update_key is used to change the key for an entity that has been in use with
175  //a different key.
176  void update_key(EntityKey key);
177 
178 // RelationVector& rel_vec() {return m_relation;}
179  void compress_relation_capacity();
180 
181  private:
182 
183  EntityKey m_key ;
184  RelationVector m_relation ;
185  Bucket * m_bucket ;
186  unsigned m_bucket_ord ;
187  unsigned m_owner_rank ;
188  size_t m_sync_count ;
189  EntityModificationLog m_mod_log ;
190 
191 // EntityImpl( const EntityImpl & ); ///< Copy constructor not allowed
192  EntityImpl & operator = ( const EntityImpl & );
193 };
194 
195 inline
196 EntityImpl::EntityImpl( const EntityKey & arg_key )
197  : m_key(arg_key),
198  m_relation(),
199  m_bucket( NULL ),
200  m_bucket_ord(0),
201  m_owner_rank(0),
202  m_sync_count(0),
203  m_mod_log( EntityLogCreated )
204 {
205  TraceIfWatching("stk_classic::mesh::impl::EntityImpl::EntityImpl", LOG_ENTITY, arg_key);
206 }
207 
208 inline
209 EntityImpl::EntityImpl()
210  : m_key(),
211  m_relation(),
212  m_bucket( NULL ),
213  m_bucket_ord(0),
214  m_owner_rank(0),
215  m_sync_count(0),
216  m_mod_log( EntityLogCreated )
217 {
218 }
219 
220 //----------------------------------------------------------------------
221 
224 } // namespace impl
225 } // namespace mesh
226 } // namespace stk_classic
227 
228 //----------------------------------------------------------------------
229 //----------------------------------------------------------------------
230 
231 #endif /* stk_mesh_EntityImpl_hpp */
raw_relation_id_type raw_relation_id() const
The encoded relation raw_relation_id.
Definition: Relation.hpp:77
EntityId entity_id(const EntityKey &key)
Given an entity key, return the identifier for the entity.
Sierra Toolkit.
PairIter< std::vector< EntityCommInfo >::const_iterator > PairIterEntityComm
Span of ( communication-subset-ordinal , process-rank ) pairs for the communication of an entity...
Definition: Types.hpp:128
std::vector< Relation > RelationVector
Span of a sorted relations for a given domain entity.
Definition: Types.hpp:161
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).
bool insert(PartVector &v, Part &part)
Insert a part into a properly ordered collection of parts. Returns true if this is a new insertion...
Definition: Part.cpp:85