[cig-commits] r13913 - short/3D/PyLith/branches/pylith-swig/modulesrc/utils
brad at geodynamics.org
brad at geodynamics.org
Wed Jan 21 21:20:18 PST 2009
Author: brad
Date: 2009-01-21 21:20:17 -0800 (Wed, 21 Jan 2009)
New Revision: 13913
Added:
short/3D/PyLith/branches/pylith-swig/modulesrc/utils/EventLogger.i
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/modulesrc/utils/utils.i
Modified:
short/3D/PyLith/branches/pylith-swig/modulesrc/utils/Makefile.am
Log:
Worked on petsc and utils modules.
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/EventLogger.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/EventLogger.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/EventLogger.i 2009-01-22 05:20:17 UTC (rev 13913)
@@ -0,0 +1,109 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file modulesrc/utils/EventLogger.i
+ *
+ * @brief Python interface to C++ EventLogger.
+ */
+
+
+namespace pylith {
+ namespace utils {
+
+ class EventLogger
+ { // EventLogger
+
+ // PUBLIC MEMBERS /////////////////////////////////////////////////
+ public :
+
+ /// Constructor
+ EventLogger(void);
+
+ /// Destructor
+ ~EventLogger(void);
+
+ /** Set name of logging class.
+ *
+ * @param name Name of logging class.
+ */
+ void className(const char* name);
+
+ /** Get name of logging class.
+ *
+ * @returns Name of logging class.
+ */
+ const char* className(void) const;
+
+ /// Setup logging class.
+ void initialize(void);
+
+ /** Register event.
+ *
+ * @prerequisite Must call initialize() before registerEvent().
+ *
+ * @param name Name of event.
+ * @returns Event identifier.
+ */
+ int registerEvent(const char* name);
+
+ /** Get event identifier.
+ *
+ * @param name Name of event.
+ * @returns Event identifier.
+ */
+ int eventId(const char* name);
+
+ /** Log event begin.
+ *
+ * @param id Event identifier.
+ */
+ void eventBegin(const int id);
+
+ /** Log event end.
+ *
+ * @param id Event identifier.
+ */
+ void eventEnd(const int id);
+
+ /** Register stage.
+ *
+ * @prerequisite Must call initialize() before registerStage().
+ *
+ * @param name Name of stage.
+ * @returns Stage identifier.
+ */
+ int registerStage(const char* name);
+
+ /** Get stage identifier.
+ *
+ * @param name Name of stage.
+ * @returns Stage identifier.
+ */
+ int stageId(const char* name);
+
+ /** Log stage begin.
+ *
+ * @param id Stage identifier.
+ */
+ void stagePush(const int id);
+
+ /// Log stage end.
+ void stagePop(void);
+
+ }; // EventLogger
+
+ } // utils
+} // pylith
+
+
+// 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-21 22:28:48 UTC (rev 13912)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/Makefile.am 2009-01-22 05:20:17 UTC (rev 13913)
@@ -13,64 +13,84 @@
subpackage = utils
include $(top_srcdir)/subpackage.am
-subpkgpyexec_LTLIBRARIES = petscmodule.la utilsmodule.la
+subpkgpyexec_LTLIBRARIES = \
+ _petscmodule.la \
+ _utilsmodule.la
-petscmodule_la_LDFLAGS = -module -avoid-version \
+subpkgpyexec_PYTHON = \
+ petsc.py \
+ utils.py
+
+petsc_swig_sources = \
+ petsc.i \
+ petsc_general.i
+
+petsc_swig_generated = \
+ petsc_wrap.cxx \
+ petsc.py
+
+utils_swig_sources = \
+ utils.i \
+ EventLogger.i
+
+utils_swig_generated = \
+ utils_wrap.cxx \
+ utils.py
+
+swig_sources = $(petsc_swig_sources) $(utils_swig_sources)
+
+swig_generated = $(petsc_swig_generated) $(utils_swig_generated)
+
+# PETSc module
+_petscmodule_la_LDFLAGS = -module -avoid-version \
$(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
-dist_petscmodule_la_SOURCES = petsc.pyxe.src
-nodist_petscmodule_la_SOURCES = \
- petsc.pyxe \
- petsc.c petsc_embed.cpp petsc_embed.h
-petscmodule_la_LIBADD = \
+
+dist__petscmodule_la_SOURCES = $(petsc_swig_sources) $(petsc_swig_generated)
+
+_petscmodule_la_LIBADD = \
$(top_builddir)/libsrc/libpylith.la \
- $(PETSC_LIB)
-if ENABLE_CUBIT
- petscmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
-endif
+ -lspatialdata \
+ $(PETSC_LIBS)
if NO_UNDEFINED
- petscmodule_la_LIBADD += $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+_petscmodule_la_LIBADD += \
+ $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
endif
+# utils module
+_utilsmodule_la_LDFLAGS = -module -avoid-version \
+ $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
-utilsmodule_la_LDFLAGS = -module -avoid-version \
- $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
-dist_utilsmodule_la_SOURCES = utils.pyxe.src
-nodist_utilsmodule_la_SOURCES = \
- utils.pyxe \
- utils.c utils_embed.cpp utils_embed.h
-utilsmodule_la_LIBADD = \
+dist__utilsmodule_la_SOURCES = $(utils_swig_sources) $(utils_swig_generated)
+
+_utilsmodule_la_LIBADD = \
$(top_builddir)/libsrc/libpylith.la \
- $(PETSC_LIB)
-if ENABLE_CUBIT
- utilsmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
-endif
+ -lspatialdata \
+ $(PETSC_LIBS)
if NO_UNDEFINED
- utilsmodule_la_LIBADD += $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+_utilsmodule_la_LIBADD += \
+ $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
endif
+INCLUDES += -I$(PYTHON_INCDIR)
-INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
+$(srcdir)/petsc_wrap.cxx $(srcdir)/petsc.py: $(petsc_swig_sources)
+ $(SWIG) -Wall -c++ -python $<
-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
+$(srcdir)/utils_wrap.cxx $(srcdir)/utils.py: $(utils_swig_sources)
+ $(SWIG) -Wall -c++ -python $<
-utils.pyx utils_embed.cpp utils_embed.h: utils.pyxe
- pyrexembed utils.pyxe
-utils.pyxe: $(srcdir)/utils.pyxe.src
- cp $(srcdir)/utils.pyxe.src $@
-utils_embed.cpp: utils_embed.h
-utils_embed.h: utils.pyx
-.pyx.c:
- pyrexc $< $(PYREX_INCLUDES)
+MAINTAINERCLEANFILES = \
+ $(srcdir)/petsc_wrap.cxx \
+ $(srcdir)/petsc.py \
+ $(srcdir)/utils_wrap.cxx \
+ $(srcdir)/utils.py
-CLEANFILES = *_embed.* \
- petsc.pyxe petsc.pyx petsc.c \
- utils.pyxe utils.pyx utils.c
# End of file
+
+
+
+
+# End of file
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc.i 2009-01-22 05:20:17 UTC (rev 13913)
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// SWIG interface
+%module petsc
+
+// Header files for module C++ code
+%{
+#include <petsc.h>
+#include <petscmat.h>
+%}
+
+%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/chararray.i"
+
+// Interfaces
+%include "petsc_general.i"
+//%include "petsc_sieve.i"
+
+// End of file
+
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/petsc_general.i 2009-01-22 05:20:17 UTC (rev 13913)
@@ -0,0 +1,102 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// ----------------------------------------------------------------------
+// initialize
+%inline %{
+ int
+ initialize(int argc, char** argv)
+ { // initialize
+ PetscErrorCode err =
+ PetscInitialize(&argc, &argv, NULL, NULL); CHKERRQ(err);
+ return 0;
+ } // initialize
+%} // inline
+
+// ----------------------------------------------------------------------
+// finalize
+%inline %{
+ int
+ finalize(void)
+ { // finaalize
+ 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/utils.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/utils/utils.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/utils/utils.i 2009-01-22 05:20:17 UTC (rev 13913)
@@ -0,0 +1,36 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// SWIG interface
+%module utils
+
+// Header files for module C++ code
+%{
+#include "pylith/utils/EventLogger.hh"
+
+#include <petsclog.h> // USES PetscLogEventBegin/End() in inline methods
+%}
+
+%include "exception.i"
+%exception {
+ try {
+ $action
+ } catch (const std::exception& err) {
+ SWIG_exception(SWIG_RuntimeError, err.what());
+ } // try/catch
+ } // exception
+
+// Interfaces
+%include "EventLogger.i"
+
+// End of file
+
More information about the CIG-COMMITS
mailing list