From df8477a7db46973bc1b28a2ff93b7f6120cd4ccd Mon Sep 17 00:00:00 2001 From: Seung Hyun Kim Date: Tue, 25 Jun 2024 09:30:40 -0500 Subject: [PATCH] bug: fix issue that boudnary condition was not properly beling applied --- elastica/boundary_conditions.py | 18 ++++++++++++------ elastica/modules/constraints.py | 8 +++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/elastica/boundary_conditions.py b/elastica/boundary_conditions.py index 87ce61b2..20c10177 100644 --- a/elastica/boundary_conditions.py +++ b/elastica/boundary_conditions.py @@ -11,7 +11,7 @@ from elastica._linalg import _batch_matvec, _batch_matrix_transpose from elastica._rotations import _get_rotation_matrix -from elastica.typing import SystemType, RodType, RigidBodyType +from elastica.typing import SystemType, RodType, RigidBodyType, ConstrainingIndex S = TypeVar("S") @@ -34,18 +34,24 @@ class ConstraintBase(ABC, Generic[S]): """ _system: S - _constrained_position_idx: np.ndarray - _constrained_director_idx: np.ndarray + _constrained_position_idx: NDArray[np.integer] + _constrained_director_idx: NDArray[np.integer] - def __init__(self, *args: Any, **kwargs: Any) -> None: + def __init__( + self, + *args: Any, + constrained_position_idx: ConstrainingIndex, + constrained_director_idx: ConstrainingIndex, + **kwargs: Any, + ) -> None: """Initialize boundary condition""" try: self._system = kwargs["_system"] self._constrained_position_idx = np.array( - kwargs.get("constrained_position_idx", []), dtype=int + constrained_position_idx, dtype=np.int_ ) self._constrained_director_idx = np.array( - kwargs.get("constrained_director_idx", []), dtype=int + constrained_director_idx, dtype=np.int_ ) except KeyError: raise KeyError( diff --git a/elastica/modules/constraints.py b/elastica/modules/constraints.py index 344306b3..2ba907f0 100644 --- a/elastica/modules/constraints.py +++ b/elastica/modules/constraints.py @@ -215,7 +215,13 @@ def instantiate(self, system: "RodType | RigidBodyType") -> ConstraintBase: ) try: bc = self._bc_cls( - *positions, *directors, *self._args, _system=system, **self._kwargs + *positions, + *directors, + *self._args, + _system=system, + constrained_position_idx=self.constrained_position_idx, + constrained_director_idx=self.constrained_director_idx, + **self._kwargs, ) return bc except (TypeError, IndexError):