Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions unsupported/__init__.py

This file was deleted.

13 changes: 13 additions & 0 deletions unsupported/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__version__ = "0.1"


import warnings

warnings.warn(
"""\n
The alchemy module is not supported.
Questions should be addressed to sandd@student.unimelb.edu.au \n """
)


from interpolation import *
38 changes: 38 additions & 0 deletions unsupported/utilities/interpolation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from scipy.spatial import cKDTree as kdTree
import numpy as np

def nn_evaluation(_fromCoords, _toCoords, n=1, weighted=False):

"""
This function provides nearest neighbour information for uw swarms,
given the "_toCoords", which could be the .data handle (coordinates) of a mesh or a different swarm,
this function returns the indices of the n nearest neighbours in "_fromCoords" (will usually be swarm.particleCoordinates.data )
it also returns the inverse-distance weights if weighted=True.

The function works in parallel, if the example below is followed


Usage
------------
#get the n indexes, weights and distances
ix, weights, d = nn_evaluation(swarm.particleCoordinates.data, toSwarm.particleCoordinates.data, n=n, weighted=False)

#apply to the 'toSwarm' variable in a parallel-safe way
if len(weights): #parallel safety
toSwarmVar.data[:,0] = np.average(fromSwarmVar.evaluate(fromSwarm)[:,0][ix], weights=weights, axis=len((weights.shape)) - 1)

"""

if len(_toCoords) > 0: #this is required for safety in parallel

tree = kdTree(_fromCoords)
d, ix = tree.query(_toCoords, n)
if n == 1:
weights = np.ones(_toCoords.shape[0])
elif not weighted:
weights = np.ones((_toCoords.shape[0], n))*(1./n)
else:
weights = (1./d[:])/(1./d[:]).sum(axis=1)[:,None]
return ix, weights, d
else:
return np.empty(0, dtype="int"), np.empty(0, dtype="int"), np.empty(0, dtype="int")