[cig-commits] r17134 - in short/3D/PyLith/trunk: . examples/twocells libsrc/meshio libsrc/topology unittests/libtests/meshio unittests/libtests/topology

brad at geodynamics.org brad at geodynamics.org
Fri Aug 27 09:52:31 PDT 2010


Author: brad
Date: 2010-08-27 09:52:31 -0700 (Fri, 27 Aug 2010)
New Revision: 17134

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/examples/twocells/Makefile.am
   short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc
   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/FieldBase.hh
   short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
   short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc
   short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKBCMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKFaultMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKSubMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldSubMesh.cc
Log:
More const fixes (mainly output unit tests). Added new Field constuctor to permit creating Field from section. More work on new Fields object.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/TODO	2010-08-27 16:52:31 UTC (rev 17134)
@@ -26,6 +26,7 @@
 * Reimplement Fields to use a single section.
 
     Fields -> SolutionFields
+    FieldsNew -> Fields
 
     FieldsNew<int fiberDim> [UniformSection]
       add(name, label, fiberDim)
@@ -38,7 +39,7 @@
       scale
       dimensionsOkay
 
-    Field(section, metadata)
+    Field(mesh, section, metadata)
        
 
 * Optimization

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/configure.ac	2010-08-27 16:52:31 UTC (rev 17134)
@@ -332,6 +332,7 @@
 		examples/greensfns/hex8/gfresponses/Makefile
 		examples/greensfns/hex8/gfspatialdb/Makefile
 		examples/twocells/twohex8/Makefile
+		examples/twocells/twohex27-cubit/Makefile
 		examples/twocells/twoquad4/Makefile
 		examples/twocells/twotet4/Makefile
 		examples/twocells/twotet4-geoproj/Makefile

Modified: short/3D/PyLith/trunk/examples/twocells/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/examples/twocells/Makefile.am	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/examples/twocells/Makefile.am	2010-08-27 16:52:31 UTC (rev 17134)
@@ -18,6 +18,7 @@
 
 SUBDIRS = \
 	twohex8 \
+	twohex27-cubit \
 	twoquad4 \
 	twotet4 \
 	twotet4-geoproj \

Modified: short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -85,16 +85,20 @@
     CHECK_PETSC_ERROR(err);
 
     const ALE::Obj<typename mesh_type::SieveMesh>& sieveMesh = mesh.sieveMesh();
-    const ALE::Obj<typename field_type::Mesh::RealSection>& coordinates = sieveMesh->getRealSection("coordinates");
-#if 0 // Waiting for Field(mesh, coordinates, metadata)
-    FieldBase::Metadata metadata;
-    field_type coordField(mesh, coordinates, metadata);
+    const ALE::Obj<typename mesh_type::RealSection>& coordinatesSection = 
+      sieveMesh->getRealSection("coordinates");
+    topology::FieldBase::Metadata metadata;
+    // :KLUDGE: We would like to use field_type for the coordinates
+    // field. However, the mesh coordinates are Field<mesh_type> and
+    // field_type can be Field<Mesh> (e.g., displacement field over a
+    // SubMesh).
+    topology::Field<mesh_type> coordinates(mesh, coordinatesSection, metadata);
 
-    coordField.createVector();
-    coordField.createScatter();
-    coordField.scatterSectionToVector();
-    err = VecView(coordField.vector(), _viewer);CHECK_PETSC_ERROR(err);
-#endif
+    coordinates.createVector();
+    coordinates.createScatter();
+    coordinates.scatterSectionToVector();
+    err = VecView(coordinates.vector(), _viewer);CHECK_PETSC_ERROR(err);
+
     Vec          elemVec;
     PetscInt     numElements, numCorners, *vertices;
     PetscScalar *tmpVertices;

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -34,18 +34,33 @@
 // Default constructor.
 template<typename mesh_type>
 pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh) :
-  _scale(1.0),
-  _label("unknown"),
   _mesh(mesh),
   _vector(0),
   _scatter(0),
-  _scatterVec(0),
-  _vecFieldType(OTHER),
-  _dimensionsOkay(false)
+  _scatterVec(0)
 { // constructor
+  _metadata.label = "unknown";
+  _metadata.vectorFieldType = OTHER;
+  _metadata.scale = 1.0;
+  _metadata.dimsOkay = false;
 } // constructor
 
 // ----------------------------------------------------------------------
+// Constructor with mesh, section, and metadata.
+template<typename mesh_type>
+pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh,
+					  const ALE::Obj<RealSection>& section,
+					  const Metadata& metadata) :
+  _metadata(metadata),
+  _mesh(mesh),
+  _section(section),
+  _vector(0),
+  _scatter(0),
+  _scatterVec(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
 // Destructor.
 template<typename mesh_type>
 pylith::topology::Field<mesh_type>::~Field(void)
@@ -111,9 +126,10 @@
 pylith::topology::Field<mesh_type>::newSection(void)
 { // newSection
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  //std::cout << "Making Field " << _label << " empty section" << std::endl;
   logger.stagePush("Field");
+
   _section = new RealSection(_mesh.comm(), _mesh.debug());  
+
   logger.stagePop();
 } // newSection
 
@@ -129,11 +145,10 @@
   typedef typename mesh_type::SieveMesh::point_type point_type;
 
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  //std::cout << "Making Field " << _label << " section type 1" << std::endl;
   logger.stagePush("Field");
   if (fiberDim < 0) {
     std::ostringstream msg;
-    msg << "Fiber dimension (" << fiberDim << ") for field '" << _label
+    msg << "Fiber dimension (" << fiberDim << ") for field '" << _metadata.label
 	<< "' must be nonnegative.";
     throw std::runtime_error(msg.str());
   } // if
@@ -164,11 +179,10 @@
   typedef typename mesh_type::SieveMesh::point_type point_type;
 
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  //std::cout << "Making Field " << _label << " section type 1b" << std::endl;
   logger.stagePush("Field");
   if (fiberDim < 0) {
     std::ostringstream msg;
-    msg << "Fiber dimension (" << fiberDim << ") for field '" << _label
+    msg << "Fiber dimension (" << fiberDim << ") for field '" << _metadata.label
 	<< "' must be nonnegative.";
     throw std::runtime_error(msg.str());
   } // if
@@ -221,8 +235,8 @@
 					       const int fiberDim)
 { // newSection
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  //std::cout << "Making Field " << _label << " section type 2" << std::endl;
   logger.stagePush("Field");
+
   if (_section.isNull()) {
     logger.stagePop();
     newSection();
@@ -230,7 +244,7 @@
   } // if
   if (fiberDim < 0) {
     std::ostringstream msg;
-    msg << "Fiber dimension (" << fiberDim << ") for field '" << _label
+    msg << "Fiber dimension (" << fiberDim << ") for field '" << _metadata.label
 	<< "' must be nonnegative.";
     throw std::runtime_error(msg.str());
   } // if
@@ -249,7 +263,6 @@
 	_section->setFiberDimension(*c_iter, fiberDim);
   } // if
 
-  //std::cout << "Done making Field " << _label << " section type 2" << std::endl;
   logger.stagePop();
 } // newSection
 
@@ -260,13 +273,12 @@
 pylith::topology::Field<mesh_type>::cloneSection(const Field& src)
 { // cloneSection
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  //std::cout << "Making Field " << _label << " section type 3" << std::endl;
   logger.stagePush("Field");
 
   deallocate();
-  _vecFieldType = src._vecFieldType;
-  _scale = src._scale;
-  _dimensionsOkay = false;
+  std::string label = _metadata.label;
+  _metadata = src._metadata;
+  _metadata.label = label;
 
   const ALE::Obj<RealSection>& srcSection = src.section();
   if (!srcSection.isNull() && _section.isNull()) {
@@ -311,9 +323,9 @@
   if (!_section.isNull())
     _section->clear();
 
-  _scale = 1.0;
-  _vecFieldType = OTHER;
-  _dimensionsOkay = false;
+  _metadata.scale = 1.0;
+  _metadata.vectorFieldType = OTHER;
+  _metadata.dimsOkay = false;
 
   logger.stagePop();
 } // clear
@@ -404,21 +416,22 @@
   const int srcSize = field.chartSize();
   const int dstSize = chartSize();
   if (field.spaceDim() != spaceDim() ||
-      field._vecFieldType != _vecFieldType ||
+      field._metadata.vectorFieldType != _metadata.vectorFieldType ||
       srcSize != dstSize) {
     std::ostringstream msg;
 
-    msg << "Cannot copy values from section '" << field._label 
-	<< "' to section '" << _label << "'. Sections are incompatible.\n"
+    msg << "Cannot copy values from section '" << field._metadata.label 
+	<< "' to section '" << _metadata.label
+	<< "'. Sections are incompatible.\n"
 	<< "  Source section:\n"
 	<< "    space dim: " << field.spaceDim() << "\n"
-	<< "    vector field type: " << field._vecFieldType << "\n"
-	<< "    scale: " << field._scale << "\n"
+	<< "    vector field type: " << field._metadata.vectorFieldType << "\n"
+	<< "    scale: " << field._metadata.scale << "\n"
 	<< "    size: " << srcSize << "\n"
 	<< "  Destination section:\n"
 	<< "    space dim: " << spaceDim() << "\n"
-	<< "    vector field type: " << _vecFieldType << "\n"
-	<< "    scale: " << _scale << "\n"
+	<< "    vector field type: " << _metadata.vectorFieldType << "\n"
+	<< "    scale: " << _metadata.scale << "\n"
 	<< "    size: " << dstSize;
     throw std::runtime_error(msg.str());
   } // if
@@ -440,8 +453,8 @@
     } // for
   } // if
 
-  _label = field._label;
-  _scale = field._scale;
+  _metadata.label = field._metadata.label;
+  _metadata.scale = field._metadata.scale;
 } // copy
 
 // ----------------------------------------------------------------------
@@ -457,13 +470,13 @@
     std::ostringstream msg;
 
     msg << "Cannot copy values from Sieve section "
-	<< _label << "'. Sections are incompatible.\n"
+	<< _metadata.label << "'. Sections are incompatible.\n"
 	<< "  Source section:\n"
 	<< "    size: " << srcSize << "\n"
 	<< "  Destination section:\n"
 	<< "    space dim: " << spaceDim() << "\n"
-	<< "    vector field type: " << _vecFieldType << "\n"
-	<< "    scale: " << _scale << "\n"
+	<< "    vector field type: " << _metadata.vectorFieldType << "\n"
+	<< "    scale: " << _metadata.scale << "\n"
 	<< "    size: " << dstSize;
     throw std::runtime_error(msg.str());
   } // if
@@ -495,22 +508,23 @@
   const int srcSize = field.chartSize();
   const int dstSize = chartSize();
   if (field.spaceDim() != spaceDim() ||
-      field._vecFieldType != _vecFieldType ||
-      field._scale != _scale ||
+      field._metadata.vectorFieldType != _metadata.vectorFieldType ||
+      field._metadata.scale != _metadata.scale ||
       srcSize != dstSize) {
     std::ostringstream msg;
 
-    msg << "Cannot add values from section '" << field._label 
-	<< "' to section '" << _label << "'. Sections are incompatible.\n"
+    msg << "Cannot add values from section '" << field._metadata.label 
+	<< "' to section '" << _metadata.label
+	<< "'. Sections are incompatible.\n"
 	<< "  Source section:\n"
 	<< "    space dim: " << field.spaceDim() << "\n"
-	<< "    vector field type: " << field._vecFieldType << "\n"
-	<< "    scale: " << field._scale << "\n"
+	<< "    vector field type: " << field._metadata.vectorFieldType << "\n"
+	<< "    scale: " << field._metadata.scale << "\n"
 	<< "    size: " << srcSize << "\n"
 	<< "  Destination section:\n"
 	<< "    space dim: " << spaceDim() << "\n"
-	<< "    vector field type: " << _vecFieldType << "\n"
-	<< "    scale: " << _scale << "\n"
+	<< "    vector field type: " << _metadata.vectorFieldType << "\n"
+	<< "    scale: " << _metadata.scale << "\n"
 	<< "    size: " << dstSize;
     throw std::runtime_error(msg.str());
   } // if
@@ -549,9 +563,10 @@
 void
 pylith::topology::Field<mesh_type>::dimensionalize(void) const
 { // dimensionalize
-  if (!_dimensionsOkay) {
+  if (!_metadata.dimsOkay) {
     std::ostringstream msg;
-    msg << "Cannot dimensionalize field '" << _label << "' because the flag "
+    msg << "Cannot dimensionalize field '" << _metadata.label
+	<< "' because the flag "
 	<< "has been set to keep field nondimensional.";
     throw std::runtime_error(msg.str());
   } // if
@@ -574,7 +589,7 @@
 	assert(fiberDim == _section->getFiberDimension(*c_iter));
       
 	_section->restrictPoint(*c_iter, &values[0], values.size());
-	normalizer.dimensionalize(&values[0], values.size(), _scale);
+	normalizer.dimensionalize(&values[0], values.size(), _metadata.scale);
 	_section->updatePointAll(*c_iter, &values[0]);
       } // if
   } // if
@@ -587,7 +602,7 @@
 pylith::topology::Field<mesh_type>::view(const char* label) const
 { // view
   std::string vecFieldString;
-  switch(_vecFieldType)
+  switch(_metadata.vectorFieldType)
     { // switch
     case SCALAR:
       vecFieldString = "scalar";
@@ -614,16 +629,16 @@
       vecFieldString = "multiple other values";
       break;
     default :
-      std::cerr << "Unknown vector field value '" << _vecFieldType
+      std::cerr << "Unknown vector field value '" << _metadata.vectorFieldType
 		<< "'." << std::endl;
       assert(0);
       throw std::logic_error("Bad vector field type in Field.");
     } // switch
 
-  std::cout << "Viewing field '" << _label << "' "<< label << ".\n"
+  std::cout << "Viewing field '" << _metadata.label << "' "<< label << ".\n"
 	    << "  vector field type: " << vecFieldString << "\n"
-	    << "  scale: " << _scale << "\n"
-	    << "  dimensionalize flag: " << _dimensionsOkay << std::endl;
+	    << "  scale: " << _metadata.scale << "\n"
+	    << "  dimensionalize flag: " << _metadata.dimsOkay << std::endl;
   if (!_section.isNull())
     _section->view(label);
 } // view

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.hh	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.hh	2010-08-27 16:52:31 UTC (rev 17134)
@@ -70,6 +70,14 @@
    */
   Field(const mesh_type& mesh);
 
+  /** Constructor with mesh, section, and metadata.
+   *
+   * @param mesh Finite-element mesh.
+   */
+  Field(const mesh_type& mesh,
+	const ALE::Obj<RealSection>& section,
+	const Metadata& metadata);
+
   /// Destructor.
   ~Field(void);
 
@@ -294,15 +302,12 @@
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 
-  double _scale; ///< Dimensional scale associated with field.
-  std::string _label; ///< Label for field.
+  Metadata _metadata;
   const mesh_type& _mesh; ///< Mesh associated with section.
   ALE::Obj<RealSection> _section; ///< Real section with data.
   PetscVec _vector; ///< PETSc vector associated with field.
   PetscVecScatter _scatter; ///< PETSc scatter associated with field.
   PetscVec _scatterVec; ///< PETSC vector used in scattering.
-  VectorFieldEnum _vecFieldType; ///< Type of vector field.
-  bool _dimensionsOkay; ///< Flag indicating it is okay to dimensionalize.
 
 
 // NOT IMPLEMENTED //////////////////////////////////////////////////////

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.icc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.icc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -42,7 +42,7 @@
 inline
 void
 pylith::topology::Field<mesh_type>::label(const char* value) {
-  _label = value;
+  _metadata.label = value;
 }
 
 // Get label for field.
@@ -50,7 +50,7 @@
 inline
 const char*
 pylith::topology::Field<mesh_type>::label(void) const {
-  return _label.c_str();
+  return _metadata.label.c_str();
 }
 
 // Set vector field type
@@ -58,7 +58,7 @@
 inline
 void
 pylith::topology::Field<mesh_type>::vectorFieldType(const VectorFieldEnum value) {
-  _vecFieldType = value;
+  _metadata.vectorFieldType = value;
 }
 
 // Get vector field type
@@ -66,7 +66,7 @@
 inline
 typename pylith::topology::Field<mesh_type>::VectorFieldEnum
 pylith::topology::Field<mesh_type>::vectorFieldType(void) const {
-  return _vecFieldType;
+  return _metadata.vectorFieldType;
 }
 
 // Set scale for dimensionalizing field.
@@ -74,7 +74,7 @@
 inline
 void
 pylith::topology::Field<mesh_type>::scale(const double value) {
-  _scale = value;
+  _metadata.scale = value;
 }
 
 // Get scale for dimensionalizing field.
@@ -82,7 +82,7 @@
 inline
 double
 pylith::topology::Field<mesh_type>::scale(void) const {
-  return _scale;
+  return _metadata.scale;
 }
 
 // Set flag indicating whether it is okay to dimensionalize field.
@@ -90,7 +90,7 @@
 inline
 void
 pylith::topology::Field<mesh_type>::addDimensionOkay(const bool value) {
-  _dimensionsOkay = value;
+  _metadata.dimsOkay = value;
 }
 
 // Set flag indicating whether it is okay to dimensionalize field.
@@ -98,7 +98,7 @@
 inline
 bool
 pylith::topology::Field<mesh_type>::addDimensionOkay(void) const {
-  return _dimensionsOkay;
+  return _metadata.dimsOkay;
 }
 
 // Get PETSc vector associated with field.

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldBase.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldBase.hh	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldBase.hh	2010-08-27 16:52:31 UTC (rev 17134)
@@ -29,6 +29,8 @@
 // Include directives ---------------------------------------------------
 #include "topologyfwd.hh" // forward declarations
 
+#include <string> // USES std::string
+
 // FieldBase ------------------------------------------------------------
 /** @brief Basic information related to a vector field over the
  * vertices or cells of a finite-element mesh.
@@ -55,6 +57,17 @@
     CELLS_FIELD=1, ///< FieldBase over cells.
   }; // DomainEnum
 
+// PUBLIC STRUCTS ///////////////////////////////////////////////////////
+public :
+
+  struct Metadata {
+    std::string label; // Label for field.
+    VectorFieldEnum vectorFieldType; ///< Type of vector field.
+    double scale; // Dimension scale associated with values.
+    bool dimsOkay; // Ok to replace nondimensionalized values 
+                   // with dimensionalized values.
+  }; // Metadata
+
 // PUBLIC MEMBERS ///////////////////////////////////////////////////////
 public :
 

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh	2010-08-27 16:52:31 UTC (rev 17134)
@@ -13,7 +13,7 @@
 /**
  * @file libsrc/topology/Fields.hh
  *
- * @brief Set of fields over a finite-element mesh. All fields are
+ * @brief Set of real fields over a finite-element mesh. All fields are
  * associated with the same points. We use uniform sections so the
  * fiber dimension is set at compile time.
  */
@@ -24,18 +24,18 @@
 // Include directives ---------------------------------------------------
 #include "topologyfwd.hh" // forward declarations
 
-#include "pylith/topology/FieldBase.hh" // USES FieldBase::DomainEnum
+#include "pylith/topology/FieldBase.hh" // USES FieldBase::Metadata
 
 #include <string> // USES std::string
 
 // Fields ---------------------------------------------------------------
 /// Container for managing multiple fields over a finite-element mesh.
-template<typename field_type,
+template<typename mesh_type,
 	 int fiberDimTotal>
 class pylith::topology::FieldsNew
 { // Fields
-  friend class TestFieldsMesh; // unit testing
-  friend class TestFieldsSubMesh; // unit testing
+  friend class TestFieldsNewMesh; // unit testing
+  friend class TestFieldsNewSubMesh; // unit testing
 
 // PUBLIC MEMBERS ///////////////////////////////////////////////////////
 public :
@@ -44,8 +44,7 @@
    *
    * @param mesh Finite-element mesh.
    */
-  Fields(const typename field_type::Mesh& mesh,
-	 const pylith::topology::FieldBase::DomainEnum domain);
+  Fields(const typename mesh_type& mesh);
 
   /// Destructor.
   virtual
@@ -65,79 +64,92 @@
   /** Add field.
    *
    * @param name Name of field.
-   * @param label Label for field (used in output).
-   */
-  void add(const char* name,
-	   const char* label);
-
-  /** Add field.
-   *
-   * @param name Name of field.
    * @param label Label for field.
    * @param fiberDim Fiber dimension for field.
    */
   void add(const char* name,
 	   const char* label,
-	   const int fiberDim);
+	   const int fiberDim,
+	   FieldBase::VectorFieldEnum vectorFieldType =FieldBase::OTHER,
+	   const double scale =1.0,
+	   const bool dimsOkay =false);
 
+  /** Create and allocate Sieve section.
+   *
+   * @param points Points over which to define section.
+   */
+  void allocate(const ALE::Obj<label_sequence>& points);
+
+  /** Create and allocate Sieve section.
+   *
+   * @param points Points over which to define section.
+   */
+  void allocate(const int_array& points,
+		const int fiberDim);
+
+  /** Create and allocate Sieve section.
+   *
+   * @param domain Type of points over which to define section.
+   * @param stratum Stratum depth (for vertices) and height (for cells).
+   */
+  void allocate(const DomainEnum domain,
+		const int stratum =0);
+
   /** Get field.
    *
    * @param name Name of field.
    */
-  const field_type& getField(const char* name) const;
+  const Field<mesh_type>& getField(const char* name) const;
 	   
   /** Get field.
    *
    * @param name Name of field.
    */
-  field_type& getField(const char* name);
+  Field<mesh_type>& getField(const char* name);
 	   
-  /** Copy layout to other fields.
-   *
-   * @param name Name of field to use as template for layout.
-   */
-  void copyLayout(const char* name);
-
   /** Get mesh associated with fields.
    *
    * @returns Finite-element mesh.
    */
-  const typename field_type::Mesh& mesh(void) const;
+  const typename mesh_type& mesh(void) const;
 
   /** Return the names of all fields.
    *
    * @returns an array of all field names
    */
   void fieldNames(int *numNames,
-		  char ***outNames);
+		  char ***names);
 
 // PROTECTED STRUCTS ////////////////////////////////////////////////////
 protected :
 
   struct FieldInfo {
+    FieldBase::Metadata metadata;
+    int fiberDim;
     int fibration; 
   }; // FieldInfo
 
 // PROTECTED TYPEDEFS ///////////////////////////////////////////////////
 protected :
 
-  typedef std::map< std::string, field_type* > map_type;
+  typedef std::map< std::string, FieldInfo > map_type;
 
 // PROTECTED MEMBERS ////////////////////////////////////////////////////
 protected :
 
-  map_type _fields;
-  const typename field_type::Mesh& _mesh;
+  map_type _fields; ///< Fields without constraints over a common set of points.
+  ALE::Obj<mesh_type::URealSection> _section; ///< Section containing fields.
+  const typename mesh_type& _mesh; ///< Mesh associated with fields.
 
 // NOT IMPLEMENTED //////////////////////////////////////////////////////
 private :
 
-  Fields(const Fields&); ///< Not implemented
-  const Fields& operator=(const Fields&); ///< Not implemented
+  FieldsNew(const FieldsNew&); ///< Not implemented
+  const FieldsNew& operator=(const FieldsNew&); ///< Not implemented
 
-}; // Fields
+}; // FieldsNew
 
-#include "Fields.icc"
+#include "FieldsNew.icc"
 
 #endif // pylith_topology_fields_hh
 

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -11,7 +11,7 @@
 //
 
 #if !defined(pylith_topology_fields_hh)
-#error "Fields.icc must be included only from Fields.hh"
+#error "FieldsNew.icc must be included only from FieldsNew.hh"
 #endif
 
 #include <sstream> // USES std::ostringstream
@@ -19,15 +19,16 @@
 
 // ----------------------------------------------------------------------
 // Default constructor.
-template<typename field_type>
-pylith::topology::Fields<field_type>::Fields(const typename field_type::Mesh& mesh) :
+template<typename mesh_type, int fiberDimTotal>
+pylith::topology::Fields<field_type>::Fields(
+				  const typename field_type::Mesh& mesh) :
   _mesh(mesh)
 { // constructor
 } // constructor
 
 // ----------------------------------------------------------------------
 // Destructor.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 pylith::topology::Fields<field_type>::~Fields(void)
 { // destructor
   deallocate();
@@ -35,20 +36,17 @@
 
 // ----------------------------------------------------------------------
 // Deallocate PETSc and local data structures.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 void
 pylith::topology::Fields<field_type>::deallocate(void)
 { // deallocate
-  const typename map_type::iterator begin = _fields.begin();
-  const typename map_type::iterator end = _fields.end();
-  for (typename map_type::iterator iter=begin; iter != end; ++iter) {
-    delete iter->second; iter->second = 0;
-  } // for
+  if (!_section.isNull())
+    _section->clear();
 } // deallocate
 
 // ----------------------------------------------------------------------
 // Check if fields contains a given field.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 bool
 pylith::topology::Fields<field_type>::hasField(const char* name) const
 { // hasField
@@ -58,10 +56,14 @@
 
 // ----------------------------------------------------------------------
 // Add field.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 void
 pylith::topology::Fields<field_type>::add(const char* name,
-					  const char* label)
+					  const char* label,
+					  const int fiberDim,
+					  const FieldBase::VectorFieldEnum vectorFieldType,
+					  const double scale,
+					  const bool dimsOkay)
 { // add
   if (hasField(name)) {
     std::ostringstream msg;
@@ -69,63 +71,37 @@
 	<< "' to fields manager, because it already exists.";
     throw std::runtime_error(msg.str());
   } // if
-  
-  _fields[name] = new field_type(_mesh);
-  _fields[name]->label(label);
-} // add
 
-// ----------------------------------------------------------------------
-// Add field.
-template<typename field_type>
-void 
-pylith::topology::Fields<field_type>::add(
-			const char* name,
-			const char* label,
-			const pylith::topology::FieldBase::DomainEnum domain,
-			const int fiberDim)
-{ // add
-  if (hasField(name)) {
+  // Check to see if we have room to add field.
+  int fiberDimCurrent = 0;
+  for (map_type::iterator iter=_fields.begin(); iter != _fields.end(); iter++)
+    fiberDimCurrent += iter->second.fiberDim;
+  if (fiberDimCurrent + fiberDim > fiberDimTotal) {
     std::ostringstream msg;
-    msg << "Could not add field '" << name
-	<< "' to fields manager, because it already exists.";
+    msg << "No room to add field '" << name << "' to Fields object.\n"
+	<< "  Total fiber dimension: " << fiberDimTotal << "\n"
+	<< "  Current fiber dimension: " << fiberDimCurrent << "\n"
+	<< "  Fiber dimension for new field: " << fiberDim;
     throw std::runtime_error(msg.str());
   } // if
+
+  // Set metadata
+  FieldInfo info;
+  info.metadata.label = label;
+  info.metadata.vectorFieldType = vectorFieldType;
+  info.metadata.scale = scale;
+  info.metadata.dimsOkay = dimsOkay;
   
-  _fields[name] = new field_type(_mesh);
-  _fields[name]->label(label);
-  _fields[name]->newSection(domain, fiberDim);
+  // Set fibration and fiber dimension
+  info.fibration = _fields.size() + 1;
+  info.fiberDim = fiberDim;
+
+  _fields[name] = info;
 } // add
 
 // ----------------------------------------------------------------------
-// Delete field.
-template<typename field_type>
-void
-pylith::topology::Fields<field_type>::del(const char* name)
-{ // del
-  typename map_type::iterator iter = _fields.find(name);
-  if (iter == _fields.end()) {
-    std::ostringstream msg;
-    msg << "Could not find field '" << name
-	<< "' in fields manager to delete.";
-    throw std::runtime_error(msg.str());
-  } // if
-  delete iter->second; iter->second = 0;
-  _fields.erase(name);
-} // del
-
-// ----------------------------------------------------------------------
-// Delete field.
-template<typename field_type>
-inline
-void
-pylith::topology::Fields<field_type>::delField(const char* name)
-{ // delField
-  del(name);
-} // delField
-
-// ----------------------------------------------------------------------
 // Get field.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 const field_type&
 pylith::topology::Fields<field_type>::get(const char* name) const
 { // get
@@ -141,7 +117,7 @@
 	   
 // ----------------------------------------------------------------------
 // Get field.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 field_type&
 pylith::topology::Fields<field_type>::get(const char* name)
 { // get
@@ -157,7 +133,7 @@
 
 // ----------------------------------------------------------------------
 // Copy layout to other fields.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 void
 pylith::topology::Fields<field_type>::copyLayout(const char* name)
 { // copyLayout
@@ -178,7 +154,7 @@
 
 // ----------------------------------------------------------------------
 // Get mesh associated with fields.
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 const typename field_type::Mesh&
 pylith::topology::Fields<field_type>::mesh(void) const
 { // mesh
@@ -187,7 +163,7 @@
 
 // ----------------------------------------------------------------------
 // Get names of all fields
-template<typename field_type>
+template<typename mesh_type, int fiberDimTotal>
 void
 pylith::topology::Fields<field_type>::fieldNames(int *numNames, char ***outNames)
 { // fieldNames

Modified: short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh	2010-08-27 16:52:31 UTC (rev 17134)
@@ -37,8 +37,7 @@
     class FieldBase;
     template<typename mesh_type> class Field;
     template<typename field_type> class Fields;
-    typedef Fields<Field<Mesh> > FieldsMesh;
-    typedef Fields<Field<SubMesh> > FieldsSubMesh;
+    template<typename field_type, int fiberDimTotal> class FieldsNew;
     class SolutionFields;
 
     class Jacobian;

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKBCMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKBCMesh.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKBCMesh.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -138,7 +138,7 @@
     writer.openTimeStep(t, *_submesh, label, id);
   } // else
   for (int i=0; i < nfields; ++i) {
-    const SubMeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
+    SubMeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
     writer.writeVertexField(t, field, *_submesh);
     CPPUNIT_ASSERT(writer._wroteVertexHeader);
     CPPUNIT_ASSERT(false == writer._wroteCellHeader);
@@ -175,7 +175,7 @@
     writer.open(*_submesh, numTimeSteps);
     writer.openTimeStep(t, *_submesh);
     for (int i=0; i < nfields; ++i) {
-      const SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);
@@ -186,7 +186,7 @@
     writer.open(*_submesh, numTimeSteps, label, id);
     writer.openTimeStep(t, *_submesh, label, id);
     for (int i=0; i < nfields; ++i) {
-      const SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field, label, id);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKFaultMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKFaultMesh.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKFaultMesh.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -141,7 +141,7 @@
     writer.openTimeStep(t, *_faultMesh, label, id);
   } // else
   for (int i=0; i < nfields; ++i) {
-    const MeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
+    MeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
     writer.writeVertexField(t, field, *_faultMesh);
     CPPUNIT_ASSERT(writer._wroteVertexHeader);
     CPPUNIT_ASSERT(false == writer._wroteCellHeader);
@@ -178,7 +178,7 @@
     writer.open(*_faultMesh, numTimeSteps);
     writer.openTimeStep(t, *_faultMesh);
     for (int i=0; i < nfields; ++i) {
-      const MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);
@@ -189,7 +189,7 @@
     writer.open(*_faultMesh, numTimeSteps, label, id);
     writer.openTimeStep(t, *_faultMesh, label, id);
     for (int i=0; i < nfields; ++i) {
-      const MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field, label, id);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKMesh.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKMesh.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -184,7 +184,7 @@
     writer.openTimeStep(t, *_mesh, label, id);
   } // else
   for (int i=0; i < nfields; ++i) {
-    const MeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
+    MeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
     writer.writeVertexField(t, field, *_mesh);
     CPPUNIT_ASSERT(writer._wroteVertexHeader);
     CPPUNIT_ASSERT(false == writer._wroteCellHeader);
@@ -221,7 +221,7 @@
     writer.open(*_mesh, numTimeSteps);
     writer.openTimeStep(t, *_mesh);
     for (int i=0; i < nfields; ++i) {
-      const MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);
@@ -232,7 +232,7 @@
     writer.open(*_mesh, numTimeSteps, label, id);
     writer.openTimeStep(t, *_mesh, label, id);
     for (int i=0; i < nfields; ++i) {
-      const MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      MeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field, label, id);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKSubMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKSubMesh.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTKSubMesh.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -139,7 +139,7 @@
     writer.openTimeStep(t, *_submesh, label, id);
   } // else
   for (int i=0; i < nfields; ++i) {
-    const MeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
+    MeshField& field = vertexFields.get(_data->vertexFieldsInfo[i].name);
     writer.writeVertexField(t, field, *_submesh);
     CPPUNIT_ASSERT(writer._wroteVertexHeader);
     CPPUNIT_ASSERT(false == writer._wroteCellHeader);
@@ -176,7 +176,7 @@
     writer.open(*_submesh, numTimeSteps);
     writer.openTimeStep(t, *_submesh);
     for (int i=0; i < nfields; ++i) {
-      const SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);
@@ -187,7 +187,7 @@
     writer.open(*_submesh, numTimeSteps, label, id);
     writer.openTimeStep(t, *_submesh, label, id);
     for (int i=0; i < nfields; ++i) {
-      const SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
+      SubMeshField& field = cellFields.get(_data->cellFieldsInfo[i].name);
       writer.writeCellField(t, field, label, id);
       CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
       CPPUNIT_ASSERT(writer._wroteCellHeader);

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -357,9 +357,9 @@
   
   field.clear();
 
-  CPPUNIT_ASSERT_EQUAL(1.0, field._scale);
-  CPPUNIT_ASSERT_EQUAL(Field<Mesh>::OTHER, field._vecFieldType);
-  CPPUNIT_ASSERT_EQUAL(false, field._dimensionsOkay);
+  CPPUNIT_ASSERT_EQUAL(1.0, field._metadata.scale);
+  CPPUNIT_ASSERT_EQUAL(Field<Mesh>::OTHER, field._metadata.vectorFieldType);
+  CPPUNIT_ASSERT_EQUAL(false, field._metadata.dimsOkay);
 } // testClear
 
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldSubMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldSubMesh.cc	2010-08-27 06:56:11 UTC (rev 17133)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldSubMesh.cc	2010-08-27 16:52:31 UTC (rev 17134)
@@ -296,9 +296,9 @@
   
   field.clear();
 
-  CPPUNIT_ASSERT_EQUAL(1.0, field._scale);
-  CPPUNIT_ASSERT_EQUAL(Field<SubMesh>::OTHER, field._vecFieldType);
-  CPPUNIT_ASSERT_EQUAL(false, field._dimensionsOkay);
+  CPPUNIT_ASSERT_EQUAL(1.0, field._metadata.scale);
+  CPPUNIT_ASSERT_EQUAL(Field<SubMesh>::OTHER, field._metadata.vectorFieldType);
+  CPPUNIT_ASSERT_EQUAL(false, field._metadata.dimsOkay);
 } // testClear
 
 // ----------------------------------------------------------------------



More information about the CIG-COMMITS mailing list