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

openmc-dev / openmc / 12776996362

14 Jan 2025 09:49PM UTC coverage: 84.938% (+0.2%) from 84.729%
12776996362

Pull #3133

github

web-flow
Merge 0495246d9 into 549cc0973
Pull Request #3133: Kinetics parameters using Iterated Fission Probability

318 of 330 new or added lines in 10 files covered. (96.36%)

1658 existing lines in 66 files now uncovered.

50402 of 59340 relevant lines covered (84.94%)

33987813.96 hits per line

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

83.91
/src/plot.cpp
1
#include "openmc/plot.h"
2

3
#include <algorithm>
4
#define _USE_MATH_DEFINES // to make M_PI declared in Intel and MSVC compilers
5
#include <cmath>
6
#include <cstdio>
7
#include <fstream>
8
#include <sstream>
9

10
#include "xtensor/xmanipulation.hpp"
11
#include "xtensor/xview.hpp"
12
#include <fmt/core.h>
13
#include <fmt/ostream.h>
14
#ifdef USE_LIBPNG
15
#include <png.h>
16
#endif
17

18
#include "openmc/constants.h"
19
#include "openmc/container_util.h"
20
#include "openmc/dagmc.h"
21
#include "openmc/error.h"
22
#include "openmc/file_utils.h"
23
#include "openmc/geometry.h"
24
#include "openmc/hdf5_interface.h"
25
#include "openmc/material.h"
26
#include "openmc/mesh.h"
27
#include "openmc/message_passing.h"
28
#include "openmc/openmp_interface.h"
29
#include "openmc/output.h"
30
#include "openmc/particle.h"
31
#include "openmc/progress_bar.h"
32
#include "openmc/random_lcg.h"
33
#include "openmc/settings.h"
34
#include "openmc/simulation.h"
35
#include "openmc/string_utils.h"
36

37
namespace openmc {
38

39
//==============================================================================
40
// Constants
41
//==============================================================================
42

43
constexpr int PLOT_LEVEL_LOWEST {-1}; //!< lower bound on plot universe level
44
constexpr int32_t NOT_FOUND {-2};
45
constexpr int32_t OVERLAP {-3};
46

47
IdData::IdData(size_t h_res, size_t v_res) : data_({v_res, h_res, 3}, NOT_FOUND)
5,484✔
48
{}
5,484✔
49

50
void IdData::set_value(size_t y, size_t x, const GeometryState& p, int level)
40,887,708✔
51
{
52
  // set cell data
53
  if (p.n_coord() <= level) {
40,887,708✔
UNCOV
54
    data_(y, x, 0) = NOT_FOUND;
×
UNCOV
55
    data_(y, x, 1) = NOT_FOUND;
×
56
  } else {
57
    data_(y, x, 0) = model::cells.at(p.coord(level).cell)->id_;
40,887,708✔
58
    data_(y, x, 1) = level == p.n_coord() - 1
81,775,416✔
59
                       ? p.cell_instance()
40,887,708✔
UNCOV
60
                       : cell_instance_at_level(p, level);
×
61
  }
62

63
  // set material data
64
  Cell* c = model::cells.at(p.lowest_coord().cell).get();
40,887,708✔
65
  if (p.material() == MATERIAL_VOID) {
40,887,708✔
66
    data_(y, x, 2) = MATERIAL_VOID;
32,044,128✔
67
    return;
32,044,128✔
68
  } else if (c->type_ == Fill::MATERIAL) {
8,843,580✔
69
    Material* m = model::materials.at(p.material()).get();
8,843,580✔
70
    data_(y, x, 2) = m->id_;
8,843,580✔
71
  }
72
}
73

74
void IdData::set_overlap(size_t y, size_t x)
30,816✔
75
{
76
  xt::view(data_, y, x, xt::all()) = OVERLAP;
30,816✔
77
}
30,816✔
78

79
PropertyData::PropertyData(size_t h_res, size_t v_res)
12✔
80
  : data_({v_res, h_res, 2}, NOT_FOUND)
12✔
81
{}
12✔
82

83
void PropertyData::set_value(
108✔
84
  size_t y, size_t x, const GeometryState& p, int level)
85
{
86
  Cell* c = model::cells.at(p.lowest_coord().cell).get();
108✔
87
  data_(y, x, 0) = (p.sqrtkT() * p.sqrtkT()) / K_BOLTZMANN;
108✔
88
  if (c->type_ != Fill::UNIVERSE && p.material() != MATERIAL_VOID) {
108✔
89
    Material* m = model::materials.at(p.material()).get();
108✔
90
    data_(y, x, 1) = m->density_gpcc_;
108✔
91
  }
92
}
108✔
93

94
void PropertyData::set_overlap(size_t y, size_t x)
×
95
{
UNCOV
96
  data_(y, x) = OVERLAP;
×
97
}
98

99
//==============================================================================
100
// Global variables
101
//==============================================================================
102

103
namespace model {
104

105
std::unordered_map<int, int> plot_map;
106
vector<std::unique_ptr<PlottableInterface>> plots;
107
uint64_t plotter_seed = 1;
108

109
} // namespace model
110

111
//==============================================================================
112
// RUN_PLOT controls the logic for making one or many plots
113
//==============================================================================
114

115
extern "C" int openmc_plot_geometry()
288✔
116
{
117

118
  for (auto& pl : model::plots) {
720✔
119
    write_message(5, "Processing plot {}: {}...", pl->id(), pl->path_plot());
432✔
120
    pl->create_output();
432✔
121
  }
122

123
  return 0;
288✔
124
}
125

126
void Plot::create_output() const
372✔
127
{
128
  if (PlotType::slice == type_) {
372✔
129
    // create 2D image
130
    create_image();
312✔
131
  } else if (PlotType::voxel == type_) {
60✔
132
    // create voxel file for 3D viewing
133
    create_voxel();
60✔
134
  }
135
}
372✔
136

137
void Plot::print_info() const
348✔
138
{
139
  // Plot type
140
  if (PlotType::slice == type_) {
348✔
141
    fmt::print("Plot Type: Slice\n");
288✔
142
  } else if (PlotType::voxel == type_) {
60✔
143
    fmt::print("Plot Type: Voxel\n");
60✔
144
  }
145

146
  // Plot parameters
147
  fmt::print("Origin: {} {} {}\n", origin_[0], origin_[1], origin_[2]);
638✔
148

149
  if (PlotType::slice == type_) {
348✔
150
    fmt::print("Width: {:4} {:4}\n", width_[0], width_[1]);
576✔
151
  } else if (PlotType::voxel == type_) {
60✔
152
    fmt::print("Width: {:4} {:4} {:4}\n", width_[0], width_[1], width_[2]);
120✔
153
  }
154

155
  if (PlotColorBy::cells == color_by_) {
348✔
156
    fmt::print("Coloring: Cells\n");
240✔
157
  } else if (PlotColorBy::mats == color_by_) {
108✔
158
    fmt::print("Coloring: Materials\n");
108✔
159
  }
160

161
  if (PlotType::slice == type_) {
348✔
162
    switch (basis_) {
288✔
163
    case PlotBasis::xy:
168✔
164
      fmt::print("Basis: XY\n");
140✔
165
      break;
168✔
166
    case PlotBasis::xz:
60✔
167
      fmt::print("Basis: XZ\n");
50✔
168
      break;
60✔
169
    case PlotBasis::yz:
60✔
170
      fmt::print("Basis: YZ\n");
50✔
171
      break;
60✔
172
    }
173
    fmt::print("Pixels: {} {}\n", pixels_[0], pixels_[1]);
576✔
174
  } else if (PlotType::voxel == type_) {
60✔
175
    fmt::print("Voxels: {} {} {}\n", pixels_[0], pixels_[1], pixels_[2]);
120✔
176
  }
177
}
348✔
178

179
void read_plots_xml()
1,541✔
180
{
181
  // Check if plots.xml exists; this is only necessary when the plot runmode is
182
  // initiated. Otherwise, we want to read plots.xml because it may be called
183
  // later via the API. In that case, its ok for a plots.xml to not exist
184
  std::string filename = settings::path_input + "plots.xml";
1,541✔
185
  if (!file_exists(filename) && settings::run_mode == RunMode::PLOTTING) {
1,541✔
UNCOV
186
    fatal_error(fmt::format("Plots XML file '{}' does not exist!", filename));
×
187
  }
188

189
  write_message("Reading plot XML file...", 5);
1,541✔
190

191
  // Parse plots.xml file
192
  pugi::xml_document doc;
1,541✔
193
  doc.load_file(filename.c_str());
1,541✔
194

195
  pugi::xml_node root = doc.document_element();
1,541✔
196

197
  read_plots_xml(root);
1,541✔
198
}
1,541✔
199

200
void read_plots_xml(pugi::xml_node root)
1,988✔
201
{
202
  for (auto node : root.children("plot")) {
2,918✔
203
    std::string id_string = get_node_value(node, "id", true);
940✔
204
    int id = std::stoi(id_string);
940✔
205
    if (check_for_node(node, "type")) {
940✔
206
      std::string type_str = get_node_value(node, "type", true);
940✔
207
      if (type_str == "slice")
940✔
208
        model::plots.emplace_back(
810✔
209
          std::make_unique<Plot>(node, Plot::PlotType::slice));
1,630✔
210
      else if (type_str == "voxel")
120✔
211
        model::plots.emplace_back(
60✔
212
          std::make_unique<Plot>(node, Plot::PlotType::voxel));
120✔
213
      else if (type_str == "projection")
60✔
214
        model::plots.emplace_back(std::make_unique<ProjectionPlot>(node));
60✔
215
      else
UNCOV
216
        fatal_error(
×
UNCOV
217
          fmt::format("Unsupported plot type '{}' in plot {}", type_str, id));
×
218

219
      model::plot_map[model::plots.back()->id()] = model::plots.size() - 1;
930✔
220
    } else {
930✔
UNCOV
221
      fatal_error(fmt::format("Must specify plot type in plot {}", id));
×
222
    }
223
  }
930✔
224
}
1,978✔
225

226
void free_memory_plot()
6,931✔
227
{
228
  model::plots.clear();
6,931✔
229
  model::plot_map.clear();
6,931✔
230
}
6,931✔
231

232
// creates an image based on user input from a plots.xml <plot>
233
// specification in the PNG/PPM format
234
void Plot::create_image() const
312✔
235
{
236

237
  size_t width = pixels_[0];
312✔
238
  size_t height = pixels_[1];
312✔
239

240
  ImageData data({width, height}, not_found_);
312✔
241

242
  // generate ids for the plot
243
  auto ids = get_map<IdData>();
312✔
244

245
  // assign colors
246
  for (size_t y = 0; y < height; y++) {
49,176✔
247
    for (size_t x = 0; x < width; x++) {
11,216,808✔
248
      int idx = color_by_ == PlotColorBy::cells ? 0 : 2;
11,167,944✔
249
      auto id = ids.data_(y, x, idx);
11,167,944✔
250
      // no setting needed if not found
251
      if (id == NOT_FOUND) {
11,167,944✔
252
        continue;
1,800,552✔
253
      }
254
      if (id == OVERLAP) {
9,398,208✔
255
        data(x, y) = overlap_color_;
30,816✔
256
        continue;
30,816✔
257
      }
258
      if (PlotColorBy::cells == color_by_) {
9,367,392✔
259
        data(x, y) = colors_[model::cell_map[id]];
5,549,712✔
260
      } else if (PlotColorBy::mats == color_by_) {
3,817,680✔
261
        if (id == MATERIAL_VOID) {
3,817,680✔
UNCOV
262
          data(x, y) = WHITE;
×
UNCOV
263
          continue;
×
264
        }
265
        data(x, y) = colors_[model::material_map[id]];
3,817,680✔
266
      } // color_by if-else
267
    }   // x for loop
268
  }     // y for loop
269

270
  // draw mesh lines if present
271
  if (index_meshlines_mesh_ >= 0) {
312✔
272
    draw_mesh_lines(data);
36✔
273
  }
274

275
// create image file
276
#ifdef USE_LIBPNG
277
  output_png(path_plot(), data);
312✔
278
#else
279
  output_ppm(path_plot(), data);
280
#endif
281
}
312✔
282

283
void PlottableInterface::set_id(pugi::xml_node plot_node)
940✔
284
{
285
  // Copy data into plots
286
  if (check_for_node(plot_node, "id")) {
940✔
287
    id_ = std::stoi(get_node_value(plot_node, "id"));
940✔
288
  } else {
UNCOV
289
    fatal_error("Must specify plot id in plots XML file.");
×
290
  }
291

292
  // Check to make sure 'id' hasn't been used
293
  if (model::plot_map.find(id_) != model::plot_map.end()) {
940✔
UNCOV
294
    fatal_error(
×
UNCOV
295
      fmt::format("Two or more plots use the same unique ID: {}", id_));
×
296
  }
297
}
940✔
298

299
// Checks if png or ppm is already present
300
bool file_extension_present(
930✔
301
  const std::string& filename, const std::string& extension)
302
{
303
  std::string file_extension_if_present =
304
    filename.substr(filename.find_last_of(".") + 1);
930✔
305
  if (file_extension_if_present == extension)
930✔
306
    return true;
24✔
307
  return false;
906✔
308
}
930✔
309

310
void Plot::set_output_path(pugi::xml_node plot_node)
880✔
311
{
312
  // Set output file path
313
  std::string filename;
880✔
314

315
  if (check_for_node(plot_node, "filename")) {
880✔
316
    filename = get_node_value(plot_node, "filename");
268✔
317
  } else {
318
    filename = fmt::format("plot_{}", id());
1,224✔
319
  }
320
  const std::string dir_if_present =
321
    filename.substr(0, filename.find_last_of("/") + 1);
880✔
322
  if (dir_if_present.size() > 0 && !dir_exists(dir_if_present)) {
880✔
323
    fatal_error(fmt::format("Directory '{}' does not exist!", dir_if_present));
10✔
324
  }
325
  // add appropriate file extension to name
326
  switch (type_) {
870✔
327
  case PlotType::slice:
810✔
328
#ifdef USE_LIBPNG
329
    if (!file_extension_present(filename, "png"))
810✔
330
      filename.append(".png");
810✔
331
#else
332
    if (!file_extension_present(filename, "ppm"))
333
      filename.append(".ppm");
334
#endif
335
    break;
810✔
336
  case PlotType::voxel:
60✔
337
    if (!file_extension_present(filename, "h5"))
60✔
338
      filename.append(".h5");
60✔
339
    break;
60✔
340
  }
341

342
  path_plot_ = filename;
870✔
343

344
  // Copy plot pixel size
345
  vector<int> pxls = get_node_array<int>(plot_node, "pixels");
1,740✔
346
  if (PlotType::slice == type_) {
870✔
347
    if (pxls.size() == 2) {
810✔
348
      pixels_[0] = pxls[0];
810✔
349
      pixels_[1] = pxls[1];
810✔
350
    } else {
UNCOV
351
      fatal_error(
×
UNCOV
352
        fmt::format("<pixels> must be length 2 in slice plot {}", id()));
×
353
    }
354
  } else if (PlotType::voxel == type_) {
60✔
355
    if (pxls.size() == 3) {
60✔
356
      pixels_[0] = pxls[0];
60✔
357
      pixels_[1] = pxls[1];
60✔
358
      pixels_[2] = pxls[2];
60✔
359
    } else {
UNCOV
360
      fatal_error(
×
UNCOV
361
        fmt::format("<pixels> must be length 3 in voxel plot {}", id()));
×
362
    }
363
  }
364
}
870✔
365

366
void PlottableInterface::set_bg_color(pugi::xml_node plot_node)
940✔
367
{
368
  // Copy plot background color
369
  if (check_for_node(plot_node, "background")) {
940✔
370
    vector<int> bg_rgb = get_node_array<int>(plot_node, "background");
48✔
371
    if (bg_rgb.size() == 3) {
48✔
372
      not_found_ = bg_rgb;
48✔
373
    } else {
UNCOV
374
      fatal_error(fmt::format("Bad background RGB in plot {}", id()));
×
375
    }
376
  }
48✔
377
}
940✔
378

379
void Plot::set_basis(pugi::xml_node plot_node)
870✔
380
{
381
  // Copy plot basis
382
  if (PlotType::slice == type_) {
870✔
383
    std::string pl_basis = "xy";
810✔
384
    if (check_for_node(plot_node, "basis")) {
810✔
385
      pl_basis = get_node_value(plot_node, "basis", true);
810✔
386
    }
387
    if ("xy" == pl_basis) {
810✔
388
      basis_ = PlotBasis::xy;
656✔
389
    } else if ("xz" == pl_basis) {
154✔
390
      basis_ = PlotBasis::xz;
60✔
391
    } else if ("yz" == pl_basis) {
94✔
392
      basis_ = PlotBasis::yz;
94✔
393
    } else {
UNCOV
394
      fatal_error(
×
UNCOV
395
        fmt::format("Unsupported plot basis '{}' in plot {}", pl_basis, id()));
×
396
    }
397
  }
810✔
398
}
870✔
399

400
void Plot::set_origin(pugi::xml_node plot_node)
870✔
401
{
402
  // Copy plotting origin
403
  auto pl_origin = get_node_array<double>(plot_node, "origin");
870✔
404
  if (pl_origin.size() == 3) {
870✔
405
    origin_ = pl_origin;
870✔
406
  } else {
UNCOV
407
    fatal_error(fmt::format("Origin must be length 3 in plot {}", id()));
×
408
  }
409
}
870✔
410

411
void Plot::set_width(pugi::xml_node plot_node)
870✔
412
{
413
  // Copy plotting width
414
  vector<double> pl_width = get_node_array<double>(plot_node, "width");
870✔
415
  if (PlotType::slice == type_) {
870✔
416
    if (pl_width.size() == 2) {
810✔
417
      width_.x = pl_width[0];
810✔
418
      width_.y = pl_width[1];
810✔
419
    } else {
UNCOV
420
      fatal_error(
×
UNCOV
421
        fmt::format("<width> must be length 2 in slice plot {}", id()));
×
422
    }
423
  } else if (PlotType::voxel == type_) {
60✔
424
    if (pl_width.size() == 3) {
60✔
425
      pl_width = get_node_array<double>(plot_node, "width");
60✔
426
      width_ = pl_width;
60✔
427
    } else {
UNCOV
428
      fatal_error(
×
UNCOV
429
        fmt::format("<width> must be length 3 in voxel plot {}", id()));
×
430
    }
431
  }
432
}
870✔
433

434
void PlottableInterface::set_universe(pugi::xml_node plot_node)
940✔
435
{
436
  // Copy plot universe level
437
  if (check_for_node(plot_node, "level")) {
940✔
438
    level_ = std::stoi(get_node_value(plot_node, "level"));
×
UNCOV
439
    if (level_ < 0) {
×
UNCOV
440
      fatal_error(fmt::format("Bad universe level in plot {}", id()));
×
441
    }
442
  } else {
443
    level_ = PLOT_LEVEL_LOWEST;
940✔
444
  }
445
}
940✔
446

447
void PlottableInterface::set_default_colors(pugi::xml_node plot_node)
940✔
448
{
449
  // Copy plot color type and initialize all colors randomly
450
  std::string pl_color_by = "cell";
940✔
451
  if (check_for_node(plot_node, "color_by")) {
940✔
452
    pl_color_by = get_node_value(plot_node, "color_by", true);
904✔
453
  }
454
  if ("cell" == pl_color_by) {
940✔
455
    color_by_ = PlotColorBy::cells;
435✔
456
    colors_.resize(model::cells.size());
435✔
457
  } else if ("material" == pl_color_by) {
505✔
458
    color_by_ = PlotColorBy::mats;
505✔
459
    colors_.resize(model::materials.size());
505✔
460
  } else {
UNCOV
461
    fatal_error(fmt::format(
×
UNCOV
462
      "Unsupported plot color type '{}' in plot {}", pl_color_by, id()));
×
463
  }
464

465
  for (auto& c : colors_) {
4,051✔
466
    c = random_color();
3,111✔
467
    // make sure we don't interfere with some default colors
468
    while (c == RED || c == WHITE) {
3,111✔
UNCOV
469
      c = random_color();
×
470
    }
471
  }
472
}
940✔
473

474
void PlottableInterface::set_user_colors(pugi::xml_node plot_node)
940✔
475
{
476
  for (auto cn : plot_node.children("color")) {
1,180✔
477
    // Make sure 3 values are specified for RGB
478
    vector<int> user_rgb = get_node_array<int>(cn, "rgb");
240✔
479
    if (user_rgb.size() != 3) {
240✔
UNCOV
480
      fatal_error(fmt::format("Bad RGB in plot {}", id()));
×
481
    }
482
    // Ensure that there is an id for this color specification
483
    int col_id;
484
    if (check_for_node(cn, "id")) {
240✔
485
      col_id = std::stoi(get_node_value(cn, "id"));
240✔
486
    } else {
UNCOV
487
      fatal_error(fmt::format(
×
UNCOV
488
        "Must specify id for color specification in plot {}", id()));
×
489
    }
490
    // Add RGB
491
    if (PlotColorBy::cells == color_by_) {
240✔
492
      if (model::cell_map.find(col_id) != model::cell_map.end()) {
132✔
493
        col_id = model::cell_map[col_id];
96✔
494
        colors_[col_id] = user_rgb;
96✔
495
      } else {
496
        warning(fmt::format(
36✔
497
          "Could not find cell {} specified in plot {}", col_id, id()));
72✔
498
      }
499
    } else if (PlotColorBy::mats == color_by_) {
108✔
500
      if (model::material_map.find(col_id) != model::material_map.end()) {
108✔
501
        col_id = model::material_map[col_id];
108✔
502
        colors_[col_id] = user_rgb;
108✔
503
      } else {
UNCOV
504
        warning(fmt::format(
×
UNCOV
505
          "Could not find material {} specified in plot {}", col_id, id()));
×
506
      }
507
    }
508
  } // color node loop
240✔
509
}
940✔
510

511
void Plot::set_meshlines(pugi::xml_node plot_node)
870✔
512
{
513
  // Deal with meshlines
514
  pugi::xpath_node_set mesh_line_nodes = plot_node.select_nodes("meshlines");
870✔
515

516
  if (!mesh_line_nodes.empty()) {
870✔
517
    if (PlotType::voxel == type_) {
36✔
UNCOV
518
      warning(fmt::format("Meshlines ignored in voxel plot {}", id()));
×
519
    }
520

521
    if (mesh_line_nodes.size() == 1) {
36✔
522
      // Get first meshline node
523
      pugi::xml_node meshlines_node = mesh_line_nodes[0].node();
36✔
524

525
      // Check mesh type
526
      std::string meshtype;
36✔
527
      if (check_for_node(meshlines_node, "meshtype")) {
36✔
528
        meshtype = get_node_value(meshlines_node, "meshtype");
36✔
529
      } else {
530
        fatal_error(fmt::format(
×
531
          "Must specify a meshtype for meshlines specification in plot {}",
UNCOV
532
          id()));
×
533
      }
534

535
      // Ensure that there is a linewidth for this meshlines specification
536
      std::string meshline_width;
36✔
537
      if (check_for_node(meshlines_node, "linewidth")) {
36✔
538
        meshline_width = get_node_value(meshlines_node, "linewidth");
36✔
539
        meshlines_width_ = std::stoi(meshline_width);
36✔
540
      } else {
541
        fatal_error(fmt::format(
×
542
          "Must specify a linewidth for meshlines specification in plot {}",
UNCOV
543
          id()));
×
544
      }
545

546
      // Check for color
547
      if (check_for_node(meshlines_node, "color")) {
36✔
548
        // Check and make sure 3 values are specified for RGB
549
        vector<int> ml_rgb = get_node_array<int>(meshlines_node, "color");
×
550
        if (ml_rgb.size() != 3) {
×
UNCOV
551
          fatal_error(
×
552
            fmt::format("Bad RGB for meshlines color in plot {}", id()));
×
553
        }
UNCOV
554
        meshlines_color_ = ml_rgb;
×
555
      }
556

557
      // Set mesh based on type
558
      if ("ufs" == meshtype) {
36✔
559
        if (!simulation::ufs_mesh) {
×
UNCOV
560
          fatal_error(
×
561
            fmt::format("No UFS mesh for meshlines on plot {}", id()));
×
562
        } else {
563
          for (int i = 0; i < model::meshes.size(); ++i) {
×
564
            if (const auto* m =
×
565
                  dynamic_cast<const RegularMesh*>(model::meshes[i].get())) {
×
UNCOV
566
              if (m == simulation::ufs_mesh) {
×
UNCOV
567
                index_meshlines_mesh_ = i;
×
568
              }
569
            }
570
          }
UNCOV
571
          if (index_meshlines_mesh_ == -1)
×
UNCOV
572
            fatal_error("Could not find the UFS mesh for meshlines plot");
×
573
        }
574
      } else if ("entropy" == meshtype) {
36✔
575
        if (!simulation::entropy_mesh) {
24✔
UNCOV
576
          fatal_error(
×
UNCOV
577
            fmt::format("No entropy mesh for meshlines on plot {}", id()));
×
578
        } else {
579
          for (int i = 0; i < model::meshes.size(); ++i) {
60✔
580
            if (const auto* m =
36✔
581
                  dynamic_cast<const RegularMesh*>(model::meshes[i].get())) {
36✔
582
              if (m == simulation::entropy_mesh) {
24✔
583
                index_meshlines_mesh_ = i;
24✔
584
              }
585
            }
586
          }
587
          if (index_meshlines_mesh_ == -1)
24✔
UNCOV
588
            fatal_error("Could not find the entropy mesh for meshlines plot");
×
589
        }
590
      } else if ("tally" == meshtype) {
12✔
591
        // Ensure that there is a mesh id if the type is tally
592
        int tally_mesh_id;
593
        if (check_for_node(meshlines_node, "id")) {
12✔
594
          tally_mesh_id = std::stoi(get_node_value(meshlines_node, "id"));
12✔
595
        } else {
UNCOV
596
          std::stringstream err_msg;
×
597
          fatal_error(fmt::format("Must specify a mesh id for meshlines tally "
×
598
                                  "mesh specification in plot {}",
UNCOV
599
            id()));
×
UNCOV
600
        }
×
601
        // find the tally index
602
        int idx;
603
        int err = openmc_get_mesh_index(tally_mesh_id, &idx);
12✔
604
        if (err != 0) {
12✔
605
          fatal_error(fmt::format("Could not find mesh {} specified in "
×
606
                                  "meshlines for plot {}",
UNCOV
607
            tally_mesh_id, id()));
×
608
        }
609
        index_meshlines_mesh_ = idx;
12✔
610
      } else {
UNCOV
611
        fatal_error(fmt::format("Invalid type for meshlines on plot {}", id()));
×
612
      }
613
    } else {
36✔
UNCOV
614
      fatal_error(fmt::format("Mutliple meshlines specified in plot {}", id()));
×
615
    }
616
  }
617
}
870✔
618

619
void PlottableInterface::set_mask(pugi::xml_node plot_node)
940✔
620
{
621
  // Deal with masks
622
  pugi::xpath_node_set mask_nodes = plot_node.select_nodes("mask");
940✔
623

624
  if (!mask_nodes.empty()) {
940✔
625
    if (mask_nodes.size() == 1) {
36✔
626
      // Get pointer to mask
627
      pugi::xml_node mask_node = mask_nodes[0].node();
36✔
628

629
      // Determine how many components there are and allocate
630
      vector<int> iarray = get_node_array<int>(mask_node, "components");
36✔
631
      if (iarray.size() == 0) {
36✔
UNCOV
632
        fatal_error(
×
UNCOV
633
          fmt::format("Missing <components> in mask of plot {}", id()));
×
634
      }
635

636
      // First we need to change the user-specified identifiers to indices
637
      // in the cell and material arrays
638
      for (auto& col_id : iarray) {
108✔
639
        if (PlotColorBy::cells == color_by_) {
72✔
640
          if (model::cell_map.find(col_id) != model::cell_map.end()) {
72✔
641
            col_id = model::cell_map[col_id];
72✔
642
          } else {
643
            fatal_error(fmt::format("Could not find cell {} specified in the "
×
644
                                    "mask in plot {}",
645
              col_id, id()));
×
646
          }
647
        } else if (PlotColorBy::mats == color_by_) {
×
UNCOV
648
          if (model::material_map.find(col_id) != model::material_map.end()) {
×
649
            col_id = model::material_map[col_id];
×
650
          } else {
651
            fatal_error(fmt::format("Could not find material {} specified in "
×
652
                                    "the mask in plot {}",
UNCOV
653
              col_id, id()));
×
654
          }
655
        }
656
      }
657

658
      // Alter colors based on mask information
659
      for (int j = 0; j < colors_.size(); j++) {
144✔
660
        if (contains(iarray, j)) {
108✔
661
          if (check_for_node(mask_node, "background")) {
72✔
662
            vector<int> bg_rgb = get_node_array<int>(mask_node, "background");
72✔
663
            colors_[j] = bg_rgb;
72✔
664
          } else {
72✔
UNCOV
665
            colors_[j] = WHITE;
×
666
          }
667
        }
668
      }
669

670
    } else {
36✔
UNCOV
671
      fatal_error(fmt::format("Mutliple masks specified in plot {}", id()));
×
672
    }
673
  }
674
}
940✔
675

676
void PlottableInterface::set_overlap_color(pugi::xml_node plot_node)
940✔
677
{
678
  color_overlaps_ = false;
940✔
679
  if (check_for_node(plot_node, "show_overlaps")) {
940✔
680
    color_overlaps_ = get_node_value_bool(plot_node, "show_overlaps");
24✔
681
    // check for custom overlap color
682
    if (check_for_node(plot_node, "overlap_color")) {
24✔
683
      if (!color_overlaps_) {
12✔
684
        warning(fmt::format(
×
685
          "Overlap color specified in plot {} but overlaps won't be shown.",
UNCOV
686
          id()));
×
687
      }
688
      vector<int> olap_clr = get_node_array<int>(plot_node, "overlap_color");
12✔
689
      if (olap_clr.size() == 3) {
12✔
690
        overlap_color_ = olap_clr;
12✔
691
      } else {
UNCOV
692
        fatal_error(fmt::format("Bad overlap RGB in plot {}", id()));
×
693
      }
694
    }
12✔
695
  }
696

697
  // make sure we allocate the vector for counting overlap checks if
698
  // they're going to be plotted
699
  if (color_overlaps_ && settings::run_mode == RunMode::PLOTTING) {
940✔
700
    settings::check_overlaps = true;
24✔
701
    model::overlap_check_count.resize(model::cells.size(), 0);
24✔
702
  }
703
}
940✔
704

705
PlottableInterface::PlottableInterface(pugi::xml_node plot_node)
940✔
706
{
707
  set_id(plot_node);
940✔
708
  set_bg_color(plot_node);
940✔
709
  set_universe(plot_node);
940✔
710
  set_default_colors(plot_node);
940✔
711
  set_user_colors(plot_node);
940✔
712
  set_mask(plot_node);
940✔
713
  set_overlap_color(plot_node);
940✔
714
}
940✔
715

716
Plot::Plot(pugi::xml_node plot_node, PlotType type)
880✔
717
  : PlottableInterface(plot_node), type_(type), index_meshlines_mesh_ {-1}
880✔
718
{
719
  set_output_path(plot_node);
880✔
720
  set_basis(plot_node);
870✔
721
  set_origin(plot_node);
870✔
722
  set_width(plot_node);
870✔
723
  set_meshlines(plot_node);
870✔
724
  slice_level_ = level_; // Copy level employed in SlicePlotBase::get_map
870✔
725
  slice_color_overlaps_ = color_overlaps_;
870✔
726
}
870✔
727

728
//==============================================================================
729
// OUTPUT_PPM writes out a previously generated image to a PPM file
730
//==============================================================================
731

UNCOV
732
void output_ppm(const std::string& filename, const ImageData& data)
×
733
{
734
  // Open PPM file for writing
735
  std::string fname = filename;
×
UNCOV
736
  fname = strtrim(fname);
×
737
  std::ofstream of;
×
738

UNCOV
739
  of.open(fname);
×
740

741
  // Write header
742
  of << "P6\n";
×
743
  of << data.shape()[0] << " " << data.shape()[1] << "\n";
×
UNCOV
744
  of << "255\n";
×
745
  of.close();
×
746

747
  of.open(fname, std::ios::binary | std::ios::app);
×
748
  // Write color for each pixel
749
  for (int y = 0; y < data.shape()[1]; y++) {
×
750
    for (int x = 0; x < data.shape()[0]; x++) {
×
UNCOV
751
      RGBColor rgb = data(x, y);
×
UNCOV
752
      of << rgb.red << rgb.green << rgb.blue;
×
753
    }
754
  }
UNCOV
755
  of << "\n";
×
756
}
757

758
//==============================================================================
759
// OUTPUT_PNG writes out a previously generated image to a PNG file
760
//==============================================================================
761

762
#ifdef USE_LIBPNG
763
void output_png(const std::string& filename, const ImageData& data)
372✔
764
{
765
  // Open PNG file for writing
766
  std::string fname = filename;
372✔
767
  fname = strtrim(fname);
372✔
768
  auto fp = std::fopen(fname.c_str(), "wb");
372✔
769

770
  // Initialize write and info structures
771
  auto png_ptr =
772
    png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
372✔
773
  auto info_ptr = png_create_info_struct(png_ptr);
372✔
774

775
  // Setup exception handling
776
  if (setjmp(png_jmpbuf(png_ptr)))
372✔
UNCOV
777
    fatal_error("Error during png creation");
×
778

779
  png_init_io(png_ptr, fp);
372✔
780

781
  // Write header (8 bit colour depth)
782
  int width = data.shape()[0];
372✔
783
  int height = data.shape()[1];
372✔
784
  png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB,
372✔
785
    PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
786
  png_write_info(png_ptr, info_ptr);
372✔
787

788
  // Allocate memory for one row (3 bytes per pixel - RGB)
789
  std::vector<png_byte> row(3 * width);
372✔
790

791
  // Write color for each pixel
792
  for (int y = 0; y < height; y++) {
61,236✔
793
    for (int x = 0; x < width; x++) {
13,628,808✔
794
      RGBColor rgb = data(x, y);
13,567,944✔
795
      row[3 * x] = rgb.red;
13,567,944✔
796
      row[3 * x + 1] = rgb.green;
13,567,944✔
797
      row[3 * x + 2] = rgb.blue;
13,567,944✔
798
    }
799
    png_write_row(png_ptr, row.data());
60,864✔
800
  }
801

802
  // End write
803
  png_write_end(png_ptr, nullptr);
372✔
804

805
  // Clean up data structures
806
  std::fclose(fp);
372✔
807
  png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
372✔
808
  png_destroy_write_struct(&png_ptr, &info_ptr);
372✔
809
}
372✔
810
#endif
811

812
//==============================================================================
813
// DRAW_MESH_LINES draws mesh line boundaries on an image
814
//==============================================================================
815

816
void Plot::draw_mesh_lines(ImageData& data) const
36✔
817
{
818
  RGBColor rgb;
36✔
819
  rgb = meshlines_color_;
36✔
820

821
  int ax1, ax2;
822
  switch (basis_) {
36✔
823
  case PlotBasis::xy:
24✔
824
    ax1 = 0;
24✔
825
    ax2 = 1;
24✔
826
    break;
24✔
827
  case PlotBasis::xz:
12✔
828
    ax1 = 0;
12✔
829
    ax2 = 2;
12✔
830
    break;
12✔
831
  case PlotBasis::yz:
×
832
    ax1 = 1;
×
833
    ax2 = 2;
×
834
    break;
×
UNCOV
835
  default:
×
UNCOV
836
    UNREACHABLE();
×
837
  }
838

839
  Position ll_plot {origin_};
36✔
840
  Position ur_plot {origin_};
36✔
841

842
  ll_plot[ax1] -= width_[0] / 2.;
36✔
843
  ll_plot[ax2] -= width_[1] / 2.;
36✔
844
  ur_plot[ax1] += width_[0] / 2.;
36✔
845
  ur_plot[ax2] += width_[1] / 2.;
36✔
846

847
  Position width = ur_plot - ll_plot;
36✔
848

849
  // Find the (axis-aligned) lines of the mesh that intersect this plot.
850
  auto axis_lines =
851
    model::meshes[index_meshlines_mesh_]->plot(ll_plot, ur_plot);
36✔
852

853
  // Find the bounds along the second axis (accounting for low-D meshes).
854
  int ax2_min, ax2_max;
855
  if (axis_lines.second.size() > 0) {
36✔
856
    double frac = (axis_lines.second.back() - ll_plot[ax2]) / width[ax2];
36✔
857
    ax2_min = (1.0 - frac) * pixels_[1];
36✔
858
    if (ax2_min < 0)
36✔
UNCOV
859
      ax2_min = 0;
×
860
    frac = (axis_lines.second.front() - ll_plot[ax2]) / width[ax2];
36✔
861
    ax2_max = (1.0 - frac) * pixels_[1];
36✔
862
    if (ax2_max > pixels_[1])
36✔
863
      ax2_max = pixels_[1];
×
864
  } else {
UNCOV
865
    ax2_min = 0;
×
UNCOV
866
    ax2_max = pixels_[1];
×
867
  }
868

869
  // Iterate across the first axis and draw lines.
870
  for (auto ax1_val : axis_lines.first) {
204✔
871
    double frac = (ax1_val - ll_plot[ax1]) / width[ax1];
168✔
872
    int ax1_ind = frac * pixels_[0];
168✔
873
    for (int ax2_ind = ax2_min; ax2_ind < ax2_max; ++ax2_ind) {
27,216✔
874
      for (int plus = 0; plus <= meshlines_width_; plus++) {
54,096✔
875
        if (ax1_ind + plus >= 0 && ax1_ind + plus < pixels_[0])
27,048✔
876
          data(ax1_ind + plus, ax2_ind) = rgb;
27,048✔
877
        if (ax1_ind - plus >= 0 && ax1_ind - plus < pixels_[0])
27,048✔
878
          data(ax1_ind - plus, ax2_ind) = rgb;
27,048✔
879
      }
880
    }
881
  }
882

883
  // Find the bounds along the first axis.
884
  int ax1_min, ax1_max;
885
  if (axis_lines.first.size() > 0) {
36✔
886
    double frac = (axis_lines.first.front() - ll_plot[ax1]) / width[ax1];
36✔
887
    ax1_min = frac * pixels_[0];
36✔
888
    if (ax1_min < 0)
36✔
UNCOV
889
      ax1_min = 0;
×
890
    frac = (axis_lines.first.back() - ll_plot[ax1]) / width[ax1];
36✔
891
    ax1_max = frac * pixels_[0];
36✔
892
    if (ax1_max > pixels_[0])
36✔
893
      ax1_max = pixels_[0];
×
894
  } else {
UNCOV
895
    ax1_min = 0;
×
UNCOV
896
    ax1_max = pixels_[0];
×
897
  }
898

899
  // Iterate across the second axis and draw lines.
900
  for (auto ax2_val : axis_lines.second) {
228✔
901
    double frac = (ax2_val - ll_plot[ax2]) / width[ax2];
192✔
902
    int ax2_ind = (1.0 - frac) * pixels_[1];
192✔
903
    for (int ax1_ind = ax1_min; ax1_ind < ax1_max; ++ax1_ind) {
30,912✔
904
      for (int plus = 0; plus <= meshlines_width_; plus++) {
61,440✔
905
        if (ax2_ind + plus >= 0 && ax2_ind + plus < pixels_[1])
30,720✔
906
          data(ax1_ind, ax2_ind + plus) = rgb;
30,720✔
907
        if (ax2_ind - plus >= 0 && ax2_ind - plus < pixels_[1])
30,720✔
908
          data(ax1_ind, ax2_ind - plus) = rgb;
30,720✔
909
      }
910
    }
911
  }
912
}
36✔
913

914
/* outputs a binary file that can be input into silomesh for 3D geometry
915
 * visualization.  It works the same way as create_image by dragging a particle
916
 * across the geometry for the specified number of voxels. The first 3 int's in
917
 * the binary are the number of x, y, and z voxels.  The next 3 double's are
918
 * the widths of the voxels in the x, y, and z directions. The next 3 double's
919
 * are the x, y, and z coordinates of the lower left point. Finally the binary
920
 * is filled with entries of four int's each. Each 'row' in the binary contains
921
 * four int's: 3 for x,y,z position and 1 for cell or material id.  For 1
922
 * million voxels this produces a file of approximately 15MB.
923
 */
924
void Plot::create_voxel() const
60✔
925
{
926
  // compute voxel widths in each direction
927
  array<double, 3> vox;
928
  vox[0] = width_[0] / static_cast<double>(pixels_[0]);
60✔
929
  vox[1] = width_[1] / static_cast<double>(pixels_[1]);
60✔
930
  vox[2] = width_[2] / static_cast<double>(pixels_[2]);
60✔
931

932
  // initial particle position
933
  Position ll = origin_ - width_ / 2.;
60✔
934

935
  // Open binary plot file for writing
936
  std::ofstream of;
60✔
937
  std::string fname = std::string(path_plot_);
60✔
938
  fname = strtrim(fname);
60✔
939
  hid_t file_id = file_open(fname, 'w');
60✔
940

941
  // write header info
942
  write_attribute(file_id, "filetype", "voxel");
60✔
943
  write_attribute(file_id, "version", VERSION_VOXEL);
60✔
944
  write_attribute(file_id, "openmc_version", VERSION);
60✔
945

946
#ifdef GIT_SHA1
947
  write_attribute(file_id, "git_sha1", GIT_SHA1);
60✔
948
#endif
949

950
  // Write current date and time
951
  write_attribute(file_id, "date_and_time", time_stamp().c_str());
60✔
952
  array<int, 3> pixels;
953
  std::copy(pixels_.begin(), pixels_.end(), pixels.begin());
60✔
954
  write_attribute(file_id, "num_voxels", pixels);
60✔
955
  write_attribute(file_id, "voxel_width", vox);
60✔
956
  write_attribute(file_id, "lower_left", ll);
60✔
957

958
  // Create dataset for voxel data -- note that the dimensions are reversed
959
  // since we want the order in the file to be z, y, x
960
  hsize_t dims[3];
961
  dims[0] = pixels_[2];
60✔
962
  dims[1] = pixels_[1];
60✔
963
  dims[2] = pixels_[0];
60✔
964
  hid_t dspace, dset, memspace;
965
  voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace);
60✔
966

967
  SlicePlotBase pltbase;
60✔
968
  pltbase.width_ = width_;
60✔
969
  pltbase.origin_ = origin_;
60✔
970
  pltbase.basis_ = PlotBasis::xy;
60✔
971
  pltbase.pixels_ = pixels_;
60✔
972
  pltbase.slice_color_overlaps_ = color_overlaps_;
60✔
973

974
  ProgressBar pb;
60✔
975
  for (int z = 0; z < pixels_[2]; z++) {
5,220✔
976
    // update z coordinate
977
    pltbase.origin_.z = ll.z + z * vox[2];
5,160✔
978

979
    // generate ids using plotbase
980
    IdData ids = pltbase.get_map<IdData>();
5,160✔
981

982
    // select only cell/material ID data and flip the y-axis
983
    int idx = color_by_ == PlotColorBy::cells ? 0 : 2;
5,160✔
984
    xt::xtensor<int32_t, 2> data_slice =
985
      xt::view(ids.data_, xt::all(), xt::all(), idx);
5,160✔
986
    xt::xtensor<int32_t, 2> data_flipped = xt::flip(data_slice, 0);
5,160✔
987

988
    // Write to HDF5 dataset
989
    voxel_write_slice(z, dspace, dset, memspace, data_flipped.data());
5,160✔
990

991
    // update progress bar
992
    pb.set_value(
5,160✔
993
      100. * static_cast<double>(z + 1) / static_cast<double>((pixels_[2])));
5,160✔
994
  }
5,160✔
995

996
  voxel_finalize(dspace, dset, memspace);
60✔
997
  file_close(file_id);
60✔
998
}
60✔
999

1000
void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset,
60✔
1001
  hid_t* memspace)
1002
{
1003
  // Create dataspace/dataset for voxel data
1004
  *dspace = H5Screate_simple(3, dims, nullptr);
60✔
1005
  *dset = H5Dcreate(file_id, "data", H5T_NATIVE_INT, *dspace, H5P_DEFAULT,
60✔
1006
    H5P_DEFAULT, H5P_DEFAULT);
1007

1008
  // Create dataspace for a slice of the voxel
1009
  hsize_t dims_slice[2] {dims[1], dims[2]};
60✔
1010
  *memspace = H5Screate_simple(2, dims_slice, nullptr);
60✔
1011

1012
  // Select hyperslab in dataspace
1013
  hsize_t start[3] {0, 0, 0};
60✔
1014
  hsize_t count[3] {1, dims[1], dims[2]};
60✔
1015
  H5Sselect_hyperslab(*dspace, H5S_SELECT_SET, start, nullptr, count, nullptr);
60✔
1016
}
60✔
1017

1018
void voxel_write_slice(
5,160✔
1019
  int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf)
1020
{
1021
  hssize_t offset[3] {x, 0, 0};
5,160✔
1022
  H5Soffset_simple(dspace, offset);
5,160✔
1023
  H5Dwrite(dset, H5T_NATIVE_INT, memspace, dspace, H5P_DEFAULT, buf);
5,160✔
1024
}
5,160✔
1025

1026
void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace)
60✔
1027
{
1028
  H5Dclose(dset);
60✔
1029
  H5Sclose(dspace);
60✔
1030
  H5Sclose(memspace);
60✔
1031
}
60✔
1032

1033
RGBColor random_color(void)
3,111✔
1034
{
1035
  return {int(prn(&model::plotter_seed) * 255),
3,111✔
1036
    int(prn(&model::plotter_seed) * 255), int(prn(&model::plotter_seed) * 255)};
3,111✔
1037
}
1038

1039
ProjectionPlot::ProjectionPlot(pugi::xml_node node) : PlottableInterface(node)
60✔
1040
{
1041
  set_output_path(node);
60✔
1042
  set_look_at(node);
60✔
1043
  set_camera_position(node);
60✔
1044
  set_field_of_view(node);
60✔
1045
  set_pixels(node);
60✔
1046
  set_opacities(node);
60✔
1047
  set_orthographic_width(node);
60✔
1048
  set_wireframe_thickness(node);
60✔
1049
  set_wireframe_ids(node);
60✔
1050
  set_wireframe_color(node);
60✔
1051

1052
  if (check_for_node(node, "orthographic_width") &&
72✔
1053
      check_for_node(node, "field_of_view"))
12✔
UNCOV
1054
    fatal_error("orthographic_width and field_of_view are mutually exclusive "
×
1055
                "parameters.");
1056
}
60✔
1057

1058
void ProjectionPlot::set_wireframe_color(pugi::xml_node plot_node)
60✔
1059
{
1060
  // Copy plot background color
1061
  if (check_for_node(plot_node, "wireframe_color")) {
60✔
1062
    vector<int> w_rgb = get_node_array<int>(plot_node, "wireframe_color");
×
UNCOV
1063
    if (w_rgb.size() == 3) {
×
1064
      wireframe_color_ = w_rgb;
×
1065
    } else {
UNCOV
1066
      fatal_error(fmt::format("Bad wireframe RGB in plot {}", id()));
×
1067
    }
1068
  }
1069
}
60✔
1070

1071
void ProjectionPlot::set_output_path(pugi::xml_node node)
60✔
1072
{
1073
  // Set output file path
1074
  std::string filename;
60✔
1075

1076
  if (check_for_node(node, "filename")) {
60✔
1077
    filename = get_node_value(node, "filename");
48✔
1078
  } else {
1079
    filename = fmt::format("plot_{}", id());
24✔
1080
  }
1081

1082
#ifdef USE_LIBPNG
1083
  if (!file_extension_present(filename, "png"))
60✔
1084
    filename.append(".png");
36✔
1085
#else
1086
  if (!file_extension_present(filename, "ppm"))
1087
    filename.append(".ppm");
1088
#endif
1089
  path_plot_ = filename;
60✔
1090
}
60✔
1091

1092
// Advances to the next boundary from outside the geometry
1093
// Returns -1 if no intersection found, and the surface index
1094
// if an intersection was found.
1095
int ProjectionPlot::advance_to_boundary_from_void(GeometryState& p)
12,560,976✔
1096
{
1097
  constexpr double scoot = 1e-5;
12,560,976✔
1098
  double min_dist = {INFINITY};
12,560,976✔
1099
  auto coord = p.coord(0);
12,560,976✔
1100
  Universe* uni = model::universes[model::root_universe].get();
12,560,976✔
1101
  int intersected_surface = -1;
12,560,976✔
1102
  for (auto c_i : uni->cells_) {
50,243,904✔
1103
    auto dist = model::cells.at(c_i)->distance(coord.r, coord.u, 0, &p);
37,682,928✔
1104
    if (dist.first < min_dist) {
37,682,928✔
1105
      min_dist = dist.first;
16,415,208✔
1106
      intersected_surface = dist.second;
16,415,208✔
1107
    }
1108
  }
1109
  if (min_dist > 1e300)
12,560,976✔
1110
    return -1;
2,400,000✔
1111
  else { // advance the particle
1112
    for (int j = 0; j < p.n_coord(); ++j)
20,321,952✔
1113
      p.coord(j).r += (min_dist + scoot) * p.coord(j).u;
10,160,976✔
1114
    return std::abs(intersected_surface);
10,160,976✔
1115
  }
1116
}
1117

1118
bool ProjectionPlot::trackstack_equivalent(
4,788,000✔
1119
  const std::vector<TrackSegment>& track1,
1120
  const std::vector<TrackSegment>& track2) const
1121
{
1122
  if (wireframe_ids_.empty()) {
4,788,000✔
1123
    // Draw wireframe for all surfaces/cells/materials
1124
    if (track1.size() != track2.size())
3,830,400✔
1125
      return false;
67,368✔
1126
    for (int i = 0; i < track1.size(); ++i) {
8,036,880✔
1127
      if (track1[i].id != track2[i].id ||
8,591,496✔
1128
          track1[i].surface != track2[i].surface) {
4,295,724✔
1129
        return false;
21,924✔
1130
      }
1131
    }
1132
    return true;
3,741,108✔
1133
  } else {
1134
    // This runs in O(nm) where n is the intersection stack size
1135
    // and m is the number of IDs we are wireframing. A simpler
1136
    // algorithm can likely be found.
1137
    for (const int id : wireframe_ids_) {
1,908,588✔
1138
      int t1_i = 0;
957,600✔
1139
      int t2_i = 0;
957,600✔
1140

1141
      // Advance to first instance of the ID
1142
      while (t1_i < track1.size() && t2_i < track2.size()) {
1,052,040✔
1143
        while (t1_i < track1.size() && track1[t1_i].id != id)
542,604✔
1144
          t1_i++;
316,704✔
1145
        while (t2_i < track2.size() && track2[t2_i].id != id)
542,604✔
1146
          t2_i++;
316,704✔
1147

1148
        // This one is really important!
1149
        if ((t1_i == track1.size() && t2_i != track2.size()) ||
549,804✔
1150
            (t1_i != track1.size() && t2_i == track2.size()))
323,904✔
1151
          return false;
6,612✔
1152
        if (t1_i == track1.size() && t2_i == track2.size())
222,912✔
1153
          break;
124,848✔
1154
        // Check if surface different
1155
        if (track1[t1_i].surface != track2[t2_i].surface)
98,064✔
1156
          return false;
3,624✔
1157

1158
        // Pretty sure this should not be used:
1159
        // if (t2_i != track2.size() - 1 &&
1160
        //     t1_i != track1.size() - 1 &&
1161
        //     track1[t1_i+1].id != track2[t2_i+1].id) return false;
1162
        if (t2_i != 0 && t1_i != 0 &&
169,980✔
1163
            track1[t1_i - 1].surface != track2[t2_i - 1].surface)
75,540✔
UNCOV
1164
          return false;
×
1165

1166
        // Check if neighboring cells are different
1167
        // if (track1[t1_i ? t1_i - 1 : 0].id != track2[t2_i ? t2_i - 1 : 0].id)
1168
        // return false; if (track1[t1_i < track1.size() - 1 ? t1_i + 1 : t1_i
1169
        // ].id !=
1170
        //    track2[t2_i < track2.size() - 1 ? t2_i + 1 : t2_i].id) return
1171
        //    false;
1172
        t1_i++, t2_i++;
94,440✔
1173
      }
1174
    }
1175
    return true;
950,988✔
1176
  }
1177
}
1178

1179
void ProjectionPlot::create_output() const
60✔
1180
{
1181
  // Get centerline vector for camera-to-model. We create vectors around this
1182
  // that form a pixel array, and then trace rays along that.
1183
  auto up = up_ / up_.norm();
60✔
1184
  Direction looking_direction = look_at_ - camera_position_;
60✔
1185
  looking_direction /= looking_direction.norm();
60✔
1186
  if (std::abs(std::abs(looking_direction.dot(up)) - 1.0) < 1e-9)
60✔
UNCOV
1187
    fatal_error("Up vector cannot align with vector between camera position "
×
1188
                "and look_at!");
1189
  Direction cam_yaxis = looking_direction.cross(up);
60✔
1190
  cam_yaxis /= cam_yaxis.norm();
60✔
1191
  Direction cam_zaxis = cam_yaxis.cross(looking_direction);
60✔
1192
  cam_zaxis /= cam_zaxis.norm();
60✔
1193

1194
  // Transformation matrix for directions
1195
  std::vector<double> camera_to_model = {looking_direction.x, cam_yaxis.x,
60✔
1196
    cam_zaxis.x, looking_direction.y, cam_yaxis.y, cam_zaxis.y,
60✔
1197
    looking_direction.z, cam_yaxis.z, cam_zaxis.z};
60✔
1198

1199
  // Now we convert to the polar coordinate system with the polar angle
1200
  // measuring the angle from the vector up_. Phi is the rotation about up_. For
1201
  // now, up_ is hard-coded to be +z.
1202
  constexpr double DEGREE_TO_RADIAN = M_PI / 180.0;
60✔
1203
  double horiz_fov_radians = horizontal_field_of_view_ * DEGREE_TO_RADIAN;
60✔
1204
  double p0 = static_cast<double>(pixels_[0]);
60✔
1205
  double p1 = static_cast<double>(pixels_[1]);
60✔
1206
  double vert_fov_radians = horiz_fov_radians * p1 / p0;
60✔
1207
  double dphi = horiz_fov_radians / p0;
60✔
1208
  double dmu = vert_fov_radians / p1;
60✔
1209

1210
  size_t width = pixels_[0];
60✔
1211
  size_t height = pixels_[1];
60✔
1212
  ImageData data({width, height}, not_found_);
60✔
1213

1214
  // This array marks where the initial wireframe was drawn.
1215
  // We convolve it with a filter that gets adjusted with the
1216
  // wireframe thickness in order to thicken the lines.
1217
  xt::xtensor<int, 2> wireframe_initial({width, height}, 0);
60✔
1218

1219
  /* Holds all of the track segments for the current rendered line of pixels.
1220
   * old_segments holds a copy of this_line_segments from the previous line.
1221
   * By holding both we can check if the cell/material intersection stack
1222
   * differs from the left or upper neighbor. This allows a robustly drawn
1223
   * wireframe. If only checking the left pixel (which requires substantially
1224
   * less memory), the wireframe tends to be spotty and be disconnected for
1225
   * surface edges oriented horizontally in the rendering.
1226
   *
1227
   * Note that a vector of vectors is required rather than a 2-tensor,
1228
   * since the stack size varies within each column.
1229
   */
1230
  const int n_threads = num_threads();
60✔
1231
  std::vector<std::vector<std::vector<TrackSegment>>> this_line_segments(
1232
    n_threads);
60✔
1233
  for (int t = 0; t < n_threads; ++t) {
150✔
1234
    this_line_segments[t].resize(pixels_[0]);
90✔
1235
  }
1236

1237
  // The last thread writes to this, and the first thread reads from it.
1238
  std::vector<std::vector<TrackSegment>> old_segments(pixels_[0]);
60✔
1239

1240
#pragma omp parallel
30✔
1241
  {
1242
    const int n_threads = num_threads();
30✔
1243
    const int tid = thread_num();
30✔
1244

1245
    GeometryState p;
30✔
1246
    p.u() = {1.0, 0.0, 0.0};
30✔
1247

1248
    int vert = tid;
30✔
1249
    for (int iter = 0; iter <= pixels_[1] / n_threads; iter++) {
6,060✔
1250

1251
      // Save bottom line of current work chunk to compare against later
1252
      // I used to have this inside the below if block, but it causes a
1253
      // spurious line to be drawn at the bottom of the image. Not sure
1254
      // why, but moving it here fixes things.
1255
      if (tid == n_threads - 1)
6,030✔
1256
        old_segments = this_line_segments[n_threads - 1];
6,030✔
1257

1258
      if (vert < pixels_[1]) {
6,030✔
1259

1260
        for (int horiz = 0; horiz < pixels_[0]; ++horiz) {
1,206,000✔
1261

1262
          // Projection mode below decides ray starting conditions
1263
          Position init_r;
1,200,000✔
1264
          Direction init_u;
1,200,000✔
1265

1266
          // Generate the starting position/direction of the ray
1267
          if (orthographic_width_ == 0.0) { // perspective projection
1,200,000✔
1268
            double this_phi =
960,000✔
1269
              -horiz_fov_radians / 2.0 + dphi * horiz + 0.5 * dphi;
960,000✔
1270
            double this_mu =
960,000✔
1271
              -vert_fov_radians / 2.0 + dmu * vert + M_PI / 2.0 + 0.5 * dmu;
960,000✔
1272
            Direction camera_local_vec;
960,000✔
1273
            camera_local_vec.x = std::cos(this_phi) * std::sin(this_mu);
960,000✔
1274
            camera_local_vec.y = std::sin(this_phi) * std::sin(this_mu);
960,000✔
1275
            camera_local_vec.z = std::cos(this_mu);
960,000✔
1276
            init_u = camera_local_vec.rotate(camera_to_model);
960,000✔
1277
            init_r = camera_position_;
960,000✔
1278
          } else { // orthographic projection
1279
            init_u = looking_direction;
240,000✔
1280

1281
            double x_pix_coord = (static_cast<double>(horiz) - p0 / 2.0) / p0;
240,000✔
1282
            double y_pix_coord = (static_cast<double>(vert) - p1 / 2.0) / p0;
240,000✔
1283

1284
            init_r = camera_position_;
240,000✔
1285
            init_r += cam_yaxis * x_pix_coord * orthographic_width_;
240,000✔
1286
            init_r += cam_zaxis * y_pix_coord * orthographic_width_;
240,000✔
1287
          }
1288

1289
          // Resets internal geometry state of particle
1290
          p.init_from_r_u(init_r, init_u);
1,200,000✔
1291

1292
          bool hitsomething = false;
1,200,000✔
1293
          bool intersection_found = true;
1,200,000✔
1294
          int loop_counter = 0;
1,200,000✔
1295

1296
          this_line_segments[tid][horiz].clear();
1,200,000✔
1297

1298
          int first_surface =
1,200,000✔
1299
            -1; // surface first passed when entering the model
1300
          bool first_inside_model = true; // false after entering the model
1,200,000✔
1301
          while (intersection_found) {
8,260,530✔
1302
            bool inside_cell = false;
7,060,530✔
1303

1304
            int32_t i_surface = std::abs(p.surface()) - 1;
7,060,530✔
1305
            if (i_surface > 0 &&
8,384,298✔
1306
                model::surfaces[i_surface]->geom_type() == GeometryType::DAG) {
1,323,768✔
1307
#ifdef DAGMC
1308
              int32_t i_cell = next_cell(i_surface,
1309
                p.cell_last(p.n_coord() - 1), p.lowest_coord().universe);
1310
              inside_cell = i_cell >= 0;
1311
#else
1312
              fatal_error(
1313
                "Not compiled for DAGMC, but somehow you have a DAGCell!");
1314
#endif
1315
            } else {
1316
              inside_cell = exhaustive_find_cell(p);
7,060,530✔
1317
            }
1318

1319
            if (inside_cell) {
7,060,530✔
1320

1321
              // This allows drawing wireframes with surface intersection
1322
              // edges on the model boundary for the same cell.
1323
              if (first_inside_model) {
780,042✔
1324
                this_line_segments[tid][horiz].emplace_back(
893,904✔
1325
                  color_by_ == PlotColorBy::mats ? p.material()
138,954✔
1326
                                                 : p.lowest_coord().cell,
307,998✔
1327
                  0.0, first_surface);
446,952✔
1328
                first_inside_model = false;
446,952✔
1329
              }
1330

1331
              hitsomething = true;
780,042✔
1332
              intersection_found = true;
780,042✔
1333
              auto dist = distance_to_boundary(p);
780,042✔
1334
              this_line_segments[tid][horiz].emplace_back(
1,560,084✔
1335
                color_by_ == PlotColorBy::mats ? p.material()
211,986✔
1336
                                               : p.lowest_coord().cell,
568,056✔
1337
                dist.distance, std::abs(dist.surface_index));
780,042✔
1338

1339
              // Advance particle
1340
              for (int lev = 0; lev < p.n_coord(); ++lev) {
1,560,084✔
1341
                p.coord(lev).r += dist.distance * p.coord(lev).u;
780,042✔
1342
              }
1343
              p.surface() = dist.surface_index;
780,042✔
1344
              p.n_coord_last() = p.n_coord();
780,042✔
1345
              p.n_coord() = dist.coord_level;
780,042✔
1346
              if (dist.lattice_translation[0] != 0 ||
780,042✔
1347
                  dist.lattice_translation[1] != 0 ||
1,560,084✔
1348
                  dist.lattice_translation[2] != 0) {
780,042✔
1349
                cross_lattice(p, dist);
1350
              }
1351

1352
            } else {
1353
              first_surface = advance_to_boundary_from_void(p);
6,280,488✔
1354
              intersection_found =
6,280,488✔
1355
                first_surface != -1; // -1 if no surface found
6,280,488✔
1356
            }
1357
            loop_counter++;
7,060,530✔
1358
            if (loop_counter > MAX_INTERSECTIONS)
7,060,530✔
1359
              fatal_error("Infinite loop in projection plot");
1360
          }
1361

1362
          // Now color the pixel based on what we have intersected...
1363
          // Loops backwards over intersections.
1364
          Position current_color(
1365
            not_found_.red, not_found_.green, not_found_.blue);
1,200,000✔
1366
          const auto& segments = this_line_segments[tid][horiz];
1,200,000✔
1367
          for (unsigned i = segments.size(); i-- > 0;) {
2,426,994✔
1368
            int colormap_idx = segments[i].id;
1,226,994✔
1369
            RGBColor seg_color = colors_[colormap_idx];
1,226,994✔
1370
            Position seg_color_vec(
1371
              seg_color.red, seg_color.green, seg_color.blue);
1,226,994✔
1372
            double mixing = std::exp(-xs_[colormap_idx] * segments[i].length);
1,226,994✔
1373
            current_color =
1374
              current_color * mixing + (1.0 - mixing) * seg_color_vec;
1,226,994✔
1375
            RGBColor result;
1,226,994✔
1376
            result.red = static_cast<uint8_t>(current_color.x);
1,226,994✔
1377
            result.green = static_cast<uint8_t>(current_color.y);
1,226,994✔
1378
            result.blue = static_cast<uint8_t>(current_color.z);
1,226,994✔
1379
            data(horiz, vert) = result;
1,226,994✔
1380
          }
1381

1382
          // Check to draw wireframe in horizontal direction. No inter-thread
1383
          // comm.
1384
          if (horiz > 0) {
1,200,000✔
1385
            if (!trackstack_equivalent(this_line_segments[tid][horiz],
1,194,000✔
1386
                  this_line_segments[tid][horiz - 1])) {
1,194,000✔
1387
              wireframe_initial(horiz, vert) = 1;
22,668✔
1388
            }
1389
          }
1390
        }
1391
      } // end "if" vert in correct range
1392

1393
      // We require a barrier before comparing vertical neighbors' intersection
1394
      // stacks. i.e. all threads must be done with their line.
1395
#pragma omp barrier
1396

1397
      // Now that the horizontal line has finished rendering, we can fill in
1398
      // wireframe entries that require comparison among all the threads. Hence
1399
      // the omp barrier being used. It has to be OUTSIDE any if blocks!
1400
      if (vert < pixels_[1]) {
6,030✔
1401
        // Loop over horizontal pixels, checking intersection stack of upper
1402
        // neighbor
1403

1404
        const std::vector<std::vector<TrackSegment>>* top_cmp = nullptr;
6,000✔
1405
        if (tid == 0)
6,000✔
1406
          top_cmp = &old_segments;
6,000✔
1407
        else
1408
          top_cmp = &this_line_segments[tid - 1];
1409

1410
        for (int horiz = 0; horiz < pixels_[0]; ++horiz) {
1,206,000✔
1411
          if (!trackstack_equivalent(
1,200,000✔
1412
                this_line_segments[tid][horiz], (*top_cmp)[horiz])) {
1,200,000✔
1413
            wireframe_initial(horiz, vert) = 1;
25,284✔
1414
          }
1415
        }
1416
      }
1417

1418
      // We need another barrier to ensure threads don't proceed to modify their
1419
      // intersection stacks on that horizontal line while others are
1420
      // potentially still working on the above.
1421
#pragma omp barrier
1422
      vert += n_threads;
6,030✔
1423
    }
1424
  } // end omp parallel
30✔
1425

1426
  // Now thicken the wireframe lines and apply them to our image
1427
  for (int vert = 0; vert < pixels_[1]; ++vert) {
12,060✔
1428
    for (int horiz = 0; horiz < pixels_[0]; ++horiz) {
2,412,000✔
1429
      if (wireframe_initial(horiz, vert)) {
2,400,000✔
1430
        if (wireframe_thickness_ == 1)
83,916✔
1431
          data(horiz, vert) = wireframe_color_;
37,908✔
1432
        for (int i = -wireframe_thickness_ / 2; i < wireframe_thickness_ / 2;
223,620✔
1433
             ++i)
1434
          for (int j = -wireframe_thickness_ / 2; j < wireframe_thickness_ / 2;
609,864✔
1435
               ++j)
1436
            if (i * i + j * j < wireframe_thickness_ * wireframe_thickness_) {
470,160✔
1437

1438
              // Check if wireframe pixel is out of bounds
1439
              int w_i = std::max(std::min(horiz + i, pixels_[0] - 1), 0);
470,160✔
1440
              int w_j = std::max(std::min(vert + j, pixels_[1] - 1), 0);
470,160✔
1441
              data(w_i, w_j) = wireframe_color_;
470,160✔
1442
            }
1443
      }
1444
    }
1445
  }
1446

1447
#ifdef USE_LIBPNG
1448
  output_png(path_plot(), data);
60✔
1449
#else
1450
  output_ppm(path_plot(), data);
1451
#endif
1452
}
60✔
1453

1454
void ProjectionPlot::print_info() const
60✔
1455
{
1456
  fmt::print("Plot Type: Projection\n");
50✔
1457
  fmt::print("Camera position: {} {} {}\n", camera_position_.x,
50✔
1458
    camera_position_.y, camera_position_.z);
60✔
1459
  fmt::print("Look at: {} {} {}\n", look_at_.x, look_at_.y, look_at_.z);
110✔
1460
  fmt::print(
50✔
1461
    "Horizontal field of view: {} degrees\n", horizontal_field_of_view_);
60✔
1462
  fmt::print("Pixels: {} {}\n", pixels_[0], pixels_[1]);
110✔
1463
}
60✔
1464

1465
void ProjectionPlot::set_opacities(pugi::xml_node node)
60✔
1466
{
1467
  xs_.resize(colors_.size(), 1e6); // set to large value for opaque by default
60✔
1468

1469
  for (auto cn : node.children("color")) {
132✔
1470
    // Make sure 3 values are specified for RGB
1471
    double user_xs = std::stod(get_node_value(cn, "xs"));
72✔
1472
    int col_id = std::stoi(get_node_value(cn, "id"));
72✔
1473

1474
    // Add RGB
1475
    if (PlotColorBy::cells == color_by_) {
72✔
1476
      if (model::cell_map.find(col_id) != model::cell_map.end()) {
72✔
1477
        col_id = model::cell_map[col_id];
72✔
1478
        xs_[col_id] = user_xs;
72✔
1479
      } else {
UNCOV
1480
        warning(fmt::format(
×
1481
          "Could not find cell {} specified in plot {}", col_id, id()));
×
1482
      }
1483
    } else if (PlotColorBy::mats == color_by_) {
×
1484
      if (model::material_map.find(col_id) != model::material_map.end()) {
×
UNCOV
1485
        col_id = model::material_map[col_id];
×
1486
        xs_[col_id] = user_xs;
×
1487
      } else {
UNCOV
1488
        warning(fmt::format(
×
UNCOV
1489
          "Could not find material {} specified in plot {}", col_id, id()));
×
1490
      }
1491
    }
1492
  }
1493
}
60✔
1494

1495
void ProjectionPlot::set_orthographic_width(pugi::xml_node node)
60✔
1496
{
1497
  if (check_for_node(node, "orthographic_width")) {
60✔
1498
    double orthographic_width =
1499
      std::stod(get_node_value(node, "orthographic_width", true));
12✔
1500
    if (orthographic_width < 0.0)
12✔
UNCOV
1501
      fatal_error("Requires positive orthographic_width");
×
1502
    orthographic_width_ = orthographic_width;
12✔
1503
  }
1504
}
60✔
1505

1506
void ProjectionPlot::set_wireframe_thickness(pugi::xml_node node)
60✔
1507
{
1508
  if (check_for_node(node, "wireframe_thickness")) {
60✔
1509
    int wireframe_thickness =
1510
      std::stoi(get_node_value(node, "wireframe_thickness", true));
24✔
1511
    if (wireframe_thickness < 0)
24✔
UNCOV
1512
      fatal_error("Requires non-negative wireframe thickness");
×
1513
    wireframe_thickness_ = wireframe_thickness;
24✔
1514
  }
1515
}
60✔
1516

1517
void ProjectionPlot::set_wireframe_ids(pugi::xml_node node)
60✔
1518
{
1519
  if (check_for_node(node, "wireframe_ids")) {
60✔
1520
    wireframe_ids_ = get_node_array<int>(node, "wireframe_ids");
12✔
1521
    // It is read in as actual ID values, but we have to convert to indices in
1522
    // mat/cell array
1523
    for (auto& x : wireframe_ids_)
24✔
1524
      x = color_by_ == PlotColorBy::mats ? model::material_map[x]
12✔
UNCOV
1525
                                         : model::cell_map[x];
×
1526
  }
1527
  // We make sure the list is sorted in order to later use
1528
  // std::binary_search.
1529
  std::sort(wireframe_ids_.begin(), wireframe_ids_.end());
60✔
1530
}
60✔
1531

1532
void ProjectionPlot::set_pixels(pugi::xml_node node)
60✔
1533
{
1534
  vector<int> pxls = get_node_array<int>(node, "pixels");
60✔
1535
  if (pxls.size() != 2)
60✔
UNCOV
1536
    fatal_error(
×
UNCOV
1537
      fmt::format("<pixels> must be length 2 in projection plot {}", id()));
×
1538
  pixels_[0] = pxls[0];
60✔
1539
  pixels_[1] = pxls[1];
60✔
1540
}
60✔
1541

1542
void ProjectionPlot::set_camera_position(pugi::xml_node node)
60✔
1543
{
1544
  vector<double> camera_pos = get_node_array<double>(node, "camera_position");
60✔
1545
  if (camera_pos.size() != 3) {
60✔
UNCOV
1546
    fatal_error(
×
UNCOV
1547
      fmt::format("look_at element must have three floating point values"));
×
1548
  }
1549
  camera_position_.x = camera_pos[0];
60✔
1550
  camera_position_.y = camera_pos[1];
60✔
1551
  camera_position_.z = camera_pos[2];
60✔
1552
}
60✔
1553

1554
void ProjectionPlot::set_look_at(pugi::xml_node node)
60✔
1555
{
1556
  vector<double> look_at = get_node_array<double>(node, "look_at");
60✔
1557
  if (look_at.size() != 3) {
60✔
UNCOV
1558
    fatal_error("look_at element must have three floating point values");
×
1559
  }
1560
  look_at_.x = look_at[0];
60✔
1561
  look_at_.y = look_at[1];
60✔
1562
  look_at_.z = look_at[2];
60✔
1563
}
60✔
1564

1565
void ProjectionPlot::set_field_of_view(pugi::xml_node node)
60✔
1566
{
1567
  // Defaults to 70 degree horizontal field of view (see .h file)
1568
  if (check_for_node(node, "field_of_view")) {
60✔
1569
    double fov = std::stod(get_node_value(node, "field_of_view", true));
24✔
1570
    if (fov < 180.0 && fov > 0.0) {
24✔
1571
      horizontal_field_of_view_ = fov;
24✔
1572
    } else {
UNCOV
1573
      fatal_error(fmt::format(
×
UNCOV
1574
        "Field of view for plot {} out-of-range. Must be in (0, 180).", id()));
×
1575
    }
1576
  }
1577
}
60✔
1578

1579
extern "C" int openmc_id_map(const void* plot, int32_t* data_out)
12✔
1580
{
1581

1582
  auto plt = reinterpret_cast<const SlicePlotBase*>(plot);
12✔
1583
  if (!plt) {
12✔
UNCOV
1584
    set_errmsg("Invalid slice pointer passed to openmc_id_map");
×
UNCOV
1585
    return OPENMC_E_INVALID_ARGUMENT;
×
1586
  }
1587

1588
  if (plt->slice_color_overlaps_ && model::overlap_check_count.size() == 0) {
12✔
UNCOV
1589
    model::overlap_check_count.resize(model::cells.size());
×
1590
  }
1591

1592
  auto ids = plt->get_map<IdData>();
12✔
1593

1594
  // write id data to array
1595
  std::copy(ids.data_.begin(), ids.data_.end(), data_out);
12✔
1596

1597
  return 0;
12✔
1598
}
12✔
1599

1600
extern "C" int openmc_property_map(const void* plot, double* data_out)
12✔
1601
{
1602

1603
  auto plt = reinterpret_cast<const SlicePlotBase*>(plot);
12✔
1604
  if (!plt) {
12✔
UNCOV
1605
    set_errmsg("Invalid slice pointer passed to openmc_id_map");
×
UNCOV
1606
    return OPENMC_E_INVALID_ARGUMENT;
×
1607
  }
1608

1609
  if (plt->slice_color_overlaps_ && model::overlap_check_count.size() == 0) {
12✔
UNCOV
1610
    model::overlap_check_count.resize(model::cells.size());
×
1611
  }
1612

1613
  auto props = plt->get_map<PropertyData>();
12✔
1614

1615
  // write id data to array
1616
  std::copy(props.data_.begin(), props.data_.end(), data_out);
12✔
1617

1618
  return 0;
12✔
1619
}
12✔
1620

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