[cig-commits] r14055 - short/3D/PyLith/branches/pylith-swig/libsrc/topology

brad at geodynamics.org brad at geodynamics.org
Sun Feb 15 20:00:18 PST 2009


Author: brad
Date: 2009-02-15 20:00:18 -0800 (Sun, 15 Feb 2009)
New Revision: 14055

Added:
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh
Removed:
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.hh
Modified:
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am
Log:
Replaced FieldsManager with SolutionFields.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh	2009-02-15 00:21:30 UTC (rev 14054)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh	2009-02-16 04:00:18 UTC (rev 14055)
@@ -22,6 +22,8 @@
 // Include directives ---------------------------------------------------
 #include "topologyfwd.hh" // forward declarations
 
+#include <string> // USES std::string
+
 // Fields ---------------------------------------------------------------
 template<typename field_type>
 class pylith::topology::Fields
@@ -81,13 +83,13 @@
    */
   void copyLayout(const char* name);
 
-// PRIVATE TYPEDEFS /////////////////////////////////////////////////////
-private :
+// PROTECTED TYPEDEFS ///////////////////////////////////////////////////
+protected :
 
   typedef std::map< std::string, field_type* > map_type;
 
-// PRIVATE MEMBERS //////////////////////////////////////////////////////
-private :
+// PROTECTED MEMBERS ////////////////////////////////////////////////////
+protected :
 
   map_type _fields;
   const typename field_type::Mesh& _mesh;

Deleted: short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.cc	2009-02-15 00:21:30 UTC (rev 14054)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.cc	2009-02-16 04:00:18 UTC (rev 14055)
@@ -1,258 +0,0 @@
-// -*- C++ -*-
-//
-// ======================================================================
-//
-//                           Brad T. Aagaard
-//                        U.S. Geological Survey
-//
-// {LicenseText}
-//
-// ======================================================================
-//
-
-#include <portinfo>
-
-#include "FieldsManager.hh" // implementation of class methods
-
-#include <stdexcept> // USES std::runtime_error
-#include <sstream> // USES std::ostringstream
-#include <strings.h> // USES strcasecmp()
-#include <cassert> // USES assert()
-
-// ----------------------------------------------------------------------
-// Constructor
-pylith::topology::FieldsManager::FieldsManager(const ALE::Obj<Mesh>& mesh) :
-  _mesh(mesh),
-  _solutionName("")
-{ // constructor
-} // constructor
- 
-// ----------------------------------------------------------------------
-// Destructor
-pylith::topology::FieldsManager::~FieldsManager(void)
-{ // destructor
-} // destructor
-
-// ----------------------------------------------------------------------
-// Add field.
-void
-pylith::topology::FieldsManager::addReal(const char* name)
-{ // addReal
-  assert(!_mesh.isNull());
-
-  map_real_type::iterator iter = _real.find(name);
-  if (iter != _real.end()) {
-    std::ostringstream msg;
-    msg << "Could not add field '" << name
-	<< "', because it already exists.";
-    throw std::runtime_error(msg.str());
-  } // if
-  
-  _real[name] = new real_section_type(_mesh->comm(), _mesh->debug());
-} // addReal
-
-// ----------------------------------------------------------------------
-// Get field.
-const ALE::Obj<pylith::real_section_type>&
-pylith::topology::FieldsManager::getReal(const char* name)
-{ // getReal
-  map_real_type::const_iterator iter = _real.find(name);
-  if (iter == _real.end()) {
-    std::ostringstream msg;
-    msg << "Could not find field '" << name << "'.";
-    throw std::runtime_error(msg.str());
-  } // if
-  return iter->second;
-} // getReal
-
-// ----------------------------------------------------------------------
-// Remove field.
-void
-pylith::topology::FieldsManager::delReal(const char* name)
-{ // delReal
-  map_real_type::const_iterator iter = _real.find(name);
-  if (iter == _real.end()) {
-    std::ostringstream msg;
-    msg << "Could not find field '" << name << "' to delete.";
-    throw std::runtime_error(msg.str());
-  } // if
-  _real.erase(name);
-} // delReal
-
-// ----------------------------------------------------------------------
-// Set fiber dimension for field.
-void
-pylith::topology::FieldsManager::setFiberDimension(const char* name,
-						   const int fiberDim,
-						   const char* points)
-{ // setFiberDimension
-  assert(!_mesh.isNull());
-  assert(fiberDim >= 0);
-
-  map_real_type::const_iterator iter = _real.find(name);
-  if (iter == _real.end()) {
-    std::ostringstream msg;
-    msg << "Could not find field '" << name << "' to delete.";
-    throw std::runtime_error(msg.str());
-  } // if
-
-  assert(!_real[name].isNull());
-  if (0 == strcasecmp(points, "vertices")) {
-    const ALE::Obj<Mesh::label_sequence>& vertices = _mesh->depthStratum(0);
-    _real[name]->setChart(real_section_type::chart_type(*std::min_element(vertices->begin(),vertices->end()),*std::max_element(vertices->begin(),vertices->end())+1));
-    _real[name]->setFiberDimension(vertices, fiberDim);
-  } else if (0 == strcasecmp(points, "cells")) {
-    const ALE::Obj<Mesh::label_sequence>& cells = _mesh->heightStratum(0);
-    _real[name]->setChart(real_section_type::chart_type(*std::min_element(cells->begin(),cells->end()),*std::max_element(cells->begin(),cells->end())+1));
-    _real[name]->setFiberDimension(cells, fiberDim);
-  } else {
-    std::ostringstream msg;
-    msg << "Could not determine parse '" << points
-	<< "' into a known point type when setting fiber dimension to "
-	<< fiberDim << " for section '" << name << "'.\n"
-	<< "Known point types are 'vertices' and 'cells'.";
-    throw std::runtime_error(msg.str());
-  } // if/else
-} // setFiberDimension
-
-// ----------------------------------------------------------------------
-// Allocate field.
-void
-pylith::topology::FieldsManager::allocate(const char* name)
-{ // allocate
-  assert(!_mesh.isNull());
-
-  map_real_type::const_iterator iter = _real.find(name);
-  if (iter == _real.end()) {
-    std::ostringstream msg;
-    msg << "Could not find field '" << name << "' to delete.";
-    throw std::runtime_error(msg.str());
-  } // if
-  
-  assert(!_real[name].isNull());
-  _mesh->allocate(_real[name]);
-} // allocate
-
-// ----------------------------------------------------------------------
-// Copy layout of field to all other fields.
-void
-pylith::topology::FieldsManager::copyLayout(const char* name)
-{ // copyLayout
-  assert(!_mesh.isNull());
-
-  map_real_type::const_iterator src = _real.find(name);
-  if (src == _real.end()) {
-    std::ostringstream msg;
-    msg << "Could not find field '" << name << "'.";
-    throw std::runtime_error(msg.str());
-  } // if
-  
-  assert(!src->second.isNull());  
-  const map_real_type::iterator begin = _real.begin();
-  const map_real_type::iterator end = _real.end();
-  for (map_real_type::iterator iter=begin; iter != end; ++iter)
-    if (iter != src) {
-      // Make sure fields are same size
-      assert(!iter->second.isNull());
-      iter->second->setAtlas(src->second->getAtlas());
-      iter->second->allocateStorage();
-      iter->second->setBC(src->second->getBC());
-    } // if
-} // copyLayout
-
-// ----------------------------------------------------------------------
-// Copy layout of field to managed fields.
-void
-pylith::topology::FieldsManager::copyLayout(
-				    const ALE::Obj<real_section_type>& field)
-{ // copyLayout
-  assert(!_mesh.isNull());
-  assert(!field.isNull());
-  
-  const map_real_type::iterator begin = _real.begin();
-  const map_real_type::iterator end = _real.end();
-  for (map_real_type::iterator iter=begin; iter != end; ++iter) {
-    // Make sure fields are same size
-    assert(!iter->second.isNull());
-    iter->second->setAtlas(field->getAtlas());
-    iter->second->allocateStorage();
-    iter->second->setBC(field->getBC());
-  } // for
-} // copyLayout
-
-// ----------------------------------------------------------------------
-// Set name of solution field.
-void
-pylith::topology::FieldsManager::solutionField(const char* name)
-{ // solutionField
-  map_real_type::const_iterator iter = _real.find(name);
-  if (iter == _real.end()) {
-    std::ostringstream msg;
-    msg << "Cannot use unknown field '" << name 
-	<< "' when setting name of solution field.";
-    throw std::runtime_error(msg.str());
-  } // if
-  _solutionName = name;
-} // solutionField
-
-// ----------------------------------------------------------------------
-// Get solution field.
-const ALE::Obj<pylith::real_section_type>&
-pylith::topology::FieldsManager::getSolution(void)
-{ // getSolution
-  if (_solutionName == "")
-    throw std::runtime_error("Cannot retrieve solution. Name of solution " \
-			     "field has not been specified.");
-  return getReal(_solutionName.c_str());
-} // getSolution
-
-// ----------------------------------------------------------------------
-// Create history manager for a subset of the managed fields.
-void
-pylith::topology::FieldsManager::createHistory(const char** fields,
-					       const int size)
-{ // createHistory
-  if (size > 0 && 0 != fields) {
-    _history.resize(size);
-    for (int i=0; i < size; ++i) {
-      map_real_type::const_iterator iter = _real.find(fields[i]);
-      if (iter == _real.end()) {
-	std::ostringstream msg;
-	msg << "Cannot use unknown field '" << fields[i] 
-	    << "' when creating history.";
-	throw std::runtime_error(msg.str());
-      } // if
-      _history[i] = fields[i];
-    } // for
-  } // if
-} // createHistory
-
-// ----------------------------------------------------------------------
-// Shift fields in history. Handles to fields are shifted so that the
-// most recent values become associated with the second most recent
-// item in the history, etc.
-void
-pylith::topology::FieldsManager::shiftHistory(void)
-{ // shiftHistory
-
-  assert(_history.size() > 0);
-  const int size = _history.size();
-  ALE::Obj<real_section_type> tmp = _real[_history[size-1]];
-  tmp.addRef();
-  for (int i=size-1; i > 0; --i)
-    _real[_history[i]] = _real[_history[i-1]];
-  _real[_history[0]] = tmp;
-
-} // shiftHistory
-
-// ----------------------------------------------------------------------
-// Get field in history by position.
-const ALE::Obj<pylith::real_section_type>&
-pylith::topology::FieldsManager::getFieldByHistory(const int index)
-{ // getFieldByHistory
-  assert(index < _history.size());
-  return getReal(_history[index].c_str());
-} // getFieldByHistory
-
-
-// End of file 

Deleted: short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.hh	2009-02-15 00:21:30 UTC (rev 14054)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/FieldsManager.hh	2009-02-16 04:00:18 UTC (rev 14055)
@@ -1,163 +0,0 @@
-// -*- C++ -*-
-//
-// ======================================================================
-//
-//                           Brad T. Aagaard
-//                        U.S. Geological Survey
-//
-// {LicenseText}
-//
-// ======================================================================
-//
-
-/**
- * @file pylith/topology/FieldsManager.hh
- *
- * @brief Object for managing fields associated with the fields
- * defined over a finite-element mesh. 
- */
-
-#if !defined(pylith_topology_fieldsmanager_hh)
-#define pylith_topology_fieldsmanager_hh
-
-#include <map> // HASA std::map
-#include <string> // USES std::string
-#include <vector> // USES std::vector
-
-#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
-
-namespace pylith {
-  namespace topology {
-    class FieldsManager;
-    class TestFieldsManager;
-  } // topology
-} // pylith
-
-class pylith::topology::FieldsManager
-{ // FieldsManager
-  friend class TestFieldsManager; // unit testing
-
-// PUBLIC MEMBERS ///////////////////////////////////////////////////////
-public :
-
-  /// Constructor
-  FieldsManager(const ALE::Obj<Mesh>& mesh);
-
-  /// Destructor
-  ~FieldsManager(void);
-
-  /** Add field.
-   *
-   * @param name Name of field.
-   */
-  void addReal(const char* name);
-
-  /** Get field.
-   *
-   * @param name Name of field.
-   */
-  const ALE::Obj<real_section_type>& getReal(const char* name);
-
-  /** Remove field.
-   *
-   * @param name Name of field.
-   */
-  void delReal(const char* name);
-
-  /** Set fiber dimension for field.
-   *
-   * @param name Name of field.
-   * @param fiberDim Fiber dimension
-   * @param points Name of set of points in mesh over which section is defined
-   *   { "vertices", "cells" }
-   */
-  void setFiberDimension(const char* name,
-			 const int fiberDim,
-			 const char* points);
-
-  /** Allocate field.
-   *
-   * @param name Name of field.
-   */
-  void allocate(const char* name);
-
-  /** Copy layout of field to all other fields.
-   *
-   * @param name Name of field.
-   */
-  void copyLayout(const char* name);
-
-  /** Copy layout of field to managed fields.
-   *
-   * @param field Field from which to copy layout.
-   */
-  void copyLayout(const ALE::Obj<real_section_type>& field);
-
-  /** Set name of solution field.
-   *
-   * @param name Name of field that is the solution.
-   */
-  void solutionField(const char* name);
-
-  /** Get solution field.
-   *
-   * @returns Solution field.
-   */
-  const ALE::Obj<real_section_type>& getSolution(void);
-
-  /** Create history manager for a subset of the managed fields.
-   *
-   * @param fields Fields in history (first is most recent).
-   * @param size Number of fields in history.
-   */
-  void createHistory(const char** fields,
-		     const int size);
-
-  /** Shift fields in history. Handles to fields are shifted so that
-   *  the most recent values become associated with the second most
-   *  recent item in the history, etc.
-   */
-  void shiftHistory(void);
-
-  /** Get field in history by position.
-   *
-   * @param index Index in history [0=most recent, 1=previous, etc]
-   * @returns Field in history.
-   */
-  const ALE::Obj<real_section_type>& getFieldByHistory(const int index);
-
-// NOT IMPLEMENTED //////////////////////////////////////////////////////
-private :
-
-  /// Not implemented
-  FieldsManager(const FieldsManager&);
-
-  /// Not implemented
-  const FieldsManager& operator=(const FieldsManager&);
-
-// PRIVATE TYPEDEFS /////////////////////////////////////////////////////
-private :
-
-  typedef std::map< std::string, ALE::Obj<real_section_type> > map_real_type;
-
-// PRIVATE MEMBERS //////////////////////////////////////////////////////
-private :
-
-  /// PETSc mesh associated with fields
-  const ALE::Obj<Mesh>& _mesh;
-
-  /// Map for fieldss stored as real fields
-  map_real_type _real;
-
-  /// Name of field that corresponds to the solution.
-  std::string _solutionName;
-
-  /// History manager for a subset of the fields
-  std::vector<std::string> _history;
-
-}; // FieldsManager
-
-#endif // pylith_topology_fieldsmanager_hh
-
-
-// End of file 

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am	2009-02-15 00:21:30 UTC (rev 14054)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am	2009-02-16 04:00:18 UTC (rev 14055)
@@ -25,6 +25,7 @@
 	MeshOps.hh \
 	MeshRefiner.hh \
 	RefineUniform.hh \
+	SolutionFields.hh \
 	SubMesh.hh \
 	SubMesh.icc \
 	SubMesh.cc \

Added: short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc	2009-02-16 04:00:18 UTC (rev 14055)
@@ -0,0 +1,103 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "SolutionFields.hh" // implementation of class methods
+
+// ----------------------------------------------------------------------
+// Default constructor.
+pylith::topology::SolutionFields::SolutionFields(const Mesh& mesh) :
+  Fields<Field<Mesh> >(mesh),
+  _solutionName("")
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor.
+pylith::topology::SolutionFields::~SolutionFields(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set name of solution field.
+void
+pylith::topology::SolutionFields::solutionField(const char* name)
+{ // solutionField
+  map_type::const_iterator iter = _fields.find(name);
+  if (iter == _fields.end()) {
+    std::ostringstream msg;
+    msg << "Cannot use unknown field '" << name 
+	<< "' when setting name of solution field.";
+    throw std::runtime_error(msg.str());
+  } // if
+  _solutionName = name;
+} // solutionField
+
+// ----------------------------------------------------------------------
+// Get solution field.
+const pylith::topology::Field<pylith::topology::Mesh>&
+pylith::topology::SolutionFields::getSolution(void) const
+{ // getSolution
+  if (_solutionName == "")
+    throw std::runtime_error("Cannot retrieve solution. Name of solution " \
+			     "field has not been specified.");
+  return get(_solutionName.c_str());
+} // getSolution
+
+// ----------------------------------------------------------------------
+// Get solution field.
+pylith::topology::Field<pylith::topology::Mesh>&
+pylith::topology::SolutionFields::getSolution(void)
+{ // getSolution
+  if (_solutionName == "")
+    throw std::runtime_error("Cannot retrieve solution. Name of solution " \
+			     "field has not been specified.");
+  return get(_solutionName.c_str());
+} // getSolution
+
+// ----------------------------------------------------------------------
+// Create history manager for a subset of the managed fields.
+void
+pylith::topology::SolutionFields::createHistory(const char** fields,
+						const int size)
+{ // createHistory
+  if (size > 0 && 0 != fields) {
+    _history.resize(size);
+    for (int i=0; i < size; ++i) {
+      map_type::const_iterator iter = _fields.find(fields[i]);
+      if (iter == _fields.end()) {
+	std::ostringstream msg;
+	msg << "Cannot use unknown field '" << fields[i] 
+	    << "' when creating history.";
+	throw std::runtime_error(msg.str());
+      } // if
+      _history[i] = fields[i];
+    } // for
+  } // if
+} // createHistory
+
+// ----------------------------------------------------------------------
+// Shift fields in history.
+void
+pylith::topology::SolutionFields::shiftHistory(void)
+{ // shiftHistory
+  assert(_history.size() > 0);
+  const int size = _history.size();
+  Field<Mesh>* tmp = _fields[_history[size-1]];
+  for (int i=size-1; i > 0; --i)
+    _fields[_history[i]] = _fields[_history[i-1]];
+  _fields[_history[0]] = tmp;
+} // shiftHistory
+
+
+// End of file 

Added: short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh	2009-02-16 04:00:18 UTC (rev 14055)
@@ -0,0 +1,101 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file libsrc/topology/SolutionFields.hh
+ *
+ * @brief Object for managing solution fields over a finite-element
+ * mesh.
+ */
+
+#if !defined(pylith_topology_solutionfields_hh)
+#define pylith_topology_solutionfields_hh
+
+// Include directives ---------------------------------------------------
+#include "topologyfwd.hh" // forward declarations
+
+#include <vector> // HASA std::vector
+
+#include "Mesh.hh" // ISA Field<Mesh>
+#include "Field.hh" // ISA Fields< Field<Mesh> >
+#include "Fields.hh" // ISA Fields< Field<Mesh> >
+
+// SolutionFields -------------------------------------------------------
+class pylith::topology::SolutionFields : public Fields<Field<Mesh> >
+{ // SolutionFields
+  friend class TestSolutionFields; // unit testing
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param mesh Finite-element mesh.
+   */
+  SolutionFields(const Mesh& mesh);
+
+  /// Destructor.
+  ~SolutionFields(void);
+
+  /** Set name of solution field.
+   *
+   * @param name Name of field that is the solution.
+   */
+  void solutionField(const char* name);
+
+  /** Get solution field.
+   *
+   * @returns Solution field.
+   */
+  const Field<Mesh>& getSolution(void) const;
+
+  /** Get solution field.
+   *
+   * @returns Solution field.
+   */
+  Field<Mesh>& getSolution(void);
+
+  /** Create history manager for a subset of the managed fields.
+   *
+   * @param fields Fields in history (first is most recent).
+   * @param size Number of fields in history.
+   */
+  void createHistory(const char** fields,
+		     const int size);
+
+  /** Shift fields in history. Handles to fields are shifted so that
+   *  the most recent values become associated with the second most
+   *  recent item in the history, etc.
+   */
+  void shiftHistory(void);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  /// Name of field that corresponds to the solution.
+  std::string _solutionName;
+
+  /// History manager for a subset of the fields
+  std::vector<std::string> _history;
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  SolutionFields(const SolutionFields&); ///< Not implemented
+  const SolutionFields& operator=(const SolutionFields&); ///< Not implemented
+
+}; // SolutionFields
+
+#endif // pylith_topology_solutionfields_hh
+
+
+// End of file 



More information about the CIG-COMMITS mailing list