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