[cig-commits] r21514 - short/3D/PyLith/trunk/libsrc/pylith/topology

brad at geodynamics.org brad at geodynamics.org
Tue Mar 12 16:04:09 PDT 2013


Author: brad
Date: 2013-03-12 16:04:09 -0700 (Tue, 12 Mar 2013)
New Revision: 21514

Added:
   short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.icc
   short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.icc
Removed:
   short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.icc
   short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.icc
Modified:
   short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.icc
Log:
Added MatVisitorMesh and MatVisitorSubMesh. Reorganized visitor headers into VisitorMesh.hh and VisitorSubMesh.hh.

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.hh	2013-03-12 20:39:31 UTC (rev 21513)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.hh	2013-03-12 23:04:09 UTC (rev 21514)
@@ -42,7 +42,10 @@
 // PUBLIC METHODS ///////////////////////////////////////////////////////
 public :
 
-  /// Default constructor (includes initialization).
+  /** Default constructor (includes initialization).
+   *
+   * @param dmMesh PETSc DM for finite-element mesh.
+   */
   CoordsVisitor(const PetscDM& dmMesh);
 
   /// Default destructor

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.icc	2013-03-12 20:39:31 UTC (rev 21513)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/CoordsVisitor.icc	2013-03-12 23:04:09 UTC (rev 21514)
@@ -32,10 +32,7 @@
   _localArray(NULL)
 { // constructor
   assert(_dm);
-  PetscErrorCode err;
-  err = DMPlexGetCoordinateSection(_dm, &_section);CHECK_PETSC_ERROR(err);assert(_section);
-  err = DMGetCoordinatesLocal(_dm, &_localVec);CHECK_PETSC_ERROR(err);assert(_localVec);
-  err = VecGetArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);assert(_localArray);
+  initialize();
 } // constructor
 
 // ----------------------------------------------------------------------
@@ -43,6 +40,27 @@
 inline
 pylith::topology::CoordsVisitor::~CoordsVisitor(void)
 { // destructor
+  clear();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Initialize cached data.
+inline
+void
+pylith::topology::CoordsVisitor::initialize(void)
+{ // initialize
+  assert(_dm);
+  PetscErrorCode err;
+  err = DMPlexGetCoordinateSection(_dm, &_section);CHECK_PETSC_ERROR(err);assert(_section);
+  err = DMGetCoordinatesLocal(_dm, &_localVec);CHECK_PETSC_ERROR(err);assert(_localVec);
+  err = VecGetArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);assert(_localArray);
+} // initialize
+
+// ----------------------------------------------------------------------
+// Clear cached data.
+void
+pylith::topology::CoordsVisitor::clear(void)
+{ // clear
   if (_localArray) {
     assert(_localVec);
     PetscErrorCode err = VecRestoreArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);
@@ -50,7 +68,7 @@
 
   _localVec = NULL;
   _section = NULL;
-} // destructor
+} // clear
 
 // ----------------------------------------------------------------------
 // Get the local coordinates array associated with the local PETSc Vec.
@@ -87,6 +105,7 @@
 
 // ----------------------------------------------------------------------
 // Get coordinates array associated with closure.
+inline
 void
 pylith::topology::CoordsVisitor::getClosure(PetscScalar** coordsCell,
 					    PetscInt* coordsSize,
@@ -100,6 +119,7 @@
 
 // ----------------------------------------------------------------------
 // Restore coordinates array associated with closure.
+inline
 void
 pylith::topology::CoordsVisitor::restoreClosure(PetscScalar** coordsCell,
 						PetscInt* coordsSize,

Deleted: short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.hh	2013-03-12 20:39:31 UTC (rev 21513)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.hh	2013-03-12 23:04:09 UTC (rev 21514)
@@ -1,161 +0,0 @@
-// -*- 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-2012 University of California, Davis
-//
-// See COPYING for license information.
-//
-// ======================================================================
-//
-
-/**
- * @file libsrc/topology/MeshVisitor.hh
- *
- * @brief C++ helper class for accessing field values at points in a
- * finite-element mesh.
- */
-
-#if !defined(pylith_topology_meshvisitor_hh)
-#define pylith_topology_meshvisitor_hh
-
-// Include directives ---------------------------------------------------
-#include "topologyfwd.hh" // forward declarations
-
-#include "pylith/utils/petscfwd.h" // HASA PetscVec, PetscSection
-
-#include <petscdmmesh.hh>
-
-// MeshVisitor ----------------------------------------------------------
-/** @brief Helper class for accessing field values at points in a
- *  finite-element mesh.
- */
-class pylith::topology::MeshVisitor
-{ // MeshVisitor
-  friend class TestMeshVisitor; // unit testing
-
-// PUBLIC METHODS ///////////////////////////////////////////////////////
-public :
-
-  /** Constructor with field over a mesh.
-   *
-   * @param field Field over a mesh.
-   */
-  MeshVisitor(const Field<Mesh>& field);
-
-  /** Constructor with field over a submesh.
-   *
-   * @param field Field over a submesh.
-   */
-  MeshVisitor(const Field<SubMesh>& field);
-
-  /// Default destructor
-  ~MeshVisitor(void);
-
-  /** Initialize using field over a mesh or submesh.
-   *
-   * @param field Field over a mesh/submesh.
-   */
-  template<typename field_type>
-  void initialize(const field_type& field);
-
-  /// Clear cached data.
-  void clear(void);
-  
-  /** Get the array of values associated with the local PETSc Vec.
-   * 
-   * @returns Array of values.
-   */
-  PetscScalar* localArray(void) const;
-
-  /** Get the PETSc section.
-   * 
-   * @returns PETSc section.
-   */
-  PetscSection petscSection(void) const;
-
-  /** Get the local PETSc Vec.
-   * 
-   * @returns PETSc Vec.
-   */
-  PetscVec localVec(void) const;
-
-  /** Get fiber dimension of coordinates for point.
-   *
-   * @param point Point in mesh.
-   * @returns Fiber dimension.
-   */
-  PetscInt sectionDof(const PetscInt point) const;
-
-  /** Get offset into coordinates array for point.
-   *
-   * @param point Point in mesh.
-   * @returns Offset.
-   */
-  PetscInt sectionOffset(const PetscInt point) const;
-
-  /** Get array of values associated with closure.
-   *
-   * @pre Must be followed by call to getClosure().
-   *
-   * @param valuesCell Array of values for cell.
-   * @param valuesSize Size of values array.
-   * @param cell Finite-element cell.
-   */
-  void getClosure(PetscScalar** valuesCell,
-		  PetscInt* valuesSize,
-		  const PetscInt cell) const;
-
-  /** Restore array of values associated with closure.
-   *
-   * @pre Must be preceded by call to getClosure().
-   *
-   * @param valuesCell Array of values for cell.
-   * @param valuesSize Size of values array.
-   * @param cell Finite-element cell.
-   */
-  void restoreClosure(PetscScalar** valuesCell,
-		      PetscInt* valuesSize,
-		      const PetscInt cell) const;
-
-  /** Set values associated with closure.
-   *
-   * @param valuesCell Array of values for cell.
-   * @param valuesSize Size of values array.
-   * @param cell Finite-element cell.
-   * @param mode Mode for inserting values.
-   */
-  void setClosure(const PetscScalar* valuesCell,
-		  const PetscInt valuesSize,
-		  const PetscInt cell,
-		  const InsertMode mode) const;
-
-// PRIVATE MEMBERS //////////////////////////////////////////////////////
-private :
-
-  PetscDM _dm; ///< Cached PETSc dm for mesh.
-  PetscVec _localVec; ///< Cached local PETSc Vec.
-  PetscSection _section; ///< Cached PETSc section.
-  PetscScalar* _localArray; ///< Cached local array
-
-// NOT IMPLEMENTED //////////////////////////////////////////////////////
-private :
-
-  MeshVisitor(const MeshVisitor&); ///< Not implemented
-  const MeshVisitor& operator=(const MeshVisitor&); ///< Not implemented
-
-}; // MeshVisitor
-
-#include "MeshVisitor.icc"
-
-#endif // pylith_topology_meshvisitor_hh
-
-
-// End of file

Deleted: short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.icc	2013-03-12 20:39:31 UTC (rev 21513)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.icc	2013-03-12 23:04:09 UTC (rev 21514)
@@ -1,159 +0,0 @@
-// -*- 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-2011 University of California, Davis
-//
-// See COPYING for license information.
-//
-// ======================================================================
-//
-
-#if !defined(pylith_topology_meshvisitor_hh)
-#error "MeshVisitor.icc must be included only from MeshVisitor.hh"
-#else
-
-#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
-
-// ----------------------------------------------------------------------
-// Constructor with field over a mesh.
-inline
-pylith::topology::MeshVisitor::MeshVisitor(const Field<Mesh>& field)
-{ // constructor
-  initialize<Field<Mesh> >(field);
-} // constructor
-
-// ----------------------------------------------------------------------
-// Constructor with field over a submesh.
-inline
-pylith::topology::MeshVisitor::MeshVisitor(const Field<SubMesh>& field)
-{ // constructor
-  initialize<Field<SubMesh> >(field);
-} // constructor
-
-// ----------------------------------------------------------------------
-// Default destructor
-inline
-pylith::topology::MeshVisitor::~MeshVisitor(void)
-{ // destructor
-  clear();
-} // destructor
-
-// ----------------------------------------------------------------------
-// Initialized cached data members.
-template<typename field_type>
-inline
-void
-pylith::topology::MeshVisitor::initialize(const field_type& field)
-{ // initialize
-  _dm = field.mesh().dmMesh();assert(_dm);
-  _section = field.petscSection();assert(_section);
-  _localVec = field.localVector();assert(_localVec);
-
-  PetscErrorCode err = VecGetArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);
-} // initialize
-
-// ----------------------------------------------------------------------
-// Default destructor
-inline
-void
-pylith::topology::MeshVisitor::clear(void)
-{ // clear
-  assert(_localVec);
-  PetscErrorCode err = VecRestoreArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);
-  assert(!_localArray);
-
-  _dm = NULL;
-  _section = NULL;
-  _localVec = NULL;
-} // clear
-
-// ----------------------------------------------------------------------
-// Get the local coordinates array associated with the local PETSc Vec.
-inline
-PetscScalar*
-pylith::topology::MeshVisitor::localArray(void) const
-{ // localArray
-  return _localArray;
-} // localArray
-
-// ----------------------------------------------------------------------
-// Get fiber dimension of coordinates for point.
-inline
-PetscInt
-pylith::topology::MeshVisitor::sectionDof(const PetscInt point) const
-{ // sectionDof
-  assert(_section);
-  PetscInt dof;
-  PetscErrorCode err = PetscSectionGetDof(_section, point, &dof);CHECK_PETSC_ERROR(err);
-  return dof;
-} // sectionDof
-
-// ----------------------------------------------------------------------
-// Get offset into coordinates array for point.
-inline
-PetscInt
-pylith::topology::MeshVisitor::sectionOffset(const PetscInt point) const
-{ // sectionOffset
-  assert(_section);
-  PetscInt offset;
-  PetscErrorCode err = PetscSectionGetOffset(_section, point, &offset);CHECK_PETSC_ERROR(err);
-  return offset;
-} // sectionOffset
-
-// ----------------------------------------------------------------------
-// Get coordinates array associated with closure.
-void
-pylith::topology::MeshVisitor::getClosure(PetscScalar** valuesCell,
-					  PetscInt* valuesSize,
-					  const PetscInt cell) const
-{ // getClosure
-  assert(_dm);
-  assert(_section);
-  assert(_localVec);
-  PetscErrorCode err = DMPlexVecGetClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
-} // getClosure
-
-// ----------------------------------------------------------------------
-/** Restore coordinates array associated with closure.
- *
- * @param coordsCell Array of coordinates for cell.
- * @param coordsSize Size of coordinates array.
- * @param cell Finite-element cell.
- */
-void
-pylith::topology::MeshVisitor::restoreClosure(PetscScalar** valuesCell,
-					      PetscInt* valuesSize,
-					      const PetscInt cell) const
-{ // restoreClosure
-  assert(_dm);
-  assert(_section);
-  assert(_localVec);
-  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
-} // restoreClosure
-
-// ----------------------------------------------------------------------
-// Set values associated with closure.
-void
-pylith::topology::MeshVisitor::setClosure(const PetscScalar* valuesCell,
-					  const PetscInt valuesSize,
-					  const PetscInt cell,
-					  const InsertMode mode) const
-{ // setClosure
-  assert(_dm);
-  assert(_section);
-  assert(_localVec);
-  PetscErrorCode err = DMPlexVecSetClosure(_dm, _section, _localVec, cell, valuesCell, mode);CHECK_PETSC_ERROR(err);
-} // setClosure
-
-#endif
-
-
-// End of file

Deleted: short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.hh	2013-03-12 20:39:31 UTC (rev 21513)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.hh	2013-03-12 23:04:09 UTC (rev 21514)
@@ -1,205 +0,0 @@
-// -*- 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-2012 University of California, Davis
-//
-// See COPYING for license information.
-//
-// ======================================================================
-//
-
-/**
- * @file libsrc/topology/SubMeshVisitor.hh
- *
- * @brief C++ helper class for accessing field values at points in a
- * submesh within a finite-element mesh.
- *
- * This visitor is used to access values associated with a submesh
- * when the field is defined over the entire mesh. This is why a
- * submesh and index set are passed to the constructor.
- *
- * Use the PointVisitorMesh object when the field and mesh/submesh are
- * defined over the same set of points (i.e., field over a submesh or field
- * of a mesh).
- */
-
-#if !defined(pylith_topology_submeshvisitor_hh)
-#define pylith_topology_submeshvisitor_hh
-
-// Include directives ---------------------------------------------------
-#include "topologyfwd.hh" // forward declarations
-
-#include "pylith/utils/petscfwd.h" // HASA PetscVec, PetscSection
-
-#include <petscdmmesh.hh>
-
-// SubMeshVisitor -------------------------------------------------------
-/** @brief Helper class for accessing field values at points in a
- *  finite-element mesh.
- */
-class pylith::topology::SubMeshVisitor
-{ // SubMeshVisitor
-  friend class TestSubMeshVisitor; // unit testing
-
-// PUBLIC METHODS ///////////////////////////////////////////////////////
-public :
-
-  /** Default constructor.
-   *
-   * @param field Field associated with visitor.
-   * @param submeshIS Submesh index set associated with visitor.
-   */
-  SubMeshVisitor(const Field<Mesh>& field,
-		 const SubMeshIS& submeshIS);
-
-  /// Default destructor
-  ~SubMeshVisitor(void);
-
-  /* Initialize cached data.
-   *
-   * @param submeshIS Submesh index set associated with visitor.
-   */
-  void initialize(const SubMeshIS& submeshIS);
-
-  /// Clear cached data.
-  void clear(void);
-  
-  /** Get the array of values associated with the local PETSc Vec.
-   * 
-   * @returns Array of values.
-   */
-  PetscScalar* localArray(void) const;
-
-  /** Get the PETSc section.
-   * 
-   * @returns PETSc section.
-   */
-  PetscSection petscSection(void) const;
-
-  /** Get the local PETSc Vec.
-   * 
-   * @returns PETSc Vec.
-   */
-  PetscVec localVec(void) const;
-
-  /** Get fiber dimension of coordinates for point.
-   *
-   * @param point Point in mesh.
-   * @returns Fiber dimension.
-   */
-  PetscInt sectionDof(const PetscInt point) const;
-
-  /** Get offset into coordinates array for point.
-   *
-   * @param point Point in mesh.
-   * @returns Offset.
-   */
-  PetscInt sectionOffset(const PetscInt point) const;
-
-  /** Get array of values associated with closure.
-   *
-   * @param valuesCell Array of values for cell.
-   * @param valuesSize Size of values array.
-   * @param cell Finite-element cell.
-   */
-  void getClosure(PetscScalar** valuesCell,
-		  PetscInt* valuesSize,
-		  const PetscInt cell) const;
-
-  /** Restore array of values associated with closure.
-   *
-   * @param valuesCell Array of values for cell.
-   * @param valuesSize Size of values array.
-   * @param cell Finite-element cell.
-   */
-  void restoreClosure(PetscScalar** valuesCell,
-		      PetscInt* valuesSize,
-		      const PetscInt cell) const;
-
-  /** Set values associated with closure.
-   *
-   * @param valuesCell Array of values for cell.
-   * @param valuesSize Size of values array.
-   * @param cell Finite-element cell.
-   * @param mode Mode for inserting values.
-   */
-  void setClosure(const PetscScalar* valuesCell,
-		  const PetscInt valuesSize,
-		  const PetscInt cell,
-		  const InsertMode mode) const;
-
-// PRIVATE MEMBERS //////////////////////////////////////////////////////
-private :
-
-  const Field<Mesh>& _field;
-
-  PetscDM _dm; ///< Cached PETSc dm for mesh.
-  PetscVec _localVec; ///< Cached local PETSc Vec.
-  PetscSection _section; ///< Cached PETSc subsection.
-  PetscScalar* _localArray; ///< Cached local array
-
-// NOT IMPLEMENTED //////////////////////////////////////////////////////
-private :
-
-  SubMeshVisitor(const SubMeshVisitor&); ///< Not implemented
-  const SubMeshVisitor& operator=(const SubMeshVisitor&); ///< Not implemented
-
-}; // SubMeshVisitor
-
-
-// SubMeshIS ------------------------------------------------------------
-/// Index set associated with submesh.
-class pylith::topology::SubMeshIS
-{ // SubMeshIS
-  friend class TestSubMeshIS; // unit testing
-
-// PUBLIC METHODS ///////////////////////////////////////////////////////
-public :
-
-  /** Default constructor.
-   * 
-   * @param submesh Submesh associated with index set.
-   */
-  SubMeshIS(const SubMesh& submesh);
-
-  /// Default destructor.
-  ~SubMeshIS(void);
-
-  /// Deallocate.
-  void deallocate(void);
-
-  /** Get the submesh.
-   *
-   * @returns Submesh.
-   */
-  const SubMesh& submesh(void) const;
-
-  /** Get PETSc index set.
-   *
-   * @returns PETSc index set.
-   */
-  PetscIS indexSet(void) const;
-
-// PRIVATE MEMBERS //////////////////////////////////////////////////////
-private :
-
-  const SubMesh& _submesh;
-  PetscIS _indexSet; ///< PETSc index set.
-
-}; // SubMeshIS
-
-
-#include "SubMeshVisitor.icc"
-
-#endif // pylith_topology_submeshvisitor_hh
-
-
-// End of file

Deleted: short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.icc	2013-03-12 20:39:31 UTC (rev 21513)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.icc	2013-03-12 23:04:09 UTC (rev 21514)
@@ -1,197 +0,0 @@
-// -*- 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-2011 University of California, Davis
-//
-// See COPYING for license information.
-//
-// ======================================================================
-//
-
-#if !defined(pylith_topology_submeshvisitor_hh)
-#error "SubMeshVisitor.icc must be included only from SubMeshVisitor.hh"
-#else
-
-#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
-
-// ----------------------------------------------------------------------
-// Default constructor.
-inline
-pylith::topology::SubMeshVisitor::SubMeshVisitor(const Field<Mesh>& field,
-						 const SubMeshIS& submeshIS) :
-  _field(field),
-  _dm(NULL),
-  _section(NULL),
-  _localVec(NULL),
-  _localArray(NULL)
-{ // constructor
-  initialize(submeshIS);
-} // constructor
-
-// ----------------------------------------------------------------------
-// Default destructor
-inline
-pylith::topology::SubMeshVisitor::~SubMeshVisitor(void)
-{ // destructor
-  clear();
-} // destructor
-
-// ----------------------------------------------------------------------
-// Initialized cached data members.
-inline
-void
-pylith::topology::SubMeshVisitor::initialize(const SubMeshIS& submeshIS)
-{ // initialize
-  _dm = submeshIS.submesh().dmMesh();assert(_dm);
-
-  _localVec = _field.localVector();assert(_localVec);
-
-  PetscErrorCode err;
-  PetscSection section = _field.petscSection();assert(section);
-  const PetscIS subpointIS = submeshIS.indexSet();assert(subpointIS);
-  err = PetscSectionCreateSubmeshSection(section, subpointIS, &_section);CHECK_PETSC_ERROR(err);assert(_section);
-  err = VecGetArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);assert(_localArray);
-} // initialize
-
-// ----------------------------------------------------------------------
-// Default destructor
-inline
-void
-pylith::topology::SubMeshVisitor::clear(void)
-{ // clear
-  assert(_localVec);
-  PetscErrorCode err = VecRestoreArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);assert(!_localArray);
-
-  err = PetscSectionDestroy(&_section);assert(!_section);
-
-  _dm = NULL;
-  _localVec = NULL;
-} // clear
-
-// ----------------------------------------------------------------------
-// Get the local coordinates array associated with the local PETSc Vec.
-inline
-PetscScalar*
-pylith::topology::SubMeshVisitor::localArray(void) const
-{ // localArray
-  return _localArray;
-} // localArray
-
-// ----------------------------------------------------------------------
-// Get fiber dimension of coordinates for point.
-inline
-PetscInt
-pylith::topology::SubMeshVisitor::sectionDof(const PetscInt point) const
-{ // sectionDof
-  assert(_section);
-  PetscInt dof;
-  PetscErrorCode err = PetscSectionGetDof(_section, point, &dof);CHECK_PETSC_ERROR(err);
-  return dof;
-} // sectionDof
-
-// ----------------------------------------------------------------------
-// Get offset into coordinates array for point.
-inline
-PetscInt
-pylith::topology::SubMeshVisitor::sectionOffset(const PetscInt point) const
-{ // sectionOffset
-  assert(_section);
-  PetscInt offset;
-  PetscErrorCode err = PetscSectionGetOffset(_section, point, &offset);CHECK_PETSC_ERROR(err);
-  return offset;
-} // sectionOffset
-
-// ----------------------------------------------------------------------
-// Get coordinates array associated with closure.
-void
-pylith::topology::SubMeshVisitor::getClosure(PetscScalar** valuesCell,
-					     PetscInt* valuesSize,
-					     const PetscInt cell) const
-{ // getClosure
-  assert(_dm);
-  assert(_section);
-  assert(_localVec);
-  PetscErrorCode err = DMPlexVecGetClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
-} // getClosure
-
-// ----------------------------------------------------------------------
-// Restore coordinates array associated with closure.
-void
-pylith::topology::SubMeshVisitor::restoreClosure(PetscScalar** valuesCell,
-						 PetscInt* valuesSize,
-						 const PetscInt cell) const
-{ // restoreClosure
-  assert(_dm);
-  assert(_section);
-  assert(_localVec);
-  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
-} // restoreClosure
-
-// ----------------------------------------------------------------------
-// Set values associated with closure.
-void
-pylith::topology::SubMeshVisitor::setClosure(const PetscScalar* valuesCell,
-					     const PetscInt valuesSize,
-					     const PetscInt cell,
-					     const InsertMode mode) const
-{ // setClosure
-  assert(_dm);
-  assert(_section);
-  assert(_localVec);
-  PetscErrorCode err = DMPlexVecSetClosure(_dm, _section, _localVec, cell, valuesCell, mode);CHECK_PETSC_ERROR(err);
-} // setClosure
-
-// ----------------------------------------------------------------------
-// Default constructor.
-pylith::topology::SubMeshIS::SubMeshIS(const SubMesh& submesh) :
-  _submesh(submesh),
-  _indexSet(NULL)
-{ // constructor
-  PetscDM dmMesh = submesh.dmMesh();assert(dmMesh);
-  PetscErrorCode err = DMPlexCreateSubpointIS(dmMesh, &_indexSet);CHECK_PETSC_ERROR(err);
-} // constructor
-
-// ----------------------------------------------------------------------
-// Default destructor.
-pylith::topology::SubMeshIS::~SubMeshIS(void)
-{ // destructor
-  deallocate();
-} // destructor
-
-// ----------------------------------------------------------------------
-// Deallocate.
-void
-pylith::topology::SubMeshIS::deallocate(void)
-{ // deallocate
-  PetscErrorCode err = ISDestroy(&_indexSet);CHECK_PETSC_ERROR(err);assert(!_indexSet);
-} // deallocate
-
-// ----------------------------------------------------------------------
-// Get the submesh.
-const pylith::topology::SubMesh&
-pylith::topology::SubMeshIS::submesh(void) const
-{ // submesh
-  return _submesh;
-} // submesh
-
-// ----------------------------------------------------------------------
-// Get PETSc index set.
-PetscIS
-pylith::topology::SubMeshIS::indexSet(void) const
-{ // indexSet
-  return _indexSet;
-} // indexSet
-
-
-#endif
-
-
-// End of file

Copied: short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.hh (from rev 21509, short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.hh)
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.hh	2013-03-12 23:04:09 UTC (rev 21514)
@@ -0,0 +1,241 @@
+// -*- 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-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+/**
+ * @file libsrc/topology/VisitorMesh.hh
+ *
+ * @brief C++ helper class for accessing field and matrix values at
+ * points in a finite-element mesh.
+ */
+
+#if !defined(pylith_topology_visitormesh_hh)
+#define pylith_topology_visitormesh_hh
+
+// Include directives ---------------------------------------------------
+#include "topologyfwd.hh" // forward declarations
+
+#include "pylith/utils/petscfwd.h" // HASA PetscVec, PetscSection
+
+#include <petscdmmesh.hh>
+
+// VecVisitorMesh ----------------------------------------------------------
+/** @brief Helper class for accessing field values at points in a
+ *  finite-element mesh.
+ */
+class pylith::topology::VecVisitorMesh
+{ // VecVisitorMesh
+  friend class TestVecVisitorMesh; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Constructor with field over a mesh.
+   *
+   * @param field Field over a mesh.
+   */
+  VecVisitorMesh(const Field<Mesh>& field);
+
+  /** Constructor with field over a submesh.
+   *
+   * @param field Field over a submesh.
+   */
+  VecVisitorMesh(const Field<SubMesh>& field);
+
+  /// Default destructor
+  ~VecVisitorMesh(void);
+
+  /** Initialize using field over a mesh or submesh.
+   *
+   * @param field Field over a mesh/submesh.
+   */
+  template<typename field_type>
+  void initialize(const field_type& field);
+
+  /// Clear cached data.
+  void clear(void);
+  
+  /** Get the array of values associated with the local PETSc Vec.
+   * 
+   * @returns Array of values.
+   */
+  PetscScalar* localArray(void) const;
+
+  /** Get the PETSc section.
+   * 
+   * @returns PETSc section.
+   */
+  PetscSection petscSection(void) const;
+
+  /** Get the local PETSc Vec.
+   * 
+   * @returns PETSc Vec.
+   */
+  PetscVec localVec(void) const;
+
+  /** Get fiber dimension of coordinates for point.
+   *
+   * @param point Point in mesh.
+   * @returns Fiber dimension.
+   */
+  PetscInt sectionDof(const PetscInt point) const;
+
+  /** Get offset into coordinates array for point.
+   *
+   * @param point Point in mesh.
+   * @returns Offset.
+   */
+  PetscInt sectionOffset(const PetscInt point) const;
+
+  /** Get array of values associated with closure.
+   *
+   * @pre Must be followed by call to getClosure().
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void getClosure(PetscScalar** valuesCell,
+		  PetscInt* valuesSize,
+		  const PetscInt cell) const;
+
+  /** Restore array of values associated with closure.
+   *
+   * @pre Must be preceded by call to getClosure().
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void restoreClosure(PetscScalar** valuesCell,
+		      PetscInt* valuesSize,
+		      const PetscInt cell) const;
+
+  /** Set values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   * @param mode Mode for inserting values.
+   */
+  void setClosure(const PetscScalar* valuesCell,
+		  const PetscInt valuesSize,
+		  const PetscInt cell,
+		  const InsertMode mode) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  PetscDM _dm; ///< Cached PETSc dm for mesh.
+  PetscVec _localVec; ///< Cached local PETSc Vec.
+  PetscSection _section; ///< Cached PETSc section.
+  PetscScalar* _localArray; ///< Cached local array
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  VecVisitorMesh(const VecVisitorMesh&); ///< Not implemented
+  const VecVisitorMesh& operator=(const VecVisitorMesh&); ///< Not implemented
+
+}; // VecVisitorMesh
+
+
+// MatVisitorMesh ----------------------------------------------------------
+/** @brief Helper class for accessing field values at points in a
+ *  finite-element mesh.
+ */
+class pylith::topology::MatVisitorMesh
+{ // MatVisitorMesh
+  friend class TestMatVisitorMesh; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param mat PETSc matrix.
+   * @param field Field associated with matrix layout.
+   */
+  MatVisitorMesh(const PetscMat& mat,
+		 const Field<Mesh>& field);
+
+  /// Default destructor
+  ~MatVisitorMesh(void);
+
+  // Initialize.
+  void initialize(void);
+
+  /// Clear cached data.
+  void clear(void);
+  
+  /** Get array of values associated with closure.
+   *
+   * @pre Must be followed by call to getClosure().
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void getClosure(PetscScalar** valuesCell,
+		  PetscInt* valuesSize,
+		  const PetscInt cell) const;
+
+  /** Restore array of values associated with closure.
+   *
+   * @pre Must be preceded by call to getClosure().
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void restoreClosure(PetscScalar** valuesCell,
+		      PetscInt* valuesSize,
+		      const PetscInt cell) const;
+
+  /** Set values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   * @param mode Mode for inserting values.
+   */
+  void setClosure(const PetscScalar* valuesCell,
+		  const PetscInt valuesSize,
+		  const PetscInt cell,
+		  const InsertMode mode) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  const PetscMat _mat; ///< Cached PETSc matrix.
+  PetscDM _dm; ///< Cached PETSc dm for mesh.
+  PetscSection _section; ///< Cached PETSc section.
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  MatVisitorMesh(const MatVisitorMesh&); ///< Not implemented
+  const MatVisitorMesh& operator=(const MatVisitorMesh&); ///< Not implemented
+
+}; // MatVisitorMesh
+
+#include "VisitorMesh.icc"
+
+#endif // pylith_topology_visitormesh_hh
+
+
+// End of file

Copied: short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.icc (from rev 21509, short/3D/PyLith/trunk/libsrc/pylith/topology/MeshVisitor.icc)
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.icc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorMesh.icc	2013-03-12 23:04:09 UTC (rev 21514)
@@ -0,0 +1,257 @@
+// -*- 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-2011 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+#if !defined(pylith_topology_visitormesh_hh)
+#error "VisitorMesh.icc must be included only from VisitorMesh.hh"
+#else
+
+#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
+
+// ----------------------------------------------------------------------
+// Constructor with field over a mesh.
+inline
+pylith::topology::VecVisitorMesh::VecVisitorMesh(const Field<Mesh>& field)
+{ // constructor
+  initialize<Field<Mesh> >(field);
+} // constructor
+
+// ----------------------------------------------------------------------
+// Constructor with field over a submesh.
+inline
+pylith::topology::VecVisitorMesh::VecVisitorMesh(const Field<SubMesh>& field)
+{ // constructor
+  initialize<Field<SubMesh> >(field);
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+pylith::topology::VecVisitorMesh::~VecVisitorMesh(void)
+{ // destructor
+  clear();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Initialized cached data members.
+template<typename field_type>
+inline
+void
+pylith::topology::VecVisitorMesh::initialize(const field_type& field)
+{ // initialize
+  _dm = field.mesh().dmMesh();assert(_dm);
+  _section = field.petscSection();assert(_section);
+  _localVec = field.localVector();assert(_localVec);
+
+  PetscErrorCode err = VecGetArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);
+} // initialize
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+void
+pylith::topology::VecVisitorMesh::clear(void)
+{ // clear
+  assert(_localVec);
+  PetscErrorCode err = VecRestoreArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);
+  assert(!_localArray);
+
+  _dm = NULL;
+  _section = NULL;
+  _localVec = NULL;
+} // clear
+
+// ----------------------------------------------------------------------
+// Get the local coordinates array associated with the local PETSc Vec.
+inline
+PetscScalar*
+pylith::topology::VecVisitorMesh::localArray(void) const
+{ // localArray
+  return _localArray;
+} // localArray
+
+// ----------------------------------------------------------------------
+// Get fiber dimension of coordinates for point.
+inline
+PetscInt
+pylith::topology::VecVisitorMesh::sectionDof(const PetscInt point) const
+{ // sectionDof
+  assert(_section);
+  PetscInt dof;
+  PetscErrorCode err = PetscSectionGetDof(_section, point, &dof);CHECK_PETSC_ERROR(err);
+  return dof;
+} // sectionDof
+
+// ----------------------------------------------------------------------
+// Get offset into coordinates array for point.
+inline
+PetscInt
+pylith::topology::VecVisitorMesh::sectionOffset(const PetscInt point) const
+{ // sectionOffset
+  assert(_section);
+  PetscInt offset;
+  PetscErrorCode err = PetscSectionGetOffset(_section, point, &offset);CHECK_PETSC_ERROR(err);
+  return offset;
+} // sectionOffset
+
+// ----------------------------------------------------------------------
+// Get coordinates array associated with closure.
+inline
+void
+pylith::topology::VecVisitorMesh::getClosure(PetscScalar** valuesCell,
+					     PetscInt* valuesSize,
+					     const PetscInt cell) const
+{ // getClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecGetClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+} // getClosure
+
+// ----------------------------------------------------------------------
+// Restore coordinates array associated with closure.
+inline
+void
+pylith::topology::VecVisitorMesh::restoreClosure(PetscScalar** valuesCell,
+						 PetscInt* valuesSize,
+						 const PetscInt cell) const
+{ // restoreClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+} // restoreClosure
+
+// ----------------------------------------------------------------------
+// Set values associated with closure.
+inline
+void
+pylith::topology::VecVisitorMesh::setClosure(const PetscScalar* valuesCell,
+					     const PetscInt valuesSize,
+					     const PetscInt cell,
+					     const InsertMode mode) const
+{ // setClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecSetClosure(_dm, _section, _localVec, cell, valuesCell, mode);CHECK_PETSC_ERROR(err);
+} // setClosure
+
+// ----------------------------------------------------------------------
+// Default constructor.
+inline
+pylith::topology::MatVisitorMesh::MatVisitorMesh(const PetscMat mat,
+						 const Field<Mesh>& field) :
+  _mat(mat),
+  _dm(NULL),
+  _section(NULL)
+{ // constructor
+  _dm = field.mesh().dmMesh();assert(_dm);
+  _section = field.petscSection();assert(_section);
+
+  initialize();
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+pylith::topology::MatVisitorMesh::~MatVisitorMesh(void)
+{ // destructor
+  clear();
+
+  _dm = NULL;
+  _mat = NULL;
+  _section = NULL;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Initialized cached data members.
+inline
+void
+pylith::topology::MatVisitorMesh::initialize(void)
+{ // initialize
+} // initialize
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+void
+pylith::topology::MatVisitorMesh::clear(void)
+{ // clear
+} // clear
+
+// ----------------------------------------------------------------------
+// Get coordinates array associated with closure.
+inline
+void
+pylith::topology::MatVisitorMesh::getClosure(PetscScalar** valuesCell,
+					     PetscInt* valuesSize,
+					     const PetscInt cell) const
+{ // getClosure
+#if 0 // NOT IMPLEMENTED
+  assert(_dm);
+  assert(_mat);
+  assert(_section);
+  PetscErrorCode err = DMPlexMatGetClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+#else
+  assert(false);
+#endif
+} // getClosure
+
+// ----------------------------------------------------------------------
+/** Restore coordinates array associated with closure.
+ *
+ * @param coordsCell Array of coordinates for cell.
+ * @param coordsSize Size of coordinates array.
+ * @param cell Finite-element cell.
+ */
+inline
+void
+pylith::topology::MatVisitorMesh::restoreClosure(PetscScalar** valuesCell,
+						 PetscInt* valuesSize,
+						 const PetscInt cell) const
+{ // restoreClosure
+  assert(_dm);
+  assert(_mat);
+  assert(_section);
+#if 0 // NOT IMPLEMENTED
+  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+#else
+  assert(false);
+#endif
+} // restoreClosure
+
+// ----------------------------------------------------------------------
+// Set values associated with closure.
+inline
+void
+pylith::topology::MatVisitorMesh::setClosure(const PetscScalar* valuesCell,
+					     const PetscInt valuesSize,
+					     const PetscInt cell,
+					     const InsertMode mode) const
+{ // setClosure
+  assert(_dm);
+  assert(_mat);
+  assert(_section);
+  PetscErrorCode err = DMPlexMatSetClosure(_dm, _section, NULL, _mat, cell, valuesCell, mode);CHECK_PETSC_ERROR(err);
+} // setClosure
+
+
+#endif
+
+
+// End of file

Copied: short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.hh (from rev 21509, short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.hh)
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.hh	2013-03-12 23:04:09 UTC (rev 21514)
@@ -0,0 +1,284 @@
+// -*- 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-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+/**
+ * @file libsrc/topology/VisitorSubMesh.hh
+ *
+ * @brief C++ helper class for accessing field and matrix values at
+ * points in a submesh within a finite-element mesh.
+ *
+ * This visitor is used to access values associated with a submesh
+ * when the field or matrix is defined over the entire mesh. This is
+ * why a submesh and index set are passed to the constructor.
+ *
+ * Use the Vec/MatVisitorMesh objects when the field and mesh/submesh
+ * are defined over the same set of points (i.e., field over a submesh
+ * or field of a mesh).
+ */
+
+#if !defined(pylith_topology_visitorsubmesh_hh)
+#define pylith_topology_visitorsubmesh_hh
+
+// Include directives ---------------------------------------------------
+#include "topologyfwd.hh" // forward declarations
+
+#include "pylith/utils/petscfwd.h" // HASA PetscVec, PetscSection
+
+#include <petscdmmesh.hh>
+
+// VecVisitorSubMesh -------------------------------------------------------
+/** @brief Helper class for accessing field values at points in a
+ *  finite-element mesh.
+ */
+class pylith::topology::VecVisitorSubMesh
+{ // VecVisitorSubMesh
+  friend class TestVecVisitorSubMesh; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param field Field associated with visitor.
+   * @param submeshIS Submesh index set associated with visitor.
+   */
+  VecVisitorSubMesh(const Field<Mesh>& field,
+		    const SubMeshIS& submeshIS);
+
+  /// Default destructor
+  ~VecVisitorSubMesh(void);
+
+  /* Initialize cached data.
+   *
+   * @param submeshIS Submesh index set associated with visitor.
+   */
+  void initialize(const SubMeshIS& submeshIS);
+
+  /// Clear cached data.
+  void clear(void);
+  
+  /** Get the array of values associated with the local PETSc Vec.
+   * 
+   * @returns Array of values.
+   */
+  PetscScalar* localArray(void) const;
+
+  /** Get the PETSc section.
+   * 
+   * @returns PETSc section.
+   */
+  PetscSection petscSection(void) const;
+
+  /** Get the local PETSc Vec.
+   * 
+   * @returns PETSc Vec.
+   */
+  PetscVec localVec(void) const;
+
+  /** Get fiber dimension of coordinates for point.
+   *
+   * @param point Point in mesh.
+   * @returns Fiber dimension.
+   */
+  PetscInt sectionDof(const PetscInt point) const;
+
+  /** Get offset into coordinates array for point.
+   *
+   * @param point Point in mesh.
+   * @returns Offset.
+   */
+  PetscInt sectionOffset(const PetscInt point) const;
+
+  /** Get array of values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void getClosure(PetscScalar** valuesCell,
+		  PetscInt* valuesSize,
+		  const PetscInt cell) const;
+
+  /** Restore array of values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void restoreClosure(PetscScalar** valuesCell,
+		      PetscInt* valuesSize,
+		      const PetscInt cell) const;
+
+  /** Set values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   * @param mode Mode for inserting values.
+   */
+  void setClosure(const PetscScalar* valuesCell,
+		  const PetscInt valuesSize,
+		  const PetscInt cell,
+		  const InsertMode mode) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  const Field<Mesh>& _field;
+
+  PetscDM _dm; ///< Cached PETSc dm for submesh.
+  PetscVec _localVec; ///< Cached local PETSc Vec.
+  PetscSection _section; ///< Cached PETSc subsection.
+  PetscScalar* _localArray; ///< Cached local array
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  VecVisitorSubMesh(const VecVisitorSubMesh&); ///< Not implemented
+  const VecVisitorSubMesh& operator=(const VecVisitorSubMesh&); ///< Not implemented
+
+}; // VecVisitorSubMesh
+
+
+// MatVisitorSubMesh -------------------------------------------------------
+/** @brief Helper class for accessing field values at points in a
+ *  finite-element mesh.
+ */
+class pylith::topology::MatVisitorSubMesh
+{ // MatVisitorSubMesh
+  friend class TestMatVisitorSubMesh; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param mat PETSc matrix.
+   * @param field Field associated with visitor.
+   * @param submeshIS Submesh index set associated with visitor.
+   */
+  MatVisitorSubMesh(const PetscMat mat,
+		    const Field<Mesh>& field,
+		    const SubMeshIS& submeshIS);
+
+  /// Default destructor
+  ~MatVisitorSubMesh(void);
+
+  // Initialize.
+  void initialize(void);
+
+  /// Clear cached data.
+  void clear(void);
+  
+  /** Get array of values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void getClosure(PetscScalar** valuesCell,
+		  PetscInt* valuesSize,
+		  const PetscInt cell) const;
+
+  /** Restore array of values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   */
+  void restoreClosure(PetscScalar** valuesCell,
+		      PetscInt* valuesSize,
+		      const PetscInt cell) const;
+
+  /** Set values associated with closure.
+   *
+   * @param valuesCell Array of values for cell.
+   * @param valuesSize Size of values array.
+   * @param cell Finite-element cell.
+   * @param mode Mode for inserting values.
+   */
+  void setClosure(const PetscScalar* valuesCell,
+		  const PetscInt valuesSize,
+		  const PetscInt cell,
+		  const InsertMode mode) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  const PetscMat _mat; ///< Cached PETSc matrix.
+  PetscDM _dm; ///< Cached PETSc dm for mesh.
+  PetscSection _subsection; ///< Cached PETSc section for submesh.
+  PetscSection _globalSection; ///< Cached PETSc global section.
+  PetscSection _globalSubsection; ///< Cached PETSc subsection.
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  MatVisitorSubMesh(const MatVisitorSubMesh&); ///< Not implemented
+  const MatVisitorSubMesh& operator=(const MatVisitorSubMesh&); ///< Not implemented
+
+}; // MatVisitorSubMesh
+
+// SubMeshIS ------------------------------------------------------------
+/// Index set associated with submesh.
+class pylith::topology::SubMeshIS
+{ // SubMeshIS
+  friend class TestSubMeshIS; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   * 
+   * @param submesh Submesh associated with index set.
+   */
+  SubMeshIS(const SubMesh& submesh);
+
+  /// Default destructor.
+  ~SubMeshIS(void);
+
+  /// Deallocate.
+  void deallocate(void);
+
+  /** Get the submesh.
+   *
+   * @returns Submesh.
+   */
+  const SubMesh& submesh(void) const;
+
+  /** Get PETSc index set.
+   *
+   * @returns PETSc index set.
+   */
+  PetscIS indexSet(void) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  const SubMesh& _submesh;
+  PetscIS _indexSet; ///< PETSc index set.
+
+}; // SubMeshIS
+
+
+#include "VisitorSubMesh.icc"
+
+#endif // pylith_topology_visitorsubmesh_hh
+
+
+// End of file

Copied: short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.icc (from rev 21509, short/3D/PyLith/trunk/libsrc/pylith/topology/SubMeshVisitor.icc)
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.icc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/VisitorSubMesh.icc	2013-03-12 23:04:09 UTC (rev 21514)
@@ -0,0 +1,310 @@
+// -*- 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-2011 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+#if !defined(pylith_topology_vecvisitorsubmesh_hh)
+#error "VecVisitorSubMesh.icc must be included only from VecVisitorSubMesh.hh"
+#else
+
+#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
+
+// ----------------------------------------------------------------------
+// Default constructor.
+inline
+pylith::topology::VecVisitorSubMesh::VecVisitorSubMesh(const Field<Mesh>& field,
+						       const SubMeshIS& submeshIS) :
+  _field(field),
+  _dm(NULL),
+  _section(NULL),
+  _localVec(NULL),
+  _localArray(NULL)
+{ // constructor
+  initialize(submeshIS);
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+pylith::topology::VecVisitorSubMesh::~VecVisitorSubMesh(void)
+{ // destructor
+  clear();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Initialized cached data members.
+inline
+void
+pylith::topology::VecVisitorSubMesh::initialize(const SubMeshIS& submeshIS)
+{ // initialize
+  _dm = submeshIS.submesh().dmMesh();assert(_dm);
+
+  _localVec = _field.localVector();assert(_localVec);
+
+  PetscErrorCode err;
+  PetscSection section = _field.petscSection();assert(section);
+  const PetscIS subpointIS = submeshIS.indexSet();assert(subpointIS);
+  err = PetscSectionCreateSubmeshSection(section, subpointIS, &_section);CHECK_PETSC_ERROR(err);assert(_section);
+  err = VecGetArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);assert(_localArray);
+} // initialize
+
+// ----------------------------------------------------------------------
+// Clear cached data members.
+inline
+void
+pylith::topology::VecVisitorSubMesh::clear(void)
+{ // clear
+  assert(_localVec);
+  PetscErrorCode err = VecRestoreArray(_localVec, &_localArray);CHECK_PETSC_ERROR(err);assert(!_localArray);
+
+  err = PetscSectionDestroy(&_section);assert(!_section);
+
+  _dm = NULL;
+  _localVec = NULL;
+} // clear
+
+// ----------------------------------------------------------------------
+// Get the local coordinates array associated with the local PETSc Vec.
+inline
+PetscScalar*
+pylith::topology::VecVisitorSubMesh::localArray(void) const
+{ // localArray
+  return _localArray;
+} // localArray
+
+// ----------------------------------------------------------------------
+// Get fiber dimension of coordinates for point.
+inline
+PetscInt
+pylith::topology::VecVisitorSubMesh::sectionDof(const PetscInt point) const
+{ // sectionDof
+  assert(_section);
+  PetscInt dof;
+  PetscErrorCode err = PetscSectionGetDof(_section, point, &dof);CHECK_PETSC_ERROR(err);
+  return dof;
+} // sectionDof
+
+// ----------------------------------------------------------------------
+// Get offset into coordinates array for point.
+inline
+PetscInt
+pylith::topology::VecVisitorSubMesh::sectionOffset(const PetscInt point) const
+{ // sectionOffset
+  assert(_section);
+  PetscInt offset;
+  PetscErrorCode err = PetscSectionGetOffset(_section, point, &offset);CHECK_PETSC_ERROR(err);
+  return offset;
+} // sectionOffset
+
+// ----------------------------------------------------------------------
+// Get coordinates array associated with closure.
+inline
+void
+pylith::topology::VecVisitorSubMesh::getClosure(PetscScalar** valuesCell,
+						PetscInt* valuesSize,
+						const PetscInt cell) const
+{ // getClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecGetClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+} // getClosure
+
+// ----------------------------------------------------------------------
+// Restore coordinates array associated with closure.
+inline
+void
+pylith::topology::VecVisitorSubMesh::restoreClosure(PetscScalar** valuesCell,
+						    PetscInt* valuesSize,
+						    const PetscInt cell) const
+{ // restoreClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+} // restoreClosure
+
+// ----------------------------------------------------------------------
+// Set values associated with closure.
+inline
+void
+pylith::topology::VecVisitorSubMesh::setClosure(const PetscScalar* valuesCell,
+						const PetscInt valuesSize,
+						const PetscInt cell,
+						const InsertMode mode) const
+{ // setClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecSetClosure(_dm, _section, _localVec, cell, valuesCell, mode);CHECK_PETSC_ERROR(err);
+} // setClosure
+
+// ----------------------------------------------------------------------
+// Default constructor.
+inline
+pylith::topology::MatVisitorSubMesh::MatVisitorSubMesh(const PetscMat mat,
+						       const Field<Mesh>& field,
+						       const SubMeshIS& submeshIS) :
+  _mat(mat),
+  _dm(NULL),
+  _section(NULL),
+  _globalSection(NULL),
+  _globalSubsection(NULL)
+{ // constructor
+  _dm = submeshIS.submesh().dmMesh();assert(_dm);
+  _section = field.petscSection();assert(_section);
+
+  PetscIS subpointIS = submeshIS.indexSet();
+  PetscSF sf = NULL;
+  PetscSection section = NULL;
+
+  PetscErrorCode err;
+  err = PetscSectionCreateSubmeshSection(section, subpointIS, &_subsection);CHECK_PETSC_ERROR(err);assert(_subsection);
+  err = DMGetPointSF(_dm, &sf);CHECK_PETSC_ERROR(err);assert(sf);
+  err = PetscSectionCreateGlobalSection(section, sf, PETSC_FALSE, &_globalSection);CHECK_PETSC_ERROR(err);assert(_globalSection);
+  err = PetscSectionCreateSubmeshSection(_globalSection, subpointIS, &_globalSubsection);CHECK_PETSC_ERROR(err);assert(_globalSubsection);
+
+  initialize();
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+pylith::topology::MatVisitorSubMesh::~MatVisitorSubMesh(void)
+{ // destructor
+  clear();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Initialized cached data members.
+inline
+void
+pylith::topology::MatVisitorSubMesh::initialize(const SubMeshIS& submeshIS)
+{ // initialize
+} // initialize
+
+// ----------------------------------------------------------------------
+// Default destructor
+inline
+void
+pylith::topology::MatVisitorSubMesh::clear(void)
+{ // clear
+} // clear
+
+// ----------------------------------------------------------------------
+// Get coordinates array associated with closure.
+inline
+void
+pylith::topology::MatVisitorSubMesh::getClosure(PetscScalar** valuesCell,
+					     PetscInt* valuesSize,
+					     const PetscInt cell) const
+{ // getClosure
+  assert(_dm);
+  assert(_subsection);
+  assert(_globalSection);
+  assert(_globalSubsection);
+#if 0 // NOT IMPLEMENTED
+  PetscErrorCode err = DMPlexVecGetClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+#else
+  assert(false);
+#endif
+} // getClosure
+
+// ----------------------------------------------------------------------
+// Restore coordinates array associated with closure.
+inline
+void
+pylith::topology::MatVisitorSubMesh::restoreClosure(PetscScalar** valuesCell,
+						    PetscInt* valuesSize,
+						    const PetscInt cell) const
+{ // restoreClosure
+  assert(_dm);
+  assert(_subsection);
+  assert(_globalSection);
+  assert(_globalSubsection);
+#if 0 // NOT IMPLEMENTED
+  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, valuesSize, valuesCell);CHECK_PETSC_ERROR(err);
+#else
+  assert(false);
+#endif
+} // restoreClosure
+
+// ----------------------------------------------------------------------
+// Set values associated with closure.
+inline
+void
+pylith::topology::MatVisitorSubMesh::setClosure(const PetscScalar* valuesCell,
+						const PetscInt valuesSize,
+						const PetscInt cell,
+						const InsertMode mode) const
+{ // setClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  err = DMPlexMatSetClosure(_dm, _subsection, _globalSubsection, _mat, cell, valuesCell, ADD_VALUES);CHECK_PETSC_ERROR(err);
+} // setClosure
+
+// ----------------------------------------------------------------------
+// Default constructor.
+inline
+pylith::topology::SubMeshIS::SubMeshIS(const SubMesh& submesh) :
+  _submesh(submesh),
+  _indexSet(NULL)
+{ // constructor
+  PetscDM dmMesh = submesh.dmMesh();assert(dmMesh);
+  PetscErrorCode err = DMPlexCreateSubpointIS(dmMesh, &_indexSet);CHECK_PETSC_ERROR(err);
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor.
+inline
+pylith::topology::SubMeshIS::~SubMeshIS(void)
+{ // destructor
+  deallocate();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Deallocate.
+inline
+void
+pylith::topology::SubMeshIS::deallocate(void)
+{ // deallocate
+  PetscErrorCode err = ISDestroy(&_indexSet);CHECK_PETSC_ERROR(err);assert(!_indexSet);
+} // deallocate
+
+// ----------------------------------------------------------------------
+// Get the submesh.
+inline
+const pylith::topology::SubMesh&
+pylith::topology::SubMeshIS::submesh(void) const
+{ // submesh
+  return _submesh;
+} // submesh
+
+// ----------------------------------------------------------------------
+// Get PETSc index set.
+inline
+PetscIS
+pylith::topology::SubMeshIS::indexSet(void) const
+{ // indexSet
+  return _indexSet;
+} // indexSet
+
+
+#endif
+
+
+// End of file



More information about the CIG-COMMITS mailing list