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

openmc-dev / openmc / 14515233533

17 Apr 2025 12:06PM UTC coverage: 83.16% (-2.3%) from 85.414%
14515233533

Pull #3087

github

web-flow
Merge 6ed397e9d into 47ca2916a
Pull Request #3087: wheel building with scikit build core

140769 of 169274 relevant lines covered (83.16%)

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

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

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

31
  write_header(file);
4,028✔
32
  write_nuclides(file);
4,028✔
33
  write_geometry(file);
4,028✔
34
  write_materials(file);
4,028✔
35

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

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

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

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

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

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

105
  auto cells_group = create_group(geom_group, "cells");
4,028✔
106
  for (const auto& c : model::cells)
19,511✔
107
    c->to_hdf5(cells_group);
15,483✔
108
  close_group(cells_group);
4,028✔
109

110
  auto surfaces_group = create_group(geom_group, "surfaces");
4,028✔
111
  for (const auto& surf : model::surfaces)
26,917✔
112
    surf->to_hdf5(surfaces_group);
22,889✔
113
  close_group(surfaces_group);
4,028✔
114

115
  auto universes_group = create_group(geom_group, "universes");
4,028✔
116
  for (const auto& u : model::universes)
11,559✔
117
    u->to_hdf5(universes_group);
7,531✔
118
  close_group(universes_group);
4,028✔
119

120
  auto lattices_group = create_group(geom_group, "lattices");
4,028✔
121
  for (const auto& lat : model::lattices)
5,106✔
122
    lat->to_hdf5(lattices_group);
1,078✔
123
  close_group(lattices_group);
4,028✔
124

125
  close_group(geom_group);
4,028✔
126
}
4,028✔
127

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

133
  hid_t materials_group = create_group(file, "materials");
4,028✔
134
  for (const auto& mat : model::materials) {
10,794✔
135
    mat->to_hdf5(materials_group);
6,766✔
136
  }
137
  close_group(materials_group);
4,028✔
138
}
4,028✔
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