Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: wrappers -> modules #177

Merged
merged 6 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/api/simulator.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Simulator
=========

.. automodule:: elastica.wrappers.base_system
.. automodule:: elastica.modules.base_system
:members:
:exclude-members: __weakref__, __init__, __str__, insert

.. automodule:: elastica.wrappers.callbacks
.. automodule:: elastica.modules.callbacks
:members:
:exclude-members: __weakref__, __init__, _callbacks, _CallBack

.. automodule:: elastica.wrappers.connections
.. automodule:: elastica.modules.connections
:members:
:exclude-members: __weakref__, __init__, __call__, _Connect

.. automodule:: elastica.wrappers.constraints
.. automodule:: elastica.modules.constraints
:members:
:exclude-members: __weakref__, __init__, _Constraint

.. automodule:: elastica.wrappers.forcing
.. automodule:: elastica.modules.forcing
:members:
:exclude-members: __weakref__, __init__, __call__, _ExtForceTorque

.. automodule:: elastica.wrappers.damping
.. automodule:: elastica.modules.damping
:members:
:exclude-members: __weakref__, __init__, __call__, _Damper
:exclude-members: __weakref__, __init__, __call__, _Damper
4 changes: 2 additions & 2 deletions docs/guide/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When using PyElastica, users will setup a simulation in which they define a syst
<h2>1. Setup Simulation</h2>

```python
from elastica.wrappers import (
from elastica.modules import (
BaseSystemCollection,
Connections,
Constraints,
Expand All @@ -28,7 +28,7 @@ class SystemSimulator(
):
pass
```
This simply combines all the wrappers previously imported together. If a wrapper is not needed for the simulation, it does not need to be added here.
This simply combines all the modules previously imported together. If a modules are not needed for the simulation, it does not need to be added here.
bhosale2 marked this conversation as resolved.
Show resolved Hide resolved

Available components are:

Expand Down
2 changes: 1 addition & 1 deletion elastica/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import defaultdict
from elastica.wrappers import *
from elastica.modules import *
from elastica.rod.cosserat_rod import *
from elastica.rod.knot_theory import *
from elastica.rigidbody import *
Expand Down
2 changes: 0 additions & 2 deletions elastica/boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
__all__ = [
"ConstraintBase",
"FreeBC",
"FreeRod", # Deprecated: remove v0.3.0
"OneEndFixedBC",
"OneEndFixedRod", # Deprecated: remove v0.3.0
"GeneralConstraint",
"FixedConstraint",
"HelicalBucklingBC",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__doc__ = """
Wrappers are simple objects that you can subclass to provide extended
Modules are simple objects that you can subclass to provide extended
functionality to the simulation, such as adding an environment, joints, controllers, etc.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from elastica.rod import RodBase
from elastica.rigidbody import RigidBodyBase
from elastica.wrappers.memory_block import construct_memory_block_structures
from elastica.modules.memory_block import construct_memory_block_structures


class BaseSystemCollection(MutableSequence):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class CallBacks:
"""
CallBacks class is a wrapper for calling callback functions, set by the user. If the user
CallBacks class is a module for calling callback functions, set by the user. If the user
wants to collect data from the simulation, the simulator class has to be derived
from the CallBacks class.

Expand Down Expand Up @@ -80,7 +80,7 @@ def _callback_execution(self, time, current_step: int, *args, **kwargs):

class _CallBack:
"""
CallBack wrapper private class
CallBack module private class

Attributes
----------
Expand All @@ -107,7 +107,7 @@ def __init__(self, sys_idx: int):

def using(self, callback_cls, *args, **kwargs):
"""
This method is a wrapper to set which callback class is used to collect data
This method is a module to set which callback class is used to collect data
from user defined rod-like object.

Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Connections:
"""
The Connections class is a wrapper for connecting rod-like objects using joints selected
The Connections class is a module for connecting rod-like objects using joints selected
by the user. To connect two rod-like objects, the simulator class must be derived from
the Connections class.

Expand Down Expand Up @@ -106,7 +106,7 @@ def _call_connections(self, *args, **kwargs):

class _Connect:
"""
Connect wrapper private class
Connect module private class

Attributes
----------
Expand Down Expand Up @@ -231,7 +231,7 @@ def set_index(self, first_idx, second_idx):

def using(self, connect_cls, *args, **kwargs):
"""
This method is a wrapper to set which joint class is used to connect
This method is a module to set which joint class is used to connect
user defined rod-like objects.

Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Constraints:
"""
The Constraints class is a wrapper for enforcing displacement boundary conditions.
The Constraints class is a module for enforcing displacement boundary conditions.
To enforce boundary conditions on rod-like objects, the simulator class
must be derived from Constraints class.

Expand Down Expand Up @@ -87,7 +87,7 @@ def _constrain_rates(self, time, *args, **kwargs):

class _Constraint:
"""
Constraint wrapper private class
Constraint module private class

Attributes
----------
Expand All @@ -114,7 +114,7 @@ def __init__(self, sys_idx: int):

def using(self, bc_cls, *args, **kwargs):
"""
This method is a wrapper to set which boundary condition class is used to
This method is a module to set which boundary condition class is used to
enforce boundary condition from user defined rod-like objects.

Parameters
Expand Down
6 changes: 3 additions & 3 deletions elastica/wrappers/damping.py → elastica/modules/damping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Damping:
"""
The Damping class is a wrapper for applying damping
The Damping class is a module for applying damping
on rod-like objects, the simulator class must be derived from
Damping class.

Expand Down Expand Up @@ -76,7 +76,7 @@ def _dampen_rates(self, time, *args, **kwargs):

class _Damper:
"""
Damper wrapper private class
Damper module private class

Attributes
----------
Expand All @@ -103,7 +103,7 @@ def __init__(self, sys_idx: int):

def using(self, damper_cls, *args, **kwargs):
"""
This method is a wrapper to set which damper class is used to
This method is a module to set which damper class is used to
enforce damping from user defined rod-like objects.

Parameters
Expand Down
6 changes: 3 additions & 3 deletions elastica/wrappers/forcing.py → elastica/modules/forcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Forcing:
"""
The Forcing class is a wrapper for applying boundary conditions that
The Forcing class is a module for applying boundary conditions that
consist of applied external forces. To apply forcing on rod-like objects,
the simulator class must be derived from the Forcing class.

Expand Down Expand Up @@ -89,7 +89,7 @@ def _call_ext_forces_torques(self, time, *args, **kwargs):

class _ExtForceTorque:
"""
Forcing wrapper private class
Forcing module private class

Attributes
----------
Expand All @@ -115,7 +115,7 @@ def __init__(self, sys_idx: int):

def using(self, forcing_cls, *args, **kwargs):
"""
This method is a wrapper to set which forcing class is used to apply forcing
This method is a module to set which forcing class is used to apply forcing
to user defined rod-like objects.

Parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__doc__ = """
This function is a wrapper to construct memory blocks for different types of systems, such as
This function is a module to construct memory blocks for different types of systems, such as
Cosserat Rods, Rigid Body etc.
"""

Expand Down
2 changes: 1 addition & 1 deletion elastica/systems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def is_system_a_collection(system):
evolve as the interface evolves. Then we can add those
requirements on the interface here.
"""
from elastica.wrappers import BaseSystemCollection
from elastica.modules import BaseSystemCollection

__sys_get_item = getattr(system, "__getitem__", None)
return issubclass(system.__class__, BaseSystemCollection) or callable(
Expand Down
21 changes: 21 additions & 0 deletions elastica/wrappers.py
Original file line number Diff line number Diff line change
@@ -0,0 +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.",
DeprecationWarning,
)
8 changes: 4 additions & 4 deletions examples/Binder/1_Timoshenko_Beam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"![timoshenko_beam_figure.png](../../assets/timoshenko_beam_figure.png)\n",
"\n",
"## Getting Started\n",
"To set up the simulation, the first thing you need to do is import the necessary classes. Here we will only import the classes that we need. The `elastica.wrappers` classes make it easy to construct different simulation systems. Along with these wrappers, we need to import a rod class, classes for the boundary conditions, and time-stepping functions. As a note, this method of explicitly importing all classes can be a bit cumbersome. Future releases will simplify this step."
"To set up the simulation, the first thing you need to do is import the necessary classes. Here we will only import the classes that we need. The `elastica.modules` classes make it easy to construct different simulation systems. Along with these modules, we need to import a rod class, classes for the boundary conditions, and time-stepping functions. As a note, this method of explicitly importing all classes can be a bit cumbersome. Future releases will simplify this step."
]
},
{
Expand All @@ -41,8 +41,8 @@
"source": [
"import numpy as np\n",
"\n",
"# Import Wrappers\n",
"from elastica.wrappers import BaseSystemCollection, Constraints, Forcing, Damping\n",
"# Import modules\n",
"from elastica.modules import BaseSystemCollection, Constraints, Forcing, Damping\n",
"\n",
"# Import Cosserat Rod Class\n",
"from elastica.rod.cosserat_rod import CosseratRod\n",
Expand All @@ -67,7 +67,7 @@
}
},
"source": [
"Now that we have imported all the necessary classes, we want to create our beam system. We do this by combining all the wrappers we need to represent the physics that we to include in the simulation. In this case, that is the `BaseSystemCollection`, `Constraint`, `Forcings` and `Damping` because the simulation will consider a rod that is fixed in place on one end, and subject to an applied force on the other end."
"Now that we have imported all the necessary classes, we want to create our beam system. We do this by combining all the modules we need to represent the physics that we to include in the simulation. In this case, that is the `BaseSystemCollection`, `Constraint`, `Forcings` and `Damping` because the simulation will consider a rod that is fixed in place on one end, and subject to an applied force on the other end."
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions examples/Binder/2_Slithering_Snake.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"\n",
"\n",
"## Getting Started\n",
"To set up the simulation, the first thing you need to do is import the necessary classes. As with the Timoshenko bean, we need to import wrapper functions which allow us to more easily construct different simulation systems. We also need to import a rod class, all the necessary forces to be applied, timestepping functions, and callback classes. "
"To set up the simulation, the first thing you need to do is import the necessary classes. As with the Timoshenko bean, we need to import modules which allow us to more easily construct different simulation systems. We also need to import a rod class, all the necessary forces to be applied, timestepping functions, and callback classes. "
]
},
{
Expand All @@ -31,8 +31,8 @@
"source": [
"import numpy as np\n",
"\n",
"# import wrappers\n",
"from elastica.wrappers import BaseSystemCollection, Constraints, Forcing, CallBacks, Damping\n",
"# import modules\n",
"from elastica.modules import BaseSystemCollection, Constraints, Forcing, CallBacks, Damping\n",
"\n",
"# import rod class, damping and forces to be applied\n",
"from elastica.rod.cosserat_rod import CosseratRod\n",
Expand All @@ -58,7 +58,7 @@
},
"source": [
"## Initialize System and Add Rod\n",
"The first thing to do is initialize the simulator class by combining all the imported wrappers. After initializing, we will generate a rod and add it to the simulation. "
"The first thing to do is initialize the simulator class by combining all the imported modules. After initializing, we will generate a rod and add it to the simulation. "
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from collections import defaultdict
from elastica.wrappers import BaseSystemCollection, Constraints, Forcing, CallBacks
from elastica.modules import BaseSystemCollection, Constraints, Forcing, CallBacks
from elastica.rod.cosserat_rod import CosseratRod
from elastica.external_forces import GravityForces, MuscleTorques
from elastica.interaction import AnisotropicFrictionalPlane
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
__doc__ = """ Test wrappers for base systems """
__doc__ = """ Test modules for base systems """

import pytest
import numpy as np

from elastica.wrappers import (
from elastica.modules import (
BaseSystemCollection,
Constraints,
Forcing,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
__doc__ = """ Test wrappers for callback """
__doc__ = """ Test modules for callback """
import numpy as np
from numpy.testing import assert_allclose
import pytest

from elastica.wrappers import CallBacks
from elastica.wrappers.callbacks import _CallBack
from elastica.modules import CallBacks
from elastica.modules.callbacks import _CallBack


class TestCallBacks:
Expand Down Expand Up @@ -61,7 +61,7 @@ def mock_init(self, *args, **kwargs):


class TestCallBacksMixin:
from elastica.wrappers import BaseSystemCollection
from elastica.modules import BaseSystemCollection

class SystemCollectionWithCallBacksMixedin(BaseSystemCollection, CallBacks):
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
__doc__ = """ Test wrappers for connections """
__doc__ = """ Test modules for connections """
import numpy as np
import pytest

from elastica.wrappers import Connections
from elastica.wrappers.connections import _Connect
from elastica.modules import Connections
from elastica.modules.connections import _Connect


class TestConnect:
Expand Down Expand Up @@ -176,7 +176,7 @@ def mock_init(self, *args, **kwargs):


class TestConnectionsMixin:
from elastica.wrappers import BaseSystemCollection
from elastica.modules import BaseSystemCollection

class SystemCollectionWithConnectionsMixedin(BaseSystemCollection, Connections):
pass
Expand Down
Loading