Skip to content

Commit

Permalink
Fix performance issues + update of release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinOtter committed Feb 23, 2022
1 parent 98253e6 commit 16fd37c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 49 deletions.
28 changes: 14 additions & 14 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ version = "2.20.1"

[[deps.DiffEqJump]]
deps = ["ArrayInterface", "Compat", "DataStructures", "DiffEqBase", "FunctionWrappers", "Graphs", "LinearAlgebra", "PoissonRandom", "Random", "RandomNumbers", "RecursiveArrayTools", "Reexport", "StaticArrays", "TreeViews", "UnPack"]
git-tree-sha1 = "ec1f3a5b4eac6502e45dcf79d213b200afd61990"
git-tree-sha1 = "e30f058eb600407e3fd4ea082e2527e3a3671238"
uuid = "c894b116-72e5-5b58-be3c-e6d8d4ac2b12"
version = "8.2.0"
version = "8.2.1"

[[deps.DiffEqNoiseProcess]]
deps = ["DiffEqBase", "Distributions", "LinearAlgebra", "Optim", "PoissonRandom", "QuadGK", "Random", "Random123", "RandomNumbers", "RecipesBase", "RecursiveArrayTools", "Requires", "ResettableStacks", "SciMLBase", "StaticArrays", "Statistics"]
Expand Down Expand Up @@ -578,15 +578,15 @@ version = "0.7.3"

[[deps.ModiaBase]]
deps = ["DataFrames", "DiffRules", "LinearAlgebra", "Measurements", "MonteCarloMeasurements", "OrderedCollections", "RecursiveFactorization", "StaticArrays", "TimerOutputs", "Unitful"]
git-tree-sha1 = "9e678c9f7ce692bb30855083b83fa35db09c0d32"
git-tree-sha1 = "e32f09c491f569f254d3c7776326539f4b3c5f24"
uuid = "ec7bf1ca-419d-4510-bbab-199861c55244"
version = "0.9.1"
version = "0.9.2"

[[deps.ModiaLang]]
deps = ["DataFrames", "DifferentialEquations", "FiniteDiff", "ForwardDiff", "InteractiveUtils", "JSON", "Measurements", "ModiaBase", "ModiaResult", "MonteCarloMeasurements", "OrderedCollections", "Printf", "Reexport", "StaticArrays", "Sundials", "Test", "TimerOutputs", "Unitful"]
git-tree-sha1 = "30a6da396a763673608bb94bf90683daec9adc6e"
git-tree-sha1 = "c3167743de35eb2aaf4b86985c086d86dfebfdba"
uuid = "34b37210-eaa3-4b48-8781-0b87bf559981"
version = "0.11.1"
version = "0.11.2"

[[deps.ModiaResult]]
deps = ["DataFrames", "Measurements", "MonteCarloMeasurements", "OrderedCollections", "Pkg", "Tables", "Unitful"]
Expand Down Expand Up @@ -707,9 +707,9 @@ version = "0.4.0"

[[deps.Polyester]]
deps = ["ArrayInterface", "BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "ManualMemory", "PolyesterWeave", "Requires", "Static", "StrideArraysCore", "ThreadingUtilities"]
git-tree-sha1 = "93b829eedfc466c844c233f285fae94dcaa1870a"
git-tree-sha1 = "2232d3865bc9a098e664f69cbe340b960d48217f"
uuid = "f517fe37-dbe3-4b94-8317-1923a5111588"
version = "0.6.5"
version = "0.6.6"

[[deps.PolyesterWeave]]
deps = ["BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "Static", "ThreadingUtilities"]
Expand Down Expand Up @@ -851,9 +851,9 @@ version = "0.1.0"

[[deps.SLEEFPirates]]
deps = ["IfElse", "Static", "VectorizationBase"]
git-tree-sha1 = "3a5ae1db486e4ce3ccd2b392389943481e20401f"
git-tree-sha1 = "61a96d8b89083a53fb2b745f3b59a05359651bbe"
uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa"
version = "0.6.29"
version = "0.6.30"

[[deps.SciMLBase]]
deps = ["ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "RecipesBase", "RecursiveArrayTools", "StaticArrays", "Statistics", "Tables", "TreeViews"]
Expand Down Expand Up @@ -913,9 +913,9 @@ version = "0.4.1"

[[deps.StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "95c6a5d0e8c69555842fc4a927fc485040ccc31c"
git-tree-sha1 = "6354dfaf95d398a1a70e0b28238321d5d17b2530"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.3.5"
version = "1.4.0"

[[deps.Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
Expand Down Expand Up @@ -953,9 +953,9 @@ version = "6.44.0"

[[deps.StrideArraysCore]]
deps = ["ArrayInterface", "CloseOpenIntervals", "IfElse", "LayoutPointers", "ManualMemory", "Requires", "SIMDTypes", "Static", "ThreadingUtilities"]
git-tree-sha1 = "2025a5d6564a93fa5b499dd216c0bc44537fb0d4"
git-tree-sha1 = "e0a02838565c4600ecd1d8874db8cfe263aaa6c7"
uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da"
version = "0.2.11"
version = "0.2.12"

[[deps.StructArrays]]
deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"]
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FileIO = "1"
JSON = "0.21"
Measurements = "2"
MeshIO = "0.4.10"
ModiaLang = "0.11.1"
ModiaLang = "0.11.2"
MonteCarloMeasurements = "1"
OrderedCollections = "1"
Reexport = "1.0"
Expand Down
10 changes: 3 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,15 @@ Non-backwards compatible changes
- Operator `buildModia3D(..)` is removed. Instead, the new constructor `Model3D(..)` must be used at the top level of a
Modia3D definition. It is now possible to define several, independent multibody systems
(currently, only one of them can have animation and animation export).

- If init/start vectors are defined (e.g. initial state of a FreeMotion joint), they must be defined as SVector{3,Float64}(..).
Otherwise, errors occur during compilation.

- Requires ModiaLang Version 0.11

Otherwise, errors occur during compilation.

Other changes

- All test models changed, due to the non-backwards compatible change.
- Code generation changed significantly, in order that the interface to Modia3D functions is type stable.
As a result, simulation is more efficient and much less memory is allocated during simulation.

- All test models changed, due to the non-backwards compatible change
- Efficiency improvements for collisions (less memory is allocated during simulation + faster simulation).


### Version 0.8.2
Expand Down
2 changes: 1 addition & 1 deletion src/Composition/dynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ while LinearEquationsIteration(_leq, <...>)
end
```
"""
function computeGeneralizedForces!(mbs::MultibodyData{F}, _leq)::MultibodyData{F} where {F}
function computeGeneralizedForces!(mbs::MultibodyData{F,TimeType}, _leq)::MultibodyData{F,TimeType} where {F,TimeType}
instantiatedModel = mbs.instantiatedModel
TimerOutputs.@timeit instantiatedModel.timer "Modia3D computeGeneralizedForces!" begin
storeResult = instantiatedModel.storeResult
Expand Down
61 changes: 37 additions & 24 deletions src/Composition/joints/joints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mutable struct MultibodyData{F <: Modia3D.VarFloatType, TimeType}
nz::Int # Number of used zero crossing functions
time::TimeType # Current time

freeMotionResiduals::Vector{F}

# for multibodyAccelerations
leq::Vector{ModiaBase.LinearEquations{F}}

Expand All @@ -39,7 +41,9 @@ mutable struct MultibodyData{F <: Modia3D.VarFloatType, TimeType}
revoluteObjects, prismaticObjects, freeMotionObjects,
zeros(F, length(revoluteObjects)), zeros(F, length(prismaticObjects)), zeros(SVector{3,F}, 2*length(freeMotionObjects)),
zeros(F, length(revoluteObjects)), zeros(F, length(prismaticObjects)), zeros(SVector{3,F}, 2*length(freeMotionObjects)),
zStartIndex, nz, Modia3D.convertAndStripUnit(TimeType, u"s", time), ModiaBase.LinearEquations{F}[])
zStartIndex, nz, Modia3D.convertAndStripUnit(TimeType, u"s", time),
zeros(F, 2*3*length(freeMotionObjects)),
ModiaBase.LinearEquations{F}[])
end

mutable struct MultibodyBuild{F <: Modia3D.VarFloatType, TimeType}
Expand Down Expand Up @@ -466,8 +470,8 @@ end
Copy states of the revolute joints into the corresponding Object3Ds.
"""
@inline function setStatesRevolute!(mbs::MultibodyData{F}, args::Vararg{F,NJOINTS_TIMES_2})::MultibodyData{F} where {F,NJOINTS_TIMES_2}
@assert(NJOINTS_TIMES_2 == 2*length(mbs.revoluteObjects))
function setStatesRevolute!(mbs::MultibodyData{F,TimeType}, args::Vararg{F})::MultibodyData{F,TimeType} where {F,TimeType}
@assert(length(args) == 2*length(mbs.revoluteObjects))
scene = mbs.scene
j = 1
@inbounds for obj in mbs.revoluteObjects
Expand All @@ -485,8 +489,8 @@ end
Copy states of the prismatic joints into the corresponding Object3Ds.
"""
@inline function setStatesPrismatic!(mbs::MultibodyData{F}, args::Vararg{F,NJOINTS_TIMES_2})::MultibodyData{F} where {F,NJOINTS_TIMES_2}
@assert(NJOINTS_TIMES_2 == 2*length(mbs.prismaticObjects))
function setStatesPrismatic!(mbs::MultibodyData{F,TimeType}, args::Vararg{F})::MultibodyData{F,TimeType} where {F,TimeType}
@assert(length(args) == 2*length(mbs.prismaticObjects))
scene = mbs.scene
j = 1
@inbounds for obj in mbs.prismaticObjects
Expand All @@ -504,8 +508,8 @@ end
Copy states of the free motion joints into the corresponding Object3Ds.
"""
@inline function setStatesFreeMotion!(mbs::MultibodyData{F}, args::Vararg{SVector{3,F},NJOINTS_TIMES_4})::MultibodyData{F} where {F,NJOINTS_TIMES_4}
@assert(NJOINTS_TIMES_4 == 4*length(mbs.freeMotionObjects))
function setStatesFreeMotion!(mbs::MultibodyData{F,TimeType}, args::Vararg{SVector{3,F}})::MultibodyData{F,TimeType} where {F,TimeType}
@assert(length(args) == 4*length(mbs.freeMotionObjects))
scene = mbs.scene
j = 1
@inbounds for obj in mbs.freeMotionObjects
Expand All @@ -525,8 +529,8 @@ end
Copy isrot123 of the free motion joints into the corresponding Object3Ds.
"""
@inline function setStatesFreeMotion_isrot123!(mbs::MultibodyData{F}, args::Vararg{Bool,NJOINTS})::MultibodyData{F} where {F,NJOINTS}
@assert(NJOINTS == length(mbs.freeMotionObjects))
function setStatesFreeMotion_isrot123!(mbs::MultibodyData{F,TimeType}, args::Vararg{Bool})::MultibodyData{F,TimeType} where {F,TimeType}
@assert(length(args) == length(mbs.freeMotionObjects))
scene = mbs.scene
@inbounds for (i,obj) in enumerate(mbs.freeMotionObjects)
scene.freeMotion[obj.jointIndex].isrot123 = args[i]
Expand All @@ -540,8 +544,8 @@ end
Copy accelerations of revolute joints into mbs.
"""
@inline function setAccelerationsRevolute!(mbs::MultibodyData{F}, args::Vararg{F,NJOINTS}) where {F,NJOINTS}
@assert(NJOINTS == length(mbs.revoluteObjects))
function setAccelerationsRevolute!(mbs::MultibodyData{F,TimeType}, args::Vararg{F}) where {F,TimeType}
@assert(length(args) == length(mbs.revoluteObjects))
scene = mbs.scene
@inbounds for (i,obj) in enumerate(mbs.revoluteObjects)
scene.revolute[obj.jointIndex].a = args[i]
Expand All @@ -555,8 +559,8 @@ end
Copy accelerations of prismatic joints into mbs.
"""
@inline function setAccelerationsPrismatic!(mbs::MultibodyData{F}, args::Vararg{F,NJOINTS}) where {F,NJOINTS}
@assert(NJOINTS == length(mbs.prismaticObjects))
function setAccelerationsPrismatic!(mbs::MultibodyData{F,TimeType}, args::Vararg{F}) where {F,TimeType}
@assert(length(args) == length(mbs.prismaticObjects))
scene = mbs.scene
@inbounds for (i,obj) in enumerate(mbs.prismaticObjects)
scene.prismatic[obj.jointIndex].a = args[i]
Expand All @@ -570,8 +574,8 @@ end
Copy accelerations of free motion joints into mbs
"""
@inline function setAccelerationsFreeMotion!(mbs::MultibodyData{F}, args::Vararg{SVector{3,F},NJOINTS_TIMES_2}) where {F,NJOINTS_TIMES_2}
@assert(NJOINTS_TIMES_2 == 2*length(mbs.freeMotionObjects))
function setAccelerationsFreeMotion!(mbs::MultibodyData{F,TimeType}, args::Vararg{SVector{3,F}}) where {F,TimeType}
@assert(length(args) == 2*length(mbs.freeMotionObjects))
scene = mbs.scene
j = 1
@inbounds for obj in mbs.freeMotionObjects
Expand All @@ -583,32 +587,41 @@ Copy accelerations of free motion joints into mbs
return mbs
end


"""
(tau1,tau2,<...>) = getGenForcesRevolute(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N}
Return generalized forces of revolute joints as NTuple.
"""
@inline getGenForcesRevolute(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N} = ntuple(i->mbs.revoluteGenForces[i], Val(N))
#getGenForcesRevolute(mbs::MultibodyData{F,TimeType}) where {F,TimeType} = mbs.revoluteGenForces
getGenForcesRevolute(mbs::MultibodyData{F,TimeType}, ::Val{N}) where {F,TimeType,N} = ntuple(i->mbs.revoluteGenForces[i], Val(N))


"""
(f1,f2,<...>) = getGenForcesPrismatic(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N}
Return generalized forces of prismatic joints as NTuple.
"""
@inline getGenForcesPrismatic(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N} = ntuple(i->mbs.prismaticGenForces[i], Val(N))
#getGenForcesPrismatic(mbs::MultibodyData{F,TimeType}) where {F,TimeType} = mbs.prismaticGenForces
getGenForcesPrismatic(mbs::MultibodyData{F,TimeType}, ::Val{N}) where {F,TimeType,N} = ntuple(i->mbs.prismaticGenForces[i], Val(N))


"""
(genf1,gent1,genf2,gent2,<...>) = getGenForcesFreeMotion(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N}
residuals = getGenForcesFreeMotion(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N}
Return generalized forces of free motion joints as NTuple.
Return generalized forces of free motion joints as Vector to be used for residuals vector.
"""
@inline getGenForcesFreeMotion(mbs::MultibodyData{F}, ::Val{N}) where {F <: Modia3D.VarFloatType,N} = ntuple(i->mbs.freeMotionGenForces[i], Val(N))



function getGenForcesFreeMotion(mbs::MultibodyData{F,TimeType})::Vector{F} where {F,TimeType}
res = mbs.freeMotionResiduals
j = 1
@assert(length(res) == 3*length(mbs.freeMotionGenForces))
@inbounds for vec in mbs.freeMotionGenForces
res[j] = vec[1]
res[j+1] = vec[2]
res[j+2] = vec[3]
j += 3
end
return res
end


# For backwards compatibility (do not use for new models)
Expand Down
2 changes: 1 addition & 1 deletion src/Modia3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Modia3D

const path = dirname(dirname(@__FILE__)) # Absolute path of package directory
const Version = "0.9.0"
const Date = "2022-02-21"
const Date = "2022-02-23"

println("\nImporting Modia3D Version $Version ($Date)")

Expand Down
2 changes: 1 addition & 1 deletion src/ModiaInterface/buildModia3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function buildModia3D!(model::AbstractDict, FloatType::Type, TimeType::Type,
end
if length(jointAccelerationsFreeMotion2) > 0
NFreeMotion2 = 2*NFreeMotion
push!(mbs_equations, :( ($(jointForcesFreeMotion2...), ) = implicitDependency(Modia3D.getGenForcesFreeMotion($mbsi, Val($NFreeMotion2)), $(jointAccelerationsFreeMotion2...)) ))
push!(mbs_equations, :( ($(jointForcesFreeMotion2...), ) = implicitDependency(Modia3D.getGenForcesFreeMotion($mbsi), $(jointAccelerationsFreeMotion2...)) ))
mbs_variables[mbsi] = Var(hideResult=true)
end

Expand Down

0 comments on commit 16fd37c

Please sign in to comment.