From e8d3fda2c991348a19b3a0e33dde4869c57630a9 Mon Sep 17 00:00:00 2001 From: Dave Grote Date: Tue, 10 Jan 2017 10:59:08 -0800 Subject: Cleaned up python importing of warpx --- Python/setup.py | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/setup.py') diff --git a/Python/setup.py b/Python/setup.py index d810afd56..bba3912c0 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -8,6 +8,7 @@ from distutils.core import setup, Extension example_module = Extension('pywarpx._warpxC', + swig_opts=['-outdir','pywarpx'], sources=['warpxC.i'], library_dirs=['.'], libraries=['warpx'], -- cgit v1.2.3 From 13917fbf0bb4db946d0caff74d02ac43dfc0dd8c Mon Sep 17 00:00:00 2001 From: Dave Grote Date: Tue, 10 Jan 2017 11:00:50 -0800 Subject: Added python wrapper around addNParticles The underlying routine needs to be implemented --- Python/setup.py | 9 ++++++++ Python/warpxC.i | 54 +++++++++++++++++++++++++++++++++++++----------- Source/WarpXWrappers.cpp | 5 +++++ Source/WarpXWrappers.h | 2 ++ 4 files changed, 58 insertions(+), 12 deletions(-) (limited to 'Python/setup.py') diff --git a/Python/setup.py b/Python/setup.py index bba3912c0..dd92c5468 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -6,12 +6,21 @@ setup.py file for WarpX from distutils.core import setup, Extension +import numpy + +try: + numpy_include = numpy.get_include() +except AttributeError: + numpy_include = numpy.get_numpy_include() + +include_dirs = [numpy_include, '../Source'] example_module = Extension('pywarpx._warpxC', swig_opts=['-outdir','pywarpx'], sources=['warpxC.i'], library_dirs=['.'], libraries=['warpx'], + include_dirs = include_dirs, ) setup (name = 'pywarpx', diff --git a/Python/warpxC.i b/Python/warpxC.i index 2dd93fce7..3a2a5cb95 100644 --- a/Python/warpxC.i +++ b/Python/warpxC.i @@ -1,18 +1,48 @@ %module warpxC -%include - -%apply (int ARGC, char **ARGV) { (int argc, char *argv[]) } - -void boxlib_init(int argc, char *argv[]); +%{ +#include -// void boxlib_init_with_inited_mpi (int argc, char** argv, MPI_Comm mpicomm); +#define SWIG_FILE_WITH_INIT +%} +%include "numpy.i" +%init %{ +import_array(); +%} -void boxlib_finalize (int finalize_mpi); - -void warpx_init (); - -void warpx_finalize (); +// For boxlib_init(int argc, char *argv[]); +%include +%apply (int ARGC, char **ARGV) { (int argc, char *argv[]) } -void warpx_evolve (int numsteps = -1); // -1 means the inputs parameter will be used. +%rename (addNParticles) wrapped_addNParticles; +%ignore addNParticles; + +%include "../Source/WarpXWrappers.h" + +%apply (int DIM1, double* IN_ARRAY1) {(int lenx, double* x), + (int leny, double* y), + (int lenz, double* z), + (int lenvx, double* vx), + (int lenvy, double* vy), + (int lenvz, double* vz)} +%apply (int DIM1, int DIM2, double* IN_FARRAY2 ) {(int lena, int nattr, double* attr)} // Note Fortran ordering + +%exception wrapped_addNParticles { + $action + if (PyErr_Occurred()) SWIG_fail; +} + +%inline %{ +void wrapped_addNParticles(int lenx, double* x, int leny, double* y, int lenz, double* z, + int lenvx, double* vx, int lenvy, double* vy, int lenvz, double* vz, + int lena, int nattr, double* attr, int uniqueparticles) { + if (lenx != leny || lenx != lenz || lenx != lenvx || lenx != lenvy || lenx != lenvz || lenx != lena ) { + PyErr_Format(PyExc_ValueError, + "Lengths of arrays must be the same, (%d, %d, %d, %d, %d, %d, %d)", + lenx, leny, lenz, lenvx, lenvy, lenvz, lena); + return; + } + addNParticles(lenx, x, y, z, vx, vy, vz, nattr, attr, uniqueparticles); +} +%} diff --git a/Source/WarpXWrappers.cpp b/Source/WarpXWrappers.cpp index d2201ef3f..e3f44ef3f 100644 --- a/Source/WarpXWrappers.cpp +++ b/Source/WarpXWrappers.cpp @@ -38,5 +38,10 @@ extern "C" WarpX& warpx = WarpX::GetInstance(); warpx.Evolve(numsteps); } + + void addNParticles(int lenx, double* x, double* y, double* z, double* vx, double* vy, double* vz, int nattr, double* attr, int uniqueparticles) + { + std::cout << "Adding " << lenx << " particles\n"; + } } diff --git a/Source/WarpXWrappers.h b/Source/WarpXWrappers.h index c7a931e94..49f22a349 100644 --- a/Source/WarpXWrappers.h +++ b/Source/WarpXWrappers.h @@ -19,6 +19,8 @@ extern "C" { void warpx_evolve (int numsteps); // -1 means the inputs parameter will be used. + void addNParticles(int lenx, double* x, double* y, double* z, double* vx, double* vy, double* vz, int nattr, double* attr, int uniqueparticles); + #ifdef __cplusplus } #endif -- cgit v1.2.3 From cd911c90649ffce1507ca109e817e2e07fd12dba Mon Sep 17 00:00:00 2001 From: atmyers Date: Thu, 19 Jan 2017 16:49:14 -0800 Subject: Fixing the Python extension installation on Linux. --- Exec/Make.WarpX | 6 +++--- Python/setup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'Python/setup.py') diff --git a/Exec/Make.WarpX b/Exec/Make.WarpX index 5288f4d4b..6dddbc34f 100644 --- a/Exec/Make.WarpX +++ b/Exec/Make.WarpX @@ -45,17 +45,17 @@ ifeq ($(shell uname),Darwin) MY_LINK_LIBRARIES = $(LDFLAGS) $(libraries) else SHARED_OPTION = -shared - MY_LINK_LIBRARIES = + MY_LINK_LIBRARIES = $(LDFLAGS) $(libraries) -lgfortran endif pyinstall: libwarpx.a @echo Making and installing python wrapper ... - LDFLAGS="$(MY_LINK_LIBRARIES)" python setup.py install + LDFLAGS="$(MY_LINK_LIBRARIES)" CC=$(CXX) python setup.py install @echo SUCCESS pybuild: libwarpx.a @echo Making python wrapper ... - LDFLAGS="$(MY_LINK_LIBRARIES)" python setup.py build + LDFLAGS="$(MY_LINK_LIBRARIES)" CC=$(CXX) python setup.py build @echo SUCCESS libwarpx.a: $(objForExecs) diff --git a/Python/setup.py b/Python/setup.py index dd92c5468..c1d2855a4 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -16,7 +16,7 @@ except AttributeError: include_dirs = [numpy_include, '../Source'] example_module = Extension('pywarpx._warpxC', - swig_opts=['-outdir','pywarpx'], + swig_opts=['-c++', '-outdir','pywarpx'], sources=['warpxC.i'], library_dirs=['.'], libraries=['warpx'], -- cgit v1.2.3