|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 - 2011 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 #include <stk_io/util/Gmesh_STKmesh_Fixture.hpp> 00009 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 00010 00011 #include <stk_mesh/base/FieldData.hpp> 00012 #include <stk_mesh/base/GetEntities.hpp> 00013 00014 # include <stk_mesh/fem/FEMHelpers.hpp> 00015 00016 #include <stk_mesh/fem/CoordinateSystems.hpp> 00017 00018 #include <Shards_BasicTopologies.hpp> 00019 #include <Shards_CellTopologyData.h> 00020 00021 #include <Ioss_Utils.h> 00022 00023 #include <assert.h> 00024 00025 enum { SpaceDim = 3 }; 00026 00027 STKUNIT_UNIT_TEST(UnitTestGmeshFixture, testUnit) 00028 { 00029 const size_t num_x = 1; 00030 const size_t num_y = 2; 00031 const size_t num_z = 3; 00032 const size_t num_surf = 6; 00033 std::string config_mesh = Ioss::Utils::to_string(num_x) + "x" + 00034 Ioss::Utils::to_string(num_y) + "x" + 00035 Ioss::Utils::to_string(num_z) + "|sideset:xXyYzZ"; 00036 stk_classic::io::util::Gmesh_STKmesh_Fixture fixture(MPI_COMM_WORLD, config_mesh); 00037 stk_classic::mesh::fem::FEMMetaData & fem_meta = stk_classic::mesh::fem::FEMMetaData::get( fixture.getMetaData() ); 00038 00039 fixture.commit(); 00040 00041 const std::vector<std::string> & sideset_names = fixture.getSidesetNames(); 00042 STKUNIT_ASSERT_EQUAL( num_surf, sideset_names.size() ); 00043 00044 for( size_t i = 0; i < num_surf; ++i ) { 00045 std::string surf_name = (std::string)"surface_" + Ioss::Utils::to_string(i+1); 00046 STKUNIT_ASSERT(surf_name == sideset_names[i]); 00047 } 00048 00049 std::vector<size_t> num_surf_elem(3); 00050 num_surf_elem[0] = num_y * num_z; 00051 num_surf_elem[1] = num_x * num_z; 00052 num_surf_elem[2] = num_x * num_y; 00053 00054 for( size_t i = 0; i < num_surf/2; ++i ) 00055 { 00056 STKUNIT_ASSERT_EQUAL( num_surf_elem[i], fixture.getSurfElemCount(2*i) ); 00057 STKUNIT_ASSERT_EQUAL( num_surf_elem[i], fixture.getSurfElemCount(2*i+1) ); 00058 } 00059 00060 const size_t total_side_count = 2 * (num_surf_elem[0]+num_surf_elem[1]+num_surf_elem[2]); 00061 STKUNIT_ASSERT_EQUAL( total_side_count, fixture.getSideCount() ); 00062 00063 const size_t total_elem_count = num_x * num_y * num_z; 00064 STKUNIT_ASSERT_EQUAL( total_elem_count, fixture.getElemCount() ); 00065 00066 const size_t total_node_count = (num_x+1) * (num_y+1) * (num_z+1); 00067 STKUNIT_ASSERT_EQUAL( total_node_count, fixture.getNodeCount() ); 00068 00069 // Needed to test field data 00070 stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian> * coord_field = 00071 fixture.getMetaData().get_field<stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian> >("coordinates"); 00072 STKUNIT_ASSERT( coord_field ); 00073 00074 // All side buckets 00075 const std::vector<stk_classic::mesh::Bucket*> & all_side_buckets = fixture.getBulkData().buckets( fem_meta.side_rank() ); 00076 00077 std::vector<stk_classic::mesh::Entity *> entities; 00078 00079 const stk_classic::mesh::PartVector & side_parts = fixture.getSideParts(); 00080 STKUNIT_ASSERT_EQUAL( sideset_names.size(), side_parts.size() ); 00081 00082 for( size_t ifset = 0; ifset < side_parts.size(); ++ifset ) 00083 { 00084 std::pair<int, double> expected = fixture.getSurfCoordInfo(ifset); 00085 00086 stk_classic::mesh::Selector selector = *side_parts[ifset]; 00087 entities.clear(); 00088 stk_classic::mesh::get_selected_entities(selector, all_side_buckets, entities); 00089 STKUNIT_ASSERT_EQUAL( fixture.getSurfElemCount(ifset), entities.size() ); 00090 00091 for ( size_t i = 0 ; i < entities.size() ; ++i ) { 00092 stk_classic::mesh::Entity & side = *entities[i] ; 00093 00094 const CellTopologyData * cell_topology = stk_classic::mesh::fem::get_cell_topology(side).getCellTopologyData(); 00095 00096 STKUNIT_ASSERT( cell_topology ); 00097 00098 stk_classic::mesh::PairIterRelation rel = side.relations( stk_classic::mesh::fem::FEMMetaData::NODE_RANK ); 00099 00100 STKUNIT_ASSERT_EQUAL( cell_topology->node_count, rel.size() ); 00101 00102 for ( unsigned j = 0 ; j < cell_topology->node_count ; ++j ) 00103 { 00104 stk_classic::mesh::Entity & rel_node = *rel[j].entity(); 00105 double * coords = stk_classic::mesh::field_data(*coord_field, rel_node); 00106 STKUNIT_ASSERT( coords ); 00107 //std::cerr << "( " << coords[0] << ", " << coords[1] << ", " << coords[2] << ")" << std::endl; 00108 00109 STKUNIT_ASSERT_DOUBLE_EQ(expected.second, coords[expected.first]); 00110 } 00111 //std::cerr << std::endl; 00112 } 00113 } 00114 } 00115