12 #include <stk_util/environment/ReportHandler.hpp> 14 #include <stk_mesh/base/Part.hpp> 15 #include <stk_mesh/base/Types.hpp> 16 #include <stk_mesh/base/Trace.hpp> 18 #include <stk_mesh/baseImpl/PartRepository.hpp> 31 std::string universal_part_name()
33 static const std::string name = convert_to_internal_name(
"UNIVERSAL");
37 void assert_same_universe(
const Part & superset ,
44 ThrowErrorMsgIf( a.empty() || b.empty() || a[0] != b[0],
45 method <<
"(...) FAILED Requirement that " <<
46 "Part[" << superset.name() <<
"] and " <<
47 "Part[" << subset.name() <<
"] are in the same " <<
48 universal_part_name() );
51 void assert_same(
const Part & part1 ,
55 ThrowErrorMsgIf( & part1 != & part2,
56 method <<
"(...) FAILED Requirement that " <<
57 "Part[" << part1.name() <<
"] and " <<
58 "Part[" << part2.name() <<
"] are the same" );
61 void assert_not_same(
const Part & part1 ,
65 ThrowErrorMsgIf( & part1 == & part2,
66 method <<
"(...) FAILED Requirement that " <<
67 "Part[" << part1.name() <<
"] and " <<
68 "Part[" << part2.name() <<
"] are not the same" );
71 void assert_superset( Part & superset ,
75 ThrowErrorMsgIf( !
contain( subset.supersets() , superset ),
76 method <<
"(...) FAILED Requirement that " <<
77 "Part[" << superset.name() <<
"] " <<
78 "is a superset of " <<
79 "Part[" << subset.name() <<
"]" );
82 void assert_not_superset(
const Part & superset ,
86 ThrowErrorMsgIf(
contain( subset.supersets() , superset ),
87 method <<
"(...) FAILED Requirement that " <<
88 "Part[" << superset.name() <<
"] " <<
89 "is not a superset of " <<
90 "Part[" << subset.name() <<
"]" );
93 void assert_rank_ordering(
const Part & superset ,
97 ThrowErrorMsgIf( superset.primary_entity_rank() < subset.primary_entity_rank(),
98 method <<
"(...) FAILED Requirement that " <<
99 "Part[ " << superset.name() <<
100 " , rank(" << superset.primary_entity_rank() <<
101 ") ] has greater rank than " <<
102 "Part[ " << subset.name() <<
103 " , rank(" << subset.primary_entity_rank() <<
") ]");
109 Part * PartRepository::universal_part()
const 111 return m_universal_part;
114 const PartVector & PartRepository::get_all_parts()
const 121 Trace_(
"stk_classic::mesh::impl::PartRepository::declare_part");
123 const PartVector & all_parts = get_all_parts();
124 Part * p =
find( all_parts, arg_name );
127 p = declare_part_impl( arg_name, arg_rank );
130 p->m_partImpl.set_primary_entity_rank(arg_rank);
138 static const char method[] =
"stk_classic::mesh::impl::PartRepository::declare_part" ;
143 for ( PartVector::const_iterator
144 i = part_intersect.begin() ; i != part_intersect.end() ; ++i ) {
145 Part *
const p = *i ;
146 assert_superset( *m_universal_part, *p , method );
152 PartVector::const_iterator j = part_intersect.begin();
153 for ( ; j != part_intersect.end() &&
154 !
contain( (*j)->supersets() , *p ) ; ++j );
155 if ( j == part_intersect.end() ) {
156 pset_clean.push_back( p );
164 if ( 1 == pset_clean.size() ) {
169 const char separator[] =
"^" ;
174 EntityRank p_rank = InvalidEntityRank;
177 for ( PartVector::iterator
178 i = pset_clean.begin() ; i != pset_clean.end() ; ++i ) {
179 if ( i != pset_clean.begin() ) { p_name.append( separator ); }
180 p_name.append( (*i)->name() );
181 if ( (*i)->primary_entity_rank() < p_rank ) {
182 p_rank = (*i)->primary_entity_rank();
187 const PartVector & all_parts = get_all_parts();
188 p =
find( all_parts, p_name );
192 p = declare_part_impl( p_name , p_rank );
196 p->m_partImpl.set_intersection_of( pset_clean );
198 for ( PartVector::iterator
199 i = pset_clean.begin() ; i != pset_clean.end() ; ++i ) {
200 declare_subset( **i, *p );
206 ThrowInvalidArgMsgIf( pset_clean != p->intersection_of(),
207 p_name <<
" FAILED FROM MALICIOUS ABUSE" );
215 Part * PartRepository::declare_part_impl(
const std::string & name, EntityRank rank)
217 size_t ordinal = get_all_parts().size();
218 Part * part =
new Part(m_meta_data,name,rank,ordinal);
219 declare_subset_impl(*m_universal_part, *part);
220 m_all_parts.push_back(part);
225 void PartRepository::declare_subset_impl( Part & superset_part, Part & subset_part )
227 superset_part.m_partImpl.add_part_to_subset( subset_part );
228 subset_part.m_partImpl.add_part_to_superset( superset_part );
232 void PartRepository::declare_subset( Part & superset, Part & subset )
234 static const char method[] =
"stk_classic::mesh::impl::PartRepository::declare_subset" ;
237 if ( !
contain( subset.supersets() , superset ) ) {
239 assert_not_same( superset , subset , method );
240 assert_not_superset( superset , subset , method );
241 assert_same_universe( superset , subset , method );
242 assert_rank_ordering( superset , subset , method );
247 declare_subset_impl( superset, subset );
251 const PartVector & subset_subsets = subset.subsets();
252 for ( PartVector::const_iterator
253 i = subset_subsets.begin() ; i != subset_subsets.end() ; ++i ) {
254 declare_subset( superset, **i );
257 const PartVector & superset_supersets = superset.supersets();
258 for ( PartVector::const_iterator
259 i = superset_supersets.begin() ; i != superset_supersets.end() ; ++i ) {
260 declare_subset( **i, subset );
265 const PartVector & superset_subsets = superset.subsets();
266 for ( PartVector::const_iterator
267 i = superset_subsets.begin() ;
268 i != superset_subsets.end() ; ++i ) {
272 if ( ! pint.intersection_of().empty() && ( & pint != & subset ) ) {
276 if (
contain( subset.supersets() , pint.intersection_of() ) ) {
277 declare_subset( pint, subset );
285 void PartRepository::declare_part_relation( Part & root_part, PartRelation relation, Part & target_part )
287 static const char method[] =
"stk_classic::mesh::impl::PartRepository::declare_part_relation" ;
290 assert_not_same( root_part , target_part , method );
291 assert_same_universe( root_part , target_part , method );
292 assert_same( root_part , *relation.m_root , method );
293 assert_same( target_part , *relation.m_target , method );
295 root_part.m_partImpl.add_relation( relation );
296 target_part.m_partImpl.add_relation( relation );
300 PartRepository::PartRepository(MetaData * meta)
302 m_universal_part(NULL),
305 m_universal_part =
new Part( m_meta_data, universal_part_name(), ~0u, 0 );
306 m_all_parts.push_back(m_universal_part);
309 PartRepository::~PartRepository()
312 for ( PartVector::const_iterator i = m_all_parts.begin() ;
313 i != m_all_parts.end() ; ++i) {
315 try {
delete part ; }
catch(...) {}
void order(PartVector &v)
Order a collection of parts: invoke sort and then unique.
bool contain(const PartVector &v, const Part &part)
Query containment within properly ordered PartVector.
Part & declare_part(FEMMetaData &meta_data, const std::string &name)
Declare a part with a given cell topology. This is just a convenient function that wraps FEMMetaData'...
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Part * find(const PartVector &parts, const std::string &name)
Find a part by name in a collection of parts.