Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_domainHash.cc
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#include "MCGIDI.hpp"
11
12namespace MCGIDI {
13
14/*! \class DomainHash
15 * This class stores the data needed for logarithmic hash look up of a domain. This is used to find a cross section given a projectile's energy.
16 */
17
18/* *********************************************************************************************************//**
19 * Default constructor used when broadcasting a Protare as needed by MPI or GPUs.
20 ***********************************************************************************************************/
21
23 m_bins( 0 ),
24 m_domainMin( 0.0 ),
25 m_domainMax( 0.0 ),
26 m_u_domainMin( 0.0 ),
27 m_u_domainMax( 0.0 ),
28 m_inverse_du( 0.0 ) {
29
30}
31
32/* *********************************************************************************************************//**
33 * @param a_bins [in] The number of bins for the hahs function.
34 * @param a_domainMin [in] The minimum value of the energy domain for the hash function.
35 * @param a_domainMax [in] The maximum value of the energy domain for the hash function.
36 ***********************************************************************************************************/
37
38LUPI_HOST_DEVICE DomainHash::DomainHash( std::size_t a_bins, double a_domainMin, double a_domainMax ) :
39 m_bins( a_bins ),
40 m_domainMin( a_domainMin ),
41 m_domainMax( a_domainMax ),
42 m_u_domainMin( log( a_domainMin ) ),
43 m_u_domainMax( log( a_domainMax ) ),
44 m_inverse_du( static_cast<double>( a_bins ) / ( m_u_domainMax - m_u_domainMin ) ) {
45
46}
47
48/* *********************************************************************************************************//**
49 * @param a_domainHash [in] The DomainHash instance to copy.
50 ***********************************************************************************************************/
51
53 m_bins( a_domainHash.bins( ) ),
54 m_domainMin( a_domainHash.domainMin( ) ),
55 m_domainMax( a_domainHash.domainMax( ) ),
56 m_u_domainMin( a_domainHash.u_domainMin( ) ),
57 m_u_domainMax( a_domainHash.u_domainMax( ) ),
58 m_inverse_du( a_domainHash.inverse_du( ) ) {
59}
60
61/* *********************************************************************************************************//**
62 * This method returns the hash index given the domain value *a_domain*. If *a_domain* is less than *m_domainMin*,
63 * the returned index is 0. If *a_domain* is greater than *m_domainMax*, the returned index is *m_bins* + 1.
64 * Otherwise, the returned index is in the range [1, *m_bins*].
65 *
66 * @param a_domain [in] The domain value that the hash index is to be returned for.
67 *
68 * @return The hash index.
69 ***********************************************************************************************************/
70
71LUPI_HOST_DEVICE std::size_t DomainHash::index( double a_domain ) const {
72
73 if( a_domain < m_domainMin ) return( 0 );
74 if( a_domain > m_domainMax ) return( m_bins + 1 );
75 double dIndex = m_inverse_du * ( log( a_domain ) - m_u_domainMin ) + 1;
76 return( static_cast<std::size_t>( dIndex ) );
77}
78
79/* *********************************************************************************************************//**
80 * This method returns the hash indices for the requested domain values *a_domainValues*.
81 *
82 * @param a_domainValues [in] The domain values.
83 *
84 * @return The hash indices.
85 ***********************************************************************************************************/
86
88
89 std::size_t i1, size( a_domainValues.size( ) );
90 Vector<std::size_t> indices( m_bins + 2, static_cast<std::size_t>( 0 ) );
91 std::size_t lastIndex = 0, currentIndex, i2 = 1;
92
93 for( i1 = 0; i1 < size; ++i1 ) {
94 currentIndex = index( a_domainValues[i1] );
95 if( currentIndex != lastIndex ) {
96 for( ; lastIndex < currentIndex; ++lastIndex, ++i2 ) {
97 indices[i2] = i1 - 1;
98 if( i1 == 0 ) indices[i2] = 0; // Special case.
99 }
100 }
101 }
102 for( ; i2 < ( m_bins + 2 ); ++i2 ) indices[i2] = indices[i2-1];
103 return( indices );
104}
105
106/* *********************************************************************************************************//**
107 * This method serializes *this* for broadcasting as needed for MPI and GPUs. The method can count the number of required
108 * bytes, pack *this* or unpack *this* depending on *a_mode*.
109 *
110 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
111 * @param a_mode [in] Specifies the action of this method.
112 ***********************************************************************************************************/
113
115
116 DATA_MEMBER_SIZE_T( m_bins, a_buffer, a_mode );
117 DATA_MEMBER_DOUBLE( m_domainMin, a_buffer, a_mode );
118 DATA_MEMBER_DOUBLE( m_domainMax, a_buffer, a_mode );
119 DATA_MEMBER_DOUBLE( m_u_domainMin, a_buffer, a_mode );
120 DATA_MEMBER_DOUBLE( m_u_domainMax, a_buffer, a_mode );
121 DATA_MEMBER_DOUBLE( m_inverse_du, a_buffer, a_mode );
122}
123
124/* *********************************************************************************************************//**
125 * Prints the contents of *this*.
126 *
127 * @param a_printValues [in] If true, the domain values that divide the hash indices are also printed.
128 ***********************************************************************************************************/
129
130LUPI_HOST void DomainHash::print( bool a_printValues ) const {
131#ifndef __CUDA_ARCH__
132 std::cout << "bins = " << m_bins << std::endl;
133 std::cout << " m_domainMin = " << m_domainMin << " << m_domainMax = " << m_domainMax << std::endl;
134 std::cout << " m_u_domainMin = " << m_u_domainMin << " << m_u_domainMax = " << m_u_domainMax << std::endl;
135 std::cout << " m_inverse_du = " << m_inverse_du << std::endl;
136 if( a_printValues ) {
137 double domain = m_domainMin, factor = pow( m_domainMax / m_domainMin, 1. / static_cast<double>( m_bins ) );
138
139 for( std::size_t i1 = 0; i1 < bins( ); ++i1, domain *= factor ) {
140 std::cout << LUPI::Misc::argumentsToString( " %14.7e", domain );
141 if( ( ( i1 + 1 ) % 10 ) == 0 ) std::cout << std::endl;
142 }
143 std::cout << LUPI::Misc::argumentsToString( " %14.7e", m_domainMax ) << std::endl;
144 }
145#endif
146}
147
148/*! \class MultiGroupHash
149 * This class stores a multi-group boundaries and has a method *index* that returns an index of the group for the requested domain value.
150 */
151
152/* *********************************************************************************************************//**
153 ***********************************************************************************************************/
154
158
159/* *********************************************************************************************************//**
160 * @param a_boundaries [in] The list of multi-group boundaries.
161 ***********************************************************************************************************/
162
163LUPI_HOST MultiGroupHash::MultiGroupHash( std::vector<double> a_boundaries ) :
164 m_boundaries( a_boundaries ) {
165
166}
167
168/* *********************************************************************************************************//**
169 * @param a_boundaries [in] The list of multi-group boundaries.
170 ***********************************************************************************************************/
171
173 m_boundaries( a_boundaries ) {
174
175}
176
177/* *********************************************************************************************************//**
178 * This constructor gets the list of multi-group boundaries from the first GIDI::Styles::MultiGroup of *a_protare*.
179 * It calls MultiGroupHash::initialize to set up *this*.
180 *
181 * @param a_protare [in] The GIDI::Protare containing the GIDI::Styles::MultiGroup style.
182 * @param a_temperatureInfo [in] This is used to determine the multi-group boundaries.
183 * @param a_particleID [in] The PoPs' id of the particle whose multi-group boundaries are desired.
184 ***********************************************************************************************************/
185
186LUPI_HOST MultiGroupHash::MultiGroupHash( GIDI::Protare const &a_protare, GIDI::Styles::TemperatureInfo const &a_temperatureInfo, std::string const &a_particleID ) {
187
188 initialize( a_protare, a_temperatureInfo, a_particleID );
189}
190
191/* *********************************************************************************************************//**
192 * This constructor gets the list of multi-group boundaries from the GIDI::Particle of *a_particles* that is the projectile.
193 *
194 * @param a_protare [in] The GIDI::Protare containing the GIDI::Styles::MultiGroup style.
195 * @param a_particles [in] The list of transportable particles.
196 ***********************************************************************************************************/
197
199
200 GIDI::Transporting::Particle const &particle = *a_particles.particle( a_protare.projectile( ).pid( ) );
201
202 m_boundaries = particle.multiGroup( ).boundaries( );
203}
204
205/* *********************************************************************************************************//**
206 * This constructor gets the list of multi-group boundaries from the GIDI::Particle of *a_particles* that is the projectile.
207 *
208 * @param a_protare [in] The GIDI::Protare containing the GIDI::Styles::MultiGroup style.
209 * @param a_particles [in] The list of transportable particles.
210 ***********************************************************************************************************/
211
213 m_boundaries( a_multiGroupHash.boundaries( ) ) {
214
215}
216
217/* *********************************************************************************************************//**
218 * This method is used by several constructors to get the multi-group data.
219 *
220 * @param a_protare [in] The GIDI::Protare containing the GIDI::Styles::MultiGroup style.
221 * @param a_temperatureInfo [in] This is used to determine the multi-group boundaries.
222 * @param a_particleID [in] The PoPs' id of the particle whose multi-group boundaries are desired.
223 ***********************************************************************************************************/
224
225LUPI_HOST void MultiGroupHash::initialize( GIDI::Protare const &a_protare, GIDI::Styles::TemperatureInfo const &a_temperatureInfo, std::string a_particleID ) {
226
227 if( a_particleID == "" ) a_particleID = a_protare.projectile( ).ID( );
228
229 GIDI::Styles::Suite const &stylesSuite( a_protare.styles( ) );
230 GIDI::Styles::HeatedMultiGroup const *heatedMultiGroupStyle1 = stylesSuite.get<GIDI::Styles::HeatedMultiGroup>( a_temperatureInfo.heatedMultiGroup( ) );
231
232 m_boundaries = heatedMultiGroupStyle1->groupBoundaries( a_particleID );
233}
234
235/* *********************************************************************************************************//**
236 * This method serializes *this* for broadcasting as needed for MPI and GPUs. The method can count the number of required
237 * bytes, pack *this* or unpack *this* depending on *a_mode*.
238 *
239 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
240 * @param a_mode [in] Specifies the action of this method.
241 ***********************************************************************************************************/
242
244
245 DATA_MEMBER_VECTOR_DOUBLE( m_boundaries, a_buffer, a_mode );
246}
247
248}
#define DATA_MEMBER_VECTOR_DOUBLE(member, buf, mode)
#define DATA_MEMBER_SIZE_T(member, buf, mode)
#define DATA_MEMBER_DOUBLE(member, buf, mode)
#define LUPI_HOST_DEVICE
#define LUPI_HOST
std::string const & pid() const
Definition GIDI.hpp:762
std::string const & ID() const
Definition GIDI.hpp:760
virtual Styles::Suite & styles()=0
ParticleInfo const & projectile() const
Definition GIDI.hpp:4541
std::vector< double > groupBoundaries(std::string const &a_ID) const
std::string const & heatedMultiGroup() const
Definition GIDI.hpp:3434
std::vector< double > const & boundaries() const
Definition GIDI.hpp:3501
MultiGroup multiGroup() const
Definition GIDI.hpp:3668
Particle const * particle(std::string const &a_particleID) const
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 MultiGroupHash()
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE Vector< double > const & boundaries() const
Definition MCGIDI.hpp:404
LUPI_HOST_DEVICE std::size_t size() const
std::string argumentsToString(char const *a_format,...)
Definition LUPI_misc.cc:305
Simple C++ string class, useful as replacement for std::string if this cannot be used,...
Definition MCGIDI.hpp:43