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

openmc-dev / openmc / 15199515869

23 May 2025 12:28AM UTC coverage: 85.224% (+0.004%) from 85.22%
15199515869

Pull #3416

github

web-flow
Merge 2293fef34 into a7d1ceba3
Pull Request #3416: Fixed a bug in charged particle energy deposition.

15 of 15 new or added lines in 2 files covered. (100.0%)

263 existing lines in 3 files now uncovered.

52359 of 61437 relevant lines covered (85.22%)

37291466.71 hits per line

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

0.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
  double charge_density();
60

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

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

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

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

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

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

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

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

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

101
  //----------------------------------------------------------------------------
102
  // Accessors
103

104
  //! Get density in [atom/b-cm]
105
  //! \return Density in [atom/b-cm]
106
  double density() const { return density_; }
107

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

112
  //! Get name
113
  //! \return Material name
UNCOV
114
  const std::string& name() const { return name_; }
×
115

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

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

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

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

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

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

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

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

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

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

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

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

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

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

192
  // Thermal scattering tables
193
  vector<ThermalTable> thermal_tables_;
194

195
  unique_ptr<Bremsstrahlung> ttb_;
196

197
private:
198
  //----------------------------------------------------------------------------
199
  // Private methods
200

201
  //! Calculate the collision stopping power
202
  void collision_stopping_power(double* s_col, bool positron);
203

204
  //! Initialize bremsstrahlung data
205
  void init_bremsstrahlung();
206

207
  //! Normalize density
208
  void normalize_density();
209

210
  void calculate_neutron_xs(Particle& p) const;
211
  void calculate_photon_xs(Particle& p) const;
212

213
  //----------------------------------------------------------------------------
214
  // Private data members
215
  int64_t index_;
216

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

226
//==============================================================================
227
// Non-member functions
228
//==============================================================================
229

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

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

240
//! Read material data from materials.xml
241
void read_materials_xml();
242

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

247
void free_memory_material();
248

249
} // namespace openmc
250
#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