|
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 00009 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 00010 #include <stk_util/parallel/Parallel.hpp> 00011 00012 #include <Ioss_ConcreteVariableType.h> 00013 #include <Ioss_Initializer.h> 00014 #include <Ioss_VariableType.h> 00015 #include <Ioss_Utils.h> 00016 00017 #include <Ioss_ElementTopology.h> 00018 00019 #include <stk_io/IossBridge.hpp> 00020 #include <Shards_CellTopology.hpp> 00021 00022 #include <assert.h> 00023 00024 namespace { 00025 template<typename T, typename U> 00026 int my_assert(T a, T b, U msg) { 00027 if (a != b) { 00028 std::cerr << "\tERROR: '" << msg << "' assertion failed: " << a << " is not equal to " << b << "\n"; 00029 return 1; 00030 } 00031 return 0; 00032 } 00033 } 00034 00035 namespace { 00036 int testElement(const std::string &name) 00037 { 00038 int errors = 0; 00039 Ioss::ElementTopology *element = Ioss::ElementTopology::factory(name); 00040 if (element == NULL) { 00041 std::cerr << "\tERROR: Element type '" << name << "' could not be constructed."; 00042 // Must return since we have a NULL pointer and can't do further tests... 00043 return 1; 00044 } 00045 if (element->name() != name) { 00046 // This is an alias. Don't run it through the rest of the tests 00047 std::cerr << "Element '" << name << "' is an alias for element '" << element->name() << "'\n"; 00048 return 0; 00049 } 00050 00051 std::cerr << "Testing element '" << name << "'\n"; 00052 // Currently not supported in shards: 00053 if (element->name() == "unknown") { 00054 std::cerr << "\tERROR (EXPECTED): No support for '" << element->name() << "'\n"; 00055 return 0; 00056 } 00057 00058 // Get the corresponding shards CellTopologyData* .. 00059 const CellTopologyData *cell_data = stk_classic::io::map_topology_ioss_to_cell(element); 00060 if (cell_data == NULL) { 00061 std::cerr << "\tERROR: Could not find a shards CellTopology corresponding to the Ioss::ElementTopology element '" 00062 << name << "'."; 00063 // Must return since we have a NULL pointer and can't do further tests... 00064 return 1; 00065 } 00066 00067 // See if we get the same element back when converting from 00068 // CellTopologyData to Ioss::ElementToplogy 00069 std::string new_name = stk_classic::io::map_topology_cell_to_ioss(cell_data, element->spatial_dimension()); 00070 Ioss::ElementTopology *new_element = Ioss::ElementTopology::factory(new_name); 00071 if (element->name() != new_element->name()) { 00072 std::cerr << "\tERROR: New name = '" << new_element->name() 00073 << "' doesn't match old name '" << element->name() 00074 << "'\n"; 00075 errors++; 00076 } 00077 00078 shards::CellTopology cell(cell_data); 00079 00080 // At this point, 'element' is the Ioss element topology and 00081 // 'cell' is the corresponding shards CellTopology data pointer. 00082 // Make sure that they agree on all subcell details... 00083 // Exceptions: 00084 // 1. An Ioss Node has 1 node per element; a shards Node has 0 nodes per element... 00085 00086 errors += my_assert(cell.getNodeCount(), 00087 static_cast<unsigned>(element->number_nodes()), 00088 "node count"); 00089 errors += my_assert(cell.getVertexCount(), 00090 static_cast<unsigned>(element->number_corner_nodes()), 00091 "vertex count"); 00092 00093 // NOTE: CellTopology and Ioss disagree on parametric dimension. 00094 int add_to = element->spatial_dimension() != element->parametric_dimension() && element->is_element() ? 1 : 0; 00095 errors += my_assert(cell.getDimension(), 00096 static_cast<unsigned>(element->parametric_dimension()+add_to), 00097 "parametric dimension"); 00098 errors += my_assert(cell.getEdgeCount(), 00099 static_cast<unsigned>(element->number_edges()), 00100 "edge count"); 00101 00102 // NOTE: Ioss counts edges and faces as boundaries for shell elements 00103 int add_boundary = 0; 00104 if (add_to == 1 && element->spatial_dimension() == 3 && element->parametric_dimension() == 2) 00105 add_boundary = cell.getEdgeCount(); 00106 00107 if (element->name() == "edge2" || element->name() == "edge3") 00108 add_boundary += 2; 00109 00110 errors += my_assert(cell.getSideCount() + add_boundary, 00111 static_cast<unsigned>(element->number_boundaries()), 00112 "boundary count"); 00113 00114 00115 // Check face topologies for all elements... 00116 if (element->is_element()) { 00117 if (cell.getDimension() == 3) { 00118 int face_count = element->number_faces(); 00119 for (int i=0; i < face_count; i++) { 00120 Ioss::ElementTopology *face = element->face_type(i+1); 00121 const CellTopologyData *cell_face = cell.getCellTopologyData(cell.getDimension()-1,i); 00122 errors += my_assert(face->name(), 00123 stk_classic::io::map_topology_cell_to_ioss(cell_face,face->spatial_dimension()), 00124 "face type"); 00125 00126 Ioss::IntVector fcon = element->face_connectivity(i+1); 00127 size_t node_count = fcon.size(); 00128 for (size_t j=0; j < node_count; j++) { 00129 std::ostringstream msg; 00130 msg << "face node connectivity for node " << j << " on face " << i; 00131 errors += my_assert(fcon[j], 00132 static_cast<int>(cell.getNodeMap(cell.getDimension()-1, i, j)), 00133 msg.str()); 00134 } 00135 } 00136 00137 int edge_count = element->number_edges(); 00138 for (int i=0; i < edge_count; i++) { 00139 00140 Ioss::IntVector fcon = element->edge_connectivity(i+1); 00141 size_t node_count = fcon.size(); 00142 for (size_t j=0; j < node_count; j++) { 00143 std::ostringstream msg; 00144 msg << "edge node connectivity for node " << j << " on edge " << i; 00145 errors += my_assert(fcon[j], 00146 static_cast<int>(cell.getNodeMap(cell.getDimension()-2, i, j)), 00147 msg.str()); 00148 } 00149 } 00150 } 00151 else if (cell.getDimension() == 2) { 00152 int edge_count = element->number_edges(); 00153 for (int i=0; i < edge_count; i++) { 00154 Ioss::ElementTopology *edge = element->edge_type(i+1); 00155 const CellTopologyData *cell_edge = cell.getCellTopologyData(cell.getDimension()-1,i); 00156 errors += my_assert(edge->name(), 00157 stk_classic::io::map_topology_cell_to_ioss(cell_edge, edge->spatial_dimension()), 00158 "edge type"); 00159 00160 Ioss::IntVector econ = element->edge_connectivity(i+1); 00161 size_t node_count = econ.size(); 00162 for (size_t j=0; j < node_count; j++) { 00163 std::ostringstream msg; 00164 msg << "edge node connectivity for node " << j << " on edge " << i; 00165 errors += my_assert(econ[j], 00166 static_cast<int>(cell.getNodeMap(cell.getDimension()-1, i, j)), 00167 msg.str()); 00168 } 00169 } 00170 00171 } 00172 } 00173 return errors; 00174 } 00175 } 00176 00177 STKUNIT_UNIT_TEST(UnitTestTopology, testUnit) 00178 { 00179 Ioss::StorageInitializer initialize_storage; 00180 Ioss::Initializer initialize_topologies; 00181 00182 Ioss::NameList elements; 00183 int element_count = Ioss::ElementTopology::describe(&elements); 00184 00185 int errors = 0; 00186 for (int i=0; i < element_count; i++) { 00187 // FIXME: Need to totally skip tetra7 for now 00188 if (elements[i] == "tetra7" || 00189 elements[i] == "tetra11" || 00190 elements[i] == "trishell4" || 00191 elements[i] == "trishell7") { 00192 continue; 00193 } 00194 00195 int current_error = testElement(elements[i]); 00196 if (elements[i] != "node" && 00197 elements[i] != "rod3d2" && 00198 elements[i] != "rod3d3" && 00199 elements[i] != "tri4a" /*FIXME?*/) { 00200 errors += current_error; 00201 } 00202 else { 00203 if (current_error > 0) 00204 std::cerr << "\t\tIGNORING " << elements[i] << " ERRORS...\n"; 00205 } 00206 } 00207 STKUNIT_ASSERT(errors == 0); 00208 } 00209 00210