Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_URR.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/* *********************************************************************************************************//**
15 * This method serializes *this* for broadcasting as needed for MPI and GPUs. The method can count the number of required
16 * bytes, pack *this* or unpack *this* depending on *a_mode*.
17 *
18 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
19 * @param a_mode [in] Specifies the action of this method.
20 ***********************************************************************************************************/
21
23
24 DATA_MEMBER_CAST( m_inURR, a_buffer, a_mode, bool );
25 DATA_MEMBER_DOUBLE( m_rng_Value, a_buffer, a_mode );
26}
27
28/* *********************************************************************************************************//**
29 * URR_protareInfos constructor.
30 *
31 * @param a_protares [in] The list of protares to be check for URR data. Each protare with URR data add to *a_URR_protareInfos*.
32 ***********************************************************************************************************/
33
35
36 setup( a_protares );
37}
38
39/* *********************************************************************************************************//**
40 * URR_protareInfos setup.
41 *
42 * @param a_protares [in] The list of protares to be check for URR data. Each protare with URR data add to *a_URR_protareInfos*.
43 ***********************************************************************************************************/
44
46
47 std::vector<URR_protareInfo> URR_protareInfo_1;
48
49 for( std::size_t i1 = 0; i1 < a_protares.size( ); ++i1 ) {
50 Protare *protare = a_protares[i1];
51
52 for( std::size_t i2 = 0; i2 < protare->numberOfProtares( ); ++i2 ) {
53 ProtareSingle *protareSingle = const_cast<ProtareSingle *>( protare->protare( i2 ) );
54
55 if( protareSingle->hasURR_probabilityTables( ) ) {
56 protareSingle->setURR_index( static_cast<int>( URR_protareInfo_1.size( ) ) );
57 URR_protareInfo_1.push_back( URR_protareInfo( ) );
58 }
59 }
60 }
61
62 m_URR_protareInfos.reserve( URR_protareInfo_1.size( ) );
63 m_URR_protareInfos.clear( );
64 for( std::size_t i1 = 0; i1 < URR_protareInfo_1.size( ); ++i1 ) m_URR_protareInfos.push_back( URR_protareInfo_1[i1] );
65}
66
67/* *********************************************************************************************************//**
68 * This method serializes *this* for broadcasting as needed for MPI and GPUs. The method can count the number of required
69 * bytes, pack *this* or unpack *this* depending on *a_mode*.
70 *
71 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
72 * @param a_mode [in] Specifies the action of this method.
73 ***********************************************************************************************************/
74
76
77 std::size_t vectorSize = m_URR_protareInfos.size( );
78 int vectorSizeInt = (int) vectorSize;
79 DATA_MEMBER_INT( vectorSizeInt, a_buffer, a_mode );
80 vectorSize = (std::size_t) vectorSizeInt;
81 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) m_URR_protareInfos.resize( vectorSize, &a_buffer.m_placement );
82 if( a_mode == LUPI::DataBuffer::Mode::Memory ) a_buffer.m_placement += m_URR_protareInfos.internalSize();
83
84 for( std::size_t vectorIndex = 0; vectorIndex < vectorSize; ++vectorIndex ) {
85 m_URR_protareInfos[vectorIndex].serialize( a_buffer, a_mode );
86 }
87}
88
89/*! \class ACE_URR_probabilityTable
90 * Class to store ACE URR probability table at one projectile energy for one type of reaction (e.g., total, elastic).
91 */
92
93/* *********************************************************************************************************//**
94 * Simple constructor needed for broadcasting.
95 ***********************************************************************************************************/
96
101
102/* *********************************************************************************************************//**
103 * @param a_energy [in] The projectile energy where the data are specified.
104 * @param a_propabilities [in] The probability for each cross section.
105 * @param a_crossSection [in] The cross section for each probability.
106 ***********************************************************************************************************/
107
108LUPI_HOST ACE_URR_probabilityTable::ACE_URR_probabilityTable( double a_energy, std::vector<double> const &a_propabilities,
109 std::vector<double> const &a_crossSection ) :
110 m_energy( a_energy ),
111 m_propabilities( a_propabilities ),
112 m_crossSections( a_crossSection ) {
113
114 double sum = 0.0;
115 for( std::size_t index = 0; index < m_propabilities.size( ); ++index ) {
116 sum += m_propabilities[index];
117 m_propabilities[index] = sum;
118 }
119 m_propabilities[m_propabilities.size( )-1] = 1.0;
120}
121
122/* *********************************************************************************************************//**
123 * Simple constructor needed for broadcasting.
124 ***********************************************************************************************************/
125
129
130/* *********************************************************************************************************//**
131 * Returns the cross section corresponding to the probability *a_rng_Value*.
132 *
133 * @param a_rng_Value [in] A random number in the range [0,1).
134 *
135 * @return The cross section associated with probability a_rng_Value;
136 ***********************************************************************************************************/
137
139
140 int intIndex = binarySearchVector( a_rng_Value, m_propabilities, true );
141 std::size_t index = static_cast<std::size_t>( intIndex );
142 if( m_propabilities[index] < a_rng_Value ) ++index;
143 return( m_crossSections[index] );
144}
145
146/* *********************************************************************************************************//**
147 * This method serializes *this* for broadcasting as needed for MPI and GPUs. The method can count the number of required
148 * bytes, pack *this* or unpack *this* depending on *a_mode*.
149 *
150 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
151 * @param a_mode [in] Specifies the action of this method.
152 ***********************************************************************************************************/
153
160
161/*! \class ACE_URR_probabilityTables
162 * Class to store ACE URR probability tables at a list of projectile energies for one type of reaction (e.g., total, elastic).
163 */
164
165/* *********************************************************************************************************//**
166 * Simple constructor needed for broadcasting.
167 ***********************************************************************************************************/
168
172
173/* *********************************************************************************************************//**
174 * @param a_capacity [in] The number of energy slots to reverse.
175 ***********************************************************************************************************/
176
178
179 m_energies.reserve( a_capacity );
180 m_ACE_URR_probabilityTables.reserve( a_capacity );
181}
182
183/* *********************************************************************************************************//**
184 ***********************************************************************************************************/
185
187
188 for( auto iter = m_ACE_URR_probabilityTables.begin( ); iter != m_ACE_URR_probabilityTables.end( ); ++iter ) delete (*iter);
189}
190
191/* *********************************************************************************************************//**
192 * Calls reserve for m_energies and m_ACE_URR_probabilityTables with the value *a_capacity*.
193 *
194 * @param a_capacity [in] The size of the space to reserve.
195 ***********************************************************************************************************/
196
198
199 m_energies.reserve( a_capacity );
200 m_ACE_URR_probabilityTables.reserve( a_capacity );
201}
202
203/* *********************************************************************************************************//**
204 * Adds *a_ACE_URR_probabilityTable* to the end of *this*.
205 *
206 * @param a_ACE_URR_probabilityTable [in] **ACE_URR_probabilityTable** instance to add.
207 ***********************************************************************************************************/
208
210
211 if( m_energies.size( ) == capacity( ) ) LUPI_THROW( "ACE_URR_probabilityTables::addEnergyData: adding too many ACE_URR_probabilityTables." );
212 m_energies.push_back( a_ACE_URR_probabilityTable->energy( ) );
213 m_ACE_URR_probabilityTables.push_back( a_ACE_URR_probabilityTable );
214}
215
216/* *********************************************************************************************************//**
217 * Returns the cross section corresponding to the probability *a_rng_Value*.
218 *
219 * @param a_energy [in] The incident projectiles energy.
220 * @param a_rng_Value [in] A random number in the range [0,1).
221 *
222 * @return The cross section associated with probability a_rng_Value;
223 ***********************************************************************************************************/
224
225LUPI_HOST_DEVICE double ACE_URR_probabilityTables::sample( double a_energy, double a_rng_Value ) {
226
227 int index = binarySearchVector( a_energy, m_energies, true );
228
229 std::size_t index_t = (std::size_t) index;
230 if( index_t < m_energies.size( ) - 1 ) {
231 if( 0.5 * ( m_energies[index_t] + m_energies[index_t+1] ) < a_energy ) ++index_t; // Find closest energy.
232 }
233
234 return( m_ACE_URR_probabilityTables[index_t]->sample( a_rng_Value ) );
235}
236
237/* *********************************************************************************************************//**
238 * This method serializes *this* for broadcasting as needed for MPI and GPUs. The method can count the number of required
239 * bytes, pack *this* or unpack *this* depending on *a_mode*.
240 *
241 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
242 * @param a_mode [in] Specifies the action of this method.
243 ***********************************************************************************************************/
244
246
247 DATA_MEMBER_VECTOR_DOUBLE( m_energies, a_buffer, a_mode );
248
249 std::size_t vectorSize = m_energies.size( );
250
251 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) m_ACE_URR_probabilityTables.resize( vectorSize, &a_buffer.m_placement );
252 if( a_mode == LUPI::DataBuffer::Mode::Memory ) a_buffer.m_placement += m_ACE_URR_probabilityTables.internalSize( );
253
254 for( std::size_t vectorIndex = 0; vectorIndex < vectorSize; ++vectorIndex ) {
255 ACE_URR_probabilityTable *ACE_URR_probabilityTable1 = m_ACE_URR_probabilityTables[vectorIndex];
256 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) {
257 if( a_buffer.m_placement != nullptr ) {
258 ACE_URR_probabilityTable1 = new(a_buffer.m_placement) ACE_URR_probabilityTable;
259 a_buffer.incrementPlacement( sizeof( ACE_URR_probabilityTable ) ); }
260 else {
261 ACE_URR_probabilityTable1 = new ACE_URR_probabilityTable;
262 }
263 m_ACE_URR_probabilityTables[vectorIndex] = ACE_URR_probabilityTable1;
264 }
265 if( a_mode == LUPI::DataBuffer::Mode::Memory ) {
266 a_buffer.incrementPlacement( sizeof( ACE_URR_probabilityTable ) );
267 }
268 ACE_URR_probabilityTable1->serialize( a_buffer, a_mode );
269 }
270}
271
272/* *********************************************************************************************************//**
273 * This method serializes a **ACE_URR_probabilityTables** instance pointed to by *a_ACE_URR_probabilityTables*.
274 *
275 * @param a_protare [in] The GIDI::Protare whose data is to be used to construct *this*.
276 * @param a_settings [in] Used to pass user options to the *this* to instruct it which data are desired.
277 * @param a_setupInfo [in] Used internally when constructing a Protare to pass information to other constructors.
278 *
279 * @return A pointer to the converted **ACE_URR_probabilityTables** instance.
280 ***********************************************************************************************************/
281
283
286
287 int64_t numberConverted;
288 char *endCharacter;
289
290 for( auto iter = a_protare.ACE_URR_probabilityTables( ).begin( ); iter != a_protare.ACE_URR_probabilityTables( ).end( ); ++iter ) {
291 bool needToInitialize( true );
292 std::map<std::size_t, std::string> columnNames;
293 ACE_URR_probabilityTablesFromGIDI *ACE_URR_probabilityTablesFromGIDI1 = new ACE_URR_probabilityTablesFromGIDI( );
295 GIDI::ACE_URR::ProbabilityTable::Forms &incidentEnergies = form->forms( );
296
297 for( auto incidentEnergyIter = incidentEnergies.begin( ); incidentEnergyIter != incidentEnergies.end( ); ++incidentEnergyIter ) {
298 GIDI::ACE_URR::IncidentEnergy *incidentEnergy = *incidentEnergyIter;
299 GIDI::Table::Table const &table = incidentEnergy->table( );
300 std::size_t numberOfRows = static_cast<std::size_t>( table.rows( ) );
301 std::size_t numberOfColumns = static_cast<std::size_t>( table.columns( ) );
302
303 std::size_t columnIndex = 0;
304 for( auto columnHeaderIter = table.columnHeaders( ).begin( ); columnHeaderIter != table.columnHeaders( ).end( ); ++columnHeaderIter ) {
305 GIDI::Table::Column const *columnHeader = dynamic_cast<GIDI::Table::Column *>( *columnHeaderIter );
306 if( needToInitialize && columnIndex > 0 ) {
307 ACE_URR_probabilityTablesFromGIDI1->m_ACE_URR_probabilityTables[columnHeader->name( )] =
308 new ACE_URR_probabilityTables( incidentEnergies.size( ) );
309 columnNames[columnIndex] = columnHeader->name( );
310 }
311 ++columnIndex;
312 }
313 needToInitialize = false;
314
315 GIDI::Table::Data const &data = table.data( );
316
317 std::string const &body = data.body( );
318 char const *text = body.c_str( );
319 double *dValues = nfu_stringToListOfDoubles( NULL, text, data.sep( ).c_str( )[0], &numberConverted, &endCharacter, 0 );
320 if( dValues == nullptr ) throw GIDI::Exception( "convertACE_URR_probabilityTablesFromGIDI: nfu_stringToListOfDoubles failed." );
321
322 std::vector<std::vector<double> > columns( numberOfColumns );
323 for( columnIndex = 0; columnIndex < numberOfColumns; ++columnIndex ) {
324 columns[columnIndex].reserve( numberOfRows );
325 for( std::size_t rowIndex = 0; rowIndex < numberOfRows; ++rowIndex ) columns[columnIndex].push_back( dValues[rowIndex*numberOfColumns+columnIndex] );
326 }
327 free( dValues );
328
329 for( columnIndex = 1; columnIndex < numberOfColumns; ++columnIndex ) {
330 ACE_URR_probabilityTablesFromGIDI1->m_ACE_URR_probabilityTables[columnNames[columnIndex]]->push_back(
331 new ACE_URR_probabilityTable( incidentEnergy->value( ), columns[0], columns[columnIndex] ) );
332 }
333 }
334 a_setupInfo.m_ACE_URR_probabilityTablesFromGIDI[form->label()] = ACE_URR_probabilityTablesFromGIDI1;
335 }
336 }
337}
338
339/* *********************************************************************************************************//**
340 * This method serializes a **Transporting::URR_mode** value.
341 *
342 * @param a_URR_mode [in] The inputted Transporting::URR_mode value.
343 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
344 * @param a_mode [in] Specifies the action of this method.
345 *
346 * @return The Transporting::URR_mode value.
347 ***********************************************************************************************************/
348
350
351 int type = 0;
352 switch( a_URR_mode ) {
354 break;
356 type = 1;
357 break;
359 type = 2;
360 break;
361 }
362 DATA_MEMBER_INT( type, a_buffer, a_mode );
363
364 if( type == 0 ) return( Transporting::URR_mode::none );
365 if( type == 1 ) return( Transporting::URR_mode::pdfs );
367}
368
369/* *********************************************************************************************************//**
370 * This method serializes a **ACE_URR_probabilityTables** instance pointed to by *a_ACE_URR_probabilityTables*.
371 *
372 * @param a_ACE_URR_probabilityTables [in] Specifies the action of this method.
373 * @param a_buffer [in] The buffer to read or write data to depending on *a_mode*.
374 * @param a_mode [in] Specifies the action of this method.
375 *
376 * @return A pointer to the serialized **ACE_URR_probabilityTables** instance.
377 ***********************************************************************************************************/
378
380 LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode ) {
381
382 int type = 0;
383 if( a_ACE_URR_probabilityTables != nullptr ) type = 1;
384 DATA_MEMBER_INT( type, a_buffer, a_mode );
385 if( type == 0 ) return( nullptr );
386
387 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) {
388 if( a_buffer.m_placement != nullptr ) {
389 a_ACE_URR_probabilityTables = new(a_buffer.m_placement) ACE_URR_probabilityTables;
390 a_buffer.incrementPlacement( sizeof( ACE_URR_probabilityTables ) ); }
391 else {
392 a_ACE_URR_probabilityTables = new ACE_URR_probabilityTables;
393 }
394 }
395
397
398 a_ACE_URR_probabilityTables->serialize( a_buffer, a_mode );
399
400 return( a_ACE_URR_probabilityTables );
401}
402
403/*! \class ACE_URR_probabilityTablesFromGIDI
404 * Class to store temporary ACE URR probability table data.
405 */
406
407/* *********************************************************************************************************//**
408 ***********************************************************************************************************/
409
413
414/* *********************************************************************************************************//**
415 ***********************************************************************************************************/
416
418
419 for( auto iter = m_ACE_URR_probabilityTables.begin( ); iter != m_ACE_URR_probabilityTables.end( ); ++iter ) delete (*iter).second;
420
421}
422
423} // End namespace MCGIDI.
#define DATA_MEMBER_CAST(member, buf, mode, someType)
#define DATA_MEMBER_VECTOR_DOUBLE(member, buf, mode)
#define DATA_MEMBER_DOUBLE(member, buf, mode)
#define DATA_MEMBER_INT( member, buf, mode)
#define LUPI_HOST_DEVICE
#define LUPI_THROW(arg)
#define LUPI_HOST
Table::Table const & table() const
Definition GIDI.hpp:4212
std::vector< IncidentEnergy * > Forms
Definition GIDI.hpp:4225
std::string const & label() const
Definition GIDI.hpp:658
Suite const & ACE_URR_probabilityTables() const
Definition GIDI.hpp:4770
iterator begin()
Definition GIDI.hpp:2594
iterator end()
Definition GIDI.hpp:2596
std::string const & name() const
Definition GIDI.hpp:2795
std::string const & body() const
Definition GIDI.hpp:2821
std::string const & sep() const
Definition GIDI.hpp:2820
LUPI_HOST_DEVICE void incrementPlacement(std::size_t a_delta)
LUPI_HOST_DEVICE double energy() const
Definition MCGIDI.hpp:488
LUPI_HOST_DEVICE ~ACE_URR_probabilityTable()
Vector< double > m_propabilities
Definition MCGIDI.hpp:481
Vector< double > m_crossSections
Definition MCGIDI.hpp:482
LUPI_HOST_DEVICE double sample(double a_rng_Value)
LUPI_HOST_DEVICE ACE_URR_probabilityTable()
Definition MCGIDI_URR.cc:97
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
std::map< std::string, ACE_URR_probabilityTables * > m_ACE_URR_probabilityTables
Definition MCGIDI.hpp:243
LUPI_HOST_DEVICE void reserve(std::size_t a_capacity)
Vector< ACE_URR_probabilityTable * > m_ACE_URR_probabilityTables
Definition MCGIDI.hpp:503
LUPI_HOST_DEVICE void push_back(ACE_URR_probabilityTable *a_ACE_URR_probabilityTable)
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE ACE_URR_probabilityTables()
LUPI_HOST_DEVICE std::size_t capacity() const
Definition MCGIDI.hpp:509
LUPI_HOST_DEVICE ~ACE_URR_probabilityTables()
LUPI_HOST_DEVICE double sample(double a_energy, double a_rng_Value)
LUPI_HOST_DEVICE void setURR_index(int a_URR_index)
Definition MCGIDI.hpp:1704
LUPI_HOST_DEVICE bool hasURR_probabilityTables() const
Definition MCGIDI.hpp:1706
std::map< std::string, ACE_URR_probabilityTablesFromGIDI * > m_ACE_URR_probabilityTablesFromGIDI
Definition MCGIDI.hpp:279
LUPI_HOST URR_mode _URR_mode() const
Definition MCGIDI.hpp:194
LUPI_HOST LookupMode::Data1d crossSectionLookupMode() const
Definition MCGIDI.hpp:158
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Definition MCGIDI_URR.cc:22
LUPI_HOST_DEVICE URR_protareInfos()
Definition MCGIDI.hpp:457
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Definition MCGIDI_URR.cc:75
LUPI_HOST void setup(Vector< Protare * > &a_protares)
Definition MCGIDI_URR.cc:45
LUPI_HOST_DEVICE std::size_t size() const
void free(voidpf ptr)
Simple C++ string class, useful as replacement for std::string if this cannot be used,...
Definition MCGIDI.hpp:43
LUPI_HOST_DEVICE ACE_URR_probabilityTables * serializeACE_URR_probabilityTables(ACE_URR_probabilityTables *a_ACE_URR_probabilityTables, LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE Transporting::URR_mode serializeURR_mode(Transporting::URR_mode a_URR_mode, LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE int binarySearchVector(double a_x, Vector< double > const &a_Xs, bool a_boundIndex=false)
Definition MCGIDI.hpp:318
LUPI_HOST void convertACE_URR_probabilityTablesFromGIDI(GIDI::ProtareSingle const &a_protare, Transporting::MC &a_settings, SetupInfo &a_setupInfo)
double * nfu_stringToListOfDoubles(statusMessageReporting *smr, char const *str, char sep, int64_t *numberConverted, char **endCharacter, int useSystem_strtod)