[cig-commits] r13456 - in short/3D/PyLith/trunk: . libsrc libsrc/topology libsrc/utils unittests/libtests/topology

brad at geodynamics.org brad at geodynamics.org
Wed Dec 3 17:40:53 PST 2008


Author: brad
Date: 2008-12-03 17:40:52 -0800 (Wed, 03 Dec 2008)
New Revision: 13456

Added:
   short/3D/PyLith/trunk/libsrc/topology/Field.cc
   short/3D/PyLith/trunk/libsrc/topology/Field.hh
   short/3D/PyLith/trunk/libsrc/topology/Field.icc
   short/3D/PyLith/trunk/libsrc/topology/Mesh.cc
   short/3D/PyLith/trunk/libsrc/topology/Mesh.icc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh
   short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.hh
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/Makefile.am
   short/3D/PyLith/trunk/libsrc/topology/Makefile.am
   short/3D/PyLith/trunk/libsrc/topology/Mesh.hh
   short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh
   short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
Log:
Created on PyLith Mesh and Field objects to extend Sieve Mesh and Mesh::real_section_type.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2008-12-03 20:38:21 UTC (rev 13455)
+++ short/3D/PyLith/trunk/TODO	2008-12-04 01:40:52 UTC (rev 13456)
@@ -10,7 +10,21 @@
 1. Reduce memory use (new labels) [Matt]
 
 2. Nondimensionalize [Brad]
+    Not working
+      coordinates in output (nondimensional instead of dimensioned)
+      solution in output (nondimensional instead of dimensioned)
+      const slip rate in output (slip rate not slip)          
 
+    Need unit tests
+      FieldOps::copyValues (obsolete?)
+      MeshIO::normalizer()
+      Material::normalizer()
+      Material::_nodimProperties()
+      Material::_dimProperties()
+      Constraint::normalizer()
+      Integrator::normalizer()
+      DataWriter::normalizer()
+
 3. Clean-up interface for materials [Brad]
 
 4. Power-law nonlinear rheology [Charles]
@@ -155,10 +169,6 @@
 
   1. Replace Pyrex/pyrexembed with SWIG
 
-  2. PyLith Mesh
-      Sieve mesh
-      coordinate system
-
   3. Fields and SolutionFields objects (containers for fields over same mesh)
        PyLith Field and FieldUniform
          Sieve real section
@@ -183,6 +193,8 @@
          Interpolate solution to desired location
          Solution field (time history)
 
+  5. Use shared pointers for objects where both Python and C++ hold pointers.
+
 ======================================================================
 THINGS WE NEED SIEVE TO DO (Matt)
 ======================================================================

Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am	2008-12-03 20:38:21 UTC (rev 13455)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am	2008-12-04 01:40:52 UTC (rev 13456)
@@ -93,8 +93,10 @@
 	meshio/VertexFilter.cc \
 	meshio/VertexFilterVecNorm.cc \
 	topology/Distributor.cc \
+	topology/Field.cc \
 	topology/FieldsManager.cc \
 	topology/FieldOps.cc \
+	topology/Mesh.cc \
 	topology/MeshOps.cc \
 	topology/MeshRefiner.cc \
 	topology/RefineUniform.cc \

Added: short/3D/PyLith/trunk/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.cc	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,83 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "Field.hh" // implementation of class methods
+
+#include "pylith/utils/array.hh" // USES double_array
+
+#include "spatialdata/geocoords/CoordSys.hh" // USES CoordSys
+#include "spatialdata/units/Nondimensional.hh" // USES Nondimensional
+
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+#include <cassert> // USES assert()
+
+// ----------------------------------------------------------------------
+// Default constructor.
+pylith::topology::Field::Field(const ALE::Obj<SieveMesh>& mesh) :
+  _scale(1.0),
+  _name("unknown"),
+  _spaceDim(0),
+  _vecFieldType(OTHER),
+  _dimensionsOkay(false)
+{ // constructor
+  assert(!mesh.isNull());
+
+  _section = new SieveMesh::real_section_type(mesh->comm(), mesh->debug());
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor.
+pylith::topology::Field::~Field(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Dimensionalize field.
+void
+pylith::topology::Field::dimensionalize(void)
+{ // dimensionalize
+  if (!_dimensionsOkay) {
+    std::ostringstream msg;
+    msg << "Cannot dimensionalize field '" << _name << "' because the flag "
+	<< "has been set to keep field nondimensional.";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  typedef SieveMesh::real_section_type::chart_type chart_type;
+
+  assert(!_section.isNull());
+  const chart_type& chart = _section->getChart();
+  const chart_type::const_iterator chartEnd = chart.end();
+
+  // Assume fiber dimension is uniform
+  const int fiberDim = _section->getFiberDimension(*chart.begin());
+  double_array values(fiberDim);
+
+  spatialdata::units::Nondimensional normalizer;
+
+  for (chart_type::const_iterator c_iter = chart.begin();
+       c_iter != chartEnd;
+       ++c_iter) {
+    assert(fiberDim == _section->getFiberDimension(*c_iter));
+
+    _section->restrictPoint(*c_iter, &values[0], values.size());
+    normalizer.dimensionalize(&values[0], values.size(), _scale);
+    _section->updatePoint(*c_iter, &values[0]);
+  } // for
+  
+} // dimensionalize
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.hh	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,163 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/topology/Field.hh
+ *
+ * @brief Vector field over the vertices or cells of a finite-element mesh.
+ *
+ * Extends Sieve real general section by adding metadata.
+ */
+
+#if !defined(pylith_topology_field_hh)
+#define pylith_topology_field_hh
+
+// Include directives ---------------------------------------------------
+#define NEWPYLITHMESH 1
+#include "pylith/utils/sievetypes.hh" // HASA PETSc real_section_type
+
+#include <string> // HASA std::string
+
+// Forward declarations -------------------------------------------------
+namespace pylith {
+  namespace topology {
+    class Field;
+    class TestField;
+  } // topology
+} // pylith
+
+// Field ----------------------------------------------------------------
+class pylith::topology::Field
+{ // Field
+  friend class TestField; // unit testing
+
+// PUBLIC ENUMS /////////////////////////////////////////////////////////
+public :
+
+  enum VectorFieldEnum {
+    SCALAR, ///< Scalar.
+    VECTOR, ///< Vector.
+    TENSOR, ///< Tensor.
+    OTHER, ///< Not a scalar, vector, or tensor.
+    MULTI_SCALAR, ///< Scalar at multiple points.
+    MULTI_VECTOR, ///< Vector at multiple points.
+    MULTI_TENSOR, ///< Tensor at multiple points.
+    MULTI_OTHER, ///< Not a scalar, vector, or tensor at multiple points.
+  }; // VectorFieldEnum
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param mesh Sieve mesh.
+   */
+  Field(const ALE::Obj<SieveMesh>& mesh);
+
+  /// Destructor.
+  ~Field(void);
+
+  /** Get Sieve section.
+   *
+   * @returns Sieve section.
+   */
+  const ALE::Obj<SieveMesh::real_section_type>& section(void) const;
+
+  /** Set name of field.
+   *
+   * @param value Name of field.
+   */
+  void name(const char* value);
+
+  /** Get name of field.
+   *
+   * @returns Name of field.
+   */
+  const char* name(void) const;
+
+  /** Set vector field type
+   *
+   * @param value Type of vector field.
+   */
+  void vectorFieldType(const VectorFieldEnum value);
+
+  /** Get vector field type
+   *
+   * @returns Type of vector field.
+   */
+  VectorFieldEnum vectorFieldType(void) const;
+
+  /** Set spatial dimension of domain.
+   *
+   * @param value Spatial dimension of domain.
+   */
+  void spaceDim(const int value);
+
+  /** Get spatial dimension of domain.
+   *
+   * @returns Spatial dimension of domain.
+   */
+  int spaceDim(void) const;
+
+  /** Set scale for dimensionalizing field.
+   *
+   * @param value Scale associated with field.
+   */
+  void scale(const double value);
+
+  /** Get scale for dimensionalizing field.
+   *
+   * @returns Scale associated with field.
+   */
+  double scale(void) const;
+
+  /** Set flag indicating whether it is okay to dimensionalize field.
+   *
+   * @param value True if it is okay to dimensionalize field.
+   */
+  void addDimensionOkay(const bool value);
+
+  /** Set flag indicating whether it is okay to dimensionalize field.
+   *
+   * @param value True if it is okay to dimensionalize field.
+   */
+  bool addDimensionOkay(void) const;
+
+  /** Dimensionalize field. Throws runtime_error if field is not
+   * allowed to be dimensionalized.
+   */
+  void dimensionalize(void);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  double _scale; ///< Dimensional scale associated with field
+  ALE::Obj<SieveMesh::real_section_type> _section; ///< Real section with data
+  std::string _name; ///< Name of field
+  int _spaceDim; ///< Spatial dimension of domain
+  VectorFieldEnum _vecFieldType; ///< Type of vector field
+  bool _dimensionsOkay; ///< Flag indicating it is okay to dimensionalize
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  Field(const Field&); ///< Not implemented
+  const Field& operator=(const Field&); ///< Not implemented
+
+}; // Field
+
+#include "Field.icc"
+
+#endif // pylith_topology_field_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/topology/Field.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.icc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.icc	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,98 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_topology_field_hh)
+#error "Field.icc must be included only from Field.hh"
+#else
+
+// Get Sieve section.
+inline
+const ALE::Obj<pylith::SieveMesh::real_section_type>&
+pylith::topology::Field::section(void) const {
+  return _section;
+}
+
+// Set name of field.
+inline
+void
+pylith::topology::Field::name(const char* value) {
+  _name = value;
+}
+
+// Get name of field.
+inline
+const char*
+pylith::topology::Field::name(void) const {
+  return _name.c_str();
+}
+
+// Set vector field type
+inline
+void
+pylith::topology::Field::vectorFieldType(const VectorFieldEnum value) {
+  _vecFieldType = value;
+}
+
+// Get vector field type
+inline
+pylith::topology::Field::VectorFieldEnum
+pylith::topology::Field::vectorFieldType(void) const {
+  return _vecFieldType;
+}
+
+// Set spatial dimension of domain.
+inline
+void
+pylith::topology::Field::spaceDim(const int value) {
+  _spaceDim = value;
+}
+
+// Get spatial dimension of domain.
+inline
+int
+pylith::topology::Field::spaceDim(void) const {
+  return _spaceDim;
+}
+
+// Set scale for dimensionalizing field.
+inline
+void
+pylith::topology::Field::scale(const double value) {
+  _scale = value;
+}
+
+// Get scale for dimensionalizing field.
+inline
+double
+pylith::topology::Field::scale(void) const {
+  return _scale;
+}
+
+// Set flag indicating whether it is okay to dimensionalize field.
+inline
+void
+pylith::topology::Field::addDimensionOkay(const bool value) {
+  _dimensionsOkay = value;
+}
+
+// Set flag indicating whether it is okay to dimensionalize field.
+inline
+bool
+pylith::topology::Field::addDimensionOkay(void) const {
+  return _dimensionsOkay;
+}
+
+
+#endif
+
+
+// End of file

Modified: short/3D/PyLith/trunk/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2008-12-03 20:38:21 UTC (rev 13455)
+++ short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2008-12-04 01:40:52 UTC (rev 13456)
@@ -15,8 +15,12 @@
 
 subpkginclude_HEADERS = \
 	Distributor.hh \
+	Field.hh \
+	Field.icc \
 	FieldsManager.hh \
 	FieldOps.hh \
+	Mesh.hh \
+	Mesh.icc \
 	MeshOps.hh \
 	MeshRefiner.hh \
 	RefineUniform.hh

Added: short/3D/PyLith/trunk/libsrc/topology/Mesh.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.cc	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "Mesh.hh" // implementation of class methods
+
+#include "spatialdata/geocoords/CoordSys.hh" // USES CoordSys
+
+// ----------------------------------------------------------------------
+// Default constructor
+pylith::topology::Mesh::Mesh(const MPI_Comm& comm,
+			     const int dim) :
+  _mesh(new SieveMesh(comm, dim)),
+  _coordsys(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor
+pylith::topology::Mesh::~Mesh(void)
+{ // destructor
+  delete _coordsys; _coordsys = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set coordinate system.
+void
+pylith::topology::Mesh::coordsys(const spatialdata::geocoords::CoordSys* cs)
+{ // coordsys
+  delete _coordsys; _coordsys = (0 != cs) ? cs->clone() : 0;
+} // coordsys
+
+// ----------------------------------------------------------------------
+// Initialize the finite-element mesh.
+void 
+pylith::topology::Mesh::initialize(void)
+{ // initialize
+  if (0 != _coordsys)
+    _coordsys->initialize();
+} // initialize
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/libsrc/topology/Mesh.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.hh	2008-12-03 20:38:21 UTC (rev 13455)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.hh	2008-12-04 01:40:52 UTC (rev 13456)
@@ -13,31 +13,92 @@
 /**
  * @file pylith/topology/Mesh.hh
  *
- * @brief Type definitions for use of PETSc mesh in PyLith.
+ * @brief PyLith finite-element mesh.
+ *
+ * Extends Sieve mesh to include coordinate system associated with
+ * domain.
  */
 
 #if !defined(pylith_topology_mesh_hh)
 #define pylith_topology_mesh_hh
 
+// Include directives ---------------------------------------------------
+#define NEWPYLITHMESH 1
+#include "pylith/utils/sievetypes.hh"
+
+// Forward declarations -------------------------------------------------
 namespace pylith {
   namespace topology {
     class Mesh;
   } // topology
 } // pylith
 
+namespace spatialdata {
+  namespace geocoords {
+    class CoordSys;
+  } // geocoords
+} // spatialdata
+
+// Mesh -----------------------------------------------------------------
 class pylith::topology::Mesh
 { // Mesh
 
-  // PUBLIC TYPEDEFS //////////////////////////////////////////////////////
+// PUBLIC METHODS ///////////////////////////////////////////////////////
 public :
 
-  typedef ALE::Obj Obj;
-  typedef ALE::Field::Mesh Mesh;
-  typedef Mesh::point_type point_type;
-  typedef Mesh::real_section_type real_section_type;
+  /** Default constructor.
+   *
+   * @param comm MPI communicator for mesh.
+   * @param dim Dimension associated with mesh cells.
+   */
+  Mesh(const MPI_Comm& comm =PETSC_COMM_WORLD,
+       const int dim =3); 
 
+  /// Default destructor
+  ~Mesh(void);
+
+  /** Get Sieve mesh.
+   *
+   * @returns Sieve mesh.
+   */
+  const ALE::Obj<SieveMesh>& sieveMesh(void) const;
+
+  /** Get Sieve mesh.
+   *
+   * @returns Sieve mesh.
+   */
+  ALE::Obj<SieveMesh>& sieveMesh(void);
+
+  /** Set coordinate system.
+   *
+   * @param cs Coordinate system.
+   */
+  void coordsys(const spatialdata::geocoords::CoordSys* cs);
+
+  /** Get coordinate system.
+   *
+   * @returns Coordinate system.
+   */
+  const spatialdata::geocoords::CoordSys* coordsys(void) const;
+
+  /// Initialize the finite-element mesh.
+  void initialize(void);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  ALE::Obj<SieveMesh> _mesh; ///< Sieve mesh
+  spatialdata::geocoords::CoordSys* _coordsys; ///< Coordinate system
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  Mesh(const Mesh&); ///< Not implemented
+  const Mesh& operator=(const Mesh&); ///< Not implemented
+
 }; // Mesh
 
+#include "Mesh.icc"
 
 #endif // pylith_topology_mesh_hh
 

Added: short/3D/PyLith/trunk/libsrc/topology/Mesh.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.icc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.icc	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_topology_mesh_hh)
+#error "Mesh.icc must be included only from Mesh.hh"
+#else
+
+// Get Sieve mesh.
+inline
+const ALE::Obj<pylith::SieveMesh>&
+pylith::topology::Mesh::sieveMesh(void) const {
+  return _mesh;
+}
+
+// Get Sieve mesh.
+inline
+ALE::Obj<pylith::SieveMesh>&
+pylith::topology::Mesh::sieveMesh(void) {
+  return _mesh;
+}
+
+// Get coordinate system.
+inline
+const spatialdata::geocoords::CoordSys*
+pylith::topology::Mesh::coordsys(void) const {
+  return _coordsys;
+}
+
+
+#endif
+
+
+// End of file

Modified: short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh	2008-12-03 20:38:21 UTC (rev 13455)
+++ short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh	2008-12-04 01:40:52 UTC (rev 13456)
@@ -23,11 +23,19 @@
 
 namespace pylith {
 
+#if NEWPYLITHMESH // For use with pylith::topology::Mesh
+  typedef ALE::IMesh<> SieveMesh;
+  typedef ALE::IMesh<ALE::LabelSifter<int, SieveMesh::point_type> > SieveSubMesh;
+  typedef ALE::Obj<SieveMesh::real_section_type> SieveRealGenSection;
+
+#else
   typedef ALE::IMesh<> Mesh;
   typedef ALE::IMesh<ALE::LabelSifter<int, Mesh::point_type> > SubMesh;
   typedef Mesh::sieve_type sieve_type;
   typedef Mesh::real_section_type real_section_type; 
   typedef Mesh::int_section_type int_section_type;
+#endif
+
 } // pylith
 
 #endif // pylith_utils_sievetypes_hh

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am	2008-12-03 20:38:21 UTC (rev 13455)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am	2008-12-04 01:40:52 UTC (rev 13456)
@@ -21,12 +21,16 @@
 
 # Primary source files
 testtopology_SOURCES = \
+	TestField.cc \
 	TestFieldsManager.cc \
+	TestMesh.cc \
 	TestMeshOps.cc \
 	test_topology.cc
 
 noinst_HEADERS = \
+	TestField.hh \
 	TestFieldsManager.hh \
+	TestMesh.hh \
 	TestMeshOps.hh
 
 # Source files associated with testing data

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,213 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestField.hh" // Implementation of class methods
+#include "pylith/topology/Field.hh" // USES Field
+
+#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/utils/array.hh" // USES double_array
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestField );
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::topology::TestField::testConstructor(void)
+{ // testConstructor
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test section().
+void
+pylith::topology::TestField::testSection(void)
+{ // testSection
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  const ALE::Obj<SieveMesh::real_section_type>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
+} // testSection
+
+// ----------------------------------------------------------------------
+// Test name().
+void 
+pylith::topology::TestField::testName(void)
+{ // testName
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  CPPUNIT_ASSERT_EQUAL(std::string("unknown"), std::string(field.name()));
+
+  const std::string name = "field A";
+  field.name(name.c_str());
+  CPPUNIT_ASSERT_EQUAL(name, std::string(field.name()));
+} // testName
+
+// ----------------------------------------------------------------------
+// Test vectorFieldType().
+void
+pylith::topology::TestField::testVectorFieldType(void)
+{ // testVectorFieldType
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  CPPUNIT_ASSERT_EQUAL(Field::OTHER, field.vectorFieldType());
+
+  const Field::VectorFieldEnum ftype = Field::TENSOR;
+  field.vectorFieldType(ftype);
+  CPPUNIT_ASSERT_EQUAL(ftype, field.vectorFieldType());
+} // testVectorFieldType
+
+// ----------------------------------------------------------------------
+// Test spaceDim().
+void
+pylith::topology::TestField::testSpaceDim(void)
+{ // testSpaceDim
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  CPPUNIT_ASSERT_EQUAL(0, field.spaceDim());
+
+  const int spaceDim = 2;
+  field.spaceDim(spaceDim);
+  CPPUNIT_ASSERT_EQUAL(spaceDim, field.spaceDim());
+} // testSpaceDim
+
+// ----------------------------------------------------------------------
+// Test scale().
+void
+pylith::topology::TestField::testScale(void)
+{ // testScale
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  CPPUNIT_ASSERT_EQUAL(1.0, field.scale());
+
+  const double scale = 4.0;
+  field.scale(scale);
+  CPPUNIT_ASSERT_EQUAL(scale, field.scale());
+} // testScale
+
+// ----------------------------------------------------------------------
+// Test addDimensionOkay().
+void
+pylith::topology::TestField::testAddDimensionOkay(void)
+{ // testAddDimensionOkay
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  CPPUNIT_ASSERT_EQUAL(false, field.addDimensionOkay());
+
+  field.addDimensionOkay(true);
+  CPPUNIT_ASSERT_EQUAL(true, field.addDimensionOkay());
+} // testAddDimensionOkay
+
+// ----------------------------------------------------------------------
+// Test dimensionalize().
+void
+pylith::topology::TestField::testDimensionalize(void)
+{ // testDimensionalize
+  Mesh mesh;
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  Field field(sieveMesh);
+
+  const int spaceDim = 2;
+  const int cellDim = 2;
+  const int nvertices = 4;
+  const int ncells = 1;
+  const int ncorners = 4;
+  const int cells[] = { 0, 1, 2, 3 };
+  const double coordinates[] = {
+    0.0, 0.0,
+    1.0, 0.0,
+    0.0, 1.0,
+    1.0, 1.0,
+  };
+
+  const int fiberDim = 3;
+  const double scale = 2.0;
+  const double valuesNondim[] = {
+    1.1, 2.2, 3.3,
+    1.2, 2.3, 3.4,
+    1.3, 2.4, 3.5,
+    1.4, 2.5, 3.6,
+  };
+
+
+  ALE::Obj<SieveMesh::sieve_type> sieve = 
+    new SieveMesh::sieve_type(sieveMesh->comm());
+  CPPUNIT_ASSERT(!sieve.isNull());
+
+  ALE::Obj<ALE::Mesh::sieve_type> s = 
+    new ALE::Mesh::sieve_type(sieve->comm(), sieve->debug());
+  
+  const bool interpolate = false;
+  ALE::SieveBuilder<ALE::Mesh>::buildTopology(s, cellDim, ncells, (int*) cells,
+					      nvertices, interpolate, 
+					      ncorners);
+  std::map<SieveMesh::point_type,SieveMesh::point_type> renumbering;
+  ALE::ISieveConverter::convertSieve(*s, *sieve, renumbering);
+  sieveMesh->setSieve(sieve);
+  sieveMesh->stratify();
+  ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim, 
+						 coordinates);
+
+  const SieveRealGenSection& section = field.section();
+  
+  const ALE::Obj<SieveMesh::label_sequence>& vertices = 
+    sieveMesh->depthStratum(0);
+  section->setChart(SieveMesh::real_section_type::chart_type(
+		  *std::min_element(vertices->begin(), vertices->end()),
+		  *std::max_element(vertices->begin(), vertices->end())+1));
+  section->setFiberDimension(vertices, fiberDim);
+  sieveMesh->allocate(section);
+
+  double_array values(fiberDim);
+
+  int i = 0;
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    section->restrictPoint(*v_iter, &values[0], values.size());
+    for (int iDim=0; iDim < fiberDim; ++iDim)
+      values[iDim] = valuesNondim[i++];
+    section->updatePoint(*v_iter, &values[0]);
+  } // for
+
+  field.scale(scale);
+  field.spaceDim(spaceDim);
+  field.addDimensionOkay(true);
+  field.dimensionalize();
+
+  i = 0;
+  const double tolerance = 1.0e-6;
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    section->restrictPoint(*v_iter, &values[0], values.size());
+    for (int iDim=0; iDim < fiberDim; ++iDim) {
+      const double valueE = valuesNondim[i++]*scale;
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(valueE, values[iDim], tolerance);
+    } // for
+  } // for
+
+} // testDimensionalize
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,86 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/topology/TestField.hh
+ *
+ * @brief C++ unit testing for Field.
+ */
+
+#if !defined(pylith_topology_testfield_hh)
+#define pylith_topology_testfield_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+// Forward declarations -------------------------------------------------
+/// Namespace for pylith package
+namespace pylith {
+  namespace topology {
+    class TestField;
+
+    class Field;
+  } // topology
+} // pylith
+
+// TestField -------------------------------------------------------------
+/// C++ unit testing for Field.
+class pylith::topology::TestField : public CppUnit::TestFixture
+{ // class TestField
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestField );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testSection );
+  CPPUNIT_TEST( testName );
+  CPPUNIT_TEST( testVectorFieldType );
+  CPPUNIT_TEST( testSpaceDim );
+  CPPUNIT_TEST( testScale );
+  CPPUNIT_TEST( testAddDimensionOkay );
+  CPPUNIT_TEST( testDimensionalize );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor.
+  void testConstructor(void);
+
+  /// Test section().
+  void testSection(void);
+
+  /// Test name().
+  void testName(void);
+
+  /// Test vectorFieldType().
+  void testVectorFieldType(void);
+
+  /// Test spaceDim().
+  void testSpaceDim(void);
+
+  /// Test scale().
+  void testScale(void);
+
+  /// Test addDimensionOkay().
+  void testAddDimensionOkay(void);
+
+  /// Test dimensionalize().
+  void testDimensionalize(void);
+
+}; // class TestField
+
+#endif // pylith_topology_testfield_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.cc	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,76 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestMesh.hh" // Implementation of class methods
+#include "pylith/topology/Mesh.hh" // USES Mesh
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestMesh );
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::topology::TestMesh::testConstructor(void)
+{ // testConstructor
+  Mesh mesh;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test sieveMesh().
+void
+pylith::topology::TestMesh::testSieveMesh(void)
+{ // testSieveMesh
+  const int dim = 2;
+
+  Mesh mesh(PETSC_COMM_WORLD, dim);
+  
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
+  CPPUNIT_ASSERT_EQUAL(dim, sieveMesh->getDimension());
+} // testSieveMesh
+
+// ----------------------------------------------------------------------
+// Test coordsys().
+void
+pylith::topology::TestMesh::testCoordsys(void)
+{ // testCoordsys
+  Mesh mesh;
+
+  spatialdata::geocoords::CSCart cs;
+  cs.setSpaceDim(2);
+
+  mesh.coordsys(&cs);
+
+  CPPUNIT_ASSERT_EQUAL(cs.spaceDim(), mesh.coordsys()->spaceDim());
+} // testCoordsys
+
+// ----------------------------------------------------------------------
+// Test initialize().
+void
+pylith::topology::TestMesh::testInitialize(void)
+{ // testInitialize
+  Mesh mesh;
+
+  spatialdata::geocoords::CSCart cs;
+  cs.setSpaceDim(2);
+
+  mesh.coordsys(&cs);
+  mesh.initialize();
+
+} // testInitialize
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestMesh.hh	2008-12-04 01:40:52 UTC (rev 13456)
@@ -0,0 +1,70 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/topology/TestMesh.hh
+ *
+ * @brief C++ unit testing for Mesh.
+ */
+
+#if !defined(pylith_topology_testmesh_hh)
+#define pylith_topology_testmesh_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+// Forward declarations -------------------------------------------------
+/// Namespace for pylith package
+namespace pylith {
+  namespace topology {
+    class TestMesh;
+
+    class Mesh;
+  } // topology
+} // pylith
+
+// TestMesh -------------------------------------------------------------
+/// C++ unit testing for Mesh.
+class pylith::topology::TestMesh : public CppUnit::TestFixture
+{ // class TestMesh
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestMesh );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testSieveMesh );
+  CPPUNIT_TEST( testCoordsys );
+  CPPUNIT_TEST( testInitialize );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor.
+  void testConstructor(void);
+
+  /// Test sieveMesh().
+  void testSieveMesh(void);
+
+  /// Test coordsys().
+  void testCoordsys(void);
+
+  /// Test initialize().
+  void testInitialize(void);
+
+}; // class TestMesh
+
+#endif // pylith_topology_testmesh_hh
+
+
+// End of file 



More information about the CIG-COMMITS mailing list