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/FieldData.hpp> 20 #include <stk_mesh/base/GetBuckets.hpp> 21 #include <stk_mesh/base/GetEntities.hpp> 23 #include <stk_mesh/fem/FEMMetaData.hpp> 24 #include <stk_mesh/fem/CoordinateSystems.hpp> 26 #include <boost/range.hpp> 27 #include <boost/foreach.hpp> 31 const stk_classic::mesh::EntityRank NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
33 typedef shards::ArrayDimTag::size_type size_type;
35 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( ATAG )
36 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( BTAG )
37 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( CTAG )
39 template<
class FieldType >
43 std::ostringstream oss;
45 ArrayType a( f , k.
begin(), k.
end() );
48 oss <<
" BucketArray[" << f.name() <<
"](" ;
50 if ( a.size() != b.size() ) {
51 throw std::runtime_error(
"UnitTestField FAILED BucketArray dimensions not consistant with Bucket::iterator");
55 for (
unsigned i = 0 ; i < ArrayType::Rank ; ++i ) {
56 if ( i ) { oss <<
"," ; }
57 oss << a.dimension(i);
58 if (a.dimension(i) != b.dimension(i)) {
59 throw std::runtime_error(
"UnitTestField FAILED BucketArray dimensions not consistant with Bucket::iterator");
63 oss <<
")" << std::endl ;
66 STKUNIT_UNIT_TEST(UnitTestField, testCartesian)
72 std::string to_str = cartesian_tag.to_string(3 , 1 );
73 std::string expected_str(
"y");
74 STKUNIT_ASSERT_EQUAL( (to_str == expected_str),
true);
77 STKUNIT_ASSERT_THROW( cartesian_tag.to_string(2 , 1 ),
80 size_type expected_idx = 1;
81 size_type idx = cartesian_tag.to_index(3 ,
"y" );
82 STKUNIT_ASSERT_EQUAL( idx, expected_idx );
85 STKUNIT_ASSERT_THROW( cartesian_tag.to_index(2 ,
"z" ),
89 STKUNIT_UNIT_TEST(UnitTestField, testCylindrical)
95 std::string to_str = cylindrical_tag.to_string(3 , 1 );
96 std::string expected_str(
"a");
97 STKUNIT_ASSERT_EQUAL( (to_str == expected_str),
true );
100 STKUNIT_ASSERT_THROW( cylindrical_tag.to_string(2 , 1 ),
101 std::runtime_error );
103 size_type expected_idx = 1;
104 size_type idx = cylindrical_tag.to_index(3 ,
"a" );
105 STKUNIT_ASSERT_EQUAL( idx, expected_idx );
108 STKUNIT_ASSERT_THROW( cylindrical_tag.to_index(2 ,
"z" ),
109 std::runtime_error );
112 STKUNIT_UNIT_TEST(UnitTestField, testFullTensor)
118 std::string to_str = fulltensor_tag.to_string(9 , 1 );
119 std::string expected_str(
"yy");
120 STKUNIT_ASSERT_EQUAL( (to_str == expected_str),
true );
123 STKUNIT_ASSERT_THROW( fulltensor_tag.to_string(2 , 1 ),
124 std::runtime_error );
126 size_type expected_idx = 6;
127 size_type idx = fulltensor_tag.to_index(9 ,
"yx" );
128 STKUNIT_ASSERT_EQUAL( idx, expected_idx );
131 STKUNIT_ASSERT_THROW( fulltensor_tag.to_index(2 ,
"zz" ),
132 std::runtime_error );
135 STKUNIT_UNIT_TEST(UnitTestField, testSymmetricTensor)
142 std::string to_str = symmetrictensor_tag.to_string(9 , 1 );
143 std::string expected_str(
"yy");
144 STKUNIT_ASSERT_EQUAL( (to_str == expected_str),
true);
147 STKUNIT_ASSERT_THROW( symmetrictensor_tag.to_string(2 , 1 ),
148 std::runtime_error );
150 size_type expected_idx = 1;
151 size_type idx = symmetrictensor_tag.to_index(6 ,
"yy" );
152 STKUNIT_ASSERT_EQUAL( idx, expected_idx );
155 STKUNIT_ASSERT_THROW( symmetrictensor_tag.to_index(5 ,
"xz" ),
156 std::runtime_error );
159 STKUNIT_UNIT_TEST(UnitTestField, testFieldDataArray)
162 std::ostringstream oss;
170 const std::string name0(
"test_field_0");
171 const std::string name1(
"test_field_1");
172 const std::string name2(
"test_field_2");
173 const std::string name3(
"test_field_3");
175 const int spatial_dimension = 3;
179 rank_zero_field & f0 = meta_data.declare_field< rank_zero_field >( name0 );
180 rank_one_field & f1 = meta_data.declare_field< rank_one_field >( name1 );
181 rank_three_field & f3 = meta_data.declare_field< rank_three_field >( name3 );
182 rank_two_field & f2 = meta_data.declare_field< rank_two_field >( name2 );
186 STKUNIT_ASSERT_THROW(meta_data.declare_field< error_type >( name1 ),
203 bulk_data.modification_begin();
207 for (
unsigned i = 1 ; i < 11 ; ++i ) {
208 bulk_data.declare_entity( NODE_RANK , i ,
209 std::vector< stk_classic::mesh::Part * >( 1 , & p0 ) );
212 for (
unsigned i = 11 ; i < 21 ; ++i ) {
213 bulk_data.declare_entity( NODE_RANK , i ,
214 std::vector< stk_classic::mesh::Part * >( 1 , & p1 ) );
217 for (
unsigned i = 21 ; i < 31 ; ++i ) {
218 bulk_data.declare_entity( NODE_RANK , i ,
219 std::vector< stk_classic::mesh::Part * >( 1 , & p2 ) );
222 for (
unsigned i = 31 ; i < 41 ; ++i ) {
223 bulk_data.declare_entity( NODE_RANK , i ,
224 std::vector< stk_classic::mesh::Part * >( 1 , & p3 ) );
228 const std::vector< stk_classic::mesh::Bucket *> & node_buckets =
229 bulk_data.buckets( NODE_RANK );
231 for ( std::vector< stk_classic::mesh::Bucket *>::const_iterator
232 ik = node_buckets.begin() ; ik != node_buckets.end() ; ++ik ) {
235 std::vector< stk_classic::mesh::Part * > parts ;
238 for ( std::vector< stk_classic::mesh::Part * >::iterator
239 ip = parts.begin() ; ip != parts.end() ; ++ip ) {
240 oss <<
" " << (*ip)->name();
243 print_bucket_array( f0 , k );
244 print_bucket_array( f1 , k );
245 print_bucket_array( f2 , k );
246 print_bucket_array( f3 , k );
250 STKUNIT_UNIT_TEST(UnitTestField, testFieldWithSelector)
253 std::ostringstream oss;
258 const std::string name0(
"test_field_0");
260 const int spatial_dimension = 3;
264 rank_zero_field & f0 = meta_data.declare_field< rank_zero_field >( name0 );
270 std::cout <<
"select_p0: "<< select_p0 << std::endl;
278 bulk_data.modification_begin();
282 for (
unsigned i = 1 ; i < 11 ; ++i ) {
283 bulk_data.declare_entity( NODE_RANK , i ,
284 std::vector< stk_classic::mesh::Part * >( 1 , & p0 ) );
287 for (
unsigned i = 11 ; i < 21 ; ++i ) {
288 bulk_data.declare_entity( NODE_RANK , i ,
289 std::vector< stk_classic::mesh::Part * >( 1 , & p1 ) );
292 const std::vector< stk_classic::mesh::Bucket *> & node_buckets =
293 bulk_data.buckets( NODE_RANK );
297 STKUNIT_ASSERT_EQUAL( 10u, num );
301 std::cout <<
"select_f0: "<< select_f0 << std::endl;
304 STKUNIT_ASSERT_EQUAL(10u, num_f0);
306 std::vector<stk_classic::mesh::Bucket*> f0_buckets;
308 unsigned num_buckets = f0_buckets.size();
309 STKUNIT_ASSERT_EQUAL(1u, num_buckets);
313 STKUNIT_ASSERT_EQUAL(8u, f0_size);
317 STKUNIT_UNIT_TEST(UnitTestField, testFieldWithSelectorAnd)
320 std::ostringstream oss;
325 const std::string name0(
"test_field_0");
327 const int spatial_dimension = 3;
331 rank_one_field & f0 = meta_data.declare_field< rank_one_field >( name0 );
333 stk_classic::mesh::EntityRank elem_rank = meta_data.element_rank();
340 std::cout <<
"elem_hex_selector: "<< elem_hex_selector << std::endl;
341 std::cout <<
"elem_tet_selector: "<< elem_tet_selector << std::endl;
350 bulk_data.modification_begin();
355 parts.push_back(&elements);
356 parts.push_back(&hex8s);
358 for (
unsigned i = 1 ; i < 11 ; ++i ) {
359 bulk_data.declare_entity( elem_rank , i , parts );
363 parts.push_back(&elements);
364 parts.push_back(&tet4s);
366 for (
unsigned i = 11 ; i < 21 ; ++i ) {
367 bulk_data.declare_entity( elem_rank , i , parts );
370 stk_classic::mesh::BucketVector f0_buckets;
375 STKUNIT_ASSERT_EQUAL(64u, f0_size);
384 STKUNIT_ASSERT_EQUAL(32u, f0_size);
389 STKUNIT_UNIT_TEST(UnitTestField, testFieldWithSelectorInvalid)
392 std::ostringstream oss;
397 const std::string name0(
"test_field_0");
399 const int spatial_dimension = 3;
403 rank_one_field & f0 = meta_data.declare_field< rank_one_field >( name0 );
405 stk_classic::mesh::EntityRank elem_rank = meta_data.element_rank();
412 std::cout <<
"elem_hexA_selector: "<< elem_hexA_selector << std::endl;
413 std::cout <<
"elem_hexB_selector: "<< elem_hexB_selector << std::endl;
416 STKUNIT_ASSERT_THROW(
426 bulk_data.modification_begin();
429 parts.push_back(&hex8s);
430 STKUNIT_ASSERT_THROW(
431 bulk_data.declare_entity( elem_rank , 1 , parts ),
437 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( ATAG )
438 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( BTAG )
439 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( CTAG )
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
static const SymmetricTensor33 & tag()
Singleton.
unsigned count_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets)
Count entities in selected buckets (selected by the given selector instance), and sorted by ID...
unsigned field_data_size(const FieldBase &field) const
Query the size of this field data specified by FieldBase.
Implement an shards::ArrayDimTag for FullTensor.
This is a class for selecting buckets based on a set of meshparts and set logic.
Implement an shards::ArrayDimTag for SymmetricTensor.
static const FullTensor36 & tag()
Singleton.
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.
static const Cartesian3d & tag()
Singleton.
An application-defined subset of a problem domain.
Implement an shards::ArrayDimTag for Cylindrical coordinate dimensions.
Implement an shards::ArrayDimTag for Cartesian coordinate dimensions.
iterator begin() const
Beginning of the bucket.
iterator end() const
End of the bucket.
Manager for an integrated collection of entities, entity relations, and buckets of field data...
void supersets(PartVector &) const
This bucket is a subset of these parts.
AllSelectedBucketsRange get_buckets(const Selector &selector, const BulkData &mesh)
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
A container for the field data of a homogeneous collection of entities.
static const Cylindrical & tag()
Singleton.
Field data Array for a given array field and bucket