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

openmc-dev / openmc / 16033007652

02 Jul 2025 06:33PM UTC coverage: 85.251% (-0.08%) from 85.33%
16033007652

Pull #3484

github

web-flow
Merge ffaa13385 into eb74d497d
Pull Request #3484: fix zam parsing

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

41 existing lines in 13 files now uncovered.

52639 of 61746 relevant lines covered (85.25%)

36642138.68 hits per line

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

33.33
/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 density in [atom/b-cm]
103
  //! \return Density in [atom/b-cm]
104
  double density() const { return density_; }
105

106
  //! Get density in [g/cm^3]
107
  //! \return Density in [g/cm^3]
108
  double density_gpcc() const { return density_gpcc_; }
109

110
  //! Get charge density in [e/b-cm]
111
  //! \return Charge density in [e/b-cm]
112
  double charge_density() const { return charge_density_; };
1,065,482✔
113

114
  //! Get name
115
  //! \return Material name
116
  const std::string& name() const { return name_; }
117

118
  //! Set name
119
  void set_name(const std::string& name) { name_ = name; }
120

121
  //! Set total density of the material
122
  //
123
  //! \param[in] density Density value
124
  //! \param[in] units Units of density
125
  void set_density(double density, const std::string& units);
126

127
  //! Set temperature of the material
128
  void set_temperature(double temperature) { temperature_ = temperature; };
129

130
  //! Get nuclides in material
131
  //! \return Indices into the global nuclides vector
132
  span<const int> nuclides() const
133
  {
134
    return {nuclide_.data(), nuclide_.size()};
135
  }
136

137
  //! Get densities of each nuclide in material
138
  //! \return Densities in [atom/b-cm]
139
  span<const double> densities() const
140
  {
141
    return {atom_density_.data(), atom_density_.size()};
142
  }
143

144
  //! Get ID of material
145
  //! \return ID of material
UNCOV
146
  int32_t id() const { return id_; }
×
147

148
  //! Assign a unique ID to the material
149
  //! \param[in] Unique ID to assign. A value of -1 indicates that an ID
150
  //!   should be automatically assigned.
151
  void set_id(int32_t id);
152

153
  //! Get whether material is fissionable
154
  //! \return Whether material is fissionable
155
  bool fissionable() const { return fissionable_; }
156
  bool& fissionable() { return fissionable_; }
×
157

158
  //! Get volume of material
159
  //! \return Volume in [cm^3]
160
  double volume() const;
161

162
  //! Get temperature of material
163
  //! \return Temperature in [K]
164
  double temperature() const;
165

166
  //! Whether or not the material is depletable
167
  bool depletable() const { return depletable_; }
168
  bool& depletable() { return depletable_; }
169

170
  //! Get pointer to NCrystal material object
171
  //! \return Pointer to NCrystal material object
172
  const NCrystalMat& ncrystal_mat() const { return ncrystal_mat_; };
173

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

189
  // To improve performance of tallying, we store an array (direct address
190
  // table) that indicates for each nuclide in data::nuclides the index of the
191
  // corresponding nuclide in the nuclide_ vector. If it is not present in the
192
  // material, the entry is set to -1.
193
  vector<int> mat_nuclide_index_;
194

195
  // Thermal scattering tables
196
  vector<ThermalTable> thermal_tables_;
197

198
  unique_ptr<Bremsstrahlung> ttb_;
199

200
private:
201
  //----------------------------------------------------------------------------
202
  // Private methods
203

204
  //! Calculate the collision stopping power
205
  void collision_stopping_power(double* s_col, bool positron);
206

207
  //! Initialize bremsstrahlung data
208
  void init_bremsstrahlung();
209

210
  //! Normalize density
211
  void normalize_density();
212

213
  void calculate_neutron_xs(Particle& p) const;
214
  void calculate_photon_xs(Particle& p) const;
215

216
  //----------------------------------------------------------------------------
217
  // Private data members
218
  int64_t index_;
219

220
  bool depletable_ {false}; //!< Is the material depletable?
221
  bool fissionable_ {
222
    false}; //!< Does this material contain fissionable nuclides
223
  //! \brief Default temperature for cells containing this material.
224
  //!
225
  //! A negative value indicates no default temperature was specified.
226
  double temperature_ {-1};
227
};
228

229
//==============================================================================
230
// Non-member functions
231
//==============================================================================
232

233
//! Calculate Sternheimer adjustment factor
234
double sternheimer_adjustment(const vector<double>& f,
235
  const vector<double>& e_b_sq, double e_p_sq, double n_conduction,
236
  double log_I, double tol, int max_iter);
237

238
//! Calculate density effect correction
239
double density_effect(const vector<double>& f, const vector<double>& e_b_sq,
240
  double e_p_sq, double n_conduction, double rho, double E, double tol,
241
  int max_iter);
242

243
//! Read material data from materials.xml
244
void read_materials_xml();
245

246
//! Read material data XML node
247
//! \param[in] root node of materials XML element
248
void read_materials_xml(pugi::xml_node root);
249

250
void free_memory_material();
251

252
} // namespace openmc
253
#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