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

openmc-dev / openmc / 22322317452

pending completion
22322317452

Pull #3808

github

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

16820 of 23482 branches covered (71.63%)

Branch coverage included in aggregate %.

76 of 92 new or added lines in 8 files covered. (82.61%)

724 existing lines in 14 files now uncovered.

56900 of 66807 relevant lines covered (85.17%)

43125827.06 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,423✔
21
{
22
  // Display output message
23
  write_message("Writing summary.h5 file...", 5);
5,423✔
24

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

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

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

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

40
void write_header(hid_t file)
5,423✔
41
{
42
  // Write filetype and version info
43
  write_attribute(file, "filetype", "summary");
5,423✔
44
  write_attribute(file, "version", VERSION_SUMMARY);
5,423✔
45
  write_attribute(file, "openmc_version", VERSION);
5,423✔
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,423✔
52
}
5,423✔
53

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

62
  for (int i = 0; i < data::nuclides.size(); ++i) {
25,319✔
63
    if (settings::run_CE) {
19,896!
64
      const auto& nuc {data::nuclides[i]};
19,896✔
65
      nuc_names.push_back(nuc->name_);
19,896✔
66
      awrs.push_back(nuc->awr_);
19,896✔
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,423✔
79
  write_attribute(nuclide_group, "n_nuclides", nuc_names.size());
5,423✔
80
  hid_t macro_group = create_group(file, "macroscopics");
5,423✔
81
  write_attribute(macro_group, "n_macroscopics", macro_names.size());
5,423✔
82
  // Write nuclide names and awrs
83
  if (!nuc_names.empty()) {
5,423✔
84
    // Write useful data from nuclide objects
85
    write_dataset(nuclide_group, "names", nuc_names);
4,143✔
86
    write_dataset(nuclide_group, "awrs", awrs);
4,143✔
87
  }
88
  if (!macro_names.empty()) {
5,423!
89
    // Write useful data from macroscopic objects
90
    write_dataset(macro_group, "names", macro_names);
×
91
  }
92
  close_group(nuclide_group);
5,423✔
93
  close_group(macro_group);
5,423✔
94
}
5,423✔
95

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

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

105
  auto cells_group = create_group(geom_group, "cells");
5,423✔
106
  for (const auto& c : model::cells)
27,568✔
107
    c->to_hdf5(cells_group);
22,145✔
108
  close_group(cells_group);
5,423✔
109

110
  auto surfaces_group = create_group(geom_group, "surfaces");
5,423✔
111
  for (const auto& surf : model::surfaces)
33,838✔
112
    surf->to_hdf5(surfaces_group);
28,415✔
113
  close_group(surfaces_group);
5,423✔
114

115
  auto universes_group = create_group(geom_group, "universes");
5,423✔
116
  for (const auto& u : model::universes)
18,348✔
117
    u->to_hdf5(universes_group);
12,925✔
118
  close_group(universes_group);
5,423✔
119

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

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

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

133
  hid_t materials_group = create_group(file, "materials");
5,423✔
134
  for (const auto& mat : model::materials) {
15,803✔
135
    mat->to_hdf5(materials_group);
10,380✔
136
  }
137
  close_group(materials_group);
5,423✔
138
}
5,423✔
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(
45✔
194
  const char* filename, bool read_temperatures, bool read_densities)
195
{
196
  if (!read_temperatures && !read_densities)
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, read_densities);
144✔
236
    }
237
  } catch (const std::exception& e) {
×
238
    set_errmsg(e.what());
×
239
    return OPENMC_E_UNASSIGNED;
×
240
  }
×
241
  close_group(cells_group);
36✔
242
  close_group(geom_group);
36✔
243

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

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

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

266
} // 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