11
22"""
33 force = SpringDamperPtP(; obj1, obj2,
4- nominalLength = 0.0,
5- nominalForce = 0.0,
6- stiffness = 0.0,
7- stiffnessForceFunction = nothing,
8- damping = 0.0,
9- dampingForceFunction = nothing )
4+ nominalLength = 0.0,
5+ nominalForce = 0.0,
6+ springForceLaw = 0.0,
7+ damperForceLaw = 0.0 )
108
119Return a `force` acting as point-to-point parallel spring-damper between
1210`obj1::`[`Object3D`](@ref) and `obj2::`[`Object3D`](@ref).
1311
1412# Arguments
1513
16- - `nominalLength`: Nominal length, i.e. distance between `obj1` and `obj2`
17- where deflection of stiffness force is zero.
18- - `nominalForce`: Nominal force, i.e. force that acts when stiffness and
19- damping forces are zero. Positive values represent tensil forces .
20- - `stiffness`: Linear stiffness coefficient of spring. Ignored if
21- `stiffnessForceFunction` is defined .
22- - `stiffnessForceFunction`: Univariate function which computes the
23- stiffness force dependent of the stiffness force deflection .
24- - `damping`: Linear damping coefficient of damper. Ignored if
25- `dampingForceFunction` is defined .
26- - `dampingForceFunction`: Univariate function which computes the
27- damping force dependent of the damper velocity .
14+ - `nominalLength` defines the nominal length, i.e. the distance between
15+ `obj1` and `obj2` where the deflection of the spring is zero.
16+ - `nominalForce` defines the nominal force, i.e. the force that acts when
17+ spring and damper forces are zero. Positive values represent tension .
18+ - `springForceLaw` defines the force law of the spring:
19+ A `Float64` value represents a linear stiffness coefficient .
20+ An univariate `Function` is used to compute the spring force dependent
21+ of its deflection. Positive values represent tension .
22+ - `damperForceLaw` defines the force law of the damper:
23+ A `Float64` value represents a linear damping coefficient .
24+ An univariate `Function` is used to compute the damper force dependent
25+ of its deflection velocity. Positive values represent expansion .
2826"""
2927mutable struct SpringDamperPtP <: Modia3D.AbstractForceElement
3028
31- obj1:: Modia3D.AbstractObject3D
32- obj2:: Modia3D.AbstractObject3D
29+ obj1:: Object3D
30+ obj2:: Object3D
3331
3432 nominalLength:: Float64
3533 nominalForce:: Float64
34+ springForceFunction:: Function
35+ damperForceFunction:: Function
3636
37- stiffness:: Float64
38- stiffnessForceFunction:: Union{Function, Nothing}
39-
40- damping:: Float64
41- dampingForceFunction:: Union{Function, Nothing}
42-
43- function SpringDamperPtP (; obj1:: Modia3D.AbstractObject3D ,
44- obj2:: Modia3D.AbstractObject3D ,
37+ function SpringDamperPtP (; obj1:: Object3D ,
38+ obj2:: Object3D ,
4539 nominalLength:: Float64 = 0.0 ,
4640 nominalForce:: Float64 = 0.0 ,
47- stiffness:: Float64 = 0.0 ,
48- stiffnessForceFunction:: Union{Function, Nothing} = nothing ,
49- damping:: Float64 = 0.0 ,
50- dampingForceFunction:: Union{Function, Nothing} = nothing )
51-
52- nomLength = Modia3D. convertAndStripUnit (Float64, u " m" , nominalLength)
53- nomForce = Modia3D. convertAndStripUnit (Float64, u " N" , nominalForce)
54- stiff = Modia3D. convertAndStripUnit (Float64, u " N/m" , stiffness)
55- damp = Modia3D. convertAndStripUnit (Float64, u " N*s/m" , damping)
56-
57- return new (obj1, obj2, nomLength, nomForce, stiff, stiffnessForceFunction, damp, dampingForceFunction)
58-
41+ springForceLaw:: Union{Float64, Function} = 0.0 ,
42+ damperForceLaw:: Union{Float64, Function} = 0.0 )
43+
44+ nomLength = Modia3D. convertAndStripUnit (Float64, u " m" , nominalLength)
45+ nomForce = Modia3D. convertAndStripUnit (Float64, u " N" , nominalForce)
46+ if (typeof (springForceLaw) == Float64)
47+ stiffness = Modia3D. convertAndStripUnit (Float64, u " N/m" , springForceLaw)
48+ springForceLaw = eval (:(fc (pos) = $ stiffness * pos))
49+ end
50+ if (typeof (damperForceLaw) == Float64)
51+ damping = Modia3D. convertAndStripUnit (Float64, u " N*s/m" , damperForceLaw)
52+ damperForceLaw = eval (:(fd (vel) = $ damping * vel))
53+ end
54+
55+ return new (obj1, obj2, nomLength, nomForce, springForceLaw, damperForceLaw)
5956 end
6057end
6158
@@ -71,16 +68,8 @@ function evaluateForceElement(force::SpringDamperPtP)
7168 vel = measFrameDistVelocity (force. obj2; frameOrig= force. obj1)
7269
7370 defl = pos - force. nominalLength
74- if isnothing (force. stiffnessForceFunction)
75- fc = force. stiffness * defl
76- else
77- fc = force. stiffnessForceFunction (defl)
78- end
79- if isnothing (force. dampingForceFunction)
80- fd = force. damping * vel
81- else
82- fd = force. dampingForceFunction (vel)
83- end
71+ fc = force. springForceFunction (defl)
72+ fd = force. damperForceFunction (vel)
8473 f12 = (fc + fd + force. nominalForce) * norm
8574
8675 applyFrameForcePair! (force. obj2, force. obj1, f12; frameCoord= force. obj1)
0 commit comments