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/FieldRelation.hpp> 19 #include <stk_mesh/base/PartRelation.hpp> 20 #include <stk_mesh/base/FieldData.hpp> 22 #include <stk_mesh/baseImpl/PartRepository.hpp> 23 #include <stk_mesh/baseImpl/EntityRepository.hpp> 24 #include <stk_mesh/baseImpl/FieldBaseImpl.hpp> 25 #include <stk_mesh/fem/CoordinateSystems.hpp> 27 #include <Shards_BasicTopologies.hpp> 32 class UnitTestFieldImpl {
34 UnitTestFieldImpl() {}
37 void testFieldRestriction();
38 void testFieldRelation();
47 STKUNIT_UNIT_TEST(UnitTestField, testUnit)
49 stk_classic::mesh::UnitTestFieldImpl ufield;
53 STKUNIT_UNIT_TEST(UnitTestFieldRestriction, testUnit)
55 stk_classic::mesh::UnitTestFieldImpl ufield;
56 ufield.testFieldRestriction();
59 STKUNIT_UNIT_TEST(UnitTestFieldRelation, testUnit)
61 stk_classic::mesh::UnitTestFieldImpl ufield;
62 ufield.testFieldRelation();
76 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( ATAG )
77 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( BTAG )
78 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( CTAG )
79 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( DTAG )
81 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( ATAG )
82 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( BTAG )
83 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( CTAG )
84 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( DTAG )
88 void UnitTestFieldImpl::testField()
96 impl::FieldRepository field_repo;
97 const FieldVector & allocated_fields = field_repo.get_fields();
103 FieldBase *
const fA =
104 field_repo.declare_field( std::string(
"A"),
105 data_traits<double>() ,
111 STKUNIT_ASSERT( allocated_fields.size() == 1 );
112 STKUNIT_ASSERT( fA != NULL );
113 STKUNIT_ASSERT( fA == allocated_fields[0] );
114 STKUNIT_ASSERT( fA->name() == std::string(
"A") );
115 STKUNIT_ASSERT( fA->type_is<
double>() );
116 STKUNIT_ASSERT( fA->state() ==
StateNone );
117 STKUNIT_ASSERT( fA->rank() == 0 );
125 STKUNIT_ASSERT_THROW(
126 field_repo.declare_field(
"A_STKFS_OLD" ,
127 data_traits<double>() ,
133 STKUNIT_ASSERT( allocated_fields.size() == 1 );
142 FieldBase *
const fB =
143 field_repo.declare_field( std::string(
"B"),
150 STKUNIT_ASSERT( allocated_fields.size() == 3 );
151 STKUNIT_ASSERT( fB != NULL );
152 STKUNIT_ASSERT( fB == allocated_fields[1] );
153 STKUNIT_ASSERT( fB->name() == std::string(
"B") );
154 STKUNIT_ASSERT( fB->type_is<
int>() );
155 STKUNIT_ASSERT( fB->state() ==
StateNew );
156 STKUNIT_ASSERT( fB->rank() == 0 );
158 const FieldBase *
const fB_old = allocated_fields[2] ;
159 STKUNIT_ASSERT( fB_old->name() == std::string(
"B_STKFS_OLD") );
160 STKUNIT_ASSERT( fB_old->type_is<
int>() );
161 STKUNIT_ASSERT( fB_old->state() ==
StateOld );
162 STKUNIT_ASSERT( fB_old->rank() == 0 );
167 FieldBase *
const fB_redundant =
168 field_repo.declare_field( std::string(
"B"),
175 STKUNIT_ASSERT( allocated_fields.size() == 3 );
176 STKUNIT_ASSERT( fB == fB_redundant );
183 const shards::ArrayDimTag * dim_tags[] =
184 { & ATAG::tag() , & BTAG::tag() , & CTAG::tag() , & DTAG::tag() };
186 FieldBase *
const fC =
187 field_repo.declare_field( std::string(
"C"),
188 data_traits<double>(),
194 STKUNIT_ASSERT( allocated_fields.size() == 7 );
195 STKUNIT_ASSERT( fC != NULL );
196 STKUNIT_ASSERT( fC == allocated_fields[3] );
197 STKUNIT_ASSERT( fC->name() == std::string(
"C") );
198 STKUNIT_ASSERT( fC->type_is<
double>() );
199 STKUNIT_ASSERT( fC->state() ==
StateNew );
200 STKUNIT_ASSERT( fC->rank() == 3 );
202 const FieldBase *
const fC_n = allocated_fields[4] ;
203 const FieldBase *
const fC_nm1 = allocated_fields[5] ;
204 const FieldBase *
const fC_nm2 = allocated_fields[6] ;
206 STKUNIT_ASSERT( fC == fC->field_state(
StateNP1 ) );
207 STKUNIT_ASSERT( fC_n == fC->field_state(
StateN ) );
208 STKUNIT_ASSERT( fC_nm1 == fC->field_state(
StateNM1 ) );
209 STKUNIT_ASSERT( fC_nm2 == fC->field_state(
StateNM2 ) );
211 STKUNIT_ASSERT( fC == fC_n->field_state(
StateNP1 ) );
212 STKUNIT_ASSERT( fC_n == fC_n->field_state(
StateN ) );
213 STKUNIT_ASSERT( fC_nm1 == fC_n->field_state(
StateNM1 ) );
214 STKUNIT_ASSERT( fC_nm2 == fC_n->field_state(
StateNM2 ) );
216 STKUNIT_ASSERT( fC == fC_nm1->field_state(
StateNP1 ) );
217 STKUNIT_ASSERT( fC_n == fC_nm1->field_state(
StateN ) );
218 STKUNIT_ASSERT( fC_nm1 == fC_nm1->field_state(
StateNM1 ) );
219 STKUNIT_ASSERT( fC_nm2 == fC_nm1->field_state(
StateNM2 ) );
221 STKUNIT_ASSERT( fC == fC_nm2->field_state(
StateNP1 ) );
222 STKUNIT_ASSERT( fC_n == fC_nm2->field_state(
StateN ) );
223 STKUNIT_ASSERT( fC_nm1 == fC_nm2->field_state(
StateNM1 ) );
224 STKUNIT_ASSERT( fC_nm2 == fC_nm2->field_state(
StateNM2 ) );
226 STKUNIT_ASSERT( fC_n->name() == std::string(
"C_STKFS_N") );
227 STKUNIT_ASSERT( fC_n->type_is<
double>() );
228 STKUNIT_ASSERT( fC_n->state() ==
StateN );
229 STKUNIT_ASSERT( fC_n->rank() == 3 );
231 STKUNIT_ASSERT( fC_nm1->name() == std::string(
"C_STKFS_NM1") );
232 STKUNIT_ASSERT( fC_nm1->type_is<
double>() );
233 STKUNIT_ASSERT( fC_nm1->state() ==
StateNM1 );
234 STKUNIT_ASSERT( fC_nm1->rank() == 3 );
236 STKUNIT_ASSERT( fC_nm2->name() == std::string(
"C_STKFS_NM2") );
237 STKUNIT_ASSERT( fC_nm2->type_is<
double>() );
238 STKUNIT_ASSERT( fC_nm2->state() ==
StateNM2 );
239 STKUNIT_ASSERT( fC_nm2->rank() == 3 );
245 for (
unsigned i = 0 ; i < allocated_fields.size() ; ++i ) {
246 FieldBase *
const f = allocated_fields[i] ;
247 STKUNIT_ASSERT( f->mesh_meta_data_ordinal() == i );
255 entity_dimension_tag.name();
263 void UnitTestFieldImpl::testFieldRestriction()
268 for (
unsigned i = 1 ; i < 8 ; ++i ) {
269 stride[i] = ( i + 1 ) * stride[i-1] ;
272 std::vector< std::string > dummy_names(1);
273 dummy_names[0].assign(
"dummy");
275 MetaData meta_data(dummy_names);
277 const FieldVector & allocated_fields = meta_data.get_fields();
283 FieldBase *
const f2 =
284 &meta_data.declare_field<
VectorField>( std::string(
"F2"), 1 );
288 FieldBase *
const f3 =
289 &meta_data.declare_field<
VectorField>( std::string(
"F3"), 2);
291 FieldBase *
const f3_old = f3->field_state(
StateOld ) ;
295 STKUNIT_ASSERT( allocated_fields.size() == 3 );
296 STKUNIT_ASSERT( f2 == allocated_fields[0] );
297 STKUNIT_ASSERT( f3 == allocated_fields[1] );
302 STKUNIT_ASSERT( f2 == f2->field_state(
StateNone ) );
303 STKUNIT_ASSERT( NULL == f2->field_state(
StateOld ) );
304 STKUNIT_ASSERT( f3 == f3->field_state(
StateNew ) );
305 STKUNIT_ASSERT( f3_old == f3->field_state(
StateOld ) );
306 STKUNIT_ASSERT( NULL == f3->field_state(
StateNM1 ) );
307 STKUNIT_ASSERT( f3 == f3_old->field_state(
StateNew ) );
308 STKUNIT_ASSERT( f3_old == f3_old->field_state(
StateOld ) );
309 STKUNIT_ASSERT( NULL == f3_old->field_state(
StateNM1 ) );
314 Part & pA = meta_data.declare_part( std::string(
"A") , 0 );
315 Part & pB = meta_data.declare_part( std::string(
"B") , 0 );
316 Part & pC = meta_data.declare_part( std::string(
"C") , 0 );
317 Part & pD = meta_data.declare_part( std::string(
"D") , 0 );
321 meta_data.declare_field_restriction(*f3, 0 , pA , stride );
322 meta_data.declare_field_restriction(*f3, 1 , pB , stride + 1 );
323 meta_data.declare_field_restriction(*f3, 2 , pC , stride + 2 );
327 STKUNIT_ASSERT( f3->restrictions().size() == 3 );
328 STKUNIT_ASSERT( f3->restrictions()[0] ==
329 FieldRestriction( 0 , pA.mesh_meta_data_ordinal() ) );
330 STKUNIT_ASSERT( f3->restrictions()[1] ==
331 FieldRestriction( 1 , pB.mesh_meta_data_ordinal() ) );
332 STKUNIT_ASSERT( f3->restrictions()[2] ==
333 FieldRestriction( 2 , pC.mesh_meta_data_ordinal() ) );
335 meta_data.declare_field_restriction(*f3, 0 , pB , stride + 1 );
337 STKUNIT_ASSERT_EQUAL( f3->max_size( 0 ) , 20u );
342 unsigned bad_stride[4] = { 5 , 4 , 6 , 3 };
343 STKUNIT_ASSERT_THROW(
344 meta_data.declare_field_restriction(*f3, 0 , pA , bad_stride ),
347 STKUNIT_ASSERT( f3->restrictions().size() == 4 );
353 STKUNIT_ASSERT_THROW(
354 meta_data.declare_field_restriction(*f3, 0 , pA , stride + 1 ),
357 STKUNIT_ASSERT( f3->restrictions().size() == 4 );
362 STKUNIT_ASSERT( f3->restrictions().size() == 4 );
368 std::cout<<
"pA ord: "<<pA.mesh_meta_data_ordinal()<<
", pD ord: "<<pD.mesh_meta_data_ordinal()<<std::endl;
369 meta_data.declare_part_subset( pD, pA );
370 meta_data.declare_field_restriction(*f2, 0 , pA , stride );
371 meta_data.declare_field_restriction(*f2, 0 , pD , stride );
373 STKUNIT_ASSERT( f2->restrictions().size() == 1 );
376 const FieldBase::Restriction & rA = f2->restriction( 0 , pA );
377 const FieldBase::Restriction & rD = f2->restriction( 0 , pD );
378 STKUNIT_ASSERT( & rA == & rD );
379 STKUNIT_ASSERT( rA.part_ordinal() == pD.mesh_meta_data_ordinal() );
389 meta_data.declare_field_restriction(*f2, 0 , pB , stride + 1 );
390 STKUNIT_ASSERT_THROW(
391 meta_data.declare_part_subset( pD, pB ),
400 FieldBase *
const f4 =
401 &meta_data.declare_field<
VectorField>( std::string(
"F4"),
404 meta_data.declare_part_subset( pD, pA );
405 meta_data.declare_part_subset( pC, pB );
407 meta_data.declare_field_restriction(*f4, 0 , pA , stride );
408 meta_data.declare_field_restriction(*f4, 1 , pB , stride + 1 );
421 FieldBase *
const f5 =
422 &meta_data.declare_field<
VectorField>( std::string(
"F5"),
425 unsigned stride2[8] ;
427 for (
unsigned i = 1 ; i < 3 ; ++i ) {
428 stride2[i] = stride[i-1];
430 for (
unsigned i = 3 ; i < 8 ; ++i ) {
433 meta_data.declare_field_restriction(*f5, 0 , pA, stride2 );
442 unsigned arg_no_stride[2];
444 arg_no_stride[0] = 1;
445 arg_no_stride[1] = 0;
447 STKUNIT_ASSERT_THROW(
448 meta_data.declare_field_restriction(*f2, 0, pA, arg_no_stride),
455 const FieldRestrictionVector & rMap = f3->restrictions();
456 const FieldRestrictionVector::const_iterator ie = rMap.end() ;
457 FieldRestrictionVector::const_iterator i = rMap.begin();
462 for ( ; i != ie ; ++i ) {
464 const unsigned len = pA.mesh_meta_data_ordinal() ? i->stride( pA.mesh_meta_data_ordinal() - 1 ) : 1 ;
465 if ( max < len ) { max = len ; }
472 void UnitTestFieldImpl::testFieldRelation()
476 FieldRelation rB(rA);
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
Previous state of a field with three+ states.
Newest state of a field with two states.
static const EntityDimension & tag()
Singleton.
Field with defined data type and multi-dimensions (if any)
State of a field with one state.
EntityId entity_id(const EntityKey &key)
Given an entity key, return the identifier for the entity.
Previous-2 state of a field with four+ states.
Previous state of a field with two states.
Implement ArrayDimTag for the entity count dimension of a BucketArray.
Newest state of a field with three+ states.
Previous-1 state of a field with three+ states.