| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <Ioss_ConcreteVariableType.h> // for StorageInitializer |
| 36 |
#include <Ioss_ElementTopology.h> // for ElementTopology, NameList |
| 37 |
#include <Ioss_Initializer.h> // for Initializer |
| 38 |
#include <iostream> // for operator<<, basic_ostream, etc |
| 39 |
#include <stk_io/IossBridge.hpp> // for map_ioss_topology_to_stk |
| 40 |
#include <stk_topology/topology.hpp> // for topology, etc |
| 41 |
#include <gtest/gtest.h> |
| 42 |
#include <string> // for operator<<, operator!=, etc |
| 43 |
#include "gtest/gtest.h" // for AssertHelper |
| 44 |
|
| 45 |
namespace { |
| 46 |
|
| 47 |
template<typename T, typename U> |
| 48 |
int my_assert(T a, T b, U msg) { |
| 49 |
if (a != b) { |
| 50 |
std::cerr << "\tERROR: '" << msg << "' assertion failed: " << a << " is not equal to " << b << "\n"; |
| 51 |
return 1; |
| 52 |
} |
| 53 |
return 0; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
namespace { |
| 58 |
|
| 59 |
int testElement(const std::string &name, unsigned spatialDim) |
| 60 |
{ |
| 61 |
int errors = 0; |
| 62 |
Ioss::ElementTopology *element = Ioss::ElementTopology::factory(name); |
| 63 |
if ( element == nullptr ) { |
| 64 |
// std::cerr << "\tERROR: Element type '" << name << "' could not be constructed."; |
| 65 |
// Must return since we have a NULL pointer and can't do further tests... |
| 66 |
return 1; |
| 67 |
} |
| 68 |
|
| 69 |
if (element->name() != name) { |
| 70 |
// This is an alias. Don't run it through the rest of the tests |
| 71 |
// std::cerr << "Element '" << name << "' is an alias for element '" << element->name() << "'\n"; |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
std::cerr << "Testing element '" << name << "'\n"; |
| 76 |
// Currently not supported: |
| 77 |
if (element->name() == "unknown" || |
| 78 |
element->name() == "bar4" || |
| 79 |
element->name() == "edge4" || |
| 80 |
element->name() == "hex9" || |
| 81 |
element->name() == "hex16" || |
| 82 |
element->name() == "hex32" || |
| 83 |
element->name() == "hex64" || |
| 84 |
element->name() == "pyramid18" || |
| 85 |
element->name() == "pyramid19" || |
| 86 |
element->name() == "quad6" || |
| 87 |
element->name() == "quad12" || |
| 88 |
element->name() == "quad16" || |
| 89 |
element->name() == "tetra14" || |
| 90 |
element->name() == "tetra15" || |
| 91 |
element->name() == "tetra16" || |
| 92 |
element->name() == "tetra40" || |
| 93 |
element->name() == "tri13" || |
| 94 |
element->name() == "tri7" || |
| 95 |
element->name() == "tri9" || |
| 96 |
element->name() == "trishell7" || |
| 97 |
element->name() == "wedge12" || |
| 98 |
element->name() == "wedge16" || |
| 99 |
element->name() == "wedge20" || |
| 100 |
element->name() == "wedge21" || |
| 101 |
element->name() == "wedge24" || |
| 102 |
element->name() == "wedge52") { |
| 103 |
std::cerr << "\tERROR (EXPECTED): No support for '" << element->name() << "'\n"; |
| 104 |
return 0; |
| 105 |
} |
| 106 |
|
| 107 |
// Get the corresponding stk::topology: |
| 108 |
stk::topology cell = stk::io::map_ioss_topology_to_stk(element, spatialDim); |
| 109 |
if (cell == stk::topology::INVALID_TOPOLOGY) { |
| 110 |
std::cerr << "\tERROR: Could not find a stk::topology corresponding to the Ioss::ElementTopology element '" << name << "'.\n"; |
| 111 |
return 1; |
| 112 |
} |
| 113 |
|
| 114 |
// See if we get the same element back when converting from |
| 115 |
// stk::topology to Ioss::ElementToplogy |
| 116 |
Ioss::ElementTopology *new_element = Ioss::ElementTopology::factory(cell.name()); |
| 117 |
if (element->name() != new_element->name()) { |
| 118 |
std::cerr << "\tERROR: New name = '" << new_element->name() << "' doesn't match old name '" << element->name() << "'\n"; |
| 119 |
errors++; |
| 120 |
} |
| 121 |
|
| 122 |
// At this point, 'element' is the Ioss element topology and |
| 123 |
// 'cell' is the corresponding stk:topology topology. |
| 124 |
// Make sure that they agree on all subcell details... |
| 125 |
// Exceptions: |
| 126 |
// 1. An Ioss Node has 1 node per element; a stk::topology Node has 0 nodes per element... |
| 127 |
|
| 128 |
errors += my_assert(static_cast<int>(cell.num_nodes()), |
| 129 |
element->number_nodes(), |
| 130 |
"node count"); |
| 131 |
errors += my_assert(static_cast<int>(cell.num_vertices()), |
| 132 |
element->number_corner_nodes(), |
| 133 |
"vertex count"); |
| 134 |
|
| 135 |
// NOTE: stk::topology and Ioss disagree on parametric dimension. |
| 136 |
int add_to = element->spatial_dimension() != element->parametric_dimension() && element->is_element() ? 1 : 0; |
| 137 |
errors += my_assert(static_cast<int>(cell.dimension()), |
| 138 |
element->parametric_dimension()+add_to, |
| 139 |
"parametric dimension"); |
| 140 |
errors += my_assert(static_cast<int>(cell.num_edges()), |
| 141 |
element->number_edges(), |
| 142 |
"edge count"); |
| 143 |
|
| 144 |
// NOTE: Ioss counts edges and faces as boundaries for shell elements |
| 145 |
errors += my_assert(static_cast<int>(cell.num_sides()), |
| 146 |
element->number_boundaries(), |
| 147 |
"boundary count"); |
| 148 |
|
| 149 |
return errors; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
TEST(UnitTestTopology, testUnit) |
| 154 |
{ |
| 155 |
Ioss::StorageInitializer initialize_storage; |
| 156 |
Ioss::Initializer initialize_topologies; |
| 157 |
|
| 158 |
Ioss::NameList elements; |
| 159 |
int element_count = Ioss::ElementTopology::describe(&elements); |
| 160 |
|
| 161 |
int errors = 0; |
| 162 |
unsigned spatialDim = 3; |
| 163 |
for (int i=0; i < element_count; i++) { |
| 164 |
// FIXME: Need to totally skip tetra7 for now |
| 165 |
if (elements[i] == "tetra7") { |
| 166 |
continue; |
| 167 |
} |
| 168 |
|
| 169 |
int current_error = testElement(elements[i], spatialDim); |
| 170 |
if (elements[i] != "node" && |
| 171 |
elements[i] != "bar2" && |
| 172 |
elements[i] != "bar3" && |
| 173 |
elements[i] != "bar4" && |
| 174 |
elements[i] != "spring2" && |
| 175 |
elements[i] != "spring3") { |
| 176 |
errors += current_error; |
| 177 |
} |
| 178 |
else { |
| 179 |
if (current_error > 0) |
| 180 |
std::cerr << "\t\tIGNORING " << elements[i] << " ERRORS...\n"; |
| 181 |
} |
| 182 |
} |
| 183 |
ASSERT_TRUE(errors == 0); |
| 184 |
} |