-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from SciML/zero_defaults
Reduce the extra initial conditions on Translational components
- Loading branch information
Showing
8 changed files
with
79 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,58 @@ | ||
using ModelingToolkit, OrdinaryDiffEq, Test | ||
using ModelingToolkit: t_nounits as t, D_nounits as D | ||
|
||
using ModelingToolkitStandardLibrary.Blocks | ||
import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica as TP | ||
using ModelingToolkitStandardLibrary.Blocks: Sine | ||
using ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica: Damper, Spring, Mass, | ||
Fixed, Force | ||
|
||
@testset "spring damper mass fixed" begin | ||
@named damper = TP.Damper(; d = 1) | ||
@named spring = TP.Spring(; c = 1, s_rel0 = 1) | ||
@named mass = TP.Mass(; m = 1, v = 1) | ||
@named fixed = TP.Fixed(s0 = 1) | ||
|
||
eqs = [connect(spring.flange_a, mass.flange_a, damper.flange_a) | ||
connect(spring.flange_b, damper.flange_b, fixed.flange)] | ||
|
||
@named model = ODESystem(eqs, t; systems = [fixed, mass, spring, damper]) | ||
|
||
sys = structural_simplify(model) | ||
|
||
foreach(println, full_equations(sys)) | ||
@mtkmodel SpringDamperMassFixed begin | ||
@components begin | ||
damper = Damper(; d = 1) | ||
spring = Spring(; c = 1, s_rel0 = 1) | ||
mass = Mass(; m = 1, v = 1, s = 0) | ||
fixed = Fixed(s0 = 1) | ||
end | ||
@equations begin | ||
connect(spring.flange_a, mass.flange_a, damper.flange_a) | ||
connect(spring.flange_b, damper.flange_b, fixed.flange) | ||
end | ||
end | ||
|
||
@mtkbuild sys = SpringDamperMassFixed() | ||
|
||
prob = ODEProblem(sys, [], (0, 20.0), []) | ||
sol = solve(prob, ImplicitMidpoint(), dt = 0.01) | ||
|
||
@test sol[mass.v][1] == 1.0 | ||
@test sol[mass.v][end]≈0.0 atol=1e-4 | ||
@test sol[sys.mass.v][1] == 1.0 | ||
@test sol[sys.mass.v][end]≈0.0 atol=1e-4 | ||
end | ||
|
||
@testset "driven spring damper mass" begin | ||
@named damper = TP.Damper(; d = 1) | ||
@named spring = TP.Spring(; c = 1, s_rel0 = 1) | ||
@named mass = TP.Mass(; m = 1, v = 1) | ||
@named fixed = TP.Fixed(; s0 = 1) | ||
@named force = TP.Force() | ||
@named source = Sine(frequency = 3, amplitude = 2) | ||
|
||
eqs = [connect(force.f, source.output) | ||
connect(force.flange, mass.flange_a) | ||
connect(spring.flange_a, mass.flange_b, damper.flange_a) | ||
connect(spring.flange_b, damper.flange_b, fixed.flange)] | ||
|
||
@named model = ODESystem(eqs, t; | ||
systems = [fixed, mass, spring, damper, force, source]) | ||
|
||
sys = structural_simplify(model) | ||
|
||
foreach(println, full_equations(sys)) | ||
@mtkmodel DrivenSpringDamperMass begin | ||
@components begin | ||
damper = Damper(; d = 1) | ||
spring = Spring(; c = 1, s_rel0 = 1) | ||
mass = Mass(; m = 1, v = 1, s = 0) | ||
fixed = Fixed(; s0 = 1) | ||
force = Force() | ||
source = Sine(frequency = 3, amplitude = 2) | ||
end | ||
|
||
@equations begin | ||
connect(force.f, source.output) | ||
connect(force.flange, mass.flange_a) | ||
connect(spring.flange_a, mass.flange_b, damper.flange_a) | ||
connect(spring.flange_b, damper.flange_b, fixed.flange) | ||
end | ||
end | ||
|
||
@mtkbuild sys = DrivenSpringDamperMass() | ||
|
||
prob = ODEProblem(sys, [], (0, 20.0), []) | ||
sol = solve(prob, Rodas4()) | ||
|
||
lb, ub = extrema(sol(15:0.05:20, idxs = mass.v).u) | ||
lb, ub = extrema(sol(15:0.05:20, idxs = sys.mass.v).u) | ||
@test -lb≈ub atol=1e-2 | ||
@test -0.11 < lb < -0.1 | ||
end |