Skip to content

Commit 252b0f5

Browse files
authored
add Position source (#330)
* add Position source * add docstring
1 parent f839b67 commit 252b0f5

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

src/Mechanical/TranslationalModelica/TranslationalModelica.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include("utils.jl")
1313
export Fixed, Mass, Spring, Damper, SpringDamper
1414
include("components.jl")
1515

16-
export Force
16+
export Force, Position
1717
include("sources.jl")
1818

1919
end

src/Mechanical/TranslationalModelica/sources.jl

+43
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,46 @@ Input signal acting as external force on a flange
1313
flange.f ~ -f.u
1414
end
1515
end
16+
17+
"""
18+
Position(; name, exact = false, f_crit = 50)
19+
20+
Forced movement of a flange according to a reference position
21+
22+
The input signal `s_ref` defines the reference position in [m]. Flange flange is forced to move relative to the support connector according to this reference motion. According to parameter `exact`, this is done in the following way:
23+
24+
- `exact=true`: The reference position is treated exactly. This is only possible, if the input signal is defined by an analytical function which can be differentiated at least twice. If this prerequisite is fulfilled, the Modelica translator will differentiate the input signal twice in order to compute the reference acceleration of the flange.
25+
- `exact=false`: The reference position is filtered and the second derivative of the filtered curve is used to compute the reference acceleration of the flange. This second derivative is not computed by numerical differentiation but by an appropriate realization of the filter. For filtering, a second order Bessel filter is used. The critical frequency (also called cut-off frequency) of the filter is defined via parameter `f_crit` in [Hz]. This value should be selected in such a way that it is higher as the essential low frequencies in the signal.
26+
27+
The input signal can be provided from one of the signal generator blocks of the block library `Blocks.Sources`.
28+
"""
29+
@mtkmodel Position begin
30+
@extend (s,) = ptf = PartialElementaryOneFlangeAndSupport2()
31+
@structural_parameters begin
32+
exact = false
33+
end
34+
@parameters begin
35+
f_crit = 50
36+
end
37+
@variables begin
38+
v(t)
39+
a(t)
40+
end
41+
@components begin
42+
s_ref = RealInput()
43+
end
44+
begin
45+
w_crit = 2π * f_crit
46+
af = 1.3617
47+
bf = 0.6180
48+
end
49+
@equations begin
50+
if exact
51+
s ~ s_ref.u
52+
else
53+
a ~ ((s_ref.u - s) * w_crit - af * v) * (w_crit / bf)
54+
end
55+
v ~ D(s)
56+
a ~ D(v)
57+
end
58+
end

test/Mechanical/translational_modelica.jl

+23-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
44
using ModelingToolkitStandardLibrary.Blocks: Sine
55
using ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica: Damper, Spring, Mass,
66
Fixed, Force,
7-
SpringDamper
7+
SpringDamper,
8+
Position
89

910
@testset "spring damper mass fixed" begin
1011
@mtkmodel SpringDamperMassFixed begin
@@ -85,3 +86,24 @@ end
8586
@test -lbub atol=1e-2
8687
@test -0.11 < lb < -0.1
8788
end
89+
90+
@testset "Position source" begin
91+
@mtkmodel TestPositionSource begin
92+
@components begin
93+
p1 = Position(exact = true)
94+
source = Sine(frequency = 3, amplitude = 2)
95+
mass = Mass(m = 1, v = 1, s = 0)
96+
end
97+
98+
@equations begin
99+
connect(source.output, p1.s_ref)
100+
connect(p1.flange, mass.flange_a)
101+
end
102+
end
103+
104+
@mtkbuild sys = TestPositionSource()
105+
prob = ODEProblem(sys, [], (0, 2pi))
106+
sol = solve(prob, Rodas4())
107+
tv = 0:0.1:(2pi)
108+
@test sol(tv, idxs = sys.mass.s)@.(2sin(2pi * tv * 3)) atol=1e-2
109+
end

0 commit comments

Comments
 (0)