Skip to content

Mechanics

Mechanical realizations shared by the engineering packages.

They are the spring and damper between two coordinates.

SpringDamperInteraction(label, *, target, states=('x1', 'x2'), masses=('m1', 'm2'), k=1.0, b=0.0)

Bases: Interaction

Linear spring and damper between two coordinates x1 and x2 of one element.

The spring pulls the coordinates together with the force -k (x1 - x2) and the damper with -b (x1' - x2'). Both forces accelerate the first coordinate divided by its mass and the second, with the opposite sign, divided by its own, as the suspension between the body and the wheel of a car or the pad between a rail and its sleeper.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the element with the two coordinates and their masses.

required
states Sequence[str]

The names of the two coordinates.

('x1', 'x2')
masses Sequence[str]

The names of the masses of the two coordinates.

('m1', 'm2')
k Annotated[float, closed_open(0, oo)]

The stiffness of the spring.

1.0
b Annotated[float, closed_open(0, oo)]

The damping of the damper.

0.0

Raises:

Type Description
ValidationError

The states or the masses are not two names.

Examples:

>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.engineering.common.mechanics import SpringDamperInteraction
>>> car = Element('car', values={'x1': 0.1, 'x2': 0.0, 'm1': 250.0, 'm2': 30.0})
>>> suspension = SpringDamperInteraction('suspension', target='car', k=16000.0, b=1000.0)
>>> System(elements=[car], interactions=[suspension]).prepare().states_
('car.x1', "car.x1'", 'car.x2', "car.x2'")
Source code in src/skcomplex/systems/engineering/common/mechanics/_spring_damper.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self,
    label: str,
    *,
    target: Role,
    states: Sequence[str] = ('x1', 'x2'),
    masses: Sequence[str] = ('m1', 'm2'),
    k: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    b: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.states = states
    self.masses = masses
    self.k = k
    self.b = b