[cig-commits] r6046 - in short/3D/PyLith/trunk: . examples/twotri3 modulesrc modulesrc/utils pylith pylith/meshio pylith/utils

brad at geodynamics.org brad at geodynamics.org
Sat Feb 17 09:43:01 PST 2007


Author: brad
Date: 2007-02-17 09:43:00 -0800 (Sat, 17 Feb 2007)
New Revision: 6046

Added:
   short/3D/PyLith/trunk/modulesrc/utils/
   short/3D/PyLith/trunk/modulesrc/utils/Makefile.am
   short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src
Modified:
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg
   short/3D/PyLith/trunk/modulesrc/Makefile.am
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/PyLithApp.py
   short/3D/PyLith/trunk/pylith/meshio/MeshIO.py
   short/3D/PyLith/trunk/pylith/utils/CheckpointTimer.py
Log:
Created PetscManager to handle PETSc options. Created petsc module to initialize/finalize PETSc.

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/configure.ac	2007-02-17 17:43:00 UTC (rev 6046)
@@ -151,6 +151,7 @@
                 modulesrc/feassemble/Makefile
                 modulesrc/meshio/Makefile
 		modulesrc/topology/Makefile
+		modulesrc/utils/Makefile
 		applications/Makefile
 		unittests/Makefile
 		unittests/libtests/Makefile

Modified: short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg	2007-02-17 17:43:00 UTC (rev 6046)
@@ -5,6 +5,7 @@
 # ----------------------------------------------------------------------
 journal.info.eqdeformation = 1
 journal.info.explicit = 1
+journal.info.petsc = 1
 
 # ----------------------------------------------------------------------
 # MPI

Modified: short/3D/PyLith/trunk/modulesrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/Makefile.am	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/modulesrc/Makefile.am	2007-02-17 17:43:00 UTC (rev 6046)
@@ -13,7 +13,8 @@
 SUBDIRS = \
 	feassemble \
 	meshio \
-	topology
+	topology \
+	utils
 
 
 # End of file 

Added: short/3D/PyLith/trunk/modulesrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/utils/Makefile.am	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/modulesrc/utils/Makefile.am	2007-02-17 17:43:00 UTC (rev 6046)
@@ -0,0 +1,43 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = utils
+include $(top_srcdir)/subpackage.am
+
+subpkgpyexec_LTLIBRARIES = petscmodule.la
+
+petscmodule_la_LDFLAGS = -module
+
+petscmodule_la_SOURCES = petsc.pyxe
+
+nodist_petscmodule_la_SOURCES = \
+	petsc.c petsc_embed.cpp petsc_embed.h
+
+petscmodule_la_LIBADD = \
+	$(top_builddir)/libsrc/libpylith.la \
+	$(PETSC_LIB)
+
+INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
+
+petsc.pyx petsc_embed.cpp  petsc_embed.h: petsc.pyxe
+	pyrexembed petsc.pyxe
+petsc.pyxe: $(srcdir)/petsc.pyxe.src
+	cp $(srcdir)/petsc.pyxe.src $@
+petsc_embed.cpp: petsc_embed.h
+petsc_embed.h: petsc.pyx
+
+.pyx.c:
+	pyrexc $< $(PYREX_INCLUDES)
+
+CLEANFILES = petsc.pyxe petsc.pyx petsc.c *_embed.*
+
+# End of file 

Added: short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src	2007-02-17 17:43:00 UTC (rev 6046)
@@ -0,0 +1,74 @@
+# -*- Pyrex -*-
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+# ----------------------------------------------------------------------
+cdef enum:
+  PETSC_NULL = 0
+cdef extern from "petsc.h":
+  ctypedef int PetscErrorCode
+  PetscErrorCode PetscInitialize(int*, char***, char[], char[])
+  PetscErrorCode PetscFinalize()
+
+# ----------------------------------------------------------------------
+cdef extern from "Python.h":
+  object PyCObject_FromVoidPtr(void*, void (*destruct)(void*))
+  void* PyCObject_AsVoidPtr(object)
+  char* PyString_AsString(object)
+  object PyList_GetItem(object, int)
+
+cdef void* ptrFromHandle(obj):
+  """Extract pointer from PyCObject."""
+  return PyCObject_AsVoidPtr(obj.handle)
+
+cdef extern from "stdlib.h":
+    ctypedef unsigned long size_t
+    void* malloc(size_t size)
+    void free(void* mem)
+
+cdef extern from "string.h":
+    void strcpy(char*, char*)
+    int strlen(char*)
+
+# ----------------------------------------------------------------------
+def petsc_initialize(options):
+  """
+  Initialize PETSc.
+  """
+  cdef PetscErrorCode err
+  cdef char** argv
+  cdef char* arg
+  cdef int argc
+
+  argc = len(options)
+  argv = <char**> malloc((argc+1)*sizeof(char*));
+  for i from 0 <= i < argc:
+    arg = PyString_AsString(PyList_GetItem(options, i));
+    argv[i] = <char*> malloc((strlen(arg)+1)*sizeof(char));
+    strcpy(argv[i], arg);
+  argv[argc] = NULL;
+  err = PetscInitialize(&argc, &argv, <char*> PETSC_NULL, <char*> PETSC_NULL)
+  for i from 0 <= i < argc:
+    free(argv[i])
+  free(argv)
+  return
+
+
+def petsc_finalize():
+  """
+  Finalize PETSc.
+  """
+  cdef PetscErrorCode err
+  err = PetscFinalize()
+  return
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2007-02-17 17:43:00 UTC (rev 6046)
@@ -44,6 +44,7 @@
 	utils/__init__.py \
 	utils/CheckpointTimer.py \
 	utils/CppData.py \
+	utils/PetscManager.py \
 	utils/importing.py \
 	utils/testarray.py
 

Modified: short/3D/PyLith/trunk/pylith/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-02-17 17:43:00 UTC (rev 6046)
@@ -39,6 +39,7 @@
     ## \b Facilities
     ## @li \b mesher Generates or imports the computational mesh.
     ## @li \b problem Computational problem to solve
+    ## @li \b petsc Manager for PETSc options
 
     import pyre.inventory
 
@@ -55,6 +56,10 @@
     problem = pyre.inventory.facility("problem", factory=EqDeformation)
     problem.meta['tip'] = "Computational problem to solve."
 
+    # Dummy facility for passing options to PETSc
+    from pylith.utils.PetscManager import PetscManager
+    petsc = pyre.inventory.facility("petsc", factory=PetscManager)
+    petsc.meta['tip'] = "Manager for PETSc options."
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
@@ -63,16 +68,11 @@
     Run the application.
     """
 
-    # :TODO: Setup initialize/finalize of PETSc here. Will need to get
-    # PETSc command line arguments using something like PetscUtil.py
-    # in 0.8. If we end up using petsc2py, some modification of
-    # PetscUtil may be necessary. Brad doesn' like mixing different
-    # formats of command line arguments and he would like to require
-    # Pyre style formats.
-
-    #mesh = self.mesher.create()
+    self.petsc.initialize()
+    mesh = self.mesher.create()
     #self.problem.mesh = mesh.distribute()
     self.problem.run(self)
+    self.petsc.finalize()
     return
   
 
@@ -81,8 +81,6 @@
     Constructor.
     """
     Application.__init__(self, name)
-    self.mesher = None
-    self.problem = None
     return
 
 
@@ -95,6 +93,7 @@
     Application._configure(self)
     self.mesher = self.inventory.mesher
     self.problem = self.inventory.problem
+    self.petsc = self.inventory.petsc
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIO.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIO.py	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIO.py	2007-02-17 17:43:00 UTC (rev 6046)
@@ -63,11 +63,8 @@
     @returns PETSc mesh object containing finite-element mesh
     """
     from pylith.topology.Mesh import Mesh
-    print "Creating Mesh object"
     mesh = Mesh()
-    print "Setting interpolate"
     self.cppHandle.interpolate = self.interpolate
-    print "Reading mesh"
     mesh.cppHandle = self.cppHandle.read(mesh.cppHandle)
     return 
 

Modified: short/3D/PyLith/trunk/pylith/utils/CheckpointTimer.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/CheckpointTimer.py	2007-02-17 11:55:51 UTC (rev 6045)
+++ short/3D/PyLith/trunk/pylith/utils/CheckpointTimer.py	2007-02-17 17:43:00 UTC (rev 6046)
@@ -10,7 +10,7 @@
 # ----------------------------------------------------------------------
 #
 
-## @file pylith/CheckpointTimer.py
+## @file pylith/utils/CheckpointTimer.py
 
 ## @brief Python CheckpointTimer object for managing checkpointing.
 



More information about the cig-commits mailing list