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

brad at geodynamics.org brad at geodynamics.org
Mon Mar 11 15:40:22 PDT 2013


Author: brad
Date: 2013-03-11 15:40:21 -0700 (Mon, 11 Mar 2013)
New Revision: 21503

Added:
   short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.icc
Modified:
   short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am
   short/3D/PyLith/trunk/libsrc/pylith/topology/topologyfwd.hh
Log:
Create Coordinates object with helper functions for accessing coordinates in Mesh or SubMesh.

Added: short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.hh	2013-03-11 22:40:21 UTC (rev 21503)
@@ -0,0 +1,128 @@
+// -*- 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/MeshCoords.hh
+ *
+ * @brief C++ helper class for accessing coordinates in a finite-element mesh.
+ */
+
+#if !defined(pylith_topology_coordinates_hh)
+#define pylith_topology_coordinates_hh
+
+// Include directives ---------------------------------------------------
+#include "topologyfwd.hh" // forward declarations
+
+#include "pylith/utils/petscfwd.h" // HASA PetscVec, PetscSection
+
+#include <petscdmmesh.hh>
+
+// Coordinates ----------------------------------------------------------
+/** @brief Helper class for accessing coordinates in a finite-element mesh.
+ */
+template<typename mesh_type>
+class pylith::topology::Coordinates
+{ // MeshCoords
+  friend class TestCoordinates; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /// Default constructor.
+  Coordinates(const mesh_type& mesh);
+
+  /// Default destructor
+  ~Coordinates(void);
+
+  /** Get the local coordinates array associated with the local PETSc Vec.
+   *
+   * Must call restoreLocalArray() afterwards.
+   * 
+   * @returns Local array.
+   */
+  PetscScalar* getLocalArray(void) const;
+
+  /** Restore local coordinates array associated with the local PETSc Vec.
+   *
+   * @preq Must be preceded by call to getLocalArray().
+   *
+   * @param a Local array.
+   */
+  void restoreLocalArray(PetscScalar** a) const;
+
+  /** Get fiber dimension of coordinates for point.
+   *
+   * @preq Must call cacheSection().
+   *
+   * @param point Point in mesh.
+   * @returns Fiber dimension.
+   */
+  PetscInt sectionDof(const PetscInt point) const;
+
+  /** Get offset into coordinates array for point.
+   *
+   * @preq Must call cacheSection().
+   *
+   * @param point Point in mesh.
+   * @returns Offset.
+   */
+  PetscInt sectionOffset(const PetscInt point) const;
+
+  /** Get coordinates array associated with closure.
+   *
+   * @param coordsCell Array of coordinates for cell.
+   * @param coordsSize Size of coordinates array.
+   * @param cell Finite-element cell.
+   */
+  void getClosure(PetscScalar** coordsCell,
+		  PetscInt* coordsSize,
+		  const PetscInt cell) const;
+
+  /** 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 restoreClosure(PetscScalar** coordsCell,
+		      PetscInt* coordsSize,
+		      const PetscInt cell) const;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  const mesh_type& _mesh;
+
+  PetscDM _dm; ///< Cached PETSc dm for mesh.
+  PetscVec _localVec; ///< Cached local PETSc Vec.
+  PetscSection _section; ///< Cached PETSc section.
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  Coordinates(const Coordinates&); ///< Not implemented
+  const Coordinates& operator=(const Coordinates&); ///< Not implemented
+
+}; // Coordinates
+
+#include "Coordinates.icc"
+
+#endif // pylith_topology_coordinates_hh
+
+
+// End of file

Added: short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.icc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Coordinates.icc	2013-03-11 22:40:21 UTC (rev 21503)
@@ -0,0 +1,137 @@
+// -*- 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_coordinates_hh)
+#error "Mesh.icc must be included only from Coordinates.hh"
+#else
+
+#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
+
+// ----------------------------------------------------------------------
+// Default constructor.
+template<typename mesh_type>
+inline
+pylith::topology::Coordinates<mesh_type>::Coordinates(const mesh_type& mesh) :
+  _mesh(mesh)
+{ // constructor
+  _dm = mesh.dmMesh();assert(_dm);
+  PetscErrorCode err;
+  err = DMPlexGetCoordinateSection(_dm, &_section);CHECK_PETSC_ERROR(err);
+  err = DMGetCoordinatesLocal(_dm, &_localVec);CHECK_PETSC_ERROR(err);
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor
+template<typename mesh_type>
+inline
+pylith::topology::Coordinates<mesh_type>::~Coordinates(void)
+{ // destructor
+  _localVec = NULL;
+  _section = NULL;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Get the local coordinates array associated with the local PETSc Vec.
+template<typename mesh_type>
+inline
+PetscScalar*
+pylith::topology::Coordinates<mesh_type>::getLocalArray(void) const
+{ // getLocalArray
+  assert(_dm);
+  assert(_localVec);
+
+  PetscScalar* coordsArray = NULL;
+  PetscErrorCode err;
+  err = DMGetCoordinatesLocal(_dm, &_localVec);CHECK_PETSC_ERROR(err);
+  err = VecGetArray(_localVec, &coordsArray);CHECK_PETSC_ERROR(err);
+  return coordsArray;
+} // getLocalArray
+
+// ----------------------------------------------------------------------
+// Restore local coordinates array associated with the local PETSc Vec.
+template<typename mesh_type>
+inline
+void
+pylith::topology::Coordinates<mesh_type>::restoreLocalArray(PetscScalar** a) const
+{ // restoreLocalArray
+  PetscErrorCode err = VecRestoreArray(_localVec, a);CHECK_PETSC_ERROR(err);
+} // restoreLocalArray
+
+// ----------------------------------------------------------------------
+// Get fiber dimension of coordinates for point.
+template<typename mesh_type>
+inline
+PetscInt
+pylith::topology::Coordinates<mesh_type>::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.
+template<typename mesh_type>
+inline
+PetscInt
+pylith::topology::Coordinates<mesh_type>::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.
+template<typename mesh_type>
+void
+pylith::topology::Coordinates<mesh_type>::getClosure(PetscScalar** coordsCell,
+						     PetscInt* coordsSize,
+						     const PetscInt cell) const
+{ // getClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecGetClosure(_dm, _section, _localVec, cell, coordsSize, coordsCell);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.
+   */
+template<typename mesh_type>
+void
+pylith::topology::Coordinates<mesh_type>::restoreClosure(PetscScalar** coordsCell,
+							 PetscInt* coordsSize,
+							 const PetscInt cell) const
+{ // restoreClosure
+  assert(_dm);
+  assert(_section);
+  assert(_localVec);
+  PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, coordsSize, coordsCell);CHECK_PETSC_ERROR(err);
+} // restoreClosure
+
+#endif
+
+
+// End of file

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am	2013-03-11 22:17:27 UTC (rev 21502)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am	2013-03-11 22:40:21 UTC (rev 21503)
@@ -20,6 +20,8 @@
 include $(top_srcdir)/subpackage.am
 
 subpkginclude_HEADERS = \
+	Coordinates.hh \
+	Coordinates.icc \
 	Distributor.hh \
 	FieldBase.hh \
 	Field.hh \

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/topologyfwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/topologyfwd.hh	2013-03-11 22:17:27 UTC (rev 21502)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/topologyfwd.hh	2013-03-11 22:40:21 UTC (rev 21503)
@@ -55,6 +55,7 @@
     class Mesh;
     class SubMesh;
     class MeshOps;
+    template<typename mesh_type> class Coordinates;
 
     class FieldBase;
     template<typename mesh_type> class Field;



More information about the CIG-COMMITS mailing list