13 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 15 #include <stk_util/parallel/Parallel.hpp> 17 #include <stk_mesh/base/MetaData.hpp> 18 #include <stk_mesh/base/BulkData.hpp> 19 #include <stk_mesh/base/GetEntities.hpp> 20 #include <stk_mesh/base/Field.hpp> 21 #include <stk_mesh/base/FieldData.hpp> 22 #include <stk_mesh/base/Comm.hpp> 23 #include <stk_mesh/base/EntityComm.hpp> 24 #include <stk_mesh/base/Part.hpp> 25 #include <stk_mesh/base/Entity.hpp> 26 #include <stk_mesh/base/GetBuckets.hpp> 27 #include <stk_mesh/base/Bucket.hpp> 28 #include <stk_mesh/base/BulkModification.hpp> 29 #include <stk_mesh/base/Entity.hpp> 30 #include <stk_mesh/base/Bucket.hpp> 31 #include <stk_mesh/base/Ghosting.hpp> 33 #include <stk_mesh/fem/FEMMetaData.hpp> 34 #include <stk_mesh/fem/FEMHelpers.hpp> 36 #include <stk_mesh/baseImpl/BucketImpl.hpp> 38 #include <stk_mesh/fixtures/BoxFixture.hpp> 40 #include <Shards_BasicTopologies.hpp> 47 using stk_classic::mesh::EntityRank;
48 using stk_classic::mesh::EntityId;
52 using stk_classic::mesh::BucketIterator;
62 const EntityRank NODE_RANK = FEMMetaData::NODE_RANK;
64 STKUNIT_UNIT_TEST(UnitTestingOfBucket, testBucket)
74 std::vector<std::string> entity_names(10);
75 for (
size_t i = 0 ; i < 10 ; ++i ) {
76 std::ostringstream name ;
77 name <<
"EntityRank" << i ;
78 entity_names[i] = name.str();
82 unsigned max_bucket_size = 4;
85 BulkData& bulk = fixture.bulk_data();
89 unsigned number_of_states = 4;
97 put_field ( temperature , NODE_RANK , universal );
98 put_field ( volume , element_rank , universal );
102 int root_box[3][2] = { { 0,4 } , { 0,5 } , { 0,6 } };
103 int local_box[3][2] = { { 0,0 } , { 0,0 } , { 0,0 } };
105 fixture.generate_boxes( root_box, local_box );
114 gold1 =
"Bucket( EntityRank0 : {UNIVERSAL} {OWNS} )";
116 gold1 =
"Bucket( EntityRank0 : {UNIVERSAL} )";
118 std::stringstream out1_str;
120 bool equal = (gold1 == out1_str.str());
121 STKUNIT_ASSERT_EQUAL ( equal,
true );
128 for (
size_t i = 0 ; i != 10 ; ++i )
134 const std::vector< FieldBase * > &field_bases = meta.
get_fields();
135 STKUNIT_ASSERT_THROW(
field_data_valid ( *field_bases[0] , *bulk.
buckets(3)[0] , 1 ,
"error" ) , std::runtime_error);
137 STKUNIT_ASSERT_THROW(
field_data_valid ( *field_bases[0] , *bulk.
buckets(3)[0] , 99 ,
"error" ) , std::runtime_error);
142 BulkData bulk2( meta2 , pm , max_bucket_size );
145 meta2.declare_field <
ScalarFieldType > (
"temperature2" , number_of_states );
147 meta2.declare_field <
ScalarFieldType > (
"volume2" , number_of_states );
148 Part & universal2 = meta2.universal_part ();
149 put_field ( temperature2 , NODE_RANK , universal2 );
150 put_field ( volume2 , element_rank , universal2 );
154 const std::vector< FieldBase * > &field_bases2 = meta2.get_fields();
155 STKUNIT_ASSERT_THROW(
field_data_valid ( *field_bases2[0] , *bulk.
buckets(0)[0] , 1 ,
"error" ) , std::runtime_error);
164 STKUNIT_ASSERT ( bulk.
buckets(0)[0]->member_any ( tmp ) );
166 STKUNIT_ASSERT ( bulk.
buckets(0)[0]->member ( **meta.
get_parts().begin() ) );
170 STKUNIT_UNIT_TEST(UnitTestingOfBucket, testGetInvolvedParts)
177 const int spatial_dimension = 3;
181 const EntityRank edge_rank = meta.
edge_rank();
187 Part & partLeft_1 = stk_classic::mesh::fem::declare_part<shards::Tetrahedron<4> >( meta,
"block_left_1" );
189 Part & partLeft_2 = stk_classic::mesh::fem::declare_part<shards::Tetrahedron<4> >( meta,
"block_left_2" );
194 union_parts.push_back(&partLeft_1);
195 union_parts.push_back(&partLeft_2);
197 BulkData bulk( FEMMetaData::get_meta_data(meta) , pm , 100 );
199 add_part4.push_back ( &partLeft_1 );
206 for (
int id_base = 0 ; id_base < 99 ; ++id_base )
208 int new_id = size * id_base + rank + 1;
215 const std::vector<Bucket*> & buckets = bulk.
buckets( element_rank );
217 std::vector<Bucket*>::const_iterator k;
222 get_involved_parts( union_parts, **k, involved_parts);
226 get_involved_parts( union_parts2, **k, involved_parts);
229 const std::vector<Bucket*> & buckets2 = bulk.
buckets( NODE_RANK );
230 std::vector<Bucket*>::const_iterator k2;
232 k2 = buckets2.begin();
233 get_involved_parts( union_parts, **k2, involved_parts);
238 BulkData bulk2( FEMMetaData::get_meta_data(meta2) , pm , 4 );
240 unsigned number_of_states = 4;
243 meta2.declare_field <
ScalarFieldType >(
"temperature2" , number_of_states);
247 Part & universal = meta2.universal_part ();
248 put_field ( temperature2 , NODE_RANK , universal );
249 put_field ( volume2 , element_rank , universal );
253 bulk2.modification_begin();
254 bulk2.declare_entity( edge_rank, rank+1 , no_part );
255 bulk2.modification_end();
258 STKUNIT_UNIT_TEST(UnitTestingOfBucket, testBucket2)
265 const int spatial_dimension = 3;
267 const EntityRank element_rank = meta.element_rank();
270 involved_parts[0] = & meta.universal_part();
271 involved_parts[1] = & meta.locally_owned_part();
273 Part & partLeft_1 = meta.declare_part(
"block_left_1", element_rank);
275 Part & partLeft_3 = stk_classic::mesh::fem::declare_part<shards::Tetrahedron<4> >( meta,
"block_left_3" );
279 BulkData bulk( FEMMetaData::get_meta_data(meta) , pm , 100 );
280 std::vector<Part *> add_part4;
281 add_part4.push_back ( &partLeft_1 );
288 for (
int id_base = 0 ; id_base < 99 ; ++id_base )
290 int new_id = size * id_base + rank;
296 const std::vector<Bucket*> & buckets2 = bulk.
buckets( element_rank );
298 std::vector<Bucket*>::const_iterator k2;
300 k2 = buckets2.begin();
305 std::vector<std::string> entity_names(10);
307 for (
size_t i = 0 ; i < 10 ; ++i ) {
308 std::ostringstream name ;
309 name <<
"EntityRank" << i ;
310 entity_names[i] = name.str();
316 unsigned number_of_states = 4;
319 meta2.declare_field <
ScalarFieldType >(
"temperature2" , number_of_states);
322 Part & universal = meta2.universal_part ();
323 put_field ( temperature2 , NODE_RANK , universal );
324 put_field ( volume2 , element_rank , universal );
332 std::ostringstream oss;
336 STKUNIT_ASSERT_EQUAL (
has_superset ( b2 , partLeft_3 ) ,
false );
340 enum { KEY_TMP_BUFFER_SIZE = 64 };
342 const unsigned max = ~(0u);
344 unsigned key_tmp_buffer[ KEY_TMP_BUFFER_SIZE ];
346 std::vector<unsigned> key_tmp_vector ;
348 const unsigned key_size = 2 + 3 ;
350 unsigned *
const key =
351 ( key_size <= KEY_TMP_BUFFER_SIZE )
353 : ( key_tmp_vector.resize( key_size ) , & key_tmp_vector[0] );
356 key[ key[0] = 3 + 1 ] = max;
359 unsigned *
const k = key + 1 ;
360 for (
unsigned i = 0 ; i < 3 ; ++i ) { k[i] = 1 ; }
378 STKUNIT_UNIT_TEST(UnitTestingOfBucket, testEntityComm)
386 const int spatial_dimension = 3;
389 BulkData bulk ( FEMMetaData::get_meta_data(meta) , pm , 100 );
390 std::vector<Part *> add_part4;
392 Part & partLeft_1 = stk_classic::mesh::fem::declare_part<shards::Tetrahedron<4> >( meta,
"block_left_1" );
395 add_part4.push_back ( &partLeft_1 );
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
Field base class with an anonymous data type and anonymous multi-dimension.
bool has_superset(const Bucket &bucket, const unsigned &ordinal)
Is this bucket a subset of the given part by partID.
This is a class for selecting buckets based on a set of meshparts and set logic.
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
field_type & put_field(field_type &field, EntityRank entity_rank, const Part &part, const void *init_value=NULL)
Declare a field to exist for a given entity type and Part.
Field with defined data type and multi-dimensions (if any)
An application-defined subset of a problem domain.
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
unsigned parallel_size() const
Size of the parallel machine.
bool modification_begin()
Begin a modification phase during which the mesh bulk data could become parallel inconsistent. This is a parallel synchronous call. The first time this method is called the mesh meta data is verified to be committed and parallel consistent. An exception is thrown if this verification fails.
bool field_data_valid(const FieldBase &f, const Bucket &k, unsigned ord, const char *required_by)
Check for existence of field data.
unsigned parallel_machine_size(ParallelMachine parallel_machine)
Member function parallel_machine_size ...
Manager for an integrated collection of entities, entity relations, and buckets of field data...
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Entity & declare_entity(EntityRank ent_rank, EntityId ent_id, const PartVector &parts)
Create or retrieve a locally owned entity of a given rank and id.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
PairIter< std::vector< EntityCommInfo >::const_iterator > PairIterEntityComm
Span of ( communication-subset-ordinal , process-rank ) pairs for the communication of an entity...
A container for the field data of a homogeneous collection of entities.
void update_field_data_states() const
Rotate the field data of multistate fields.
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)