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

openmc-dev / openmc / 17626478777

10 Sep 2025 08:49PM UTC coverage: 85.177% (-0.03%) from 85.209%
17626478777

Pull #3546

github

web-flow
Merge 0bc00e071 into 366509051
Pull Request #3546: Add distributed cell density multipliers

146 of 193 new or added lines in 13 files covered. (75.65%)

166 existing lines in 8 files now uncovered.

53067 of 62302 relevant lines covered (85.18%)

38802975.01 hits per line

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

20.0
/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]
NEW
104
  double atom_density(int32_t i, double rho_multiplier=1.0) const {
×
NEW
105
    return atom_density_(i) * rho_multiplier;
×
106
  }
107

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

204
  unique_ptr<Bremsstrahlung> ttb_;
205

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

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

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

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

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

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

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

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

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

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

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

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

256
void free_memory_material();
257

258
} // namespace openmc
259
#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