Skip to content
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
42 changes: 21 additions & 21 deletions docs/src/connectors/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The idea behind the selection of the **through** variable is that it should be a
```math
\begin{aligned}
\partial {\color{blue}{across}} / \partial t \cdot c_1 = {\color{green}{through}} \\
{\color{green}{through}} \cdot c_2 = {\color{blue}{across}}
{\color{green}{through}} \cdot c_2 = {\color{blue}{across}}
\end{aligned}
```

Expand All @@ -29,7 +29,7 @@ For the Electrical domain, the across variable is *voltage* and the through vari
- Energy Dissipation:

```math
\partial {\color{blue}{voltage}} / \partial t \cdot capacitance = {\color{green}{current}}
\partial {\color{blue}{voltage}} / \partial t \cdot capacitance = {\color{green}{current}}
```

- Flow:
Expand All @@ -45,13 +45,13 @@ For the translation domain, choosing *velocity* for the across variable and *for
- Energy Dissipation:

```math
\partial {\color{blue}{velocity}} / \partial t \cdot mass = {\color{green}{force}}
\partial {\color{blue}{velocity}} / \partial t \cdot mass = {\color{green}{force}}
```

- Flow:

```math
{\color{green}{force}} \cdot (1/damping) = {\color{blue}{velocity}}
{\color{green}{force}} \cdot (1/damping) = {\color{blue}{velocity}}
```

The diagram here shows the similarity of problems in different physical domains.
Expand All @@ -65,13 +65,13 @@ Now, if we choose *position* for the across variable, a similar relationship can
- Energy Dissipation:

```math
\partial^2 {\color{blue}{position}} / \partial t^2 \cdot mass = {\color{green}{force}}
\partial^2 {\color{blue}{position}} / \partial t^2 \cdot mass = {\color{green}{force}}
```

- Flow:

```math
{\color{green}{force}} \cdot (1/damping) = \partial {\color{blue}{position}} / \partial t
{\color{green}{force}} \cdot (1/damping) = \partial {\color{blue}{position}} / \partial t
```

As can be seen, we must now establish a higher order derivative to define the Energy Dissipation and Flow equations, requiring an extra equation, as will be shown in the example below.
Expand Down Expand Up @@ -134,8 +134,8 @@ Now using the Translational library based on velocity, we can see the same relat
using ModelingToolkitStandardLibrary
const TV = ModelingToolkitStandardLibrary.Mechanical.Translational

@named damping = TV.Damper(d = 1, v_a_0 = 1)
@named body = TV.Mass(m = 1, v_0 = 1)
@named damping = TV.Damper(d = 1, flange_a.v = 1)
@named body = TV.Mass(m = 1, v = 1)
@named ground = TV.Fixed()

eqs = [connect(damping.flange_a, body.flange)
Expand Down Expand Up @@ -167,8 +167,8 @@ Now, let's consider the position-based approach. We can build the same model wi
```@example connections
const TP = ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition

@named damping = TP.Damper(d = 1, v_a_0 = 1)
@named body = TP.Mass(m = 1, v_0 = 1)
@named damping = TP.Damper(d = 1, va = 1, vb = 0.0)
@named body = TP.Mass(m = 1, v = 1)
@named ground = TP.Fixed(s_0 = 0)

eqs = [connect(damping.flange_a, body.flange)
Expand Down Expand Up @@ -197,10 +197,10 @@ plot(p1, p2, p3)

The question then arises, can the position be plotted when using the Mechanical Translational Domain based on the Velocity Across variable? Yes, we can! There are 2 solutions:

1. the `Mass` component will add the position variable when the `s_0` parameter is used to set an initial position. Otherwise, the component does not track the position.
1. the `Mass` component will add the position variable when the `s` parameter is used to set an initial position. Otherwise, the component does not track the position.

```julia
@named body = TV.Mass(m = 1, v_0 = 1, s_0 = 0)
@named body = TV.Mass(m = 1, v = 1, s = 0)
```

2. implement a `PositionSensor`
Expand All @@ -220,31 +220,31 @@ In this problem, we have a mass, spring, and damper which are connected to a fix

#### Damper

The damper will connect the flange/flange 1 (`flange_a`) to the mass, and flange/flange 2 (`flange_b`) to the fixed point. For both position- and velocity-based domains, we set the damping constant `d=1` and `v_a_0=1` and leave the default for `v_b_0` at 0. For the position domain, we also need to set the initial positions for `flange_a` and `flange_b`.
The damper will connect the flange/flange 1 (`flange_a`) to the mass, and flange/flange 2 (`flange_b`) to the fixed point. For both position- and velocity-based domains, we set the damping constant `d=1` and `va=1` and leave the default for `v_b_0` at 0. For the position domain, we also need to set the initial positions for `flange_a` and `flange_b`.

```@example connections
@named dv = TV.Damper(d = 1, v_a_0 = 1)
@named dp = TP.Damper(d = 1, v_a_0 = 1, s_a_0 = 3, s_b_0 = 1)
@named dv = TV.Damper(d = 1, flange_a.v = 1)
@named dp = TP.Damper(d = 1, va = 1, vb = 0.0, flange_a__s = 3, flange_b__s = 1)
nothing # hide
```

#### Spring

The spring will connect the flange/flange 1 (`flange_a`) to the mass, and flange/flange 2 (`flange_b`) to the fixed point. For both position- and velocity-based domains, we set the spring constant `k=1`. The velocity domain then requires the initial velocity `v_a_0` and initial spring stretch `delta_s_0`. The position domain instead needs the initial positions for `flange_a` and `flange_b` and the natural spring length `l`.
The spring will connect the flange/flange 1 (`flange_a`) to the mass, and flange/flange 2 (`flange_b`) to the fixed point. For both position- and velocity-based domains, we set the spring constant `k=1`. The velocity domain then requires the initial velocity `va` and initial spring stretch `delta_s`. The position domain instead needs the initial positions for `flange_a` and `flange_b` and the natural spring length `l`.

```@example connections
@named sv = TV.Spring(k = 1, v_a_0 = 1, delta_s_0 = 1)
@named sp = TP.Spring(k = 1, s_a_0 = 3, s_b_0 = 1, l = 1)
@named sv = TV.Spring(k = 1, flange_a__v = 1, delta_s = 1)
@named sp = TP.Spring(k = 1, flange_a__s = 3, flange_b__s = 1, l = 1)
nothing # hide
```

#### Mass

For both position- and velocity-based domains, we set the mass `m=1` and initial velocity `v_0=1`. Like the damper, the position domain requires the position initial conditions set as well.
For both position- and velocity-based domains, we set the mass `m=1` and initial velocity `v=1`. Like the damper, the position domain requires the position initial conditions set as well.

```@example connections
@named bv = TV.Mass(m = 1, v_0 = 1)
@named bp = TP.Mass(m = 1, v_0 = 1, s_0 = 3)
@named bv = TV.Mass(m = 1, v = 1)
@named bp = TP.Mass(m = 1, v = 1, s = 3)
nothing # hide
```

Expand Down
2 changes: 1 addition & 1 deletion src/Hydraulic/IsothermalCompressible/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ dm ────► │ │ area

ports = @named begin
port = HydraulicPort(; p_int)
flange = MechanicalPort(; f_int = p_int * area)
flange = MechanicalPort(; f = p_int * area)
damper = ValveBase(; p_a_int = p_int, p_b_int = p_int, area_int = 1, Cd,
Cd_reverse, minimum_area)
end
Expand Down
45 changes: 23 additions & 22 deletions src/Mechanical/MultiBody2D/components.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@component function Link(; name, m, l, I, g, x1_0 = 0, y1_0 = 0)
pars = @parameters begin
m = m
l = l
I = I
g = g
x1_0 = x1_0
y1_0 = y1_0
@mtkmodel Link begin
@parameters begin
m
l
I
g
x1_0 = 0.0
y1_0 = 0.0
end

vars = @variables begin
@variables begin
(A(t) = 0), [state_priority = 10]
(dA(t) = 0), [state_priority = 10]
(ddA(t) = 0), [state_priority = 10]
Expand Down Expand Up @@ -40,13 +40,16 @@
ddy_cm(t) = 0
end

@named TX1 = MechanicalPort()
@named TY1 = MechanicalPort()
@components begin
TX1 = MechanicalPort()
TY1 = MechanicalPort()

@named TX2 = MechanicalPort()
@named TY2 = MechanicalPort()
TX2 = MechanicalPort()
TY2 = MechanicalPort()
end

eqs = [D(A) ~ dA
@equations begin
D(A) ~ dA
D(dA) ~ ddA
D(x1) ~ dx1
D(y1) ~ dy1
Expand All @@ -57,17 +60,17 @@
D(y_cm) ~ dy_cm
D(dy_cm) ~ ddy_cm

# x forces
# x forces
m * ddx_cm ~ fx1 + fx2

# y forces
# y forces
m * ddy_cm ~ m * g + fy1 + fy2

# torques
# torques
I * ddA ~ -fy1 * (x2 - x1) / 2 + fy2 * (x2 - x1) / 2 + fx1 * (y2 - y1) / 2 -
fx2 * (y2 - y1) / 2

# geometry
# geometry
x2 ~ l * cos(A) + x1
y2 ~ l * sin(A) + y1
x_cm ~ l * cos(A) / 2 + x1
Expand All @@ -79,8 +82,6 @@
TX2.f ~ fx2
TX2.v ~ dx2
TY2.f ~ fy2
TY2.v ~ dy2]

return ODESystem(eqs, t, vars, pars; name = name, systems = [TX1, TY1, TX2, TY2],
defaults = [TX1.v => 0, TY1.v => 0, TX2.v => 0, TY2.v => 0])
TY2.v ~ dy2
end
end
Loading