Skip to content

Commit 9ecb661

Browse files
committed
introduce mprIterMax, default value = 120
1 parent a36390e commit 9ecb661

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/Composition/scene.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ struct SceneOptions{F <: Modia3D.VarFloatType}
239239
gap = 0.001,
240240
enableVisualization = true,
241241
animationFile = nothing,
242-
provideAnimationHistory = false,
242+
provideAnimationHistory = false,
243243
visualizeFrames = false,
244244
visualizeBoundingBox = false,
245245
visualizeContactPoints = false,
@@ -323,6 +323,7 @@ Defines global properties of the system, such as the gravity field. Exactly one
323323
| `elasticContactReductionFactor` | 1.0 (> 0.0, <= 1.0) |
324324
| `maximumContactDamping` | 2000.0 |
325325
| `mprTolerance` | 1.0e-20 |
326+
| `mprIterMax` | 120 |
326327
| `visualizeFrames` | false |
327328
| `visualizeBoundingBox` | false |
328329
| `visualizeContactPoints` | false |
@@ -364,6 +365,8 @@ Defines global properties of the system, such as the gravity field. Exactly one
364365
- `mprTolerance::1.0e-20`: Local tolerance used for terminating the mpr algorithm (that computes the distances between shapes). Changing this value might improve speed.
365366
For integrators with step-size control, a value is needed that is much smaller as the relative tolerance used for the integration.
366367
368+
- `mprIterMax::120`: Local maximum amount of iterations used for mpr algorithm. If more iterations are needed a message is printed.
369+
367370
- `visualizeFrames::Bool`: = true, to visualize the coordinate system of every [Object3D](@ref) that is not explicitly switched off.
368371
369372
- `visualizeBoundingBox::Bool`: Flag enabled for visualizing Axis Aligned Bounding Box (AABB) for all solid shapes allowed to collide
@@ -427,11 +430,11 @@ mutable struct Scene{F <: Modia3D.VarFloatType} <: Modia3D.AbstractScene
427430
AABB::Vector{Vector{Basics.BoundingBox{F}}} # Bounding boxes of elements that can collide
428431
zStartIndex::Int # start index of collision zero crossing functions
429432
forceElements::Vector{Modia3D.AbstractForceElement}
430-
provideAnimationData::Bool # = true, if animation data shall be provided
433+
provideAnimationData::Bool # = true, if animation data shall be provided
431434
exportAnimation::Bool # animation file export is enabled
432435
animation::Vector{animationStep} # animation data of visible Object3Ds
433436
outputCounter::Int64 # animation/visualization output step counter
434-
437+
435438
# Data specific to a particular joint type
436439
revolute::Vector{Revolute{F}}
437440
prismatic::Vector{Prismatic{F}}
@@ -442,6 +445,7 @@ mutable struct Scene{F <: Modia3D.VarFloatType} <: Modia3D.AbstractScene
442445
useOptimizedStructure = true,
443446
enableContactDetection = true,
444447
mprTolerance = 1.0e-20,
448+
mprIterMax = 120,
445449
elasticContactReductionFactor = F(1.0),
446450
maximumContactDamping = F(2000),
447451
gap = 0.001,
@@ -465,7 +469,7 @@ mutable struct Scene{F <: Modia3D.VarFloatType} <: Modia3D.AbstractScene
465469

466470
sceneOptions = SceneOptions{F}(gravityField = gravityField,
467471
useOptimizedStructure = useOptimizedStructure,
468-
contactDetection = ContactDetectionMPR_handler{Modia3D.MPRFloatType, F}(tol_rel = mprTolerance),
472+
contactDetection = ContactDetectionMPR_handler{Modia3D.MPRFloatType, F}(tol_rel = mprTolerance, niter_max = mprIterMax),
469473
nVisualContSupPoints = nVisualContSupPoints,
470474
gap = gap,
471475
enableContactDetection = enableContactDetection,
@@ -476,7 +480,7 @@ mutable struct Scene{F <: Modia3D.VarFloatType} <: Modia3D.AbstractScene
476480
defaultFrameLength = defaultFrameLength,
477481
enableVisualization = enableVisualization,
478482
animationFile = animationFile,
479-
provideAnimationHistory = provideAnimationHistory,
483+
provideAnimationHistory = provideAnimationHistory,
480484
visualizeFrames = visualizeFrames,
481485
visualizeBoundingBox = visualizeBoundingBox,
482486
visualizeContactPoints = visualizeContactPoints,
@@ -524,7 +528,7 @@ mutable struct Scene{F <: Modia3D.VarFloatType} <: Modia3D.AbstractScene
524528
Vector{Vector{Basics.BoundingBox{F}}}[],
525529
1,
526530
Vector{Modia3D.AbstractForceElement}[],
527-
provideAnimationData,
531+
provideAnimationData,
528532
exportAnimation,
529533
Vector{animationStep}[],
530534
0,

src/contactDetection/ContactDetectionMPR/ContactDetectionMPR_handler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ mutable struct ContactDetectionMPR_handler{T,F} <: Modia3D.AbstractContactDetect
106106
defaultContactSphereDiameter::Float64
107107

108108
function ContactDetectionMPR_handler{T,F}(;tol_rel = 1.0e-20,
109-
niter_max = 100) where {T,F}
109+
niter_max = 120) where {T,F}
110110
@assert(tol_rel > 0.0)
111111
@assert(niter_max > 0)
112112
contact_eps = F(max(1e-13, 10*tol_rel))

src/contactDetection/ContactDetectionMPR/mpr.jl

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,15 @@ function phase3(r0::SupportPoint, r1::SupportPoint, r2::SupportPoint, r3::Suppor
321321
end
322322
end
323323
end
324-
if niter_max < 100
325-
@warn("MPR (phase 3): Numerical issues with distance computation between $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)). Max. number of iterations (= $niter_max) is reached. niter_max increased locally by 10 and phase 3 is rerun.")
326-
phase3(r0, r1org, r2org, r3org, niter_max + 10, tol_rel, shapeA, shapeB, scale)
327-
else
328-
@warn("MPR (phase 3): Max. number of iterations (= $niter_max) is reached and $niter_max > 100, look at $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)). tol_rel increased locally for this computation to $new_tol.")
329-
if isTC2
330-
(distance,r1,r2,r3,r4) = finalTC2(r1_new,r2_new,r3_new,r4_new)
331-
return distance, r1, r2, r3, r4
332-
end
333-
if isTC3
334-
(distance,r1,r2,r3,r4) = finalTC3(r0, r1_new, r2_new, r3_new, r4_new)
335-
return distance, r1, r2, r3, r4
336-
end
324+
@warn("MPR (phase 3): Max. number of iterations (mprIterMax = $niter_max) is reached. Please, increase mprIterMax. tol_rel increased locally for this computation to $new_tol. Look at shapes $(Modia3D.fullName(shapeA)) and $(Modia3D.fullName(shapeB)).")
325+
if isTC2
326+
(distance,r1,r2,r3,r4) = finalTC2(r1_new,r2_new,r3_new,r4_new)
327+
return distance, r1, r2, r3, r4
328+
end
329+
if isTC3
330+
(distance,r1,r2,r3,r4) = finalTC3(r0, r1_new, r2_new, r3_new, r4_new)
331+
return distance, r1, r2, r3, r4
337332
end
338-
@error("passiert das?!?!?")
339333
return distance, r1, r2, r3, r4 # needed for a unique return type
340334
end
341335

test/Collision/BouncingEllipsoidOnSphere.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BouncingEllipsoid = Model3D(
66
boxHeigth = 0.1,
77
gravField = UniformGravityField(g=9.81, n=[0, -1, 0]),
88
world = Object3D(feature=Scene(gravityField=:gravField,
9-
mprTolerance=1.0e-19,
9+
mprTolerance=1.0e-20,
1010
defaultFrameLength=0.2,
1111
enableContactDetection=true)),
1212
worldFrame = Object3D(parent=:world, feature=Visual(shape=CoordinateSystem(length=0.5))),

0 commit comments

Comments
 (0)