Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_sampling.hpp
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#ifndef MCGIDI_sampling_hpp_included
11#define MCGIDI_sampling_hpp_included 1
12
13#include <LUPI_declareMacro.hpp>
14#include <MCGIDI_vector.hpp>
15#include <MCGIDI_string.hpp>
16
17namespace MCGIDI {
18
19/*
20============================================================
21======================= DomainHash =========================
22============================================================
23*/
25
26 private:
27 std::size_t m_bins; /**< The number of bins for the hash. */
28 double m_domainMin; /**< The minimum domain value for the hash. */
29 double m_domainMax; /**< The maximum domain value for the hash. */
30 double m_u_domainMin; /**< The log of m_domainMin ). */
31 double m_u_domainMax; /**< The log of m_domainMax ). */
32 double m_inverse_du; /**< The value *m_bins* / ( *m_u_domainMax* - *m_u_domainMin* ). */
33
34 public:
36 LUPI_HOST_DEVICE DomainHash( std::size_t a_bins, double a_domainMin, double a_domainMax );
37 LUPI_HOST_DEVICE DomainHash( DomainHash const &a_domainHash );
38
39 LUPI_HOST_DEVICE std::size_t bins( ) const { return( m_bins ); } /**< Returns the value of the **m_bins**. */
40 LUPI_HOST_DEVICE double domainMin( ) const { return( m_domainMin ); } /**< Returns the value of the **m_domainMax**. */
41 LUPI_HOST_DEVICE double domainMax( ) const { return( m_domainMax ); } /**< Returns the value of the **m_domainMax**. */
42 LUPI_HOST_DEVICE double u_domainMin( ) const { return( m_u_domainMin ); } /**< Returns the value of the **m_u_domainMin**. */
43 LUPI_HOST_DEVICE double u_domainMax( ) const { return( m_u_domainMax ); } /**< Returns the value of the **m_u_domainMax**. */
44 LUPI_HOST_DEVICE double inverse_du( ) const { return( m_inverse_du ); } /**< Returns the value of the **m_inverse_du**. */
45
46 LUPI_HOST_DEVICE std::size_t index( double a_domain ) const ;
47 LUPI_HOST_DEVICE Vector<std::size_t > map( Vector<double> const &a_domainValues ) const ;
48
50
51 LUPI_HOST void print( bool a_printValues ) const ;
52};
53
54namespace Sampling {
55
57class ProductHandler;
58
59LUPI_HOST_DEVICE std::size_t evaluationForHashIndex( std::size_t a_hashIndex, Vector<std::size_t> const &a_hashIndices, double a_energy,
60 Vector<double> const &a_energies, double *a_energyFraction );
61
62namespace Upscatter {
63
64 enum class Model { none, A, B, BSnLimits, DBRC };
65
66/*
67============================================================
68===================== ModelDBRC_data =======================
69============================================================
70*/
71
73
74 public:
75 double m_neutronMass; /**< The mass of the neutron. */
76 double m_targetMass; /**< The mass of the target. */
77 Vector<double> m_energies; /**< The energy grid for the cross section. */
78 Vector<double> m_crossSections; /**< The cross sections corresponding to the energy grid. */
79 Vector<std::size_t> m_hashIndices; /**< The indicies for the energy hash function. */
80 MCGIDI::DomainHash m_domainHash; /**< The hash "function". */
81
82 public:
84 LUPI_HOST ModelDBRC_data( double a_neutronMass, double a_targetMass, Vector<double> const &a_energies, Vector<double> const &a_crossSections,
85 DomainHash const &a_domainHash );
87
88 LUPI_HOST_DEVICE double evaluate( double a_energy );
89 LUPI_HOST_DEVICE double targetThermalSpeed( double a_temperature );
90 LUPI_HOST_DEVICE double crossSectionMax( double a_energy, double a_targetThermalSpeed );
91
93};
94
96
97} // End of namespace Upscatter.
98
99/*
100============================================================
101================ ClientRandomNumberGenerator ===============
102============================================================
103*/
105 private:
106 double (*m_generator)( void * ); /**< User supplied generator. */
107 void *m_state; /**< User supplied state. */
108
109 public:
110 LUPI_HOST_DEVICE ClientRandomNumberGenerator( double (*a_generator)( void * ), void *a_state );
111
112 LUPI_HOST_DEVICE double (*generator( ))( void * ) { return( m_generator ); }
113 LUPI_HOST_DEVICE void *state( ) { return( m_state ); }
114 LUPI_HOST_DEVICE double Double( ) { return( m_generator( m_state ) ); }
115
116// The following are deprecated.
117 LUPI_HOST_DEVICE double (*rng( ))( void * ) { return( generator( ) ); }
118 LUPI_HOST_DEVICE void *rngState( ) { return( state( ) ); }
119 LUPI_HOST_DEVICE double dRng( ) { return( Double( ) ); }
120};
121
122/*
123============================================================
124=================== Client Code RNG Data ===================
125============================================================
126*/
128
129 public:
130 LUPI_HOST_DEVICE ClientCodeRNGData( double (*a_generator)( void * ), void *a_state );
131};
132
133/*
134============================================================
135=========================== Input ==========================
136============================================================
137*/
138
139class Input {
140
141 friend ProtareSingle;
142 friend Reaction;
144 friend GRIN_capture;
145 friend GRIN_inelastic;
146
147 private:
148 bool m_wantVelocity = true ; /**< See member m_isVelocity in class Product for meaning. This is user input. */
149
150 bool m_dataInTargetFrame = false; /**< **True** if the data are in the target's frame and **false** otherwise. */
151 double m_modelTemperature = 0.0; /**< The temperature used when sampling product data. For example, in upscatter model A the projectile is boosted into a sampled target's frame and the modelled temperature is 0.0. */
152 double m_modelEnergy = 0.0; /**< The projectile energy used when sampling product data (see comment for member **m_modelTemperature**. */
153
154 SampledType m_sampledType = SampledType::uncorrelatedBody; /**< For internal use only. Set by distributions and used in the method **MCGIDI::Sampling::ProductHandler::add**. */
155
156 // The next 2 members are set by the user via the setTemperatureAndEnergy method.
157 double m_temperature = 0.0; /**< The temperature of the material. This member is set by the user. */
158 double m_energy = 0.0; /**< The energy of the projectile. This member is set by the user. */
159
160 public:
161
162 Upscatter::Model m_upscatterModel = Upscatter::Model::none; /**< The upscatter model to use when sampling a target's velocity. */
163
164
165 // The rest of the members are set by MCGIDI methods.
166 // These five are used for upscatter model A and the last 4 also used by model B.
167 double m_projectileBeta = 0.0; /**< The beta = speed / c of the projectile. */
168 double m_muLab = 0.0; /**< The cosine of the angle between the projectile's and the sampled target's velocities. */
169 double m_targetBeta = 0.0; /**< The beta = speed / c of the target. */
170 double m_relativeBeta = 0.0; /**< The beta = speed / c of the relative speed between the projectile and the target. */
171
172 Reaction const *m_reaction = nullptr; /**< The current reaction whose products are being sampled. */
173
174 double m_projectileMass = 0.0; /**< The mass of the projectile. */
175 double m_targetMass = 0.0; /**< The mass of the target. */
176
177 GIDI::Frame m_frame = GIDI::Frame::lab; /**< The frame the product data are returned in. */
178 int m_numberOfDBRC_rejections = 0; /**< For the DBRC upscattering model, this is the number of rejections + 1 per product sample. */
179
180 double m_mu = 0.0; /**< The sampled mu = cos( theta ) for the product. */
181 double m_phi = 0.0; /**< The sampled phi for the product. */
182
183 double m_energyOut1 = 0.0; /**< The sampled energy of the product. */
184 double m_px_vx1 = 0.0; /**< Variable used for two-body sampling. */
185 double m_py_vy1 = 0.0; /**< Variable used for two-body sampling. */
186 double m_pz_vz1 = 0.0; /**< Variable used for two-body sampling. */
187
188 double m_energyOut2 = 0.0; /**< The sampled energy of the second product for a two-body interaction. */
189 double m_px_vx2 = 0.0; /**< Variable used for two-body sampling. */
190 double m_py_vy2 = 0.0; /**< Variable used for two-body sampling. */
191 double m_pz_vz2 = 0.0; /**< Variable used for two-body sampling. */
192
193 int m_delayedNeutronIndex = -1; /**< If the product is a delayed neutron, this is its index. */
194 double m_delayedNeutronDecayRate = 0.0; /**< If the product is a delayed neutron, this is its decay rate. */
195
196 int m_GRIN_intermediateResidual = -1; /**< For special GRIN product sampling, this is the GNDS intid of the intermediate residual. */
197
198 LUPI_HOST_DEVICE Input( bool a_wantVelocity, Upscatter::Model a_upscatterModel );
199
200 LUPI_HOST_DEVICE bool wantVelocity( ) const { return( m_wantVelocity ); } /**< Returns the value of the *m_wantVelocity* member. */
201 LUPI_HOST_DEVICE double temperature( ) const { return( m_temperature ); } /**< Returns the value of the *m_temperature* member. */
202 LUPI_HOST_DEVICE double energy( ) const { return( m_energy ); } /**< Returns the value of the *m_energy* member. */
203 LUPI_HOST_DEVICE void setTemperatureAndEnergy( double a_temperature, double a_energy );
204
205 LUPI_HOST_DEVICE bool dataInTargetFrame( ) const { return( m_dataInTargetFrame ); } /**< Returns the value of the *m_dataInTargetFrame*. */
206 LUPI_HOST_DEVICE double modelTemperature( ) const { return( m_modelTemperature ); } /**< Returns the value of the *m_dataInTargetFrame* member. */
207 LUPI_HOST_DEVICE double modelEnergy( ) const { return( m_modelEnergy ); } /**< Returns the value of the *m_modelEnergy* member. */
208
209 SampledType sampledType( ) const { return( m_sampledType ); } /**< Returns the value of the *m_sampledType* member. */
210 LUPI_HOST_DEVICE void setSampledType( SampledType a_sampledType ) { m_sampledType = a_sampledType; } /**< Sets the member *m_sampledType* to *a_sampledType*. */
211};
212
213/*
214============================================================
215========================== Product =========================
216============================================================
217*/
218class Product {
219
220 public:
222 bool m_isVelocity; /**< If true, m_px_vx, m_py_vy and m_pz_vz are velocities otherwise momenta. */
223 int m_productIntid; /**< The intid of the sampled product. */
224 int m_productIndex; /**< The index of the sampled product. */
225 int m_userProductIndex; /**< The user particle index of the sampled product. */
226 int m_numberOfDBRC_rejections; /**< For the DBRC upscattering model, this is the number of rejections + 1 per product sample. */
227 double m_productMass; /**< The mass of the sampled product. */
228 double m_kineticEnergy; /**< The kinetic energy of the sampled product. */
229 double m_px_vx; /**< The velocity or momentum along the x-axis of the sampled product. */
230 double m_py_vy; /**< The velocity or momentum along the y-axis of the sampled product. */
231 double m_pz_vz; /**< The velocity or momentum along the z-axis of the sampled product. The z-axis is along the direction of the projectile's velolcity. */
232 int m_delayedNeutronIndex; /**< If the product is a delayed neutron, this is its index. */
233 double m_delayedNeutronDecayRate; /**< If the product is a delayed neutron, this is its decay rate. */
234 double m_birthTimeSec; /**< Some products, like delayed fission neutrons, are to appear (be born) later. This is the time in seconds that such a particle should be born since the interaction. */
235};
236
237/*
238============================================================
239====================== ProductHandler ======================
240============================================================
241*/
243
244 public:
247
248 template <typename RNG, typename PUSHBACK>
249 LUPI_HOST_DEVICE void add( double a_projectileEnergy, int a_productIntid, int a_productIndex, int a_userProductIndex, double a_productMass, Input &a_input,
250 RNG && a_rng, PUSHBACK && push_back, bool isPhoton );
251};
252
253/*
254============================================================
255================ StdVectorProductHandler ===================
256============================================================
257*/
258#ifdef __CUDACC__
259
260#define MCGIDI_CUDACC_numberOfProducts 1000
261
262class StdVectorProductHandler : public ProductHandler {
263
264 private:
265 std::size_t m_size;
266 Product m_products[1024];
267
268 public:
269 LUPI_HOST_DEVICE StdVectorProductHandler( ) : m_size( 0 ) { }
271
272 LUPI_HOST_DEVICE std::size_t size( ) { return( m_size ); }
273 LUPI_HOST_DEVICE Product &operator[]( long a_index ) { return( m_products[a_index] ); }
274 LUPI_HOST_DEVICE void push_back( Product &a_product ) {
275 if( m_size < MCGIDI_CUDACC_numberOfProducts ) {
276 m_products[m_size] = a_product;
277 ++m_size;
278 }
279 }
280 LUPI_HOST_DEVICE void clear( ) { m_size = 0; }
281};
282
283#else
285
286 private:
287 std::vector<Product> m_products; /**< The list of products sampled. */
288
289 public:
292
293 LUPI_HOST_DEVICE std::size_t size( ) { return( m_products.size( ) ); }
294 LUPI_HOST_DEVICE Product &operator[]( std::size_t a_index ) { return( m_products[a_index] ); }
295 LUPI_HOST_DEVICE std::vector<Product> &products( ) { return( m_products ); }
296 LUPI_HOST_DEVICE void push_back( Product &a_product ) { m_products.push_back( a_product ); }
297 LUPI_HOST_DEVICE void clear( ) { m_products.clear( ); }
298};
299#endif
300
301/*
302============================================================
303============== MCGIDIVectorProductHandler ==================
304============================================================
305*/
307
308 private:
309 Vector<Product> m_products; /**< The list of products sampled. */
310
311 public:
312 LUPI_HOST_DEVICE MCGIDIVectorProductHandler( std::size_t a_size = 20 ) :
313 m_products( ) {
314
315 m_products.reserve( a_size );
316 }
318
319 LUPI_HOST_DEVICE std::size_t size( ) { return( m_products.size( ) ); }
320 LUPI_HOST_DEVICE Product const &operator[]( std::size_t a_index ) const { return( m_products[a_index] ); }
321 LUPI_HOST_DEVICE Vector<Product> const &products( ) const { return( m_products ); }
322 LUPI_HOST_DEVICE void push_back( Product &a_product ) { m_products.push_back( a_product ); }
323 LUPI_HOST_DEVICE void clear( ) { m_products.clear( ); }
324};
325
326} // End of namespace Sampling.
327
328} // End of namespace MCGIDI.
329
330#endif // End of MCGIDI_sampling_hpp_included
G4double B(G4double temperature)
const G4double A[17]
#define LUPI_HOST_DEVICE
#define LUPI_HOST
LUPI_HOST_DEVICE DomainHash()
LUPI_HOST_DEVICE double domainMin() const
LUPI_HOST_DEVICE double u_domainMin() const
LUPI_HOST_DEVICE double inverse_du() const
LUPI_HOST_DEVICE double u_domainMax() const
LUPI_HOST void print(bool a_printValues) const
LUPI_HOST_DEVICE double domainMax() const
LUPI_HOST_DEVICE std::size_t index(double a_domain) const
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE std::size_t bins() const
LUPI_HOST_DEVICE Vector< std::size_t > map(Vector< double > const &a_domainValues) const
LUPI_HOST_DEVICE ClientCodeRNGData(double(*a_generator)(void *), void *a_state)
LUPI_HOST_DEVICE ClientRandomNumberGenerator(double(*a_generator)(void *), void *a_state)
LUPI_HOST_DEVICE double(*)(void *) generator()
LUPI_HOST_DEVICE double(*)(void *) rng()
LUPI_HOST_DEVICE double modelTemperature() const
SampledType sampledType() const
LUPI_HOST_DEVICE void setTemperatureAndEnergy(double a_temperature, double a_energy)
LUPI_HOST_DEVICE bool wantVelocity() const
LUPI_HOST_DEVICE double temperature() const
LUPI_HOST_DEVICE double modelEnergy() const
LUPI_HOST_DEVICE Input(bool a_wantVelocity, Upscatter::Model a_upscatterModel)
Upscatter::Model m_upscatterModel
LUPI_HOST_DEVICE void setSampledType(SampledType a_sampledType)
LUPI_HOST_DEVICE bool dataInTargetFrame() const
LUPI_HOST_DEVICE double energy() const
LUPI_HOST_DEVICE void push_back(Product &a_product)
LUPI_HOST_DEVICE MCGIDIVectorProductHandler(std::size_t a_size=20)
LUPI_HOST_DEVICE Vector< Product > const & products() const
LUPI_HOST_DEVICE Product const & operator[](std::size_t a_index) const
LUPI_HOST_DEVICE void add(double a_projectileEnergy, int a_productIntid, int a_productIndex, int a_userProductIndex, double a_productMass, Input &a_input, RNG &&a_rng, PUSHBACK &&push_back, bool isPhoton)
LUPI_HOST_DEVICE Product & operator[](std::size_t a_index)
LUPI_HOST_DEVICE std::vector< Product > & products()
LUPI_HOST_DEVICE void push_back(Product &a_product)
LUPI_HOST_DEVICE double crossSectionMax(double a_energy, double a_targetThermalSpeed)
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE double targetThermalSpeed(double a_temperature)
LUPI_HOST_DEVICE double evaluate(double a_energy)
Frame
Definition GIDI.hpp:146
LUPI_HOST_DEVICE ModelDBRC_data * serializeModelDBRC_data(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode, ModelDBRC_data *a_modelDBRC_data)
LUPI_HOST_DEVICE std::size_t evaluationForHashIndex(std::size_t a_hashIndex, Vector< std::size_t > const &a_hashIndices, double a_energy, Vector< double > const &a_energies, double *a_energyFraction)
Simple C++ string class, useful as replacement for std::string if this cannot be used,...
Definition MCGIDI.hpp:43