From bf889922cb214a93eb7f382522b2134f0aa9441c Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 29 Nov 2011 13:24:11 -0500 Subject: [PATCH] Added check for particle undergoing too many events. --- src/constants.f90 | 3 +++ src/physics.f90 | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/constants.f90 b/src/constants.f90 index a1ee88cf89..9e63c6c40b 100644 --- a/src/constants.f90 +++ b/src/constants.f90 @@ -73,6 +73,9 @@ module constants ! Used for surface current tallies real(8), parameter :: TINY_BIT = 1e-8 + ! Maximum number of collisions/crossings + integer, parameter :: MAX_EVENTS = 10000 + ! Codes for read errors -- better hope these numbers are never used in an ! input file! integer, parameter :: ERROR_INT = -huge(0) diff --git a/src/physics.f90 b/src/physics.f90 index 7e9fed018e..9ce663ed85 100644 --- a/src/physics.f90 +++ b/src/physics.f90 @@ -31,6 +31,7 @@ contains integer :: surf ! surface which particle is on integer :: last_cell ! most recent cell particle was in + integer :: n_event ! number of collisions/crossings real(8) :: d_to_boundary ! distance to nearest boundary real(8) :: d_to_collision ! sampled distance to collision real(8) :: distance ! distance particle travels @@ -63,6 +64,9 @@ contains call write_message() end if + ! Initialize number of events to zero + n_event = 0 + ! find energy index, interpolation factor do while (p % alive) @@ -100,7 +104,16 @@ contains ! Save coordinates at collision for tallying purposes p % last_xyz = p % xyz end if - + + ! If particle has too many events, display warning and kill it + n_event = n_event + 1 + if (n_event == MAX_EVENTS) then + message = "Particle " // trim(int_to_str(p%id)) // " underwent " & + // "maximum number of events." + call warning() + p % alive = .false. + end if + end do end subroutine transport