LCOV - code coverage report
Current view: top level - include - run_fullmonte.h (source / functions) Hit Total Coverage
Test: code_coverage_filter.info Lines: 14 18 77.8 %
Date: 2024-03-28 16:04:17 Functions: 1 4 25.0 %
Branches: 11 24 45.8 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * @author: Abed Yassine
       3                 :            :  * @date: September 26th, 2019
       4                 :            :  * @brief: A wrapper class to run a fullmonte kernel (since most of the options are constant)
       5                 :            :  */
       6                 :            : 
       7                 :            : #ifndef _RUN_FULL_MONTE_H
       8                 :            : #define _RUN_FULL_MONTE_H
       9                 :            : 
      10                 :            : /* FullMonte Includes */
      11                 :            : 
      12                 :            : #include <FullMonteSW/Config.h> 
      13                 :            : #include "pdt_space_config.h"
      14                 :            : 
      15                 :            : // Geometry Includes
      16                 :            : #include <FullMonteSW/Geometry/Sources/Ball.hpp>
      17                 :            : #include <FullMonteSW/Geometry/Sources/Line.hpp>
      18                 :            : #include <FullMonteSW/Geometry/Sources/Volume.hpp>
      19                 :            : #include <FullMonteSW/Geometry/Sources/Composite.hpp>
      20                 :            : #include <FullMonteSW/Geometry/Sources/Fiber.hpp>
      21                 :            : #include <FullMonteSW/Geometry/Sources/Point.hpp>
      22                 :            : #include <FullMonteSW/Geometry/Sources/PencilBeam.hpp>
      23                 :            : #include <FullMonteSW/Geometry/Sources/Cylinder.hpp>
      24                 :            : #include <FullMonteSW/Geometry/Sources/CylDetector.hpp>
      25                 :            : #include <FullMonteSW/Geometry/Sources/TetraFace.hpp>
      26                 :            : #include <FullMonteSW/Geometry/Predicates/VolumeCellInRegionPredicate.hpp>
      27                 :            : #include <FullMonteSW/Geometry/Queries/TetraEnclosingPointByLinearSearch.hpp>
      28                 :            : #include <FullMonteSW/Geometry/MaterialSet.hpp>
      29                 :            : #include <FullMonteSW/Geometry/Material.hpp>
      30                 :            : 
      31                 :            : // Kernel Includes
      32                 :            : #if USE_CUDA
      33                 :            : #include <FullMonteSW/Kernels/CUDA/TetraCUDAVolumeKernel.hpp>
      34                 :            : #include <FullMonteSW/Kernels/CUDA/TetraCUDASurfaceKernel.hpp>
      35                 :            : #include <FullMonteSW/Kernels/CUDA/TetraCUDAInternalKernel.hpp>
      36                 :            : #endif
      37                 :            : #include <FullMonteSW/Kernels/Software/TetraVolumeKernel.hpp>
      38                 :            : #include <FullMonteSW/Kernels/Software/TetraSurfaceKernel.hpp>
      39                 :            : #include <FullMonteSW/Kernels/Software/TetraInternalKernel.hpp>
      40                 :            : #include <FullMonteSW/Kernels/SeedSweep.hpp>
      41                 :            : 
      42                 :            : // Data types includes
      43                 :            : #include <FullMonteSW/OutputTypes/OutputDataCollection.hpp>
      44                 :            : #include <FullMonteSW/OutputTypes/SpatialMap2D.hpp>
      45                 :            : 
      46                 :            : // Queries Includes
      47                 :            : #include <FullMonteSW/Queries/BasicStats.hpp>
      48                 :            : #include <FullMonteSW/Queries/EnergyToFluence.hpp>
      49                 :            : #include <FullMonteSW/Queries/EventCountComparison.hpp>
      50                 :            : 
      51                 :            : // Storage Includes
      52                 :            : #include <FullMonteSW/Storage/TIMOS/TIMOSMeshReader.hpp>
      53                 :            : #include <FullMonteSW/Storage/TIMOS/TIMOSMaterialReader.hpp>
      54                 :            : #include <FullMonteSW/Storage/TIMOS/TIMOSMeshWriter.hpp>
      55                 :            : #include <FullMonteSW/Storage/VTK/VTKMeshReader.hpp>
      56                 :            : #include <FullMonteSW/Storage/VTK/VTKMeshWriter.hpp>
      57                 :            : #include <FullMonteSW/Storage/VTK/VTKSurfaceWriter.hpp>
      58                 :            : #include <FullMonteSW/Storage/TextFile/TextFileMatrixWriter.hpp>
      59                 :            : 
      60                 :            : class Parser;
      61                 :            : 
      62                 :            : class WrapperFullMonteSW
      63                 :            : {
      64                 :            : public:
      65                 :            :     WrapperFullMonteSW(); 
      66                 :            :     WrapperFullMonteSW(string mesh_file, Parser* fparser, bool read_vtk, bool use_cuda);
      67                 :            : 
      68                 :         31 :     ~WrapperFullMonteSW() 
      69                 :         31 :     {
      70         [ +  - ]:         31 :         if (_mesh) {
      71         [ +  - ]:         31 :             delete _mesh; 
      72                 :            :         }
      73                 :            : 
      74         [ -  + ]:         31 :         if (_mesh_writer) {
      75         [ #  # ]:          0 :            delete _mesh_writer;
      76                 :            :         }
      77                 :            : 
      78         [ +  - ]:         31 :         if (_materials) {
      79         [ +  - ]:         31 :             delete _materials; 
      80                 :            :         }
      81                 :            :         
      82         [ +  - ]:         31 :         if (_kernel) {
      83         [ +  - ]:         31 :             delete _kernel;
      84                 :            :         }
      85                 :            : #if USE_CUDA
      86                 :            :         if (_kernel_cuda) {
      87                 :            :             delete _kernel_cuda;
      88                 :            :         }
      89                 :            : #endif
      90                 :            : 
      91         [ +  - ]:         31 :         if (_tetraCache) {
      92         [ +  - ]:         31 :             delete _tetraCache;
      93                 :            :         }
      94                 :            : 
      95         [ +  - ]:         31 :         if (_enclosing) {
      96         [ +  - ]:         31 :             delete _enclosing;
      97                 :            :         }
      98                 :         31 :     }
      99                 :            : 
     100                 :            :     // run fullmonte helper functions
     101                 :            :     void start_fullmonte_async(const Source::Abstract* source, long long unsigned num_packets);
     102                 :            :     OutputDataCollection* get_fm_result();
     103                 :            : #if USE_CUDA
     104                 :            :     void start_fullmonte_async_cuda(const Source::Abstract* source, long long unsigned num_packets);
     105                 :            :     OutputDataCollection* get_fm_result_cuda();
     106                 :            : #endif
     107                 :            : 
     108                 :            :     void run_composite_fullmonte(const vector<Source::Abstract*>& sources, 
     109                 :            :                             vector<float>& fluence, bool dump_data_to_file, std::string file_name = "", 
     110                 :            :                             long long unsigned num_packets = 1000000);
     111                 :            :     void run_multiple_fullmonte(const vector<Source::Abstract*>& sources, 
     112                 :            :                         vector<vector<float>> & fluence_matrix, 
     113                 :            :                         bool dump_data_to_file, std::string file_name = "", 
     114                 :            :                         long long unsigned num_packets = 1000000);
     115                 :            : 
     116                 :            :     void run_multiple_fullmonte_with_detectors(const vector<Source::Abstract*> & sources, 
     117                 :            :                 std::vector<std::vector<float>> & detected_weights, 
     118                 :            :                 float detected_radius, float detector_na, long long unsigned num_packets = 1000000);
     119                 :            :     
     120                 :            :     void write_mesh(string file_name);
     121                 :            :     
     122                 :            :     unsigned get_tetra_enclosing_point(float xcoord, float ycoord, float zcoord); 
     123                 :            : 
     124                 :          0 :     void update_kernel_materials(MaterialSet* new_ms) { _kernel->materials(new_ms); }
     125                 :            : 
     126                 :            :     void create_material_set(); // read materials from file parser and update kernel material set
     127                 :            :     void read_parameters();
     128                 :            : 
     129                 :            :     WrapperFullMonteSW* clone() const;
     130                 :            : 
     131                 :          0 :     TetraMesh*          get_tetra_mesh() { return _mesh; }
     132                 :          0 :     MaterialSet*        get_material_set() { return _materials; }
     133                 :            : 
     134                 :            : private: 
     135                 :            :     TetraMesh*          _mesh;
     136                 :            :     MaterialSet*        _materials = nullptr; 
     137                 :            : 
     138                 :            :     // FullMonte parameters
     139                 :            :     float               _roulette_pr_win;
     140                 :            :     float               _roulette_w_min;
     141                 :            :     unsigned            _max_steps;
     142                 :            :     unsigned            _max_hits;
     143                 :            :     unsigned            _rand_seed;
     144                 :            :     
     145                 :            :     EnergyToFluence     _EVF;
     146                 :            :     VTKMeshWriter*      _mesh_writer;
     147                 :            : 
     148                 :            :     TetraVolumeKernel*  _kernel; 
     149                 :            : #if USE_CUDA
     150                 :            :     TetraCUDAVolumeKernel*  _kernel_cuda; 
     151                 :            : #endif
     152                 :            : 
     153                 :            :     string              _mesh_file;
     154                 :            :     Parser*             _fparser;
     155                 :            :     bool                _read_vtk;
     156                 :            : 
     157                 :            :     bool                _use_cuda;
     158                 :            : 
     159                 :            :     // This used for find enclosing tetra of a point 
     160                 :            :     TetraLookupCache*   _tetraCache = nullptr;
     161                 :            :     TetraEnclosingPointByLinearSearch*  _enclosing = nullptr;
     162                 :            : };
     163                 :            : #endif

Generated by: LCOV version 1.12