[cig-commits] r17161 - in short/3D/PyLith/trunk: libsrc/topology unittests/libtests/topology
brad at geodynamics.org
brad at geodynamics.org
Wed Sep 1 17:38:39 PDT 2010
Author: brad
Date: 2010-09-01 17:38:38 -0700 (Wed, 01 Sep 2010)
New Revision: 17161
Added:
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh
Modified:
short/3D/PyLith/trunk/libsrc/topology/Field.cc
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc
short/3D/PyLith/trunk/libsrc/topology/Makefile.am
short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh
short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
Log:
Finished preliminary implementation of new Fields object (FieldsNew). Added corresponding unit tests.
Modified: short/3D/PyLith/trunk/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.cc 2010-09-01 03:26:33 UTC (rev 17160)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.cc 2010-09-02 00:38:38 UTC (rev 17161)
@@ -58,6 +58,7 @@
_scatter(0),
_scatterVec(0)
{ // constructor
+ assert(!section.isNull());
} // constructor
// ----------------------------------------------------------------------
Added: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc 2010-09-02 00:38:38 UTC (rev 17161)
@@ -0,0 +1,308 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::runtime_error
+
+// ----------------------------------------------------------------------
+// Default constructor.
+template<typename mesh_type>
+pylith::topology::FieldsNew<mesh_type>::FieldsNew(const mesh_type& mesh) :
+ _mesh(mesh)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor.
+template<typename mesh_type>
+pylith::topology::FieldsNew<mesh_type>::~FieldsNew(void)
+{ // destructor
+ deallocate();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Deallocate PETSc and local data structures.
+template<typename mesh_type>
+void
+pylith::topology::FieldsNew<mesh_type>::deallocate(void)
+{ // deallocate
+ if (!_section.isNull())
+ _section->clear();
+
+ const typename map_type::const_iterator fieldsEnd = _fields.end();
+ for (typename map_type::iterator f_iter = _fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter) {
+ delete f_iter->second.field; f_iter->second.field = 0;
+ } // for
+} // deallocate
+
+// ----------------------------------------------------------------------
+// Add field.
+template<typename mesh_type>
+void
+pylith::topology::FieldsNew<mesh_type>::add(const char* name,
+ const char* label,
+ const int fiberDim,
+ const FieldBase::VectorFieldEnum vectorFieldType,
+ const double scale,
+ const bool dimsOkay)
+{ // add
+ if (hasField(name)) {
+ std::ostringstream msg;
+ msg << "Could not add field '" << name
+ << "' to fields manager, because it already exists.";
+ 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;
+
+ // Set fibration and fiber dimension
+ info.fibration = _fields.size();
+ info.fiberDim = fiberDim;
+
+ info.field = 0;
+
+ _fields[name] = info;
+} // add
+
+// ----------------------------------------------------------------------
+// Create and allocate Sieve section.
+template<typename mesh_type>
+void
+pylith::topology::FieldsNew<mesh_type>::allocate(const ALE::Obj<typename mesh_type::SieveMesh::label_sequence>& points)
+{ // allocate
+ typedef typename mesh_type::SieveMesh::point_type point_type;
+ typedef typename mesh_type::RealSection RealSection;
+
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ logger.stagePush("Fields");
+
+ // Set fiber dimension
+ const int fiberDim = _fiberDim();
+ assert(fiberDim > 0);
+ _section = new RealSection(_mesh.comm(), _mesh.debug());
+ assert(!_section.isNull());
+
+ // Set spaces
+ const typename map_type::const_iterator fieldsEnd = _fields.end();
+ for (typename map_type::iterator f_iter=_fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter)
+ _section->addSpace();
+
+ if (points->size() > 0) {
+ const point_type pointMin =
+ *std::min_element(points->begin(), points->end());
+ const point_type pointMax =
+ *std::max_element(points->begin(), points->end());
+ _section->setChart(typename RealSection::chart_type(pointMin, pointMax+1));
+ _section->setFiberDimension(points, fiberDim);
+
+ int fibration = 0;
+ for (typename map_type::iterator f_iter=_fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter, ++fibration)
+ _section->setFiberDimension(points, f_iter->second.fiberDim, fibration);
+ } else // Create empty chart
+ _section->setChart(typename RealSection::chart_type(0, 0));
+
+ // Allocate section
+ const ALE::Obj<typename mesh_type::SieveMesh>& sieveMesh = _mesh.sieveMesh();
+ assert(!sieveMesh.isNull());
+ sieveMesh->allocate(_section);
+
+ logger.stagePop();
+} // allocate
+
+// ----------------------------------------------------------------------
+// Create and allocate Sieve section.
+template<typename mesh_type>
+void
+pylith::topology::FieldsNew<mesh_type>::allocate(const int_array& points)
+{ // allocate
+ typedef typename mesh_type::SieveMesh::point_type point_type;
+ typedef typename mesh_type::RealSection RealSection;
+
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ logger.stagePush("Field");
+
+ // Set fiber dimension
+ const int fiberDim = _fiberDim();
+ assert(fiberDim > 0);
+ _section = new RealSection(_mesh.comm(), _mesh.debug());
+ assert(!_section.isNull());
+
+ // Set spaces
+ const typename map_type::const_iterator fieldsEnd = _fields.end();
+ for (typename map_type::iterator f_iter=_fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter)
+ _section->addSpace();
+
+ const int npts = points.size();
+ if (npts > 0) {
+ const point_type pointMin = points.min();
+ const point_type pointMax = points.max();
+ _section->setChart(typename RealSection::chart_type(pointMin, pointMax+1));
+ for (int i=0; i < npts; ++i)
+ _section->setFiberDimension(points[i], fiberDim);
+
+ int fibration = 0;
+ for (typename map_type::iterator f_iter=_fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter, ++fibration)
+ for (int i=0; i < npts; ++i)
+ _section->setFiberDimension(points[i],
+ f_iter->second.fiberDim, fibration);
+ } else // create empty chart
+ _section->setChart(typename RealSection::chart_type(0, 0));
+
+ // Allocate section
+ const ALE::Obj<typename mesh_type::SieveMesh>& sieveMesh = _mesh.sieveMesh();
+ assert(!sieveMesh.isNull());
+ sieveMesh->allocate(_section);
+
+ logger.stagePop();
+} // allocate
+
+// ----------------------------------------------------------------------
+// Create and allocate Sieve section.
+template<typename mesh_type>
+void
+pylith::topology::FieldsNew<mesh_type>::allocate(const FieldBase::DomainEnum domain,
+ const int stratum)
+{ // allocate
+ const ALE::Obj<typename mesh_type::SieveMesh>& sieveMesh = _mesh.sieveMesh();
+ assert(!sieveMesh.isNull());
+
+ ALE::Obj<typename mesh_type::SieveMesh::label_sequence> points;
+ if (FieldBase::VERTICES_FIELD == domain)
+ points = sieveMesh->depthStratum(stratum);
+ else if (FieldBase::CELLS_FIELD == domain)
+ points = sieveMesh->heightStratum(stratum);
+ else {
+ std::cerr << "Unknown value for DomainEnum: " << domain << std::endl;
+ assert(0);
+ throw std::logic_error("Bad domain enum in Field.");
+ } // else
+
+ allocate(points);
+} // allocate
+
+// ----------------------------------------------------------------------
+// Get field.
+template<typename mesh_type>
+const pylith::topology::Field<mesh_type>&
+pylith::topology::FieldsNew<mesh_type>::get(const char* name) const
+{ // get
+ typename map_type::const_iterator f_iter = _fields.find(name);
+ if (f_iter == _fields.end()) {
+ std::ostringstream msg;
+ msg << "Could not find field '" << name
+ << "' in fields manager for retrieval.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ const int fibration = f_iter->second.fibration;
+ assert(fibration >= 0 && fibration < _fields.size());
+
+ if (0 == f_iter->second.field) {
+ assert(!_section.isNull());
+ assert(!_section->getFibration(fibration).isNull());
+ f_iter->second.field =
+ new Field<mesh_type>(_mesh, _section->getFibration(fibration),
+ f_iter->second.metadata);
+ assert(0 != f_iter->second.field);
+ } // if
+
+ return *f_iter->second.field;
+} // get
+
+// ----------------------------------------------------------------------
+// Get field.
+template<typename mesh_type>
+pylith::topology::Field<mesh_type>&
+pylith::topology::FieldsNew<mesh_type>::get(const char* name)
+{ // get
+ typename map_type::iterator f_iter = _fields.find(name);
+ if (f_iter == _fields.end()) {
+ std::ostringstream msg;
+ msg << "Could not find field '" << name
+ << "' in fields manager for retrieval.";
+ throw std::runtime_error(msg.str());
+ } // if
+ const int fibration = f_iter->second.fibration;
+ assert(fibration >= 0 && fibration < _fields.size());
+
+ if (0 == f_iter->second.field) {
+ assert(!_section.isNull());
+ assert(!_section->getFibration(fibration).isNull());
+ f_iter->second.field =
+ new Field<mesh_type>(_mesh, _section->getFibration(fibration),
+ f_iter->second.metadata);
+ assert(0 != f_iter->second.field);
+ } // if
+
+ return *f_iter->second.field;
+} // get
+
+// ----------------------------------------------------------------------
+// Get names of all fields
+template<typename mesh_type>
+void
+pylith::topology::FieldsNew<mesh_type>::fieldNames(int *numNames,
+ std::string** names) const
+{ // fieldNames
+ const int size = _fields.size();
+ *numNames = size;
+ *names = new std::string[size];
+
+ int i = 0;
+ const typename map_type::const_iterator fieldsEnd = _fields.end();
+ for (typename map_type::const_iterator f_iter = _fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter)
+ (*names)[i++] = f_iter->first;
+} // fieldNames
+
+// ----------------------------------------------------------------------
+// Compute total fiber dimension for section.
+template<typename mesh_type>
+int
+pylith::topology::FieldsNew<mesh_type>::_fiberDim(void) const
+{ // _fiberDim
+ int fiberDim = 0;
+ const typename map_type::const_iterator fieldsEnd = _fields.end();
+ for (typename map_type::const_iterator f_iter=_fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter)
+ fiberDim += f_iter->second.fiberDim;
+
+ if (fiberDim < 0) {
+ std::ostringstream msg;
+ msg << "Fiber dimension (" << fiberDim << ") for Fields object must "
+ << "be nonnegative.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+
+ return fiberDim;
+} // _fiberDim
+
+
+// End of file
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh 2010-09-01 03:26:33 UTC (rev 17160)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh 2010-09-02 00:38:38 UTC (rev 17161)
@@ -30,8 +30,7 @@
// Fields ---------------------------------------------------------------
/// Container for managing multiple fields over a finite-element mesh.
-template<typename mesh_type,
- int fiberDimTotal>
+template<typename mesh_type>
class pylith::topology::FieldsNew
{ // Fields
friend class TestFieldsNewMesh; // unit testing
@@ -44,11 +43,11 @@
*
* @param mesh Finite-element mesh.
*/
- Fields(const typename mesh_type& mesh);
+ FieldsNew(const mesh_type& mesh);
/// Destructor.
virtual
- ~Fields(void);
+ ~FieldsNew(void);
/// Deallocate PETSc and local data structures.
virtual
@@ -78,47 +77,47 @@
*
* @param points Points over which to define section.
*/
- void allocate(const ALE::Obj<label_sequence>& points);
+ void allocate(const ALE::Obj<typename mesh_type::SieveMesh::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);
+ void allocate(const int_array& points);
/** 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,
+ void allocate(const FieldBase::DomainEnum domain,
const int stratum =0);
/** Get field.
*
* @param name Name of field.
*/
- const Field<mesh_type>& getField(const char* name) const;
+ const Field<mesh_type>& get(const char* name) const;
/** Get field.
*
* @param name Name of field.
*/
- Field<mesh_type>& getField(const char* name);
+ Field<mesh_type>& get(const char* name);
/** Get mesh associated with fields.
*
* @returns Finite-element mesh.
*/
- const typename mesh_type& mesh(void) const;
+ const mesh_type& mesh(void) const;
/** Return the names of all fields.
*
- * @returns an array of all field names
+ * @param numNames Number of fields,
+ * @param names Names of fields.
*/
- void fieldNames(int *numNames,
- char ***names);
+ void fieldNames(int* numNames,
+ std::string** names) const;
// PROTECTED STRUCTS ////////////////////////////////////////////////////
protected :
@@ -127,6 +126,7 @@
FieldBase::Metadata metadata;
int fiberDim;
int fibration;
+ Field<mesh_type>* field;
}; // FieldInfo
// PROTECTED TYPEDEFS ///////////////////////////////////////////////////
@@ -134,12 +134,21 @@
typedef std::map< std::string, FieldInfo > map_type;
+// PROTECTED METHODS ////////////////////////////////////////////////////
+protected :
+
+ /** Compute total fiber dimension for section.
+ *
+ * @returns Fiber dimension.
+ */
+ int _fiberDim(void) const;
+
// PROTECTED MEMBERS ////////////////////////////////////////////////////
protected :
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.
+ ALE::Obj<typename mesh_type::RealSection> _section; ///< Section containing fields.
+ const mesh_type& _mesh; ///< Mesh associated with fields.
// NOT IMPLEMENTED //////////////////////////////////////////////////////
private :
@@ -150,6 +159,7 @@
}; // FieldsNew
#include "FieldsNew.icc"
+#include "FieldsNew.cc"
#endif // pylith_topology_fields_hh
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc 2010-09-01 03:26:33 UTC (rev 17160)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc 2010-09-02 00:38:38 UTC (rev 17161)
@@ -14,170 +14,24 @@
#error "FieldsNew.icc must be included only from FieldsNew.hh"
#endif
-#include <sstream> // USES std::ostringstream
-#include <stdexcept> // USES std::runtime_error
-
// ----------------------------------------------------------------------
-// Default constructor.
-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 mesh_type, int fiberDimTotal>
-pylith::topology::Fields<field_type>::~Fields(void)
-{ // destructor
- deallocate();
-} // destructor
-
-// ----------------------------------------------------------------------
-// Deallocate PETSc and local data structures.
-template<typename mesh_type, int fiberDimTotal>
-void
-pylith::topology::Fields<field_type>::deallocate(void)
-{ // deallocate
- if (!_section.isNull())
- _section->clear();
-} // deallocate
-
-// ----------------------------------------------------------------------
// Check if fields contains a given field.
-template<typename mesh_type, int fiberDimTotal>
+template<typename mesh_type>
bool
-pylith::topology::Fields<field_type>::hasField(const char* name) const
+pylith::topology::FieldsNew<mesh_type>::hasField(const char* name) const
{ // hasField
typename map_type::const_iterator iter = _fields.find(name);
return iter != _fields.end();
} // hasField
// ----------------------------------------------------------------------
-// Add field.
-template<typename mesh_type, int fiberDimTotal>
-void
-pylith::topology::Fields<field_type>::add(const char* name,
- const char* label,
- const int fiberDim,
- const FieldBase::VectorFieldEnum vectorFieldType,
- const double scale,
- const bool dimsOkay)
-{ // add
- if (hasField(name)) {
- std::ostringstream msg;
- msg << "Could not add field '" << name
- << "' to fields manager, because it already exists.";
- throw std::runtime_error(msg.str());
- } // if
-
- // 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 << "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;
-
- // Set fibration and fiber dimension
- info.fibration = _fields.size() + 1;
- info.fiberDim = fiberDim;
-
- _fields[name] = info;
-} // add
-
-// ----------------------------------------------------------------------
-// Get field.
-template<typename mesh_type, int fiberDimTotal>
-const field_type&
-pylith::topology::Fields<field_type>::get(const char* name) const
-{ // get
- typename map_type::const_iterator iter = _fields.find(name);
- if (iter == _fields.end()) {
- std::ostringstream msg;
- msg << "Could not find field '" << name
- << "' in fields manager for retrieval.";
- throw std::runtime_error(msg.str());
- } // if
- return *iter->second;
-} // get
-
-// ----------------------------------------------------------------------
-// Get field.
-template<typename mesh_type, int fiberDimTotal>
-field_type&
-pylith::topology::Fields<field_type>::get(const char* name)
-{ // get
- typename map_type::iterator iter = _fields.find(name);
- if (iter == _fields.end()) {
- std::ostringstream msg;
- msg << "Could not find field '" << name
- << "' in fields manager for retrieval.";
- throw std::runtime_error(msg.str());
- } // if
- return *iter->second;
-} // get
-
-// ----------------------------------------------------------------------
-// Copy layout to other fields.
-template<typename mesh_type, int fiberDimTotal>
-void
-pylith::topology::Fields<field_type>::copyLayout(const char* name)
-{ // copyLayout
- typename map_type::const_iterator src = _fields.find(name);
- if (src == _fields.end()) {
- std::ostringstream msg;
- msg << "Could not find field '" << name
- << "' in fields manager for retrieval.";
- throw std::runtime_error(msg.str());
- } // if
-
- 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)
- if (iter != src)
- iter->second->cloneSection(*src->second);
-} // copyLayout
-
-// ----------------------------------------------------------------------
// Get mesh associated with fields.
-template<typename mesh_type, int fiberDimTotal>
-const typename field_type::Mesh&
-pylith::topology::Fields<field_type>::mesh(void) const
+template<typename mesh_type>
+const mesh_type&
+pylith::topology::FieldsNew<mesh_type>::mesh(void) const
{ // mesh
return _mesh;
} // mesh
-// ----------------------------------------------------------------------
-// Get names of all fields
-template<typename mesh_type, int fiberDimTotal>
-void
-pylith::topology::Fields<field_type>::fieldNames(int *numNames, char ***outNames)
-{ // fieldNames
- *numNames = _fields.size();
- PetscErrorCode ierr = PetscMalloc((*numNames) * sizeof(char *), outNames);
- const typename map_type::const_iterator namesEnd = _fields.end();
- int i = 0;
- for (typename map_type::const_iterator name = _fields.begin(); name != namesEnd; ++name) {
- char *newName;
- ierr = PetscStrallocpy(name->first.c_str(), &newName);
- (*outNames)[i++] = newName;
- }
-} // fieldNames
-
-
// End of file
Modified: short/3D/PyLith/trunk/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Makefile.am 2010-09-01 03:26:33 UTC (rev 17160)
+++ short/3D/PyLith/trunk/libsrc/topology/Makefile.am 2010-09-02 00:38:38 UTC (rev 17161)
@@ -27,6 +27,9 @@
Field.cc \
Fields.hh \
Fields.icc \
+ FieldsNew.hh \
+ FieldsNew.icc \
+ FieldsNew.cc \
Jacobian.hh \
Mesh.hh \
Mesh.icc \
Modified: short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh 2010-09-01 03:26:33 UTC (rev 17160)
+++ short/3D/PyLith/trunk/libsrc/topology/topologyfwd.hh 2010-09-02 00:38:38 UTC (rev 17161)
@@ -37,7 +37,7 @@
class FieldBase;
template<typename mesh_type> class Field;
template<typename field_type> class Fields;
- template<typename field_type, int fiberDimTotal> class FieldsNew;
+ template<typename mesh_type> class FieldsNew;
class SolutionFields;
class Jacobian;
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am 2010-09-01 03:26:33 UTC (rev 17160)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am 2010-09-02 00:38:38 UTC (rev 17161)
@@ -34,6 +34,7 @@
TestFieldSubMesh.cc \
TestFieldsMesh.cc \
TestFieldsSubMesh.cc \
+ TestFieldsNewMesh.cc \
TestSolutionFields.cc \
TestJacobian.cc \
test_topology.cc
@@ -47,6 +48,7 @@
TestFieldSubMesh.hh \
TestFieldsMesh.hh \
TestFieldsSubMesh.hh \
+ TestFieldsNewMesh.hh \
TestSolutionFields.hh \
TestJacobian.hh
Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc 2010-09-02 00:38:38 UTC (rev 17161)
@@ -0,0 +1,229 @@
+// -*- 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 "TestFieldsNewMesh.hh" // Implementation of class methods
+
+#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/Field.hh" // USES Field
+#include "pylith/topology/FieldsNew.hh" // USES FieldsNew
+
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestFieldsNewMesh );
+
+// ----------------------------------------------------------------------
+typedef pylith::topology::FieldsNew<pylith::topology::Mesh> FieldsNewMesh;
+typedef pylith::topology::Mesh::RealSection RealSection;
+typedef pylith::topology::Mesh::SieveMesh SieveMesh;
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldsNewMesh::setUp(void)
+{ // setUp
+ _mesh = new Mesh;
+ meshio::MeshIOAscii importer;
+ importer.filename("data/tri3.mesh");
+ importer.read(_mesh);
+} // setUp
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldsNewMesh::tearDown(void)
+{ // tearDown
+ delete _mesh; _mesh = 0;
+} // tearDown
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::topology::TestFieldsNewMesh::testConstructor(void)
+{ // testConstructor
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test hasField().
+void
+pylith::topology::TestFieldsNewMesh::testHasField(void)
+{ // testHasField
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+
+ CPPUNIT_ASSERT_EQUAL(true, fields.hasField("field A"));
+ CPPUNIT_ASSERT_EQUAL(false, fields.hasField("field B"));
+ CPPUNIT_ASSERT_EQUAL(false, fields.hasField("field C"));
+
+ fields.add("field B", "displacement", 3, FieldBase::VECTOR);
+
+ CPPUNIT_ASSERT_EQUAL(true, fields.hasField("field A"));
+ CPPUNIT_ASSERT_EQUAL(true, fields.hasField("field B"));
+ CPPUNIT_ASSERT_EQUAL(false, fields.hasField("field C"));
+
+} // testHasField
+
+// ----------------------------------------------------------------------
+// Test add().
+void
+pylith::topology::TestFieldsNewMesh::testAdd(void)
+{ // testAdd
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "displacement", 4, FieldBase::OTHER, 2.0, true);
+
+ const size_t size = 2;
+ CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+} // testAdd
+
+#if 0
+// ----------------------------------------------------------------------
+// Test add(domain).
+void
+pylith::topology::TestFieldsNewMesh::testAddDomain(void)
+{ // testAddDomain
+ const int fiberDim = 3;
+
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ const char* label = "field";
+ fields.add(label, "velocity", Field<Mesh>::VERTICES_FIELD, fiberDim);
+ const size_t size = 1;
+ CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+
+ Field<Mesh>& field = fields.get(label);
+ const ALE::Obj<RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
+ const ALE::Obj<SieveMesh>& sieveMesh = _mesh->sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
+ const ALE::Obj<SieveMesh::label_sequence>& vertices =
+ sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
+ field.allocate();
+ for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter)
+ CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+} // testAddDomain
+#endif
+
+// ----------------------------------------------------------------------
+// Test get().
+void
+pylith::topology::TestFieldsNewMesh::testGet(void)
+{ // testGet
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "displacement", 4, FieldBase::OTHER, 2.0, true);
+ fields.allocate(FieldBase::VERTICES_FIELD);
+
+ const Field<Mesh>& fieldA = fields.get("field A");
+ CPPUNIT_ASSERT_EQUAL(std::string("velocity"), std::string(fieldA.label()));
+ CPPUNIT_ASSERT_EQUAL(FieldBase::VECTOR,
+ fieldA.vectorFieldType());
+ CPPUNIT_ASSERT_EQUAL(1.0, fieldA.scale());
+ CPPUNIT_ASSERT_EQUAL(false, fieldA.addDimensionOkay());
+
+ const Field<Mesh>& fieldB = fields.get("field B");
+ CPPUNIT_ASSERT_EQUAL(std::string("displacement"),
+ std::string(fieldB.label()));
+ CPPUNIT_ASSERT_EQUAL(FieldBase::OTHER,
+ fieldB.vectorFieldType());
+ CPPUNIT_ASSERT_EQUAL(2.0, fieldB.scale());
+ CPPUNIT_ASSERT_EQUAL(true, fieldB.addDimensionOkay());
+} // testGet
+
+// ----------------------------------------------------------------------
+// Test get() const.
+void
+pylith::topology::TestFieldsNewMesh::testGetConst(void)
+{ // testGetConst
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "displacement", 4, FieldBase::OTHER, 2.0, true);
+ fields.allocate(FieldBase::VERTICES_FIELD);
+
+ const Field<Mesh>& fieldA = fields.get("field A");
+ CPPUNIT_ASSERT_EQUAL(std::string("velocity"), std::string(fieldA.label()));
+ CPPUNIT_ASSERT_EQUAL(FieldBase::VECTOR,
+ fieldA.vectorFieldType());
+ CPPUNIT_ASSERT_EQUAL(1.0, fieldA.scale());
+ CPPUNIT_ASSERT_EQUAL(false, fieldA.addDimensionOkay());
+
+ const Field<Mesh>& fieldB = fields.get("field B");
+ CPPUNIT_ASSERT_EQUAL(std::string("displacement"),
+ std::string(fieldB.label()));
+ CPPUNIT_ASSERT_EQUAL(FieldBase::OTHER,
+ fieldB.vectorFieldType());
+ CPPUNIT_ASSERT_EQUAL(2.0, fieldB.scale());
+ CPPUNIT_ASSERT_EQUAL(true, fieldB.addDimensionOkay());
+} // testGetConst
+
+// ----------------------------------------------------------------------
+// Test mesh().
+void
+pylith::topology::TestFieldsNewMesh::testMesh(void)
+{ // testMesh
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ const Mesh& mesh = fields.mesh();
+} // testMesh
+
+// ----------------------------------------------------------------------
+// Test fieldNames() const.
+void
+pylith::topology::TestFieldsNewMesh::testFieldNames(void)
+{ // testFieldNames
+ const int numFieldsE = 2;
+ const char* namesE[2] = {
+ "field A",
+ "field B"
+ };
+
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "displacement", 4, FieldBase::OTHER, 2.0, true);
+
+ int numFields = 0;
+ std::string* names = 0;
+ fields.fieldNames(&numFields, &names);
+
+ CPPUNIT_ASSERT_EQUAL(numFieldsE, numFields);
+
+ for (int i=0; i < numFields; ++i)
+ CPPUNIT_ASSERT_EQUAL(std::string(namesE[i]), names[i]);
+
+ delete[] names; names = 0;
+} // testFieldNames
+
+
+// End of file
Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh 2010-09-02 00:38:38 UTC (rev 17161)
@@ -0,0 +1,113 @@
+// -*- 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/TestFieldsNewMesh.hh
+ *
+ * @brief C++ unit testing for FieldsNew<Mesh>.
+ */
+
+#if !defined(pylith_topology_testfieldsnewmesh_hh)
+#define pylith_topology_testfieldsnewmesh_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 TestFieldsNewMesh;
+ } // topology
+} // pylith
+
+// TestField -------------------------------------------------------------
+/// C++ unit testing for Field.
+class pylith::topology::TestFieldsNewMesh : public CppUnit::TestFixture
+{ // class TestField
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestFieldsNewMesh );
+
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testHasField );
+ CPPUNIT_TEST( testAdd );
+#if 0
+ CPPUNIT_TEST( testAllocateSequence );
+ CPPUNIT_TEST( testAllocateArray );
+ CPPUNIT_TEST( testAllocateDomain );
+#endif
+ CPPUNIT_TEST( testGet );
+ CPPUNIT_TEST( testGetConst );
+ CPPUNIT_TEST( testMesh );
+ CPPUNIT_TEST( testFieldNames );
+
+ CPPUNIT_TEST_SUITE_END();
+
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /// Setup test case.
+ void setUp(void);
+
+ /// Tear down test case.
+ void tearDown(void);
+
+ /// Test constructor.
+ void testConstructor(void);
+
+ /// Test hasField().
+ void testHasField(void);
+
+ /// Test add().
+ void testAdd(void);
+
+ /// Test allocate(label_sequence).
+ void testAllocateSequence(void);
+
+ /// Test allocate(int_array).
+ void testAllocateArray(void);
+
+ /// Test allocate(domain).
+ void testAllocateDomain(void);
+
+ /// Test getField().
+ void testGet(void);
+
+ /// Test getField() for const FieldsNew.
+ void testGetConst(void);
+
+ /// Test mesh().
+ void testMesh(void);
+
+ /// Test fieldNames().
+ void testFieldNames(void);
+
+// PRIVATE MEMBERS /////////////////////////////////////////////////////
+private :
+
+ Mesh* _mesh;
+
+}; // class TestFieldsNewMesh
+
+#endif // pylith_topology_testfieldsnewmesh_hh
+
+
+// End of file
More information about the CIG-COMMITS
mailing list