Skip to content

Commit

Permalink
Merge pull request #135 from ModiaSim/gh_avoidBushingCodeGeneration
Browse files Browse the repository at this point in the history
Speed up Bushing
  • Loading branch information
GerhardHippmann authored Jan 15, 2024
2 parents 18ebcaf + 4cdc5ea commit 51f337c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ julia -JModia3D_sysimage.so (otherwise)
### Forthcoming version

- Enable kinematic chain flipping for structure variable systems
- Avoid function code generation for linear stiffness and damping in SpringDamperPtP and Bushing


### Version 0.12.2
Expand Down
24 changes: 12 additions & 12 deletions src/Composition/ForceElements/Bushing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,30 @@ mutable struct Bushing{F <: Modia3D.VarFloatType} <: Modia3D.AbstractForceElemen
if (isa(springForceLaw[dir], Function))
springForceFunction[dir] = springForceLaw[dir]
else
stiffness = Modia3D.convertAndStripUnit(F, u"N/m", springForceLaw[dir])
fsymb = Symbol(path, "_", "fc", dir)
springForceFunction[dir] = eval(:($fsymb(pos) = $stiffness * pos))
stiffness::F = Modia3D.convertAndStripUnit(F, u"N/m", springForceLaw[dir])
stiffnessFunction(pos::F) = stiffness * pos
springForceFunction[dir] = stiffnessFunction
end
if (isa(damperForceLaw[dir], Function))
damperForceFunction[dir] = damperForceLaw[dir]
else
damping = Modia3D.convertAndStripUnit(F, u"N*s/m", damperForceLaw[dir])
fsymb = Symbol(path, "_", "fd", dir)
damperForceFunction[dir] = eval(:($fsymb(vel) = $damping * vel))
damping::F = Modia3D.convertAndStripUnit(F, u"N*s/m", damperForceLaw[dir])
dampingFunction(vel::F) = damping * vel
damperForceFunction[dir] = dampingFunction
end
if (isa(rotSpringForceLaw[dir], Function))
rotSpringForceFunction[dir] = rotSpringForceLaw[dir]
else
stiffness = Modia3D.convertAndStripUnit(F, u"N*m/rad", rotSpringForceLaw[dir])
fsymb = Symbol(path, "_", "mc", dir)
rotSpringForceFunction[dir] = eval(:($fsymb(ang) = $stiffness * ang))
rotStiffness::F = Modia3D.convertAndStripUnit(F, u"N*m/rad", rotSpringForceLaw[dir])
rotStiffnessFunction(ang::F) = rotStiffness * ang
rotSpringForceFunction[dir] = rotStiffnessFunction
end
if (isa(rotDamperForceLaw[dir], Function))
rotDamperForceFunction[dir] = rotDamperForceLaw[dir]
else
damping = Modia3D.convertAndStripUnit(F, u"N*m*s/rad", rotDamperForceLaw[dir])
fsymb = Symbol(path, "_", "md", dir)
rotDamperForceFunction[dir] = eval(:($fsymb(angd) = $damping * angd))
rotDamping::F = Modia3D.convertAndStripUnit(F, u"N*m*s/rad", rotDamperForceLaw[dir])
rotDampingFunction(om::F) = rotDamping * om
rotDamperForceFunction[dir] = rotDampingFunction
end
end

Expand Down
18 changes: 9 additions & 9 deletions src/Composition/ForceElements/SpringDamperPtP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ mutable struct SpringDamperPtP{F <: Modia3D.VarFloatType} <: Modia3D.AbstractFor
nomLength = Modia3D.convertAndStripUnit(F, u"m", nominalLength)
nomForce = Modia3D.convertAndStripUnit(F, u"N", nominalForce)

if (!isa(springForceLaw, Function))
stiffness = Modia3D.convertAndStripUnit(F, u"N/m", springForceLaw)
fkt1(_x) = stiffness*_x
if (isa(springForceLaw, Function))
springForceFunction = springForceLaw
else
fkt1 = springForceLaw
stiffness::F = Modia3D.convertAndStripUnit(F, u"N/m", springForceLaw)
springForceFunction(pos::F) = stiffness * pos
end

if (!isa(damperForceLaw, Function))
damping = Modia3D.convertAndStripUnit(F, u"N*s/m", damperForceLaw)
fkt2(_x) = damping*_x
if (isa(damperForceLaw, Function))
damperForceFunction = damperForceLaw
else
fkt2 = damperForceLaw
damping::F = Modia3D.convertAndStripUnit(F, u"N*s/m", damperForceLaw)
damperForceFunction(vel::F) = damping * vel
end

return new(path, obj1, obj2, nomLength, nomForce, fkt1, fkt2)
return new(path, obj1, obj2, nomLength, nomForce, springForceFunction, damperForceFunction)
end
end
SpringDamperPtP(; kwargs...) = SpringDamperPtP{Float64}(; kwargs...)
Expand Down

0 comments on commit 51f337c

Please sign in to comment.