Sierra Toolkit  Version of the Day
UnitTestProperty.cpp
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 
10 #include <sstream>
11 #include <stdexcept>
12 
13 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
14 
15 #include <stk_util/parallel/Parallel.hpp>
16 
17 #include <stk_mesh/base/MetaData.hpp>
18 #include <stk_mesh/base/Part.hpp>
19 #include <stk_mesh/base/Property.hpp>
20 #include <stk_mesh/baseImpl/PartRepository.hpp>
21 #include <stk_mesh/baseImpl/EntityRepository.hpp>
22 #include <stk_mesh/fem/FEMMetaData.hpp>
23 #include <stk_mesh/fem/FEMHelpers.hpp>
24 
28 
29 namespace {
30 
31 STKUNIT_UNIT_TEST(UnitTestProperty, testProperty)
32 {
33  const int spatial_dimension = 3;
34  MetaData meta_data(stk_classic::mesh::fem::entity_rank_names(spatial_dimension));
35  MetaData meta_data2(stk_classic::mesh::fem::entity_rank_names(spatial_dimension));
36  unsigned size = 0;
37  unsigned EntityRank = 0;
38 
39  Property<int> & pi = meta_data.declare_property<int>("my_i");
40  Property<double> & pf = meta_data.declare_property<double>("my_d");
41  Property<double> & px = meta_data.declare_property<double>("my_x");
42  Property<double> & pa = meta_data.declare_property<double>("my_array",5);
43 
44  const Property<int> & pi2 = meta_data.declare_property<int>("my_i5");
45  Property<double> & pb = meta_data.declare_property<double>("my_y",0);
46  Property<int> & pi3 = meta_data.declare_property<int>("my_i", pi.size());
47  Property<unsigned> & pi_unsigned = meta_data.declare_property<unsigned>("string_unsigned", size);
48  const Property<unsigned> & pi_unsigned_const = meta_data.declare_property<unsigned>("string_unsigned", size);
49  Property<unsigned> & pi_unsigned_2 = meta_data.declare_property<unsigned>("string_unsigned_2");
50  const Property<unsigned> & pi_unsigned_const_2 = meta_data.declare_property<unsigned>("string_unsigned_2");
51  Property<double> & pProp = meta_data.declare_property<double>("string_correct_new_double", pb.size());
52  Part & part_not_equal_to_pi2 = meta_data2.declare_part( "part_not_equal_to_pi2" );
53  Part & part_not_equal_to_pi = meta_data2.declare_part( "part_not_equal_to_pi");
54  Part & part_not_equal_to_pi2_2 = meta_data2.declare_part( "part_not_equal_to_pi2_2", EntityRank );
55  Part & part = meta_data.declare_part( "part", EntityRank );
56 
57  meta_data.commit();
58  meta_data2.commit();
59 
60  STKUNIT_ASSERT( pi.type_is<int>() );
61  STKUNIT_ASSERT( pf.type_is<double>() );
62  STKUNIT_ASSERT( px.type_is<double>() );
63  STKUNIT_ASSERT( pa.type_is<double>() );
64 
65  STKUNIT_ASSERT( ! pi.type_is<double>() );
66  STKUNIT_ASSERT( ! pa.type_is<int>() );
67 
68  STKUNIT_ASSERT_EQUAL( pi.size() , 1u );
69  STKUNIT_ASSERT_EQUAL( pf.size() , 1u );
70  STKUNIT_ASSERT_EQUAL( px.size() , 1u );
71  STKUNIT_ASSERT_EQUAL( pa.size() , 5u );
72 
73  //Covers add_property in Property.hpp and put_property in MetaData.hpp
74  meta_data.put_property( pi , meta_data.locally_owned_part() );
75  //covers property_data in Property.hpp
76  STKUNIT_ASSERT( stk_classic::mesh::property_data( pi , meta_data.locally_owned_part() ) != NULL);
77  STKUNIT_ASSERT( !stk_classic::mesh::property_data( px , meta_data.locally_owned_part() ) );
78 
79  //Coverage of virtual const data_type * data( unsigned key ) const in Property.hpp
80  STKUNIT_ASSERT_FALSE( stk_classic::mesh::property_data( pi2 , meta_data.locally_owned_part() ) != NULL);
81 
82  //Cover unsigned data type in Property.hpp
83  STKUNIT_ASSERT_FALSE( stk_classic::mesh::property_data( pi_unsigned , meta_data.locally_owned_part() ) != NULL);
84  STKUNIT_ASSERT_FALSE( stk_classic::mesh::property_data( pi_unsigned_2 , meta_data.locally_owned_part() ) != NULL);
85  STKUNIT_ASSERT( ! pi_unsigned.type_is<int>() );
86 
87  //Cover unsigned const data type in Property.hpp
88  STKUNIT_ASSERT_FALSE( stk_classic::mesh::property_data( pi_unsigned_const , meta_data.locally_owned_part() ) != NULL);
89  STKUNIT_ASSERT_FALSE( stk_classic::mesh::property_data( pi_unsigned_const_2 , meta_data.locally_owned_part() ) != NULL);
90 
91  //Coverage of Property.hpp to test two unequal parts for const property_type and cover of property_data_throw
92  STKUNIT_ASSERT_THROW(property_data( pi2 , part_not_equal_to_pi2 ),
93  std::logic_error);
94  STKUNIT_ASSERT_THROW(property_data( pi2 , part_not_equal_to_pi2_2 ),
95  std::logic_error);
96 
97  //Test get_property_base with an correct type in Property.cpp
98  const std::string& string_correct_double = "my_d";
99  meta_data.get_property<double>( string_correct_double );
100 
101  //Test get_property_base with an incorrect type and size in Property.cpp
102  const std::string& string_incorrect_double = "my_i";
103  STKUNIT_ASSERT_THROW(
104  meta_data.get_property<double>( string_incorrect_double ),
105  std::runtime_error
106  );
107 
108  //More coverage of Property.hpp to test two parts with different meta data
109  STKUNIT_ASSERT_THROW(stk_classic::mesh::property_data( pi , part_not_equal_to_pi ),
110  std::logic_error);
111 
112  //Final coverage of MetaData.hpp - declare_property
113  const std::string& string_correct_new_double = "my_y";
114  meta_data.get_property<double>( string_correct_new_double );
115  STKUNIT_ASSERT( (pb).type_is<double>() );
116 
117  //Coverage of add_property in Property.hpp
118  meta_data.put_property( pProp, part);
119 
120  //Coverage of declare_property in MetaData.hpp
121  STKUNIT_ASSERT( pb.type_is<double>() );
122 
123  //Further coverage of declare_property in MetaData.hpp ( pv != NULL)
124  STKUNIT_ASSERT( pi3.type_is<int>() );
125 
126 }
127 }
Property with defined data type and multi-dimensions (if any)
The manager of an integrated collection of parts and fields.
Definition: MetaData.hpp:56
const property_type::data_type * property_data(const property_type &prop, const Part &part)
Query pointer to property data for a given part.
Definition: Property.hpp:44
unsigned size() const
Query number of members, if an array.
An application-defined subset of a problem domain.
Definition: Part.hpp:49
bool type_is() const
Query if the scalar type is DataType.