Skip to content

Commit 8acebf8

Browse files
committed
All test models changed to Model3D(..) and partially adapted. Some minor fixes in the code. Release notes added. Version number changed to 0.9.0.
1 parent bea4099 commit 8acebf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+290
-281
lines changed

docs/src/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ Download and install the free DLR SimVis Community Edition, e.g. with [https://v
4848

4949
## Release Notes
5050

51+
### Version 0.9.0
52+
53+
Non-backwards compatible changes
54+
55+
- Operator `buildModia3D(..)` is removed. Instead, the new constructor `Model3D(..)` must be used at the top level of a
56+
Modia3D definition. It is now possible to define several, independent multibody systems
57+
(currently, only one of them can have animation and animation export).
58+
59+
- If init/start vectors are defined (e.g. initial state of a FreeMotion joint), they must be defined as SVector{3,Float64}(..).
60+
Otherwise, errors occur during compilation.
61+
62+
- Requires ModiaLang Version 0.11
63+
64+
65+
Other changes
66+
67+
- Code generation changed significantly, in order that the interface to Modia3D functions is type stable.
68+
As a result, simulation is more efficient and much less memory is allocated during simulation.
69+
70+
- All test models changed, due to the non-backwards compatible change
71+
72+
5173
### Version 0.8.2
5274

5375
- Fix Cone contact detection

docs/src/internal/Profiling.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The simplest technique is to put `@time` in front of the statement that should b
1414

1515
module BouncingSphereSimulation_time
1616

17-
@time begin BouncingSphere = Model(
17+
@time begin BouncingSphere = Model3D(
1818
...
1919
)
2020
end
@@ -30,7 +30,7 @@ This gives the following output:
3030
```julia
3131
0.000116 seconds (199 allocations: 12.344 KiB)
3232

33-
Instantiating model Main.BouncingSphereSimulation.buildModia3D(BouncingSphere)
33+
Instantiating model Main.BouncingSphereSimulation.BouncingSphere
3434
1.106054 seconds (2.40 M allocations: 150.386 MiB, 3.92% gc time, 62.47% compilation time)
3535
0.322050 seconds (579.29 k allocations: 32.774 MiB, 5.81% compilation time)
3636
0.077613 seconds (1.74 k allocations: 97.844 KiB)
@@ -91,7 +91,7 @@ function `getDerivatives!(..)` is called twice to force compilation of this func
9191
The `logTiming=true` flag generates the following output in this case:
9292

9393
```
94-
Instantiating model Main.MobileWithLogTiming.buildModia3D(Mobile)
94+
Instantiating model Main.MobileWithLogTiming.Mobile
9595
9696
Execute getDerivatives
9797
First executions of getDerivatives
@@ -101,9 +101,9 @@ First executions of getDerivatives
101101
... first simulation:
102102
8.341341 seconds (37.34 M allocations: 2.236 GiB, 3.36% gc time)
103103
... second simulation:
104-
... Simulate model buildModia3D(Mobile)
104+
... Simulate model Mobile
105105
Initialization at time = 0.0 s
106-
Termination of buildModia3D(Mobile) at time = 5.0 s
106+
Termination of Mobile at time = 5.0 s
107107
cpuTime = 11.7 s
108108
allocated = 2290.0 MiB
109109
algorithm = CVODE_BDF
@@ -123,7 +123,7 @@ First executions of getDerivatives
123123
nStateEvents = 0
124124
nRestartEvents = 0
125125
126-
... Timings for simulation of buildModia3D(Mobile):
126+
... Timings for simulation of Mobile:
127127
──────────────────────────────────────────────────────────────────────────────────────────────
128128
Time Allocations
129129
────────────────────── ───────────────────────

docs/src/tutorial/CollisionHandling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module BouncingSphere3D
1111
1212
using Modia3D
1313
14-
BouncingSphere = Model(
14+
BouncingSphere = Model3D(
1515
boxHeigth = 0.1,
1616
world = Object3D(feature=Scene(enableContactDetection = true,
1717
animationFile = "BouncingSphere.json")),
@@ -28,7 +28,7 @@ BouncingSphere = Model(
2828
free = FreeMotion(obj1=:world, obj2=:sphere, r=Var(init=[0.0, 1.0, 0.0]))
2929
)
3030
31-
bouncingSphere = @instantiateModel(buildModia3D(BouncingSphere), unitless=true)
31+
bouncingSphere = @instantiateModel(BouncingSphere, unitless=true)
3232
simulate!(bouncingSphere, stopTime=2.2, dtmax=0.1)
3333
3434
@usingModiaPlot

docs/src/tutorial/GettingStarted.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ module Pendulum1
1515

1616
using Modia3D
1717

18-
Pendulum = Model(
18+
Pendulum = Model3D(
1919
world = Object3D(feature=Scene()),
2020
body = Object3D(feature=Solid(massProperties=MassProperties(mass=1.0))),
2121
bodyFrame = Object3D(parent=:body, translation=[-0.5, 0.0, 0.0]),
2222
rev = Revolute(obj1=:world, obj2=:bodyFrame)
2323
)
2424

25-
pendulum = @instantiateModel(buildModia3D(Pendulum), unitless=true)
25+
pendulum = @instantiateModel(Pendulum, unitless=true)
2626
simulate!(pendulum, stopTime=3.0)
2727

2828
@usingModiaPlot # use the plot package defined by ENV["MODIA_PLOT"]
@@ -38,7 +38,7 @@ julia> include("$(Modia3D.path)/test/Tutorial/Pendulum1.jl")
3838

3939
The `world` [Object3D](@ref) has feature [Scene](@ref) and is therefore the inertial system. The `body` Object3D is a [Solid](@ref) and defines the pendulum as a mass point with `mass = 1.0`. The `bodyFrame` Object3D defines a coordinate system on the `body` that is translated along the x-axis. A revolute joint connects `world` with `bodyFrame`.
4040

41-
With command `buildModia3D(Pendulum)`, the model definition is inspected and a few lines of code included, in order that joint variables are communicated between the Modia equations and the Modia3D multibody program. Keyword `unitless=true` defines that code generation is performed without units (because Modia3D does not yet fully support units in all components).
41+
With command `Model3D(..)`, a few lines of code are included, in order that joint variables are communicated between the Modia equations and the Modia3D multibody program. Keyword `unitless=true` defines that code generation is performed without units (because Modia3D does not yet fully support units in all components).
4242

4343
The commands above generate an instance of the model, simulate it and generate the following plot:
4444

@@ -54,7 +54,7 @@ module Pendulum2
5454

5555
using Modia3D
5656

57-
Pendulum = Model(
57+
Pendulum = Model3D(
5858
world = Object3D(feature=Scene(animationFile="Pendulum2.json")),
5959
obj1 = Object3D(feature=Solid(shape=Beam(axis=1, length=1.0, width=0.2, thickness=0.2),
6060
solidMaterial="Steel", visualMaterial=VisualMaterial(color="Blue"))),
@@ -63,7 +63,7 @@ Pendulum = Model(
6363
rev = Revolute(obj1=:world, obj2=:obj2)
6464
)
6565

66-
pendulum = @instantiateModel(buildModia3D(Pendulum), unitless=true)
66+
pendulum = @instantiateModel(Pendulum, unitless=true)
6767
simulate!(pendulum, stopTime=3.0)
6868

6969
@usingModiaPlot
@@ -97,7 +97,7 @@ using Modia3D
9797

9898
include("$(Modia3D.modelsPath)/AllModels.jl")
9999

100-
Pendulum = Model(
100+
Pendulum = Model3D(
101101
world = Object3D(feature=Scene(animationFile="Pendulum3.json")),
102102
obj1 = Object3D(feature=Solid(shape=Beam(axis=1, length=1.0, width=0.2, thickness=0.2),
103103
solidMaterial="Steel", visualMaterial=VisualMaterial(color="Blue"))),
@@ -111,7 +111,7 @@ Pendulum = Model(
111111
(damper.flange_a, fixed.flange)]
112112
)
113113

114-
pendulum = @instantiateModel(buildModia3D(Pendulum), unitless=true)
114+
pendulum = @instantiateModel(Pendulum, unitless=true)
115115
simulate!(pendulum, stopTime=3.0)
116116

117117
@usingModiaPlot

src/Composition/ForceElements/Bushing.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Bushing(; kwargs...) = Bushing{Float64}(; kwargs...)
119119

120120

121121
# Compute deformation angles from rotation matrix
122-
function anglesFromRotation(largeAngles::Bool, R12::SMatrix{3,3,F}, w12::SVector{3,F}) where F <: Modia3D.VarFloatType
122+
function anglesFromRotation(largeAngles::Bool, R12::SMatrix{3,3,F,9}, w12::SVector{3,F})::Tuple{SVector{3,F},SVector{3,F},SMatrix{2,2,F,4}} where F <: Modia3D.VarFloatType
123123
if largeAngles
124124
sbe = clamp(R12[3,1], F(-1.0), F(1.0))
125125
cbe = sqrt(F(1.0) - sbe*sbe)
@@ -132,10 +132,10 @@ function anglesFromRotation(largeAngles::Bool, R12::SMatrix{3,3,F}, w12::SVector
132132
ald = w12[1] + (sal*w12[2] - cal*w12[3])*sbe/cbe
133133
bed = cal*w12[2] + sal*w12[3]
134134
gad = (-sal*w12[2] + cal*w12[3])/cbe
135-
return (SVector{3,F}(al, be, ga), SVector{3,F}(ald, bed, gad), SMatrix{2,2,F}(sal, cal, sbe, cbe))
135+
return (SVector{3,F}(al, be, ga), SVector{3,F}(ald, bed, gad), SMatrix{2,2,F,4}(sal, cal, sbe, cbe))
136136
else
137137
@error("Gimbal lock of Bushing transformation.")
138-
return (SVector{3,F}(0.0, 0.0, 0.0), SVector{3,F}(0.0, 0.0, 0.0), SMatrix{2,2,F}(0.0, 0.0, 0.0, 0.0))
138+
return (SVector{3,F}(0.0, 0.0, 0.0), SVector{3,F}(0.0, 0.0, 0.0), SMatrix{2,2,F,4}(0.0, 0.0, 0.0, 0.0))
139139
end
140140
else
141141
al = R12[2,3]
@@ -147,12 +147,12 @@ function anglesFromRotation(largeAngles::Bool, R12::SMatrix{3,3,F}, w12::SVector
147147
if (max(abs(al), abs(be), abs(ga)) > 0.174)
148148
@warn("Bushing angle exceeds 10 deg.")
149149
end
150-
return (SVector{3,F}(al, be, ga), SVector{3,F}(ald, bed, gad), SMatrix{2,2,F}(0.0, 0.0, 0.0, 0.0))
150+
return (SVector{3,F}(al, be, ga), SVector{3,F}(ald, bed, gad), SMatrix{2,2,F,4}(0.0, 0.0, 0.0, 0.0))
151151
end
152152
end
153153

154154
# Compute torque vector from force law moments
155-
function torqueFromMoments(largeAngles::Bool, moments::SVector{3,F}, sico::SMatrix{2,2,F}) where F <: Modia3D.VarFloatType
155+
function torqueFromMoments(largeAngles::Bool, moments::SVector{3,F}, sico::SMatrix{2,2,F,4})::SVector{3,F} where F <: Modia3D.VarFloatType
156156
if largeAngles
157157
tx = moments[1] + sico[1,2]*moments[3]
158158
ty = sico[2,1]*moments[2] - sico[1,1]*sico[2,2]*moments[3]
@@ -164,13 +164,13 @@ function torqueFromMoments(largeAngles::Bool, moments::SVector{3,F}, sico::SMatr
164164
end
165165

166166

167-
function initializeForceElement(force::Bushing{F}) where F <: Modia3D.VarFloatType
167+
function initializeForceElement(force::Bushing{F})::Nothing where F <: Modia3D.VarFloatType
168168
force.obj1.hasForceElement = true
169169
force.obj2.hasForceElement = true
170170
return nothing
171171
end
172172

173-
function evaluateForceElement(force::Bushing{F}) where F <: Modia3D.VarFloatType
173+
function evaluateForceElement(force::Bushing{F})::Nothing where F <: Modia3D.VarFloatType
174174
R12 = measFrameRotation(force.obj2; frameOrig=force.obj1)
175175
r12 = measFramePosition(force.obj2; frameOrig=force.obj1, frameCoord=force.obj1)
176176
w12 = measFrameRotVelocity(force.obj2; frameOrig=force.obj1, frameCoord=force.obj1)
@@ -190,6 +190,6 @@ function evaluateForceElement(force::Bushing{F}) where F <: Modia3D.VarFloatType
190190
return nothing
191191
end
192192

193-
function terminateForceElement(force::Bushing{F}) where F <: Modia3D.VarFloatType
193+
function terminateForceElement(force::Bushing{F})::Nothing where F <: Modia3D.VarFloatType
194194
return nothing
195195
end

src/Composition/dynamics.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ function computeGeneralizedForces!(mbs::MultibodyData{F}, _leq)::MultibodyData{F
370370
exportAnimation = scene.exportAnimation
371371

372372
if isTerminal #if Modia.isTerminalOfAllSegments(sim)
373-
println("... isTerminal = true")
374373
TimerOutputs.@timeit instantiatedModel.timer "Modia3D_4 isTerminal" begin
375374
for force in forceElements
376375
terminateForceElement(force)

src/Composition/joints/joints.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ Copy accelerations of prismatic joints into mbs.
559559
@assert(NJOINTS == length(mbs.prismaticObjects))
560560
scene = mbs.scene
561561
@inbounds for (i,obj) in enumerate(mbs.prismaticObjects)
562-
scene.prismatic[obj.jointIndex] = args[i]
562+
scene.prismatic[obj.jointIndex].a = args[i]
563563
end
564564
return mbs
565565
end

src/ModiaInterface/_module.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import OrderedCollections
2525
import Modia3D
2626
import Modia3D.Composition
2727
using ModiaLang
28+
using StaticArrays
2829

2930

3031
# ModiaLang models

src/ModiaInterface/buildModia3D.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using OrderedCollections
22

3-
appendSymbol(path::Nothing, name::Symbol) = name
4-
appendSymbol(path , name::Symbol) = :( $path.$name )
3+
appendSymbol(path::Nothing, name::Union{Symbol,Expr}) = name
4+
appendSymbol(path , name::Union{Symbol,Expr}) = :( $path.$name )
5+
appendSymbol(path::String , name::Union{Symbol,Expr}) = path == "" ? string(name) : path*"."*string(name)
56

67
derSymbol(path::Nothing, name::Symbol) = :(der($name))
78
derSymbol(path , name::Symbol) = :(der($path.$name))
@@ -106,7 +107,7 @@ function buildModia3D!(model::AbstractDict, FloatType::Type, TimeType::Type,
106107
if jointType == :Revolute || jointType == :RevoluteWithFlange
107108
ndofTotal += 1
108109
NRevolute += 1
109-
revoluteIndices[modelPathAsString*"."*string(path)] = NRevolute
110+
revoluteIndices[appendSymbol(modelPathAsString,path)] = NRevolute
110111
push!(jointStatesRevolute, appendSymbol(path, :phi))
111112
push!(jointStatesRevolute, appendSymbol(path, :w))
112113
if jointType == :RevoluteWithFlange
@@ -125,7 +126,7 @@ function buildModia3D!(model::AbstractDict, FloatType::Type, TimeType::Type,
125126
elseif jointType == :Prismatic || jointType == :PrismaticWithFlange
126127
ndofTotal += 1
127128
NPrismatic += 1
128-
prismaticIndices[modelPathAsString*"."*string(path)] = NPrismatic
129+
prismaticIndices[appendSymbol(modelPathAsString,path)] = NPrismatic
129130
push!(jointStatesPrismatic, appendSymbol(path, :s))
130131
push!(jointStatesPrismatic, appendSymbol(path, :v))
131132
if jointType == :PrismaticWithFlange
@@ -144,7 +145,7 @@ function buildModia3D!(model::AbstractDict, FloatType::Type, TimeType::Type,
144145
elseif jointType == :FreeMotion
145146
ndofTotal += 6
146147
NFreeMotion += 1
147-
freeMotionIndices[modelPathAsString*"."*string(path)] = NFreeMotion
148+
freeMotionIndices[appendSymbol(modelPathAsString,path)] = NFreeMotion
148149
push!(jointStatesFreeMotion, appendSymbol(path, :r))
149150
push!(jointStatesFreeMotion, appendSymbol(path, :v))
150151
push!(jointStatesFreeMotion, appendSymbol(path, :rot))

src/ModiaInterface/model3D.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,21 @@ PrismaticWithFlange(; obj1, obj2, axis=1, s=Var(init=0.0), v=Var(init=0.0), canC
9494
9595
Return joint rot. kinematics matrix `J` for Cardan angles `rot123` (rotation sequence x-y-z).
9696
"""
97-
function J123(rot123::AbstractVector)
98-
97+
function J123(rot123::SVector{3,F})::SMatrix{3,3,F,9} where {F}
9998
(sbe, cbe) = sincos(rot123[2])
10099
(sga, cga) = sincos(rot123[3])
101-
return [ cga -sga 0.0 ;
102-
cbe*sga cbe*cga 0.0 ;
103-
-sbe*cga sbe*sga cbe ] / cbe
104-
100+
return SMatrix{3,3,F,9}(cga/cbe, sga, -sbe*cga/cbe, -sga/cbe, cga, sbe*sga/cbe, F(0.0), F(0.0), F(1.0))
105101
end
106102

107103
"""
108104
J = J132(rot132::AbstractVector)
109105
110106
Return joint rot. kinematics matrix `J` for Cardan angles `rot132` (rotation sequence x-z-y).
111107
"""
112-
function J132(rot132::AbstractVector)
113-
108+
function J132(rot132::SVector{3,F})::SMatrix{3,3,F,9} where {F}
114109
(sga, cga) = sincos(rot132[2])
115110
(sbe, cbe) = sincos(rot132[3])
116-
return [ cbe 0.0 sbe ;
117-
-sbe*cga 0.0 cbe*cga ;
118-
cbe*sga cga sbe*sga ] / cga
119-
111+
return SMatrix{3,3,F,9}(cbe/cga, -sbe, cbe*sga/cga, F(0.0), F(0.0), F(1.0), sbe/cga, cbe, sbe*sga/cga)
120112
end
121113

122114

0 commit comments

Comments
 (0)