Sierra Toolkit  Version of the Day
Part.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 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_Part_hpp
10 #define stk_mesh_Part_hpp
11 
12 //----------------------------------------------------------------------
13 
14 #include <iosfwd>
15 #include <string>
16 #include <vector>
17 #include <algorithm>
18 
19 #include <stk_util/util/CSet.hpp>
20 #include <stk_mesh/base/Types.hpp>
21 #include <stk_mesh/base/PartRelation.hpp>
22 #include <stk_mesh/baseImpl/PartImpl.hpp>
23 
24 //----------------------------------------------------------------------
25 
26 namespace stk_classic {
27 namespace mesh {
28 
29 namespace impl {
30  class PartRepository;
31 } // namespace impl
32 
37 //----------------------------------------------------------------------
49 class Part {
50 public:
51 
55  MetaData & mesh_meta_data() const { return m_partImpl.mesh_meta_data(); }
56 
64  unsigned primary_entity_rank() const { return m_partImpl.primary_entity_rank(); }
65 
67  const std::string & name() const { return m_partImpl.name(); }
68 
72  unsigned mesh_meta_data_ordinal() const { return m_partImpl.mesh_meta_data_ordinal(); }
73 
75  const PartVector & supersets() const { return m_partImpl.supersets(); }
76 
78  const PartVector & subsets() const { return m_partImpl.subsets(); }
79 
81  const PartVector & intersection_of() const { return m_partImpl.intersection_of(); }
82 
84  const std::vector<PartRelation> & relations() const { return m_partImpl.relations(); }
85 
87  bool operator == ( const Part & rhs ) const { return this == & rhs ; }
88 
90  bool operator != ( const Part & rhs ) const { return this != & rhs ; }
91 
93  template<class A>
94  const A * attribute() const { return m_partImpl.attribute<A>(); }
95 
96 private:
97 
101  MetaData & meta_data() const { return m_partImpl.mesh_meta_data(); }
102 
103 
104  impl::PartImpl m_partImpl;
105 
106  /* \brief A part is owned by a PartRepository, as such only the owning
107  * PartRepository can create, delete, or modify a part.
108  * The owner-modifies rule is enforced by the implementation being
109  * a private data object on the Part and the PartRepository is a
110  * friend.
111  */
112  friend class ::stk_classic::mesh::impl::PartRepository ;
113  friend class ::stk_classic::mesh::MetaData ;
114 
115 #ifndef DOXYGEN_COMPILE
116 
120  Part( MetaData * arg_meta_data , const std::string & arg_name, EntityRank arg_rank, size_t arg_ordinal)
121  : m_partImpl(arg_meta_data,arg_name,arg_rank,arg_ordinal)
122  { }
123 
124  ~Part() {}
125  Part();
126  Part( const Part & );
127  Part & operator = ( const Part & );
128 
129 #endif /* DOXYGEN_COMPILE */
130 
131 };
132 
133 static const char INTERNAL_PART_PREFIX = '{';
134 static const char INTERNAL_PART_POSTFIX = '}';
135 
136 inline
137 bool is_internal(const std::string& part_name)
138 {
139  return part_name.size() > 2 && *part_name.begin() == INTERNAL_PART_PREFIX && *part_name.rbegin() == INTERNAL_PART_POSTFIX;
140 }
141 
142 inline
143 bool is_internal(const Part& part)
144 { return is_internal(part.name()); }
145 
146 std::string convert_to_internal_name(const std::string& part_name);
147 
148 //----------------------------------------------------------------------
150 struct PartLess {
151 
152  inline bool operator()( const Part & lhs , const Part & rhs ) const
153  { return lhs.mesh_meta_data_ordinal() < rhs.mesh_meta_data_ordinal(); }
154 
155  inline bool operator()( const Part & lhs , const Part * rhs ) const
156  { return lhs.mesh_meta_data_ordinal() < rhs->mesh_meta_data_ordinal(); }
157 
158  inline bool operator()( const Part * lhs , const Part & rhs ) const
159  { return lhs->mesh_meta_data_ordinal() < rhs.mesh_meta_data_ordinal(); }
160 
161  inline bool operator()( const Part * lhs , const Part * rhs ) const
162  { return lhs->mesh_meta_data_ordinal() < rhs->mesh_meta_data_ordinal(); }
163 };
164 
166 void order( PartVector & );
167 
168 inline
169 void order( OrdinalVector & v )
170 {
171  OrdinalVector::iterator ev = v.end();
172  OrdinalVector::iterator iv = v.begin();
173  std::sort( iv , ev );
174  iv = std::unique( iv , ev );
175  v.erase( iv , ev );
176 }
177 
181 bool insert( PartVector & , Part & );
182 
183 inline
184 bool insert_ordinal( OrdinalVector & v , unsigned part_ordinal )
185 {
186  for(OrdinalVector::iterator i=v.begin(), e=v.end(); i!=e; ++i) {
187  if (*i == part_ordinal) return false;
188  if (*i > part_ordinal) {
189  v.insert(i, part_ordinal);
190  return true;
191  }
192  }
193 
194  v.push_back(part_ordinal);
195  return true ;
196 }
197 
199 void remove( PartVector & , Part & );
200 
202 Part * find( const PartVector & , const std::string & );
203 
205 bool contain( const PartVector & , const Part & );
206 
207 template<class Iterator>
208 inline
209 bool contains_ordinal( Iterator beg, Iterator end, unsigned part_ordinal )
210 {
211  for(Iterator i=beg; i!=end; ++i) {
212  if (*i == part_ordinal) return true;
213  }
214 
215  return false;
216 }
217 
219 bool contain( const PartVector & , const PartVector & );
220 
222 size_t intersect( const PartVector & , const PartVector & );
223 
225 size_t intersect( const PartVector & , const PartVector & , PartVector & );
226 
230 bool intersect( const Part & , const Part & );
231 
232 //----------------------------------------------------------------------
236 std::ostream & print( std::ostream & , const char * const , const Part & );
237 
238 
242 } // namespace mesh
243 } // namespace stk_classic
244 
245 //----------------------------------------------------------------------
246 //----------------------------------------------------------------------
247 
248 #endif
249 
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
Definition: Bucket.cpp:259
bool operator==(const Part &rhs) const
Equality comparison.
Definition: Part.hpp:87
The manager of an integrated collection of parts and fields.
Definition: MetaData.hpp:56
void order(PartVector &v)
Order a collection of parts: invoke sort and then unique.
Definition: Part.cpp:76
unsigned primary_entity_rank() const
The primary entity type for this part.
Definition: Part.hpp:64
size_t intersect(const PartVector &v, const PartVector &p)
Query cardinality of intersection of two PartVectors.
Definition: Part.cpp:141
An application-defined subset of a problem domain.
Definition: Part.hpp:49
bool contain(const PartVector &v, const Part &part)
Query containment within properly ordered PartVector.
Definition: Part.cpp:108
const PartVector & intersection_of() const
Parts for which this part is defined as the intersection.
Definition: Part.hpp:81
MetaData & mesh_meta_data() const
The meta data manager that owns the PartRepository which created this part.
Definition: Part.hpp:55
const std::string & name() const
Application-defined text name of this part.
Definition: Part.hpp:67
unsigned mesh_meta_data_ordinal() const
Internally generated ordinal of this part that is unique within the owning meta data manager...
Definition: Part.hpp:72
const PartVector & supersets() const
Parts that are supersets of this part.
Definition: Part.hpp:75
const A * attribute() const
Query attribute that has been attached to this part.
Definition: Part.hpp:94
const std::vector< PartRelation > & relations() const
PartRelations for which this part is a member, root or target.
Definition: Part.hpp:84
Ordering operator for parts.
Definition: Part.hpp:150
const PartVector & subsets() const
Parts that are subsets of this part.
Definition: Part.hpp:78
Sierra Toolkit.
bool operator!=(const Part &rhs) const
Inequality comparison.
Definition: Part.hpp:90
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
Part * find(const PartVector &parts, const std::string &name)
Find a part by name in a collection of parts.
Definition: Part.cpp:22
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