[cig-commits] r5082 - in short/3D/PyLith/branches/pylith-0.8: . pylith3d/module

brad at geodynamics.org brad at geodynamics.org
Tue Oct 24 17:30:54 PDT 2006


Author: brad
Date: 2006-10-24 17:30:53 -0700 (Tue, 24 Oct 2006)
New Revision: 5082

Added:
   short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.cc
   short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.h
Modified:
   short/3D/PyLith/branches/pylith-0.8/configure.ac
   short/3D/PyLith/branches/pylith-0.8/pylith3d/module/Makefile.am
   short/3D/PyLith/branches/pylith-0.8/pylith3d/module/bindings.cc
   short/3D/PyLith/branches/pylith-0.8/pylith3d/module/scanner.cc
Log:
Moved interpolatePoints from scanner.cc to interpolate.cc. Green's functions stuff is turned on with --enable-greensfns argument to configure. Still need to add test for Numeric/arrayobject.h to configure.ac.

Modified: short/3D/PyLith/branches/pylith-0.8/configure.ac
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/configure.ac	2006-10-24 00:57:54 UTC (rev 5081)
+++ short/3D/PyLith/branches/pylith-0.8/configure.ac	2006-10-25 00:30:53 UTC (rev 5082)
@@ -20,6 +20,13 @@
     [want_embedding=yes])
 AM_CONDITIONAL([COND_EMBEDDING], [test "$want_embedding" = yes])
 
+# Green's functions option
+AC_ARG_ENABLE([greensfns],
+	[  --enable-greensfns        Enable Green's functions application (requires Numeric) [[default=no]]],
+	[enable_greensfns=yes],
+	[enable_greensfns=no])
+AM_CONDITIONAL([ENABLE_GREENSFNS], [test "$enable_greensfns" = yes])
+
 # Checks for programs.
 AM_PATH_PYTHON([2.3])
 CIT_PYTHON_SYSCONFIG

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/module/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/module/Makefile.am	2006-10-24 00:57:54 UTC (rev 5081)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/module/Makefile.am	2006-10-25 00:30:53 UTC (rev 5082)
@@ -66,4 +66,10 @@
 	write_modelinfo.cc \
 	write_modelinfo.h
 
+if ENABLE_GREENSFNS
+sources += interpolate.cc \
+	interpolate.h
+CPPFLAGS += -DGREENSFNS
+endif
+
 ## end of Makefile.am

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/module/bindings.cc
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/module/bindings.cc	2006-10-24 00:57:54 UTC (rev 5081)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/module/bindings.cc	2006-10-25 00:30:53 UTC (rev 5082)
@@ -47,6 +47,10 @@
 #include "write_modelinfo.h" // output routines
 #include "misc.h"          // miscellaneous methods
 
+#if defined(GREENSFNS)
+#include "interpolate.h"
+#endif
+
 // the method table
 
 struct PyMethodDef pypylith3d_methods[] = {
@@ -403,6 +407,14 @@
     {pypylith3d_try_binio__name__, pypylith3d_try_binio,
      METH_VARARGS, pypylith3d_try_binio__doc__},
 
+#if defined(GREENSFNS)
+
+    // try binary I/O to see if it works
+    {pypylith3d_interpolatePoints__name__, pypylith3d_interpolatePoints,
+     METH_VARARGS, pypylith3d_interpolatePoints__doc__},
+
+#endif
+
     // copyright note
     {pypylith3d_copyright__name__, pypylith3d_copyright,
      METH_VARARGS, pypylith3d_copyright__doc__},

Added: short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.cc
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.cc	2006-10-24 00:57:54 UTC (rev 5081)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.cc	2006-10-25 00:30:53 UTC (rev 5082)
@@ -0,0 +1,108 @@
+// -*- C++ -*-
+// 
+//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+//  PyLith by Charles A. Williams, Brad Aagaard, and Matt Knepley
+//
+//  Copyright (c) 2004-2006 Rensselaer Polytechnic Institute
+//
+//  Permission is hereby granted, free of charge, to any person obtaining
+//  a copy of this software and associated documentation files (the
+//  "Software"), to deal in the Software without restriction, including
+//  without limitation the rights to use, copy, modify, merge, publish,
+//  distribute, sublicense, and/or sell copies of the Software, and to
+//  permit persons to whom the Software is furnished to do so, subject to
+//  the following conditions:
+//
+//  The above copyright notice and this permission notice shall be
+//  included in all copies or substantial portions of the Software.
+//
+//  THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+//  EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+//  MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
+//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+//  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+//  OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
+//  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// 
+
+#include <Distribution.hh>
+#include <petscmesh.h>
+#include <src/dm/mesh/meshpylith.h>
+#include <petscmat.h>
+#include <portinfo>
+#include "journal/debug.h"
+
+#include <Python.h>
+
+#include "interpolate.h"
+#include "exceptionhandler.h"
+#include "pylith3d_externs.h"
+#include <stdio.h>
+#include <string.h>
+
+#include "Numeric/arrayobject.h"
+
+char pypylith3d_interpolatePoints__doc__[] = "";
+char pypylith3d_interpolatePoints__name__[] = "interpolatePoints";
+
+PyObject * pypylith3d_interpolatePoints(PyObject *, PyObject *args)
+{
+  using ALE::Obj;
+  PyObject      *pyMesh, *pySol;
+  PyArrayObject *pyPoints;
+
+  int ok = PyArg_ParseTuple(args, (char *) "OOO!:interpolatePoints", &pyMesh, &pySol, &PyArray_Type, &pyPoints);
+  if (!ok) {
+    return 0;
+  }
+  if ((pyPoints->nd != 2) || (pyPoints->descr->type_num != PyArray_DOUBLE)) {
+    PyErr_SetString(PyExc_ValueError, "points must be a 2d array with double values");
+    return 0;
+  }
+  if (pyPoints->dimensions[1] != 3) {
+    PyErr_SetString(PyExc_ValueError, "points must be a 3d");
+    return 0;
+  }
+  if ((pyPoints->strides[0] != 3 * sizeof(double)) || (pyPoints->strides[1] != sizeof(double))) {
+    PyErr_SetString(PyExc_ValueError, "points must be a contiguous array");
+    return 0;
+  }
+
+  Mesh           mesh = (Mesh) PyCObject_AsVoidPtr(pyMesh);
+  Vec            sol  = (Vec)  PyCObject_AsVoidPtr(pySol);
+  SectionReal    displacement, fullDisplacement;
+  const int      numPoints = pyPoints->dimensions[0];
+  double        *values;
+  PetscErrorCode ierr;
+
+  ierr = MeshGetSectionReal(mesh, "displacement", &displacement);
+  ierr = updateDisplacement(displacement, sol);
+  ierr = createFullDisplacement(mesh, &fullDisplacement);
+  ierr = MeshInterpolatePoints(mesh, fullDisplacement, numPoints, (double *) pyPoints->data, &values);
+  ierr = SectionRealDestroy(displacement);
+  ierr = PetscFree(values);
+
+  int            dims[2]  = {numPoints, 3};
+  PyArrayObject *pyValues = (PyArrayObject *) PyArray_FromDims(2, dims, PyArray_DOUBLE);
+  double        *data     = (double *) pyValues->data;
+
+  for(int p = 0; p < numPoints; ++p) {
+    for(int d = 0; d < 3; d++) {
+      data[p*3+d] = values[p*3+d];
+    }
+  }
+
+  ierr = PetscFree(values);
+  journal::debug_t debug("pylith3d");
+  debug
+    << journal::at(__HERE__)
+    << "Interpolated points"
+    << journal::endl;
+
+  return Py_BuildValue((char *) "N", pyValues);
+}
+
+// End of file

Added: short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.h
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.h	2006-10-24 00:57:54 UTC (rev 5081)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/module/interpolate.h	2006-10-25 00:30:53 UTC (rev 5082)
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+// 
+//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+//  PyLith by Charles A. Williams, Brad Aagaard, and Matt Knepley
+//
+//  Copyright (c) 2004-2006 Rensselaer Polytechnic Institute
+//
+//  Permission is hereby granted, free of charge, to any person obtaining
+//  a copy of this software and associated documentation files (the
+//  "Software"), to deal in the Software without restriction, including
+//  without limitation the rights to use, copy, modify, merge, publish,
+//  distribute, sublicense, and/or sell copies of the Software, and to
+//  permit persons to whom the Software is furnished to do so, subject to
+//  the following conditions:
+//
+//  The above copyright notice and this permission notice shall be
+//  included in all copies or substantial portions of the Software.
+//
+//  THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+//  EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+//  MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
+//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+//  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+//  OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
+//  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// 
+
+#if !defined(pypylith3d_interpolate_h)
+#define pypylith3d_interpolate_h
+
+// interpolate points
+extern char pypylith3d_interpolatePoints__name__[];
+extern char pypylith3d_interpolatePoints__doc__[];
+extern "C"
+PyObject * pypylith3d_interpolatePoints(PyObject *, PyObject *);
+
+#endif
+
+// End of file

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/module/scanner.cc
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/module/scanner.cc	2006-10-24 00:57:54 UTC (rev 5081)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/module/scanner.cc	2006-10-25 00:30:53 UTC (rev 5082)
@@ -569,6 +569,7 @@
   return Py_None;
 }
 
+#if 0
 #include "Numeric/arrayobject.h"
 
 char pypylith3d_interpolatePoints__doc__[] = "";
@@ -630,6 +631,7 @@
 
   return Py_BuildValue((char *) "N", pyValues);
 }
+#endif
 
 // Scan boundary conditions
 
@@ -673,7 +675,7 @@
 	    strlen(forceUnits),
 	    strlen(bcInputFile),
 	    sizeof(errorstring));
-    
+
   if(0 != exceptionhandler(errorcode, errorstring)) {
     return 0;
   }



More information about the cig-commits mailing list