Sierra Toolkit Version of the Day
UnitTestProperty.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #include <sstream>
00011 #include <stdexcept>
00012 
00013 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00014 
00015 #include <stk_util/parallel/Parallel.hpp>
00016 
00017 #include <stk_mesh/base/MetaData.hpp>
00018 #include <stk_mesh/base/Part.hpp>
00019 #include <stk_mesh/base/Property.hpp>
00020 #include <stk_mesh/baseImpl/PartRepository.hpp>
00021 #include <stk_mesh/baseImpl/EntityRepository.hpp>
00022 #include <stk_mesh/fem/FEMMetaData.hpp>
00023 #include <stk_mesh/fem/FEMHelpers.hpp>
00024 
00025 using stk::mesh::MetaData;
00026 using stk::mesh::Part;
00027 using stk::mesh::Property;
00028 
00029 namespace {
00030 
00031 STKUNIT_UNIT_TEST(UnitTestProperty, testProperty)
00032 {
00033   const int spatial_dimension = 3;
00034   MetaData meta_data(stk::mesh::fem::entity_rank_names(spatial_dimension));
00035   MetaData meta_data2(stk::mesh::fem::entity_rank_names(spatial_dimension));
00036   unsigned size = 0;
00037   unsigned EntityRank = 0;
00038 
00039   Property<int> & pi = meta_data.declare_property<int>("my_i");
00040   Property<double> & pf = meta_data.declare_property<double>("my_d");
00041   Property<double> & px = meta_data.declare_property<double>("my_x");
00042   Property<double> & pa = meta_data.declare_property<double>("my_array",5);
00043 
00044   const Property<int> & pi2 = meta_data.declare_property<int>("my_i5");
00045   Property<double> & pb = meta_data.declare_property<double>("my_y",0);
00046   Property<int> & pi3 = meta_data.declare_property<int>("my_i", pi.size());
00047   Property<unsigned> & pi_unsigned = meta_data.declare_property<unsigned>("string_unsigned", size);
00048   const Property<unsigned> & pi_unsigned_const = meta_data.declare_property<unsigned>("string_unsigned", size);
00049   Property<unsigned> & pi_unsigned_2 = meta_data.declare_property<unsigned>("string_unsigned_2");
00050   const Property<unsigned> & pi_unsigned_const_2 = meta_data.declare_property<unsigned>("string_unsigned_2");
00051   Property<double> & pProp = meta_data.declare_property<double>("string_correct_new_double", pb.size());
00052   Part & part_not_equal_to_pi2 =  meta_data2.declare_part( "part_not_equal_to_pi2" );
00053   Part & part_not_equal_to_pi = meta_data2.declare_part( "part_not_equal_to_pi");
00054   Part & part_not_equal_to_pi2_2 = meta_data2.declare_part( "part_not_equal_to_pi2_2", EntityRank );
00055   Part & part = meta_data.declare_part( "part", EntityRank );
00056 
00057   meta_data.commit();
00058   meta_data2.commit();
00059 
00060   STKUNIT_ASSERT( pi.type_is<int>() );
00061   STKUNIT_ASSERT( pf.type_is<double>() );
00062   STKUNIT_ASSERT( px.type_is<double>() );
00063   STKUNIT_ASSERT( pa.type_is<double>() );
00064 
00065   STKUNIT_ASSERT( ! pi.type_is<double>() );
00066   STKUNIT_ASSERT( ! pa.type_is<int>() );
00067 
00068   STKUNIT_ASSERT_EQUAL( pi.size() , 1u );
00069   STKUNIT_ASSERT_EQUAL( pf.size() , 1u );
00070   STKUNIT_ASSERT_EQUAL( px.size() , 1u );
00071   STKUNIT_ASSERT_EQUAL( pa.size() , 5u );
00072 
00073   //Covers add_property in Property.hpp and put_property in MetaData.hpp
00074   meta_data.put_property( pi , meta_data.locally_owned_part() );
00075   //covers property_data in Property.hpp
00076   STKUNIT_ASSERT( stk::mesh::property_data( pi , meta_data.locally_owned_part() ) != NULL);
00077   STKUNIT_ASSERT( !stk::mesh::property_data( px , meta_data.locally_owned_part() ) );
00078 
00079   //Coverage of virtual const data_type * data( unsigned key ) const in Property.hpp
00080   STKUNIT_ASSERT_FALSE( stk::mesh::property_data( pi2 , meta_data.locally_owned_part() ) != NULL);
00081 
00082   //Cover unsigned data type in Property.hpp
00083   STKUNIT_ASSERT_FALSE( stk::mesh::property_data( pi_unsigned , meta_data.locally_owned_part() ) != NULL);
00084   STKUNIT_ASSERT_FALSE( stk::mesh::property_data( pi_unsigned_2 , meta_data.locally_owned_part() ) != NULL);
00085   STKUNIT_ASSERT( ! pi_unsigned.type_is<int>() );
00086 
00087   //Cover unsigned const data type in Property.hpp
00088   STKUNIT_ASSERT_FALSE( stk::mesh::property_data( pi_unsigned_const , meta_data.locally_owned_part() ) != NULL);
00089   STKUNIT_ASSERT_FALSE( stk::mesh::property_data( pi_unsigned_const_2 , meta_data.locally_owned_part() ) != NULL);
00090 
00091   //Coverage of Property.hpp to test two unequal parts for const property_type and cover of property_data_throw
00092   STKUNIT_ASSERT_THROW(property_data( pi2 , part_not_equal_to_pi2 ),
00093            std::logic_error);
00094   STKUNIT_ASSERT_THROW(property_data( pi2 , part_not_equal_to_pi2_2 ),
00095            std::logic_error);
00096 
00097   //Test get_property_base with an correct type in Property.cpp
00098   const std::string& string_correct_double = "my_d";
00099   meta_data.get_property<double>( string_correct_double );
00100 
00101   //Test get_property_base with an incorrect type and size in Property.cpp
00102   const std::string& string_incorrect_double = "my_i";
00103   STKUNIT_ASSERT_THROW(
00104       meta_data.get_property<double>( string_incorrect_double ),
00105       std::runtime_error
00106       );
00107 
00108   //More coverage of Property.hpp to test two parts with different meta data
00109   STKUNIT_ASSERT_THROW(stk::mesh::property_data( pi , part_not_equal_to_pi ),
00110                        std::logic_error);
00111 
00112   //Final coverage of MetaData.hpp - declare_property
00113   const std::string& string_correct_new_double = "my_y";
00114   meta_data.get_property<double>( string_correct_new_double );
00115   STKUNIT_ASSERT( (pb).type_is<double>() );
00116 
00117   //Coverage of add_property in Property.hpp
00118   meta_data.put_property( pProp, part);
00119 
00120   //Coverage of declare_property in MetaData.hpp
00121   STKUNIT_ASSERT( pb.type_is<double>() );
00122 
00123   //Further coverage of declare_property in MetaData.hpp ( pv != NULL)
00124   STKUNIT_ASSERT( pi3.type_is<int>() );
00125 
00126 }
00127 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines