[cig-commits] r18488 - in short/3D/PyLith/trunk: libsrc/pylith/meshio libsrc/pylith/topology unittests/libtests/topology

brad at geodynamics.org brad at geodynamics.org
Sun May 29 08:46:39 PDT 2011


Author: brad
Date: 2011-05-29 08:46:39 -0700 (Sun, 29 May 2011)
New Revision: 18488

Added:
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.hh
Modified:
   short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5.cc
   short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5Ext.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.hh
   short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
Log:
Create string<->enum conversion routine. Use string for vector field type in HDF5 files.

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5.cc	2011-05-29 03:15:17 UTC (rev 18487)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5.cc	2011-05-29 15:46:39 UTC (rev 18488)
@@ -312,10 +312,9 @@
       hid_t h5 = -1;
       err = PetscViewerHDF5GetFileId(_viewer, &h5); CHECK_PETSC_ERROR(err);
       assert(h5 >= 0);
-      const int vectorFieldType = field.vectorFieldType();
       std::string fullName = std::string("/vertex_fields/") + field.label();
       HDF5::writeAttribute(h5, fullName.c_str(), "vector_field_type",
-			   (void*)&vectorFieldType, H5T_NATIVE_INT);
+			   topology::FieldBase::vectorFieldString(field.vectorFieldType()));
     } // if
   } catch (const std::exception& err) {
     std::ostringstream msg;

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5Ext.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5Ext.cc	2011-05-29 03:15:17 UTC (rev 18487)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/DataWriterHDF5Ext.cc	2011-05-29 15:46:39 UTC (rev 18488)
@@ -364,10 +364,9 @@
 	_h5->createDatasetRawExternal("/vertex_fields", field.label(),
 				      _datasetFilename(field.label()).c_str(),
 				      dims, ndims, H5T_IEEE_F64BE);
-	const int vectorFieldType = field.vectorFieldType();
 	std::string fullName = std::string("/vertex_fields/") + field.label();
 	_h5->writeAttribute(fullName.c_str(), "vector_field_type",
-			    (void*)&vectorFieldType, H5T_NATIVE_INT);
+			    topology::FieldBase::vectorFieldString(field.vectorFieldType()));
 
       } else {
 	// Update number of time steps in external dataset info in HDF5 file.

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.cc	2011-05-29 03:15:17 UTC (rev 18487)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.cc	2011-05-29 15:46:39 UTC (rev 18488)
@@ -32,5 +32,65 @@
 { // destructor
 } // destructor
 
+// ----------------------------------------------------------------------
+// Get string associated with vector field type.
+const char*
+pylith::topology::FieldBase::vectorFieldString(VectorFieldEnum value)
+{ // vectorFieldString
+  switch (value) {
+  case SCALAR :
+    return "scalar";
+  case VECTOR :
+    return "vector";
+  case TENSOR :
+    return "tensor";
+  case OTHER :
+    return "other";
+  case MULTI_SCALAR :
+    return "multi_scalar";
+  case MULTI_VECTOR :
+    return "multi_vector";
+  case MULTI_TENSOR :
+    return "multi_tensor";
+  case MULTI_OTHER :
+    return "multi_other";
+  default :
+    assert(0);
+    throw std::logic_error("Unknown vector field type in vectorFieldString().");
+  } // switch
+} // vectorFieldString
 
+// ----------------------------------------------------------------------
+// Get string associated with vector field type.
+pylith::topology::FieldBase::VectorFieldEnum
+pylith::topology::FieldBase::parseVectorFieldString(const char* value)
+{ // parseVectorFieldString
+  VectorFieldEnum valueEnum = SCALAR;
+
+  if (0 == strcmp(value, "scalar"))
+    valueEnum = SCALAR;
+  else if (0 == strcmp(value, "vector"))
+    valueEnum = VECTOR;
+  else if (0 == strcmp(value, "tensor"))
+    valueEnum = TENSOR;
+  else if (0 == strcmp(value, "other"))
+    valueEnum = OTHER;
+  else if (0 == strcmp(value, "multi_scalar"))
+    valueEnum = MULTI_SCALAR;
+  else if (0 == strcmp(value, "multi_vector"))
+    valueEnum = MULTI_VECTOR;
+  else if (0 == strcmp(value, "multi_tensor"))
+    valueEnum = MULTI_TENSOR;
+  else if (0 == strcmp(value, "multi_other"))
+    valueEnum = MULTI_OTHER;
+  else {
+    assert(0);
+    throw std::logic_error("Unknown vector field string in "
+			   "parseVectorFieldString().");
+  } // else
+  
+  return valueEnum;
+} // parseVectorFieldString
+
+
 // End of file 

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.hh	2011-05-29 03:15:17 UTC (rev 18487)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/FieldBase.hh	2011-05-29 15:46:39 UTC (rev 18488)
@@ -74,6 +74,24 @@
   FieldBase(void); ///< Default constructor.
   ~FieldBase(void); ///< Default destructor.
 
+  /** Get string associated with vector field type.
+   *
+   * @param value Vector field type.
+   * @returns String associated with vector field type.
+   */
+  static
+  const char*
+  vectorFieldString(VectorFieldEnum value);
+
+  /** Get string associated with vector field type.
+   *
+   * @param value String associated with vector field type.
+   * @returns Vector field type.
+   */
+  static
+  VectorFieldEnum
+  parseVectorFieldString(const char* value);
+
 // NOT IMPLEMENTED //////////////////////////////////////////////////////
 private :
 

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am	2011-05-29 03:15:17 UTC (rev 18487)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am	2011-05-29 15:46:39 UTC (rev 18488)
@@ -30,6 +30,7 @@
 	TestMesh.cc \
 	TestMeshOps.cc \
 	TestSubMesh.cc \
+	TestFieldBase.cc \
 	TestFieldMesh.cc \
 	TestFieldSubMesh.cc \
 	TestFieldsMesh.cc \
@@ -45,6 +46,7 @@
 	TestMesh.hh \
 	TestSubMesh.hh \
 	TestMeshOps.hh \
+	TestFieldBase.hh \
 	TestFieldMesh.hh \
 	TestFieldSubMesh.hh \
 	TestFieldsMesh.hh \

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.cc	2011-05-29 15:46:39 UTC (rev 18488)
@@ -0,0 +1,77 @@
+// -*- 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 "TestFieldBase.hh" // Implementation of class methods
+
+#include "pylith/topology/FieldBase.hh" // USES Field
+
+#include <string> // USES std::string
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestFieldBase );
+
+// ----------------------------------------------------------------------
+// Test vectorFieldString()
+void
+pylith::topology::TestFieldBase::testVectorFieldString(void)
+{ // testVectorFieldString
+  CPPUNIT_ASSERT_EQUAL(std::string("scalar"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::SCALAR)));
+  CPPUNIT_ASSERT_EQUAL(std::string("vector"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::VECTOR)));
+  CPPUNIT_ASSERT_EQUAL(std::string("tensor"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::TENSOR)));
+  CPPUNIT_ASSERT_EQUAL(std::string("other"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::OTHER)));
+  CPPUNIT_ASSERT_EQUAL(std::string("multi_scalar"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::MULTI_SCALAR)));
+  CPPUNIT_ASSERT_EQUAL(std::string("multi_vector"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::MULTI_VECTOR)));
+  CPPUNIT_ASSERT_EQUAL(std::string("multi_tensor"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::MULTI_TENSOR)));
+  CPPUNIT_ASSERT_EQUAL(std::string("multi_other"),
+		       std::string(FieldBase::vectorFieldString(FieldBase::MULTI_OTHER)));
+} // testVectorFieldString
+
+// ----------------------------------------------------------------------
+// Test parseVectorFieldString()
+void
+pylith::topology::TestFieldBase::testParseVectorFieldString(void)
+{ // testParseVectorFieldString
+  CPPUNIT_ASSERT_EQUAL(FieldBase::SCALAR,
+		       FieldBase::parseVectorFieldString("scalar"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::VECTOR,
+		       FieldBase::parseVectorFieldString("vector"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::TENSOR,
+		       FieldBase::parseVectorFieldString("tensor"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::OTHER,
+		       FieldBase::parseVectorFieldString("other"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::MULTI_SCALAR,
+		       FieldBase::parseVectorFieldString("multi_scalar"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::MULTI_VECTOR,
+		       FieldBase::parseVectorFieldString("multi_vector"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::MULTI_TENSOR,
+		       FieldBase::parseVectorFieldString("multi_tensor"));
+  CPPUNIT_ASSERT_EQUAL(FieldBase::MULTI_OTHER,
+		       FieldBase::parseVectorFieldString("multi_other"));
+} // testParseVectorFieldString
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldBase.hh	2011-05-29 15:46:39 UTC (rev 18488)
@@ -0,0 +1,69 @@
+// -*- 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/topology/TestFieldBase.hh
+ *
+ * @brief C++ unit testing for Field.
+ */
+
+#if !defined(pylith_topology_testfieldbase_hh)
+#define pylith_topology_testfieldbase_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "pylith/topology/topologyfwd.hh" // forward declarations
+
+// Forward declarations -------------------------------------------------
+/// Namespace for pylith package
+namespace pylith {
+  namespace topology {
+    class TestFieldBase;
+  } // topology
+} // pylith
+
+// TestFieldBase -------------------------------------------------------------
+/// C++ unit testing for Field.
+class pylith::topology::TestFieldBase : public CppUnit::TestFixture
+{ // class TestFieldBase
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestFieldBase );
+
+  CPPUNIT_TEST( testVectorFieldString );
+  CPPUNIT_TEST( testParseVectorFieldString );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test vectorFieldString().
+  void testVectorFieldString(void);
+
+  /// Test parseVectorFieldString().
+  void testParseVectorFieldString(void);
+
+
+}; // class TestFieldBase
+
+#endif // pylith_topology_testfieldbase_hh
+
+
+// End of file 



More information about the CIG-COMMITS mailing list