A monte carlo pin cell spectral code for nuclear engineering applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Isotope.h
Go to the documentation of this file.
1 
9 #ifndef ISOTOPE_H_
10 #define ISOTOPE_H_
11 
12 #ifdef __cplusplus
13 #include <limits>
14 #include <vector>
15 #include <map>
16 #include <math.h>
17 #include <stdarg.h>
18 #include <string.h>
19 #include <sys/stat.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <iostream>
23 #include <fstream>
24 #include <string>
25 
26 #include "interpolate.h"
27 #include "integrate.h"
28 #include "arraycreator.h"
29 #include "xsreader.h"
30 #include "log.h"
31 #include "vector.h"
32 #include "Neutron.h"
33 #endif
34 
41 class Isotope {
42 private:
46  static int _n;
48  int _uid;
50  int _A;
57  float _alpha;
59  float _eta;
61  float _rho;
63  float _AO;
65  float _T;
68  float _mu_avg;
72  bool _rescaled;
73 
77  float* _elastic_xs;
83 
87  float* _capture_xs;
93 
97  float* _fission_xs;
103 
107  float* _absorb_xs;
110 
114  float* _total_xs;
118 
127 
133  float _kB;
141  float** _thermal_cdfs;
143  float* _E_to_kT;
145  float* _Eprime_to_E;
146 
147  void loadXS();
148  void setElasticXS(float* elastic_xs, float* elastic_xs_energies, int num_elastic_xs);
149  void setCaptureXS(float* capture_xs, float* capture_xs_energies,
150  int num_capture_xs);
151  void setFissionXS(float* fission_xs, float* fission_xs_energies,
152  int num_fission_xs);
153  void rescaleXS(float start_energy, float end_energy, int num_energies);
154  void generateAbsorptionXS(float start_energy, float end_energy,
155  int num_energies);
156  void generateTotalXS(float start_energy, float end_energy,
157  int num_energies);
158 
159  void initializeThermalScattering(float start_energy, float end_energy,
160  int num_bins, int num_distributions);
161  float thermalScatteringProb(float E_prime_to_E, int dist_index);
162 
163 public:
164  Isotope(char *_isotope_name);
165  virtual ~Isotope();
166 
167  void parseName(char* isotope_name);
168  void makeFissionable();
169 
170  char* getIsotopeName() const;
171  int getUid() const;
172  int getA() const;
173  float getAlpha() const;
174  float getTemperature() const;
175  float getMuAverage() const;
176  bool isFissionable() const;
178 
179  int getNumXSEnergies(char* xs_type) const;
180 
181  float getElasticXS(float energy) const;
182  float getElasticXS(int energy_index) const;
183  float getAbsorptionXS(float energy) const;
184  float getAbsorptionXS(int energy_index) const;
185  float getCaptureXS(float energy) const;
186  float getCaptureXS(int energy_index) const;
187  float getFissionXS(float energy) const;
188  float getFissionXS(int energy_index) const;
189  float getTotalXS(float energy) const;
190  float getTotalXS(int energy_index) const;
191  float getTransportXS(int energy_index) const;
192  float getTransportXS(float energy) const;
193 
194  bool usesThermalScattering();
195  bool isRescaled() const;
196  int getEnergyGridIndex(float energy) const;
197 
198  /* IMPORTANT: The following eight class method prototypes must
199  * not be changed without changing Geometry.i to allow for the
200  * data arrays to be transformed into numpy arrays */
201  void retrieveXSEnergies(float* energies, int num_xs, char* xs_type) const;
202  void retrieveXS(float* xs, int num_xs, char* xs_type) const;
203 
204  void setElasticXS(double* energies, int num_energies,
205  double* elastic_xs, int num_xs);
206  void setCaptureXS(double* energies, int num_energies,
207  double* capture_xs, int num_xs);
208  void setFissionXS(double* energies, int num_energies,
209  double* fission_xs, int num_xs);
210 
211  void setMultigroupElasticXS(double* energies, int num_energies,
212  double* elastic_xs, int num_xs);
213  void setMultigroupCaptureXS(double* energies, int num_energies,
214  double* capture_xs, int num_xs);
215  void setMultigroupFissionXS(double* energies, int num_energies,
216  double* fission_xs, int num_xs);
217 
218 
219  void loadXS(char* xs_type);
220  void setA(int A);
221  void setTemperature(float T);
223  void setThermalScatteringCutoff(float cutoff_energy);
224  void useThermalScattering();
225 
226  Isotope* clone();
227 
231  float getThermalScatteringEnergy(float energy);
232 
233  int getNumThermalCDFs();
234  int getNumThermalCDFBins();
235  void retrieveThermalCDFs(float* cdfs, int num_values);
236  void retrieveThermalPDFs(float* pdfs, int num_values);
237  void retrieveEtokT(float* E_to_kT, int num_cdfs);
238  void retrieveEprimeToE(float* Eprime_to_E, int num_bins);
239 };
240 
241 
250 inline int Isotope::getEnergyGridIndex(float energy) const {
251 
252  int index;
253 
254  /* Compute the lethargy */
255  float lethargy = log10(energy);
256 
257  /* If the energy is outside of the grid, pin the energy to the max/min */
258  if (lethargy > _end_lethargy)
259  index = _num_energies - 1;
260  else if (lethargy < _start_lethargy)
261  index = 0;
262  /* If the lethargy is within the grid, comput the index */
263  else
264  index = int(floor((lethargy - _start_lethargy) / _delta_lethargy));
265 
266  return index;
267 }
268 
269 
270 #endif /* ISOTOPE_H_ */
The neutron C structure.
bool isRescaled() const
This method returns whether or not the Isotope's cross-sections have been rescaled to a uniform letha...
Definition: Isotope.cpp:1229
Represents a neutron in a PINSPEC simulation.
Definition: Neutron.h:27
int _A_squared
Definition: Isotope.h:52
Isotope * clone()
This method clones a given Isotope class object by executing a deep copy of all of the Isotope's clas...
Definition: Isotope.cpp:1749
float getThermalScatteringEnergy(float energy)
For a given neutron energy (eV) in a scattering collision, this function returns the outgoing energy ...
Definition: Isotope.cpp:1803
void setMultigroupElasticXS(double *energies, int num_energies, double *elastic_xs, int num_xs)
Sets the multigroup elastic cross-section data for this isotope.
Definition: Isotope.cpp:615
void setTemperature(float T)
Set the temperature of the isotope in degrees Kelvin.
Definition: Isotope.cpp:1257
int _A_plus_one_squared
Definition: Isotope.h:55
float _end_lethargy
Definition: Isotope.h:124
float _thermal_cutoff
Definition: Isotope.h:131
int _num_fission_xs
Definition: Isotope.h:95
int _num_elastic_xs
Definition: Isotope.h:75
void setThermalScatteringCutoff(float cutoff_energy)
Sets the thermal scattering high energy cutoff energy.
Definition: Isotope.cpp:1275
float * _total_xs
Definition: Isotope.h:114
float * _Eprime_to_E
Definition: Isotope.h:145
bool usesThermalScattering()
This method returns true if the thermal scattering distributions for this isotope are to be used when...
Definition: Isotope.cpp:1219
The Isotope represents a nuclide at some temperature.
Definition: Isotope.h:41
bool _rescaled
Definition: Isotope.h:72
float _mu_avg
Definition: Isotope.h:68
int getNumThermalCDFs()
Returns the number of thermal scattering CDFs.
Definition: Isotope.cpp:2001
void generateTotalXS(float start_energy, float end_energy, int num_energies)
Computes the microscopic total cross-section from the isotope's capture, elastic scatter and fission ...
Definition: Isotope.cpp:1721
void collideNeutron(neutron *neutron)
For a given energy, this method samples a collision type, updates the neutron's outgoing energy and k...
Definition: Isotope.cpp:2142
float getCaptureXS(float energy) const
Returns the microscopic capture cross-section value for some energy.
Definition: Isotope.cpp:1006
float * _absorb_xs
Definition: Isotope.h:107
float getTemperature() const
Return the temperature in degrees Kelvin for this isotope.
Definition: Isotope.cpp:187
float getFissionXS(float energy) const
Returns the microscopic fission cross-section value for some energy.
Definition: Isotope.cpp:1059
void retrieveXSEnergies(float *energies, int num_xs, char *xs_type) const
Fills an array with cross-section energy values.
Definition: Isotope.cpp:271
float * _total_xs_energies
Definition: Isotope.h:117
void sampleCollisionType(neutron *neutron)
Determines a random collision type based on the values of each of the isotope's cross-section values ...
Definition: Isotope.cpp:1768
float * _capture_xs
Definition: Isotope.h:87
float * _elastic_xs_energies
Definition: Isotope.h:79
void setMultigroupFissionXS(double *energies, int num_energies, double *fission_xs, int num_xs)
Sets the multigroup fission cross-section data for this isotope.
Definition: Isotope.cpp:813
int _num_capture_xs
Definition: Isotope.h:85
void makeFissionable()
Inform isotope that it is fissionable.
Definition: Isotope.cpp:1292
float thermalScatteringProb(float E_prime_to_E, int dist_index)
This function computes the thermal scattering probability for a ratio of initial to final energies...
Definition: Isotope.cpp:1964
float * _elastic_xs
Definition: Isotope.h:77
float _start_lethargy
Definition: Isotope.h:122
Isotope(char *_isotope_name)
Isotope constructor.
Definition: Isotope.cpp:17
float _alpha
Definition: Isotope.h:57
void retrieveThermalPDFs(float *pdfs, int num_values)
Loads an input array with the energies for each of the isotope's thermal PDFs.
Definition: Isotope.cpp:2060
float * _E_to_kT
Definition: Isotope.h:143
float getThermalScatteringCutoff()
Return the thermal scattering high energy cutoff.
Definition: Isotope.cpp:217
float ** _thermal_cdfs
Definition: Isotope.h:141
void retrieveXS(float *xs, int num_xs, char *xs_type) const
Fills an array with microscopic cross-section values.
Definition: Isotope.cpp:322
int getUid() const
Returns the unique ID auto-generated for the isotope.
Definition: Isotope.cpp:159
float getTransportXS(int energy_index) const
Returns the microscopic transport cross-section value for a certain energy index in this isotope's re...
Definition: Isotope.cpp:1208
int _num_absorb_xs
Definition: Isotope.h:105
float * _thermal_dist
Definition: Isotope.h:139
Functions for creating arrays with similar syntax to MATLAB.
void setMultigroupCaptureXS(double *energies, int num_energies, double *capture_xs, int num_xs)
Sets the multigroup capture cross-section data for this isotope.
Definition: Isotope.cpp:713
char * getIsotopeName() const
Returns the name of the of isotope.
Definition: Isotope.cpp:150
int getEnergyGridIndex(float energy) const
This method returns the index for a certain energy (eV) into the Isotope's uniform lethargy grid...
Definition: Isotope.h:250
void useThermalScattering()
Informs isotope to use thermal scattering to sample outgoing collision energies.
Definition: Isotope.cpp:1284
int getNumXSEnergies(char *xs_type) const
Returns the number of energies for a particular cross-section type.
Definition: Isotope.cpp:229
bool isFissionable() const
Return whether this isotope is fissionable (true) or not (false)
Definition: Isotope.cpp:207
int getNumThermalCDFBins()
Returns the number of energy bins for each thermal scattering CDF.
Definition: Isotope.cpp:2010
void retrieveEtokT(float *E_to_kT, int num_cdfs)
Loads an input array with the values for each thermal scattering CDF.
Definition: Isotope.cpp:2086
bool _use_thermal_scattering
Definition: Isotope.h:129
void parseName(char *isotope_name)
Parse input name and set atomic number for isotope.
Definition: Isotope.cpp:108
bool _capture_rescaled
Definition: Isotope.h:92
float _T
Definition: Isotope.h:65
float _delta_lethargy
Definition: Isotope.h:126
virtual ~Isotope()
Isotope destructor deletes arrays of cross-section values that have been assigned to this isotope...
Definition: Isotope.cpp:70
float getElasticXS(float energy) const
Returns the microscopic elastic scattering cross-section value for some energy.
Definition: Isotope.cpp:898
float getTotalXS(float energy) const
Returns the microscopic total cross-section value for some energy.
Definition: Isotope.cpp:1113
void setElasticXS(float *elastic_xs, float *elastic_xs_energies, int num_elastic_xs)
Set the elastic cross-section for this isotope.
Definition: Isotope.cpp:1547
void initializeThermalScattering(float start_energy, float end_energy, int num_bins, int num_distributions)
This method initializes the probability distributions for thermal scattering.
Definition: Isotope.cpp:1876
static int _n
Definition: Isotope.h:46
bool _fissionable
Definition: Isotope.h:70
float getAbsorptionXS(float energy) const
Returns the microscopic absorption cross-section value for some energy.
Definition: Isotope.cpp:952
void loadXS()
Load the ENDF cross-section data from ASCII files into arrays for this isotope.
Definition: Isotope.cpp:1312
void setFissionXS(float *fission_xs, float *fission_xs_energies, int num_fission_xs)
Set the fission cross-section for this isotope.
Definition: Isotope.cpp:1577
float getDistanceTraveled(neutron *neutron)
For a given neutron, this method samples a distance traveled to next collision.
Definition: Isotope.cpp:2122
int _uid
Definition: Isotope.h:48
int _A
Definition: Isotope.h:50
float _kB
Definition: Isotope.h:133
Utility functions for commonly used vector operations.
void rescaleXS(float start_energy, float end_energy, int num_energies)
Rescales all of the isotope's cross-sections onto a uniform lethargy grid.
Definition: Isotope.cpp:1595
float getMuAverage() const
Return the average value of the cosine of the scattering angle.
Definition: Isotope.cpp:198
void retrieveEprimeToE(float *Eprime_to_E, int num_bins)
Loads an input array with the values for each thermal scattering CDF.
Definition: Isotope.cpp:2108
int _num_thermal_cdfs
Definition: Isotope.h:135
float * _fission_xs_energies
Definition: Isotope.h:99
void retrieveThermalCDFs(float *cdfs, int num_values)
Loads an input array with the values for each of the isotope's thermal CDFs.
Definition: Isotope.cpp:2033
void setCaptureXS(float *capture_xs, float *capture_xs_energies, int num_capture_xs)
Set the capture cross-section for this isotope.
Definition: Isotope.cpp:1562
bool _elastic_rescaled
Definition: Isotope.h:82
float _eta
Definition: Isotope.h:59
float _AO
Definition: Isotope.h:63
Utility functions for numerical integration of 1D functions.
Utility functions to parse in ENDF cross-sections from text files into data arrays.
int _num_energies
Definition: Isotope.h:120
void neglectThermalScattering()
Informs isotope not to use thermal scattering to sample outgoing collision energies.
Definition: Isotope.cpp:1266
float * _fission_xs
Definition: Isotope.h:97
bool _fission_rescaled
Definition: Isotope.h:102
float getAlpha() const
Returns the alpha values for this isotope.
Definition: Isotope.cpp:178
void generateAbsorptionXS(float start_energy, float end_energy, int num_energies)
Computes the microscopic absorption cross-section from the isotope's capture and fission (if applicab...
Definition: Isotope.cpp:1686
int _num_total_xs
Definition: Isotope.h:112
float * _absorb_xs_energies
Definition: Isotope.h:109
int _num_thermal_cdf_bins
Definition: Isotope.h:137
Utility functions for writing log messages to the screen.
Utility functions for linear interpolation of 1D functions.
float _rho
Definition: Isotope.h:61
int getA() const
Returns the atomic number of this isotope.
Definition: Isotope.cpp:168
void setA(int A)
Set the atomic number and update alpha, eta and rho.
Definition: Isotope.cpp:1244
char * _isotope_name
Definition: Isotope.h:44
float * _capture_xs_energies
Definition: Isotope.h:89