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

openmc-dev / openmc / 13703779155

06 Mar 2025 04:45PM UTC coverage: 85.674% (+0.5%) from 85.129%
13703779155

Pull #3087

github

web-flow
Merge 20c292e2a into e360cb467
Pull Request #3087: wheel building with scikit build core

47261 of 55164 relevant lines covered (85.67%)

29624867.19 hits per line

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

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

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

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

31
  write_header(file);
3,841✔
32
  write_nuclides(file);
3,841✔
33
  write_geometry(file);
3,841✔
34
  write_materials(file);
3,841✔
35

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

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

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

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

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

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

105
  auto cells_group = create_group(geom_group, "cells");
3,841✔
106
  for (const auto& c : model::cells)
18,576✔
107
    c->to_hdf5(cells_group);
14,735✔
108
  close_group(cells_group);
3,841✔
109

110
  auto surfaces_group = create_group(geom_group, "surfaces");
3,841✔
111
  for (const auto& surf : model::surfaces)
25,608✔
112
    surf->to_hdf5(surfaces_group);
21,767✔
113
  close_group(surfaces_group);
3,841✔
114

115
  auto universes_group = create_group(geom_group, "universes");
3,841✔
116
  for (const auto& u : model::universes)
10,888✔
117
    u->to_hdf5(universes_group);
7,047✔
118
  close_group(universes_group);
3,841✔
119

120
  auto lattices_group = create_group(geom_group, "lattices");
3,841✔
121
  for (const auto& lat : model::lattices)
4,831✔
122
    lat->to_hdf5(lattices_group);
990✔
123
  close_group(lattices_group);
3,841✔
124

125
  close_group(geom_group);
3,841✔
126
}
3,841✔
127

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

133
  hid_t materials_group = create_group(file, "materials");
3,841✔
134
  for (const auto& mat : model::materials) {
10,145✔
135
    mat->to_hdf5(materials_group);
6,304✔
136
  }
137
  close_group(materials_group);
3,841✔
138
}
3,841✔
139

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

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

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

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

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

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

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

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

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

193
extern "C" int openmc_properties_import(const char* filename)
×
194
{
195
  // Display output message
196
  auto msg = fmt::format("Importing properties from {}...", filename);
×
197
  write_message(msg, 5);
×
198

199
  // Create a new file using default properties.
200
  if (!file_exists(filename)) {
×
201
    set_errmsg(fmt::format("File '{}' does not exist.", filename));
×
202
    return OPENMC_E_INVALID_ARGUMENT;
×
203
  }
204
  hid_t file = file_open(filename, 'r');
×
205

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

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

227
  // Read cell properties
228
  auto cells_group = open_group(geom_group, "cells");
×
229
  try {
230
    for (const auto& c : model::cells) {
×
231
      c->import_properties_hdf5(cells_group);
×
232
    }
233
  } catch (const std::exception& e) {
×
234
    set_errmsg(e.what());
×
235
    return OPENMC_E_UNASSIGNED;
×
236
  }
×
237
  close_group(cells_group);
×
238
  close_group(geom_group);
×
239

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

251
  // Read material properties
252
  for (const auto& mat : model::materials) {
×
253
    mat->import_properties_hdf5(materials_group);
×
254
  }
255
  close_group(materials_group);
×
256

257
  // Terminate access to the file.
258
  file_close(file);
×
259
  return 0;
×
260
}
261

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

© 2025 Coveralls, Inc