[cig-commits] r18480 - in short/3D/PyLith/trunk: libsrc/pylith libsrc/pylith/meshio unittests/libtests/meshio unittests/libtests/meshio/data
brad at geodynamics.org
brad at geodynamics.org
Fri May 27 12:57:37 PDT 2011
Author: brad
Date: 2011-05-27 12:57:36 -0700 (Fri, 27 May 2011)
New Revision: 18480
Added:
short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc
short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/data/gentwocell.jou
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.jou
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8_12.2.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8_13.0.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.jou
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4_12.2.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4_13.0.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.jou
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4_12.2.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4_13.0.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.jou
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3_12.2.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3_13.0.exo
Removed:
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.cub
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.cub
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.cub
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.exo
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.cub
short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.exo
Modified:
short/3D/PyLith/trunk/libsrc/pylith/Makefile.am
short/3D/PyLith/trunk/libsrc/pylith/meshio/Makefile.am
short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.cc
short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.hh
short/3D/PyLith/trunk/libsrc/pylith/meshio/meshiofwd.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOCubit.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitHex.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitQuad.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTet.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTri.cc
Log:
Refactored MeshIOCubit into MeshIOCubit and ExodusII for cleaner implementation. Created journal scripts for generating test Exodus files. Added test Exodus files for v12.2 and v13.0.
Modified: short/3D/PyLith/trunk/libsrc/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/Makefile.am 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/libsrc/pylith/Makefile.am 2011-05-27 19:57:36 UTC (rev 18480)
@@ -189,6 +189,7 @@
if ENABLE_CUBIT
libpylith_la_SOURCES += \
+ meshio/ExodusII.cc \
meshio/MeshIOCubit.cc
libpylith_la_LIBADD += -lnetcdf_c++ -lnetcdf
endif
@@ -198,8 +199,6 @@
feassemble/ElasticityImplicitCUDA.cc \
feassemble/ElasticityImplicitCUDAKernel.cu
libpylith_la_LIBADD += -lcudart -lcuda
-# -L/usr/local/cuda/lib
-# INCLUDES += -I/usr/local/cuda/include
endif
Added: short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,324 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "ExodusII.hh" // implementation of class methods
+
+#include "petsc.h" // USES MPI_Comm
+
+// :KLUDGE: Prevent NetCDF from definining MPI types
+#define MPI_INCLUDED
+#include <netcdfcpp.h> // USES netcdf
+
+#include <cassert> // USES assert()
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::ExodusII::ExodusII(void) :
+ _filename(""),
+ _file(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Constructor with filename
+pylith::meshio::ExodusII::ExodusII(const char* filename) :
+ _filename(filename),
+ _file(0)
+{ // constructor
+ open();
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::ExodusII::~ExodusII(void)
+{ // destructor
+ close();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set filename.
+void
+pylith::meshio::ExodusII::filename(const char* name)
+{ // filename
+ _filename = name;
+} // filename
+
+// ----------------------------------------------------------------------
+// Get filename.
+const char*
+pylith::meshio::ExodusII::filename(void) const
+{ // filename
+ return _filename.c_str();
+} // filename
+
+// ----------------------------------------------------------------------
+// Open file.
+void
+pylith::meshio::ExodusII::open(void)
+{ // open
+ close();
+
+ _file = new NcFile(_filename.c_str());
+ if (!_file->is_valid()) {
+ std::ostringstream msg;
+ msg << "Could not open ExodusII file '" << _filename
+ << "' for reading.\n";
+ throw std::runtime_error(msg.str());
+ } // if
+} // open
+
+// ----------------------------------------------------------------------
+// Close file.
+void
+pylith::meshio::ExodusII::close(void)
+{ // close
+ if (_file)
+ _file->close();
+ delete _file; _file = 0;
+} // close
+
+// ----------------------------------------------------------------------
+// Check if Cubit Exodus file constains dimension.
+bool
+pylith::meshio::ExodusII::hasDim(const char* name) const
+{ // hasDim
+ assert(_file);
+
+ bool found = false;
+
+ const int ndims = _file->num_dims();
+ for (int i=0; i < ndims; ++i) {
+ NcDim* dim = _file->get_dim(i);
+ assert(dim);
+ if (0 == strcmp(dim->name(), name)) {
+ found = true;
+ break;
+ } // if
+ } // for
+
+ return found;
+} // hasDim
+
+// ----------------------------------------------------------------------
+// Check if Cubit Exodus file constains attribute.
+bool
+pylith::meshio::ExodusII::hasAtt(const char* name) const
+{ // hasAtt
+ assert(_file);
+
+ bool found = false;
+
+ const int natts = _file->num_atts();
+ for (int i=0; i < natts; ++i) {
+ NcAtt* att = _file->get_att(i);
+ assert(att);
+ if (0 == strcmp(att->name(), name)) {
+ found = true;
+ break;
+ } // if
+ } // for
+
+ return found;
+} // hasAtt
+
+// ----------------------------------------------------------------------
+// Check if Cubit Exodus file constains variable.
+bool
+pylith::meshio::ExodusII::hasVar(const char* name) const
+{ // hasVar
+ assert(_file);
+
+ bool found = false;
+
+ const int nvars = _file->num_vars();
+ for (int i=0; i < nvars; ++i) {
+ NcVar* var = _file->get_var(i);
+ assert(var);
+ if (0 == strcmp(var->name(), name)) {
+ found = true;
+ break;
+ } // if
+ } // for
+
+ return found;
+} // hasVar
+
+// ----------------------------------------------------------------------
+// Get value for dimension.
+int
+pylith::meshio::ExodusII::getDim(const char* name) const
+{ // getDim
+ assert(_file);
+
+ if (!hasDim(name)) {
+ std::ostringstream msg;
+ msg << "Missing dimension '" << name << "'.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ NcDim* dim = _file->get_dim(name);
+ assert(dim);
+ return dim->size();
+} // getDim
+
+// ----------------------------------------------------------------------
+// Get values for variable as an array of doubles.
+void
+pylith::meshio::ExodusII::getVar(double* values,
+ int* dims,
+ int ndims,
+ const char* name) const
+{ // getVar
+ assert(_file);
+ assert(values);
+
+ if (!hasVar(name)) {
+ std::ostringstream msg;
+ msg << "Missing real variable '" << name << "'.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ NcVar* var = _file->get_var(name);
+ assert(var);
+ if (ndims != var->num_dims()) {
+ std::ostringstream msg;
+ msg << "Expecting " << ndims << " dimensions for variable '" << name
+ << "' but variable only has " << var->num_dims() << " dimensions.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ for (int iDim=0; iDim < ndims; ++iDim) {
+ NcDim* d = var->get_dim(iDim);
+ assert(d);
+ if (dims[iDim] != d->size()) {
+ std::ostringstream msg;
+ msg << "Expecting dimension " << iDim << " of variable '" << name
+ << "' to be " << dims[iDim] << ", but dimension is " << d->size()
+ << ".";
+ throw std::runtime_error(msg.str());
+ } // if
+ } // for
+
+ long* counts = var->edges();
+ bool ok = var->get(values, counts);
+ delete[] counts; counts = 0;
+ if (!ok) {
+ std::ostringstream msg;
+ msg << "Coult not get values for variable '" << name << ".";
+ throw std::runtime_error(msg.str());
+ } // if
+} // getVar
+
+// ----------------------------------------------------------------------
+// Get values for variable as an array of ints.
+void
+pylith::meshio::ExodusII::getVar(int* values,
+ int* dims,
+ int ndims,
+ const char* name) const
+{ // getVar
+ assert(_file);
+ assert(values);
+
+ if (!hasVar(name)) {
+ std::ostringstream msg;
+ msg << "Missing integer variable '" << name << "'.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ NcVar* var = _file->get_var(name);
+ assert(var);
+ if (ndims != var->num_dims()) {
+ std::ostringstream msg;
+ msg << "Expecting " << ndims << " dimensions for variable '" << name
+ << "' but variable only has " << var->num_dims() << " dimensions.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ for (int iDim=0; iDim < ndims; ++iDim) {
+ NcDim* d = var->get_dim(iDim);
+ assert(d);
+ if (dims[iDim] != d->size()) {
+ std::ostringstream msg;
+ msg << "Expecting dimension " << iDim << " of variable '" << name
+ << "' to be " << dims[iDim]<< ", but dimension is " << d->size()
+ << ".";
+ throw std::runtime_error(msg.str());
+ } // if
+ } // for
+
+ long* counts = var->edges();
+ bool ok = var->get(values, counts);
+ delete[] counts; counts = 0;
+ if (!ok) {
+ std::ostringstream msg;
+ msg << "Coult not get values for variable '" << name << ".";
+ throw std::runtime_error(msg.str());
+ } // if
+} // getVar
+
+// ----------------------------------------------------------------------
+// Get values for variable as an array of strings.
+void
+pylith::meshio::ExodusII::getVar(string_vector* values,
+ int dim,
+ const char* name) const
+{ // getVar
+ assert(_file);
+ assert(values);
+
+ if (!hasVar(name)) {
+ std::ostringstream msg;
+ msg << "Missing string variable '" << name << "'.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ NcVar* var = _file->get_var(name);
+ assert(var);
+
+ if (var->num_dims() != 2) {
+ std::ostringstream msg;
+ msg << "Expecting 2 dimensions for variable '" << name
+ << "' but variable only has " << var->num_dims() << " dimensions.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ long* counts = var->edges();
+ const int bufferSize = counts[1];
+ char* buffer = (bufferSize > 0) ? new char[bufferSize] : 0;
+ for (int i=0; i < dim; ++i) {
+ var->set_cur(i);
+ bool ok = var->get(buffer, 1, bufferSize, 0, 0, 0);
+ if (!ok) {
+ std::ostringstream msg;
+ msg << "Could not read string in variable '" << name << "'.";
+ throw std::runtime_error(msg.str());
+ } // if
+ (*values)[i] = buffer;
+ //std::cout << "GROUP: '" << (*values)[i] << "'." << std::endl;
+ } // for
+ delete[] buffer; buffer = 0;
+ delete[] counts; counts = 0;
+} // getVar
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.hh (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/ExodusII.hh 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,149 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+/**
+ * @file libsrc/meshio/ExodusII.hh
+ *
+ * @brief C++ I/O functions for CUBIT Exodus II files.
+ */
+
+#if !defined(pylith_meshio_exodusii_hh)
+#define pylith_meshio_exodusii_hh
+
+// Include directives ---------------------------------------------------
+#include "meshiofwd.hh" // Forward declarations
+
+#include "pylith/utils/array.hh" // USES int_array, double_array, string_vector
+
+#include <string> // HASA std::string
+
+// Forward declarations -------------------------------------------------
+/// C++ input/output manager for CUBIT Exodus II files.
+class NcFile; // netcdf file
+
+// ExodusII ----------------------------------------------------------
+class pylith::meshio::ExodusII
+{ // ExodusII
+ friend class TestExodusII; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ ExodusII(void);
+
+ /** Open file.
+ *
+ * @param filename Name of file.
+ */
+ ExodusII(const char* filename);
+
+ /// Destructor
+ ~ExodusII(void);
+
+ /** Set filename.
+ *
+ * @param filename Name of file
+ */
+ void filename(const char* name);
+
+ /** Get filename.
+ *
+ * @returns Name of file
+ */
+ const char* filename(void) const;
+
+ /// Open file.
+ void open(void);
+
+ /// Close file.
+ void close(void);
+
+ /** Check if file constains dimension.
+ *
+ * @param name Name of dimension.
+ * @returns True if file contains variable, false otherwise.
+ */
+ bool hasDim(const char* name) const;
+
+ /** Check if file constains attribute.
+ *
+ * @param name Name of attribute.
+ * @returns True if file contains variable, false otherwise.
+ */
+ bool hasAtt(const char* name) const;
+
+ /** Check if file constains variable.
+ *
+ * @param name Name of variable.
+ * @returns True if file contains variable, false otherwise.
+ */
+ bool hasVar(const char* name) const;
+
+ /** Get dimension from file.
+ *
+ * @param name Name of dimension.
+ * @returns Value of dimension.
+ */
+ int getDim(const char* name) const;
+
+ /** Get values for variable as an array of doubles.
+ *
+ * @param values Array of values.
+ * @param dims Expected dimensions for variable.
+ * @param ndims Number of dimension for variable.
+ * @param name Name of variable.
+ */
+ void getVar(double* values,
+ int* dims,
+ int ndims,
+ const char* name) const;
+
+ /** Get values for variable as an array of ints.
+ *
+ * @param values Array of values.
+ * @param dims Expected dimensions for variable.
+ * @param ndims Number of dimension for variable.
+ * @param name Name of variable.
+ */
+ void getVar(int* values,
+ int* dims,
+ int ndims,
+ const char* name) const;
+
+ /** Get values for variable as an array of strings.
+ *
+ * @param values Array of values.
+ * @param dim Number of values.
+ * @param name Name of variable.
+ */
+ void getVar(string_vector* values,
+ int dim,
+ const char* name) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+ std::string _filename; ///< Name of file
+ NcFile* _file; ///< ExodusII file
+
+}; // ExodusII
+
+#endif // pylith_meshio_exodusii_hh
+
+// End of file
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/Makefile.am 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/Makefile.am 2011-05-27 19:57:36 UTC (rev 18480)
@@ -75,7 +75,8 @@
PsetFile.hh \
PsetFileAscii.hh \
PsetFileAscii.icc \
- PsetFileBinary.hh
+ PsetFileBinary.hh \
+ ExodusII.hh
# End of file
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.cc 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -21,16 +21,13 @@
#include "MeshIOCubit.hh" // implementation of class methods
#include "MeshBuilder.hh" // USES MeshBuilder
+#include "ExodusII.hh" // USES ExodusII
#include "pylith/utils/array.hh" // USES double_array, int_array, string_vector
#include "petsc.h" // USES MPI_Comm
#include "journal/info.h" // USES journal::info_t
-// :KLUDGE: Prevent NetCDF from definining MPI types
-#define MPI_INCLUDED
-#include <netcdfcpp.h> // USES netcdf
-
#include <cassert> // USES assert()
#include <stdexcept> // USES std::runtime_error
#include <sstream> // USES std::ostringstream
@@ -78,29 +75,19 @@
MPI_Comm_rank(_mesh->comm(), &rank);
if (0 == rank) {
try {
- NcFile ncfile(_filename.c_str());
- if (!ncfile.is_valid()) {
- std::ostringstream msg;
- msg << "Could not open Cubit Exodus file '" << _filename
- << "' for reading.\n";
- throw std::runtime_error(msg.str());
- } // if
+ ExodusII exofile(_filename.c_str());
+ const int meshDim = exofile.getDim("num_dim");
- NcDim* num_dim = ncfile.get_dim("num_dim");
- if (0 == num_dim)
- throw std::runtime_error("Could not get dimension 'num_dim'.");
- meshDim = num_dim->size();
-
- _readVertices(ncfile, &coordinates, &numVertices, &spaceDim);
- _readCells(ncfile, &cells, &materialIds, &numCells, &numCorners);
+ _readVertices(exofile, &coordinates, &numVertices, &spaceDim);
+ _readCells(exofile, &cells, &materialIds, &numCells, &numCorners);
_orientCells(&cells, numCells, numCorners, meshDim);
MeshBuilder::buildMesh(_mesh, &coordinates, numVertices, spaceDim,
cells, numCells, numCorners, meshDim,
_interpolate);
_setMaterials(materialIds);
- _readGroups(ncfile);
+ _readGroups(exofile);
} catch (std::exception& err) {
std::ostringstream msg;
msg << "Error while reading Cubit Exodus file '" << _filename << "'.\n"
@@ -126,23 +113,17 @@
void
pylith::meshio::MeshIOCubit::_write(void) const
{ // write
- NcFile ncfile(_filename.c_str());
- if (!ncfile.is_valid()) {
- std::ostringstream msg;
- msg << "Could not open Cubit Exodus file '" << _filename
- << "' for writing.\n";
- throw std::runtime_error(msg.str());
- } // if
+ ExodusII exofile(_filename.c_str());
- _writeDimensions(ncfile);
- _writeVariables(ncfile);
- _writeAttributes(ncfile);
+ _writeDimensions(exofile);
+ _writeVariables(exofile);
+ _writeAttributes(exofile);
} // write
// ----------------------------------------------------------------------
// Read mesh vertices.
void
-pylith::meshio::MeshIOCubit::_readVertices(NcFile& ncfile,
+pylith::meshio::MeshIOCubit::_readVertices(ExodusII& exofile,
double_array* coordinates,
int* numVertices,
int* numDims) const
@@ -154,28 +135,22 @@
journal::info_t info("meshiocubit");
// Space dimension
- NcDim* num_dim = ncfile.get_dim("num_dim");
- if (0 == num_dim)
- throw std::runtime_error("Could not get dimension 'num_dim'.");
- *numDims = num_dim->size();
+ *numDims = exofile.getDim("num_dim");
// Number of vertices
- NcDim* num_nodes = ncfile.get_dim("num_nodes");
- if (0 == num_nodes)
- throw std::runtime_error("Could not get dimension 'num_nodes'.");
- *numVertices = num_nodes->size();
+ *numVertices = exofile.getDim("num_nodes");
info << journal::at(__HERE__)
<< "Reading " << *numVertices << " vertices." << journal::endl;
- if (_hasVar(ncfile, "coord")) {
+ if (exofile.hasVar("coord")) {
const int ndims = 2;
int dims[2];
dims[0] = *numDims;
dims[1] = *numVertices;
double_array buffer(*numVertices * *numDims);
- _getVar(&buffer, dims, ndims, ncfile, "coord");
-
+ exofile.getVar(&buffer[0], dims, ndims, "coord");
+
coordinates->resize(*numVertices * *numDims);
for (int iVertex=0; iVertex < *numVertices; ++iVertex)
for (int iDim=0; iDim < *numDims; ++iDim)
@@ -193,7 +168,7 @@
dims[0] = *numVertices;
for (int i=0; i < *numDims; ++i) {
- _getVar(&buffer, dims, ndims, ncfile, coordNames[i]);
+ exofile.getVar(&buffer[0], dims, ndims, coordNames[i]);
for (int iVertex=0; iVertex < *numVertices; ++iVertex)
(*coordinates)[iVertex*(*numDims)+i] = buffer[iVertex];
@@ -204,7 +179,7 @@
// ----------------------------------------------------------------------
// Read mesh cells.
void
-pylith::meshio::MeshIOCubit::_readCells(NcFile& ncfile,
+pylith::meshio::MeshIOCubit::_readCells(ExodusII& exofile,
int_array* cells,
int_array* materialIds,
int* numCells,
@@ -217,70 +192,50 @@
journal::info_t info("meshiocubit");
- NcDim* num_elem = ncfile.get_dim("num_elem");
- if (0 == num_elem)
- throw std::runtime_error("Could not get dimension 'num_elem'.");
- *numCells = num_elem->size();
- NcDim* num_el_blk = ncfile.get_dim("num_el_blk");
- if (0 == num_el_blk)
- throw std::runtime_error("Could not get dimension 'num_el_blk'.");
- const int numMaterials = num_el_blk->size();
+ *numCells = exofile.getDim("num_elem");
+ const int numMaterials = exofile.getDim("num_el_blk");
info << journal::at(__HERE__)
<< "Reading " << *numCells << " cells in " << numMaterials
<< " blocks." << journal::endl;
- NcVar* eb_prop1 = ncfile.get_var("eb_prop1");
- if (0 == eb_prop1)
- throw std::runtime_error("Could not get variable 'eb_prop1'.");
- std::valarray<int> blockIds(numMaterials);
- long* counts = eb_prop1->edges();
- bool ok = eb_prop1->get(&blockIds[0], counts);
- delete[] counts; counts = 0;
- materialIds->resize(*numCells);
+ int_array blockIds(numMaterials);
+ int ndims = 1;
+ int dims[2];
+ dims[0] = numMaterials;
+ dims[1] = 0;
+ exofile.getVar(&blockIds[0], dims, ndims, "eb_prop1");
+ materialIds->resize(*numCells);
*numCorners = 0;
for (int iMaterial=0, index=0; iMaterial < numMaterials; ++iMaterial) {
std::ostringstream varname;
varname << "num_nod_per_el" << iMaterial+1;
- NcDim* num_nod_per_el = ncfile.get_dim(varname.str().c_str());
- if (0 == num_nod_per_el)
- throw std::runtime_error("Could not get dimension 'num_nod_per_el'.");
if (0 == *numCorners) {
- *numCorners = num_nod_per_el->size();
+ *numCorners = exofile.getDim(varname.str().c_str());
const int size = (*numCells) * (*numCorners);
cells->resize(size);
- } else if (num_nod_per_el->size() != *numCorners) {
+ } else if (exofile.getDim(varname.str().c_str()) != *numCorners) {
std::ostringstream msg;
msg << "All materials must have the same number of vertices per cell.\n"
<< "Expected " << *numCorners << " vertices per cell, but block "
- << blockIds[iMaterial] << " has " << num_nod_per_el->size()
+ << blockIds[iMaterial] << " has "
+ << exofile.getDim(varname.str().c_str())
<< " vertices.";
throw std::runtime_error(msg.str());
} // if
varname.str("");
varname << "num_el_in_blk" << iMaterial+1;
- NcDim* num_el_in_blk = ncfile.get_dim(varname.str().c_str());
- if (0 == num_el_in_blk)
- throw std::runtime_error("Could not get dimension 'num_el_in_blk'.");
- const int blockSize = num_el_in_blk->size();
+ const int blockSize = exofile.getDim(varname.str().c_str());
varname.str("");
varname << "connect" << iMaterial+1;
- NcVar* connect = ncfile.get_var(varname.str().c_str());
- if (0 == connect)
- throw std::runtime_error("Could not get variable 'connect'.");
- if (2 != connect->num_dims())
- throw std::runtime_error("Number of dimensions of variable "
- "'connect' must be 2.");
- const int size = connect->num_vals();
- assert(blockSize * (*numCorners) == size);
- long* counts = connect->edges();
- bool ok = connect->get(&(*cells)[index * (*numCorners)], counts);
- delete[] counts; counts = 0;
- if (!ok)
- throw std::runtime_error("Could not get cell values.");
+ ndims = 2;
+ dims[0] = blockSize;
+ dims[1] = *numCorners;
+ exofile.getVar(&(*cells)[index* (*numCorners)], dims, ndims,
+ varname.str().c_str());
for (int i=0; i < blockSize; ++i)
(*materialIds)[index+i] = blockIds[iMaterial];
@@ -294,73 +249,47 @@
// ----------------------------------------------------------------------
// Read mesh groups.
void
-pylith::meshio::MeshIOCubit::_readGroups(NcFile& ncfile)
+pylith::meshio::MeshIOCubit::_readGroups(ExodusII& exofile)
{ // _readGroups
journal::info_t info("meshiocubit");
- NcDim* num_node_sets = ncfile.get_dim("num_node_sets");
- if (0 == num_node_sets)
- throw std::runtime_error("Could not get dimension 'num_node_sets'.");
- const int numGroups = num_node_sets->size();
+ const int numGroups = exofile.getDim("num_node_sets");
info << journal::at(__HERE__)
<< "Found " << numGroups << " node sets." << journal::endl;
+
+ int_array ids(numGroups);
+ int ndims = 1;
+ int dims[2];
+ dims[0] = numGroups;
+ dims[1] = 0;
+ exofile.getVar(&ids[0], dims, ndims, "ns_prop1");
- NcVar* ns_prop1 = ncfile.get_var("ns_prop1");
- if (0 == ns_prop1)
- throw std::runtime_error("Could not get variable 'ns_prop1'.");
- std::valarray<int> ids(numGroups);
- long* counts = ns_prop1->edges();
- bool ok = ns_prop1->get(&ids[0], counts);
- delete[] counts; counts = 0;
-
string_vector groupNames(numGroups);
+
if (_useNodesetNames) {
- NcVar* ns_names = ncfile.get_var("ns_names");
- if (0 == ns_names)
- throw std::runtime_error("Could not get variable 'ns_names'.");
- long* counts = ns_names->edges();
- if (ns_names->num_dims() != 2)
- throw std::runtime_error("Expected variable 'ns_names' to have "
- "2 dimensions.");
- const int bufferSize = counts[1];
- char* buffer = (bufferSize > 0) ? new char[bufferSize] : 0;
- for (int i=0; i < numGroups; ++i) {
- ns_names->set_cur(i);
- bool ok = ns_names->get(buffer, 1, bufferSize, 0, 0, 0);
- if (!ok) {
- std::ostringstream msg;
- msg << "Could not read name of nodeset " << ids[i] << ".";
- throw std::runtime_error(msg.str());
- } // if
- groupNames[i] = buffer;
- //std::cout << "GROUP: '" << groupNames[i] << "'." << std::endl;
- } // for
- delete[] buffer; buffer = 0;
- delete[] counts; counts = 0;
+ exofile.getVar(&groupNames, numGroups, "ns_names");
} // if
for (int iGroup=0; iGroup < numGroups; ++iGroup) {
- std::valarray<int> points;
std::ostringstream varname;
+ varname << "num_nod_ns" << iGroup+1;
+ const int nodesetSize = exofile.getDim(varname.str().c_str());
+ int_array points(nodesetSize);
+
+ varname.str("");
varname << "node_ns" << iGroup+1;
- NcVar* node_ns = ncfile.get_var(varname.str().c_str());
- if (0 == node_ns)
- throw std::runtime_error("Could not get node set.");
- const int size = node_ns->num_vals();
+ ndims = 1;
+ dims[0] = nodesetSize;
+
info << journal::at(__HERE__)
<< "Reading node set '" << groupNames[iGroup] << "' with id "
- << ids[iGroup] << " containing "
- << size << " nodes." << journal::endl;
+ << ids[iGroup] << " containing " << nodesetSize << " nodes."
+ << journal::endl;
+ exofile.getVar(&points[0], dims, ndims, varname.str().c_str());
- points.resize(size);
- long* counts = node_ns->edges();
- bool ok = node_ns->get(&points[0], counts);
- delete[] counts; counts = 0;
- if (!ok)
- throw std::runtime_error("Could not get node set.");
- std::sort(&points[0], &points[size]);
+ std::sort(&points[0], &points[nodesetSize]);
points -= 1; // use zero index
GroupPtType type = VERTEX;
@@ -377,7 +306,7 @@
// ----------------------------------------------------------------------
// Write mesh dimensions.
void
-pylith::meshio::MeshIOCubit::_writeDimensions(NcFile& ncfile) const
+pylith::meshio::MeshIOCubit::_writeDimensions(ExodusII& exofile) const
{ // _writeDimensions
throw std::logic_error("MeshIOCubit::_writeDimensions() not implemented.");
} // _writeDimensions
@@ -385,7 +314,7 @@
// ----------------------------------------------------------------------
// Write mesh variables.
void
-pylith::meshio::MeshIOCubit::_writeVariables(NcFile& ncfile) const
+pylith::meshio::MeshIOCubit::_writeVariables(ExodusII& exofile) const
{ // _writeVariables
throw std::logic_error("MeshIOCubit::_writeVariables() not implemented.");
} // _writeVariables
@@ -393,7 +322,7 @@
// ----------------------------------------------------------------------
// Write mesh attributes.
void
-pylith::meshio::MeshIOCubit::_writeAttributes(NcFile& ncfile) const
+pylith::meshio::MeshIOCubit::_writeAttributes(ExodusII& exofile) const
{ // _writeAttributes
throw std::logic_error("MeshIOCubit::_writeAttributes() not implemented.");
} // _writeAttributes
@@ -503,128 +432,5 @@
} // _orientCells
-// ----------------------------------------------------------------------
-// Check if Cubit Exodus file constains variable.
-bool
-pylith::meshio::MeshIOCubit::_hasVar(NcFile& ncfile,
- const char* name) const
-{ // _hasVar
- bool found = false;
- const int nvars = ncfile.num_vars();
- std::cout << "NVARS: " << nvars << std::endl;
- for (int i=0; i < nvars; ++i) {
- NcVar* var = ncfile.get_var(i);
- assert(var);
- std::cout << "VAR " << i << ", name" << var->name() << std::endl;
- if (0 == strcmp(var->name(), name)) {
- found = true;
- break;
- } // if
- } // for
-
- return found;
-} // _hasVar
-
-// ----------------------------------------------------------------------
-// Get values for variable as an array of doubles.
-void
-pylith::meshio::MeshIOCubit::_getVar(double_array* values,
- int* dims,
- int ndims,
- NcFile& ncfile,
- const char* name) const
-{ // _getVar
- if (!_hasVar(ncfile, name)) {
- std::ostringstream msg;
- msg << "Cubit Exodus file '" << _filename << "' is missing variable '"
- << name << "'.";
- throw std::runtime_error(msg.str());
- } // if
-
- NcVar* var = ncfile.get_var(name);
- assert(var);
- if (ndims != var->num_dims()) {
- std::ostringstream msg;
- msg << "Expecting " << ndims << " for variable '" << name <<
- "' in Cubit Exodus file '" << _filename << "' but variable only has "
- << var->num_dims() << " dimensions.";
- throw std::runtime_error(msg.str());
- } // if
-
- for (int iDim=0; iDim < ndims; ++iDim) {
- NcDim* d = var->get_dim(iDim);
- assert(d);
- if (dims[iDim] != d->size()) {
- std::ostringstream msg;
- msg << "Expecting dimension " << iDim << " of variable '" << name
- << "' in Cubit Exodus file '" << _filename << "' to be " << dims[iDim]
- << ", but dimension is " << d->size() << "." << std::endl;
- throw std::runtime_error(msg.str());
- } // if
- } // for
-
- long* counts = var->edges();
- assert(values->size() == var->num_vals());
- bool ok = var->get(&(*values)[0], counts);
- delete[] counts; counts = 0;
- if (!ok) {
- std::ostringstream msg;
- msg << "Coult not get values for variable '" << name <<
- "' in Cubit Exodus file '" << _filename << ".";
- throw std::runtime_error(msg.str());
- } // if
-} // _getVar
-
-// ----------------------------------------------------------------------
-// Get values for variable as an array of ints.
-void
-pylith::meshio::MeshIOCubit::_getVar(int_array* values,
- int* dims,
- int ndims,
- NcFile& ncfile,
- const char* name) const
-{ // _getVar
- if (!_hasVar(ncfile, name)) {
- std::ostringstream msg;
- msg << "Cubit Exodus file '" << _filename << "' is missing variable '"
- << name << "'.";
- throw std::runtime_error(msg.str());
- } // if
-
- NcVar* var = ncfile.get_var(name);
- assert(var);
- if (ndims != var->num_dims()) {
- std::ostringstream msg;
- msg << "Expecting " << ndims << " for variable '" << name <<
- "' in Cubit Exodus file '" << _filename << "' but variable only has "
- << var->num_dims() << " dimensions.";
- throw std::runtime_error(msg.str());
- } // if
-
- for (int iDim=0; iDim < ndims; ++iDim) {
- NcDim* d = var->get_dim(iDim);
- assert(d);
- if (dims[iDim] != d->size()) {
- std::ostringstream msg;
- msg << "Expecting dimension " << iDim << " of variable '" << name
- << "' in Cubit Exodus file '" << _filename << "' to be " << dims[iDim]
- << ", but dimension is " << d->size() << "." << std::endl;
- throw std::runtime_error(msg.str());
- } // if
- } // for
-
- long* counts = var->edges();
- assert(values->size() == var->num_vals());
- bool ok = var->get(&(*values)[0], counts);
- delete[] counts; counts = 0;
- if (!ok) {
- std::ostringstream msg;
- msg << "Coult not get values for variable '" << name <<
- "' in Cubit Exodus file '" << _filename << ".";
- throw std::runtime_error(msg.str());
- } // if
-} // _getVar
-
-
// End of file
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.hh 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/MeshIOCubit.hh 2011-05-27 19:57:36 UTC (rev 18480)
@@ -30,10 +30,6 @@
#include <string> // HASA std::string
-// Forward declarations -------------------------------------------------
-/// C++ input/output manager for CUBIT Exodus II files.
-class NcFile; // netcdf file
-
// MeshIOCubit ----------------------------------------------------------
class pylith::meshio::MeshIOCubit : public MeshIO
{ // MeshIOCubit
@@ -88,7 +84,7 @@
* @param numVertices Pointer to number of vertices.
* @param spaceDim Pointer to dimension of coordinates vector space.
*/
- void _readVertices(NcFile& filein,
+ void _readVertices(ExodusII& filein,
double_array* coordinates,
int* numVertices,
int* spaceDim) const;
@@ -101,7 +97,7 @@
* @param pNumCells Pointer to number of cells
* @param pNumCorners Pointer to number of corners
*/
- void _readCells(NcFile& filein,
+ void _readCells(ExodusII& filein,
int_array* pCells,
int_array* pMaterialIds,
int* numCells,
@@ -111,25 +107,25 @@
*
* @param ncfile Cubit Exodus file.
*/
- void _readGroups(NcFile& filein);
+ void _readGroups(ExodusII& filein);
/** Write mesh dimensions.
*
* @param ncfile Cubit Exodus file.
*/
- void _writeDimensions(NcFile& ncfile) const;
+ void _writeDimensions(ExodusII& ncfile) const;
/** Write mesh variables.
*
* @param ncfile Cubit Exodus file.
*/
- void _writeVariables(NcFile& ncfile) const;
+ void _writeVariables(ExodusII& ncfile) const;
/** Write mesh attributes.
*
* @param ncfile Cubit Exodus file.
*/
- void _writeAttributes(NcFile& ncfile) const;
+ void _writeAttributes(ExodusII& ncfile) const;
/** Reorder vertices in cells to match PyLith conventions.
*
@@ -144,43 +140,6 @@
const int numCorners,
const int meshDim);
- /** Check if Cubit Exodus file constains variable.
- *
- * @param ncfile Cubit Exodus file.
- * @param name Name of variable.
- * @returns True if file contains variable, false otherwise.
- */
- bool _hasVar(NcFile& ncfile,
- const char* name) const;
-
- /** Get values for variable as an array of doubles.
- *
- * @param values Array of values.
- * @param dims Expected dimensions for variable.
- * @param ndims Number of dimension for variable.
- * @param ncfile Cubit Exodus file.
- * @param name Name of variable.
- */
- void _getVar(double_array* values,
- int* dims,
- int ndims,
- NcFile& ncfile,
- const char* name) const;
-
- /** Get values for variable as an array of ints.
- *
- * @param values Array of values.
- * @param dims Expected dimensions for variable.
- * @param ndims Number of dimension for variable.
- * @param ncfile Cubit Exodus file.
- * @param name Name of variable.
- */
- void _getVar(int_array* values,
- int* dims,
- int ndims,
- NcFile& ncfile,
- const char* name) const;
-
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/meshiofwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/meshiofwd.hh 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/meshiofwd.hh 2011-05-27 19:57:36 UTC (rev 18480)
@@ -45,6 +45,7 @@
class PsetFile;
class PsetFileAscii;
class PsetFileBinary;
+ class ExodusII;
template<typename mesh_type, typename field_type> class OutputManager;
template<typename mesh_type, typename field_type> class DataWriter;
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am 2011-05-27 19:57:36 UTC (rev 18480)
@@ -216,8 +216,12 @@
$(PETSC_LIB) $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
if ENABLE_CUBIT
- testmeshio_SOURCES += TestMeshIOCubit.cc
- noinst_HEADERS += TestMeshIOCubit.hh
+ testmeshio_SOURCES += \
+ TestExodusII.cc \
+ TestMeshIOCubit.cc
+ noinst_HEADERS += \
+ TestExodusII.hh \
+ TestMeshIOCubit.hh
testmeshio_LDADD += -lnetcdf_c++ -lnetcdf
endif
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.cc (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,157 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestExodusII.hh" // Implementation of class methods
+
+#include "pylith/meshio/ExodusII.hh"
+
+#include "pylith/utils/array.hh" // USES int_array, double_array, string_vector
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::meshio::TestExodusII );
+
+// ----------------------------------------------------------------------
+// Test constructor
+void
+pylith::meshio::TestExodusII::testConstructor(void)
+{ // testConstructor
+ ExodusII exofile;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test filename()
+void
+pylith::meshio::TestExodusII::testFilename(void)
+{ // testFilename
+ ExodusII exofile;
+
+ const char* filename = "hi.txt";
+ exofile.filename(filename);
+ CPPUNIT_ASSERT(0 == strcmp(filename, exofile.filename()));
+} // testFilename
+
+// ----------------------------------------------------------------------
+// Test open() and close();
+void
+pylith::meshio::TestExodusII::testOpenClose(void)
+{ // testOpenClose
+ ExodusII exofile("data/twotri3.exo");
+ CPPUNIT_ASSERT(exofile._file);
+
+ exofile.close();
+ CPPUNIT_ASSERT(!exofile._file);
+} // testOpenClose
+
+// ----------------------------------------------------------------------
+// Test hasDim()
+void
+pylith::meshio::TestExodusII::testHasDim(void)
+{ // testHasDim
+ ExodusII exofile("data/twotri3.exo");
+
+ CPPUNIT_ASSERT(exofile.hasDim("num_dim"));
+ CPPUNIT_ASSERT(!exofile.hasDim("abcdefghijklm"));
+} // testHasDim
+
+// ----------------------------------------------------------------------
+// Test hasAtt()
+void
+pylith::meshio::TestExodusII::testHasAtt(void)
+{ // testHasAtt
+ ExodusII exofile("data/twotri3.exo");
+
+ CPPUNIT_ASSERT(exofile.hasAtt("version"));
+ CPPUNIT_ASSERT(!exofile.hasAtt("abcdefghijklm"));
+} // testHasAtt
+
+// ----------------------------------------------------------------------
+// Test hasVar()
+void
+pylith::meshio::TestExodusII::testHasVar(void)
+{ // testHasVar
+ ExodusII exofile("data/twotri3.exo");
+
+ CPPUNIT_ASSERT(exofile.hasVar("connect1"));
+ CPPUNIT_ASSERT(!exofile.hasVar("abcdefghijklm"));
+} // testHasVar
+
+// ----------------------------------------------------------------------
+// Test getVar(double*).
+void
+pylith::meshio::TestExodusII::testGetVarDouble(void)
+{ // testGetVarDouble
+ const double coordsE[8] = { -1.0, 0.0, 0.0, 1.0,
+ 0.0, -1.0, 1.0, 0.0 };
+
+ const int ndims = 2;
+ int dims[2];
+ dims[0] = 2;
+ dims[1] = 4;
+ const int size = dims[0]*dims[1];
+ double_array coords(size);
+
+ ExodusII exofile("data/twotri3.exo");
+ exofile.getVar(&coords[0], dims, ndims, "coord");
+
+ const double tolerance = 1.0e-06;
+ for (int i=0; i < size; ++i)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(coordsE[i], coords[i], tolerance);
+} // testGetVarDouble
+
+// ----------------------------------------------------------------------
+// Test getVar(int*).
+void
+pylith::meshio::TestExodusII::testGetVarInt(void)
+{ // testGetVarDouble
+ const int connectE[3] = { 3, 2, 4 };
+
+ const int ndims = 2;
+ int dims[2];
+ dims[0] = 1;
+ dims[1] = 3;
+ const int size = dims[0]*dims[1];
+ int_array connect(size);
+
+ ExodusII exofile("data/twotri3.exo");
+ exofile.getVar(&connect[0], dims, ndims, "connect2");
+
+ for (int i=0; i < size; ++i)
+ CPPUNIT_ASSERT_EQUAL(connectE[i], connect[i]);
+} // testGetVarDouble
+
+// ----------------------------------------------------------------------
+// Test getVar(string_vector).
+void
+pylith::meshio::TestExodusII::testGetVarString(void)
+{ // testGetVarString
+ const char* namesE[2] = { "x", "y" };
+
+ const int dim = 2;
+ string_vector names(2);
+
+ ExodusII exofile("data/twotri3.exo");
+ exofile.getVar(&names, dim, "coor_names");
+
+ for (int i=0; i < dim; ++i)
+ CPPUNIT_ASSERT_EQUAL(std::string(namesE[i]), names[i]);
+} // testGetVarString
+
+
+// End of file
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.hh (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestExodusII.hh 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,94 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/meshio/TestExodusII.hh
+ *
+ * @brief C++ TestExodusII object
+ *
+ * C++ unit testing for ExodusII.
+ */
+
+#if !defined(pylith_meshio_testexodusii_hh)
+#define pylith_meshio_testexodusii_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+// Forward declarations -------------------------------------------------
+namespace pylith {
+ namespace meshio {
+ class TestExodusII;
+ } // meshio
+} // pylith
+
+// TestExodusII ------------------------------------------------------
+class pylith::meshio::TestExodusII : public CppUnit::TestFixture
+{ // class TestExodusII
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestExodusII );
+
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testFilename );
+ CPPUNIT_TEST( testOpenClose );
+ CPPUNIT_TEST( testHasDim );
+ CPPUNIT_TEST( testHasAtt );
+ CPPUNIT_TEST( testHasVar );
+ CPPUNIT_TEST( testGetVarDouble );
+ CPPUNIT_TEST( testGetVarInt );
+ CPPUNIT_TEST( testGetVarString );
+
+ CPPUNIT_TEST_SUITE_END();
+
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /// Test constructor
+ void testConstructor(void);
+
+ /// Test filename()
+ void testFilename(void);
+
+ /// Test open() and close().
+ void testOpenClose(void);
+
+ /// Test hasDim()
+ void testHasDim(void);
+
+ /// Test hasAtt()
+ void testHasAtt(void);
+
+ /// Test hasVar()
+ void testHasVar(void);
+
+ /// Test getVar(double*)
+ void testGetVarDouble(void);
+
+ /// Test getVar(int*)
+ void testGetVarInt(void);
+
+ /// Test getVar(string_vector)
+ void testGetVarString(void);
+
+}; // class TestExodusII
+
+#endif // pylith_meshio_testexodusii_hh
+
+
+// End of file
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOCubit.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOCubit.cc 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOCubit.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -82,8 +82,8 @@
pylith::meshio::TestMeshIOCubit::testReadTri(void)
{ // testReadTri
MeshDataCubitTri data;
- const char* filename = "data/twotri3.exo";
- _testRead(data, filename);
+ _testRead(data, "data/twotri3_12.2.exo");
+ _testRead(data, "data/twotri3_13.0.exo");
} // testReadTri
// ----------------------------------------------------------------------
@@ -92,8 +92,8 @@
pylith::meshio::TestMeshIOCubit::testReadQuad(void)
{ // testReadQuad
MeshDataCubitQuad data;
- const char* filename = "data/twoquad4.exo";
- _testRead(data, filename);
+ _testRead(data, "data/twoquad4_12.2.exo");
+ _testRead(data, "data/twoquad4_13.0.exo");
} // testReadQuad
// ----------------------------------------------------------------------
@@ -102,8 +102,8 @@
pylith::meshio::TestMeshIOCubit::testReadTet(void)
{ // testReadTet
MeshDataCubitTet data;
- const char* filename = "data/twotet4.exo";
- _testRead(data, filename);
+ _testRead(data, "data/twotet4_12.2.exo");
+ _testRead(data, "data/twotet4_13.0.exo");
} // testReadTet
// ----------------------------------------------------------------------
@@ -112,8 +112,8 @@
pylith::meshio::TestMeshIOCubit::testReadHex(void)
{ // testReadHex
MeshDataCubitHex data;
- const char* filename = "data/twohex8.exo";
- _testRead(data, filename);
+ _testRead(data, "data/twohex8_12.2.exo");
+ _testRead(data, "data/twohex8_13.0.exo");
} // testReadHex
// ----------------------------------------------------------------------
@@ -124,7 +124,7 @@
{ // _testRead
MeshIOCubit iohandler;
iohandler.filename(filename);
- iohandler.useNodesetNames(false);
+ iohandler.useNodesetNames(true);
// Read mesh
topology::Mesh mesh;
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am 2011-05-27 19:57:36 UTC (rev 18480)
@@ -26,10 +26,14 @@
cube2_binary_64.gmv \
cube2_binary_64.pset \
mesh3DIndexOne.txt \
- twotri3.exo \
- twoquad4.exo \
- twotet4.exo \
- twohex8.exo \
+ twotri3_12.2.exo \
+ twotri3_13.0.exo \
+ twoquad4_12.2.exo \
+ twoquad4_13.0.exo \
+ twotet4_12.2.exo \
+ twotet4_13.0.exo \
+ twohex8_12.2.exo \
+ twohex8_13.0.exo \
mesh2D_comments.txt \
line2.mesh \
line2_t10.vtk \
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitHex.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitHex.cc 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitHex.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -63,7 +63,7 @@
};
const char* pylith::meshio::MeshDataCubitHex::_groupNames[] = {
- "2", "4"
+ "right_face", "top_face"
};
const char* pylith::meshio::MeshDataCubitHex::_groupTypes[] = {
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitQuad.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitQuad.cc 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitQuad.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -48,15 +48,15 @@
const int pylith::meshio::MeshDataCubitQuad::_numGroups = 2;
const int pylith::meshio::MeshDataCubitQuad::_groupSizes[] =
- { 2, 2 };
+ { 2, 3 };
const int pylith::meshio::MeshDataCubitQuad::_groups[] = {
0, 3,
- 4, 5
+ 2, 3, 5
};
const char* pylith::meshio::MeshDataCubitQuad::_groupNames[] = {
- "100", "101"
+ "left_edge", "top_edge"
};
const char* pylith::meshio::MeshDataCubitQuad::_groupTypes[] = {
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTet.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTet.cc 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTet.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -41,21 +41,22 @@
1, 4, 2, 3
};
const int pylith::meshio::MeshDataCubitTet::_materialIds[] = {
- 1, 2
+ 7, 8
};
const int pylith::meshio::MeshDataCubitTet::_numGroups = 2;
const int pylith::meshio::MeshDataCubitTet::_groupSizes[] =
- { 3, 4 };
+ { 4, 3 };
const int pylith::meshio::MeshDataCubitTet::_groups[] = {
+ 0, 1, 2, 3,
1, 2, 3,
- 0, 1, 2, 4
};
const char* pylith::meshio::MeshDataCubitTet::_groupNames[] = {
- "100", "101"
+ "bottom_face",
+ "mid_face",
};
const char* pylith::meshio::MeshDataCubitTet::_groupTypes[] = {
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTri.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTri.cc 2011-05-27 18:19:37 UTC (rev 18479)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshDataCubitTri.cc 2011-05-27 19:57:36 UTC (rev 18480)
@@ -46,15 +46,15 @@
const int pylith::meshio::MeshDataCubitTri::_numGroups = 2;
const int pylith::meshio::MeshDataCubitTri::_groupSizes[] =
- { 1, 1 };
+ { 1, 2 };
const int pylith::meshio::MeshDataCubitTri::_groups[] = {
0,
- 3
+ 2, 3
};
const char* pylith::meshio::MeshDataCubitTri::_groupNames[] = {
- "5", "6"
+ "left_vertex", "right_vertex"
};
const char* pylith::meshio::MeshDataCubitTri::_groupTypes[] = {
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/gentwocell.jou
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/gentwocell.jou (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/gentwocell.jou 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,7 @@
+# CUBIT script to generate simple Exodus files for testing ExodusII
+# and MeshIOCubit.
+
+playback "twotri3.jou"
+playback "twoquad4.jou"
+playback "twotet4.jou"
+playback "twohex8.jou"
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.cub
===================================================================
(Binary files differ)
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.exo
===================================================================
(Binary files differ)
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.jou
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.jou (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8.jou 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,36 @@
+# CUBIT script to generate simple Exodus files for testing ExodusII
+# and MeshIOCubit.
+
+reset
+
+create node location -2.0 -1.0 1.0
+create node location -2.0 -1.0 -1.0
+create node location -2.0 1.0 -1.0
+create node location -2.0 1.0 1.0
+create node location 0.0 -1.0 1.0
+create node location 0.0 -1.0 -1.0
+create node location 0.0 1.0 -1.0
+create node location 0.0 1.0 1.0
+create node location 2.0 -1.0 1.0
+create node location 2.0 -1.0 -1.0
+create node location 2.0 1.0 -1.0
+create node location 2.0 1.0 1.0
+
+
+create hex node 1 2 3 4 5 6 7 8
+create hex node 5 6 7 8 9 10 11 12
+
+block 7 hex 1
+block 8 hex 2
+
+nodeset 1 node 9 10 11 12
+nodeset 1 name "right_face"
+
+nodeset 2 node 1 4 5 8 9 12
+nodeset 2 name "top_face"
+
+#{filename=Quote("twohex8_"//VERSION//".exo")}
+export mesh {filename} dimension 3 overwrite
+
+
+
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8_12.2.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8_12.2.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8_13.0.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twohex8_13.0.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.cub
===================================================================
(Binary files differ)
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.exo
===================================================================
(Binary files differ)
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.jou
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.jou (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4.jou 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,28 @@
+# CUBIT script to generate simple Exodus files for testing ExodusII
+# and MeshIOCubit.
+
+reset
+
+create node location 0.0 0.0 0.0
+create node location 1.0 0.0 0.0
+create node location 1.0 1.0 0.0
+create node location 0.0 1.0 0.0
+create node location 2.0 0.0 0.0
+create node location 2.0 1.0 0.0
+
+create face node 1 2 3 4
+create face node 2 5 6 3
+
+block 10 face 1
+block 11 face 2
+
+nodeset 1 node 1 4
+nodeset 1 name "left_edge"
+
+nodeset 2 node 3 4 6
+nodeset 2 name "top_edge"
+
+#{filename=Quote("twoquad4_"//VERSION//".exo")}
+export mesh {filename} dimension 2 overwrite
+
+
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4_12.2.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4_12.2.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4_13.0.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twoquad4_13.0.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.cub
===================================================================
(Binary files differ)
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.exo
===================================================================
(Binary files differ)
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.jou
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.jou (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4.jou 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,28 @@
+# CUBIT script to generate simple Exodus files for testing ExodusII
+# and MeshIOCubit.
+
+reset
+
+create node location -2.0 0.0 0.0
+create node location 0.0 -1.0 0.0
+create node location 0.0 1.0 0.0
+create node location 0.0 0.0 2.0
+create node location 2.0 0.0 0.0
+
+
+create tet node 1 2 3 4
+create tet node 2 5 3 4
+
+block 7 tet 1
+block 8 tet 2
+
+nodeset 1 node 2 3 4
+nodeset 1 name "mid_face"
+
+nodeset 2 node 1 2 3 4
+nodeset 2 name "bottom_face"
+
+#{filename=Quote("twotet4_"//VERSION//".exo")}
+export mesh {filename} dimension 3 overwrite
+
+
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4_12.2.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4_12.2.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4_13.0.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotet4_13.0.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.cub
===================================================================
(Binary files differ)
Deleted: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.exo
===================================================================
(Binary files differ)
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.jou
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.jou (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3.jou 2011-05-27 19:57:36 UTC (rev 18480)
@@ -0,0 +1,26 @@
+# CUBIT script to generate simple Exodus files for testing ExodusII
+# and MeshIOCubit.
+
+reset
+
+create node location -1.0 0.0 0.0
+create node location 0.0 -1.0 0.0
+create node location 0.0 1.0 0.0
+create node location 1.0 0.0 0.0
+
+create tri node 1 2 3
+create tri node 3 2 4
+
+block 2 tri 1
+block 3 tri 2
+
+nodeset 1 node 1
+nodeset 1 name "left_vertex"
+
+nodeset 2 node 3 4
+nodeset 2 name "right_vertex"
+
+#{filename=Quote("twotri3_"//VERSION//".exo")}
+export mesh {filename} dimension 2 overwrite
+
+
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3_12.2.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3_12.2.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3_13.0.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/libtests/meshio/data/twotri3_13.0.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the CIG-COMMITS
mailing list