Sierra Toolkit  Version of the Day
UnitTestGmeshFixture.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 - 2011 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 #include <stk_io/util/Gmesh_STKmesh_Fixture.hpp>
9 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
10 
11 #include <stk_mesh/base/FieldData.hpp>
12 #include <stk_mesh/base/GetEntities.hpp>
13 
14 # include <stk_mesh/fem/FEMHelpers.hpp>
15 
16 #include <stk_mesh/fem/CoordinateSystems.hpp>
17 
18 #include <Shards_BasicTopologies.hpp>
19 #include <Shards_CellTopologyData.h>
20 
21 #include <Ioss_Utils.h>
22 
23 #include <assert.h>
24 
25 enum { SpaceDim = 3 };
26 
27 STKUNIT_UNIT_TEST(UnitTestGmeshFixture, testUnit)
28 {
29  const size_t num_x = 1;
30  const size_t num_y = 2;
31  const size_t num_z = 3;
32  const size_t num_surf = 6;
33  std::string config_mesh = Ioss::Utils::to_string(num_x) + "x" +
34  Ioss::Utils::to_string(num_y) + "x" +
35  Ioss::Utils::to_string(num_z) + "|sideset:xXyYzZ";
36  stk_classic::io::util::Gmesh_STKmesh_Fixture fixture(MPI_COMM_WORLD, config_mesh);
38 
39  fixture.commit();
40 
41  const std::vector<std::string> & sideset_names = fixture.getSidesetNames();
42  STKUNIT_ASSERT_EQUAL( num_surf, sideset_names.size() );
43 
44  for( size_t i = 0; i < num_surf; ++i ) {
45  std::string surf_name = (std::string)"surface_" + Ioss::Utils::to_string(i+1);
46  STKUNIT_ASSERT(surf_name == sideset_names[i]);
47  }
48 
49  std::vector<size_t> num_surf_elem(3);
50  num_surf_elem[0] = num_y * num_z;
51  num_surf_elem[1] = num_x * num_z;
52  num_surf_elem[2] = num_x * num_y;
53 
54  for( size_t i = 0; i < num_surf/2; ++i )
55  {
56  STKUNIT_ASSERT_EQUAL( num_surf_elem[i], fixture.getSurfElemCount(2*i) );
57  STKUNIT_ASSERT_EQUAL( num_surf_elem[i], fixture.getSurfElemCount(2*i+1) );
58  }
59 
60  const size_t total_side_count = 2 * (num_surf_elem[0]+num_surf_elem[1]+num_surf_elem[2]);
61  STKUNIT_ASSERT_EQUAL( total_side_count, fixture.getSideCount() );
62 
63  const size_t total_elem_count = num_x * num_y * num_z;
64  STKUNIT_ASSERT_EQUAL( total_elem_count, fixture.getElemCount() );
65 
66  const size_t total_node_count = (num_x+1) * (num_y+1) * (num_z+1);
67  STKUNIT_ASSERT_EQUAL( total_node_count, fixture.getNodeCount() );
68 
69  // Needed to test field data
71  fixture.getMetaData().get_field<stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian> >("coordinates");
72  STKUNIT_ASSERT( coord_field );
73 
74  // All side buckets
75  const std::vector<stk_classic::mesh::Bucket*> & all_side_buckets = fixture.getBulkData().buckets( fem_meta.side_rank() );
76 
77  std::vector<stk_classic::mesh::Entity *> entities;
78 
79  const stk_classic::mesh::PartVector & side_parts = fixture.getSideParts();
80  STKUNIT_ASSERT_EQUAL( sideset_names.size(), side_parts.size() );
81 
82  for( size_t ifset = 0; ifset < side_parts.size(); ++ifset )
83  {
84  std::pair<int, double> expected = fixture.getSurfCoordInfo(ifset);
85 
86  stk_classic::mesh::Selector selector = *side_parts[ifset];
87  entities.clear();
88  stk_classic::mesh::get_selected_entities(selector, all_side_buckets, entities);
89  STKUNIT_ASSERT_EQUAL( fixture.getSurfElemCount(ifset), entities.size() );
90 
91  for ( size_t i = 0 ; i < entities.size() ; ++i ) {
92  stk_classic::mesh::Entity & side = *entities[i] ;
93 
94  const CellTopologyData * cell_topology = stk_classic::mesh::fem::get_cell_topology(side).getCellTopologyData();
95 
96  STKUNIT_ASSERT( cell_topology );
97 
98  stk_classic::mesh::PairIterRelation rel = side.relations( stk_classic::mesh::fem::FEMMetaData::NODE_RANK );
99 
100  STKUNIT_ASSERT_EQUAL( cell_topology->node_count, rel.size() );
101 
102  for ( unsigned j = 0 ; j < cell_topology->node_count ; ++j )
103  {
104  stk_classic::mesh::Entity & rel_node = *rel[j].entity();
105  double * coords = stk_classic::mesh::field_data(*coord_field, rel_node);
106  STKUNIT_ASSERT( coords );
107  //std::cerr << "( " << coords[0] << ", " << coords[1] << ", " << coords[2] << ")" << std::endl;
108 
109  STKUNIT_ASSERT_DOUBLE_EQ(expected.second, coords[expected.first]);
110  }
111  //std::cerr << std::endl;
112  }
113  }
114 }
115 
FEMMetaData is a class that implements a Finite Element Method skin on top of the Sierra Tool Kit Met...
Definition: FEMMetaData.hpp:54
EntityRank side_rank() const
Returns the side rank which changes depending on spatial dimension.
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
Definition: FieldData.hpp:116
This is a class for selecting buckets based on a set of meshparts and set logic.
Definition: Selector.hpp:112
Field with defined data type and multi-dimensions (if any)
Definition: Field.hpp:118
void get_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets, std::vector< Entity * > &entities)
Get entities in selected buckets (selected by the given selector instance), and sorted by ID...
Definition: GetEntities.cpp:77
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
Definition: Entity.hpp:161
void commit()
Commit the part and field declarations so that the meta data manager can be used to create mesh bulk ...
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
static FEMMetaData & get(const MetaData &meta)
Getter for FEMMetaData off of a MetaData object.
std::string to_string(const T &t)
Definition: StringUtil.cpp:135