@@ -115,61 +115,122 @@ end
115115end
116116
117117@testset " sources & sensors" begin
118- function System (; name)
119- systems = @named begin
120- pos = TV. Position ()
121- pos_sensor = TV. PositionSensor (; s = 1 )
122- force = TV. Force ()
123- force_sensor = TV. ForceSensor ()
124-
125- spring = TV. Spring (; k = 1000 )
126-
127- src1 = Sine (frequency = 100 , amplitude = 2 )
128- src2 = Sine (frequency = 100 , amplitude = - 1 )
129-
130- pos_value = RealInput ()
131- force_output = RealOutput ()
118+ @testset " Translational" begin
119+ @testset " PositionSensor & ForceSensor" begin
120+ function System (; name)
121+ systems = @named begin
122+ pos = TV. Position ()
123+ pos_sensor = TV. PositionSensor (; s = 1 )
124+ force = TV. Force ()
125+ force_sensor = TV. ForceSensor ()
126+
127+ spring = TV. Spring (; k = 1000 )
128+
129+ src1 = Sine (frequency = 100 , amplitude = 2 )
130+ src2 = Sine (frequency = 100 , amplitude = - 1 )
131+
132+ pos_value = RealInput ()
133+ force_output = RealOutput ()
134+ end
135+
136+ eqs = [connect (pos. s, src1. output)
137+ connect (force. f, src2. output)
138+ connect (pos. flange, force_sensor. flange_a)
139+ connect (force_sensor. flange_b, spring. flange_a)
140+ connect (spring. flange_b, force. flange, pos_sensor. flange)
141+ connect (pos_value, pos_sensor. output)
142+ connect (force_output, force_sensor. output)]
143+
144+ ODESystem (eqs, t, [], []; name, systems)
145+ end
146+
147+ @named system = System ()
148+ s = complete (system)
149+ sys = structural_simplify (system)
150+ prob = ODEProblem (sys, [], (0 , 1 / 400 ))
151+ sol = solve (prob, Rosenbrock23 ())
152+
153+ delta_s = 1 / 1000
154+ s_b = 2 - delta_s + 1
155+
156+ @test sol[s. pos_value. u][end ]≈ s_b atol= 1e-3
157+ @test all (sol[s. spring. flange_a. f] .== sol[s. force_output. u])
132158 end
133159
134- eqs = [connect (pos. s, src1. output)
135- connect (force. f, src2. output)
136- connect (spring. flange_a, pos. flange, force_sensor. flange)
137- connect (spring. flange_b, force. flange, pos_sensor. flange)
138- connect (pos_value, pos_sensor. output)
139- connect (force_output, force_sensor. output)]
140-
141- ODESystem (eqs, t, [], []; name, systems)
160+ @testset " AccelerationSensor" begin
161+ @named acc = TV. AccelerationSensor ()
162+ m = 4
163+ @named mass = TV. Mass (m = m)
164+ @named force = TV. Force ()
165+ @named source = Sine (frequency = 2 , amplitude = 1 )
166+ @named acc_output = RealOutput ()
167+ eqs = [
168+ connect (force. f, source. output),
169+ connect (force. flange, mass. flange),
170+ connect (acc. flange, mass. flange),
171+ connect (acc_output, acc. output)
172+ ]
173+ @named sys = ODESystem (
174+ eqs, t, [], []; systems = [force, source, mass, acc, acc_output])
175+ s = complete (structural_simplify (sys))
176+ prob = ODEProblem (s, [], (0.0 , pi ))
177+ sol = solve (prob, Tsit5 ())
178+ @test sol[sys. acc_output. u] ≈ (sol[sys. mass. f] ./ m)
179+ end
142180 end
143181
144- @named system = System ()
145- s = complete (system)
146- sys = structural_simplify (system)
147- prob = ODEProblem (sys, [], (0 , 1 / 400 ))
148- sol = solve (prob, Rosenbrock23 ())
182+ @testset " TranslationalPosition" begin
183+ @testset " PositionSensor & ForceSensor" begin
184+ function mass_spring (; name)
185+ systems = @named begin
186+ fixed = TP. Fixed ()
187+ spring = TP. Spring (;
188+ k = 10.0 , l = 1.0 , flange_a__s = 0.0 , flange_b__s = 2.0 )
189+ mass = TP. Mass (; m = 100.0 , s = 2.0 , v = 0.0 )
190+ pos_sensor = TP. PositionSensor ()
191+ force_sensor = TP. ForceSensor ()
192+ pos_value = RealOutput ()
193+ force_value = RealOutput ()
194+ end
195+ eqs = [
196+ connect (fixed. flange, force_sensor. flange_a),
197+ connect (force_sensor. flange_b, spring. flange_a),
198+ connect (spring. flange_b, mass. flange, pos_sensor. flange),
199+ connect (pos_sensor. output, pos_value),
200+ connect (force_sensor. output, force_value)
201+ ]
202+ ODESystem (eqs, t, [], []; name, systems)
203+ end
204+
205+ @named model = mass_spring ()
206+ sys = structural_simplify (model)
207+
208+ prob = ODEProblem (sys, [], (0.0 , 1.0 ))
209+ sol = solve (prob, Tsit5 ())
210+
211+ @test all (sol[sys. spring. flange_a. f] .== sol[sys. force_value. u])
212+ @test all (sol[sys. mass. s] .== sol[sys. pos_value. u])
213+ end
149214
150- delta_s = 1 / 1000
151- s_b = 2 - delta_s + 1
152-
153- @test sol[s. pos_value. u][end ]≈ s_b atol= 1e-3
154-
155- @testset " AccelerationSensor" begin
156- @named acc = TV. AccelerationSensor ()
157- m = 4
158- @named mass = TV. Mass (m = m)
159- @named force = TV. Force ()
160- @named source = Sine (frequency = 2 , amplitude = 1 )
161- @named acc_output = RealOutput ()
162- eqs = [
163- connect (force. f, source. output),
164- connect (force. flange, mass. flange),
165- connect (acc. flange, mass. flange),
166- connect (acc_output, acc. output)
167- ]
168- @named sys = ODESystem (
169- eqs, t, [], []; systems = [force, source, mass, acc, acc_output])
170- s = complete (structural_simplify (sys))
171- prob = ODEProblem (s, [], (0.0 , pi ))
172- sol = solve (prob, Tsit5 ())
173- @test sol[sys. acc_output. u] ≈ (sol[sys. mass. f] ./ m)
215+ @testset " AccelerationSensor" begin
216+ @named acc = TP. AccelerationSensor ()
217+ m = 4
218+ @named mass = TP. Mass (m = m)
219+ @named force = TP. Force ()
220+ @named source = Sine (frequency = 2 , amplitude = 1 )
221+ @named acc_output = RealOutput ()
222+ eqs = [
223+ connect (force. f, source. output),
224+ connect (force. flange, mass. flange),
225+ connect (acc. flange, mass. flange),
226+ connect (acc_output, acc. output)
227+ ]
228+ @named sys = ODESystem (
229+ eqs, t, [], []; systems = [force, source, mass, acc, acc_output])
230+ s = complete (structural_simplify (sys))
231+ prob = ODEProblem (s, [], (0.0 , pi ))
232+ sol = solve (prob, Tsit5 ())
233+ @test sol[sys. acc_output. u] ≈ (sol[sys. mass. f] ./ m)
234+ end
174235 end
175236end
0 commit comments