From 4acdb9936de2612e49f8448f0a2999a67c9ad2a8 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 3 Jan 2025 17:17:00 +0100 Subject: [PATCH] Add max iteration criterion for while loop (default 1000). Added since neutrons would very rarely get stuck, leading to simulation hang. --- mcstas-comps/contrib/Vertical_Bender.comp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mcstas-comps/contrib/Vertical_Bender.comp b/mcstas-comps/contrib/Vertical_Bender.comp index 55060bc27..230db4494 100644 --- a/mcstas-comps/contrib/Vertical_Bender.comp +++ b/mcstas-comps/contrib/Vertical_Bender.comp @@ -92,7 +92,8 @@ SETTING PARAMETERS ( vector rBottomPar={0.99, 0.219, 6.07, 0.0, 0.003}, vector rSidesPar={0.99, 0.219, 6.07, 0.0, 0.003}, xwidth, yheight, length, radius, G=9.8, int nchan=1, d=0.0, - int debug=0, int endFlat=0, int drawOption=1, int alwaystrack=0, diststep1=0.020, diststep2=0.002 + int debug=0, int endFlat=0, int drawOption=1, int alwaystrack=0, diststep1=0.020, diststep2=0.002, + int recurse_max=1000 ) /* Neutron parameters : (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */ @@ -312,9 +313,10 @@ TRACE Rbottom = absR - hhalf; } - + + int counter=0; for(;;) { - + counter++; double tLeft, tRight, tTop, tBot, tIn, tOut, tMirror; double tUp, tSide, time, endtime; double R, Q; @@ -481,6 +483,11 @@ TRACE ABSORB; break; } + if (counter>recurse_max) { + // Neutron is dead. Kill it! + ABSORB; + break; + } }