GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSEMProcess.cc
Go to the documentation of this file.
1 // ************************************************************************
2 // * This file is part of GGEMS. *
3 // * *
4 // * GGEMS is free software: you can redistribute it and/or modify *
5 // * it under the terms of the GNU General Public License as published by *
6 // * the Free Software Foundation, either version 3 of the License, or *
7 // * (at your option) any later version. *
8 // * *
9 // * GGEMS is distributed in the hope that it will be useful, *
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 // * GNU General Public License for more details. *
13 // * *
14 // * You should have received a copy of the GNU General Public License *
15 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
16 // * *
17 // ************************************************************************
18 
33 
37 
39 : process_id_(0),
40  process_name_(""),
41  primary_particle_(""),
42  secondary_particle_(""),
43  is_secondaries_(false)
44 {
45  GGcout("GGEMSEMProcess", "GGEMSEMProcess", 3) << "GGEMSEMProcess creating..." << GGendl;
46 
47  GGcout("GGEMSEMProcess", "GGEMSEMProcess", 3) << "GGEMSEMProcess created!!!" << GGendl;
48 }
49 
53 
55 {
56  GGcout("GGEMSEMProcess", "~GGEMSEMProcess", 3) << "GGEMSEMProcess erasing..." << GGendl;
57 
58  GGcout("GGEMSEMProcess", "~GGEMSEMProcess", 3) << "GGEMSEMProcess erased!!!" << GGendl;
59 }
60 
64 
65 void GGEMSEMProcess::BuildCrossSectionTables(cl::Buffer* particle_cross_sections, cl::Buffer* material_tables, GGsize const& thread_index)
66 {
67  // Getting OpenCL manager
69  GGsize device_index = opencl_manager.GetIndexOfActivatedDevice(thread_index);
70 
71  GGcout("GGEMSEMProcess", "BuildCrossSectionTables", 3) << "Building cross section table for process " << process_name_ << " on device: " << opencl_manager.GetDeviceName(device_index) << GGendl;
72 
73  // Set missing information in cross section table
74  GGEMSParticleCrossSections* cross_section_device = opencl_manager.GetDeviceBuffer<GGEMSParticleCrossSections>(particle_cross_sections, sizeof(GGEMSParticleCrossSections), thread_index);
75 
76  // Store index of activated process
77  cross_section_device->photon_cs_id_[cross_section_device->number_of_activated_photon_processes_] = process_id_;
78 
79  // Increment number of activated photon process
80  cross_section_device->number_of_activated_photon_processes_ += 1;
81 
82  // Get the material tables
83  GGEMSMaterialTables* materials_device = opencl_manager.GetDeviceBuffer<GGEMSMaterialTables>(material_tables, sizeof(GGEMSMaterialTables), thread_index);
84 
85  // Compute Compton cross section par material
86  GGsize number_of_bins = cross_section_device->number_of_bins_;
87  // Loop over the materials
88  for (GGsize j = 0; j < materials_device->number_of_materials_; ++j) {
89  // Loop over the number of bins
90  for (GGsize i = 0; i < number_of_bins; ++i) {
91  cross_section_device->photon_cross_sections_[process_id_][i + j*number_of_bins] = ComputeCrossSectionPerMaterial(cross_section_device, materials_device, j, i);
92  }
93  }
94 
95  // If flag activate print tables
97  if (process_manager.IsPrintPhysicTables()) {
98  GGcout("GGEMSEMProcess", "BuildCrossSectionTables", 0) << "* PROCESS " << process_name_ << " on device: " << opencl_manager.GetDeviceName(device_index) << GGendl;
99 
100  // Loop over material
101  for (GGsize j = 0; j < materials_device->number_of_materials_; ++j) {
102  GGsize id_elt = materials_device->index_of_chemical_elements_[j];
103  GGcout("GGEMSEMProcess", "BuildCrossSectionTables", 0) << " - Material: " << cross_section_device->material_names_[j]
104  << ", density: " << materials_device->density_of_material_[j]/(g/cm3) << " g.cm-3" << GGendl;
105  // Loop over number of bins (energy)
106  for (GGsize i = 0; i < number_of_bins; ++i) {
107  GGcout("GGEMSEMProcess", "BuildCrossSectionTables", 0) << " + Energy: " << cross_section_device->energy_bins_[i]/keV << " keV, cross section: "
108  << (cross_section_device->photon_cross_sections_[process_id_][i + j*number_of_bins]/materials_device->density_of_material_[j])/(cm2/g) << " cm2.g-1" << GGendl;
109  // Loop over elements
110  for (GGsize k = 0; k < materials_device->number_of_chemical_elements_[j]; ++k) {
111  GGuchar atomic_number = materials_device->atomic_number_Z_[k+id_elt];
112  GGcout("GGEMSEMProcess", "BuildCrossSectionTables", 0) << " # Element (Z): " << atomic_number
113  << ", atomic number density: " << materials_device->atomic_number_density_[k+id_elt]/(1/cm3) << " atom/cm3, cross section per atom: "
114  << cross_section_device->photon_cross_sections_per_atom_[process_id_][i + atomic_number*number_of_bins]/(cm2)<< " cm2" << GGendl;
115  }
116  }
117  }
118  }
119 
120  // Release pointer
121  opencl_manager.ReleaseDeviceBuffer(material_tables, materials_device, thread_index);
122  opencl_manager.ReleaseDeviceBuffer(particle_cross_sections, cross_section_device, thread_index);
123 }
124 
128 
129 GGfloat GGEMSEMProcess::ComputeCrossSectionPerMaterial(GGEMSParticleCrossSections* cross_section_device, GGEMSMaterialTables const* material_tables, GGsize const& material_index, GGsize const& energy_index)
130 {
131  GGfloat energy = cross_section_device->energy_bins_[energy_index];
132  GGfloat cross_section_material = 0.0f;
133  GGsize index_of_offset = material_tables->index_of_chemical_elements_[material_index];
134 
135  // Loop over all the chemical elements
136  for (GGsize i = 0; i < material_tables->number_of_chemical_elements_[material_index]; ++i) {
137  GGuchar atomic_number = material_tables->atomic_number_Z_[i+index_of_offset];
138  GGfloat cross_section_per_atom = ComputeCrossSectionPerAtom(energy, atomic_number);
139  cross_section_device->photon_cross_sections_per_atom_[process_id_][energy_index + atomic_number*cross_section_device->number_of_bins_] = cross_section_per_atom;
140  cross_section_material += material_tables->atomic_number_density_[i+index_of_offset] * cross_section_per_atom;
141  }
142  return cross_section_material;
143 }
GGEMSParticleCrossSections_t::number_of_bins_
GGsize number_of_bins_
Definition: GGEMSParticleCrossSections.hh:43
GGEMSParticleCrossSections_t::number_of_activated_photon_processes_
GGsize number_of_activated_photon_processes_
Definition: GGEMSParticleCrossSections.hh:54
GGEMSMaterialTables_t::density_of_material_
GGfloat density_of_material_[255]
Definition: GGEMSMaterialTables.hh:49
GGEMSParticleCrossSections
struct GGEMSParticleCrossSections_t GGEMSParticleCrossSections
GGEMSEMProcess::~GGEMSEMProcess
virtual ~GGEMSEMProcess(void)
GGEMSEMProcess destructor.
Definition: GGEMSEMProcess.cc:54
GGEMSParticleCrossSections_t::energy_bins_
GGfloat energy_bins_[MAX_CROSS_SECTION_TABLE_NUMBER_BINS]
Definition: GGEMSParticleCrossSections.hh:47
GGEMSMaterialTables_t::atomic_number_density_
GGfloat atomic_number_density_[255 *32]
Definition: GGEMSMaterialTables.hh:75
GGEMSEMProcess::BuildCrossSectionTables
virtual void BuildCrossSectionTables(cl::Buffer *particle_cross_sections, cl::Buffer *material_tables, GGsize const &thread_index)
build cross section tables and storing them in particle_cross_sections
Definition: GGEMSEMProcess.cc:65
GGEMSParticleCrossSections_t
Structure storing the photon cross sections for OpenCL device.
Definition: GGEMSParticleCrossSections.hh:41
GGEMSProcessesManager.hh
GGEMS class managing the processes in GGEMS simulation.
GGEMSEMProcess::process_name_
std::string process_name_
Definition: GGEMSEMProcess.hh:126
GGEMSMaterialTables_t::atomic_number_Z_
GGuchar atomic_number_Z_[255 *32]
Definition: GGEMSMaterialTables.hh:74
GGEMSParticleCrossSections_t::photon_cross_sections_
GGfloat photon_cross_sections_[NUMBER_PHOTON_PROCESSES][256 *MAX_CROSS_SECTION_TABLE_NUMBER_BINS]
Definition: GGEMSParticleCrossSections.hh:52
GGEMSOpenCLManager::ReleaseDeviceBuffer
void ReleaseDeviceBuffer(cl::Buffer *const device_ptr, T *host_ptr, GGsize const &thread_index)
Get the device pointer on host to write on it. Mandatory after a GetDeviceBufferWrite ou GetDeviceBuf...
Definition: GGEMSOpenCLManager.hh:495
GGEMSMaterialTables_t::number_of_materials_
GGsize number_of_materials_
Definition: GGEMSMaterialTables.hh:44
GGEMSEMProcess.hh
GGEMS mother class for electromagnectic process.
GGsize
#define GGsize
Definition: GGEMSTypes.hh:252
GGEMSParticleCrossSections_t::photon_cs_id_
GGchar photon_cs_id_[NUMBER_PHOTON_PROCESSES]
Definition: GGEMSParticleCrossSections.hh:55
keV
__constant GGfloat keV
Definition: GGEMSSystemOfUnits.hh:102
cm3
__constant GGfloat cm3
Definition: GGEMSSystemOfUnits.hh:59
cm2
__constant GGfloat cm2
Definition: GGEMSSystemOfUnits.hh:58
GGEMSProcessesManager::IsPrintPhysicTables
bool IsPrintPhysicTables(void) const
check boolean value for physic tables printing
Definition: GGEMSProcessesManager.hh:171
GGEMSMaterialTables_t::number_of_chemical_elements_
GGsize number_of_chemical_elements_[255]
Definition: GGEMSMaterialTables.hh:48
GGEMSMaterialTables_t::index_of_chemical_elements_
GGsize index_of_chemical_elements_[255]
Definition: GGEMSMaterialTables.hh:73
GGcout
GGEMSStream GGcout
Definition: GGEMSPrint.cc:34
GGEMSEMProcess::GGEMSEMProcess
GGEMSEMProcess(void)
GGEMSEMProcess constructor.
Definition: GGEMSEMProcess.cc:38
GGEMSMaterialTables_t
Structure storing the material tables on OpenCL device.
Definition: GGEMSMaterialTables.hh:42
GGEMSEMProcess::ComputeCrossSectionPerAtom
virtual GGfloat ComputeCrossSectionPerAtom(GGfloat const &energy, GGuchar const &atomic_number) const =0
compute a cross section for an atom
GGEMSProcessesManager
GGEMS class managing the processes in GGEMS simulation.
Definition: GGEMSProcessesManager.hh:42
g
__constant GGfloat g
Definition: GGEMSSystemOfUnits.hh:111
GGEMSOpenCLManager::GetDeviceBuffer
T * GetDeviceBuffer(cl::Buffer *device_ptr, GGsize const &size, GGsize const &thread_index)
Get the device pointer on host to write on it. ReleaseDeviceBuffer must be used after this method!...
Definition: GGEMSOpenCLManager.hh:480
GGEMSEMProcess::process_id_
GGchar process_id_
Definition: GGEMSEMProcess.hh:125
GGEMSMaterialTables
struct GGEMSMaterialTables_t GGEMSMaterialTables
GGendl
#define GGendl
overload C++ std::endl
Definition: GGEMSPrint.hh:60
GGEMSEMProcess::ComputeCrossSectionPerMaterial
GGfloat ComputeCrossSectionPerMaterial(GGEMSParticleCrossSections *cross_section, GGEMSMaterialTables const *material_tables, GGsize const &material_index, GGsize const &energy_index)
compute cross section for a process for a material
Definition: GGEMSEMProcess.cc:129
GGEMSParticleCrossSections_t::photon_cross_sections_per_atom_
GGfloat photon_cross_sections_per_atom_[NUMBER_PHOTON_PROCESSES][101 *MAX_CROSS_SECTION_TABLE_NUMBER_BINS]
Definition: GGEMSParticleCrossSections.hh:53
GGEMSParticleCrossSections_t::material_names_
GGchar material_names_[256][64]
Definition: GGEMSParticleCrossSections.hh:57
GGEMSOpenCLManager
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
Definition: GGEMSOpenCLManager.hh:54
GGuchar
#define GGuchar
Definition: GGEMSTypes.hh:203
GGEMSOpenCLManager::GetDeviceName
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
Definition: GGEMSOpenCLManager.hh:145
GGEMSOpenCLManager::GetIndexOfActivatedDevice
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
Definition: GGEMSOpenCLManager.hh:175
GGEMSProcessesManager::GetInstance
static GGEMSProcessesManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSProcessesManager.hh:60
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273
GGEMSOpenCLManager::GetInstance
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSOpenCLManager.hh:72