Skip to content

Commit

Permalink
Added more docstrings to detectors. Update python setup in CI. update…
Browse files Browse the repository at this point in the history
…d todos. Added ffpe-trap to @testdebug
  • Loading branch information
lewisfish committed Oct 4, 2023
1 parent e320394 commit 495045a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
if: ${{ contains(matrix.os, 'ubuntu') && contains(matrix.toolchain.compiler, 'gcc') }}
uses: codecov/codecov-action@v3.1.1

- uses: actions/setup-python@v1
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: build docs
Expand Down
2 changes: 1 addition & 1 deletion fpm.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ option run sMCRT --compiler gfortran --flag "-fopenmp -O2 -march=native -flto -m
option test --compiler gfortran --flag "-O0 -fprofile-arcs -ftest-coverage --coverage"

@testdebug
option test --compiler gfortran --flag "-O0 -g -fbacktrace -fcheck=all"
option test --compiler gfortran --flag "-O0 -g -fbacktrace -fcheck=all -ffpe-trap=invalid,overflow,underflow,denormal"


@testintel
Expand Down
19 changes: 12 additions & 7 deletions old_docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ List of ToDo's for SignedMCRT.
- [ ] Add voxel geometry
- [ ] Add mesh geometry
- [ ] Improve performance of SDF intersection
- [ ] Implement KD trees in 2D
- [ ] Implement KD trees in 3D
- [ ] Make code serializable so that we can checkpoint simulations
- [ ] Save input toml file
- [ ] photons run
Expand Down Expand Up @@ -75,10 +73,17 @@ List of ToDo's for SignedMCRT.
- [x] Matrix class
- [x] Vec4 Class
- [ ] SDF Class
- [ ] Detector Class
- [ ] Circle
- [ ] Camera
- [ ] Annulus
- [x] Helpers
- [ ] Modifiers
- [ ] Base
- [x] Shapes
- [x] Detector Class
- [x] Circle
- [x] Camera
- [x] Annulus
- [x] Surfaces
- [x] Grid
- [x] Optical Properties
- [ ] Photon class
- [x] Uniform
- [x] Point
Expand All @@ -92,7 +97,7 @@ List of ToDo's for SignedMCRT.
- [ ] Photon movement code
- [ ] History Stack Class
- [ ] I/O
- [ ] Random Numbers
- [x] Random Numbers
- [x] Fresnel reflections
- [x] Simple reflect
- [x] Simple refract
Expand Down
44 changes: 36 additions & 8 deletions src/detectors/detector_base.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ module detector_mod
use constants, only : wp

implicit none

!> Hit type, which records possible interaction information
type :: hit_t
type(vector) :: pos, dir
!> Poition of the interaction
type(vector) :: pos
!> Direction the photon came from
type(vector) :: dir
!> Value to deposit
real(kind=wp) :: value
!> Layer ID of interaction
integer :: layer
end type hit_t

Expand All @@ -17,10 +22,15 @@ module detector_mod
module procedure hit_init
end interface hit_t

!> abstract detector
type, abstract :: detector
! abstract detector
type(vector) :: pos, dir
!> position of the detector
type(vector) :: pos
!> Surface normal of the detector
type(vector) :: dir
!> Layer ID of the detector
integer :: layer
!> Boolean, if true store the history of the photon prior to detection.
logical :: trackHistory
contains
private
Expand Down Expand Up @@ -49,18 +59,30 @@ subroutine recordHitInterface(this, hitpoint, history)
type(history_stack_t), intent(inout) :: history
end subroutine recordHitInterface
end interface


!> 1D detector type. Records linear information
type, abstract, extends(detector) :: detector1D
!> Number of bins
integer :: nbins
!> Bin width
real(kind=wp) :: bin_wid
!> Bins
real(kind=wp), allocatable :: data(:)
contains
procedure :: record_hit => record_hit_1D_sub
end type detector1D


!> 2D detecctor type. Records spatial information
type, abstract, extends(detector) :: detector2D
integer :: nbinsX, nbinsY
real(kind=wp) :: bin_wid_x, bin_wid_y
!> Number of bins in x dimension (detector space)
integer :: nbinsX
!> Number of bins in y dimension (detector space)
integer :: nbinsY
!> Bin width in the x dimension
real(kind=wp) :: bin_wid_x
!> Bin width in the y dimension
real(kind=wp) :: bin_wid_y
!> Bins
real(kind=wp), allocatable :: data(:,:)
contains
procedure :: record_hit => record_hit_2D_sub
Expand All @@ -82,12 +104,15 @@ type(hit_t) function hit_init(val)
end function hit_init

subroutine record_hit_1D_sub(this, hitpoint, history)
!! check if a hit is on the detector and record it if so

use historyStack, only : history_stack_t
use sim_state_mod, only : state

class(detector1D), intent(inout) :: this
!> Interaction information
type(hit_t), intent(in) :: hitpoint
!> Photon packet history
type(history_stack_t), intent(inout) :: history

real(kind=wp) :: value
Expand All @@ -106,12 +131,15 @@ subroutine record_hit_1D_sub(this, hitpoint, history)
end subroutine record_hit_1D_sub

subroutine record_hit_2D_sub(this, hitpoint, history)
!! check if a hit is on the detector and record it if so

use historyStack, only : history_stack_t
use sim_state_mod, only : state

class(detector2D), intent(inout) :: this
!> Interaction information
type(hit_t), intent(in) :: hitpoint
!> Photon packet history
type(history_stack_t), intent(inout) :: history

real(kind=wp), volatile :: x, y
Expand Down
17 changes: 14 additions & 3 deletions src/detectors/detectors.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module detectors
end type circle_dect

interface circle_dect
!> Initialise circular detector
module procedure init_circle_dect
end interface circle_dect

Expand All @@ -32,6 +33,7 @@ module detectors
end type annulus_dect

interface annulus_dect
!> Initialise annuluar detector
module procedure init_annulus_dect
end interface annulus_dect

Expand Down Expand Up @@ -70,6 +72,7 @@ module detectors
contains

function init_circle_dect(pos, dir, layer, radius, nbins, maxval, trackHistory) result(out)
!! Initalise Circle detector
!> Centre of detector
type(vector), intent(in) :: pos
!> Normal of the detector
Expand Down Expand Up @@ -105,10 +108,12 @@ function init_circle_dect(pos, dir, layer, radius, nbins, maxval, trackHistory)
end function init_circle_dect

logical function check_hit_circle(this, hitpoint)
!! Check if a hitpoint is in the circle

use geometry, only : intersectCircle

class(circle_dect), intent(INOUT) :: this
!> Hitpoint to check
type(hit_t), intent(IN) :: hitpoint

real(kind=wp) :: t
Expand All @@ -122,6 +127,8 @@ logical function check_hit_circle(this, hitpoint)
end function check_hit_circle

function init_annulus_dect(pos, dir, layer, r1, r2, nbins, maxval, trackHistory) result(out)
!! Initalise Annular detector

!> Centre of detector
type(vector), intent(in) :: pos
!> Normal of the detector
Expand Down Expand Up @@ -160,8 +167,9 @@ function init_annulus_dect(pos, dir, layer, r1, r2, nbins, maxval, trackHistory)
end function init_annulus_dect

logical function check_hit_annulus(this, hitpoint)

!! Check if a hitpoint is in the annulus
class(annulus_dect), intent(INOUT) :: this
!> Hitpoint to check
type(hit_t), intent(IN) :: hitpoint

real(kind=wp) :: newpos
Expand All @@ -176,6 +184,8 @@ logical function check_hit_annulus(this, hitpoint)
end function check_hit_annulus

function init_camera(p1, p2, p3, layer, nbins, maxval, trackHistory) result(out)
!! Initalise Camera detector

!> Position of the 1st corner of the detector
type(vector), intent(in) :: p1
!> Distance from p1 to the 2nd corner
Expand Down Expand Up @@ -219,8 +229,10 @@ function init_camera(p1, p2, p3, layer, nbins, maxval, trackHistory) result(out)
end function init_camera

logical function check_hit_camera(this, hitpoint)
!! [ref](https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection)
!! Check if a hitpoint is in the camera detector
!! [ref](https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection)
class(camera), intent(inout) :: this
!> Hitpoint to check
type(hit_t), intent(in) :: hitpoint

real(kind=wp) :: t, proj1, proj2
Expand All @@ -239,5 +251,4 @@ logical function check_hit_camera(this, hitpoint)
end if
end if
end function check_hit_camera

end module detectors

0 comments on commit 495045a

Please sign in to comment.