Skip to content

Commit

Permalink
Merged in prabhuramachandran/pysph/fix-bugs (pull request #172)
Browse files Browse the repository at this point in the history
Fix a bunch of issues
  • Loading branch information
prabhuramachandran committed May 22, 2015
2 parents 29280fc + 0c0a621 commit d851707
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 83 deletions.
4 changes: 2 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Core dependencies
The core dependencies are:

- NumPy_
- Cython_ (version 0.19 and above)
- Cython_ (version 0.20 and above)
- Mako_
- nose_ for running the unit tests.

Expand Down Expand Up @@ -184,7 +184,7 @@ On OS X, your best bet is to install `Enthought Canopy`_ or Anaconda_ or some
other Python distribution. Ensure that you have gcc or clang installed by
installing XCode. See `this
<http://stackoverflow.com/questions/12228382/after-install-xcode-where-is-clang>`_
if you installed XCode but can't find clang or gcc.
if you installed XCode but can't find clang or gcc.

^^^^^^^^^^^^^
OpenMP on OSX
Expand Down
2 changes: 1 addition & 1 deletion pysph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See PEP 440 for more on suitable version numbers.
__version__ = '1.0a1.dev'
__version__ = '1.0a1.dev0'


# Conditional Imports for Parallel stuff
Expand Down
7 changes: 6 additions & 1 deletion pysph/sph/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ class Context(dict):
>>> c.keys()
['a', 'x', 'b']
"""
__getattr__ = dict.__getitem__
def __getattr__(self, key):
try:
return self.__getitem__(key)
except KeyError:
raise AttributeError('Context has no attribute %s'%key)

def __setattr__(self, key, value):
self[key] = value

Expand Down
77 changes: 48 additions & 29 deletions pysph/tools/interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,29 @@ class Interpolator(object):
"""

def __init__(self, particle_arrays, num_points=125000, kernel=None,
x=None, y=None, z=None):
x=None, y=None, z=None, domain_manager=None):
"""
Parameters
----------
particle_arrays: A list of particle arrays.
num_points: the number of points to interpolate on to.
kernel: the kernel to use for interpolation.
x: ndarray: the x-coordinate of points on which to interpolate.
y: ndarray: the y-coordinate of points on which to interpolate.
z: ndarray: the z-coordinate of points on which to interpolate.
The x, y, z coordinates need not be specified, and if they are not,
the bounds of the interpolated domain is automatically computed and
`num_points` number of points are used in this domain uniformly placed.
Parameters
----------
particle_arrays: list
A list of particle arrays.
num_points: int
the number of points to interpolate on to.
kernel: Kernel
the kernel to use for interpolation.
x: ndarray
the x-coordinate of points on which to interpolate.
y: ndarray
the y-coordinate of points on which to interpolate.
z: ndarray
the z-coordinate of points on which to interpolate.
domain_manager: DomainManager
An optional Domain manager for periodic domains.
"""
self._set_particle_arrays(particle_arrays)
bounds = get_bounding_box(self.particle_arrays)
Expand All @@ -109,6 +114,7 @@ def __init__(self, particle_arrays, num_points=125000, kernel=None,
self.pa = None
self.nnps = None
self.func_eval = None
self.domain_manager = domain_manager
if x is None and y is None and z is None:
self.set_domain(bounds, shape)
else:
Expand All @@ -118,16 +124,20 @@ def __init__(self, particle_arrays, num_points=125000, kernel=None,
def set_interpolation_points(self, x=None, y=None, z=None):
"""Set the points on which we must interpolate the arrays.
Parameters
-----------
x: ndarray: the x-coordinate of points on which to interpolate.
y: ndarray: the y-coordinate of points on which to interpolate.
z: ndarray: the z-coordinate of points on which to interpolate.
If any of x, y, z is not passed it is assumed to be 0.0 and shaped
like the other non-None arrays.
Parameters
----------
x: ndarray
the x-coordinate of points on which to interpolate.
y: ndarray
the y-coordinate of points on which to interpolate.
z: ndarray
the z-coordinate of points on which to interpolate.
"""
tmp = None
for tmp in (x, y, z):
Expand All @@ -153,26 +163,34 @@ def _get_array(_t):
def set_domain(self, bounds, shape):
"""Set the domain to interpolate into.
Parameters:
-----------
Parameters
----------
bounds: (xmin, xmax, ymin, ymax, zmin, zmax)
shape: (nx, ny, nz)
bounds: tuple
(xmin, xmax, ymin, ymax, zmin, zmax)
shape: tuple
(nx, ny, nz)
"""
self.bounds = np.asarray(bounds)
self.shape = np.asarray(shape)
x, y, z = self._create_default_points(self.bounds, self.shape)
self.set_interpolation_points(x, y, z)

def interpolate(self, prop, gradient=False):
"""
"""Interpolate given property.
Parameters
----------
:prop: The name of the property to interpolate.
prop: str
The name of the property to interpolate.
:gradient: bool: Evaluate gradient and not function.
gradient: bool
Evaluate gradient and not function.
:return: A numpy array suitably shaped with the property
interpolated.
Returns
-------
A numpy array suitably shaped with the property interpolated.
"""
for array in self.particle_arrays:
data = array.get(prop, only_real_particles=False)
Expand Down Expand Up @@ -202,6 +220,7 @@ def _create_nnps(self, arrays):
# create the neighbor locator object
self.nnps = NNPS(dim=self.kernel.dim, particles=arrays,
radius_scale=self.kernel.radius_scale,
domain=self.domain_manager,
cache=True)
self.nnps.update()
self.func_eval.set_nnps(self.nnps)
Expand Down
6 changes: 2 additions & 4 deletions pyzoltan/core/carray.pxd
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# This file (carray.pxd) has been generated automatically on
# Sat May 16 00:36:51 2015
# This file (carray.pxd) has been generated automatically.
# DO NOT modify this file
# To make changes modify the source templates (carray.pxd.mako) and regenerate
"""
Implementation of arrays of different types in Cython.
Implementation of resizeable arrays of different types in Cython.
Declaration File.
Expand Down Expand Up @@ -201,4 +200,3 @@ cdef class DoubleArray(BaseArray):
cpdef reset(self)
cpdef long index(self, double value)


8 changes: 2 additions & 6 deletions pyzoltan/core/carray.pxd.mako
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<%
import datetime
now = datetime.datetime.now()
type_info = [
('int', 'IntArray', 'NPY_INT'),
('unsigned int', 'UIntArray', 'NPY_UINT'),
('long', 'LongArray', 'NPY_LONG'),
('float', 'FloatArray', 'NPY_FLOAT'),
('double', 'DoubleArray', 'NPY_DOUBLE'),
]
%># This file (carray.pxd) has been generated automatically on
# ${now.strftime('%c')}
%># This file (carray.pxd) has been generated automatically.
# DO NOT modify this file
# To make changes modify the source templates (carray.pxd.mako) and regenerate
"""
Implementation of arrays of different types in Cython.
Implementation of resizeable arrays of different types in Cython.

Declaration File.

Expand Down Expand Up @@ -93,4 +90,3 @@ cdef class ${CLASSNAME}(BaseArray):
cpdef long index(self, ${ARRAY_TYPE} value)

% endfor

6 changes: 2 additions & 4 deletions pyzoltan/core/carray.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This file (carray.pxd) has been generated automatically on
# Sat May 16 01:28:08 2015
# This file (carray.pxd) has been generated automatically.
# DO NOT modify this file
# To make changes modify the source templates (carray_pxd.src) and regenerate
# To make changes modify the source templates (carray.pxd.mako) and regenerate
"""
Implementation of resizeable arrays of different types in Cython.
Expand Down Expand Up @@ -2300,4 +2299,3 @@ cdef class DoubleArray(BaseArray):
self.minimum = min_val
self.maximum = max_val


10 changes: 2 additions & 8 deletions pyzoltan/core/carray.pyx.mako
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<%
import datetime
now = datetime.datetime.now()
type_info = [
('int', 'IntArray', 'NPY_INT'),
('unsigned int', 'UIntArray', 'NPY_UINT'),
('long', 'LongArray', 'NPY_LONG'),
('float', 'FloatArray', 'NPY_FLOAT'),
('double', 'DoubleArray', 'NPY_DOUBLE'),
]
%># This file (carray.pxd) has been generated automatically on
# ${now.strftime('%c')}
## The section below is the header section which is copied unmodified into
## the generated file
%># This file (carray.pxd) has been generated automatically.
# DO NOT modify this file
# To make changes modify the source templates (carray_pxd.src) and regenerate
# To make changes modify the source templates (carray.pxd.mako) and regenerate
"""
Implementation of resizeable arrays of different types in Cython.

Expand Down Expand Up @@ -682,4 +677,3 @@ cdef class ${CLASSNAME}(BaseArray):
self.maximum = max_val

% endfor

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
numpy
setuptools
Cython>=0.19
Cython>=0.20
mako
nose
80 changes: 53 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from setuptools import find_packages, setup
from Cython.Distutils import build_ext, Extension

Have_MPI = True
HAVE_MPI = True
try:
import mpi4py
except ImportError:
Have_MPI = False
HAVE_MPI = False

USE_ZOLTAN=True

Expand All @@ -23,10 +23,6 @@
extra_compile_args = []


mpi_inc_dirs = []
mpi_compile_args = []
mpi_link_args = []

def get_deps(*args):
"""Given a list of basenames, this checks if a .pyx or .pxd exists
and returns the list.
Expand Down Expand Up @@ -114,24 +110,47 @@ def get_zoltan_directory(varname):
return d


openmp_compile_args, openmp_link_args, openmp_env = get_openmp_flags()

if Have_MPI:
mpic = 'mpic++'
if compiler == 'intel':
link_args = check_output([mpic, '-cc=icc', '-link_info']).strip()
link_args = link_args[3:]
compile_args = check_output(
[mpic, '-cc=icc', '-compile_info']
).strip()
compile_args = compile_args[3:]
def get_mpi_flags():
"""Returns mpi_inc_dirs, mpi_compile_args, mpi_link_args.
"""
global HAVE_MPI
mpi_inc_dirs = []
mpi_compile_args = []
mpi_link_args = []
if not HAVE_MPI:
return mpi_inc_dirs, mpi_compile_args, mpi_link_args
try:
mpic = 'mpic++'
if compiler == 'intel':
link_args = check_output([mpic, '-cc=icc', '-link_info']).strip()
link_args = link_args[3:]
compile_args = check_output(
[mpic, '-cc=icc', '-compile_info']
).strip()
compile_args = compile_args[3:]
else:
link_args = check_output([mpic, '--showme:link']).strip()
compile_args = check_output([mpic, '--showme:compile']).strip()
except:
print '-'*80
print "Unable to run mpic++ correctly, skipping parallel build"
print '-'*80
HAVE_MPI = False
else:
link_args = check_output([mpic, '--showme:link']).strip()
compile_args = check_output([mpic, '--showme:compile']).strip()
mpi_link_args.extend(link_args.split())
mpi_compile_args.extend(compile_args.split())
mpi_inc_dirs.append(mpi4py.get_include())
mpi_link_args.extend(link_args.split())
mpi_compile_args.extend(compile_args.split())
mpi_inc_dirs.append(mpi4py.get_include())

return mpi_inc_dirs, mpi_compile_args, mpi_link_args


def get_zoltan_args():
"""Returns zoltan_include_dirs, zoltan_library_dirs
"""
global HAVE_MPI
zoltan_include_dirs, zoltan_library_dirs = [], []
if not HAVE_MPI:
return zoltan_include_dirs, zoltan_library_dirs
# First try with the environment variable 'ZOLTAN'
zoltan_base = get_zoltan_directory('ZOLTAN')
inc = lib = ''
Expand All @@ -148,10 +167,9 @@ def get_zoltan_directory(varname):

if (not USE_ZOLTAN):
print("*"*80)
print("Zoltan Environment variable" \
"not set, not using ZOLTAN!")
print("Zoltan Environment variable not set, not using ZOLTAN!")
print("*"*80)
Have_MPI = False
HAVE_MPI = False
else:
print('-'*70)
print("Using Zoltan from:\n%s\n%s"%(inc, lib))
Expand All @@ -163,6 +181,14 @@ def get_zoltan_directory(varname):
zoltan_cython_include = [ os.path.abspath('./pyzoltan/czoltan') ]
zoltan_include_dirs += zoltan_cython_include

return zoltan_include_dirs, zoltan_library_dirs


openmp_compile_args, openmp_link_args, openmp_env = get_openmp_flags()
mpi_inc_dirs, mpi_compile_args, mpi_link_args = get_mpi_flags()
zoltan_include_dirs, zoltan_library_dirs = get_zoltan_args()


include_dirs = [numpy.get_include()]

cmdclass = {'build_ext': build_ext}
Expand Down Expand Up @@ -227,7 +253,7 @@ def get_zoltan_directory(varname):
for ext in ext_modules:
ext.include_dirs = include_dirs

if Have_MPI:
if HAVE_MPI:
zoltan_modules = [
Extension(
name="pyzoltan.core.zoltan",
Expand Down Expand Up @@ -338,7 +364,7 @@ def get_zoltan_directory(varname):
ext_modules = ext_modules,
include_package_data = True,
cmdclass=cmdclass,
install_requires = ['numpy', 'mako', 'Cython>=0.19'],
install_requires = ['numpy', 'mako', 'Cython>=0.20'],
extras_require = extras_require,
zip_safe = False,
entry_points = """
Expand Down

0 comments on commit d851707

Please sign in to comment.