Skip to content

Commit 3dc2b19

Browse files
Merge pull request #47 from ModiaSim/an_useMPRFloatType
An use mpr float type
2 parents 735e716 + 479d59a commit 3dc2b19

File tree

9 files changed

+196
-168
lines changed

9 files changed

+196
-168
lines changed

src/Basics/_module.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Andrea Neumayr and Martin Otter, [DLR - Institute of System Dynamics and Control
1313
"""
1414
module Basics
1515

16+
import Modia3D
17+
1618
export trailingPartOfName
1719

1820
export neps, sign_eps, radToDeg

src/Basics/constantsAndFunctions.jl

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,37 @@
77

88

99
# Epsilon and sign
10-
const neps = sqrt( eps() )
11-
sign_eps(value::Float64; seps::Float64 = 100*neps)::Float64 = value > seps ? 1.0 : (value < -seps ? -1.0 : 0.0)
12-
13-
function normalizeVector(n::SVector{3,Float64})::SVector{3,Float64}
14-
nabs = norm(n)
15-
if nabs <= neps
16-
println("neps ", neps)
17-
println("nabs ", nabs)
18-
@assert(nabs > neps) # && norm(vec) > eps()
19-
# return nothing
20-
else
10+
const neps = sqrt( eps(Modia3D.MPRFloatType) )
11+
12+
function sign_eps(value::T; ) where {T}
13+
seps::T = 100.0*neps
14+
return value > seps ? T(1.0) : (value < -seps ? T(-1.0) : T(0.0))
15+
end
16+
17+
function normalizeVector(n::SVector{3,T}) where {T}
18+
nabs = norm(n)
19+
if nabs <= neps
20+
println("neps ", neps)
21+
println("nabs ", nabs)
22+
@assert(nabs > neps) # && norm(vec) > eps()
23+
# return nothing
24+
end
2125
return n/nabs
22-
end
2326
end
2427

2528
# Standard constants
26-
const radToDeg = 180.0/pi
29+
const radToDeg = 180.0/pi
2730

2831
""" mutable struct BoundingBox - Smallest box that contains a visual element"""
2932
mutable struct BoundingBox
30-
x_min::Float64
31-
x_max::Float64
32-
y_min::Float64
33-
y_max::Float64
34-
z_min::Float64
35-
z_max::Float64
36-
BoundingBox() = new(0.0,0.0,0.0,0.0,0.0,0.0)
37-
BoundingBox(x_min,x_max,y_min,y_max,z_min,z_max) = new(x_min,x_max,y_min,y_max,z_min,z_max)
33+
x_min::Float64
34+
x_max::Float64
35+
y_min::Float64
36+
y_max::Float64
37+
z_min::Float64
38+
z_max::Float64
39+
BoundingBox() = new(0.0,0.0,0.0,0.0,0.0,0.0)
40+
BoundingBox(x_min,x_max,y_min,y_max,z_min,z_max) = new(x_min,x_max,y_min,y_max,z_min,z_max)
3841
end
3942

4043

@@ -44,17 +47,17 @@ linearMovement(delta_x, tStart, tEnd, time) = delta_x*(time-tStart)/(tEnd-tStart
4447

4548
# Trailing part of type name
4649
function trailingPartOfTypeAsString(obj)::String
47-
name = string( typeof(obj) )
50+
name = string( typeof(obj) )
4851

49-
# Determine trailing solid (after last ".")
50-
i = first(something(findlast(".", name), 0:-1))
51-
return i > 0 && i < length(name) ? name[i+1:end] : name
52+
# Determine trailing solid (after last ".")
53+
i = first(something(findlast(".", name), 0:-1))
54+
return i > 0 && i < length(name) ? name[i+1:end] : name
5255
end
5356

5457
function trailingPartOfName(name::AbstractString)::String
55-
# Determine trailing part of name (after last ".")
56-
i = first(something(findlast(".", name), 0:-1))
57-
return i > 0 && i < length(name) ? name[i+1:end] : name
58+
# Determine trailing part of name (after last ".")
59+
i = first(something(findlast(".", name), 0:-1))
60+
return i > 0 && i < length(name) ? name[i+1:end] : name
5861
end
5962

6063

src/Composition/supportPoints.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
function supportPoint(obj::Composition.Object3D, e::SVector{3,Float64})
1+
function supportPoint(obj::Composition.Object3D, e::SVector{3,T}) where {T}
22
shapeKind = obj.shapeKind
33
solid::Modia3D.Solid = obj.feature
4-
collisionSmoothingRadius = solid.collisionSmoothingRadius
4+
collisionSmoothingRadius = T(solid.collisionSmoothingRadius)
5+
obj_r_abs = SVector{3, T}(obj.r_abs)
6+
obj_R_abs = SMatrix{3,3,T,9}(obj.R_abs)
57

68
if shapeKind == Modia3D.SphereKind
79
#sphere::Modia3D.Sphere = obj.shape
8-
return Modia3D.supportPoint_Sphere(obj.shape, obj.r_abs, obj.R_abs, e)
10+
return Modia3D.supportPoint_Sphere(obj.shape, obj_r_abs, obj_R_abs, e)
911
elseif shapeKind == Modia3D.EllipsoidKind
1012
#ellipsoid::Modia3D.Ellipsoid = obj.shape
11-
return Modia3D.supportPoint_Ellipsoid(obj.shape, obj.r_abs, obj.R_abs, e)
13+
return Modia3D.supportPoint_Ellipsoid(obj.shape, obj_r_abs, obj_R_abs, e)
1214
elseif shapeKind == Modia3D.BoxKind
1315
#box::Modia3D.Box = obj.shape
14-
return Modia3D.supportPoint_Box(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
16+
return Modia3D.supportPoint_Box(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
1517
elseif shapeKind == Modia3D.CylinderKind
1618
#cylinder::Modia3D.Cylinder = obj.shape
17-
return Modia3D.supportPoint_Cylinder(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
19+
return Modia3D.supportPoint_Cylinder(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
1820
elseif shapeKind == Modia3D.ConeKind
1921
#cone::Modia3D.Cone = obj.shape
20-
return Modia3D.supportPoint_Cone(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
22+
return Modia3D.supportPoint_Cone(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
2123
elseif shapeKind == Modia3D.CapsuleKind
2224
#capsule::Modia3D.Capsule = obj.shape
23-
return Modia3D.supportPoint_Capsule(obj.shape, obj.r_abs, obj.R_abs, e)
25+
return Modia3D.supportPoint_Capsule(obj.shape, obj_r_abs, obj_R_abs, e)
2426
elseif shapeKind == Modia3D.BeamKind
2527
#beam::Modia3D.Beam = obj.shape
26-
return Modia3D.supportPoint_Beam(obj.shape, obj.r_abs, obj.R_abs, e, collisionSmoothingRadius)
28+
return Modia3D.supportPoint_Beam(obj.shape, obj_r_abs, obj_R_abs, e, collisionSmoothingRadius)
2729
elseif shapeKind == Modia3D.FileMeshKind
2830
#fileMesh::Modia3D.FileMesh = obj.shape
29-
return Modia3D.supportPoint_FileMesh(obj.shape, obj.r_abs, obj.R_abs, e)
31+
return Modia3D.supportPoint_FileMesh(obj.shape, obj_r_abs, obj_R_abs, e)
3032
else
3133
error("not supported shape for support points")
3234
end

src/Modia3D.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ convertAndStripUnit(TargetType, requiredUnit, value) =
9494
numberType(value) <: Unitful.AbstractQuantity && unit.(value) != Unitful.NoUnits ?
9595
convert(TargetType, ustrip.( uconvert.(requiredUnit, value))) : convert(TargetType, value)
9696

97-
97+
# MPRFloatType is used to change betweeen Double64 and Float64 for mpr calculations
98+
const MPRFloatType = Float64
9899

99100
# Include sub-modules
100101
include(joinpath("Frames" , "_module.jl"))

0 commit comments

Comments
 (0)