From 434770e9e19156b4e80c3d580a116f9f8416e151 Mon Sep 17 00:00:00 2001 From: Johann Hell Date: Sun, 7 Jan 2024 18:45:22 +0100 Subject: [PATCH] speedup SpringDamperPtP --- src/Composition/ForceElements/SpringDamperPtP.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Composition/ForceElements/SpringDamperPtP.jl b/src/Composition/ForceElements/SpringDamperPtP.jl index e7cef08..6ebf6e5 100644 --- a/src/Composition/ForceElements/SpringDamperPtP.jl +++ b/src/Composition/ForceElements/SpringDamperPtP.jl @@ -66,18 +66,22 @@ 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) - fsymb = Symbol(path, "_", "fc") - springForceLaw = eval(:($fsymb(pos) = $stiffness * pos)) + fkt1(_x) = stiffness*_x + else + fkt1 = springForceLaw end + if (!isa(damperForceLaw, Function)) damping = Modia3D.convertAndStripUnit(F, u"N*s/m", damperForceLaw) - fsymb = Symbol(path, "_", "fd") - damperForceLaw = eval(:($fsymb(vel) = $damping * vel)) + fkt2(_x) = damping*_x + else + fkt2 = damperForceLaw end - return new(path, obj1, obj2, nomLength, nomForce, springForceLaw, damperForceLaw) + return new(path, obj1, obj2, nomLength, nomForce, fkt1, fkt2) end end SpringDamperPtP(; kwargs...) = SpringDamperPtP{Float64}(; kwargs...)