Sierra Toolkit  Version of the Day
UnitTestTopologyMap.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 
9 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
10 #include <stk_util/parallel/Parallel.hpp>
11 
12 #include <Ioss_ConcreteVariableType.h>
13 #include <Ioss_Initializer.h>
14 #include <Ioss_VariableType.h>
15 #include <Ioss_Utils.h>
16 
17 #include <Ioss_ElementTopology.h>
18 
19 #include <stk_io/IossBridge.hpp>
20 #include <Shards_CellTopology.hpp>
21 
22 #include <assert.h>
23 
24 namespace {
25 template<typename T, typename U>
26 int my_assert(T a, T b, U msg) {
27  if (a != b) {
28  std::cerr << "\tERROR: '" << msg << "' assertion failed: " << a << " is not equal to " << b << "\n";
29  return 1;
30  }
31  return 0;
32 }
33 }
34 
35 namespace {
36 int testElement(const std::string &name)
37 {
38  int errors = 0;
39  Ioss::ElementTopology *element = Ioss::ElementTopology::factory(name);
40  if (element == NULL) {
41  std::cerr << "\tERROR: Element type '" << name << "' could not be constructed.";
42  // Must return since we have a NULL pointer and can't do further tests...
43  return 1;
44  }
45  if (element->name() != name) {
46  // This is an alias. Don't run it through the rest of the tests
47  std::cerr << "Element '" << name << "' is an alias for element '" << element->name() << "'\n";
48  return 0;
49  }
50 
51  std::cerr << "Testing element '" << name << "'\n";
52  // Currently not supported in shards:
53  if (element->name() == "unknown") {
54  std::cerr << "\tERROR (EXPECTED): No support for '" << element->name() << "'\n";
55  return 0;
56  }
57 
58  // Get the corresponding shards CellTopologyData* ..
59  const CellTopologyData *cell_data = stk::io::map_topology_ioss_to_cell(element);
60  if (cell_data == NULL) {
61  std::cerr << "\tERROR: Could not find a shards CellTopology corresponding to the Ioss::ElementTopology element '"
62  << name << "'.";
63  // Must return since we have a NULL pointer and can't do further tests...
64  return 1;
65  }
66 
67  // See if we get the same element back when converting from
68  // CellTopologyData to Ioss::ElementToplogy
69  std::string new_name = stk::io::map_topology_cell_to_ioss(cell_data, element->spatial_dimension());
70  Ioss::ElementTopology *new_element = Ioss::ElementTopology::factory(new_name);
71  if (element->name() != new_element->name()) {
72  std::cerr << "\tERROR: New name = '" << new_element->name()
73  << "' doesn't match old name '" << element->name()
74  << "'\n";
75  errors++;
76  }
77 
78  shards::CellTopology cell(cell_data);
79 
80  // At this point, 'element' is the Ioss element topology and
81  // 'cell' is the corresponding shards CellTopology data pointer.
82  // Make sure that they agree on all subcell details...
83  // Exceptions:
84  // 1. An Ioss Node has 1 node per element; a shards Node has 0 nodes per element...
85 
86  errors += my_assert(cell.getNodeCount(),
87  static_cast<unsigned>(element->number_nodes()),
88  "node count");
89  errors += my_assert(cell.getVertexCount(),
90  static_cast<unsigned>(element->number_corner_nodes()),
91  "vertex count");
92 
93  // NOTE: CellTopology and Ioss disagree on parametric dimension.
94  int add_to = element->spatial_dimension() != element->parametric_dimension() && element->is_element() ? 1 : 0;
95  errors += my_assert(cell.getDimension(),
96  static_cast<unsigned>(element->parametric_dimension()+add_to),
97  "parametric dimension");
98  errors += my_assert(cell.getEdgeCount(),
99  static_cast<unsigned>(element->number_edges()),
100  "edge count");
101 
102  // NOTE: Ioss counts edges and faces as boundaries for shell elements
103  int add_boundary = 0;
104  if (add_to == 1 && element->spatial_dimension() == 3 && element->parametric_dimension() == 2)
105  add_boundary = cell.getEdgeCount();
106 
107  if (element->name() == "edge2" || element->name() == "edge3")
108  add_boundary += 2;
109 
110  errors += my_assert(cell.getSideCount() + add_boundary,
111  static_cast<unsigned>(element->number_boundaries()),
112  "boundary count");
113 
114 
115  // Check face topologies for all elements...
116  if (element->is_element()) {
117  if (cell.getDimension() == 3) {
118  int face_count = element->number_faces();
119  for (int i=0; i < face_count; i++) {
120  Ioss::ElementTopology *face = element->face_type(i+1);
121  const CellTopologyData *cell_face = cell.getCellTopologyData(cell.getDimension()-1,i);
122  errors += my_assert(face->name(),
123  stk::io::map_topology_cell_to_ioss(cell_face,face->spatial_dimension()),
124  "face type");
125 
126  Ioss::IntVector fcon = element->face_connectivity(i+1);
127  size_t node_count = fcon.size();
128  for (size_t j=0; j < node_count; j++) {
129  std::ostringstream msg;
130  msg << "face node connectivity for node " << j << " on face " << i;
131  errors += my_assert(fcon[j],
132  static_cast<int>(cell.getNodeMap(cell.getDimension()-1, i, j)),
133  msg.str());
134  }
135  }
136 
137  int edge_count = element->number_edges();
138  for (int i=0; i < edge_count; i++) {
139 
140  Ioss::IntVector fcon = element->edge_connectivity(i+1);
141  size_t node_count = fcon.size();
142  for (size_t j=0; j < node_count; j++) {
143  std::ostringstream msg;
144  msg << "edge node connectivity for node " << j << " on edge " << i;
145  errors += my_assert(fcon[j],
146  static_cast<int>(cell.getNodeMap(cell.getDimension()-2, i, j)),
147  msg.str());
148  }
149  }
150  }
151  else if (cell.getDimension() == 2) {
152  int edge_count = element->number_edges();
153  for (int i=0; i < edge_count; i++) {
154  Ioss::ElementTopology *edge = element->edge_type(i+1);
155  const CellTopologyData *cell_edge = cell.getCellTopologyData(cell.getDimension()-1,i);
156  errors += my_assert(edge->name(),
157  stk::io::map_topology_cell_to_ioss(cell_edge, edge->spatial_dimension()),
158  "edge type");
159 
160  Ioss::IntVector econ = element->edge_connectivity(i+1);
161  size_t node_count = econ.size();
162  for (size_t j=0; j < node_count; j++) {
163  std::ostringstream msg;
164  msg << "edge node connectivity for node " << j << " on edge " << i;
165  errors += my_assert(econ[j],
166  static_cast<int>(cell.getNodeMap(cell.getDimension()-1, i, j)),
167  msg.str());
168  }
169  }
170 
171  }
172  }
173  return errors;
174 }
175 }
176 
177 STKUNIT_UNIT_TEST(UnitTestTopology, testUnit)
178 {
179  Ioss::StorageInitializer initialize_storage;
180  Ioss::Initializer initialize_topologies;
181 
182  Ioss::NameList elements;
183  int element_count = Ioss::ElementTopology::describe(&elements);
184 
185  int errors = 0;
186  for (int i=0; i < element_count; i++) {
187  // FIXME: Need to totally skip tetra7 for now
188  if (elements[i] == "tetra7" ||
189  elements[i] == "tetra11" ||
190  elements[i] == "trishell4" ||
191  elements[i] == "trishell7") {
192  continue;
193  }
194 
195  int current_error = testElement(elements[i]);
196  if (elements[i] != "node" &&
197  elements[i] != "rod3d2" &&
198  elements[i] != "rod3d3" &&
199  elements[i] != "tri4a" /*FIXME?*/) {
200  errors += current_error;
201  }
202  else {
203  if (current_error > 0)
204  std::cerr << "\t\tIGNORING " << elements[i] << " ERRORS...\n";
205  }
206  }
207  STKUNIT_ASSERT(errors == 0);
208 }
209 
210 
const CellTopologyData * map_topology_ioss_to_cell(const Ioss::ElementTopology *topology)
Definition: IossBridge.cpp:670
std::string map_topology_cell_to_ioss(const CellTopologyData *cell_top, int spatial_dimension)
Definition: IossBridge.cpp:687