Skip to content

Commit fb64b8a

Browse files
Merge pull request #97 from ModiaSim/otter_next_main_2022_02_06
Otter next main 2022 02 06
2 parents 72ad5df + 16fd37c commit fb64b8a

File tree

74 files changed

+1392
-1049
lines changed

Some content is hidden

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

74 files changed

+1392
-1049
lines changed

Manifest.toml

Lines changed: 101 additions & 88 deletions
Large diffs are not rendered by default.

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Modia3D"
22
uuid = "07f2c1e0-90b0-56cf-bda7-b44b56e34eed"
33
authors = ["Andrea Neumayr <[email protected]>", "Martin Otter <[email protected]>", "Gerhard Hippmann <[email protected]>"]
4-
version = "0.8.2"
4+
version = "0.9.0"
55

66
[deps]
77
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
@@ -32,7 +32,7 @@ FileIO = "1"
3232
JSON = "0.21"
3333
Measurements = "2"
3434
MeshIO = "0.4.10"
35-
ModiaLang = "0.10.0"
35+
ModiaLang = "0.11.2"
3636
MonteCarloMeasurements = "1"
3737
OrderedCollections = "1"
3838
Reexport = "1.0"

docs/src/index.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ 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+
- If init/start vectors are defined (e.g. initial state of a FreeMotion joint), they must be defined as SVector{3,Float64}(..).
59+
Otherwise, errors occur during compilation.
60+
61+
Other changes
62+
63+
- All test models changed, due to the non-backwards compatible change.
64+
- Code generation changed significantly, in order that the interface to Modia3D functions is type stable.
65+
As a result, simulation is more efficient and much less memory is allocated during simulation.
66+
- Efficiency improvements for collisions (less memory is allocated during simulation + faster simulation).
67+
68+
5169
### Version 0.8.2
5270

5371
- 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/_module.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Andrea Neumayr and Martin Otter, [DLR - Institute of System Dynamics and Control
2020
"""
2121
module Composition
2222

23+
export MultibodyData
24+
2325
export initialize, initAnalysis!, performAnalysis!, closeAnalysis!, visualize!, visualizeWorld!
2426
export updatePosition!, update!
2527
export RotationVariables, RCardan123
@@ -29,6 +31,13 @@ export FixTranslation
2931
export setAngle!, connect
3032
export setDistance!
3133

34+
export openModel3D!
35+
export setStatesRevolute! , setAccelerationsRevolute! , getGenForcesRevolute
36+
export setStatesPrismatic! , setAccelerationsPrismatic! , getGenForcesPrismatic
37+
export setStatesFreeMotion!, setAccelerationsFreeMotion!, getGenForcesFreeMotion
38+
export setStatesFreeMotion_isrot123!
39+
40+
export computeGeneralizedForces!
3241

3342
export distanceAndAngles, distance, planarRotationAngle
3443
export measFrameRotation, measFramePosition, measFrameDistance
@@ -81,6 +90,7 @@ import Modia3D.Shapes
8190
import JSON
8291
import Printf
8392
import ModiaLang
93+
import ModiaLang: ModiaBase
8494
import TimerOutputs
8595
import MonteCarloMeasurements
8696

0 commit comments

Comments
 (0)