Sierra Toolkit Version of the Day
UnitTestTopologyMap.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 
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::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::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   errors += my_assert(cell.getSideCount(),
00102           static_cast<unsigned>(element->number_boundaries()),
00103           "boundary count");
00104 
00105 
00106   // Check face topologies for all elements...
00107   if (element->is_element()) {
00108     if (cell.getDimension() == 3) {
00109       int face_count = element->number_faces();
00110       for (int i=0; i < face_count; i++) {
00111   Ioss::ElementTopology *face = element->face_type(i+1);
00112   const CellTopologyData *cell_face = cell.getCellTopologyData(cell.getDimension()-1,i);
00113   errors += my_assert(face->name(),
00114           stk::io::map_topology_cell_to_ioss(cell_face,face->spatial_dimension()),
00115           "face type");
00116 
00117   Ioss::IntVector fcon = element->face_connectivity(i+1);
00118   size_t node_count = fcon.size();
00119   for (size_t j=0; j < node_count; j++) {
00120     std::ostringstream msg;
00121     msg << "face node connectivity for node " << j << " on face " << i;
00122     errors += my_assert(fcon[j],
00123             static_cast<int>(cell.getNodeMap(cell.getDimension()-1, i, j)),
00124             msg.str());
00125   }
00126       }
00127 
00128       int edge_count = element->number_edges();
00129       for (int i=0; i < edge_count; i++) {
00130 
00131   Ioss::IntVector fcon = element->edge_connectivity(i+1);
00132   size_t node_count = fcon.size();
00133   for (size_t j=0; j < node_count; j++) {
00134     std::ostringstream msg;
00135     msg << "edge node connectivity for node " << j << " on edge " << i;
00136     errors += my_assert(fcon[j],
00137             static_cast<int>(cell.getNodeMap(cell.getDimension()-2, i, j)),
00138             msg.str());
00139   }
00140       }
00141     }
00142     else if (cell.getDimension() == 2) {
00143       int edge_count = element->number_edges();
00144       for (int i=0; i < edge_count; i++) {
00145   Ioss::ElementTopology *edge = element->edge_type(i+1);
00146   const CellTopologyData *cell_edge = cell.getCellTopologyData(cell.getDimension()-1,i);
00147   errors += my_assert(edge->name(),
00148           stk::io::map_topology_cell_to_ioss(cell_edge, edge->spatial_dimension()),
00149           "edge type");
00150 
00151   Ioss::IntVector econ = element->edge_connectivity(i+1);
00152   size_t node_count = econ.size();
00153   for (size_t j=0; j < node_count; j++) {
00154     std::ostringstream msg;
00155     msg << "edge node connectivity for node " << j << " on edge " << i;
00156     errors += my_assert(econ[j],
00157             static_cast<int>(cell.getNodeMap(cell.getDimension()-1, i, j)),
00158             msg.str());
00159   }
00160       }
00161 
00162     }
00163   }
00164   return errors;
00165 }
00166 }
00167 
00168 STKUNIT_UNIT_TEST(UnitTestTopology, testUnit)
00169 {
00170   Ioss::StorageInitializer initialize_storage;
00171   Ioss::Initializer        initialize_topologies;
00172 
00173   Ioss::NameList elements;
00174   int element_count = Ioss::ElementTopology::describe(&elements);
00175 
00176   int errors = 0;
00177   for (int i=0; i < element_count; i++) {
00178     // FIXME: Need to totally skip tetra7 for now
00179     if (elements[i] == "tetra7") {
00180       continue;
00181     }
00182 
00183     int current_error = testElement(elements[i]);
00184     if (elements[i] != "node" &&
00185         elements[i] != "rod3d2" &&
00186         elements[i] != "rod3d3" &&
00187         elements[i] != "tri4a" /*FIXME?*/) {
00188       errors += current_error;
00189     }
00190     else {
00191       if (current_error > 0)
00192   std::cerr << "\t\tIGNORING " << elements[i] << " ERRORS...\n";
00193     }
00194   }
00195   STKUNIT_ASSERT(errors == 0);
00196 }
00197 
00198 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends