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

openmc-dev / openmc / 14840340664

05 May 2025 03:38PM UTC coverage: 85.195% (-0.009%) from 85.204%
14840340664

Pull #3392

github

web-flow
Merge 5bc1ec35f into 1e7d8324e
Pull Request #3392: Map Compton subshell data to atomic relaxation data

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

330 existing lines in 19 files now uncovered.

52194 of 61264 relevant lines covered (85.2%)

37398320.1 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
  //! 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 name
111
  //! \return Material name
UNCOV
112
  const std::string& name() const { return name_; }
×
113

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

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

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

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

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

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

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

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

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

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

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

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

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

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

190
  // Thermal scattering tables
191
  vector<ThermalTable> thermal_tables_;
192

193
  unique_ptr<Bremsstrahlung> ttb_;
194

195
private:
196
  //----------------------------------------------------------------------------
197
  // Private methods
198

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

202
  //! Initialize bremsstrahlung data
203
  void init_bremsstrahlung();
204

205
  //! Normalize density
206
  void normalize_density();
207

208
  void calculate_neutron_xs(Particle& p) const;
209
  void calculate_photon_xs(Particle& p) const;
210

211
  //----------------------------------------------------------------------------
212
  // Private data members
213
  int64_t index_;
214

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

224
//==============================================================================
225
// Non-member functions
226
//==============================================================================
227

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

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

238
//! Read material data from materials.xml
239
void read_materials_xml();
240

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

245
void free_memory_material();
246

247
} // namespace openmc
248
#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

© 2025 Coveralls, Inc