From f320541433a2f19ea91bf9459f4e94aaa61f32dc Mon Sep 17 00:00:00 2001 From: Arman Tekinalp <53585636+armantekinalp@users.noreply.github.com> Date: Mon, 20 Feb 2023 14:16:04 -0600 Subject: [PATCH 1/8] Update: README.md include cite information via Zenodo --- README.md | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 90f2ab82..56c09c12 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

PyElastica

-[![Build_status][badge-travis]][link-travis] [![CI][badge-CI]][link-CI] [![Documentation Status][badge-docs-status]][link-docs-status] [![codecov][badge-codecov]][link-codecov] [![Downloads][badge-pepy-download-count]][link-pepy-download-count] [![Binder][badge-binder]][link-binder] [![Gitter][badge-gitter]][link-gitter] +[![Build_status][badge-travis]][link-travis] [![CI][badge-CI]][link-CI] [![Documentation Status][badge-docs-status]][link-docs-status] [![codecov][badge-codecov]][link-codecov] [![Downloads][badge-pepy-download-count]][link-pepy-download-count] [![DOI][badge-doi]][link-doi] [![Binder][badge-binder]][link-binder] [![Gitter][badge-gitter]][link-gitter]
PyElastica is the python implementation of **Elastica**: an *open-source* project for simulating assemblies of slender, one-dimensional structures using Cosserat Rod theory. @@ -26,12 +26,23 @@ Documentation of PyElastica is available [here][link-docs-website]. We ask that any publications which use Elastica cite as following: ``` -@misc{tekinalp2022pyelastica, - title={PyElastica: A computational framework for Cosserat rod assemblies}, - author={Tekinalp, Arman and Kim, Seung Hyun and Parthasarathy, Tejaswin and Bhosale, Yashraj}, - journal={https://github.com/GazzolaLab/PyElastica}, - year={2022}, - publisher={GitHub} +@software{arman_tekinalp_2023_7658872, + author = {Arman Tekinalp and + Seung Hyun Kim and + Yashraj Bhosale and + Tejaswin Parthasarathy and + Noel Naughton and + Maximilian Stölzle and + Zhi Dou and + Chia-Hsien (Cathy) Shih and + Mattia Gazzola}, + title = {PyElastica}, + month = feb, + year = 2023, + publisher = {Zenodo}, + version = {v0.3.0.post1}, + doi = {10.5281/zenodo.7658872}, + url = {https://doi.org/10.5281/zenodo.7658872} } ``` @@ -91,6 +102,7 @@ _Names arranged alphabetically_ [badge-pepy-download-count]: https://pepy.tech/badge/pyelastica [badge-codecov]: https://codecov.io/gh/GazzolaLab/PyElastica/branch/master/graph/badge.svg [badge-gitter]: https://badges.gitter.im/PyElastica/community.svg +[badge-doi]: https://zenodo.org/badge/254172891.svg [link-pypi]: https://badge.fury.io/py/pyelastica [link-travis]: https://travis-ci.com/github/GazzolaLab/PyElastica [link-CI]: https://github.com/GazzolaLab/PyElastica/actions @@ -101,3 +113,4 @@ _Names arranged alphabetically_ [badge-binder-tutorial]: https://img.shields.io/badge/Launch-PyElastica%20Tutorials-579ACA.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJXmsrfZ4TuhWn1olL1olJXmsqBi7X1olJXmspZmslbmMhbmsdemsVfl8ZgmsNim8Jpk8F0m7R4m7F5nLB6jbh7jbiDirOEibOGnKaMhq+PnaCVg6qWg6qegKaff6WhnpKofKGtnomxeZy3noG6dZi+n3vCcpPDcpPGn3bLb4/Mb47UbIrVa4rYoGjdaIbeaIXhoWHmZYHobXvpcHjqdHXreHLroVrsfG/uhGnuh2bwj2Hxk17yl1vzmljzm1j0nlX1olL3AJXWAAAAbXRSTlMAEBAQHx8gICAuLjAwMDw9PUBAQEpQUFBXV1hgYGBkcHBwcXl8gICAgoiIkJCQlJicnJ2goKCmqK+wsLC4usDAwMjP0NDQ1NbW3Nzg4ODi5+3v8PDw8/T09PX29vb39/f5+fr7+/z8/Pz9/v7+zczCxgAABC5JREFUeAHN1ul3k0UUBvCb1CTVpmpaitAGSLSpSuKCLWpbTKNJFGlcSMAFF63iUmRccNG6gLbuxkXU66JAUef/9LSpmXnyLr3T5AO/rzl5zj137p136BISy44fKJXuGN/d19PUfYeO67Znqtf2KH33Id1psXoFdW30sPZ1sMvs2D060AHqws4FHeJojLZqnw53cmfvg+XR8mC0OEjuxrXEkX5ydeVJLVIlV0e10PXk5k7dYeHu7Cj1j+49uKg7uLU61tGLw1lq27ugQYlclHC4bgv7VQ+TAyj5Zc/UjsPvs1sd5cWryWObtvWT2EPa4rtnWW3JkpjggEpbOsPr7F7EyNewtpBIslA7p43HCsnwooXTEc3UmPmCNn5lrqTJxy6nRmcavGZVt/3Da2pD5NHvsOHJCrdc1G2r3DITpU7yic7w/7Rxnjc0kt5GC4djiv2Sz3Fb2iEZg41/ddsFDoyuYrIkmFehz0HR2thPgQqMyQYb2OtB0WxsZ3BeG3+wpRb1vzl2UYBog8FfGhttFKjtAclnZYrRo9ryG9uG/FZQU4AEg8ZE9LjGMzTmqKXPLnlWVnIlQQTvxJf8ip7VgjZjyVPrjw1te5otM7RmP7xm+sK2Gv9I8Gi++BRbEkR9EBw8zRUcKxwp73xkaLiqQb+kGduJTNHG72zcW9LoJgqQxpP3/Tj//c3yB0tqzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC [link-binder]: https://mybinder.org/v2/gh/GazzolaLab/PyElastica/master?filepath=examples%2FBinder%2F0_PyElastica_Tutorials_Overview.ipynb [link-gitter]: https://gitter.im/PyElastica/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +[link-doi]: https://zenodo.org/badge/latestdoi/254172891 From 7b3fe2d0204a175c9e5e64265c70b9577b4ca8c9 Mon Sep 17 00:00:00 2001 From: Arman Tekinalp <53585636+armantekinalp@users.noreply.github.com> Date: Wed, 22 Feb 2023 17:11:53 -0600 Subject: [PATCH 2/8] Update Readme citation title --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56c09c12..5e52b6ad 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,9 @@ We ask that any publications which use Elastica cite as following: Zhi Dou and Chia-Hsien (Cathy) Shih and Mattia Gazzola}, - title = {PyElastica}, + title = {{PyElastica: Open-source software for the + simulation of assemblies of slender, one- + dimensional structures using Cosserat Rod theory}}, month = feb, year = 2023, publisher = {Zenodo}, From 2b7f59628fce36ac44acdd20a463708dd253f744 Mon Sep 17 00:00:00 2001 From: AsadNizami Date: Mon, 27 Mar 2023 23:13:17 +0530 Subject: [PATCH 3/8] Wildcard imports removed --- .../AxialStretchingCase/axial_stretching.py | 22 +++++----- .../general_constraint_allow_yaw.py | 28 ++++++++----- examples/ButterflyCase/butterfly.py | 16 ++++---- .../continuum_flagella.py | 24 ++++++----- .../ContinuumSnakeCase/continuum_snake.py | 26 ++++++------ .../generic_system_type_fixed_joint.py | 39 ++++++++++-------- .../generic_system_type_spherical_joint.py | 39 ++++++++++-------- .../parallel_connection_example.py | 35 +++++++++------- .../flexible_swinging_pendulum.py | 21 +++++----- .../FrictionValidationCases/axial_friction.py | 18 ++++---- .../rolling_friction_initial_velocity.py | 18 ++++---- .../rolling_friction_on_inclined_plane.py | 16 ++++---- .../rolling_friction_torque.py | 20 +++++---- .../convergence_helicalbuckling.py | 16 ++++---- .../HelicalBucklingCase/helicalbuckling.py | 16 ++++---- examples/JointCases/fixed_joint.py | 35 +++++++++------- examples/JointCases/fixed_joint_torsion.py | 35 +++++++++------- examples/JointCases/hinge_joint.py | 35 +++++++++------- examples/JointCases/spherical_joint.py | 35 +++++++++------- .../MuscularFlagella/muscular_flagella.py | 29 +++++++------ examples/MuscularSnake/muscular_snake.py | 37 +++++++++-------- examples/RestartExample/restart_example.py | 20 ++++----- .../rod_cylinder_contact.py | 33 ++++++++------- .../rod_cylinder_contact_friction.py | 41 +++++++++++-------- .../rod_cylinder_contact_validation.py | 29 +++++++------ .../rod_cylinder_contact_with_y_normal.py | 29 +++++++------ .../rigid_cylinder_rotational_motion_case.py | 20 +++++---- ...igid_cylinder_translational_motion_case.py | 20 +++++---- .../rigid_sphere_rotational_motion_case.py | 20 +++++---- .../rigid_sphere_translational_motion_case.py | 20 +++++---- .../rod_rod_contact_inclined_validation.py | 31 ++++++++------ .../rod_rod_contact_parallel_validation.py | 31 ++++++++------ .../PlectonemesCase/plectoneme_case.py | 38 ++++++++--------- .../SolenoidsCase/solenoid_case.py | 35 +++++++++------- .../convergence_timoshenko.py | 28 +++++++------ examples/TimoshenkoBeamCase/timoshenko.py | 30 +++++++------- 36 files changed, 548 insertions(+), 437 deletions(-) diff --git a/examples/AxialStretchingCase/axial_stretching.py b/examples/AxialStretchingCase/axial_stretching.py index 53e1478e..e9383202 100644 --- a/examples/AxialStretchingCase/axial_stretching.py +++ b/examples/AxialStretchingCase/axial_stretching.py @@ -26,11 +26,11 @@ import numpy as np from matplotlib import pyplot as plt -from elastica import * +import elastica as ea class StretchingBeamSimulator( - BaseSystemCollection, Constraints, Forcing, Damping, CallBacks + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping, ea.CallBacks ): pass @@ -57,7 +57,7 @@ class StretchingBeamSimulator( poisson_ratio = 0.5 shear_modulus = youngs_modulus / (poisson_ratio + 1.0) -stretchable_rod = CosseratRod.straight_rod( +stretchable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -72,13 +72,13 @@ class StretchingBeamSimulator( stretch_sim.append(stretchable_rod) stretch_sim.constrain(stretchable_rod).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) end_force_x = 1.0 end_force = np.array([end_force_x, 0.0, 0.0]) stretch_sim.add_forcing_to(stretchable_rod).using( - EndpointForces, 0.0 * end_force, end_force, ramp_up_time=1e-2 + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=1e-2 ) # add damping @@ -89,19 +89,19 @@ class StretchingBeamSimulator( dt = 0.1 * dl damping_constant = 0.1 stretch_sim.dampen(stretchable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) # Add call backs -class AxialStretchingCallBack(CallBackBaseClass): +class AxialStretchingCallBack(ea.CallBackBaseClass): """ Tracks the velocity norms of the rod """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -120,18 +120,18 @@ def make_callback(self, system, time, current_step: int): return -recorded_history = defaultdict(list) +recorded_history = ea.defaultdict(list) stretch_sim.collect_diagnostics(stretchable_rod).using( AxialStretchingCallBack, step_skip=200, callback_params=recorded_history ) stretch_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, stretch_sim, final_time, total_steps) +ea.integrate(timestepper, stretch_sim, final_time, total_steps) if PLOT_FIGURE: # First-order theory with base-length diff --git a/examples/BoundaryConditionsCases/general_constraint_allow_yaw.py b/examples/BoundaryConditionsCases/general_constraint_allow_yaw.py index 35356588..94cd0bcb 100644 --- a/examples/BoundaryConditionsCases/general_constraint_allow_yaw.py +++ b/examples/BoundaryConditionsCases/general_constraint_allow_yaw.py @@ -1,7 +1,8 @@ __doc__ = """Fixed joint example, for detailed explanation refer to Zhang et. al. Nature Comm. methods section.""" import numpy as np -from elastica import * +import elastica as ea + from examples.BoundaryConditionsCases.bc_cases_postprocessing import ( plot_position, plot_orientation, @@ -12,7 +13,12 @@ class GeneralConstraintSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -43,7 +49,7 @@ class GeneralConstraintSimulator( start_rod_2 = start_rod_1 + direction * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -59,7 +65,7 @@ class GeneralConstraintSimulator( # Apply boundary conditions to rod1: only allow yaw general_constraint_sim.constrain(rod1).using( - GeneralConstraint, + ea.GeneralConstraint, constrained_position_idx=(0,), constrained_director_idx=(0,), translational_constraint_selector=np.array([True, True, True]), @@ -68,37 +74,37 @@ class GeneralConstraintSimulator( # add forces to endpoint general_constraint_sim.add_forcing_to(rod1).using( - EndpointForces, + ea.EndpointForces, start_force=np.zeros((3,)), end_force=1e-0 * np.ones((3,)), ramp_up_time=0.5, ) # add uniform torsion torque general_constraint_sim.add_forcing_to(rod1).using( - UniformTorques, torque=1e-3, direction=np.array([0, 0, 1]) + ea.UniformTorques, torque=1e-3, direction=np.array([0, 0, 1]) ) # add damping damping_constant = 0.4 general_constraint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) general_constraint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=diagnostic_step_skip, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=diagnostic_step_skip, callback_params=pp_list_rod1 ) general_constraint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() print("Total steps", total_steps) -integrate(timestepper, general_constraint_sim, final_time, total_steps) +ea.integrate(timestepper, general_constraint_sim, final_time, total_steps) plot_orientation( diff --git a/examples/ButterflyCase/butterfly.py b/examples/ButterflyCase/butterfly.py index 8233c24d..9e28601d 100644 --- a/examples/ButterflyCase/butterfly.py +++ b/examples/ButterflyCase/butterfly.py @@ -3,11 +3,11 @@ from matplotlib.colors import to_rgb -from elastica import * +import elastica as ea from elastica.utils import MaxDimension -class ButterflySimulator(BaseSystemCollection, CallBacks): +class ButterflySimulator(ea.BaseSystemCollection, ea.CallBacks): pass @@ -60,7 +60,7 @@ class ButterflySimulator(BaseSystemCollection, CallBacks): - np.sin(angle_of_inclination) * vertical_direction ) -butterfly_rod = CosseratRod.straight_rod( +butterfly_rod = ea.CosseratRod.straight_rod( n_elem, start=origin.reshape(3), direction=np.array([0.0, 0.0, 1.0]), @@ -77,13 +77,13 @@ class ButterflySimulator(BaseSystemCollection, CallBacks): butterfly_sim.append(butterfly_rod) # Add call backs -class VelocityCallBack(CallBackBaseClass): +class VelocityCallBack(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -102,7 +102,7 @@ def make_callback(self, system, time, current_step: int): return -recorded_history = defaultdict(list) +recorded_history = ea.defaultdict(list) # initially record history recorded_history["time"].append(0.0) recorded_history["position"].append(butterfly_rod.position_collection.copy()) @@ -117,13 +117,13 @@ def make_callback(self, system, time, current_step: int): butterfly_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() dt = 0.01 * dl total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, butterfly_sim, final_time, total_steps) +ea.integrate(timestepper, butterfly_sim, final_time, total_steps) if PLOT_FIGURE: # Plot the histories diff --git a/examples/ContinuumFlagellaCase/continuum_flagella.py b/examples/ContinuumFlagellaCase/continuum_flagella.py index 1c8d8027..6038ee5f 100644 --- a/examples/ContinuumFlagellaCase/continuum_flagella.py +++ b/examples/ContinuumFlagellaCase/continuum_flagella.py @@ -3,7 +3,7 @@ import numpy as np import os -from elastica import * +import elastica as ea from examples.ContinuumFlagellaCase.continuum_flagella_postprocessing import ( plot_velocity, plot_video, @@ -11,7 +11,9 @@ ) -class FlagellaSimulator(BaseSystemCollection, Constraints, Forcing, Damping, CallBacks): +class FlagellaSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping, ea.CallBacks +): pass @@ -33,7 +35,7 @@ def run_flagella( poisson_ratio = 0.5 shear_modulus = E / (poisson_ratio + 1.0) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -53,7 +55,7 @@ def run_flagella( # Head and tail control points are zero. control_points = np.hstack((0, b_coeff[:-1], 0)) flagella_sim.add_forcing_to(shearable_rod).using( - MuscleTorques, + ea.MuscleTorques, base_length=base_length, b_coeff=control_points, period=period, @@ -72,7 +74,7 @@ def run_flagella( fluid_density * base_length * base_length / (period * reynolds_number) ) flagella_sim.add_forcing_to(shearable_rod).using( - SlenderBodyTheory, dynamic_viscosity=dynamic_viscosity + ea.SlenderBodyTheory, dynamic_viscosity=dynamic_viscosity ) # add damping @@ -82,19 +84,19 @@ def run_flagella( damping_constant = 0.625 dt = 1e-4 * period flagella_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) # Add call backs - class ContinuumFlagellaCallBack(CallBackBaseClass): + class ContinuumFlagellaCallBack(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -119,19 +121,19 @@ def make_callback(self, system, time, current_step: int): return - pp_list = defaultdict(list) + pp_list = ea.defaultdict(list) flagella_sim.collect_diagnostics(shearable_rod).using( ContinuumFlagellaCallBack, step_skip=200, callback_params=pp_list ) flagella_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() # timestepper = PEFRL() final_time = (10.0 + 0.01) * period total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, flagella_sim, final_time, total_steps) + ea.integrate(timestepper, flagella_sim, final_time, total_steps) if PLOT_FIGURE: filename_plot = "continuum_flagella_velocity.png" diff --git a/examples/ContinuumSnakeCase/continuum_snake.py b/examples/ContinuumSnakeCase/continuum_snake.py index 9f19f595..2c03118a 100644 --- a/examples/ContinuumSnakeCase/continuum_snake.py +++ b/examples/ContinuumSnakeCase/continuum_snake.py @@ -2,7 +2,7 @@ import os import numpy as np -from elastica import * +import elastica as ea from examples.ContinuumSnakeCase.continuum_snake_postprocessing import ( plot_snake_velocity, @@ -12,7 +12,9 @@ ) -class SnakeSimulator(BaseSystemCollection, Constraints, Forcing, Damping, CallBacks): +class SnakeSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping, ea.CallBacks +): pass @@ -38,7 +40,7 @@ def run_snake( poisson_ratio = 0.5 shear_modulus = E / (poisson_ratio + 1.0) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -56,13 +58,13 @@ def run_snake( # Add gravitational forces gravitational_acc = -9.80665 snake_sim.add_forcing_to(shearable_rod).using( - GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) + ea.GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) ) # Add muscle torques wave_length = b_coeff[-1] snake_sim.add_forcing_to(shearable_rod).using( - MuscleTorques, + ea.MuscleTorques, base_length=base_length, b_coeff=b_coeff[:-1], period=period, @@ -85,7 +87,7 @@ def run_snake( ) # [forward, backward, sideways] static_mu_array = np.zeros(kinetic_mu_array.shape) snake_sim.add_forcing_to(shearable_rod).using( - AnisotropicFrictionalPlane, + ea.AnisotropicFrictionalPlane, k=1.0, nu=1e-6, plane_origin=origin_plane, @@ -102,7 +104,7 @@ def run_snake( damping_constant = 2e-3 time_step = 1e-4 snake_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=time_step, ) @@ -112,13 +114,13 @@ def run_snake( step_skip = int(1.0 / (rendering_fps * time_step)) # Add call backs - class ContinuumSnakeCallBack(CallBackBaseClass): + class ContinuumSnakeCallBack(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -145,15 +147,15 @@ def make_callback(self, system, time, current_step: int): return - pp_list = defaultdict(list) + pp_list = ea.defaultdict(list) snake_sim.collect_diagnostics(shearable_rod).using( ContinuumSnakeCallBack, step_skip=step_skip, callback_params=pp_list ) snake_sim.finalize() - timestepper = PositionVerlet() - integrate(timestepper, snake_sim, final_time, total_steps) + timestepper = ea.PositionVerlet() + ea.integrate(timestepper, snake_sim, final_time, total_steps) if PLOT_FIGURE: filename_plot = "continuum_snake_velocity.png" diff --git a/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_fixed_joint.py b/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_fixed_joint.py index d338b2a2..97ea44b0 100644 --- a/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_fixed_joint.py +++ b/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_fixed_joint.py @@ -1,7 +1,7 @@ __doc__ = """Fixed joint example, for detailed explanation refer to Zhang et. al. Nature Comm. methods section.""" import numpy as np -from elastica import * +import elastica as ea from elastica.experimental.connection_contact_joint.generic_system_type_connection import ( GenericSystemTypeFixedJoint, ) @@ -14,7 +14,12 @@ class FixedJointSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -45,7 +50,7 @@ class FixedJointSimulator( start_cylinder = start_rod_2 + direction * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -59,7 +64,7 @@ class FixedJointSimulator( ) fixed_joint_sim.append(rod1) # Create rod 2 -rod2 = CosseratRod.straight_rod( +rod2 = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction, @@ -72,7 +77,7 @@ class FixedJointSimulator( shear_modulus=shear_modulus, ) fixed_joint_sim.append(rod2) -cylinder = Cylinder( +cylinder = ea.Cylinder( start=start_cylinder, direction=direction, normal=normal, @@ -84,7 +89,7 @@ class FixedJointSimulator( # Apply boundary conditions to rod1. fixed_joint_sim.constrain(rod1).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Connect rod 1 and rod 2 @@ -111,7 +116,7 @@ class FixedJointSimulator( # Add forces to rod2 fixed_joint_sim.add_forcing_to(rod2).using( - EndpointForcesSinusoidal, + ea.EndpointForcesSinusoidal, start_force_mag=0, end_force_mag=5e-3, ramp_up_time=0.2, @@ -125,38 +130,38 @@ class FixedJointSimulator( # dt = 1e-5 damping_constant = 0.4 fixed_joint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) fixed_joint_sim.dampen(rod2).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) -pp_list_cylinder = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) +pp_list_cylinder = ea.defaultdict(list) fixed_joint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=step_skip, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=step_skip, callback_params=pp_list_rod1 ) fixed_joint_sim.collect_diagnostics(rod2).using( - MyCallBack, step_skip=step_skip, callback_params=pp_list_rod2 + ea.MyCallBack, step_skip=step_skip, callback_params=pp_list_rod2 ) fixed_joint_sim.collect_diagnostics(cylinder).using( - MyCallBack, step_skip=step_skip, callback_params=pp_list_cylinder + ea.MyCallBack, step_skip=step_skip, callback_params=pp_list_cylinder ) fixed_joint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, fixed_joint_sim, final_time, total_steps) +ea.integrate(timestepper, fixed_joint_sim, final_time, total_steps) PLOT_FIGURE = True SAVE_FIGURE = True diff --git a/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_spherical_joint.py b/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_spherical_joint.py index 3d3a61da..811ac691 100644 --- a/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_spherical_joint.py +++ b/examples/ExperimentalCases/GenericSystemConnectionCases/generic_system_type_spherical_joint.py @@ -2,7 +2,7 @@ methods section.""" import numpy as np -from elastica import * +import elastica as ea from elastica.experimental.connection_contact_joint.generic_system_type_connection import ( GenericSystemTypeFreeJoint, ) @@ -15,7 +15,12 @@ class SphericalJointSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -46,7 +51,7 @@ class SphericalJointSimulator( start_cylinder = start_rod_2 + direction * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -60,7 +65,7 @@ class SphericalJointSimulator( ) spherical_joint_sim.append(rod1) # Create rod 2 -rod2 = CosseratRod.straight_rod( +rod2 = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction, @@ -74,7 +79,7 @@ class SphericalJointSimulator( ) spherical_joint_sim.append(rod2) # Create cylinder -cylinder = Cylinder( +cylinder = ea.Cylinder( start=start_cylinder, direction=direction, normal=normal, @@ -86,7 +91,7 @@ class SphericalJointSimulator( # Apply boundary conditions to rod1. spherical_joint_sim.constrain(rod1).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Connect rod 1 and rod 2 @@ -107,7 +112,7 @@ class SphericalJointSimulator( # Add forces to rod2 spherical_joint_sim.add_forcing_to(rod2).using( - EndpointForcesSinusoidal, + ea.EndpointForcesSinusoidal, start_force_mag=0, end_force_mag=5e-3, ramp_up_time=0.2, @@ -121,38 +126,38 @@ class SphericalJointSimulator( # dt = 1e-5 damping_constant = 4e-3 spherical_joint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) spherical_joint_sim.dampen(rod2).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) -pp_list_cylinder = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) +pp_list_cylinder = ea.defaultdict(list) spherical_joint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=step_skip, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=step_skip, callback_params=pp_list_rod1 ) spherical_joint_sim.collect_diagnostics(rod2).using( - MyCallBack, step_skip=step_skip, callback_params=pp_list_rod2 + ea.MyCallBack, step_skip=step_skip, callback_params=pp_list_rod2 ) spherical_joint_sim.collect_diagnostics(cylinder).using( - MyCallBack, step_skip=step_skip, callback_params=pp_list_cylinder + ea.MyCallBack, step_skip=step_skip, callback_params=pp_list_cylinder ) spherical_joint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, spherical_joint_sim, final_time, total_steps) +ea.integrate(timestepper, spherical_joint_sim, final_time, total_steps) PLOT_FIGURE = True SAVE_FIGURE = True diff --git a/examples/ExperimentalCases/ParallelConnectionExample/parallel_connection_example.py b/examples/ExperimentalCases/ParallelConnectionExample/parallel_connection_example.py index 636f043d..ba931c13 100644 --- a/examples/ExperimentalCases/ParallelConnectionExample/parallel_connection_example.py +++ b/examples/ExperimentalCases/ParallelConnectionExample/parallel_connection_example.py @@ -1,7 +1,7 @@ __doc__ = """Parallel connection example""" import numpy as np -from elastica import * +import elastica as ea from elastica.experimental.connection_contact_joint.parallel_connection import ( get_connection_vector_straight_straight_rod, SurfaceJointSideBySide, @@ -16,7 +16,12 @@ class ParallelConnection( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -40,7 +45,7 @@ class ParallelConnection( start_rod_2 = start_rod_1 + binormal * 2 * base_radius # Create rod 1 -rod_one = CosseratRod.straight_rod( +rod_one = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -54,7 +59,7 @@ class ParallelConnection( ) parallel_connection_sim.append(rod_one) # Create rod 2 -rod_two = CosseratRod.straight_rod( +rod_two = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction, @@ -70,16 +75,16 @@ class ParallelConnection( # Apply boundary conditions to rod1. parallel_connection_sim.constrain(rod_one).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Apply boundary conditions to rod2. parallel_connection_sim.constrain(rod_two).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Apply a contraction force on rod one. -class ContractionForce(NoForces): +class ContractionForce(ea.NoForces): def __init__( self, ramp, @@ -135,24 +140,24 @@ def apply_forces(self, system, time: np.float64 = 0.0): damping_constant = 4e-3 dt = 1e-3 parallel_connection_sim.dampen(rod_one).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) parallel_connection_sim.dampen(rod_two).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -class ParallelConnecitonCallback(CallBackBaseClass): +class ParallelConnecitonCallback(ea.CallBackBaseClass): """ Call back function for parallel connection """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -165,8 +170,8 @@ def make_callback(self, system, time, current_step: int): return -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) parallel_connection_sim.collect_diagnostics(rod_one).using( @@ -178,13 +183,13 @@ def make_callback(self, system, time, current_step: int): parallel_connection_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() final_time = 20.0 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, parallel_connection_sim, final_time, total_steps) +ea.integrate(timestepper, parallel_connection_sim, final_time, total_steps) PLOT_FIGURE = True SAVE_FIGURE = False diff --git a/examples/FlexibleSwingingPendulumCase/flexible_swinging_pendulum.py b/examples/FlexibleSwingingPendulumCase/flexible_swinging_pendulum.py index abe94d13..d6364e24 100644 --- a/examples/FlexibleSwingingPendulumCase/flexible_swinging_pendulum.py +++ b/examples/FlexibleSwingingPendulumCase/flexible_swinging_pendulum.py @@ -1,14 +1,15 @@ """ Flexible swinging pendulum test-case isort:skip_file """ + import numpy as np from matplotlib import pyplot as plt -from elastica import * +import elastica as ea class SwingingFlexiblePendulumSimulator( - BaseSystemCollection, Constraints, Forcing, CallBacks + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.CallBacks ): pass @@ -36,7 +37,7 @@ class SwingingFlexiblePendulumSimulator( # For shear modulus of 1e4, nu is 99! poisson_ratio = 0.5 -pendulum_rod = CosseratRod.straight_rod( +pendulum_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -53,7 +54,7 @@ class SwingingFlexiblePendulumSimulator( # Bad name : whats a FreeRod anyway? -class HingeBC(ConstraintBase): +class HingeBC(ea.ConstraintBase): """ the end of the rod fixed x[0] """ @@ -77,18 +78,18 @@ def constrain_rates(self, rod, time): # Add gravitational forces gravitational_acc = -9.80665 pendulum_sim.add_forcing_to(pendulum_rod).using( - GravityForces, acc_gravity=np.array([gravitational_acc, 0.0, 0.0]) + ea.GravityForces, acc_gravity=np.array([gravitational_acc, 0.0, 0.0]) ) # Add call backs -class PendulumCallBack(CallBackBaseClass): +class PendulumCallBack(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -112,7 +113,7 @@ def make_callback(self, system, time, current_step: int): total_steps = int(final_time / dt) print("Total steps", total_steps) -recorded_history = defaultdict(list) +recorded_history = ea.defaultdict(list) step_skip = ( 60 if PLOT_VIDEO @@ -123,10 +124,10 @@ def make_callback(self, system, time, current_step: int): ) pendulum_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() -integrate(timestepper, pendulum_sim, final_time, total_steps) +ea.integrate(timestepper, pendulum_sim, final_time, total_steps) if PLOT_VIDEO: diff --git a/examples/FrictionValidationCases/axial_friction.py b/examples/FrictionValidationCases/axial_friction.py index 14331121..685ffdea 100644 --- a/examples/FrictionValidationCases/axial_friction.py +++ b/examples/FrictionValidationCases/axial_friction.py @@ -1,13 +1,13 @@ __doc__ = """Axial friction validation, for detailed explanation refer to Gazzola et. al. R. Soc. 2018 section 4.1.4 and Appendix G """ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_axial_friction_validation, ) -class AxialFrictionSimulator(BaseSystemCollection, Constraints, Forcing): +class AxialFrictionSimulator(ea.BaseSystemCollection, ea.Constraints, ea.Forcing): pass @@ -39,7 +39,7 @@ def simulate_axial_friction_with(force=0.0): # Set shear matrix shear_matrix = np.repeat(1e4 * np.identity((3))[:, :, np.newaxis], n_elem, axis=2) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -56,17 +56,17 @@ def simulate_axial_friction_with(force=0.0): shearable_rod.shear_matrix = shear_matrix axial_friction_sim.append(shearable_rod) - axial_friction_sim.constrain(shearable_rod).using(FreeBC) + axial_friction_sim.constrain(shearable_rod).using(ea.FreeBC) # Add gravitational forces gravitational_acc = -9.80665 axial_friction_sim.add_forcing_to(shearable_rod).using( - GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) + ea.GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) ) # Add Uniform force on the rod axial_friction_sim.add_forcing_to(shearable_rod).using( - UniformForces, force=1.0 * force, direction=direction + ea.UniformForces, force=1.0 * force, direction=direction ) # Add friction forces @@ -77,7 +77,7 @@ def simulate_axial_friction_with(force=0.0): kinetic_mu_array = np.array([0.4, 0.2, 0.2]) # [forward, backward, sideways] axial_friction_sim.add_forcing_to(shearable_rod).using( - AnisotropicFrictionalPlane, + ea.AnisotropicFrictionalPlane, k=10.0, nu=1e-4, plane_origin=origin_plane, @@ -88,13 +88,13 @@ def simulate_axial_friction_with(force=0.0): ) axial_friction_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 0.25 dt = 1e-5 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, axial_friction_sim, final_time, total_steps) + ea.integrate(timestepper, axial_friction_sim, final_time, total_steps) # compute translational and rotational energy translational_energy = shearable_rod.compute_translational_energy() diff --git a/examples/FrictionValidationCases/rolling_friction_initial_velocity.py b/examples/FrictionValidationCases/rolling_friction_initial_velocity.py index 73d99a70..4919fb76 100644 --- a/examples/FrictionValidationCases/rolling_friction_initial_velocity.py +++ b/examples/FrictionValidationCases/rolling_friction_initial_velocity.py @@ -2,14 +2,14 @@ section 4.1.4 and Appendix G """ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) class RollingFrictionInitialVelocitySimulator( - BaseSystemCollection, Constraints, Forcing, Damping + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping ): pass @@ -43,7 +43,7 @@ def simulate_rolling_friction_initial_velocity_with(IFactor=0.0): # Set shear matrix shear_matrix = np.repeat(1e4 * np.identity((3))[:, :, np.newaxis], n_elem, axis=2) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -67,12 +67,12 @@ def simulate_rolling_friction_initial_velocity_with(IFactor=0.0): shearable_rod.velocity_collection[0, :] += Vs rolling_friction_initial_velocity_sim.append(shearable_rod) - rolling_friction_initial_velocity_sim.constrain(shearable_rod).using(FreeBC) + rolling_friction_initial_velocity_sim.constrain(shearable_rod).using(ea.FreeBC) # Add damping dt = 1e-6 * 2 rolling_friction_initial_velocity_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) @@ -80,7 +80,7 @@ def simulate_rolling_friction_initial_velocity_with(IFactor=0.0): # Add gravitational forces gravitational_acc = -9.80665 rolling_friction_initial_velocity_sim.add_forcing_to(shearable_rod).using( - GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) + ea.GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) ) # Add friction forces @@ -91,7 +91,7 @@ def simulate_rolling_friction_initial_velocity_with(IFactor=0.0): kinetic_mu_array = np.array([0.2, 0.2, 0.2]) # [forward, backward, sideways] rolling_friction_initial_velocity_sim.add_forcing_to(shearable_rod).using( - AnisotropicFrictionalPlane, + ea.AnisotropicFrictionalPlane, k=10.0, nu=1e-4, plane_origin=origin_plane, @@ -102,12 +102,12 @@ def simulate_rolling_friction_initial_velocity_with(IFactor=0.0): ) rolling_friction_initial_velocity_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 2.0 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate( + ea.integrate( timestepper, rolling_friction_initial_velocity_sim, final_time, total_steps ) diff --git a/examples/FrictionValidationCases/rolling_friction_on_inclined_plane.py b/examples/FrictionValidationCases/rolling_friction_on_inclined_plane.py index af8f8326..3c36e2ae 100644 --- a/examples/FrictionValidationCases/rolling_friction_on_inclined_plane.py +++ b/examples/FrictionValidationCases/rolling_friction_on_inclined_plane.py @@ -2,14 +2,14 @@ section 4.1.4 and Appendix G """ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) class RollingFrictionOnInclinedPlaneSimulator( - BaseSystemCollection, Constraints, Forcing + ea.BaseSystemCollection, ea.Constraints, ea.Forcing ): pass @@ -42,7 +42,7 @@ def simulate_rolling_friction_on_inclined_plane_with(alpha_s=0.0): # Set shear matrix shear_matrix = np.repeat(1e4 * np.identity((3))[:, :, np.newaxis], n_elem, axis=2) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -59,11 +59,11 @@ def simulate_rolling_friction_on_inclined_plane_with(alpha_s=0.0): shearable_rod.shear_matrix = shear_matrix rolling_friction_on_inclined_plane_sim.append(shearable_rod) - rolling_friction_on_inclined_plane_sim.constrain(shearable_rod).using(FreeBC) + rolling_friction_on_inclined_plane_sim.constrain(shearable_rod).using(ea.FreeBC) gravitational_acc = -9.80665 rolling_friction_on_inclined_plane_sim.add_forcing_to(shearable_rod).using( - GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) + ea.GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) ) alpha = alpha_s * np.pi @@ -77,7 +77,7 @@ def simulate_rolling_friction_on_inclined_plane_with(alpha_s=0.0): kinetic_mu_array = np.array([0.2, 0.2, 0.2]) # [forward, backward, sideways] rolling_friction_on_inclined_plane_sim.add_forcing_to(shearable_rod).using( - AnisotropicFrictionalPlane, + ea.AnisotropicFrictionalPlane, k=10.0, nu=1e-4, plane_origin=origin_plane, @@ -88,13 +88,13 @@ def simulate_rolling_friction_on_inclined_plane_with(alpha_s=0.0): ) rolling_friction_on_inclined_plane_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 0.5 dt = 1e-6 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate( + ea.integrate( timestepper, rolling_friction_on_inclined_plane_sim, final_time, total_steps ) diff --git a/examples/FrictionValidationCases/rolling_friction_torque.py b/examples/FrictionValidationCases/rolling_friction_torque.py index 3284f769..dbc9f7a1 100644 --- a/examples/FrictionValidationCases/rolling_friction_torque.py +++ b/examples/FrictionValidationCases/rolling_friction_torque.py @@ -2,13 +2,15 @@ section 4.1.4 and Appendix G """ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) -class RollingFrictionTorqueSimulator(BaseSystemCollection, Constraints, Forcing): +class RollingFrictionTorqueSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing +): pass @@ -40,7 +42,7 @@ def simulate_rolling_friction_torque_with(C_s=0.0): # Set shear matrix shear_matrix = np.repeat(1e4 * np.identity((3))[:, :, np.newaxis], n_elem, axis=2) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -57,17 +59,17 @@ def simulate_rolling_friction_torque_with(C_s=0.0): shearable_rod.shear_matrix = shear_matrix rolling_friction_torque_sim.append(shearable_rod) - rolling_friction_torque_sim.constrain(shearable_rod).using(FreeBC) + rolling_friction_torque_sim.constrain(shearable_rod).using(ea.FreeBC) # Add gravitational forces gravitational_acc = -9.80665 rolling_friction_torque_sim.add_forcing_to(shearable_rod).using( - GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) + ea.GravityForces, acc_gravity=np.array([0.0, gravitational_acc, 0.0]) ) # Add Uniform torque on the rod rolling_friction_torque_sim.add_forcing_to(shearable_rod).using( - UniformTorques, torque=1.0 * C_s, direction=direction + ea.UniformTorques, torque=1.0 * C_s, direction=direction ) # Add friction forces @@ -78,7 +80,7 @@ def simulate_rolling_friction_torque_with(C_s=0.0): kinetic_mu_array = np.array([0.2, 0.2, 0.2]) # [forward, backward, sideways] rolling_friction_torque_sim.add_forcing_to(shearable_rod).using( - AnisotropicFrictionalPlane, + ea.AnisotropicFrictionalPlane, k=10.0, nu=1e-4, plane_origin=origin_plane, @@ -89,13 +91,13 @@ def simulate_rolling_friction_torque_with(C_s=0.0): ) rolling_friction_torque_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 1.0 dt = 1e-6 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, rolling_friction_torque_sim, final_time, total_steps) + ea.integrate(timestepper, rolling_friction_torque_sim, final_time, total_steps) # compute translational and rotational energy translational_energy = shearable_rod.compute_translational_energy() diff --git a/examples/HelicalBucklingCase/convergence_helicalbuckling.py b/examples/HelicalBucklingCase/convergence_helicalbuckling.py index 6ad5597f..21f7e8c8 100644 --- a/examples/HelicalBucklingCase/convergence_helicalbuckling.py +++ b/examples/HelicalBucklingCase/convergence_helicalbuckling.py @@ -2,7 +2,7 @@ section 3.4.1 """ import numpy as np -from elastica import * +import elastica as ea from examples.HelicalBucklingCase.helicalbuckling_postprocessing import ( analytical_solution, envelope, @@ -11,7 +11,9 @@ from examples.convergence_functions import plot_convergence, calculate_error_norm -class HelicalBucklingSimulator(BaseSystemCollection, Constraints, Forcing, Damping): +class HelicalBucklingSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping +): pass @@ -47,7 +49,7 @@ def simulate_helicalbucklin_beam_with( np.fill_diagonal(temp_bend_matrix, [1.345, 1.345, 0.789]) bend_matrix = np.repeat(temp_bend_matrix[:, :, np.newaxis], n_elem - 1, axis=2) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -68,13 +70,13 @@ def simulate_helicalbucklin_beam_with( dl = base_length / n_elem dt = 1e-3 * dl helicalbuckling_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) helicalbuckling_sim.constrain(shearable_rod).using( - HelicalBucklingBC, + ea.HelicalBucklingBC, constrained_position_idx=(0, -1), constrained_director_idx=(0, -1), twisting_time=500, @@ -83,7 +85,7 @@ def simulate_helicalbucklin_beam_with( ) helicalbuckling_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() shearable_rod.velocity_collection[..., int((n_elem) / 2)] += np.array( [0, 1e-6, 0.0] ) @@ -92,7 +94,7 @@ def simulate_helicalbucklin_beam_with( final_time = 10500 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, helicalbuckling_sim, final_time, total_steps) + ea.integrate(timestepper, helicalbuckling_sim, final_time, total_steps) # calculate errors and norms # Since we need to evaluate analytical solution only on nodes, n_nodes = n_elems+1 diff --git a/examples/HelicalBucklingCase/helicalbuckling.py b/examples/HelicalBucklingCase/helicalbuckling.py index 2743dd8e..7c1a789c 100644 --- a/examples/HelicalBucklingCase/helicalbuckling.py +++ b/examples/HelicalBucklingCase/helicalbuckling.py @@ -2,13 +2,15 @@ Gazzola et. al. R. Soc. 2018 section 3.4.1 """ import numpy as np -from elastica import * +import elastica as ea from examples.HelicalBucklingCase.helicalbuckling_postprocessing import ( plot_helicalbuckling, ) -class HelicalBucklingSimulator(BaseSystemCollection, Constraints, Damping, Forcing): +class HelicalBucklingSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Damping, ea.Forcing +): pass @@ -42,7 +44,7 @@ class HelicalBucklingSimulator(BaseSystemCollection, Constraints, Damping, Forci np.fill_diagonal(temp_bend_matrix, [1.345, 1.345, 0.789]) bend_matrix = np.repeat(temp_bend_matrix[:, :, np.newaxis], n_elem - 1, axis=2) -shearable_rod = CosseratRod.straight_rod( +shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -65,13 +67,13 @@ class HelicalBucklingSimulator(BaseSystemCollection, Constraints, Damping, Forci dl = base_length / n_elem dt = 1e-3 * dl helicalbuckling_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) helicalbuckling_sim.constrain(shearable_rod).using( - HelicalBucklingBC, + ea.HelicalBucklingBC, constrained_position_idx=(0, -1), constrained_director_idx=(0, -1), twisting_time=500, @@ -80,14 +82,14 @@ class HelicalBucklingSimulator(BaseSystemCollection, Constraints, Damping, Forci ) helicalbuckling_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() shearable_rod.velocity_collection[..., int((n_elem) / 2)] += np.array([0, 1e-6, 0.0]) # timestepper = PEFRL() final_time = 10500.0 total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, helicalbuckling_sim, final_time, total_steps) +ea.integrate(timestepper, helicalbuckling_sim, final_time, total_steps) if PLOT_FIGURE: plot_helicalbuckling(shearable_rod, SAVE_FIGURE) diff --git a/examples/JointCases/fixed_joint.py b/examples/JointCases/fixed_joint.py index c5c8064e..4f6b9809 100644 --- a/examples/JointCases/fixed_joint.py +++ b/examples/JointCases/fixed_joint.py @@ -1,7 +1,7 @@ __doc__ = """Fixed joint example, for detailed explanation refer to Zhang et. al. Nature Comm. methods section.""" import numpy as np -from elastica import * +import elastica as ea from examples.JointCases.joint_cases_postprocessing import ( plot_position, plot_video, @@ -11,7 +11,12 @@ class FixedJointSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -35,7 +40,7 @@ class FixedJointSimulator( start_rod_2 = start_rod_1 + direction * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -49,7 +54,7 @@ class FixedJointSimulator( ) fixed_joint_sim.append(rod1) # Create rod 2 -rod2 = CosseratRod.straight_rod( +rod2 = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction, @@ -65,17 +70,17 @@ class FixedJointSimulator( # Apply boundary conditions to rod1. fixed_joint_sim.constrain(rod1).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Connect rod 1 and rod 2 fixed_joint_sim.connect( first_rod=rod1, second_rod=rod2, first_connect_idx=-1, second_connect_idx=0 -).using(FixedJoint, k=1e5, nu=0.0, kt=1e1, nut=0.0) +).using(ea.FixedJoint, k=1e5, nu=0.0, kt=1e1, nut=0.0) # Add forces to rod2 fixed_joint_sim.add_forcing_to(rod2).using( - EndpointForcesSinusoidal, + ea.EndpointForcesSinusoidal, start_force_mag=0, end_force_mag=5e-3, ramp_up_time=0.2, @@ -90,35 +95,35 @@ class FixedJointSimulator( damping_constant = 0.4 dt = 1e-4 fixed_joint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) fixed_joint_sim.dampen(rod2).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) fixed_joint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod1 ) fixed_joint_sim.collect_diagnostics(rod2).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod2 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod2 ) fixed_joint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() final_time = 10 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, fixed_joint_sim, final_time, total_steps) +ea.integrate(timestepper, fixed_joint_sim, final_time, total_steps) PLOT_FIGURE = True SAVE_FIGURE = False diff --git a/examples/JointCases/fixed_joint_torsion.py b/examples/JointCases/fixed_joint_torsion.py index 35f9f7f3..5d90132a 100644 --- a/examples/JointCases/fixed_joint_torsion.py +++ b/examples/JointCases/fixed_joint_torsion.py @@ -1,7 +1,7 @@ __doc__ = """Fixed joint example, for detailed explanation refer to Zhang et. al. Nature Comm. methods section.""" import numpy as np -from elastica import * +import elastica as ea from elastica.joint import get_relative_rotation_two_systems from examples.JointCases.joint_cases_postprocessing import ( plot_position, @@ -13,7 +13,12 @@ class FixedJointSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -38,7 +43,7 @@ class FixedJointSimulator( start_rod_2 = start_rod_1 + direction_rod1 * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction_rod1, @@ -52,7 +57,7 @@ class FixedJointSimulator( ) fixed_joint_sim.append(rod1) # Create rod 2 -rod2 = CosseratRod.straight_rod( +rod2 = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction_rod2, @@ -68,14 +73,14 @@ class FixedJointSimulator( # Apply boundary conditions to rod1. fixed_joint_sim.constrain(rod1).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Connect rod 1 and rod 2 fixed_joint_sim.connect( first_rod=rod1, second_rod=rod2, first_connect_idx=-1, second_connect_idx=0 ).using( - FixedJoint, + ea.FixedJoint, k=1e5, nu=1.0, kt=1e3, @@ -85,43 +90,43 @@ class FixedJointSimulator( # Add forces to rod2 fixed_joint_sim.add_forcing_to(rod2).using( - UniformTorques, torque=5e-3, direction=np.array([0.0, 0.0, 1.0]) + ea.UniformTorques, torque=5e-3, direction=np.array([0.0, 0.0, 1.0]) ) # add damping damping_constant = 0.4 dt = 1e-5 fixed_joint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) fixed_joint_sim.dampen(rod2).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) fixed_joint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod1 ) fixed_joint_sim.collect_diagnostics(rod2).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod2 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod2 ) fixed_joint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() final_time = 10 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, fixed_joint_sim, final_time, total_steps) +ea.integrate(timestepper, fixed_joint_sim, final_time, total_steps) plot_orientation( diff --git a/examples/JointCases/hinge_joint.py b/examples/JointCases/hinge_joint.py index 9a165806..c478552e 100644 --- a/examples/JointCases/hinge_joint.py +++ b/examples/JointCases/hinge_joint.py @@ -1,7 +1,7 @@ __doc__ = """Hinge joint example, for detailed explanation refer to Zhang et. al. Nature Comm. methods section.""" import numpy as np -from elastica import * +import elastica as ea from examples.JointCases.joint_cases_postprocessing import ( plot_position, plot_video, @@ -11,7 +11,12 @@ class HingeJointSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -35,7 +40,7 @@ class HingeJointSimulator( start_rod_2 = start_rod_1 + direction * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -49,7 +54,7 @@ class HingeJointSimulator( ) hinge_joint_sim.append(rod1) # Create rod 2 -rod2 = CosseratRod.straight_rod( +rod2 = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction, @@ -65,19 +70,19 @@ class HingeJointSimulator( # Apply boundary conditions to rod1. hinge_joint_sim.constrain(rod1).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Connect rod 1 and rod 2 hinge_joint_sim.connect( first_rod=rod1, second_rod=rod2, first_connect_idx=-1, second_connect_idx=0 ).using( - HingeJoint, k=1e5, nu=0, kt=1e1, normal_direction=roll_direction + ea.HingeJoint, k=1e5, nu=0, kt=1e1, normal_direction=roll_direction ) # 1e-2 # Add forces to rod2 hinge_joint_sim.add_forcing_to(rod2).using( - EndpointForcesSinusoidal, + ea.EndpointForcesSinusoidal, start_force_mag=0, end_force_mag=5e-3, ramp_up_time=0.2, @@ -92,35 +97,35 @@ class HingeJointSimulator( damping_constant = 4e-3 dt = 5e-5 hinge_joint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) hinge_joint_sim.dampen(rod2).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) hinge_joint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod1 ) hinge_joint_sim.collect_diagnostics(rod2).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod2 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod2 ) hinge_joint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() final_time = 10 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, hinge_joint_sim, final_time, total_steps) +ea.integrate(timestepper, hinge_joint_sim, final_time, total_steps) PLOT_FIGURE = True SAVE_FIGURE = False diff --git a/examples/JointCases/spherical_joint.py b/examples/JointCases/spherical_joint.py index b7c7a6b8..f71da4f5 100644 --- a/examples/JointCases/spherical_joint.py +++ b/examples/JointCases/spherical_joint.py @@ -2,7 +2,7 @@ methods section.""" import numpy as np -from elastica import * +import elastica as ea from examples.JointCases.joint_cases_postprocessing import ( plot_position, plot_video, @@ -12,7 +12,12 @@ class SphericalJointSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -36,7 +41,7 @@ class SphericalJointSimulator( start_rod_2 = start_rod_1 + direction * base_length # Create rod 1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -50,7 +55,7 @@ class SphericalJointSimulator( ) spherical_joint_sim.append(rod1) # Create rod 2 -rod2 = CosseratRod.straight_rod( +rod2 = ea.CosseratRod.straight_rod( n_elem, start_rod_2, direction, @@ -66,19 +71,19 @@ class SphericalJointSimulator( # Apply boundary conditions to rod1. spherical_joint_sim.constrain(rod1).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Connect rod 1 and rod 2 spherical_joint_sim.connect( first_rod=rod1, second_rod=rod2, first_connect_idx=-1, second_connect_idx=0 ).using( - FreeJoint, k=1e5, nu=0 + ea.FreeJoint, k=1e5, nu=0 ) # k=kg/s2 nu=kg/s 1e-2 # Add forces to rod2 spherical_joint_sim.add_forcing_to(rod2).using( - EndpointForcesSinusoidal, + ea.EndpointForcesSinusoidal, start_force_mag=0, end_force_mag=5e-3, ramp_up_time=0.2, @@ -93,35 +98,35 @@ class SphericalJointSimulator( damping_constant = 4e-3 dt = 5e-5 spherical_joint_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) spherical_joint_sim.dampen(rod2).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) -pp_list_rod1 = defaultdict(list) -pp_list_rod2 = defaultdict(list) +pp_list_rod1 = ea.defaultdict(list) +pp_list_rod2 = ea.defaultdict(list) spherical_joint_sim.collect_diagnostics(rod1).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod1 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod1 ) spherical_joint_sim.collect_diagnostics(rod2).using( - MyCallBack, step_skip=1000, callback_params=pp_list_rod2 + ea.MyCallBack, step_skip=1000, callback_params=pp_list_rod2 ) spherical_joint_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() final_time = 10 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, spherical_joint_sim, final_time, total_steps) +ea.integrate(timestepper, spherical_joint_sim, final_time, total_steps) PLOT_FIGURE = True SAVE_FIGURE = False diff --git a/examples/MuscularFlagella/muscular_flagella.py b/examples/MuscularFlagella/muscular_flagella.py index 1d64a100..dcca35c2 100644 --- a/examples/MuscularFlagella/muscular_flagella.py +++ b/examples/MuscularFlagella/muscular_flagella.py @@ -1,7 +1,7 @@ __doc__ = """Muscular flagella example from Zhang et. al. Nature Comm 2019 paper.""" import numpy as np -from elastica import * +import elastica as ea from examples.MuscularFlagella.post_processing import ( plot_video_2D, plot_video, @@ -15,7 +15,12 @@ class MuscularFlagellaSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, CallBacks, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.CallBacks, + ea.Damping, ): pass @@ -54,7 +59,7 @@ class MuscularFlagellaSimulator( binormal = np.cross(direction, normal) nu_body = 0 -flagella_body = CosseratRod.straight_rod( +flagella_body = ea.CosseratRod.straight_rod( n_elem_body, start, direction, @@ -140,7 +145,7 @@ class MuscularFlagellaSimulator( start_muscle = np.array([4.5 * base_length_muscle, 0.0053, 0.1]) -flagella_muscle = CosseratRod.straight_rod( +flagella_muscle = ea.CosseratRod.straight_rod( n_elem_muscle, start_muscle, direction, @@ -157,7 +162,7 @@ class MuscularFlagellaSimulator( # add damping muscular_flagella_sim.dampen(flagella_muscle).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu_muscle, time_step=time_step, ) @@ -193,13 +198,13 @@ class MuscularFlagellaSimulator( reynolds_number = 1.8e-2 dynamic_viscosity = 1.2e-3 muscular_flagella_sim.add_forcing_to(flagella_body).using( - SlenderBodyTheory, dynamic_viscosity=dynamic_viscosity + ea.SlenderBodyTheory, dynamic_viscosity=dynamic_viscosity ) # Add call backs -class MuscularFlagellaCallBack(CallBackBaseClass): +class MuscularFlagellaCallBack(ea.CallBackBaseClass): def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -214,14 +219,14 @@ def make_callback(self, system, time, current_step: int): self.callback_params["tangents"].append(system.tangents.copy()) -post_processing_dict_body = defaultdict(list) +post_processing_dict_body = ea.defaultdict(list) muscular_flagella_sim.collect_diagnostics(flagella_body).using( MuscularFlagellaCallBack, step_skip=step_skip, callback_params=post_processing_dict_body, ) -post_processing_dict_muscle = defaultdict(list) +post_processing_dict_muscle = ea.defaultdict(list) muscular_flagella_sim.collect_diagnostics(flagella_muscle).using( MuscularFlagellaCallBack, step_skip=step_skip, @@ -231,9 +236,9 @@ def make_callback(self, system, time, current_step: int): muscular_flagella_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() print("Total steps", total_steps) -integrate(timestepper, muscular_flagella_sim, final_time, total_steps) +ea.integrate(timestepper, muscular_flagella_sim, final_time, total_steps) # Plot the videos diff --git a/examples/MuscularSnake/muscular_snake.py b/examples/MuscularSnake/muscular_snake.py index 1329c5d5..1c9474b2 100644 --- a/examples/MuscularSnake/muscular_snake.py +++ b/examples/MuscularSnake/muscular_snake.py @@ -1,6 +1,6 @@ __doc__ = """Muscular snake example from Zhang et. al. Nature Comm 2019 paper.""" import numpy as np -from elastica import * +import elastica as ea from examples.MuscularSnake.post_processing import ( plot_video_with_surface, plot_snake_velocity, @@ -14,7 +14,12 @@ # Set base simulator class class MuscularSnakeSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, CallBacks, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.CallBacks, + ea.Damping, ): pass @@ -45,7 +50,7 @@ class MuscularSnakeSimulator( normal = np.array([0.0, 0.0, 1.0]) start = np.array([0.0, 0.0, base_radius_body]) -snake_body = CosseratRod.straight_rod( +snake_body = ea.CosseratRod.straight_rod( n_elem_body, start, direction, @@ -115,7 +120,7 @@ class MuscularSnakeSimulator( ] ) - muscle_rod = CosseratRod.straight_rod( + muscle_rod = ea.CosseratRod.straight_rod( n_elem_muscle_group_one_to_three, start_muscle, direction, @@ -180,7 +185,7 @@ class MuscularSnakeSimulator( ] ) - muscle_rod = CosseratRod.straight_rod( + muscle_rod = ea.CosseratRod.straight_rod( n_elem_muscle_group_two_to_four, start_muscle, direction, @@ -228,7 +233,7 @@ class MuscularSnakeSimulator( # Add dissipation to backbone muscular_snake_simulator.dampen(snake_body).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu_body, time_step=time_step, ) @@ -236,7 +241,7 @@ class MuscularSnakeSimulator( # Add dissipation to muscles for rod in rod_list: muscular_snake_simulator.dampen(rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu_muscle, time_step=time_step, ) @@ -245,7 +250,7 @@ class MuscularSnakeSimulator( post_processing_forces_dict_list = [] for i in range(n_muscle_fibers): - post_processing_forces_dict_list.append(defaultdict(list)) + post_processing_forces_dict_list.append(ea.defaultdict(list)) muscle_rod = muscle_rod_list[i] side_of_body = 1 if i % 2 == 0 else -1 @@ -265,7 +270,7 @@ class MuscularSnakeSimulator( straight_straight_rod_connection_list = [] -straight_straight_rod_connection_post_processing_dict = defaultdict(list) +straight_straight_rod_connection_post_processing_dict = ea.defaultdict(list) for idx, rod_two in enumerate(muscle_rod_list): rod_one = snake_body ( @@ -331,7 +336,7 @@ class MuscularSnakeSimulator( # Only apply to the snake body. gravitational_acc = -9.81 muscular_snake_simulator.add_forcing_to(snake_body).using( - GravityForces, acc_gravity=np.array([0.0, 0.0, gravitational_acc]) + ea.GravityForces, acc_gravity=np.array([0.0, 0.0, gravitational_acc]) ) origin_plane = np.array([0.0, 0.0, 0.0]) @@ -345,7 +350,7 @@ class MuscularSnakeSimulator( ) # [forward, backward, sideways] static_mu_array = 2 * kinetic_mu_array muscular_snake_simulator.add_forcing_to(snake_body).using( - AnisotropicFrictionalPlane, + ea.AnisotropicFrictionalPlane, k=1e1, nu=40, plane_origin=origin_plane, @@ -356,9 +361,9 @@ class MuscularSnakeSimulator( ) -class MuscularSnakeCallBack(CallBackBaseClass): +class MuscularSnakeCallBack(ea.CallBackBaseClass): def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -383,7 +388,7 @@ def make_callback(self, system, time, current_step: int): post_processing_dict_list = [] for idx, rod in enumerate(rod_list): - post_processing_dict_list.append(defaultdict(list)) + post_processing_dict_list.append(ea.defaultdict(list)) muscular_snake_simulator.collect_diagnostics(rod).using( MuscularSnakeCallBack, step_skip=step_skip, @@ -391,8 +396,8 @@ def make_callback(self, system, time, current_step: int): ) muscular_snake_simulator.finalize() -timestepper = PositionVerlet() -integrate(timestepper, muscular_snake_simulator, final_time, total_steps) +timestepper = ea.PositionVerlet() +ea.integrate(timestepper, muscular_snake_simulator, final_time, total_steps) plot_video_with_surface( diff --git a/examples/RestartExample/restart_example.py b/examples/RestartExample/restart_example.py index 1d291f09..2765a23c 100644 --- a/examples/RestartExample/restart_example.py +++ b/examples/RestartExample/restart_example.py @@ -3,11 +3,11 @@ """ import numpy as np -from elastica import * +import elastica as ea class RestartExampleSimulator( - BaseSystemCollection, Constraints, Forcing, Damping, CallBacks + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping, ea.CallBacks ): pass @@ -30,7 +30,7 @@ class RestartExampleSimulator( shear_modulus = E / (poisson_ratio + 1.0) # Create rod -shearable_rod = CosseratRod.straight_rod( +shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -49,13 +49,13 @@ class RestartExampleSimulator( # Constrain one end of the rod. restart_example_simulator.constrain(shearable_rod).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Add end point forces to rod end_force = np.array([-15.0, 0.0, 0.0]) restart_example_simulator.add_forcing_to(shearable_rod).using( - EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 ) # add damping @@ -63,7 +63,7 @@ class RestartExampleSimulator( dl = base_length / n_elem dt = 0.01 * dl restart_example_simulator.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) @@ -78,14 +78,14 @@ class RestartExampleSimulator( restart_file_location = "data/" if LOAD_FROM_RESTART: - restart_time = load_state(restart_example_simulator, restart_file_location, True) + restart_time = ea.load_state(restart_example_simulator, restart_file_location, True) else: restart_time = np.float64(0.0) -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() total_steps = int(final_time / dt) -time = integrate( +time = ea.integrate( timestepper, restart_example_simulator, final_time, @@ -97,4 +97,4 @@ class RestartExampleSimulator( # `restart_file_location` directory there is one file called system_0.npz . For each system appended on the simulator # separate system_#.npz file will be created. if SAVE_DATA_RESTART: - save_state(restart_example_simulator, restart_file_location, time, True) + ea.save_state(restart_example_simulator, restart_file_location, time, True) diff --git a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact.py b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact.py index 81781e3a..30ed71bb 100644 --- a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact.py +++ b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact.py @@ -1,11 +1,16 @@ import numpy as np -from elastica import * +import elastica as ea from post_processing import plot_velocity, plot_video_with_surface def rod_cylinder_contact_case(inclination_angle=0.0): class RodCylinderParallelContact( - BaseSystemCollection, Constraints, Connections, CallBacks, Forcing, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.CallBacks, + ea.Forcing, + ea.Damping, ): pass @@ -29,7 +34,7 @@ class RodCylinderParallelContact( direction = np.array([np.sin(inclination_angle), 0.0, np.cos(inclination_angle)]) normal = np.array([0.0, 1.0, 0.0]) - rod = CosseratRod.straight_rod( + rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -52,7 +57,7 @@ class RodCylinderParallelContact( cylinder_direction = np.array([0.0, 0.0, 1.0]) cylinder_normal = np.array([0.0, 1.0, 0.0]) - rigid_body = Cylinder( + rigid_body = ea.Cylinder( start=cylinder_start, direction=cylinder_direction, normal=cylinder_normal, @@ -64,7 +69,7 @@ class RodCylinderParallelContact( # Add contact between rigid body and rod rod_cylinder_parallel_contact_simulator.connect(rod, rigid_body).using( - ExternalContact, + ea.ExternalContact, k=5e4, nu=0.1, ) @@ -72,7 +77,7 @@ class RodCylinderParallelContact( # add damping damping_constant = 1e-2 rod_cylinder_parallel_contact_simulator.dampen(rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=time_step, ) @@ -80,13 +85,13 @@ class RodCylinderParallelContact( # Add callbacks post_processing_dict_list = [] # For rod - class StraightRodCallBack(CallBackBaseClass): + class StraightRodCallBack(ea.CallBackBaseClass): """ Call back function for two arm octopus """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -120,7 +125,7 @@ def make_callback(self, system, time, current_step: int): return - class RigidCylinderCallBack(CallBackBaseClass): + class RigidCylinderCallBack(ea.CallBackBaseClass): """ Call back function for two arm octopus """ @@ -128,7 +133,7 @@ class RigidCylinderCallBack(CallBackBaseClass): def __init__( self, step_skip: int, callback_params: dict, resize_cylinder_elems: int ): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params self.n_elem_cylinder = resize_cylinder_elems @@ -191,14 +196,14 @@ def make_callback(self, system, time, current_step: int): return - post_processing_dict_list.append(defaultdict(list)) + post_processing_dict_list.append(ea.defaultdict(list)) rod_cylinder_parallel_contact_simulator.collect_diagnostics(rod).using( StraightRodCallBack, step_skip=step_skip, callback_params=post_processing_dict_list[0], ) # For rigid body - post_processing_dict_list.append(defaultdict(list)) + post_processing_dict_list.append(ea.defaultdict(list)) rod_cylinder_parallel_contact_simulator.collect_diagnostics(rigid_body).using( RigidCylinderCallBack, step_skip=step_skip, @@ -207,9 +212,9 @@ def make_callback(self, system, time, current_step: int): ) rod_cylinder_parallel_contact_simulator.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() - integrate( + ea.integrate( timestepper, rod_cylinder_parallel_contact_simulator, final_time, total_steps ) diff --git a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_friction.py b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_friction.py index 5f83f3be..35d9cef2 100644 --- a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_friction.py +++ b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_friction.py @@ -1,5 +1,5 @@ import numpy as np -from elastica import * +import elastica as ea from post_processing import plot_velocity, plot_video_with_surface @@ -7,7 +7,12 @@ def rod_cylinder_contact_friction_case( force_coefficient=0.1, normal_force_mag=10, POST_PROCESSING=False ): class RodCylinderParallelContact( - BaseSystemCollection, Constraints, Connections, CallBacks, Forcing, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.CallBacks, + ea.Forcing, + ea.Damping, ): pass @@ -31,7 +36,7 @@ class RodCylinderParallelContact( direction = np.array([0, 0.0, 1.0]) normal = np.array([0.0, 1.0, 0.0]) - rod = CosseratRod.straight_rod( + rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -49,17 +54,19 @@ class RodCylinderParallelContact( # Push the rod towards the cylinder to make sure contact is there normal_force_direction = np.array([-1.0, 0.0, 0.0]) rod_cylinder_parallel_contact_simulator.add_forcing_to(rod).using( - UniformForces, force=normal_force_mag, direction=normal_force_direction + ea.UniformForces, force=normal_force_mag, direction=normal_force_direction ) # Apply uniform forces on the rod rod_cylinder_parallel_contact_simulator.add_forcing_to(rod).using( - UniformForces, force=normal_force_mag * force_coefficient, direction=direction + ea.UniformForces, + force=normal_force_mag * force_coefficient, + direction=direction, ) # add damping damping_constant = 2e-3 rod_cylinder_parallel_contact_simulator.dampen(rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=time_step, ) @@ -71,7 +78,7 @@ class RodCylinderParallelContact( cylinder_direction = np.array([0.0, 0.0, 1.0]) cylinder_normal = np.array([0.0, 1.0, 0.0]) - rigid_body = Cylinder( + rigid_body = ea.Cylinder( start=cylinder_start, direction=cylinder_direction, normal=cylinder_normal, @@ -83,12 +90,12 @@ class RodCylinderParallelContact( # Constrain the rigid body position and directors rod_cylinder_parallel_contact_simulator.constrain(rigid_body).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) # Add contact between rigid body and rod rod_cylinder_parallel_contact_simulator.connect(rod, rigid_body).using( - ExternalContact, + ea.ExternalContact, k=1e5, nu=100, velocity_damping_coefficient=1e5, @@ -98,13 +105,13 @@ class RodCylinderParallelContact( # Add callbacks post_processing_dict_list = [] # For rod - class StraightRodCallBack(CallBackBaseClass): + class StraightRodCallBack(ea.CallBackBaseClass): """ Call back function for two arm octopus """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -138,7 +145,7 @@ def make_callback(self, system, time, current_step: int): return - class RigidCylinderCallBack(CallBackBaseClass): + class RigidCylinderCallBack(ea.CallBackBaseClass): """ Call back function for two arm octopus """ @@ -146,7 +153,7 @@ class RigidCylinderCallBack(CallBackBaseClass): def __init__( self, step_skip: int, callback_params: dict, resize_cylinder_elems: int ): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params self.n_elem_cylinder = resize_cylinder_elems @@ -210,14 +217,14 @@ def make_callback(self, system, time, current_step: int): return if POST_PROCESSING: - post_processing_dict_list.append(defaultdict(list)) + post_processing_dict_list.append(ea.defaultdict(list)) rod_cylinder_parallel_contact_simulator.collect_diagnostics(rod).using( StraightRodCallBack, step_skip=step_skip, callback_params=post_processing_dict_list[0], ) # For rigid body - post_processing_dict_list.append(defaultdict(list)) + post_processing_dict_list.append(ea.defaultdict(list)) rod_cylinder_parallel_contact_simulator.collect_diagnostics(rigid_body).using( RigidCylinderCallBack, step_skip=step_skip, @@ -226,9 +233,9 @@ def make_callback(self, system, time, current_step: int): ) rod_cylinder_parallel_contact_simulator.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() - integrate( + ea.integrate( timestepper, rod_cylinder_parallel_contact_simulator, final_time, total_steps ) diff --git a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_validation.py b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_validation.py index b7cc970b..33b16b6d 100644 --- a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_validation.py +++ b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_validation.py @@ -1,10 +1,15 @@ import numpy as np -from elastica import * +import elastica as ea from post_processing import plot_video, plot_cylinder_rod_position class SingleRodSingleCylinderInteractionSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, CallBacks, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.CallBacks, + ea.Damping, ): pass @@ -78,7 +83,7 @@ class SingleRodSingleCylinderInteractionSimulator( ) start_rod_1 = global_rot_mat @ start_rod_1 -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -95,7 +100,7 @@ class SingleRodSingleCylinderInteractionSimulator( single_rod_sim.append(rod1) -cylinder = Cylinder( +cylinder = ea.Cylinder( cylinder_start, cylinder_direction, cylinder_normal, @@ -105,17 +110,17 @@ class SingleRodSingleCylinderInteractionSimulator( ) single_rod_sim.append(cylinder) -single_rod_sim.connect(rod1, cylinder).using(ExternalContact, 1e2, 0.1) +single_rod_sim.connect(rod1, cylinder).using(ea.ExternalContact, 1e2, 0.1) # Add call backs -class PositionCollector(CallBackBaseClass): +class PositionCollector(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -128,11 +133,11 @@ def make_callback(self, system, time, current_step: int): return -recorded_rod_history = defaultdict(list) +recorded_rod_history = ea.defaultdict(list) single_rod_sim.collect_diagnostics(rod1).using( PositionCollector, step_skip=200, callback_params=recorded_rod_history ) -recorded_cyl_history = defaultdict(list) +recorded_cyl_history = ea.defaultdict(list) single_rod_sim.collect_diagnostics(cylinder).using( PositionCollector, step_skip=200, callback_params=recorded_cyl_history ) @@ -141,19 +146,19 @@ def make_callback(self, system, time, current_step: int): damping_constant = 1e-3 dt = 1e-4 single_rod_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) single_rod_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() final_time = 2.0 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, single_rod_sim, final_time, total_steps) +ea.integrate(timestepper, single_rod_sim, final_time, total_steps) if PLOT_FIGURE: plot_video( diff --git a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_with_y_normal.py b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_with_y_normal.py index 87303d34..b9692f90 100644 --- a/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_with_y_normal.py +++ b/examples/RigidBodyCases/RodRigidBodyContact/rod_cylinder_contact_with_y_normal.py @@ -1,10 +1,15 @@ import numpy as np -from elastica import * +import elastica as ea from post_processing import plot_video, plot_cylinder_rod_position class SingleRodSingleCylinderInteractionSimulator( - BaseSystemCollection, Constraints, Connections, Forcing, CallBacks, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.CallBacks, + ea.Damping, ): pass @@ -56,7 +61,7 @@ class SingleRodSingleCylinderInteractionSimulator( ) # start_rod_1[2] = cylinder_radius + base_length -rod1 = CosseratRod.straight_rod( +rod1 = ea.CosseratRod.straight_rod( n_elem, start_rod_1, direction, @@ -73,7 +78,7 @@ class SingleRodSingleCylinderInteractionSimulator( single_rod_sim.append(rod1) -cylinder = Cylinder( +cylinder = ea.Cylinder( cylinder_start, cylinder_direction, cylinder_normal, @@ -83,17 +88,17 @@ class SingleRodSingleCylinderInteractionSimulator( ) single_rod_sim.append(cylinder) -single_rod_sim.connect(rod1, cylinder).using(ExternalContact, 1e2, 0.1) +single_rod_sim.connect(rod1, cylinder).using(ea.ExternalContact, 1e2, 0.1) # Add call backs -class PositionCollector(CallBackBaseClass): +class PositionCollector(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -106,11 +111,11 @@ def make_callback(self, system, time, current_step: int): return -recorded_rod_history = defaultdict(list) +recorded_rod_history = ea.defaultdict(list) single_rod_sim.collect_diagnostics(rod1).using( PositionCollector, step_skip=200, callback_params=recorded_rod_history ) -recorded_cyl_history = defaultdict(list) +recorded_cyl_history = ea.defaultdict(list) single_rod_sim.collect_diagnostics(cylinder).using( PositionCollector, step_skip=200, callback_params=recorded_cyl_history ) @@ -119,19 +124,19 @@ def make_callback(self, system, time, current_step: int): damping_constant = 1e-3 dt = 1e-4 single_rod_sim.dampen(rod1).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) single_rod_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() final_time = 2.0 dl = base_length / n_elem total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, single_rod_sim, final_time, total_steps) +ea.integrate(timestepper, single_rod_sim, final_time, total_steps) if PLOT_FIGURE: plot_video( diff --git a/examples/RigidBodyCases/rigid_cylinder_rotational_motion_case.py b/examples/RigidBodyCases/rigid_cylinder_rotational_motion_case.py index 32316656..9a8149b8 100644 --- a/examples/RigidBodyCases/rigid_cylinder_rotational_motion_case.py +++ b/examples/RigidBodyCases/rigid_cylinder_rotational_motion_case.py @@ -1,11 +1,13 @@ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) -class RigidCylinderSimulator(BaseSystemCollection, Constraints, Forcing, CallBacks): +class RigidCylinderSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.CallBacks +): pass @@ -37,11 +39,11 @@ def rigid_cylinder_rotational_motion_verification(torque=0.0): base_area = np.pi * base_radius ** 2 density = 1000 - cylinder = Cylinder(start, direction, normal, base_length, base_radius, density) + cylinder = ea.Cylinder(start, direction, normal, base_length, base_radius, density) rigid_cylinder_sim.append(cylinder) - class PointCoupleToCenter(NoForces): + class PointCoupleToCenter(ea.NoForces): """ Applies torque on rigid body """ @@ -61,13 +63,13 @@ def apply_forces(self, system, time: np.float = 0.0): ) # Add call backs - class RigidSphereCallBack(CallBackBaseClass): + class RigidSphereCallBack(ea.CallBackBaseClass): """ Call back function for continuum snake """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -85,19 +87,19 @@ def make_callback(self, system, time, current_step: int): return step_skip = 200 - pp_list = defaultdict(list) + pp_list = ea.defaultdict(list) rigid_cylinder_sim.collect_diagnostics(cylinder).using( RigidSphereCallBack, step_skip=step_skip, callback_params=pp_list ) rigid_cylinder_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 0.25 dt = 4.0e-5 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, rigid_cylinder_sim, final_time, total_steps) + ea.integrate(timestepper, rigid_cylinder_sim, final_time, total_steps) # compute translational and rotational energy translational_energy = cylinder.compute_translational_energy() diff --git a/examples/RigidBodyCases/rigid_cylinder_translational_motion_case.py b/examples/RigidBodyCases/rigid_cylinder_translational_motion_case.py index 40496076..c70d3510 100644 --- a/examples/RigidBodyCases/rigid_cylinder_translational_motion_case.py +++ b/examples/RigidBodyCases/rigid_cylinder_translational_motion_case.py @@ -1,11 +1,13 @@ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) -class RigidCylinderSimulator(BaseSystemCollection, Constraints, Forcing, CallBacks): +class RigidCylinderSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.CallBacks +): pass @@ -37,11 +39,11 @@ def rigid_cylinder_translational_motion_verification(force=0.0): base_area = np.pi * base_radius ** 2 density = 1000 - cylinder = Cylinder(start, direction, normal, base_length, base_radius, density) + cylinder = ea.Cylinder(start, direction, normal, base_length, base_radius, density) rigid_cylinder_sim.append(cylinder) - class PointForceToCenter(NoForces): + class PointForceToCenter(ea.NoForces): """ Applies force on rigid body """ @@ -59,13 +61,13 @@ def apply_forces(self, system, time: np.float = 0.0): ) # Add call backs - class RigidSphereCallBack(CallBackBaseClass): + class RigidSphereCallBack(ea.CallBackBaseClass): """ Call back function """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -83,19 +85,19 @@ def make_callback(self, system, time, current_step: int): return step_skip = 200 - pp_list = defaultdict(list) + pp_list = ea.defaultdict(list) rigid_cylinder_sim.collect_diagnostics(cylinder).using( RigidSphereCallBack, step_skip=step_skip, callback_params=pp_list ) rigid_cylinder_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 0.25 dt = 4.0e-5 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, rigid_cylinder_sim, final_time, total_steps) + ea.integrate(timestepper, rigid_cylinder_sim, final_time, total_steps) # compute translational and rotational energy translational_energy = cylinder.compute_translational_energy() diff --git a/examples/RigidBodyCases/rigid_sphere_rotational_motion_case.py b/examples/RigidBodyCases/rigid_sphere_rotational_motion_case.py index 1e051ede..a4871d87 100644 --- a/examples/RigidBodyCases/rigid_sphere_rotational_motion_case.py +++ b/examples/RigidBodyCases/rigid_sphere_rotational_motion_case.py @@ -1,11 +1,13 @@ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) -class RigidSphereSimulator(BaseSystemCollection, Constraints, Forcing, CallBacks): +class RigidSphereSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.CallBacks +): pass @@ -28,11 +30,11 @@ def rigid_sphere_rolling_verification(torque=0.0): # setting up test params density = 1000 sphere_radius = 0.05 - sphere = Sphere([0.0, sphere_radius, 0.0], sphere_radius, density) + sphere = ea.Sphere([0.0, sphere_radius, 0.0], sphere_radius, density) rigid_sphere_sim.append(sphere) - class PointCoupleToCenter(NoForces): + class PointCoupleToCenter(ea.NoForces): """ Applies torque on rigid body """ @@ -52,13 +54,13 @@ def apply_forces(self, system, time: np.float = 0.0): ) # Add call backs - class RigidSphereCallBack(CallBackBaseClass): + class RigidSphereCallBack(ea.CallBackBaseClass): """ Call back function """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -76,19 +78,19 @@ def make_callback(self, system, time, current_step: int): return step_skip = 200 - pp_list = defaultdict(list) + pp_list = ea.defaultdict(list) rigid_sphere_sim.collect_diagnostics(sphere).using( RigidSphereCallBack, step_skip=step_skip, callback_params=pp_list ) rigid_sphere_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 0.25 # 11.0 + 0.01) dt = 4.0e-5 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, rigid_sphere_sim, final_time, total_steps) + ea.integrate(timestepper, rigid_sphere_sim, final_time, total_steps) # compute translational and rotational energy translational_energy = sphere.compute_translational_energy() diff --git a/examples/RigidBodyCases/rigid_sphere_translational_motion_case.py b/examples/RigidBodyCases/rigid_sphere_translational_motion_case.py index 9c8fdafa..ee1116d2 100644 --- a/examples/RigidBodyCases/rigid_sphere_translational_motion_case.py +++ b/examples/RigidBodyCases/rigid_sphere_translational_motion_case.py @@ -1,11 +1,13 @@ import numpy as np -from elastica import * +import elastica as ea from examples.FrictionValidationCases.friction_validation_postprocessing import ( plot_friction_validation, ) -class RigidSphereSimulator(BaseSystemCollection, Constraints, Forcing, CallBacks): +class RigidSphereSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.CallBacks +): pass @@ -29,11 +31,11 @@ def rigid_sphere_translational_motion_verification(force=0.0): # setting up test params density = 1000 sphere_radius = 0.05 - sphere = Sphere([0.0, sphere_radius, 0.0], sphere_radius, density) + sphere = ea.Sphere([0.0, sphere_radius, 0.0], sphere_radius, density) rigid_sphere_sim.append(sphere) - class PointForceToCenter(NoForces): + class PointForceToCenter(ea.NoForces): """ Applies force on rigid body """ @@ -53,13 +55,13 @@ def apply_forces(self, system, time: np.float = 0.0): ) # Add call backs - class RigidSphereCallBack(CallBackBaseClass): + class RigidSphereCallBack(ea.CallBackBaseClass): """ Call back function """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -77,19 +79,19 @@ def make_callback(self, system, time, current_step: int): return step_skip = 200 - pp_list = defaultdict(list) + pp_list = ea.defaultdict(list) rigid_sphere_sim.collect_diagnostics(sphere).using( RigidSphereCallBack, step_skip=step_skip, callback_params=pp_list ) rigid_sphere_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() final_time = 0.25 dt = 4.0e-5 total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, rigid_sphere_sim, final_time, total_steps) + ea.integrate(timestepper, rigid_sphere_sim, final_time, total_steps) # compute translational and rotational energy translational_energy = sphere.compute_translational_energy() diff --git a/examples/RodContactCase/RodRodContact/rod_rod_contact_inclined_validation.py b/examples/RodContactCase/RodRodContact/rod_rod_contact_inclined_validation.py index dd3d3ee0..90908264 100644 --- a/examples/RodContactCase/RodRodContact/rod_rod_contact_inclined_validation.py +++ b/examples/RodContactCase/RodRodContact/rod_rod_contact_inclined_validation.py @@ -1,5 +1,5 @@ import numpy as np -from elastica import * +import elastica as ea from examples.RodContactCase.post_processing import ( plot_video_with_surface, plot_velocity, @@ -7,7 +7,12 @@ class InclinedRodRodContact( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -47,7 +52,7 @@ class InclinedRodRodContact( n_elem_rod_one = 50 start_rod_one = start + normal * 0.2 -rod_one = CosseratRod.straight_rod( +rod_one = ea.CosseratRod.straight_rod( n_elem_rod_one, start_rod_one, direction, @@ -72,7 +77,7 @@ class InclinedRodRodContact( normal = np.array([0.0, -np.sin(inclination), np.cos(inclination)]) start_rod_two = start -rod_two = CosseratRod.straight_rod( +rod_two = ea.CosseratRod.straight_rod( n_elem_rod_two, start_rod_two, direction, @@ -89,7 +94,7 @@ class InclinedRodRodContact( # Contact between two rods inclined_rod_rod_contact_sim.connect(rod_one, rod_two).using( - ExternalContact, k=1e3, nu=0.0 + ea.ExternalContact, k=1e3, nu=0.0 ) # add damping @@ -97,22 +102,22 @@ class InclinedRodRodContact( # damping_constant = 2e-3 damping_constant = 4e-4 inclined_rod_rod_contact_sim.dampen(rod_one).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) inclined_rod_rod_contact_sim.dampen(rod_two).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) # Add call backs -class RodCallBack(CallBackBaseClass): +class RodCallBack(ea.CallBackBaseClass): """ """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -138,7 +143,7 @@ def make_callback(self, system, time, current_step: int): return -post_processing_dict_rod1 = defaultdict( +post_processing_dict_rod1 = ea.defaultdict( list ) # list which collected data will be append # set the diagnostics for rod and collect data @@ -148,7 +153,7 @@ def make_callback(self, system, time, current_step: int): callback_params=post_processing_dict_rod1, ) -post_processing_dict_rod2 = defaultdict( +post_processing_dict_rod2 = ea.defaultdict( list ) # list which collected data will be append # set the diagnostics for rod and collect data @@ -161,8 +166,8 @@ def make_callback(self, system, time, current_step: int): inclined_rod_rod_contact_sim.finalize() # Do the simulation -timestepper = PositionVerlet() -integrate(timestepper, inclined_rod_rod_contact_sim, final_time, total_steps) +timestepper = ea.PositionVerlet() +ea.integrate(timestepper, inclined_rod_rod_contact_sim, final_time, total_steps) # plotting the videos filename_video = "inclined_rods_contact.mp4" diff --git a/examples/RodContactCase/RodRodContact/rod_rod_contact_parallel_validation.py b/examples/RodContactCase/RodRodContact/rod_rod_contact_parallel_validation.py index 68d07633..bbe17fbc 100644 --- a/examples/RodContactCase/RodRodContact/rod_rod_contact_parallel_validation.py +++ b/examples/RodContactCase/RodRodContact/rod_rod_contact_parallel_validation.py @@ -1,5 +1,5 @@ import numpy as np -from elastica import * +import elastica as ea from examples.RodContactCase.post_processing import ( plot_video_with_surface, plot_velocity, @@ -7,7 +7,12 @@ class ParallelRodRodContact( - BaseSystemCollection, Constraints, Connections, Forcing, Damping, CallBacks + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.Damping, + ea.CallBacks, ): pass @@ -47,7 +52,7 @@ class ParallelRodRodContact( n_elem_rod_one = 50 start_rod_one = start + normal * 0.2 -rod_one = CosseratRod.straight_rod( +rod_one = ea.CosseratRod.straight_rod( n_elem_rod_one, start_rod_one, direction, @@ -69,7 +74,7 @@ class ParallelRodRodContact( start_rod_two = start -rod_two = CosseratRod.straight_rod( +rod_two = ea.CosseratRod.straight_rod( n_elem_rod_two, start_rod_two, direction, @@ -86,7 +91,7 @@ class ParallelRodRodContact( # Contact between two rods parallel_rod_rod_contact_sim.connect(rod_one, rod_two).using( - ExternalContact, k=1e3, nu=0.001 + ea.ExternalContact, k=1e3, nu=0.001 ) # add damping @@ -94,22 +99,22 @@ class ParallelRodRodContact( # damping_constant = 2e-3 damping_constant = 2e-4 parallel_rod_rod_contact_sim.dampen(rod_one).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) parallel_rod_rod_contact_sim.dampen(rod_two).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=damping_constant, time_step=dt, ) # Add call backs -class RodCallBack(CallBackBaseClass): +class RodCallBack(ea.CallBackBaseClass): """ """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -135,7 +140,7 @@ def make_callback(self, system, time, current_step: int): return -post_processing_dict_rod1 = defaultdict( +post_processing_dict_rod1 = ea.defaultdict( list ) # list which collected data will be append # set the diagnostics for rod and collect data @@ -145,7 +150,7 @@ def make_callback(self, system, time, current_step: int): callback_params=post_processing_dict_rod1, ) -post_processing_dict_rod2 = defaultdict( +post_processing_dict_rod2 = ea.defaultdict( list ) # list which collected data will be append # set the diagnostics for rod and collect data @@ -158,8 +163,8 @@ def make_callback(self, system, time, current_step: int): parallel_rod_rod_contact_sim.finalize() # Do the simulation -timestepper = PositionVerlet() -integrate(timestepper, parallel_rod_rod_contact_sim, final_time, total_steps) +timestepper = ea.PositionVerlet() +ea.integrate(timestepper, parallel_rod_rod_contact_sim, final_time, total_steps) # plotting the videos filename_video = "parallel_rods_contact.mp4" diff --git a/examples/RodContactCase/RodSelfContact/PlectonemesCase/plectoneme_case.py b/examples/RodContactCase/RodSelfContact/PlectonemesCase/plectoneme_case.py index 761aa994..4280d280 100644 --- a/examples/RodContactCase/RodSelfContact/PlectonemesCase/plectoneme_case.py +++ b/examples/RodContactCase/RodSelfContact/PlectonemesCase/plectoneme_case.py @@ -1,5 +1,5 @@ import numpy as np -from elastica import * +import elastica as ea from examples.RodContactCase.post_processing import ( plot_video_with_surface, plot_velocity, @@ -8,12 +8,12 @@ class PlectonemesCase( - BaseSystemCollection, - Constraints, - Connections, - Forcing, - CallBacks, - Damping, + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.CallBacks, + ea.Damping, ): pass @@ -53,7 +53,7 @@ class PlectonemesCase( 3, ) -sherable_rod = CosseratRod.straight_rod( +sherable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -73,7 +73,7 @@ class PlectonemesCase( # Add damping plectonemes_sim.dampen(sherable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) @@ -82,7 +82,7 @@ class PlectonemesCase( from elastica._rotations import _get_rotation_matrix -class SelonoidsBC(ConstraintBase): +class SelonoidsBC(ea.ConstraintBase): """ """ def __init__( @@ -167,14 +167,14 @@ def constrain_rates(self, rod, time): ) # Add self contact to prevent penetration -plectonemes_sim.connect(sherable_rod, sherable_rod).using(SelfContact, k=1e4, nu=10) +plectonemes_sim.connect(sherable_rod, sherable_rod).using(ea.SelfContact, k=1e4, nu=10) # Add callback functions for plotting position of the rod later on -class RodCallBack(CallBackBaseClass): +class RodCallBack(ea.CallBackBaseClass): """ """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -201,7 +201,7 @@ def make_callback(self, system, time, current_step: int): return -post_processing_dict = defaultdict(list) # list which collected data will be append +post_processing_dict = ea.defaultdict(list) # list which collected data will be append # set the diagnostics for rod and collect data plectonemes_sim.collect_diagnostics(sherable_rod).using( RodCallBack, @@ -213,8 +213,8 @@ def make_callback(self, system, time, current_step: int): plectonemes_sim.finalize() # Run the simulation -time_stepper = PositionVerlet() -integrate(time_stepper, plectonemes_sim, final_time, total_steps) +time_stepper = ea.PositionVerlet() +ea.integrate(time_stepper, plectonemes_sim, final_time, total_steps) # plotting the videos filename_video = "plectonemes.mp4" @@ -255,9 +255,9 @@ def make_callback(self, system, time, current_step: int): type_of_additional_segment = "next_tangent" -total_twist, local_twist = compute_twist(position_history, normal_history) +total_twist, local_twist = ea.compute_twist(position_history, normal_history) -total_link = compute_link( +total_link = ea.compute_link( position_history, normal_history, radius_history, @@ -265,7 +265,7 @@ def make_callback(self, system, time, current_step: int): type_of_additional_segment, ) -total_writhe = compute_writhe( +total_writhe = ea.compute_writhe( position_history, segment_length, type_of_additional_segment ) diff --git a/examples/RodContactCase/RodSelfContact/SolenoidsCase/solenoid_case.py b/examples/RodContactCase/RodSelfContact/SolenoidsCase/solenoid_case.py index 2c3ec335..7ac594f1 100644 --- a/examples/RodContactCase/RodSelfContact/SolenoidsCase/solenoid_case.py +++ b/examples/RodContactCase/RodSelfContact/SolenoidsCase/solenoid_case.py @@ -1,5 +1,5 @@ import numpy as np -from elastica import * +import elastica as ea from examples.RodContactCase.post_processing import ( plot_video_with_surface, plot_velocity, @@ -8,7 +8,12 @@ class SolenoidCase( - BaseSystemCollection, Constraints, Connections, Forcing, CallBacks, Damping + ea.BaseSystemCollection, + ea.Constraints, + ea.Connections, + ea.Forcing, + ea.CallBacks, + ea.Damping, ): pass @@ -52,7 +57,7 @@ class SolenoidCase( F_pulling_scalar = 300 -sherable_rod = CosseratRod.straight_rod( +sherable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -70,7 +75,7 @@ class SolenoidCase( # Add damping solenoid_sim.dampen(sherable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) @@ -79,7 +84,7 @@ class SolenoidCase( from elastica._rotations import _get_rotation_matrix -class SelonoidsBC(ConstraintBase): +class SelonoidsBC(ea.ConstraintBase): """ """ def __init__( @@ -164,7 +169,7 @@ def constrain_rates(self, rod, time): ) solenoid_sim.add_forcing_to(sherable_rod).using( - EndpointForces, + ea.EndpointForces, np.zeros( 3, ), @@ -173,14 +178,14 @@ def constrain_rates(self, rod, time): ) # Add self contact to prevent penetration -solenoid_sim.connect(sherable_rod, sherable_rod).using(SelfContact, k=1e4, nu=10) +solenoid_sim.connect(sherable_rod, sherable_rod).using(ea.SelfContact, k=1e4, nu=10) # Add callback functions for plotting position of the rod later on -class RodCallBack(CallBackBaseClass): +class RodCallBack(ea.CallBackBaseClass): """ """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -207,7 +212,7 @@ def make_callback(self, system, time, current_step: int): return -post_processing_dict = defaultdict(list) # list which collected data will be append +post_processing_dict = ea.defaultdict(list) # list which collected data will be append # set the diagnostics for rod and collect data solenoid_sim.collect_diagnostics(sherable_rod).using( RodCallBack, @@ -219,8 +224,8 @@ def make_callback(self, system, time, current_step: int): solenoid_sim.finalize() # Run the simulation -time_stepper = PositionVerlet() -integrate(time_stepper, solenoid_sim, final_time, total_steps) +time_stepper = ea.PositionVerlet() +ea.integrate(time_stepper, solenoid_sim, final_time, total_steps) # plotting the videos filename_video = "solenoid.mp4" @@ -261,9 +266,9 @@ def make_callback(self, system, time, current_step: int): type_of_additional_segment = "next_tangent" -total_twist, local_twist = compute_twist(position_history, normal_history) +total_twist, local_twist = ea.compute_twist(position_history, normal_history) -total_link = compute_link( +total_link = ea.compute_link( position_history, normal_history, radius_history, @@ -271,7 +276,7 @@ def make_callback(self, system, time, current_step: int): type_of_additional_segment, ) -total_writhe = compute_writhe( +total_writhe = ea.compute_writhe( position_history, segment_length, type_of_additional_segment ) diff --git a/examples/TimoshenkoBeamCase/convergence_timoshenko.py b/examples/TimoshenkoBeamCase/convergence_timoshenko.py index 2a896b25..98c16dce 100644 --- a/examples/TimoshenkoBeamCase/convergence_timoshenko.py +++ b/examples/TimoshenkoBeamCase/convergence_timoshenko.py @@ -2,7 +2,7 @@ Gazzola et. al. R. Soc. 2018 section 3.4.3 """ import numpy as np -from elastica import * +import elastica as ea from examples.TimoshenkoBeamCase.timoshenko_postprocessing import ( plot_timoshenko, analytical_shearable, @@ -10,7 +10,9 @@ from examples.convergence_functions import calculate_error_norm, plot_convergence -class TimoshenkoBeamSimulator(BaseSystemCollection, Constraints, Forcing, Damping): +class TimoshenkoBeamSimulator( + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.Damping +): pass @@ -40,7 +42,7 @@ def simulate_timoshenko_beam_with( poisson_ratio = 99 shear_modulus = E / (poisson_ratio + 1.0) - shearable_rod = CosseratRod.straight_rod( + shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -58,23 +60,23 @@ def simulate_timoshenko_beam_with( dl = base_length / n_elem dt = 0.07 * dl timoshenko_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) timoshenko_sim.constrain(shearable_rod).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) end_force = np.array([-15.0, 0.0, 0.0]) timoshenko_sim.add_forcing_to(shearable_rod).using( - EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2 + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2 ) if ADD_UNSHEARABLE_ROD: # Start into the plane unshearable_start = np.array([0.0, -1.0, 0.0]) shear_modulus = E / (-0.7 + 1.0) - unshearable_rod = CosseratRod.straight_rod( + unshearable_rod = ea.CosseratRod.straight_rod( n_elem, unshearable_start, direction, @@ -91,26 +93,28 @@ def simulate_timoshenko_beam_with( timoshenko_sim.append(unshearable_rod) # add damping timoshenko_sim.dampen(unshearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) timoshenko_sim.constrain(unshearable_rod).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, + constrained_position_idx=(0,), + constrained_director_idx=(0,), ) timoshenko_sim.add_forcing_to(unshearable_rod).using( - EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2 + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2 ) timoshenko_sim.finalize() - timestepper = PositionVerlet() + timestepper = ea.PositionVerlet() # timestepper = PEFRL() dl = base_length / n_elem dt = 0.01 * dl total_steps = int(final_time / dt) print("Total steps", total_steps) - integrate(timestepper, timoshenko_sim, final_time, total_steps) + ea.integrate(timestepper, timoshenko_sim, final_time, total_steps) if PLOT_FIGURE: plot_timoshenko(shearable_rod, end_force, SAVE_FIGURE, ADD_UNSHEARABLE_ROD) diff --git a/examples/TimoshenkoBeamCase/timoshenko.py b/examples/TimoshenkoBeamCase/timoshenko.py index e459f803..8b9ac44d 100644 --- a/examples/TimoshenkoBeamCase/timoshenko.py +++ b/examples/TimoshenkoBeamCase/timoshenko.py @@ -2,12 +2,12 @@ Gazzola et. al. R. Soc. 2018 section 3.4.3 """ import numpy as np -from elastica import * +import elastica as ea from examples.TimoshenkoBeamCase.timoshenko_postprocessing import plot_timoshenko class TimoshenkoBeamSimulator( - BaseSystemCollection, Constraints, Forcing, CallBacks, Damping + ea.BaseSystemCollection, ea.Constraints, ea.Forcing, ea.CallBacks, ea.Damping ): pass @@ -36,7 +36,7 @@ class TimoshenkoBeamSimulator( poisson_ratio = 99 shear_modulus = E / (poisson_ratio + 1.0) -shearable_rod = CosseratRod.straight_rod( +shearable_rod = ea.CosseratRod.straight_rod( n_elem, start, direction, @@ -54,18 +54,18 @@ class TimoshenkoBeamSimulator( dl = base_length / n_elem dt = 0.07 * dl timoshenko_sim.dampen(shearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) timoshenko_sim.constrain(shearable_rod).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) end_force = np.array([-15.0, 0.0, 0.0]) timoshenko_sim.add_forcing_to(shearable_rod).using( - EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 ) @@ -73,7 +73,7 @@ class TimoshenkoBeamSimulator( # Start into the plane unshearable_start = np.array([0.0, -1.0, 0.0]) shear_modulus = E / (-0.7 + 1.0) - unshearable_rod = CosseratRod.straight_rod( + unshearable_rod = ea.CosseratRod.straight_rod( n_elem, unshearable_start, direction, @@ -91,25 +91,25 @@ class TimoshenkoBeamSimulator( # add damping timoshenko_sim.dampen(unshearable_rod).using( - AnalyticalLinearDamper, + ea.AnalyticalLinearDamper, damping_constant=nu, time_step=dt, ) timoshenko_sim.constrain(unshearable_rod).using( - OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) + ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) ) timoshenko_sim.add_forcing_to(unshearable_rod).using( - EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 ) # Add call backs -class VelocityCallBack(CallBackBaseClass): +class VelocityCallBack(ea.CallBackBaseClass): """ Tracks the velocity norms of the rod """ def __init__(self, step_skip: int, callback_params: dict): - CallBackBaseClass.__init__(self) + ea.CallBackBaseClass.__init__(self) self.every = step_skip self.callback_params = callback_params @@ -125,18 +125,18 @@ def make_callback(self, system, time, current_step: int): return -recorded_history = defaultdict(list) +recorded_history = ea.defaultdict(list) timoshenko_sim.collect_diagnostics(shearable_rod).using( VelocityCallBack, step_skip=500, callback_params=recorded_history ) timoshenko_sim.finalize() -timestepper = PositionVerlet() +timestepper = ea.PositionVerlet() # timestepper = PEFRL() total_steps = int(final_time / dt) print("Total steps", total_steps) -integrate(timestepper, timoshenko_sim, final_time, total_steps) +ea.integrate(timestepper, timoshenko_sim, final_time, total_steps) if PLOT_FIGURE: plot_timoshenko(shearable_rod, end_force, SAVE_FIGURE, ADD_UNSHEARABLE_ROD) From c33c98107255c22e90c21dcea89a1b87bf7085d4 Mon Sep 17 00:00:00 2001 From: AsadNizami Date: Tue, 4 Apr 2023 12:23:22 +0530 Subject: [PATCH 4/8] Removed wildcards imports from the module --- elastica/boundary_conditions.py | 8 -------- elastica/callback_functions.py | 1 - elastica/dissipation.py | 6 +----- .../generic_system_type_connection.py | 1 - elastica/experimental/interaction.py | 4 ---- elastica/external_forces.py | 10 +--------- elastica/interaction.py | 6 ------ elastica/joint.py | 2 +- elastica/restart.py | 2 +- elastica/rigidbody/cylinder.py | 1 - elastica/rigidbody/sphere.py | 1 - elastica/rod/cosserat_rod.py | 1 - elastica/rod/data_structures.py | 9 +-------- elastica/rod/factory_function.py | 1 - elastica/rod/knot_theory.py | 7 ------- elastica/transformations.py | 1 - elastica/utils.py | 2 +- elastica/wrappers.py | 9 +-------- 18 files changed, 7 insertions(+), 65 deletions(-) diff --git a/elastica/boundary_conditions.py b/elastica/boundary_conditions.py index 5fbaf4da..b9310658 100644 --- a/elastica/boundary_conditions.py +++ b/elastica/boundary_conditions.py @@ -1,12 +1,4 @@ __doc__ = """ Built-in boundary condition implementationss """ -__all__ = [ - "ConstraintBase", - "FreeBC", - "OneEndFixedBC", - "GeneralConstraint", - "FixedConstraint", - "HelicalBucklingBC", -] import warnings from typing import Optional, Type, Union diff --git a/elastica/callback_functions.py b/elastica/callback_functions.py index 09f5b8aa..ab865dfd 100644 --- a/elastica/callback_functions.py +++ b/elastica/callback_functions.py @@ -1,5 +1,4 @@ __doc__ = """ Module contains callback classes to save simulation data for rod-like objects """ -__all__ = ["CallBackBaseClass", "MyCallBack", "ExportCallBack"] import os import sys diff --git a/elastica/dissipation.py b/elastica/dissipation.py index 5004d7d1..f52cdc5d 100644 --- a/elastica/dissipation.py +++ b/elastica/dissipation.py @@ -3,11 +3,7 @@ Built in damper module implementations """ -__all__ = [ - "DamperBase", - "AnalyticalLinearDamper", - "LaplaceDissipationFilter", -] + from abc import ABC, abstractmethod from elastica.typing import RodType, SystemType diff --git a/elastica/experimental/connection_contact_joint/generic_system_type_connection.py b/elastica/experimental/connection_contact_joint/generic_system_type_connection.py index d4a0e235..e2628ae2 100644 --- a/elastica/experimental/connection_contact_joint/generic_system_type_connection.py +++ b/elastica/experimental/connection_contact_joint/generic_system_type_connection.py @@ -1,7 +1,6 @@ __doc__ = ( """ Module containing joint classes to connect rods and rigid bodies together. """ ) -__all__ = ["GenericSystemTypeFreeJoint", "GenericSystemTypeFixedJoint"] from elastica.joint import FreeJoint, FixedJoint from elastica.typing import SystemType from elastica.utils import Tolerance, MaxDimension diff --git a/elastica/experimental/interaction.py b/elastica/experimental/interaction.py index c603e016..5e41f784 100644 --- a/elastica/experimental/interaction.py +++ b/elastica/experimental/interaction.py @@ -1,12 +1,8 @@ __doc__ = """ Experimental interaction implementation.""" -__all__ = [ - "AnisotropicFrictionalPlaneRigidBody", -] import numpy as np from elastica.external_forces import NoForces -from elastica.interaction import * from elastica.interaction import ( find_slipping_elements, apply_normal_force_numba_rigid_body, diff --git a/elastica/external_forces.py b/elastica/external_forces.py index 68604fd9..e7edc668 100644 --- a/elastica/external_forces.py +++ b/elastica/external_forces.py @@ -1,13 +1,5 @@ __doc__ = """ Numba implementation module for boundary condition implementations that apply external forces to the rod.""" -__all__ = [ - "NoForces", - "GravityForces", - "EndpointForces", - "UniformTorques", - "UniformForces", - "MuscleTorques", - "EndpointForcesSinusoidal", -] + import numpy as np from elastica._linalg import _batch_matvec diff --git a/elastica/interaction.py b/elastica/interaction.py index 587598dd..a0da78ff 100644 --- a/elastica/interaction.py +++ b/elastica/interaction.py @@ -1,10 +1,4 @@ __doc__ = """ Numba implementation module containing interactions between a rod and its environment.""" -__all__ = [ - "AnisotropicFrictionalPlane", - "InteractionPlane", - "InteractionPlaneRigidBody", - "SlenderBodyTheory", -] import numpy as np diff --git a/elastica/joint.py b/elastica/joint.py index 4db75f97..8cc9bd85 100644 --- a/elastica/joint.py +++ b/elastica/joint.py @@ -1,5 +1,5 @@ __doc__ = """ Module containing joint classes to connect multiple rods together. """ -__all__ = ["FreeJoint", "HingeJoint", "FixedJoint", "ExternalContact", "SelfContact"] + from elastica._linalg import _batch_product_k_ik_to_ik from elastica._rotations import _inv_rotate from math import sqrt diff --git a/elastica/restart.py b/elastica/restart.py index 0ca4c931..7e97cb83 100644 --- a/elastica/restart.py +++ b/elastica/restart.py @@ -1,5 +1,5 @@ __doc__ = """Generate or load restart file implementations.""" -__all__ = ["save_state", "load_state"] + import numpy as np import os from itertools import groupby diff --git a/elastica/rigidbody/cylinder.py b/elastica/rigidbody/cylinder.py index fe095f2f..f9078d49 100644 --- a/elastica/rigidbody/cylinder.py +++ b/elastica/rigidbody/cylinder.py @@ -1,5 +1,4 @@ __doc__ = """""" -__all__ = ["Cylinder"] import numpy as np diff --git a/elastica/rigidbody/sphere.py b/elastica/rigidbody/sphere.py index dfce60e1..a02d4259 100644 --- a/elastica/rigidbody/sphere.py +++ b/elastica/rigidbody/sphere.py @@ -1,5 +1,4 @@ __doc__ = """""" -__all__ = ["Sphere"] import numpy as np diff --git a/elastica/rod/cosserat_rod.py b/elastica/rod/cosserat_rod.py index 6af88e6b..5b8c8fcd 100644 --- a/elastica/rod/cosserat_rod.py +++ b/elastica/rod/cosserat_rod.py @@ -1,5 +1,4 @@ __doc__ = """ Rod classes and implementation details """ -__all__ = ["CosseratRod"] import typing diff --git a/elastica/rod/data_structures.py b/elastica/rod/data_structures.py index 705c0971..0e199b97 100644 --- a/elastica/rod/data_structures.py +++ b/elastica/rod/data_structures.py @@ -1,12 +1,5 @@ __doc__ = "Data structure wrapper for rod components" -__all__ = [ - "_RodSymplecticStepperMixin", - "_bootstrap_from_data", - "_State", - "_DerivativeState", - "_KinematicState", - "_DynamicState", -] + import numpy as np import numba from numba import njit diff --git a/elastica/rod/factory_function.py b/elastica/rod/factory_function.py index 871d8de8..e259f62f 100644 --- a/elastica/rod/factory_function.py +++ b/elastica/rod/factory_function.py @@ -1,5 +1,4 @@ __doc__ = """ Factory function to allocate variables for Cosserat Rod""" -__all__ = ["allocate"] from typing import Optional, Tuple import logging import numpy as np diff --git a/elastica/rod/knot_theory.py b/elastica/rod/knot_theory.py index f31d2abe..e9688423 100644 --- a/elastica/rod/knot_theory.py +++ b/elastica/rod/knot_theory.py @@ -9,13 +9,6 @@ The details discussion is included in `N Charles et. al. PRL (2019) `_. """ -__all__ = [ - "KnotTheoryCompatibleProtocol", - "KnotTheory", - "compute_twist", - "compute_link", - "compute_writhe", -] import sys diff --git a/elastica/transformations.py b/elastica/transformations.py index 142b9f5d..882094c4 100644 --- a/elastica/transformations.py +++ b/elastica/transformations.py @@ -1,5 +1,4 @@ __doc__ = """ Rotation interface functions""" -__all__ = ["skew_symmetrize", "inv_skew_symmetrize", "rotate"] import numpy as np diff --git a/elastica/utils.py b/elastica/utils.py index 57fb24a1..5d84741c 100644 --- a/elastica/utils.py +++ b/elastica/utils.py @@ -1,6 +1,6 @@ """ Handy utilities """ -__all__ = ["isqrt"] + import functools import numpy as np from numpy import finfo, float64 diff --git a/elastica/wrappers.py b/elastica/wrappers.py index af8940f2..e6ef6d51 100644 --- a/elastica/wrappers.py +++ b/elastica/wrappers.py @@ -1,13 +1,6 @@ import warnings -__all__ = [ - "BaseSystemCollection", - "Connections", - "Constraints", - "Forcing", - "CallBacks", - "Damping", -] + from elastica.modules.base_system import BaseSystemCollection from elastica.modules.connections import Connections from elastica.modules.constraints import Constraints From 72013103f9e8ce6731765ea1735067079b3a9f38 Mon Sep 17 00:00:00 2001 From: AsadNizami Date: Tue, 4 Apr 2023 22:25:50 +0530 Subject: [PATCH 5/8] update --- elastica/__init__.py | 15 --------------- elastica/wrappers.py | 7 ------- 2 files changed, 22 deletions(-) diff --git a/elastica/__init__.py b/elastica/__init__.py index 27f5138a..e69de29b 100644 --- a/elastica/__init__.py +++ b/elastica/__init__.py @@ -1,15 +0,0 @@ -from collections import defaultdict -from elastica.modules import * -from elastica.rod.cosserat_rod import * -from elastica.rod.knot_theory import * -from elastica.rigidbody import * -from elastica.boundary_conditions import * -from elastica.external_forces import * -from elastica.callback_functions import * -from elastica.dissipation import * -from elastica.interaction import * -from elastica.joint import * -from elastica.timestepper import * -from elastica.restart import * -from elastica.reset_functions_for_block_structure import * -from elastica.typing import * diff --git a/elastica/wrappers.py b/elastica/wrappers.py index e6ef6d51..bfdd3cf1 100644 --- a/elastica/wrappers.py +++ b/elastica/wrappers.py @@ -1,13 +1,6 @@ import warnings -from elastica.modules.base_system import BaseSystemCollection -from elastica.modules.connections import Connections -from elastica.modules.constraints import Constraints -from elastica.modules.forcing import Forcing -from elastica.modules.callbacks import CallBacks -from elastica.modules.damping import Damping - warnings.warn( "elastica.wrappers is refactored to elastica.modules in version 0.3.0.", DeprecationWarning, From d943f1df84da066706138902fe1b009668c2af02 Mon Sep 17 00:00:00 2001 From: AsadNizami Date: Thu, 6 Apr 2023 00:41:02 +0530 Subject: [PATCH 6/8] removed all wildcards import --- elastica/__init__.py | 73 +++++++++++++++++++ elastica/memory_block/__init__.py | 9 +-- elastica/modules/__init__.py | 8 -- .../__init__.py | 5 -- elastica/rigidbody/__init__.py | 1 - elastica/rod/__init__.py | 2 +- elastica/timestepper/__init__.py | 9 +-- 7 files changed, 77 insertions(+), 30 deletions(-) diff --git a/elastica/__init__.py b/elastica/__init__.py index e69de29b..7622bf26 100644 --- a/elastica/__init__.py +++ b/elastica/__init__.py @@ -0,0 +1,73 @@ +from collections import defaultdict +from elastica.rod.knot_theory import KnotTheory, KnotTheoryCompatibleProtocol +from elastica.rod.rod_base import RodBase +from elastica.rod.cosserat_rod import CosseratRod +from elastica.rigidbody.rigid_body import RigidBodyBase +from elastica.rigidbody.cylinder import Cylinder +from elastica.rigidbody.sphere import Sphere +from elastica.boundary_conditions import ( + ConstraintBase, + FreeBC, + OneEndFixedBC, + GeneralConstraint, + FixedConstraint, + HelicalBucklingBC, + FreeRod, + OneEndFixedRod, +) +from elastica.external_forces import ( + NoForces, + EndpointForces, + GravityForces, + UniformForces, + UniformTorques, + MuscleTorques, + EndpointForcesSinusoidal, +) +from elastica.interaction import ( + AnisotropicFrictionalPlane, + InteractionPlane, + SlenderBodyTheory, +) +from elastica.joint import ( + FreeJoint, + ExternalContact, + FixedJoint, + HingeJoint, + SelfContact, +) +from elastica.callback_functions import CallBackBaseClass, ExportCallBack, MyCallBack +from elastica.dissipation import ( + DamperBase, + AnalyticalLinearDamper, + LaplaceDissipationFilter, +) +from elastica.modules.base_system import BaseSystemCollection +from elastica.modules.callbacks import CallBacks +from elastica.modules.connections import Connections +from elastica.modules.constraints import Constraints +from elastica.modules.forcing import Forcing +from elastica.modules.damping import Damping +from elastica.transformations import inv_skew_symmetrize +from elastica.transformations import rotate +from elastica._calculus import ( + position_difference_kernel, + position_average, + quadrature_kernel, + difference_kernel, + quadrature_kernel_for_block_structure, + difference_kernel_for_block_structure, +) +from elastica._linalg import levi_civita_tensor +from elastica.utils import isqrt +from elastica.typing import RodType, SystemType +from elastica.timestepper import ( + integrate, + PositionVerlet, + PEFRL, + RungeKutta4, + EulerForward, + extend_stepper_interface, +) +from elastica.memory_block.memory_block_rigid_body import MemoryBlockRigidBody +from elastica.memory_block.memory_block_rod import MemoryBlockCosseratRod diff --git a/elastica/memory_block/__init__.py b/elastica/memory_block/__init__.py index 4d89d9d7..e14c5108 100644 --- a/elastica/memory_block/__init__.py +++ b/elastica/memory_block/__init__.py @@ -1,7 +1,2 @@ -__all__ = [ - "MemoryBlockCosseratRod", - "MemoryBlockRigidBody", -] - -from elastica.memory_block.memory_block_rod import MemoryBlockCosseratRod -from elastica.memory_block.memory_block_rigid_body import MemoryBlockRigidBody +from .memory_block_rigid_body import MemoryBlockRigidBody +from .memory_block_rod import MemoryBlockCosseratRod diff --git a/elastica/modules/__init__.py b/elastica/modules/__init__.py index 6dec136a..889bf69f 100644 --- a/elastica/modules/__init__.py +++ b/elastica/modules/__init__.py @@ -4,14 +4,6 @@ """ -__all__ = [ - "BaseSystemCollection", - "Connections", - "Constraints", - "Forcing", - "CallBacks", - "Damping", -] from .base_system import BaseSystemCollection from .connections import Connections from .constraints import Constraints diff --git a/elastica/reset_functions_for_block_structure/__init__.py b/elastica/reset_functions_for_block_structure/__init__.py index dc00ff55..5ef94f94 100644 --- a/elastica/reset_functions_for_block_structure/__init__.py +++ b/elastica/reset_functions_for_block_structure/__init__.py @@ -1,8 +1,3 @@ -__all__ = [ - "_reset_scalar_ghost", - "_reset_vector_ghost", -] - from elastica.reset_functions_for_block_structure._reset_ghost_vector_or_scalar import ( _reset_scalar_ghost, _reset_vector_ghost, diff --git a/elastica/rigidbody/__init__.py b/elastica/rigidbody/__init__.py index f72edff3..732577df 100644 --- a/elastica/rigidbody/__init__.py +++ b/elastica/rigidbody/__init__.py @@ -1,4 +1,3 @@ -__all__ = ["RigidBodyBase", "Cylinder", "Sphere"] from .rigid_body import RigidBodyBase from .cylinder import Cylinder from .sphere import Sphere diff --git a/elastica/rod/__init__.py b/elastica/rod/__init__.py index 08263853..6dca5160 100644 --- a/elastica/rod/__init__.py +++ b/elastica/rod/__init__.py @@ -1,6 +1,6 @@ __doc__ = """Rod classes and its data structures """ -from elastica.rod.knot_theory import * +from elastica.rod.knot_theory import KnotTheory from elastica.rod.data_structures import * from elastica.rod.rod_base import RodBase diff --git a/elastica/timestepper/__init__.py b/elastica/timestepper/__init__.py index 5e275ec5..3efa466e 100644 --- a/elastica/timestepper/__init__.py +++ b/elastica/timestepper/__init__.py @@ -1,12 +1,5 @@ __doc__ = """Timestepping utilities to be used with Rod and RigidBody classes""" -__all__ = [ - "integrate", - "PositionVerlet", - "PEFRL", - "RungeKutta4", - "EulerForward", - "extend_stepper_interface", -] + import numpy as np from tqdm import tqdm From 0e875d9151e8f94cd33bfab93ca28bf9fafdba95 Mon Sep 17 00:00:00 2001 From: AsadNizami Date: Thu, 6 Apr 2023 01:26:03 +0530 Subject: [PATCH 7/8] update --- elastica/rod/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/elastica/rod/__init__.py b/elastica/rod/__init__.py index 6dca5160..b9285b3c 100644 --- a/elastica/rod/__init__.py +++ b/elastica/rod/__init__.py @@ -2,5 +2,11 @@ from elastica.rod.knot_theory import KnotTheory -from elastica.rod.data_structures import * from elastica.rod.rod_base import RodBase +from elastica.rod.data_structures import ( + _RodSymplecticStepperMixin, + _State, + _DerivativeState, + _KinematicState, + _DynamicState, +) From 530387bef6d2d0f44dede15a31b92e9b74141bf8 Mon Sep 17 00:00:00 2001 From: AsadNizami Date: Fri, 7 Apr 2023 02:57:21 +0530 Subject: [PATCH 8/8] bringing back __all__ --- elastica/wrappers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/elastica/wrappers.py b/elastica/wrappers.py index bfdd3cf1..fa3990f8 100644 --- a/elastica/wrappers.py +++ b/elastica/wrappers.py @@ -1,5 +1,21 @@ import warnings +__all__ = [ + "BaseSystemCollection", + "Connections", + "Constraints", + "Forcing", + "CallBacks", + "Damping", +] + +from elastica.modules.base_system import BaseSystemCollection +from elastica.modules.connections import Connections +from elastica.modules.constraints import Constraints +from elastica.modules.forcing import Forcing +from elastica.modules.callbacks import CallBacks +from elastica.modules.damping import Damping + warnings.warn( "elastica.wrappers is refactored to elastica.modules in version 0.3.0.",