[cig-commits] r13928 - in short/3D/PyLith/branches/pylith-swig: . libsrc/topology modulesrc modulesrc/mpi modulesrc/topology modulesrc/utils pylith pylith/mpi pylith/topology unittests/libtests/topology unittests/pytests/topology

brad at geodynamics.org brad at geodynamics.org
Thu Jan 22 16:21:22 PST 2009


Author: brad
Date: 2009-01-22 16:21:22 -0800 (Thu, 22 Jan 2009)
New Revision: 13928

Added:
   short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/
   short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/Makefile.am
   short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi_comm.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Mesh.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/topology/topology.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_mat.i
Modified:
   short/3D/PyLith/branches/pylith-swig/configure.ac
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.icc
   short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am
   short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Makefile.am
   short/3D/PyLith/branches/pylith-swig/modulesrc/utils/Makefile.am
   short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i
   short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am
   short/3D/PyLith/branches/pylith-swig/pylith/__init__.py
   short/3D/PyLith/branches/pylith-swig/pylith/mpi/Communicator.py
   short/3D/PyLith/branches/pylith-swig/pylith/topology/Mesh.py
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.hh
   short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/TestMesh.py
   short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/testdriver.py
Log:
Worked on mpi Communicator and Mesh.

Modified: short/3D/PyLith/branches/pylith-swig/configure.ac
===================================================================
--- short/3D/PyLith/branches/pylith-swig/configure.ac	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/configure.ac	2009-01-23 00:21:22 UTC (rev 13928)
@@ -218,6 +218,7 @@
                 modulesrc/feassemble/Makefile
                 modulesrc/materials/Makefile
                 modulesrc/meshio/Makefile
+                modulesrc/mpi/Makefile
                 modulesrc/solver/Makefile
 		modulesrc/topology/Makefile
 		modulesrc/utils/Makefile

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.hh	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.hh	2009-01-23 00:21:22 UTC (rev 13928)
@@ -23,13 +23,14 @@
 #define pylith_topology_mesh_hh
 
 // Include directives ---------------------------------------------------
-#define NEWPYLITHMESH 1
+#define NEWPYLITHMESH 1 
 #include "pylith/utils/sievetypes.hh"
 
 // Forward declarations -------------------------------------------------
 namespace pylith {
   namespace topology {
     class Mesh;
+    class TestMesh; // unit testing
   } // topology
 } // pylith
 
@@ -42,6 +43,7 @@
 // Mesh -----------------------------------------------------------------
 class pylith::topology::Mesh
 { // Mesh
+  friend class TestMesh; // unit testing
 
 // PUBLIC METHODS ///////////////////////////////////////////////////////
 public :
@@ -81,9 +83,39 @@
    */
   const spatialdata::geocoords::CoordSys* coordsys(void) const;
 
+  /** Set debug flag.
+   *
+   * @param value Turn on debugging if true.
+   */
+   void debug(const bool value);
+
+  /** Get debug flag.
+   *
+   * @param Get debugging flag.
+   */
+   bool debug(void) const;
+
+  /** Get dimension of mesh.
+   *
+   * @returns Dimension of mesh.
+   */
+  int dimension(void) const;
+
+  /** Get MPI communicator associated with mesh.
+   *
+   * @returns MPI communicator.
+   */
+  const MPI_Comm comm(void) const;
+    
   /// Initialize the finite-element mesh.
   void initialize(void);
 
+  /** Print mesh to stdout.
+   *
+   * @param label Label for mesh.
+   */
+  void view(const char* label);
+
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.icc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.icc	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Mesh.icc	2009-01-23 00:21:22 UTC (rev 13928)
@@ -35,7 +35,42 @@
   return _coordsys;
 }
 
+// Set debug flag.
+inline
+void
+pylith::topology::Mesh::debug(const bool value) {
+  _mesh->setDebug(value);
+}
 
+// Get debug flag.
+inline
+bool
+pylith::topology::Mesh::debug(void) const {
+  return _mesh->debug();
+}
+
+// Get dimension of mesh.
+inline
+int
+pylith::topology::Mesh::dimension(void) const {
+  return _mesh->getDimension();
+}
+
+// Get MPI communicator associated with mesh.
+inline
+const MPI_Comm
+pylith::topology::Mesh::comm(void) const {
+  return _mesh->comm();
+}
+    
+// Print mesh to stdout.
+inline
+void
+pylith::topology::Mesh::view(const char* label) {
+  _mesh->view(label);
+}
+
+
 #endif
 
 

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am	2009-01-23 00:21:22 UTC (rev 13928)
@@ -16,6 +16,7 @@
 	feassemble \
 	materials \
 	meshio \
+	mpi \
 	solver \
 	topology \
 	utils

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/Makefile.am	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/Makefile.am	2009-01-23 00:21:22 UTC (rev 13928)
@@ -0,0 +1,56 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = mpi
+include $(top_srcdir)/subpackage.am
+
+subpkgpyexec_LTLIBRARIES = _mpimodule.la
+
+subpkgpyexec_PYTHON = mpi.py
+
+swig_sources = \
+	mpi.i \
+	mpi_comm.i
+
+swig_generated = \
+	mpi_wrap.cxx \
+	mpi.py
+
+_mpimodule_la_LDFLAGS = -module -avoid-version \
+	$(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
+
+dist__mpimodule_la_SOURCES = $(swig_sources) $(swig_generated)
+
+_mpimodule_la_LIBADD = \
+	$(top_builddir)/libsrc/libpylith.la \
+	-lspatialdata \
+	$(PETSC_LIBS)
+if ENABLE_CUBIT
+  _mpimodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+if NO_UNDEFINED
+_mpimodule_la_LIBADD += \
+	$(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+endif
+
+INCLUDES += $(PYTHON_EGG_CPPFLAGS) -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
+
+$(srcdir)/mpi_wrap.cxx $(srcdir)/mpi.py: $(swig_sources)
+	$(SWIG) -Wall -c++ -python $<
+
+
+MAINTAINERCLEANFILES = \
+	$(srcdir)/mpi_wrap.cxx \
+	$(srcdir)/mpi.py
+
+
+# End of file 

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// SWIG interface
+%module mpi
+
+// Header files for module C++ code
+%{
+#include <petsc.h>
+%}
+
+%include "typemaps.i"
+
+// Interfaces
+%include "mpi_comm.i"
+
+// End of file
+

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi_comm.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi_comm.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/mpi/mpi_comm.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -0,0 +1,89 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+
+// ----------------------------------------------------------------------
+// destructor
+%typemap(newfree) MPI_Comm* {
+  delete $1
+}
+
+// ----------------------------------------------------------------------
+// PETSC_COMM_WORLD
+%inline %{
+  MPI_Comm*
+  petsc_comm_world(void) {
+    return new MPI_Comm(PETSC_COMM_WORLD);
+  } // petc_comm_world
+%}
+
+// ----------------------------------------------------------------------
+// PETSC_COMM_SELF
+%inline %{
+  MPI_Comm*
+  petsc_comm_self(void) {
+    return new MPI_Comm(PETSC_COMM_SELF);
+  } // petsc_comm_self
+%}
+
+// ----------------------------------------------------------------------
+// MPI_COMM_WORLD
+%inline %{
+  MPI_Comm*
+  mpi_comm_world(void) {
+    return new MPI_Comm(MPI_COMM_WORLD);
+  } // comm_world
+%}
+
+// ----------------------------------------------------------------------
+// MPI_COMM_SELF
+%inline %{
+  MPI_Comm*
+  mpi_comm_self(void) {
+    return new MPI_Comm(MPI_COMM_SELF);
+  } // comm_self
+%}
+
+// ----------------------------------------------------------------------
+// rank()
+%inline %{
+  int
+  rank(MPI_Comm* comm) {
+    int value = 0;
+    MPI_Comm_rank(*comm, &value);
+    return value;
+  } // rank
+%}
+
+// ----------------------------------------------------------------------
+// size()
+%inline %{
+  int
+  size(MPI_Comm* comm) {
+    int value = 0;
+    MPI_Comm_size(*comm, &value);
+    return value;
+  } // rank
+%}
+
+// ----------------------------------------------------------------------
+// barrier()
+%inline %{
+  void
+  barrier(MPI_Comm* comm) {
+    MPI_Barrier(*comm);
+  } // rank
+%}
+
+
+// End of file
+

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Makefile.am	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Makefile.am	2009-01-23 00:21:22 UTC (rev 13928)
@@ -13,40 +13,45 @@
 subpackage = topology
 include $(top_srcdir)/subpackage.am
 
-subpkgpyexec_LTLIBRARIES = topologymodule.la
+subpkgpyexec_LTLIBRARIES = _topologymodule.la
 
-topologymodule_la_LDFLAGS = -module -avoid-version \
+subpkgpyexec_PYTHON = topology.py
+
+swig_sources = \
+	topology.i \
+	../include/mpi.i \
+	Mesh.i
+
+swig_generated = \
+	topology_wrap.cxx \
+	topology.py
+
+_topologymodule_la_LDFLAGS = -module -avoid-version \
 	$(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
 
-dist_topologymodule_la_SOURCES = topology.pyxe.src
-nodist_topologymodule_la_SOURCES = \
-	topology.pyxe \
-	topology.c topology_embed.cpp topology_embed.h
+dist__topologymodule_la_SOURCES = $(swig_sources) $(swig_generated)
 
-topologymodule_la_LIBADD = \
+_topologymodule_la_LIBADD = \
 	$(top_builddir)/libsrc/libpylith.la \
 	-lspatialdata \
-	$(PETSC_LIB)
-
+	$(PETSC_LIBS)
 if ENABLE_CUBIT
-  topologymodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+  _topologymodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
 endif
 if NO_UNDEFINED
-  topologymodule_la_LIBADD += $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+_topologymodule_la_LIBADD += \
+	$(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
 endif
 
 INCLUDES += $(PYTHON_EGG_CPPFLAGS) -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
 
-topology.pyx topology_embed.cpp  topology_embed.h: topology.pyxe
-	pyrexembed topology.pyxe
-topology.pyxe: $(srcdir)/topology.pyxe.src
-	cp $(srcdir)/topology.pyxe.src $@
-topology_embed.cpp: topology_embed.h
-topology_embed.h: topology.pyx
+$(srcdir)/topology_wrap.cxx $(srcdir)/topology.py: $(swig_sources)
+	$(SWIG) -Wall -c++ -python $<
 
-.pyx.c:
-	pyrexc $(PYTHON_EGG_PYXFLAGS) $<
 
-CLEANFILES = topology.pyxe topology.pyx topology.c *_embed.*
+MAINTAINERCLEANFILES = \
+	$(srcdir)/topology_wrap.cxx \
+	$(srcdir)/topology.py
 
+
 # End of file 

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Mesh.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Mesh.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Mesh.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file modulesrc/topology/Mesh.hh
+ *
+ * @brief Python interface to C++ PyLith Mesh object.
+ */
+
+namespace pylith {
+  namespace topology {
+
+    // Mesh -------------------------------------------------------------
+    class Mesh
+    { // Mesh
+
+      // PUBLIC METHODS /////////////////////////////////////////////////
+    public :
+
+      /** Default constructor.
+       *
+       * @param comm MPI communicator for mesh.
+       * @param dim Dimension associated with mesh cells.
+       */
+      Mesh(const MPI_Comm& comm =PETSC_COMM_WORLD,
+	   const int dim =3); 
+
+      /// Default destructor
+      ~Mesh(void);
+
+      /** Set coordinate system.
+       *
+       * @param cs Coordinate system.
+       */
+      void coordsys(const spatialdata::geocoords::CoordSys* cs);
+      
+      /** Get coordinate system.
+       *
+       * @returns Coordinate system.
+       */
+      const spatialdata::geocoords::CoordSys* coordsys(void) const;
+      
+      /** Set debug flag.
+       *
+       * @param value Turn on debugging if true.
+       */
+      void debug(const bool value);
+      
+      /** Get debug flag.
+       *
+       * @param Get debugging flag.
+       */
+      bool debug(void) const;
+
+      /** Get dimension of mesh.
+       *
+       * @returns Dimension of mesh.
+       */
+      int dimension(void) const;
+      
+      /** Get MPI communicator associated with mesh.
+       *
+       * @returns MPI communicator.
+       */
+      const MPI_Comm comm(void) const;
+    
+      /// Initialize the finite-element mesh.
+      void initialize(void);
+      
+      /** Print mesh to stdout.
+       *
+       * @param label Label for mesh.
+       */
+      void view(const char* label);
+
+    }; // Mesh
+
+  } // topology
+} // pylith
+
+
+// End of file

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/topology.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/topology.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/topology.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// SWIG interface
+%module topology
+
+// Header files for module C++ code
+%{
+#include "pylith/topology/Mesh.hh"
+%}
+
+%include "exception.i"
+%exception {
+  try {
+    $action
+  } catch (const std::exception& err) {
+    SWIG_exception(SWIG_RuntimeError, err.what());
+  } // try/catch
+ } // exception
+
+%include "typemaps.i"
+%include "../include/mpi.i"
+
+// Interfaces
+%include "Mesh.i"
+
+// End of file
+

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/Makefile.am	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/Makefile.am	2009-01-23 00:21:22 UTC (rev 13928)
@@ -23,7 +23,8 @@
 
 petsc_swig_sources = \
 	petsc.i \
-	petsc_general.i
+	petsc_general.i \
+	petsc_mat.i
 
 petsc_swig_generated = \
 	petsc_wrap.cxx \
@@ -72,7 +73,7 @@
 endif
 
 
-INCLUDES += -I$(PYTHON_INCDIR)
+INCLUDES += $(PYTHON_EGG_CPPFLAGS) -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
 
 $(srcdir)/petsc_wrap.cxx $(srcdir)/petsc.py: $(petsc_swig_sources)
 	$(SWIG) -Wall -c++ -python $<
@@ -89,8 +90,3 @@
 
 
 # End of file 
-
-
-
-
-# End of file 

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -33,7 +33,7 @@
 
 // Interfaces
 %include "petsc_general.i"
-//%include "petsc_sieve.i"
+%include "petsc_mat.i"
 
 // End of file
 

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -27,76 +27,12 @@
 %inline %{
   int
   finalize(void)
-  { // finaalize
+  { // finalize
     PetscErrorCode err = PetscFinalize(); CHKERRQ(err);
     return 0;
   } // finalize
 %} // inline
 
-// ----------------------------------------------------------------------
-// mat_assemble
-// Assemble matrix.
-%inline %{
-  int
-  mat_assemble(Mat* mat,
-               const char* mode)
-  { // mat_assemble
-    PetscErrorCode err = 0;
-    if (0 == strcmp(mode, "final_assembly")) {
-      err = MatAssemblyBegin(*mat, MAT_FINAL_ASSEMBLY);CHKERRQ(err);
-      err = MatAssemblyEnd(*mat, MAT_FINAL_ASSEMBLY);CHKERRQ(err);
-    } else if (0 == strcmp(mode, "flush_assembly")) {
-      err = MatAssemblyBegin(*mat, MAT_FLUSH_ASSEMBLY); CHKERRQ(err);
-      err = MatAssemblyEnd(*mat, MAT_FLUSH_ASSEMBLY); CHKERRQ(err);
-    } else
-      throw std::runtime_error("Unknown mode");
-  return 0;
-  } // mat_assemble
-%} // inline
 
-// ----------------------------------------------------------------------
-// mat_setzero
-// Zero out entries in matrix (retain structure).
-%inline %{
-  int
-  mat_setzero(Mat* mat)
-  { // mat_setzero
-    PetscErrorCode err = MatZeroEntries(*mat); CHKERRQ(err);
-    return 0;
-  } // mat_setzero
-%} // inline
-
-// ----------------------------------------------------------------------
-// mat_view
-// View matrix.
-%inline %{
-  int
-  mat_view(Mat* mat)
-  { // mat_view
-    PetscErrorCode err = 
-      MatView(*mat, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(err);
-    return 0;
-  } // mat_view
-%} // inline
-
-// ----------------------------------------------------------------------
-// mat_view_binary
-// Write matrix to binary file.
-%inline %{
-  int
-  mat_view_binary(Mat* mat,
-		    const char* filename)
-  { // mat_view_binary
-  PetscViewer viewer;
-  PetscErrorCode err = 
-    PetscViewerBinaryOpen(PETSC_COMM_WORLD, filename,
-			  FILE_MODE_WRITE, &viewer); CHKERRQ(err);
-  err = MatView(*mat, viewer); CHKERRQ(err);
-  err = PetscViewerDestroy(viewer); CHKERRQ(err);
-  return 0;
-  } // mat_view_binary
-%} // inline
-
-
 // End of file
 

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_mat.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_mat.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_mat.i	2009-01-23 00:21:22 UTC (rev 13928)
@@ -0,0 +1,79 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// ----------------------------------------------------------------------
+// mat_assemble
+// Assemble matrix.
+%inline %{
+  int
+  mat_assemble(Mat* mat,
+               const char* mode)
+  { // mat_assemble
+    PetscErrorCode err = 0;
+    if (0 == strcmp(mode, "final_assembly")) {
+      err = MatAssemblyBegin(*mat, MAT_FINAL_ASSEMBLY);CHKERRQ(err);
+      err = MatAssemblyEnd(*mat, MAT_FINAL_ASSEMBLY);CHKERRQ(err);
+    } else if (0 == strcmp(mode, "flush_assembly")) {
+      err = MatAssemblyBegin(*mat, MAT_FLUSH_ASSEMBLY); CHKERRQ(err);
+      err = MatAssemblyEnd(*mat, MAT_FLUSH_ASSEMBLY); CHKERRQ(err);
+    } else
+      throw std::runtime_error("Unknown mode");
+  return 0;
+  } // mat_assemble
+%} // inline
+
+// ----------------------------------------------------------------------
+// mat_setzero
+// Zero out entries in matrix (retain structure).
+%inline %{
+  int
+  mat_setzero(Mat* mat)
+  { // mat_setzero
+    PetscErrorCode err = MatZeroEntries(*mat); CHKERRQ(err);
+    return 0;
+  } // mat_setzero
+%} // inline
+
+// ----------------------------------------------------------------------
+// mat_view
+// View matrix.
+%inline %{
+  int
+  mat_view(Mat* mat)
+  { // mat_view
+    PetscErrorCode err = 
+      MatView(*mat, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(err);
+    return 0;
+  } // mat_view
+%} // inline
+
+// ----------------------------------------------------------------------
+// mat_view_binary
+// Write matrix to binary file.
+%inline %{
+  int
+  mat_view_binary(Mat* mat,
+		    const char* filename)
+  { // mat_view_binary
+  PetscViewer viewer;
+  PetscErrorCode err = 
+    PetscViewerBinaryOpen(PETSC_COMM_WORLD, filename,
+			  FILE_MODE_WRITE, &viewer); CHKERRQ(err);
+  err = MatView(*mat, viewer); CHKERRQ(err);
+  err = PetscViewerDestroy(viewer); CHKERRQ(err);
+  return 0;
+  } // mat_view_binary
+%} // inline
+
+
+// End of file
+

Modified: short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am	2009-01-23 00:21:22 UTC (rev 13928)
@@ -93,6 +93,8 @@
 	meshio/SingleOutput.py \
 	meshio/VertexFilter.py \
 	meshio/VertexFilterVecNorm.py \
+	mpi/__init__.py \
+	mpi/Communicator.py \
 	problems/__init__.py \
 	problems/Explicit.py \
 	problems/Formulation.py \

Modified: short/3D/PyLith/branches/pylith-swig/pylith/__init__.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/__init__.py	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/pylith/__init__.py	2009-01-23 00:21:22 UTC (rev 13928)
@@ -18,6 +18,7 @@
            'feassemble',
            'materials',
            'meshio',
+           'mpi',
            'problems',
            'solver',
            'topology',

Modified: short/3D/PyLith/branches/pylith-swig/pylith/mpi/Communicator.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/mpi/Communicator.py	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/pylith/mpi/Communicator.py	2009-01-23 00:21:22 UTC (rev 13928)
@@ -26,11 +26,11 @@
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
-  def __init__(self, group):
+  def __init__(self, cppComm):
     """
     Constructor.
     """
-    self.handle = mpimodule.create_communicator(group)
+    self.handle = cppComm
     self.rank = mpimodule.rank(self.handle)
     self.size = mpimodule.size(self.handle)
     return
@@ -51,7 +51,7 @@
   """
   global _petsc_world
   if _petsc_world is None:
-      _petsc_world = Communicator(mpimodule.PETSC_COMM_WORLD)
+      _petsc_world = Communicator(mpimodule.petsc_comm_world())
   return _petsc_world
 
 
@@ -62,7 +62,7 @@
   """
   global _petsc_self
   if _petsc_self is None:
-      _petsc_self = Communicator(mpimodule.PETSC_COMM_SELF)
+      _petsc_self = Communicator(mpimodule.petsc_comm_self())
   return _petsc_self
 
 
@@ -73,7 +73,7 @@
   """
   global _mpi_world
   if _mpi_world is None:
-      _mpi_world = Communicator(mpimodule.MPI_COMM_WORLD)
+      _mpi_world = Communicator(mpimodule.mpi_comm_world())
   return _mpi_world
 
 

Modified: short/3D/PyLith/branches/pylith-swig/pylith/topology/Mesh.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/topology/Mesh.py	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/pylith/topology/Mesh.py	2009-01-23 00:21:22 UTC (rev 13928)
@@ -16,145 +16,34 @@
 ##
 ## Factory: finite_element_mesh
 
-from pyre.components.Component import Component
+from topology import Mesh as ModuleMesh
 
+from topology import mpi_communicator
+
 # Mesh class
-class Mesh(Component):
+class Mesh(ModuleMesh):
   """
   Python Mesh for finite-element topology information.
   """
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
-  def __init__(self, name="mesh"):
+  def __init__(self, comm=None, dim=None):
     """
     Constructor.
     """
-    Component.__init__(self, name, facility="finite_element_mesh")
-    self.cppHandle = None
-    self.coordsys = None
-    self.debug = False
+    if comm is None and dim is None:
+      print "A"
+      ModuleMesh.__init__(self)
+    elif dim is None:
+      print "B"
+      commInt = mpi_communicator(comm)
+      print commInt
+      ModuleMesh.__init__(self, comm)
+    else:
+      print "C"
+      ModuleMesh.__init__(self, comm, dim)
     return
 
 
-  def initialize(self, coordsys):
-    """
-    Initialize mesh.
-    """
-    self._createCppHandle()
-    self.coordsys = coordsys
-    return
-
-
-  def setDebug(self, flag):
-    """
-    Set debugging flag.
-    """
-    self.debug = flag
-    self.cppHandle.debug = self.debug
-    return
-  
-
-  def dimension(self):
-    """
-    Get dimension of mesh.
-    """
-    dim = None
-    if not self.cppHandle is None:
-      dim = self.cppHandle.dimension
-    return dim
-  
-
-  def view(self):
-    """
-    View the mesh.
-    """
-    if not self.cppHandle is None:
-      self.cppHandle.view()
-    return
-
-
-  def comm(self):
-    """
-    Get MPI communicator associated with mesh.
-    """
-    comm = None
-    #if not self.cppHandle is None:
-    #  comm = self.cppHandle.comm
-    import mpi
-    comm = mpi.MPI_COMM_WORLD
-    return comm
-
-
-  def getRealSection(self, label):
-    """
-    Get real section from mesh.
-    """
-    assert(None != self.cppHandle)
-    return self.cppHandle.getRealSection(label)
-
-
-  def createRealSection(self, label, fiberDim):
-    """
-    Create real section (but don't allocate).
-    """
-    assert(None != self.cppHandle)
-    return self.cppHandle.createRealSection(label, fiberDim)
-
-
-  def allocateRealSection(self, field):
-    """
-    Allocated (and zero) real section.
-    """
-    assert(None != self.cppHandle)
-    self.cppHandle.allocateRealSection(field)
-    return
-  
-
-  def createMatrix(self, field):
-    """
-    Create sparse matrix compatible with field.
-    """
-    assert(None != self.cppHandle)
-    return self.cppHandle.createMatrix(field)
-  
-
-  def checkMaterialIds(self, materialIds):
-    """
-    Make sure material id for each cell matches id of a material.
-    """
-    assert(None != self.cppHandle)
-    self.cppHandle.checkMaterialIds(materialIds)
-    return
-
-
-  # PRIVATE METHODS ////////////////////////////////////////////////////
-
-  def _configure(self):
-    """
-    Set members based using inventory.
-    """
-    Component._configure(self)
-    return
-
-  
-  def _createCppHandle(self):
-    """
-    Create handle to corresponding C++ object.
-    """
-    if None == self.cppHandle:
-      import pylith.topology.topology as bindings
-      self.cppHandle = bindings.Mesh()
-    return
-  
-
-# FACTORIES ////////////////////////////////////////////////////////////
-
-def finite_element_mesh():
-  """
-  Factory associated with Mesh.
-  """
-  return Mesh()
-
-
 # End of file

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.cc	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.cc	2009-01-23 00:21:22 UTC (rev 13928)
@@ -58,6 +58,40 @@
 } // testCoordsys
 
 // ----------------------------------------------------------------------
+// Test debug().
+void
+pylith::topology::TestMesh::testDebug(void)
+{ // testDebug
+  Mesh mesh;
+
+  CPPUNIT_ASSERT_EQUAL(false, mesh.debug());
+
+  mesh.debug(true);
+  CPPUNIT_ASSERT_EQUAL(true, mesh.debug());
+} // testDebug
+
+// ----------------------------------------------------------------------
+// Test dimension().
+void
+pylith::topology::TestMesh::testDimension(void)
+{ // testDimension
+  const int dim = 2;
+  Mesh mesh(PETSC_COMM_WORLD, dim);
+
+  CPPUNIT_ASSERT_EQUAL(dim, mesh.dimension());
+} // testDimension
+
+// ----------------------------------------------------------------------
+// Test comm().
+void
+pylith::topology::TestMesh::testComm(void)
+{ // testComm
+  Mesh mesh(PETSC_COMM_SELF);
+
+  CPPUNIT_ASSERT_EQUAL(PETSC_COMM_SELF, mesh.comm());
+} // testComm
+
+// ----------------------------------------------------------------------
 // Test initialize().
 void
 pylith::topology::TestMesh::testInitialize(void)

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.hh	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestMesh.hh	2009-01-23 00:21:22 UTC (rev 13928)
@@ -43,6 +43,9 @@
   CPPUNIT_TEST( testConstructor );
   CPPUNIT_TEST( testSieveMesh );
   CPPUNIT_TEST( testCoordsys );
+  CPPUNIT_TEST( testDebug );
+  CPPUNIT_TEST( testDimension );
+  CPPUNIT_TEST( testComm );
   CPPUNIT_TEST( testInitialize );
 
   CPPUNIT_TEST_SUITE_END();
@@ -59,6 +62,15 @@
   /// Test coordsys().
   void testCoordsys(void);
 
+  /// Test debug().
+  void testDebug(void);
+
+  /// Test dimension().
+  void testDimension(void);
+
+  /// Test comm().
+  void testComm(void);
+
   /// Test initialize().
   void testInitialize(void);
 

Modified: short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/TestMesh.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/TestMesh.py	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/TestMesh.py	2009-01-23 00:21:22 UTC (rev 13928)
@@ -24,7 +24,7 @@
   Unit testing of Mesh object.
   """
 
-  def test_constructor(self):
+  def test_constructorA(self):
     """
     Test constructor.
     """
@@ -32,111 +32,69 @@
     return
 
 
-  def test_initialize(self):
+  def test_constructorB(self):
     """
-    Test initialize().
+    Test constructor.
     """
-    from spatialdata.geocoords.CSCart import CSCart
-    cs = CSCart()
-
-    mesh = Mesh()
-    mesh.initialize(cs)
-    self.assertNotEqual(None, mesh.cppHandle)
-    self.assertEqual(cs, mesh.coordsys)
-    return
-
-
-  def test_comm(self):
-    """
-    Test comm().
-    """
-    mesh = self._getMesh()
-    comm = mesh.comm()
     import mpi
-    self.assertEqual(mpi.MPI_COMM_WORLD, comm)
+    comm = mpi.MPI_COMM_SELF
+    print comm
+    mesh = Mesh(comm=mpi.MPI_COMM_SELF)
     return
 
 
-  def test_getRealSection(self):
+  def test_coordsys(self):
     """
-    Test createRealSection().
-
-    WARNING: This is not a rigorous test of createRealSection()
-    because we don't verify the results.
+    Test coordsys().
     """
-    mesh = self._getMesh()
-    field = mesh.getRealSection("field")
+    from spatialdata.geocoords.CSCart import CSCart
+    cs = CSCart()
+    cs.inventory.spaceDim = 2
+    cs._configure()
 
-    # We should really add something here to check to make sure things
-    # actually initialized correctly.
+    mesh = Mesh()
+    mesh.coordsys(cs)
+    self.assertEqual(cs.spaceDim(), mesh.coordsys().spaceDim())
     return
 
 
-  def test_createRealSection(self):
+  def test_debug(self):
     """
-    Test createRealSection().
-
-    WARNING: This is not a rigorous test of createRealSection()
-    because we don't verify the results.
+    Test debug().
     """
-    mesh = self._getMesh()
-    field = mesh.createRealSection("field", fiberDim=2)
+    mesh = Mesh()
 
-    # We should really add something here to check to make sure things
-    # actually initialized correctly.
-    return
+    self.assertEqual(False, mesh.debug())
 
-
-  def test_allocateRealSection(self):
-    """
-    Test createRealSection().
-
-    WARNING: This is not a rigorous test of createRealSection()
-    because we don't verify the results.
-    """
-    mesh = self._getMesh()
-    field = mesh.createRealSection("field", fiberDim=2)
-    mesh.allocateRealSection(field)
-
-    # We should really add something here to check to make sure things
-    # actually initialized correctly.
+    mesh.debug(True)
+    self.assertEqual(True, mesh.debug())
     return
 
 
-  def test_createMatrix(self):
+  def test_dimension(self):
     """
-    Test createRealSection().
-
-    WARNING: This is not a rigorous test of createRealSection()
-    because we don't verify the results.
+    Test debug().
     """
-    mesh = self._getMesh()
-    field = mesh.createRealSection("field", fiberDim=2)
-    mesh.allocateRealSection(field)
-    matrix = mesh.createMatrix(field)
-
-    # We should really add something here to check to make sure things
-    # actually initialized correctly.
+    mesh = Mesh()
+    
+    dim = 3
+    self.assertEqual(dim, mesh.dimension())
     return
 
 
-  def test_checkMaterialIds(self):
+  def test_initialize(self):
     """
-    Test createRealSection().
+    Test initialize().
     """
-    mesh = self._getMesh()
-    materialIds = [4, 3]
-    mesh.checkMaterialIds(materialIds)
+    from spatialdata.geocoords.CSCart import CSCart
+    cs = CSCart()
 
-    materialIds[0] = -2
-    caughtError = False
-    try:
-      mesh.checkMaterialIds(materialIds)
-    except RuntimeError:
-      caughtError = True
-    self.assertTrue(caughtError)
+    mesh = Mesh()
+    mesh.coordsys(cs)
+    mesh.initialize()
     return
 
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _getMesh(self):
@@ -145,16 +103,18 @@
     """
     from spatialdata.geocoords.CSCart import CSCart
     cs = CSCart()
-    cs.spaceDim = 2
+    cs.inventory.spaceDim = 2
+    cs._configure()
 
     from spatialdata.units.Nondimensional import Nondimensional
     normalizer = Nondimensional()
-    normalizer.initialize()    
+    normalizer._configure()    
 
     from pylith.meshio.MeshIOAscii import MeshIOAscii
     importer = MeshIOAscii()
-    importer.filename = "data/tri3.mesh"
-    importer.coordsys = cs
+    importer.inventory.filename = "data/tri3.mesh"
+    importer.inventory.coordsys = cs
+    importer._configure()
     mesh = importer.read(normalizer, debug=False, interpolate=False)
     
     return mesh

Modified: short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/testdriver.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/testdriver.py	2009-01-22 23:54:07 UTC (rev 13927)
+++ short/3D/PyLith/branches/pylith-swig/unittests/pytests/topology/testdriver.py	2009-01-23 00:21:22 UTC (rev 13928)
@@ -57,14 +57,14 @@
     from TestMesh import TestMesh
     suite.addTest(unittest.makeSuite(TestMesh))
 
-    from TestMeshGenerator import TestMeshGenerator
-    suite.addTest(unittest.makeSuite(TestMeshGenerator))
+    #from TestMeshGenerator import TestMeshGenerator
+    #suite.addTest(unittest.makeSuite(TestMeshGenerator))
 
-    from TestMeshImporter import TestMeshImporter
-    suite.addTest(unittest.makeSuite(TestMeshImporter))
+    #from TestMeshImporter import TestMeshImporter
+    #suite.addTest(unittest.makeSuite(TestMeshImporter))
 
-    from TestFieldsManager import TestFieldsManager
-    suite.addTest(unittest.makeSuite(TestFieldsManager))
+    #from TestFieldsManager import TestFieldsManager
+    #suite.addTest(unittest.makeSuite(TestFieldsManager))
 
     return suite
 



More information about the CIG-COMMITS mailing list