Skip to content

Commit

Permalink
Fix #142 by adjusting data structure of fixed_positions and `fixed_…
Browse files Browse the repository at this point in the history
…directors` (#147)

* Fix #142 by changing order of `fixed_positions` and `fixed_directors`
* Remove empty initialization of `self.fixed_positions` and `self.fixed_directors`
  • Loading branch information
mstoelzle authored Jul 20, 2022
1 parent 5e306ee commit 8b120cc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions elastica/boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8b120cc

Please sign in to comment.