-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement slicing for LB #4178
Implement slicing for LB #4178
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Removing unnecessary c variables from population and squeezing output from property boundary so it has the right dimensions
src/python/espressomd/lb.pyx
Outdated
def __init__(self, key): | ||
shape = lb_lbfluid_get_shape() | ||
self.x_indices, self.y_indices, self.z_indices = self.get_indices( | ||
key, shape[0], shape[1], shape[2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, key): | |
shape = lb_lbfluid_get_shape() | |
self.x_indices, self.y_indices, self.z_indices = self.get_indices( | |
key, shape[0], shape[1], shape[2]) | |
def __init__(self, key, shape): | |
self.shape = shape | |
self.x_indices, self.y_indices, self.z_indices = self.get_indices( | |
key, shape[0], shape[1], shape[2]) |
src/python/espressomd/lb.pyx
Outdated
@@ -542,3 +548,137 @@ cdef class LBFluidRoutines: | |||
|
|||
def __set__(self, value): | |||
raise NotImplementedError | |||
|
|||
cdef class LBSlice: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cdef class LBSlice: | |
class LBSlice: |
src/python/espressomd/lb.pyx
Outdated
cdef np.ndarray x_indices | ||
cdef np.ndarray y_indices | ||
cdef np.ndarray z_indices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cdef np.ndarray x_indices | |
cdef np.ndarray y_indices | |
cdef np.ndarray z_indices |
src/python/espressomd/lb.pyx
Outdated
|
||
property density: | ||
def __get__(self): | ||
prop_name = "density" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop_name = "density" |
src/python/espressomd/lb.pyx
Outdated
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3) | ||
|
||
def __set__(self, value): | ||
prop_name = "density" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop_name = "density" |
src/python/espressomd/lb.pyx
Outdated
|
||
property pressure_tensor_neq: | ||
def __get__(self): | ||
prop_name = "pressure_tensor_neq" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop_name = "pressure_tensor_neq" |
src/python/espressomd/lb.pyx
Outdated
|
||
property population: | ||
def __get__(self): | ||
prop_name = "population" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop_name = "population" |
src/python/espressomd/lb.pyx
Outdated
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res) | ||
|
||
def __set__(self, value): | ||
prop_name = "population" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop_name = "population" |
src/python/espressomd/lb.pyx
Outdated
property boundary: | ||
def __get__(self): | ||
shape_res = (1,) | ||
prop_name = "boundary" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop_name = "boundary" |
src/python/espressomd/lb.pyx
Outdated
property density: | ||
def __get__(self): | ||
prop_name = "density" | ||
shape_res = (1,) | ||
return np.squeeze(self.get_values( | ||
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3) | ||
|
||
def __set__(self, value): | ||
prop_name = "density" | ||
self.set_values( | ||
self.x_indices, | ||
self.y_indices, | ||
self.z_indices, | ||
prop_name, | ||
value) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property density: | |
def __get__(self): | |
prop_name = "density" | |
shape_res = (1,) | |
return np.squeeze(self.get_values( | |
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3) | |
def __set__(self, value): | |
prop_name = "density" | |
self.set_values( | |
self.x_indices, | |
self.y_indices, | |
self.z_indices, | |
prop_name, | |
value) | |
@property | |
def density(self): | |
prop_name = "density" | |
shape_res = (1,) | |
return np.squeeze(self.get_values( | |
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3) | |
@density.setter | |
def density(self, value): | |
self.set_values( | |
self.x_indices, | |
self.y_indices, | |
self.z_indices, | |
prop_name, | |
value) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the modern python syntax for properties
@KaiserMartin Here is the result of applying Kai's review: jngrad/espresso@fix-4143 (diff view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR ready for merge from my side.
please don't merge it yet, we're looking into a simplification using a python reflection |
The |
I accidentally pushed the
GitHub also closed the PR using my username. Moving over to #4195. Sorry for the inconvenience. |
Fixes #4143
Description of changes:
The output is a multidimensional array containing the requested quantity and is of dimension len(slice_x)*len(slice_y)*len(slice_z)*len(quantity), where len(quantity) is the dimensions of the quantity, for example 3 in case of velocity. The output array is arranged in the way numpy cycles through slices. Therefore, when setting attributes one has to set the dimensions of the input array exactly the same way numpy cycles through the sliced nodes.
An error is issued if the dimensions of the slices and the input does not match.