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

brad at geodynamics.org brad at geodynamics.org
Sat Mar 9 12:25:31 PST 2013


Author: brad
Date: 2013-03-09 12:25:31 -0800 (Sat, 09 Mar 2013)
New Revision: 21480

Modified:
   short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc
Log:
Added more helper functions to Field to streamline code.

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh	2013-03-09 01:15:50 UTC (rev 21479)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh	2013-03-09 20:25:31 UTC (rev 21480)
@@ -87,24 +87,6 @@
   /// Deallocate PETSc and local data structures.
   void deallocate(void);
   
-  /** Get PetscSection.
-   *
-   * @returns PetscSection.
-   */
-  PetscSection petscSection() const;
-
-  /** Get local Vec.
-   *
-   * @returns local Vec.
-   */
-  Vec localVector() const;
-
-  /** Get global Vec.
-   *
-   * @returns global Vec.
-   */
-  Vec globalVector() const;
-
   /** Get mesh associated with field.
    *
    * @returns Finite-element mesh.
@@ -115,7 +97,7 @@
    *
    * @returns DM
    */
-  DM dmMesh(void) const;
+  PetscDM dmMesh(void) const;
 
   /** Set label for field.
    *
@@ -185,6 +167,54 @@
    */
   int spaceDim(void) const;
 
+  /** Get PetscSection.
+   *
+   * @returns PETSc section.
+   */
+  PetscSection petscSection(void) const;
+
+  /** Get the local PETSc Vec.
+   *
+   * @returns PETSc Vec object.
+   */
+  PetscVec localVector(void) const;
+
+  /** Get the global PETSc Vec.
+   *
+   * @returns PETSc Vec object.
+   */
+  PetscVec globalVector(void) const;
+
+  /** Get the local array associated with the local PETSc Vec.
+   *
+   * Must call restoryArray() afterwards.
+   * 
+   * @returns Local array.
+   */
+  PetscScalar* getLocalArray(void) const;
+
+  /** Restore local 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 for point.
+   *
+   * @param point Point in mesh.
+   * @returns Fiber dimension.
+   */
+  PetscInt sectionDof(const PetscInt point) const;
+
+  /** Get offset into array for point.
+   *
+   * @param point Point in mesh.
+   * @returns Offset.
+   */
+  PetscInt sectionOffset(const PetscInt point) const;
+
   /** Get the number of sieve points in the chart.
    *
    * @returns the chart size.

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc	2013-03-09 01:15:50 UTC (rev 21479)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc	2013-03-09 20:25:31 UTC (rev 21480)
@@ -37,7 +37,7 @@
 // Get local vector.
 template<typename mesh_type>
 inline
-Vec
+PetscVec
 pylith::topology::Field<mesh_type>::localVector(void) const {
   return _localVec;
 }
@@ -45,11 +45,58 @@
 // Get global vector.
 template<typename mesh_type>
 inline
-Vec
+PetscVec
 pylith::topology::Field<mesh_type>::globalVector(void) const {
   return _globalVec;
 }
 
+// Get the local array associated with the local PETSc Vec.
+template<typename mesh_type>
+inline
+PetscScalar*
+pylith::topology::Field<mesh_type>::getLocalArray(void) const
+{ // getLocalArray
+  PetscScalar* localArray = NULL;
+  PetscErrorCode err = VecGetArray(_localVec, &localArray);CHECK_PETSC_ERROR(err);
+  assert((_localVec && localArray) || (!_localVec && !localArray));
+
+  return localArray;
+} // getLocalArray
+
+// Restore local array associated with the local PETSc Vec.
+template<typename mesh_type>
+inline
+void
+pylith::topology::Field<mesh_type>::restoreLocalArray(PetscScalar** localArray) const
+{ // restoreLocalArray
+  PetscErrorCode err = VecRestoreArray(_localVec, localArray);CHECK_PETSC_ERROR(err);
+  assert(!(*localArray));
+} // restoreLocalArray
+
+// Get fiber dimension for point.
+template<typename mesh_type>
+inline
+PetscInt
+pylith::topology::Field<mesh_type>::sectionDof(const PetscInt point) const
+{ // sectionDof
+  const PetscSection& section = petscSection();assert(section);
+  PetscInt dof;
+  PetscErrorCode err = PetscSectionGetDof(section, point, &dof);CHECK_PETSC_ERROR(err);
+  return dof;
+} // sectionDof
+
+// Get offset into array for point.
+template<typename mesh_type>
+inline
+PetscInt
+pylith::topology::Field<mesh_type>::sectionOffset(const PetscInt point) const
+{ // sectionOffset
+  const PetscSection& section = petscSection();assert(section);
+  PetscInt offset;
+  PetscErrorCode err = PetscSectionGetOffset(section, point, &offset);CHECK_PETSC_ERROR(err);
+  return offset;
+} // sectionOffset
+
 // Get mesh associated with field.
 template<typename mesh_type>
 inline
@@ -61,7 +108,7 @@
 
 template<typename mesh_type>
 inline
-DM
+PetscDM
 pylith::topology::Field<mesh_type>::dmMesh(void) const {
   return _dm;
 }



More information about the CIG-COMMITS mailing list