enhencement:new tests for rigid body data structur
ers. If only numpy is present we are also testing that possiblity now.
@@ -12,6 +12,8 @@ from elastica.timestepper import (
PositionVerlet,
integrate,
)
+import elastica
+import importlib
def make_simple_system_with_positions_directors(start_position, start_director):
@@ -108,7 +110,7 @@ class TestSteppersAgainstRigidBodyLikeSystems:
# )
@pytest.mark.parametrize("symplectic_stepper", SymplecticSteppers)
- def test_symplectics_against_ellipse_motion(self, symplectic_stepper):
+ def test_symplectics_against_ellipse_motion_with_numba(self, symplectic_stepper):
random_start_position = np.random.randn(3, 1)
random_directors, _ = np.linalg.qr(np.random.randn(3, 3))
@@ -145,3 +147,54 @@ class TestSteppersAgainstRigidBodyLikeSystems:
rtol=Tolerance.rtol() * 1e1,
atol=Tolerance.atol(),
)
+
+ @pytest.mark.parametrize("symplectic_stepper", SymplecticSteppers)
+ def test_symplectics_against_ellipse_motion_with_numpy(
+ self, symplectic_stepper, monkeypatch
+ ):
+ monkeypatch.setenv("IMPORT_TEST_NUMPY", "True", prepend=False)
+ # After changing the import flag reload the modules.
+ importlib.reload(elastica)
+ importlib.reload(elastica.rigidbody.data_structures)
+
+ random_start_position = np.random.randn(3, 1)
+ random_directors, _ = np.linalg.qr(np.random.randn(3, 3))
+ random_directors = random_directors.reshape(3, 3, 1)
+
+ rod_like_system = make_simple_system_with_positions_directors(
+ random_start_position, random_directors
+ )
+ final_time = 1.0
+ n_steps = 1000
+ stepper = symplectic_stepper()
+
+ integrate(stepper, rod_like_system, final_time=final_time, n_steps=n_steps)
+
+ assert_allclose(
+ rod_like_system.position_collection.reshape(3),
+ rod_like_system.analytical_solution("Positions", final_time),
+ rtol=Tolerance.rtol() * 1e1,
+ atol=Tolerance.atol(),
+ )
+
+ assert_allclose(
+ rod_like_system.velocity_collection.reshape(3),
+ rod_like_system.analytical_solution("Velocity", final_time),
+ rtol=Tolerance.rtol() * 1e1,
+ atol=Tolerance.atol(),
+ )
+
+ # Reshaping done in the director collection to prevent numba from
+ # complaining about returning multiple types
+ assert_allclose(
+ rod_like_system.director_collection.reshape(-1, 1),
+ rod_like_system.analytical_solution("Directors", final_time),
+ rtol=Tolerance.rtol() * 1e1,
+ atol=Tolerance.atol(),
+ )
+
+ # Remove the import flag
+ monkeypatch.delenv("IMPORT_TEST_NUMPY")
+ # Reload the elastica after changing flag
+ importlib.reload(elastica)
+ importlib.reload(elastica.rigidbody.data_structures)
