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

Rename RollingDisc submodel disc to wheel improving consistency #132

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
init-shell: >-
bash
powershell
cache-environment: false
cache-environment: true
post-cleanup: 'all'
- name: Deactivate the tutorials environment
run: |
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_rolling_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def create_rolling_disc_manual(efficient_kdes: bool, efficient_constraints: bool

def create_rolling_disc_brim():
rolling_disc = RollingDisc("disc")
rolling_disc.disc = KnifeEdgeWheel("wheel")
rolling_disc.wheel = KnifeEdgeWheel("wheel")
rolling_disc.ground = FlatGround("ground")
rolling_disc.tire = NonHolonomicTire("tire")
rolling_disc.define_all()
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/rolling_disc_uml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/tutorials/four_bar_linkage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/rolling_disc_from_scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
26 changes: 20 additions & 6 deletions src/brim/other/rolling_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import contextlib
from typing import Any
from warnings import warn

from sympy import Matrix, Symbol, symbols
from sympy.physics.mechanics import (
Expand All @@ -25,15 +26,28 @@ class RollingDisc(ModelBase):

required_models: tuple[ModelRequirement, ...] = (
ModelRequirement("ground", GroundBase, "Ground model."),
ModelRequirement("disc", WheelBase, "Disc model."),
ModelRequirement("wheel", WheelBase, "Wheel model."),
)
required_connections: tuple[ConnectionRequirement, ...] = (
ConnectionRequirement("tire", TireBase, "Tire model."),
)
ground: GroundBase
disc: WheelBase
wheel: WheelBase
tire: TireBase

@property
def disc(self) -> WheelBase:
"""Disc model."""
warn("The 'disc' attribute is deprecated, use 'wheel' instead.",
DeprecationWarning, stacklevel=2)
return self.wheel

@disc.setter
def disc(self, value: WheelBase) -> None:
warn("The 'disc' attribute is deprecated, use 'wheel' instead.",
DeprecationWarning, stacklevel=2)
self.wheel = value

@property
def descriptions(self) -> dict[Any, str]:
"""Dictionary of descriptions of the rolling disc's attributes."""
Expand All @@ -55,7 +69,7 @@ def _define_connections(self) -> None:
"""Define the connections between the submodels."""
super()._define_connections()
self.tire.ground = self.ground
self.tire.wheel = self.disc
self.tire.wheel = self.wheel

def _define_objects(self) -> None:
"""Define the objects of the rolling disc."""
Expand All @@ -74,9 +88,9 @@ def _define_kinematics(self) -> None:
roll_frame = ReferenceFrame("roll_frame")
yaw_frame.orient_axis(self.ground.frame, self.ground.frame.z, self.q[2])
roll_frame.orient_axis(yaw_frame, yaw_frame.x, self.q[3])
self.disc.frame.orient_axis(roll_frame, roll_frame.y, self.q[4])
self.disc.frame.set_ang_vel(
self.ground.frame, self.disc.frame.ang_vel_in(self.ground.frame).xreplace(
self.wheel.frame.orient_axis(roll_frame, roll_frame.y, self.q[4])
self.wheel.frame.set_ang_vel(
self.ground.frame, self.wheel.frame.ang_vel_in(self.ground.frame).xreplace(
qd_repl))
self.ground.set_pos_point(self.tire.contact_point, self.q[:2])
self.tire.contact_point.set_vel(
Expand Down
6 changes: 3 additions & 3 deletions tests/bicycle/test_tires.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ class TestInContactTire:
def _setup_rolling_disc(self) -> None:
self.model = RollingDisc("model")
self.model.ground = FlatGround("ground")
self.model.disc = KnifeEdgeWheel("wheel")
self.model.wheel = KnifeEdgeWheel("wheel")
self.model.tire = InContactTire("tire")
self.ground, self.wheel, self.tire = (
self.model.ground, self.model.disc, self.model.tire)
self.model.ground, self.model.wheel, self.model.tire)

def test_default(self, _setup_rolling_disc) -> None:
self.model.define_all()
Expand Down Expand Up @@ -254,7 +254,7 @@ def test_compute_normal_force_rolling_disc(self, _setup_rolling_disc, no_slip
aux_eq = system.eom_method.auxiliary_eqs
fn_eq = Matrix.cramer_solve(*linear_eq_to_matrix(
aux_eq, self.tire.symbols["Fz"]))[0]
m, r = self.model.disc.body.mass, self.model.disc.radius
m, r = self.model.wheel.body.mass, self.model.wheel.radius
q4, u4 = self.model.q[3], self.model.u[3]
fn_eq_expected = m * (g - r * (u4 ** 2 * cos(q4) + sin(q4) * u4.diff()))
assert simplify(fn_eq - fn_eq_expected) == 0
Expand Down
34 changes: 17 additions & 17 deletions tests/core/test_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ def _define_objects(self) -> None:
self.symbols["my_sym2"] = Symbol(self._add_prefix("my_sym2"))

self.disc = RollingDisc("rolling_disc")
self.disc.disc = KnifeEdgeWheel("disc")
self.disc.wheel = KnifeEdgeWheel("disc")
self.disc.ground = FlatGround("ground")
self.disc.tire = MyTire("tire")
self.load_group = MyLoad("load")
self.disc.disc.add_load_groups(self.load_group)
self.disc.wheel.add_load_groups(self.load_group)

def test_init(self) -> None:
disc = RollingDisc("model")
assert isinstance(disc, ModelBase)
assert str(disc) == "model"
assert repr(disc) == "RollingDisc('model')"
assert disc.name == "model"
assert disc.disc is None
assert disc.wheel is None
assert disc.ground is None
assert disc.tire is None

Expand All @@ -91,7 +91,7 @@ def test_invalid_name(self, name) -> None:
def test_invalid_model(self) -> None:
disc = RollingDisc("model")
with pytest.raises(TypeError):
disc.disc = FlatGround("ground")
disc.wheel = FlatGround("ground")

def test_invalid_connection(self) -> None:
disc = RollingDisc("model")
Expand All @@ -110,12 +110,12 @@ def test_invalid_submodel_of_connection(self, _create_model) -> None:

def test_get_description_own_description(self, _create_model) -> None:
self.disc.define_all()
assert (self.disc.disc.get_description(self.disc.disc.radius) ==
self.disc.disc.descriptions[self.disc.disc.radius])
assert (self.disc.wheel.get_description(self.disc.wheel.radius) ==
self.disc.wheel.descriptions[self.disc.wheel.radius])

def test_get_description_of_submodel(self, _create_model) -> None:
self.disc.define_all()
assert self.disc.get_description(self.disc.disc.radius) is not None
assert self.disc.get_description(self.disc.wheel.radius) is not None

def test_get_description_of_connection(self, _create_model) -> None:
self.disc.define_all()
Expand All @@ -132,15 +132,15 @@ def test_get_description_of_not_existing_symbol(self, _create_model) -> None:
def test_traversal_get_all_symbols(self, _create_model) -> None:
self.disc.define_all()
assert self.disc.get_all_symbols() == {
self.disc.disc.symbols["r"], self.disc.tire.symbols["my_sym1"],
self.disc.wheel.symbols["r"], self.disc.tire.symbols["my_sym1"],
self.disc.tire.symbols["my_sym2"], self.load_group.symbols["T"]
}
assert self.disc.disc.get_all_symbols() == {
self.disc.disc.symbols["r"], self.load_group.symbols["T"]}
assert self.disc.wheel.get_all_symbols() == {
self.disc.wheel.symbols["r"], self.load_group.symbols["T"]}
assert self.disc.tire.get_all_symbols() == {
self.disc.disc.symbols["r"], self.disc.tire.symbols["my_sym1"],
self.disc.wheel.symbols["r"], self.disc.tire.symbols["my_sym1"],
self.disc.tire.symbols["my_sym2"], self.load_group.symbols["T"]}
assert self.disc.disc.load_groups[0].get_all_symbols() == {
assert self.disc.wheel.load_groups[0].get_all_symbols() == {
self.load_group.symbols["T"]}

@pytest.mark.parametrize("sym, expected", [
Expand All @@ -157,7 +157,7 @@ def test_traversal_get_all_symbols(self, _create_model) -> None:
def test_type_get_all_symbols(self, sym, expected, _create_model) -> None:
self.disc.define_connections()
self.disc.define_objects()
self.disc.disc.symbols["r"] = sym
self.disc.wheel.symbols["r"] = sym
assert self.disc.get_all_symbols() == {
self.disc.tire.symbols["my_sym1"], self.disc.tire.symbols["my_sym2"],
self.load_group.symbols["T"], *expected}
Expand Down Expand Up @@ -222,8 +222,8 @@ def test_to_system(self, _create_model) -> None:
self.disc.define_all()
system = self.disc.to_system()
assert system.loads == (
Torque(self.disc.disc.frame,
self.load_group.symbols["T"] * self.disc.disc.rotation_axis),)
Torque(self.disc.wheel.frame,
self.load_group.symbols["T"] * self.disc.wheel.rotation_axis),)

def test_is_root(self, _create_model) -> None:
class MyModel(ModelBase):
Expand All @@ -238,12 +238,12 @@ def _define_objects(self) -> None:

root = MyModel("root")
root.rolling_disc = self.disc
for obj in (root, self.disc, self.disc.disc, self.disc.ground):
for obj in (root, self.disc, self.disc.wheel, self.disc.ground):
assert obj.is_root is None
root.define_connections()
root.define_objects()
assert root.is_root
for obj in (self.disc, self.disc.disc, self.disc.ground):
for obj in (self.disc, self.disc.wheel, self.disc.ground):
assert not obj.is_root
root.define_kinematics()
root.define_loads()
Expand Down
8 changes: 4 additions & 4 deletions tests/core/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def test_get_from_requirement_error(self) -> None:
Registry().get_from_requirement(WheelBase)

@pytest.mark.parametrize("args, kwargs, subset, disjoint", [
((RollingDisc("disc"), "disc"), {},
((RollingDisc("disc"), "wheel"), {},
{KnifeEdgeWheel, ToroidalWheel}, {NonHolonomicTire, WheelBase, RollingDisc}),
((RollingDisc, "disc"), {},
((RollingDisc, "wheel"), {},
{KnifeEdgeWheel, ToroidalWheel}, {NonHolonomicTire, WheelBase, RollingDisc}),
((RollingDisc("disc"), "tire"), {},
{NonHolonomicTire}, {TireBase, KnifeEdgeWheel, RollingDisc}),
((RollingDisc("disc"), "disc"), {"drop_abstract": False},
((RollingDisc("disc"), "wheel"), {"drop_abstract": False},
{KnifeEdgeWheel, ToroidalWheel, WheelBase}, {NonHolonomicTire, RollingDisc}),
((RollingDisc("disc"), "tire"), {"drop_abstract": False},
{NonHolonomicTire, TireBase}, {KnifeEdgeWheel, RollingDisc}),
Expand All @@ -73,7 +73,7 @@ def test_get_from_property(self, args, kwargs, subset, disjoint) -> None:

def test_get_from_property_error(self) -> None:
with pytest.raises(ValueError):
Registry().get_from_property(RollingDisc("disc"), "wheel")
Registry().get_from_property(RollingDisc("disc"), "not_a_submodel")

@pytest.mark.parametrize("args, kwargs, subset, disjoint", [
((PinElbowStickLeftArm("arm"),), {},
Expand Down
18 changes: 13 additions & 5 deletions tests/other/test_rolling_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _arbitrary_values() -> dict[str, float]:
@pytest.fixture()
def _rolling_disc_brim(self) -> None:
self.rolling_disc = RollingDisc("rolling_disc")
self.rolling_disc.disc = KnifeEdgeWheel("disc")
self.rolling_disc.wheel = KnifeEdgeWheel("disc")
self.rolling_disc.tire = NonHolonomicTire("tire")
self.rolling_disc.ground = FlatGround("ground")
self.rolling_disc.define_all()
Expand All @@ -31,13 +31,13 @@ def _rolling_disc_brim(self) -> None:
-Symbol("g") * self.rolling_disc.ground.get_normal(
self.rolling_disc.ground.origin))
str_vals = self._arbitrary_values()
inertia = self.rolling_disc.disc.body.central_inertia.to_matrix(
self.rolling_disc.disc.frame)
inertia = self.rolling_disc.wheel.body.central_inertia.to_matrix(
self.rolling_disc.wheel.frame)
self.val_dict = {
self.rolling_disc.disc.body.mass: str_vals["m"],
self.rolling_disc.wheel.body.mass: str_vals["m"],
inertia[0, 0]: str_vals["ixx"],
inertia[1, 1]: str_vals["iyy"],
self.rolling_disc.disc.radius: str_vals["r"],
self.rolling_disc.wheel.radius: str_vals["r"],
Symbol("g"): str_vals["g"],
**{qi: str_vals[f"q{i}"] for i, qi in enumerate(self.rolling_disc.q, 1)},
**{ui: str_vals[f"u{i}"] for i, ui in enumerate(self.rolling_disc.u, 1)}
Expand Down Expand Up @@ -124,3 +124,11 @@ def test_rolling_disc_description(self, _rolling_disc_brim) -> None:
assert self.rolling_disc.descriptions[qi]
for ui in self.rolling_disc.u:
assert self.rolling_disc.descriptions[ui]

def test_disc_property_deprecation(self) -> None:
model = RollingDisc("model")
with pytest.warns(DeprecationWarning):
model.disc = KnifeEdgeWheel("wheel")
with pytest.warns(DeprecationWarning):
disc = model.disc
assert disc is model.wheel
Loading