-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make it possible to change
world.n
(#166)
* make it possible to change `world.n` * add test file * tweak tutorial * fix some instances of double worlds
- Loading branch information
1 parent
8e70a4f
commit 3bf6cf6
Showing
5 changed files
with
104 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Multibody, ModelingToolkit, JuliaSimCompiler, Test | ||
@mtkmodel FallingBody begin | ||
@components begin | ||
my_world = World(g = 1, n = [0, 1, 0]) | ||
body = Body(isroot=true) | ||
end | ||
end | ||
|
||
@named model = FallingBody() | ||
model = complete(model) | ||
ssys = structural_simplify(IRSystem(model)) | ||
prob = ODEProblem(ssys, [], (0, 1)) | ||
sol = solve(prob, Tsit5()) | ||
|
||
tv = 0:0.1:1 | ||
@test iszero(sol(tv, idxs=model.body.r_0[1])) | ||
@test sol(tv, idxs=model.body.r_0[2]) ≈ tv.^2 ./ 2 atol=1e-6 | ||
@test iszero(sol(tv, idxs=model.body.r_0[3])) | ||
|
||
|
||
# Change g | ||
prob = ODEProblem(ssys, [model.my_world.g .=> 2], (0, 1)) | ||
sol = solve(prob, Tsit5()) | ||
@test iszero(sol(tv, idxs=model.body.r_0[1])) | ||
@test sol(tv, idxs=model.body.r_0[2]) ≈ 2*tv.^2 ./ 2 atol=1e-6 | ||
@test iszero(sol(tv, idxs=model.body.r_0[3])) | ||
|
||
# Change n | ||
prob = ODEProblem(ssys, collect(model.my_world.n) .=> [1, 0, 0], (0, 1)) | ||
sol = solve(prob, Tsit5()) | ||
@test sol(tv, idxs=model.body.r_0[1]) ≈ tv.^2 ./ 2 atol=1e-6 | ||
@test iszero(sol(tv, idxs=model.body.r_0[2])) | ||
@test iszero(sol(tv, idxs=model.body.r_0[3])) | ||
|
||
|
||
## World in more than one place | ||
# This should result in too many equations | ||
@mtkmodel FallingBodyOuter begin | ||
@components begin | ||
inner_model = FallingBody() | ||
my_world_outer = World(g = 2, n = [0, 1, 0]) | ||
body = Body(isroot=true) | ||
end | ||
end | ||
|
||
@named model = FallingBodyOuter() | ||
model = complete(model) | ||
@test_throws ModelingToolkit.ExtraEquationsSystemException structural_simplify(IRSystem(model)) | ||
|