• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 18223010909

03 Oct 2025 01:02PM UTC coverage: 85.192% (-0.007%) from 85.199%
18223010909

Pull #3592

github

web-flow
Merge ab97ff94d into 8a62e7e32
Pull Request #3592: Speed up time correction factors

5 of 5 new or added lines in 1 file covered. (100.0%)

321 existing lines in 12 files now uncovered.

53186 of 62431 relevant lines covered (85.19%)

38471764.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/include/openmc/material.h
1
#ifndef OPENMC_MATERIAL_H
2
#define OPENMC_MATERIAL_H
3

4
#include <string>
5
#include <unordered_map>
6

7
#include "openmc/span.h"
8
#include "pugixml.hpp"
9
#include "xtensor/xtensor.hpp"
10
#include <hdf5.h>
11

12
#include "openmc/bremsstrahlung.h"
13
#include "openmc/constants.h"
14
#include "openmc/memory.h" // for unique_ptr
15
#include "openmc/ncrystal_interface.h"
16
#include "openmc/particle.h"
17
#include "openmc/vector.h"
18

19
namespace openmc {
20

21
//==============================================================================
22
// Global variables
23
//==============================================================================
24

25
class Material;
26

27
namespace model {
28

29
extern std::unordered_map<int32_t, int32_t> material_map;
30
extern vector<unique_ptr<Material>> materials;
31

32
} // namespace model
33

34
//==============================================================================
35
//! A substance with constituent nuclides and thermal scattering data
36
//==============================================================================
37

38
class Material {
39
public:
40
  //----------------------------------------------------------------------------
41
  // Types
42
  struct ThermalTable {
43
    int index_table;   //!< Index of table in data::thermal_scatt
44
    int index_nuclide; //!< Index in nuclide_
45
    double fraction;   //!< How often to use table
46
  };
47

48
  //----------------------------------------------------------------------------
49
  // Constructors, destructors, factory functions
50
  Material() {};
51
  explicit Material(pugi::xml_node material_node);
52
  ~Material();
53

54
  //----------------------------------------------------------------------------
55
  // Methods
56

57
  void calculate_xs(Particle& p) const;
58

59
  //! Assign thermal scattering tables to specific nuclides within the material
60
  //! so the code knows when to apply bound thermal scattering data
61
  void init_thermal();
62

63
  //! Set up mapping between global nuclides vector and indices in nuclide_
64
  void init_nuclide_index();
65

66
  //! Finalize the material, assigning tables, normalize density, etc.
67
  void finalize();
68

69
  //! Write material data to HDF5
70
  void to_hdf5(hid_t group) const;
71

72
  //! Export physical properties to HDF5
73
  //! \param[in] group  HDF5 group to write to
74
  void export_properties_hdf5(hid_t group) const;
75

76
  //! Import physical properties from HDF5
77
  //! \param[in] group  HDF5 group to read from
78
  void import_properties_hdf5(hid_t group);
79

80
  //! Add nuclide to the material
81
  //
82
  //! \param[in] nuclide Name of the nuclide
83
  //! \param[in] density Density of the nuclide in [atom/b-cm]
84
  void add_nuclide(const std::string& nuclide, double density);
85

86
  //! Set atom densities for the material
87
  //
88
  //! \param[in] name Name of each nuclide
89
  //! \param[in] density Density of each nuclide in [atom/b-cm]
90
  void set_densities(
91
    const vector<std::string>& name, const vector<double>& density);
92

93
  //! Clone the material by deep-copying all members, except for the ID,
94
  //  which will get auto-assigned to the next available ID. After creating
95
  //  the new material, it is added to openmc::model::materials.
96
  //! \return reference to the cloned material
97
  Material& clone();
98

99
  //----------------------------------------------------------------------------
100
  // Accessors
101

102
  //! Get the atom density in [atom/b-cm]
103
  //! \return Density in [atom/b-cm]
104
  double atom_density(int32_t i, double rho_multiplier = 1.0) const
×
105
  {
106
    return atom_density_(i) * rho_multiplier;
×
107
  }
108

109
  //! Get density in [atom/b-cm]
110
  //! \return Density in [atom/b-cm]
111
  double density() const { return density_; }
112

113
  //! Get density in [g/cm^3]
114
  //! \return Density in [g/cm^3]
115
  double density_gpcc() const { return density_gpcc_; }
116

117
  //! Get charge density in [e/b-cm]
118
  //! \return Charge density in [e/b-cm]
119
  double charge_density() const { return charge_density_; };
1,065,482✔
120

121
  //! Get name
122
  //! \return Material name
UNCOV
123
  const std::string& name() const { return name_; }
×
124

125
  //! Set name
126
  void set_name(const std::string& name) { name_ = name; }
127

128
  //! Set total density of the material
129
  //
130
  //! \param[in] density Density value
131
  //! \param[in] units Units of density
132
  void set_density(double density, const std::string& units);
133

134
  //! Set temperature of the material
135
  void set_temperature(double temperature) { temperature_ = temperature; };
136

137
  //! Get nuclides in material
138
  //! \return Indices into the global nuclides vector
139
  span<const int> nuclides() const
140
  {
141
    return {nuclide_.data(), nuclide_.size()};
142
  }
143

144
  //! Get densities of each nuclide in material
145
  //! \return Densities in [atom/b-cm]
146
  span<const double> densities() const
147
  {
148
    return {atom_density_.data(), atom_density_.size()};
149
  }
150

151
  //! Get ID of material
152
  //! \return ID of material
153
  int32_t id() const { return id_; }
×
154

155
  //! Assign a unique ID to the material
156
  //! \param[in] Unique ID to assign. A value of -1 indicates that an ID
157
  //!   should be automatically assigned.
158
  void set_id(int32_t id);
159

160
  //! Get whether material is fissionable
161
  //! \return Whether material is fissionable
162
  bool fissionable() const { return fissionable_; }
163
  bool& fissionable() { return fissionable_; }
×
164

165
  //! Get volume of material
166
  //! \return Volume in [cm^3]
167
  double volume() const;
168

169
  //! Get temperature of material
170
  //! \return Temperature in [K]
171
  double temperature() const;
172

173
  //! Whether or not the material is depletable
174
  bool depletable() const { return depletable_; }
175
  bool& depletable() { return depletable_; }
176

177
  //! Get pointer to NCrystal material object
178
  //! \return Pointer to NCrystal material object
179
  const NCrystalMat& ncrystal_mat() const { return ncrystal_mat_; };
180

181
  //----------------------------------------------------------------------------
182
  // Data
183
  int32_t id_ {C_NONE};                 //!< Unique ID
184
  std::string name_;                    //!< Name of material
185
  vector<int> nuclide_;                 //!< Indices in nuclides vector
186
  vector<int> element_;                 //!< Indices in elements vector
187
  NCrystalMat ncrystal_mat_;            //!< NCrystal material object
188
  xt::xtensor<double, 1> atom_density_; //!< Nuclide atom density in [atom/b-cm]
189
  double density_;                      //!< Total atom density in [atom/b-cm]
190
  double density_gpcc_;                 //!< Total atom density in [g/cm^3]
191
  double charge_density_;               //!< Total charge density in [e/b-cm]
192
  double volume_ {-1.0};                //!< Volume in [cm^3]
193
  vector<bool> p0_; //!< Indicate which nuclides are to be treated with
194
                    //!< iso-in-lab scattering
195

196
  // To improve performance of tallying, we store an array (direct address
197
  // table) that indicates for each nuclide in data::nuclides the index of the
198
  // corresponding nuclide in the nuclide_ vector. If it is not present in the
199
  // material, the entry is set to -1.
200
  vector<int> mat_nuclide_index_;
201

202
  // Thermal scattering tables
203
  vector<ThermalTable> thermal_tables_;
204

205
  unique_ptr<Bremsstrahlung> ttb_;
206

207
private:
208
  //----------------------------------------------------------------------------
209
  // Private methods
210

211
  //! Calculate the collision stopping power
212
  void collision_stopping_power(double* s_col, bool positron);
213

214
  //! Initialize bremsstrahlung data
215
  void init_bremsstrahlung();
216

217
  //! Normalize density
218
  void normalize_density();
219

220
  void calculate_neutron_xs(Particle& p) const;
221
  void calculate_photon_xs(Particle& p) const;
222

223
  //----------------------------------------------------------------------------
224
  // Private data members
225
  int64_t index_;
226

227
  bool depletable_ {false}; //!< Is the material depletable?
228
  bool fissionable_ {
229
    false}; //!< Does this material contain fissionable nuclides
230
  //! \brief Default temperature for cells containing this material.
231
  //!
232
  //! A negative value indicates no default temperature was specified.
233
  double temperature_ {-1};
234
};
235

236
//==============================================================================
237
// Non-member functions
238
//==============================================================================
239

240
//! Calculate Sternheimer adjustment factor
241
double sternheimer_adjustment(const vector<double>& f,
242
  const vector<double>& e_b_sq, double e_p_sq, double n_conduction,
243
  double log_I, double tol, int max_iter);
244

245
//! Calculate density effect correction
246
double density_effect(const vector<double>& f, const vector<double>& e_b_sq,
247
  double e_p_sq, double n_conduction, double rho, double E, double tol,
248
  int max_iter);
249

250
//! Read material data from materials.xml
251
void read_materials_xml();
252

253
//! Read material data XML node
254
//! \param[in] root node of materials XML element
255
void read_materials_xml(pugi::xml_node root);
256

257
void free_memory_material();
258

259
} // namespace openmc
260
#endif // OPENMC_MATERIAL_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc