Skip to content

Commit 1b3ad93

Browse files
Float64 -> Real numbers for force element parameters
1 parent dadbb06 commit 1b3ad93

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

src/Composition/ForceElements/Bushing.jl

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ i.e. the orientation of `obj2` does not influence the resulting forces.
2020
positive axis directions at `obj1` and in opposite directions at `obj2`.
2121
- `springForceLaw` defines the force law of the spring in x-, y- and
2222
z-direction:
23-
- A `Float64` value represents a linear stiffness coefficient.
23+
- A `Real` number represents a linear stiffness coefficient.
2424
- An univariate `Function` is used to compute the spring force
2525
dependent of its deflection.
2626
- `damperForceLaw` defines the force law of the damper in x-, y- and
2727
z-direction:
28-
- A `Float64` value represents a linear damping coefficient.
28+
- A `Real` number represents a linear damping coefficient.
2929
- An univariate `Function` is used to compute the damper force
3030
dependent of its deflection velocity.
3131
- `nominalTorque` defines nominal torques about alpha, beta and gamma
3232
directions.
3333
- `rotSpringForceLaw` defines the force law of the rotational spring
3434
about alpha-, beta- and gamma-direction:
35-
- A `Float64` value represents a linear damping coefficient.
35+
- A `Real` number represents a linear damping coefficient.
3636
- An univariate `Function` is used to compute the spring force
3737
dependent of its deflection.
3838
- `rotDamperForceLaw` defines the force law of the rotational damper
3939
about alpha-, beta- and gamma-direction:
40-
- A `Float64` value represents a linear damping coefficient.
40+
- A `Real` number represents a linear damping coefficient.
4141
- An univariate `Function` is used to compute the damper force
4242
dependent of its deflection velocity.
4343
- `largeAngles` can be used to enable large angle mode.
@@ -74,13 +74,6 @@ mutable struct Bushing <: Modia3D.AbstractForceElement
7474
rotSpringForceLaw::AbstractVector = Modia3D.ZeroVector3D,
7575
rotDamperForceLaw::AbstractVector = Modia3D.ZeroVector3D,
7676
largeAngles::Bool = false )
77-
for dir in 1:3
78-
@assert(typeof(springForceLaw[dir]) == Float64 || isa(springForceLaw[dir], Function))
79-
@assert(typeof(damperForceLaw[dir]) == Float64 || isa(damperForceLaw[dir], Function))
80-
@assert(typeof(rotSpringForceLaw[dir]) == Float64 || isa(rotSpringForceLaw[dir], Function))
81-
@assert(typeof(rotDamperForceLaw[dir]) == Float64 || isa(rotDamperForceLaw[dir], Function))
82-
end
83-
8477
nomForce = Modia3D.convertAndStripUnit(SVector{3,Float64}, u"N" , nominalForce)
8578
nomTorque = Modia3D.convertAndStripUnit(SVector{3,Float64}, u"N*m", nominalTorque)
8679
springForceFunction = Vector{Function}(undef, 3)
@@ -89,33 +82,33 @@ mutable struct Bushing <: Modia3D.AbstractForceElement
8982
rotDamperForceFunction = Vector{Function}(undef, 3)
9083
irand = rand(Int)
9184
for dir in 1:3
92-
if (typeof(springForceLaw[dir]) == Float64)
85+
if (isa(springForceLaw[dir], Function))
86+
springForceFunction[dir] = springForceLaw[dir]
87+
else
9388
stiffness = Modia3D.convertAndStripUnit(Float64, u"N/m", springForceLaw[dir])
9489
fsymb = Symbol("fc", dir, "_", irand) # todo: replace irand by force.path
9590
springForceFunction[dir] = eval(:($fsymb(pos) = $stiffness * pos))
96-
else
97-
springForceFunction[dir] = springForceLaw[dir]
9891
end
99-
if (typeof(damperForceLaw[dir]) == Float64)
92+
if (isa(damperForceLaw[dir], Function))
93+
damperForceFunction[dir] = damperForceLaw[dir]
94+
else
10095
damping = Modia3D.convertAndStripUnit(Float64, u"N*s/m", damperForceLaw[dir])
10196
fsymb = Symbol("fd", dir, "_", irand) # todo: replace irand by force.path
10297
damperForceFunction[dir] = eval(:($fsymb(vel) = $damping * vel))
103-
else
104-
damperForceFunction[dir] = damperForceLaw[dir]
10598
end
106-
if (typeof(rotSpringForceLaw[dir]) == Float64)
99+
if (isa(rotSpringForceLaw[dir], Function))
100+
rotSpringForceFunction[dir] = rotSpringForceLaw[dir]
101+
else
107102
stiffness = Modia3D.convertAndStripUnit(Float64, u"N*m/rad", rotSpringForceLaw[dir])
108103
fsymb = Symbol("mc", dir, "_", irand) # todo: replace irand by force.path
109104
rotSpringForceFunction[dir] = eval(:($fsymb(ang) = $stiffness * ang))
110-
else
111-
rotSpringForceFunction[dir] = rotSpringForceLaw[dir]
112105
end
113-
if (typeof(rotDamperForceLaw[dir]) == Float64)
106+
if (isa(rotDamperForceLaw[dir], Function))
107+
rotDamperForceFunction[dir] = rotDamperForceLaw[dir]
108+
else
114109
damping = Modia3D.convertAndStripUnit(Float64, u"N*m*s/rad", rotDamperForceLaw[dir])
115110
fsymb = Symbol("md", dir, "_", irand) # todo: replace irand by force.path
116111
rotDamperForceFunction[dir] = eval(:($fsymb(angd) = $damping * angd))
117-
else
118-
rotDamperForceFunction[dir] = rotDamperForceLaw[dir]
119112
end
120113
end
121114

src/Composition/ForceElements/SpringDamperPtP.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Return a `force` acting as point-to-point parallel spring-damper between
1616
- `nominalForce` defines the nominal force, i.e. the force that acts when
1717
spring and damper forces are zero. Positive values represent tension.
1818
- `springForceLaw` defines the force law of the spring:
19-
- A `Float64` value represents a linear stiffness coefficient.
19+
- A `Real` number represents a linear stiffness coefficient.
2020
- An univariate `Function` is used to compute the spring force
2121
dependent of its deflection. Positive values represent tension.
2222
- `damperForceLaw` defines the force law of the damper:
23-
- A `Float64` value represents a linear damping coefficient.
23+
- A `Real` number represents a linear damping coefficient.
2424
- An univariate `Function` is used to compute the damper force
2525
dependent of its deflection velocity. Positive values represent
2626
expansion.
@@ -37,20 +37,20 @@ mutable struct SpringDamperPtP <: Modia3D.AbstractForceElement
3737

3838
function SpringDamperPtP(; obj1::Object3D,
3939
obj2::Object3D,
40-
nominalLength::Float64 = 0.0,
41-
nominalForce::Float64 = 0.0,
42-
springForceLaw::Union{Float64, Function} = 0.0,
43-
damperForceLaw::Union{Float64, Function} = 0.0 )
40+
nominalLength::Real = 0.0,
41+
nominalForce::Real = 0.0,
42+
springForceLaw::Union{Real, Function} = 0.0,
43+
damperForceLaw::Union{Real, Function} = 0.0 )
4444

4545
nomLength = Modia3D.convertAndStripUnit(Float64, u"m", nominalLength)
4646
nomForce = Modia3D.convertAndStripUnit(Float64, u"N", nominalForce)
4747
irand = rand(Int)
48-
if (typeof(springForceLaw) == Float64)
48+
if (!isa(springForceLaw, Function))
4949
stiffness = Modia3D.convertAndStripUnit(Float64, u"N/m", springForceLaw)
5050
fsymb = Symbol("fc", "_", irand) # todo: replace irand by force.path
5151
springForceLaw = eval(:($fsymb(pos) = $stiffness * pos))
5252
end
53-
if (typeof(damperForceLaw) == Float64)
53+
if (!isa(damperForceLaw, Function))
5454
damping = Modia3D.convertAndStripUnit(Float64, u"N*s/m", damperForceLaw)
5555
fsymb = Symbol("fd", "_", irand) # todo: replace irand by force.path
5656
damperForceLaw = eval(:(fd(vel) = $damping * vel))

0 commit comments

Comments
 (0)