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

openmc-dev / openmc / 22286612725

22 Feb 2026 10:21PM UTC coverage: 81.784% (+0.09%) from 81.69%
22286612725

Pull #3808

github

web-flow
Merge a62b545e2 into 83a30f686
Pull Request #3808: Add properties to settings w/ documentation, c++ loading of filename, and python round-trip test

17355 of 24476 branches covered (70.91%)

Branch coverage included in aggregate %.

83 of 100 new or added lines in 8 files covered. (83.0%)

721 existing lines in 14 files now uncovered.

57750 of 67357 relevant lines covered (85.74%)

42989222.51 hits per line

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

84.36
/src/summary.cpp
1
#include "openmc/summary.h"
2

3
#include <fmt/core.h>
4

5
#include "openmc/capi.h"
6
#include "openmc/cell.h"
7
#include "openmc/file_utils.h"
8
#include "openmc/hdf5_interface.h"
9
#include "openmc/lattice.h"
10
#include "openmc/material.h"
11
#include "openmc/message_passing.h"
12
#include "openmc/mgxs_interface.h"
13
#include "openmc/nuclide.h"
14
#include "openmc/output.h"
15
#include "openmc/settings.h"
16
#include "openmc/surface.h"
17

18
namespace openmc {
19

20
void write_summary()
5,470✔
21
{
22
  // Display output message
23
  write_message("Writing summary.h5 file...", 5);
5,470✔
24

25
  // Set filename for summary file
26
  std::string filename = fmt::format("{}summary.h5", settings::path_output);
4,254✔
27

28
  // Create a new file using default properties.
29
  hid_t file = file_open(filename, 'w');
5,470✔
30

31
  write_header(file);
5,470✔
32
  write_nuclides(file);
5,470✔
33
  write_geometry(file);
5,470✔
34
  write_materials(file);
5,470✔
35

36
  // Terminate access to the file.
37
  file_close(file);
5,470✔
38
}
5,470✔
39

40
void write_header(hid_t file)
5,470✔
41
{
42
  // Write filetype and version info
43
  write_attribute(file, "filetype", "summary");
5,470✔
44
  write_attribute(file, "version", VERSION_SUMMARY);
5,470✔
45
  write_attribute(file, "openmc_version", VERSION);
5,470✔
46
#ifdef GIT_SHA1
47
  write_attribute(file, "git_sha1", GIT_SHA1);
48
#endif
49

50
  // Write current date and time
51
  write_attribute(file, "date_and_time", time_stamp());
5,470✔
52
}
5,470✔
53

54
void write_nuclides(hid_t file)
5,470✔
55
{
56
  // Build vectors of nuclide names and awrs while only sorting nuclides from
57
  // macroscopics
58
  vector<std::string> nuc_names;
5,470✔
59
  vector<std::string> macro_names;
5,470✔
60
  vector<double> awrs;
5,470✔
61

62
  for (int i = 0; i < data::nuclides.size(); ++i) {
25,506✔
63
    if (settings::run_CE) {
20,036!
64
      const auto& nuc {data::nuclides[i]};
20,036✔
65
      nuc_names.push_back(nuc->name_);
20,036✔
66
      awrs.push_back(nuc->awr_);
20,036✔
67
    } else {
68
      const auto& nuc {data::mg.nuclides_[i]};
×
69
      if (nuc.awr != MACROSCOPIC_AWR) {
×
70
        nuc_names.push_back(nuc.name);
×
71
        awrs.push_back(nuc.awr);
×
72
      } else {
73
        macro_names.push_back(nuc.name);
×
74
      }
75
    }
76
  }
77

78
  hid_t nuclide_group = create_group(file, "nuclides");
5,470✔
79
  write_attribute(nuclide_group, "n_nuclides", nuc_names.size());
5,470✔
80
  hid_t macro_group = create_group(file, "macroscopics");
5,470✔
81
  write_attribute(macro_group, "n_macroscopics", macro_names.size());
5,470✔
82
  // Write nuclide names and awrs
83
  if (!nuc_names.empty()) {
5,470✔
84
    // Write useful data from nuclide objects
85
    write_dataset(nuclide_group, "names", nuc_names);
4,188✔
86
    write_dataset(nuclide_group, "awrs", awrs);
4,188✔
87
  }
88
  if (!macro_names.empty()) {
5,470!
89
    // Write useful data from macroscopic objects
90
    write_dataset(macro_group, "names", macro_names);
×
91
  }
92
  close_group(nuclide_group);
5,470✔
93
  close_group(macro_group);
5,470✔
94
}
5,470✔
95

96
void write_geometry(hid_t file)
5,470✔
97
{
98
  auto geom_group = create_group(file, "geometry");
5,470✔
99

100
  write_attribute(geom_group, "n_cells", model::cells.size());
5,470✔
101
  write_attribute(geom_group, "n_surfaces", model::surfaces.size());
5,470✔
102
  write_attribute(geom_group, "n_universes", model::universes.size());
5,470✔
103
  write_attribute(geom_group, "n_lattices", model::lattices.size());
5,470✔
104

105
  auto cells_group = create_group(geom_group, "cells");
5,470✔
106
  for (const auto& c : model::cells)
29,817✔
107
    c->to_hdf5(cells_group);
24,347✔
108
  close_group(cells_group);
5,470✔
109

110
  auto surfaces_group = create_group(geom_group, "surfaces");
5,470✔
111
  for (const auto& surf : model::surfaces)
34,824✔
112
    surf->to_hdf5(surfaces_group);
29,354✔
113
  close_group(surfaces_group);
5,470✔
114

115
  auto universes_group = create_group(geom_group, "universes");
5,470✔
116
  for (const auto& u : model::universes)
20,461✔
117
    u->to_hdf5(universes_group);
14,991✔
118
  close_group(universes_group);
5,470✔
119

120
  auto lattices_group = create_group(geom_group, "lattices");
5,470✔
121
  for (const auto& lat : model::lattices)
6,644✔
122
    lat->to_hdf5(lattices_group);
1,174✔
123
  close_group(lattices_group);
5,470✔
124

125
  close_group(geom_group);
5,470✔
126
}
5,470✔
127

128
void write_materials(hid_t file)
5,470✔
129
{
130
  // write number of materials
131
  write_dataset(file, "n_materials", model::materials.size());
5,470✔
132

133
  hid_t materials_group = create_group(file, "materials");
5,470✔
134
  for (const auto& mat : model::materials) {
15,880✔
135
    mat->to_hdf5(materials_group);
10,410✔
136
  }
137
  close_group(materials_group);
5,470✔
138
}
5,470✔
139

140
//==============================================================================
141
// C API
142
//==============================================================================
143

144
extern "C" int openmc_properties_export(const char* filename)
36✔
145
{
146
  // Only write from master process
147
  if (!mpi::master)
36!
148
    return 0;
×
149

150
  // Set a default filename if none was passed
151
  std::string name = filename ? filename : "properties.h5";
72✔
152

153
  // Display output message
154
  auto msg = fmt::format("Exporting properties to {}...", name);
28✔
155
  write_message(msg, 5);
36✔
156

157
  // Create a new file using default properties.
158
  hid_t file = file_open(name, 'w');
36✔
159

160
  // Write metadata
161
  write_attribute(file, "filetype", "properties");
36✔
162
  write_attribute(file, "version", VERSION_STATEPOINT);
36✔
163
  write_attribute(file, "openmc_version", VERSION);
36✔
164
#ifdef GIT_SHA1
165
  write_attribute(file, "git_sha1", GIT_SHA1);
166
#endif
167
  write_attribute(file, "date_and_time", time_stamp());
36✔
168
  write_attribute(file, "path", settings::path_input);
36✔
169

170
  // Write cell properties
171
  auto geom_group = create_group(file, "geometry");
36✔
172
  write_attribute(geom_group, "n_cells", model::cells.size());
36✔
173
  auto cells_group = create_group(geom_group, "cells");
36✔
174
  for (const auto& c : model::cells) {
162✔
175
    c->export_properties_hdf5(cells_group);
126✔
176
  }
177
  close_group(cells_group);
36✔
178
  close_group(geom_group);
36✔
179

180
  // Write material properties
181
  hid_t materials_group = create_group(file, "materials");
36✔
182
  write_attribute(materials_group, "n_materials", model::materials.size());
36✔
183
  for (const auto& mat : model::materials) {
144✔
184
    mat->export_properties_hdf5(materials_group);
108✔
185
  }
186
  close_group(materials_group);
36✔
187

188
  // Terminate access to the file.
189
  file_close(file);
36✔
190
  return 0;
36✔
191
}
36✔
192

193
extern "C" int openmc_properties_import(const char* filename,
45✔
194
  bool read_temperatures_from_properties, bool read_densities_from_properties)
195
{
196
  if (!read_temperatures_from_properties && !read_densities_from_properties)
45!
NEW
197
    return 0;
×
198

199
  // Display output message
200
  auto msg = fmt::format("Importing properties from {}...", filename);
35✔
201
  write_message(msg, 5);
45✔
202

203
  // Create a new file using default properties.
204
  if (!file_exists(filename)) {
45!
205
    set_errmsg(fmt::format("File '{}' does not exist.", filename));
×
206
    return OPENMC_E_INVALID_ARGUMENT;
×
207
  }
208
  hid_t file = file_open(filename, 'r');
45✔
209

210
  // Ensure the filetype is correct
211
  std::string filetype;
45✔
212
  read_attribute(file, "filetype", filetype);
45✔
213
  if (filetype != "properties") {
45!
214
    file_close(file);
×
215
    set_errmsg(fmt::format("File '{}' is not a properties file.", filename));
×
216
    return OPENMC_E_INVALID_ARGUMENT;
×
217
  }
218

219
  // Make sure number of cells matches
220
  auto geom_group = open_group(file, "geometry");
45✔
221
  int32_t n;
222
  read_attribute(geom_group, "n_cells", n);
45✔
223
  if (n != openmc::model::cells.size()) {
45✔
224
    close_group(geom_group);
9✔
225
    file_close(file);
9✔
226
    set_errmsg(fmt::format(
9✔
227
      "Number of cells in {} doesn't match current model.", filename));
228
    return OPENMC_E_GEOMETRY;
9✔
229
  }
230

231
  // Read cell properties
232
  auto cells_group = open_group(geom_group, "cells");
36✔
233
  try {
234
    for (const auto& c : model::cells) {
180✔
235
      c->import_properties_hdf5(cells_group, read_temperatures_from_properties,
144✔
236
        read_densities_from_properties);
237
    }
238
  } catch (const std::exception& e) {
×
239
    set_errmsg(e.what());
×
240
    return OPENMC_E_UNASSIGNED;
×
241
  }
×
242
  close_group(cells_group);
36✔
243
  close_group(geom_group);
36✔
244

245
  // Make sure number of cells matches
246
  auto materials_group = open_group(file, "materials");
36✔
247
  read_attribute(materials_group, "n_materials", n);
36✔
248
  if (n != openmc::model::materials.size()) {
36✔
249
    close_group(materials_group);
9✔
250
    file_close(file);
9✔
251
    set_errmsg(fmt::format(
9✔
252
      "Number of materials in {} doesn't match current model.", filename));
253
    return OPENMC_E_GEOMETRY;
9✔
254
  }
255

256
  // Read material properties
257
  for (const auto& mat : model::materials) {
108✔
258
    mat->import_properties_hdf5(
81✔
259
      materials_group, read_densities_from_properties);
260
  }
261
  close_group(materials_group);
27✔
262

263
  // Terminate access to the file.
264
  file_close(file);
27✔
265
  return 0;
27✔
266
}
45✔
267

268
} // namespace openmc
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