Skip to content

Commit e9f430d

Browse files
ven-kChrisRackauckas
authored andcommitted
refactor: update the arglist of non-dsl components to match the style of dsl components
- this will allow upgradation of those without breaking again
1 parent 485eecc commit e9f430d

File tree

12 files changed

+156
-187
lines changed

12 files changed

+156
-187
lines changed

docs/src/connectors/connections.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The idea behind the selection of the **through** variable is that it should be a
1818
```math
1919
\begin{aligned}
2020
\partial {\color{blue}{across}} / \partial t \cdot c_1 = {\color{green}{through}} \\
21-
{\color{green}{through}} \cdot c_2 = {\color{blue}{across}}
21+
{\color{green}{through}} \cdot c_2 = {\color{blue}{across}}
2222
\end{aligned}
2323
```
2424

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

3131
```math
32-
\partial {\color{blue}{voltage}} / \partial t \cdot capacitance = {\color{green}{current}}
32+
\partial {\color{blue}{voltage}} / \partial t \cdot capacitance = {\color{green}{current}}
3333
```
3434

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

4747
```math
48-
\partial {\color{blue}{velocity}} / \partial t \cdot mass = {\color{green}{force}}
48+
\partial {\color{blue}{velocity}} / \partial t \cdot mass = {\color{green}{force}}
4949
```
5050

5151
- Flow:
5252

5353
```math
54-
{\color{green}{force}} \cdot (1/damping) = {\color{blue}{velocity}}
54+
{\color{green}{force}} \cdot (1/damping) = {\color{blue}{velocity}}
5555
```
5656

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

6767
```math
68-
\partial^2 {\color{blue}{position}} / \partial t^2 \cdot mass = {\color{green}{force}}
68+
\partial^2 {\color{blue}{position}} / \partial t^2 \cdot mass = {\color{green}{force}}
6969
```
7070

7171
- Flow:
7272

7373
```math
74-
{\color{green}{force}} \cdot (1/damping) = \partial {\color{blue}{position}} / \partial t
74+
{\color{green}{force}} \cdot (1/damping) = \partial {\color{blue}{position}} / \partial t
7575
```
7676

7777
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.
@@ -134,7 +134,7 @@ Now using the Translational library based on velocity, we can see the same relat
134134
using ModelingToolkitStandardLibrary
135135
const TV = ModelingToolkitStandardLibrary.Mechanical.Translational
136136
137-
@named damping = TV.Damper(d = 1, v_a_0 = 1)
137+
@named damping = TV.Damper(d = 1, va = 1)
138138
@named body = TV.Mass(m = 1, v_0 = 1)
139139
@named ground = TV.Fixed()
140140
@@ -167,7 +167,7 @@ Now, let's consider the position-based approach. We can build the same model wi
167167
```@example connections
168168
const TP = ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition
169169
170-
@named damping = TP.Damper(d = 1, v_a_0 = 1)
170+
@named damping = TP.Damper(d = 1, va = 1)
171171
@named body = TP.Mass(m = 1, v_0 = 1)
172172
@named ground = TP.Fixed(s_0 = 0)
173173
@@ -220,21 +220,21 @@ In this problem, we have a mass, spring, and damper which are connected to a fix
220220

221221
#### Damper
222222

223-
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`.
223+
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`.
224224

225225
```@example connections
226-
@named dv = TV.Damper(d = 1, v_a_0 = 1)
227-
@named dp = TP.Damper(d = 1, v_a_0 = 1, s_a_0 = 3, s_b_0 = 1)
226+
@named dv = TV.Damper(d = 1, va = 1)
227+
@named dp = TP.Damper(d = 1, va = 1, flange_a__s = 3, flange_b__s = 1)
228228
nothing # hide
229229
```
230230

231231
#### Spring
232232

233-
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`.
233+
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`.
234234

235235
```@example connections
236-
@named sv = TV.Spring(k = 1, v_a_0 = 1, delta_s_0 = 1)
237-
@named sp = TP.Spring(k = 1, s_a_0 = 3, s_b_0 = 1, l = 1)
236+
@named sv = TV.Spring(k = 1, va = 1, delta_s = 1)
237+
@named sp = TP.Spring(k = 1, flange_a__s = 3, flange_b__s = 1, l = 1)
238238
nothing # hide
239239
```
240240

src/Hydraulic/IsothermalCompressible/components.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ dm ────► │ │ area
506506

507507
ports = @named begin
508508
port = HydraulicPort(; p_int)
509-
flange = MechanicalPort(; f_int = p_int * area)
509+
flange = MechanicalPort(; f = p_int * area)
510510
damper = ValveBase(; p_a_int = p_int, p_b_int = p_int, area_int = 1, Cd,
511511
Cd_reverse, minimum_area)
512512
end

src/Mechanical/Rotational/utils.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Partial model for the compliant connection of two rotational 1-dim. shaft flange
5656
5757
# States:
5858
59-
- `phi_rel(t)`: [`rad`] Relative rotation angle (`flange_b.phi - flange_a.phi`), initial value defaults to 0.0.
60-
- `tau(t)`: [`N.m`] Torque between flanges (`flange_b.tau`), initial value defaults to 0.0.
59+
- `phi_rel(t)`: [`rad`] Relative rotation angle (`flange_b.phi - flange_a.phi`). It accepts an initial value, which defaults to 0.0.
60+
- `tau(t)`: [`N.m`] Torque between flanges (`flange_b.tau`). It accepts an initial value, which defaults to 0.0.
6161
6262
# Connectors:
6363
@@ -71,8 +71,8 @@ Partial model for the compliant connection of two rotational 1-dim. shaft flange
7171
flange_b = Flange()
7272
end
7373
@variables begin
74-
phi_rel(t), [description = "Relative rotation angle between flanges"]
75-
tau(t), [description = "Torque between flanges"]
74+
phi_rel(t) = 0.0, [description = "Relative rotation angle between flanges"]
75+
tau(t) = 0.0, [description = "Torque between flanges"]
7676
end
7777
@equations begin
7878
phi_rel ~ flange_b.phi - flange_a.phi
@@ -88,10 +88,10 @@ Partial model for the compliant connection of two rotational 1-dim. shaft flange
8888
8989
# States:
9090
91-
- `phi_rel(t)`: [`rad`] Relative rotation angle (= flange_b.phi - flange_a.phi). Initial value defaults to 0.0.
92-
- `w_rel(t)`: [`rad/s`] Relative angular velocity (= D(phi_rel)). Initial value defaults to 0.0.
93-
- `a_rel(t)`: [`rad/s²`] Relative angular acceleration (= D(w_rel)). Initial value defaults to 0.0.
94-
- `tau(t)`: [`N.m`] Torque between flanges (= flange_b.tau). Initial value defaults to 0.0.
91+
- `phi_rel(t)`: [`rad`] Relative rotation angle (= flange_b.phi - flange_a.phi). It accepts an initial value, which defaults to 0.0.
92+
- `w_rel(t)`: [`rad/s`] Relative angular velocity (= D(phi_rel)). It accepts an initial value, which defaults to 0.0.
93+
- `a_rel(t)`: [`rad/s²`] Relative angular acceleration (= D(w_rel)). It accepts an initial value, which defaults to 0.0.
94+
- `tau(t)`: [`N.m`] Torque between flanges (= flange_b.tau). It accepts an initial value, which defaults to 0.0.
9595
9696
# Connectors:
9797
@@ -104,10 +104,10 @@ Partial model for the compliant connection of two rotational 1-dim. shaft flange
104104
flange_b = Flange()
105105
end
106106
@variables begin
107-
phi_rel(t), [description = "Relative rotation angle between flanges"]
108-
w_rel(t), [description = "Relative angular velocity between flanges"]
109-
a_rel(t), [description = "Relative angular acceleration between flanges"]
110-
tau(t), [description = "Torque between flanges"]
107+
phi_rel(t) = 0.0, [description = "Relative rotation angle between flanges"]
108+
w_rel(t) = 0.0, [description = "Relative angular velocity between flanges"]
109+
a_rel(t) = 0.0, [description = "Relative angular acceleration between flanges"]
110+
tau(t) = 0.0, [description = "Torque between flanges"]
111111
end
112112
@equations begin
113113
phi_rel ~ flange_b.phi - flange_a.phi

src/Mechanical/Translational/components.jl

+37-45
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,22 @@ Sliding mass with inertia
5858
5959
- `flange`: 1-dim. translational flange
6060
"""
61-
@component function Mass(; name, v_0 = 0.0, m, s_0 = nothing, g = nothing)
61+
@component function Mass(; name, v = 0.0, m, s = nothing, g = nothing)
6262
pars = @parameters begin
6363
m = m
64-
v_0 = v_0
6564
end
65+
@named flange = MechanicalPort(; v = v)
66+
6667
vars = @variables begin
67-
v(t) = v_0
68+
v(t) = v
6869
f(t) = 0
6970
end
7071

71-
@named flange = MechanicalPort()
72-
7372
eqs = [flange.v ~ v
7473
flange.f ~ f]
7574

7675
# gravity option
77-
if !isnothing(g)
76+
if g !== nothing
7877
@parameters g = g
7978
push!(pars, g)
8079
push!(eqs, D(v) ~ f / m + g)
@@ -83,99 +82,86 @@ Sliding mass with inertia
8382
end
8483

8584
# position option
86-
if !isnothing(s_0)
87-
@parameters s_0 = s_0
88-
push!(pars, s_0)
89-
90-
@variables s(t) = s_0
85+
if s !== nothing
86+
@variables s(t) = s
9187
push!(vars, s)
9288

9389
push!(eqs, D(s) ~ v)
9490
end
9591

96-
return compose(ODESystem(eqs, t, vars, pars; name = name, defaults = [flange.v => v_0]),
92+
return compose(ODESystem(eqs, t, vars, pars; name = name),
9793
flange)
9894
end
9995

10096
const REL = Val(:relative)
10197

10298
"""
103-
Spring(; name, k, delta_s_0 = 0.0, v_a_0=0.0, v_b_0=0.0)
99+
Spring(; name, k, delta_s = 0.0, va=0.0, v_b_0=0.0)
104100
105101
Linear 1D translational spring
106102
107103
# Parameters:
108104
109105
- `k`: [N/m] Spring constant
110-
- `delta_s_0`: initial spring stretch
111-
- `v_a_0`: [m/s] Initial value of absolute linear velocity at flange_a (default 0 m/s)
106+
- `delta_s`: initial spring stretch
107+
- `va`: [m/s] Initial value of absolute linear velocity at flange_a (default 0 m/s)
112108
- `v_b_0`: [m/s] Initial value of absolute linear velocity at flange_b (default 0 m/s)
113109
114110
# Connectors:
115111
116112
- `flange_a`: 1-dim. translational flange on one side of spring
117113
- `flange_b`: 1-dim. translational flange on opposite side of spring
118114
"""
119-
@component function Spring(; name, k, delta_s_0 = 0.0, v_a_0 = 0.0, v_b_0 = 0.0)
120-
Spring(REL; name, k, delta_s_0, v_a_0, v_b_0)
115+
@component function Spring(; name, k, delta_s = 0.0, flange_a__v = 0.0, flange_b__v = 0.0)
116+
Spring(REL; name, k, delta_s, flange_a__v, flange_b__v)
121117
end # default
122118

123-
@component function Spring(::Val{:relative}; name, k, delta_s_0 = 0.0, v_a_0 = 0.0,
124-
v_b_0 = 0.0)
119+
@component function Spring(::Val{:relative}; name, k, delta_s = 0.0, flange_a__v = 0.0,
120+
flange_b__v = 0.0)
125121
pars = @parameters begin
126122
k = k
127-
delta_s_0 = delta_s_0
128-
v_a_0 = v_a_0
129-
v_b_0 = v_b_0
130123
end
131124
vars = @variables begin
132-
delta_s(t) = delta_s_0
125+
delta_s(t) = delta_s
133126
f(t) = 0
134127
end
135128

136-
@named flange_a = MechanicalPort()
137-
@named flange_b = MechanicalPort()
129+
@named flange_a = MechanicalPort(; v = flange_a__v)
130+
@named flange_b = MechanicalPort(; v = flange_b__v)
138131

139132
eqs = [D(delta_s) ~ flange_a.v - flange_b.v
140133
f ~ k * delta_s
141134
flange_a.f ~ +f
142135
flange_b.f ~ -f]
143-
return compose(ODESystem(eqs, t, vars, pars; name = name,
144-
defaults = [flange_a.v => v_a_0, flange_b.v => v_b_0]),
136+
return compose(ODESystem(eqs, t, vars, pars; name = name),
145137
flange_a,
146-
flange_b) #flange_a.f => +k*delta_s_0, flange_b.f => -k*delta_s_0
138+
flange_b) #flange_a.f => +k*delta_s, flange_b.f => -k*delta_s
147139
end
148140

149141
const ABS = Val(:absolute)
150-
@component function Spring(::Val{:absolute}; name, k, s_a_0 = 0, s_b_0 = 0, v_a_0 = 0.0,
151-
v_b_0 = 0.0,
152-
l = 0)
142+
@component function Spring(::Val{:absolute}; name, k, sa = 0, sb = 0, flange_a__v = 0.0,
143+
flange_b__v = 0.0, l = 0)
153144
pars = @parameters begin
154145
k = k
155-
s_a_0 = s_a_0
156-
s_b_0 = s_b_0
157-
v_a_0 = v_a_0
158-
v_b_0 = v_b_0
159146
l = l
160147
end
161148
vars = @variables begin
162-
s1(t) = s_a_0
163-
s2(t) = s_b_0
149+
sa(t) = sa
150+
sb(t) = sb
164151
f(t) = 0
165152
end
166153

167-
@named flange_a = MechanicalPort()
168-
@named flange_b = MechanicalPort()
154+
@named flange_a = MechanicalPort(; v = flange_a__v)
155+
@named flange_b = MechanicalPort(; v = flange_b__v)
169156

170-
eqs = [D(s1) ~ flange_a.v
171-
D(s2) ~ flange_b.v
172-
f ~ k * (s1 - s2 - l) #delta_s
157+
eqs = [D(sa) ~ flange_a.v
158+
D(sb) ~ flange_b.v
159+
f ~ k * (sa - sb - l) #delta_s
173160
flange_a.f ~ +f
174161
flange_b.f ~ -f]
175-
return compose(ODESystem(eqs, t, vars, pars; name = name,
176-
defaults = [flange_a.v => v_a_0, flange_b.v => v_b_0]),
162+
return compose(ODESystem(eqs, t, vars, pars; name = name,),
177163
flange_a,
178-
flange_b) #, flange_a.f => k * (s_a_0 - s_b_0 - l)
164+
flange_b) #, flange_a.f => k * (flange_a__s - flange_b__s - l)
179165
end
180166

181167
"""
@@ -213,3 +199,9 @@ Linear 1D translational damper
213199
flange_b.f ~ -f
214200
end
215201
end
202+
203+
204+
#=
205+
206+
207+
=#

0 commit comments

Comments
 (0)