From 8b120cc1e629f43834c29e5694f33282f718b82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20St=C3=B6lzle?= Date: Wed, 20 Jul 2022 10:01:29 +0200 Subject: [PATCH] Fix #142 by adjusting data structure of `fixed_positions` and `fixed_directors` (#147) * Fix #142 by changing order of `fixed_positions` and `fixed_directors` * Remove empty initialization of `self.fixed_positions` and `self.fixed_directors` --- elastica/boundary_conditions.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/elastica/boundary_conditions.py b/elastica/boundary_conditions.py index cc8823e5d..9c903eb18 100644 --- a/elastica/boundary_conditions.py +++ b/elastica/boundary_conditions.py @@ -308,8 +308,14 @@ def __init__(self, *fixed_data, **kwargs): else: # TODO: This part is prone to error. break - self.fixed_positions = np.array(pos) - self.fixed_directors = np.array(dir) + + if len(pos) > 0: + # transpose from (blocksize, dim) to (dim, blocksize) + self.fixed_positions = np.array(pos).transpose((1, 0)) + + if len(dir) > 0: + # transpose from (blocksize, dim, dim) to (dim, dim, blocksize) + self.fixed_directors = np.array(dir).transpose((1, 2, 0)) def constrain_values( self, rod: Union[Type[RodBase], Type[RigidBodyBase]], time: float @@ -362,7 +368,7 @@ def nb_constraint_rotational_values( block_size = indices.size for i in range(block_size): k = indices[i] - director_collection[..., k] = fixed_director_collection[i, ...] + director_collection[..., k] = fixed_director_collection[..., i] @staticmethod @njit(cache=True) @@ -385,9 +391,7 @@ def nb_constrain_translational_values( block_size = indices.size for i in range(block_size): k = indices[i] - position_collection[0, k] = fixed_position_collection[i, 0] - position_collection[1, k] = fixed_position_collection[i, 1] - position_collection[2, k] = fixed_position_collection[i, 2] + position_collection[..., k] = fixed_position_collection[..., i] @staticmethod @njit(cache=True)