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

openmc-dev / openmc / 21597104861

02 Feb 2026 03:53PM UTC coverage: 81.674% (-0.3%) from 81.968%
21597104861

Pull #3751

github

web-flow
Merge 4a6501226 into 6041ee6ae
Pull Request #3751: Resolve conflict with weight windows and global russian roulette

16697 of 23049 branches covered (72.44%)

Branch coverage included in aggregate %.

76 of 84 new or added lines in 5 files covered. (90.48%)

471 existing lines in 31 files now uncovered.

54833 of 64531 relevant lines covered (84.97%)

37154420.72 hits per line

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

87.57
/src/geometry_aux.cpp
1
#include "openmc/geometry_aux.h"
2

3
#include <algorithm> // for std::max
4
#include <sstream>
5
#include <unordered_set>
6

7
#include <fmt/core.h>
8
#include <pugixml.hpp>
9

10
#include "openmc/cell.h"
11
#include "openmc/constants.h"
12
#include "openmc/container_util.h"
13
#include "openmc/dagmc.h"
14
#include "openmc/error.h"
15
#include "openmc/file_utils.h"
16
#include "openmc/geometry.h"
17
#include "openmc/lattice.h"
18
#include "openmc/material.h"
19
#include "openmc/settings.h"
20
#include "openmc/surface.h"
21
#include "openmc/tallies/filter.h"
22
#include "openmc/tallies/filter_cell_instance.h"
23
#include "openmc/tallies/filter_distribcell.h"
24

25
namespace openmc {
26

27
namespace model {
28
std::unordered_map<int32_t, int32_t> universe_level_counts;
29
} // namespace model
30

31
void read_geometry_xml()
1,002✔
32
{
33
  // Display output message
34
  write_message("Reading geometry XML file...", 5);
1,002✔
35

36
  // Check if geometry.xml exists
37
  std::string filename = settings::path_input + "geometry.xml";
1,002✔
38
  if (!file_exists(filename)) {
1,002!
39
    fatal_error("Geometry XML file '" + filename + "' does not exist!");
×
40
  }
41

42
  // Parse settings.xml file
43
  pugi::xml_document doc;
1,002✔
44
  auto result = doc.load_file(filename.c_str());
1,002✔
45
  if (!result) {
1,002!
46
    fatal_error("Error processing geometry.xml file.");
×
47
  }
48

49
  // Get root element
50
  pugi::xml_node root = doc.document_element();
1,002✔
51

52
  read_geometry_xml(root);
1,002✔
53
}
1,002✔
54

55
void read_geometry_xml(pugi::xml_node root)
5,914✔
56
{
57
  // Read surfaces, cells, lattice
58
  std::set<std::pair<int, int>> periodic_pairs;
5,914✔
59
  std::unordered_map<int, double> albedo_map;
5,914✔
60
  std::unordered_map<int, int> periodic_sense_map;
5,914✔
61

62
  read_surfaces(root, periodic_pairs, albedo_map, periodic_sense_map);
5,914✔
63
  read_cells(root);
5,914✔
64
  prepare_boundary_conditions(periodic_pairs, albedo_map, periodic_sense_map);
5,914✔
65
  read_lattices(root);
5,914✔
66

67
  // Check to make sure a boundary condition was applied to at least one
68
  // surface
69
  bool boundary_exists = false;
5,914✔
70
  for (const auto& surf : model::surfaces) {
14,634✔
71
    if (surf->bc_) {
14,610✔
72
      boundary_exists = true;
5,890✔
73
      break;
5,890✔
74
    }
75
  }
76

77
  if (settings::run_mode != RunMode::PLOTTING &&
5,914✔
78
      settings::run_mode != RunMode::VOLUME && !boundary_exists) {
5,827!
79
    fatal_error("No boundary conditions were applied to any surfaces!");
×
80
  }
81

82
  // Allocate universes, universe cell arrays, and assign base universe
83
  model::root_universe = find_root_universe();
5,914✔
84

85
  // if the root universe is DAGMC geometry, make sure the model is well-formed
86
  check_dagmc_root_univ();
5,914✔
87
}
5,914✔
88

89
//==============================================================================
90

91
void adjust_indices()
5,914✔
92
{
93
  // Adjust material/fill idices.
94
  for (auto& c : model::cells) {
28,893✔
95
    if (c->fill_ != C_NONE) {
22,979✔
96
      int32_t id = c->fill_;
5,398✔
97
      auto search_univ = model::universe_map.find(id);
5,398✔
98
      auto search_lat = model::lattice_map.find(id);
5,398✔
99
      if (search_univ != model::universe_map.end()) {
5,398✔
100
        c->type_ = Fill::UNIVERSE;
3,944✔
101
        c->fill_ = search_univ->second;
3,944✔
102
      } else if (search_lat != model::lattice_map.end()) {
1,454!
103
        c->type_ = Fill::LATTICE;
1,454✔
104
        c->fill_ = search_lat->second;
1,454✔
105
      } else {
106
        fatal_error(fmt::format("Specified fill {} on cell {} is neither a "
×
107
                                "universe nor a lattice.",
108
          id, c->id_));
×
109
      }
110
    } else {
111
      c->type_ = Fill::MATERIAL;
17,581✔
112
      for (auto& mat_id : c->material_) {
36,062✔
113
        if (mat_id != MATERIAL_VOID) {
18,481✔
114
          auto search = model::material_map.find(mat_id);
14,513✔
115
          if (search == model::material_map.end()) {
14,513!
116
            fatal_error(
×
117
              fmt::format("Could not find material {} specified on cell {}",
×
118
                mat_id, c->id_));
×
119
          }
120
          // Change from ID to index
121
          mat_id = search->second;
14,513✔
122
        }
123
      }
124
    }
125
  }
126

127
  // Change cell.universe values from IDs to indices.
128
  for (auto& c : model::cells) {
28,893✔
129
    auto search = model::universe_map.find(c->universe_);
22,979✔
130
    if (search != model::universe_map.end()) {
22,979!
131
      c->universe_ = search->second;
22,979✔
132
    } else {
133
      fatal_error(fmt::format("Could not find universe {} specified on cell {}",
×
134
        c->universe_, c->id_));
×
135
    }
136
  }
137

138
  // Change all lattice universe values from IDs to indices.
139
  for (auto& l : model::lattices) {
7,344✔
140
    l->adjust_indices();
1,430✔
141
  }
142
}
5,914✔
143

144
//==============================================================================
145
//! Partition some universes with many z-planes for faster find_cell searches.
146

147
void partition_universes()
5,914✔
148
{
149
  // Iterate over universes with more than 10 cells.  (Fewer than 10 is likely
150
  // not worth partitioning.)
151
  for (const auto& univ : model::universes) {
18,112✔
152
    if (univ->cells_.size() > 10) {
12,198✔
153
      // Collect the set of surfaces in this universe.
154
      std::unordered_set<int32_t> surf_inds;
132✔
155
      for (auto i_cell : univ->cells_) {
2,244✔
156
        for (auto token : model::cells[i_cell]->surfaces()) {
7,992✔
157
          surf_inds.insert(std::abs(token) - 1);
5,880✔
158
        }
2,112✔
159
      }
160

161
      // Partition the universe if there are more than 5 z-planes.  (Fewer than
162
      // 5 is likely not worth it.)
163
      int n_zplanes = 0;
132✔
164
      for (auto i_surf : surf_inds) {
1,716✔
165
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
1,656!
166
          ++n_zplanes;
480✔
167
          if (n_zplanes > 5) {
480✔
168
            univ->partitioner_ = make_unique<UniversePartitioner>(*univ);
72✔
169
            break;
72✔
170
          }
171
        }
172
      }
173
    }
132✔
174
  }
175
}
5,914✔
176

177
//==============================================================================
178

179
void assign_temperatures()
5,914✔
180
{
181
  for (auto& c : model::cells) {
28,893✔
182
    // Ignore non-material cells and cells with defined temperature.
183
    if (c->material_.size() == 0)
22,979✔
184
      continue;
5,398✔
185
    if (c->sqrtkT_.size() > 0)
17,581✔
186
      continue;
236✔
187

188
    c->sqrtkT_.reserve(c->material_.size());
17,345✔
189
    for (auto i_mat : c->material_) {
35,590✔
190
      if (i_mat == MATERIAL_VOID) {
18,245✔
191
        // Set void region to 0K.
192
        c->sqrtkT_.push_back(0);
3,968✔
193
      } else {
194
        const auto& mat {model::materials[i_mat]};
14,277✔
195
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
14,277✔
196
      }
197
    }
198
  }
199
}
5,914✔
200

201
//==============================================================================
202

203
void finalize_cell_densities()
5,914✔
204
{
205
  for (auto& c : model::cells) {
28,893✔
206
    // Convert to density multipliers.
207
    if (!c->density_mult_.empty()) {
22,979✔
208
      for (int32_t instance = 0; instance < c->density_mult_.size();
984✔
209
           ++instance) {
210
        c->density_mult_[instance] /=
924✔
211
          model::materials[c->material(instance)]->density_gpcc();
924✔
212
      }
213
    } else {
214
      c->density_mult_ = {1.0};
22,919✔
215
    }
216
  }
217
}
5,914✔
218

219
//==============================================================================
220

221
void get_temperatures(
5,827✔
222
  vector<vector<double>>& nuc_temps, vector<vector<double>>& thermal_temps)
223
{
224
  for (const auto& cell : model::cells) {
28,569✔
225
    // Skip non-material cells.
226
    if (cell->fill_ != C_NONE)
22,742✔
227
      continue;
5,390✔
228

229
    for (int j = 0; j < cell->material_.size(); ++j) {
35,604✔
230
      // Skip void materials
231
      int i_material = cell->material_[j];
18,252✔
232
      if (i_material == MATERIAL_VOID)
18,252✔
233
        continue;
3,952✔
234

235
      // Get temperature(s) of cell (rounding to nearest integer)
236
      vector<double> cell_temps;
14,300✔
237
      if (cell->sqrtkT_.size() == 1) {
14,300✔
238
        double sqrtkT = cell->sqrtkT_[0];
13,260✔
239
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
13,260✔
240
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
1,040✔
241
        double sqrtkT = cell->sqrtkT_[j];
1,028✔
242
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
1,028✔
243
      } else {
244
        for (double sqrtkT : cell->sqrtkT_)
60✔
245
          cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
48✔
246
      }
247

248
      const auto& mat {model::materials[i_material]};
14,300✔
249
      for (const auto& i_nuc : mat->nuclide_) {
64,071✔
250
        for (double temperature : cell_temps) {
99,578✔
251
          // Add temperature if it hasn't already been added
252
          if (!contains(nuc_temps[i_nuc], temperature))
49,807✔
253
            nuc_temps[i_nuc].push_back(temperature);
22,087✔
254
        }
255
      }
256

257
      for (const auto& table : mat->thermal_tables_) {
16,760✔
258
        // Get index in data::thermal_scatt array
259
        int i_sab = table.index_table;
2,460✔
260

261
        for (double temperature : cell_temps) {
4,920✔
262
          // Add temperature if it hasn't already been added
263
          if (!contains(thermal_temps[i_sab], temperature))
2,460✔
264
            thermal_temps[i_sab].push_back(temperature);
904✔
265
        }
266
      }
267
    }
14,300✔
268
  }
269
}
5,827✔
270

271
//==============================================================================
272

273
void finalize_geometry()
5,914✔
274
{
275
  // Perform some final operations to set up the geometry
276
  adjust_indices();
5,914✔
277
  count_universe_instances();
5,914✔
278
  partition_universes();
5,914✔
279

280
  // Assign temperatures to cells that don't have temperatures already assigned
281
  assign_temperatures();
5,914✔
282

283
  // Determine number of nested coordinate levels in the geometry
284
  model::n_coord_levels = maximum_levels(model::root_universe);
5,914✔
285
}
5,914✔
286

287
//==============================================================================
288

289
int32_t find_root_universe()
5,914✔
290
{
291
  // Find all the universes listed as a cell fill.
292
  std::unordered_set<int32_t> fill_univ_ids;
5,914✔
293
  for (const auto& c : model::cells) {
28,893✔
294
    fill_univ_ids.insert(c->fill_);
22,979✔
295
  }
296

297
  // Find all the universes contained in a lattice.
298
  for (const auto& lat : model::lattices) {
7,344✔
299
    for (auto it = lat->begin(); it != lat->end(); ++it) {
714,406✔
300
      fill_univ_ids.insert(*it);
712,976✔
301
    }
302
    if (lat->outer_ != NO_OUTER_UNIVERSE) {
1,430✔
303
      fill_univ_ids.insert(lat->outer_);
308✔
304
    }
305
  }
306

307
  // Figure out which universe is not in the set.  This is the root universe.
308
  bool root_found {false};
5,914✔
309
  int32_t root_univ;
310
  for (int32_t i = 0; i < model::universes.size(); i++) {
18,112✔
311
    auto search = fill_univ_ids.find(model::universes[i]->id_);
12,198✔
312
    if (search == fill_univ_ids.end()) {
12,198✔
313
      if (root_found) {
5,914!
314
        fatal_error("Two or more universes are not used as fill universes, so "
×
315
                    "it is not possible to distinguish which one is the root "
316
                    "universe.");
317
      } else {
318
        root_found = true;
5,914✔
319
        root_univ = i;
5,914✔
320
      }
321
    }
322
  }
323
  if (!root_found)
5,914!
324
    fatal_error("Could not find a root universe.  Make sure "
×
325
                "there are no circular dependencies in the geometry.");
326

327
  return root_univ;
5,914✔
328
}
5,914✔
329

330
//==============================================================================
331

332
void prepare_distribcell(const std::vector<int32_t>* user_distribcells)
5,912✔
333
{
334
  write_message("Preparing distributed cell instances...", 5);
5,912✔
335

336
  std::unordered_set<int32_t> distribcells;
5,912✔
337

338
  // start with any cells manually specified via the C++ API
339
  if (user_distribcells) {
5,912✔
340
    distribcells.insert(user_distribcells->begin(), user_distribcells->end());
12✔
341
  }
342

343
  // Find all cells listed in a DistribcellFilter or CellInstanceFilter
344
  for (auto& filt : model::tally_filters) {
12,508✔
345
    auto* distrib_filt = dynamic_cast<DistribcellFilter*>(filt.get());
6,596!
346
    auto* cell_inst_filt = dynamic_cast<CellInstanceFilter*>(filt.get());
6,596!
347
    if (distrib_filt) {
6,596✔
348
      distribcells.insert(distrib_filt->cell());
140✔
349
    }
350
    if (cell_inst_filt) {
6,596✔
351
      const auto& filter_cells = cell_inst_filt->cells();
24✔
352
      distribcells.insert(filter_cells.begin(), filter_cells.end());
24✔
353
    }
354
  }
355

356
  // By default, add material cells to the list of distributed cells
357
  if (settings::material_cell_offsets) {
5,912!
358
    for (int64_t i = 0; i < model::cells.size(); ++i) {
28,937✔
359
      if (model::cells[i]->type_ == Fill::MATERIAL)
23,025✔
360
        distribcells.insert(i);
17,603✔
361
    }
362
  }
363

364
  // Make sure that the number of materials/temperatures matches the number of
365
  // cell instances.
366
  for (int i = 0; i < model::cells.size(); i++) {
28,937✔
367
    Cell& c {*model::cells[i]};
23,025✔
368

369
    if (c.material_.size() > 1) {
23,025✔
370
      if (c.material_.size() != c.n_instances()) {
140!
371
        fatal_error(fmt::format(
×
372
          "Cell {} was specified with {} materials but has {} distributed "
373
          "instances. The number of materials must equal one or the number "
374
          "of instances.",
375
          c.id_, c.material_.size(), c.n_instances()));
×
376
      }
377
    }
378

379
    if (c.sqrtkT_.size() > 1) {
23,025✔
380
      if (c.sqrtkT_.size() != c.n_instances()) {
152!
381
        fatal_error(fmt::format(
×
382
          "Cell {} was specified with {} temperatures but has {} distributed "
383
          "instances. The number of temperatures must equal one or the number "
384
          "of instances.",
385
          c.id_, c.sqrtkT_.size(), c.n_instances()));
×
386
      }
387
    }
388

389
    if (c.density_mult_.size() > 1) {
23,025✔
390
      if (c.density_mult_.size() != c.n_instances()) {
48!
391
        fatal_error(fmt::format("Cell {} was specified with {} density "
×
392
                                "multipliers but has {} distributed "
393
                                "instances. The number of density multipliers "
394
                                "must equal one or the number "
395
                                "of instances.",
396
          c.id_, c.density_mult_.size(), c.n_instances()));
×
397
      }
398
    }
399
  }
400

401
  // Search through universes for material cells and assign each one a
402
  // distribcell array index according to the containing universe.
403
  vector<int32_t> target_univ_ids;
5,912✔
404
  for (const auto& u : model::universes) {
18,132✔
405
    for (auto idx : u->cells_) {
35,245✔
406
      if (distribcells.find(idx) != distribcells.end()) {
23,025✔
407
        if (!contains(target_univ_ids, u->id_)) {
17,663✔
408
          target_univ_ids.push_back(u->id_);
10,182✔
409
        }
410
        model::cells[idx]->distribcell_index_ =
17,663✔
411
          std::find(target_univ_ids.begin(), target_univ_ids.end(), u->id_) -
17,663✔
412
          target_univ_ids.begin();
35,326✔
413
      }
414
    }
415
  }
416

417
  // Allocate the cell and lattice offset tables.
418
  int n_maps = target_univ_ids.size();
5,912✔
419
  for (auto& c : model::cells) {
28,937✔
420
    if (c->type_ != Fill::MATERIAL) {
23,025✔
421
      c->offset_.resize(n_maps, C_NONE);
5,422✔
422
    }
423
  }
424
  for (auto& lat : model::lattices) {
7,354✔
425
    lat->allocate_offset_table(n_maps);
1,442✔
426
  }
427

428
// Fill the cell and lattice offset tables.
429
#pragma omp parallel for
2,332✔
430
  for (int map = 0; map < target_univ_ids.size(); map++) {
8,500✔
431
    auto target_univ_id = target_univ_ids[map];
4,920✔
432
    std::unordered_map<int32_t, int32_t> univ_count_memo;
4,920✔
433
    for (const auto& univ : model::universes) {
23,322✔
434
      int32_t offset = 0;
18,402✔
435
      for (int32_t cell_indx : univ->cells_) {
83,092✔
436
        Cell& c = *model::cells[cell_indx];
64,690✔
437

438
        if (c.type_ == Fill::UNIVERSE) {
64,690✔
439
          c.offset_[map] = offset;
36,118✔
440
          int32_t search_univ = c.fill_;
36,118✔
441
          offset += count_universe_instances(
36,118✔
442
            search_univ, target_univ_id, univ_count_memo);
443

444
        } else if (c.type_ == Fill::LATTICE) {
28,572✔
445
          c.offset_[map] = offset;
3,014✔
446
          Lattice& lat = *model::lattices[c.fill_];
3,014✔
447
          offset += lat.fill_offset_table(target_univ_id, map, univ_count_memo);
3,014✔
448
        }
449
      }
450
    }
451
  }
4,920✔
452
}
5,912✔
453

454
//==============================================================================
455

456
void count_universe_instances()
5,914✔
457
{
458
  for (auto& univ : model::universes) {
18,112✔
459
    std::unordered_map<int32_t, int32_t> univ_count_memo;
12,198✔
460
    univ->n_instances_ = count_universe_instances(
12,198✔
461
      model::root_universe, univ->id_, univ_count_memo);
12,198✔
462
  }
12,198✔
463
}
5,914✔
464

465
//==============================================================================
466

467
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
11,976,522✔
468
  std::unordered_map<int32_t, int32_t>& univ_count_memo)
469
{
470
  // If this is the target, it can't contain itself.
471
  if (model::universes[search_univ]->id_ == target_univ_id) {
11,976,522✔
472
    return 1;
2,016,186✔
473
  }
474

475
  // If we have already counted the number of instances, reuse that value.
476
  auto search = univ_count_memo.find(search_univ);
9,960,336✔
477
  if (search != univ_count_memo.end()) {
9,960,336✔
478
    return search->second;
5,907,364✔
479
  }
480

481
  int count {0};
4,052,972✔
482
  for (int32_t cell_indx : model::universes[search_univ]->cells_) {
8,243,348✔
483
    Cell& c = *model::cells[cell_indx];
4,190,376✔
484

485
    if (c.type_ == Fill::UNIVERSE) {
4,190,376✔
486
      int32_t next_univ = c.fill_;
126,744✔
487
      count +=
126,744✔
488
        count_universe_instances(next_univ, target_univ_id, univ_count_memo);
126,744✔
489

490
    } else if (c.type_ == Fill::LATTICE) {
4,063,632✔
491
      Lattice& lat = *model::lattices[c.fill_];
13,780✔
492
      for (auto it = lat.begin(); it != lat.end(); ++it) {
7,265,432✔
493
        int32_t next_univ = *it;
7,251,652✔
494
        count +=
7,251,652✔
495
          count_universe_instances(next_univ, target_univ_id, univ_count_memo);
7,251,652✔
496
      }
497
    }
498
  }
499

500
  // Remember the number of instances in this universe.
501
  univ_count_memo[search_univ] = count;
4,052,972✔
502

503
  return count;
4,052,972✔
504
}
505

506
//==============================================================================
507

508
std::string distribcell_path_inner(int32_t target_cell, int32_t map,
1,865,872✔
509
  int32_t target_offset, const Universe& search_univ, int32_t offset)
510
{
511
  std::stringstream path;
1,865,872✔
512

513
  path << "u" << search_univ.id_ << "->";
1,865,872✔
514

515
  // Check to see if this universe directly contains the target cell.  If so,
516
  // write to the path and return.
517
  for (int32_t cell_indx : search_univ.cells_) {
8,656,680✔
518
    if ((cell_indx == target_cell) && (offset == target_offset)) {
7,465,024!
519
      Cell& c = *model::cells[cell_indx];
674,216✔
520
      path << "c" << c.id_;
674,216✔
521
      return path.str();
1,348,432✔
522
    }
523
  }
524

525
  // The target must be further down the geometry tree and contained in a fill
526
  // cell or lattice cell in this universe.  Find which cell contains the
527
  // target.
528
  vector<std::int32_t>::const_reverse_iterator cell_it {
529
    search_univ.cells_.crbegin()};
1,191,656✔
530
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
6,790,688!
531
    Cell& c = *model::cells[*cell_it];
6,790,688✔
532

533
    // Material cells don't contain other cells so ignore them.
534
    if (c.type_ != Fill::MATERIAL) {
6,790,688✔
535
      int32_t temp_offset = offset + c.offset_[map];
1,700,768✔
536
      if (c.type_ == Fill::LATTICE) {
1,700,768!
537
        Lattice& lat = *model::lattices[c.fill_];
1,700,768✔
538
        int32_t indx = lat.universes_.size() * map + lat.begin().indx_;
1,700,768✔
539
        temp_offset += lat.offsets_[indx];
1,700,768✔
540
      }
541

542
      // The desired cell is the first cell that gives an offset smaller or
543
      // equal to the target offset.
544
      if (temp_offset <= target_offset)
1,700,768✔
545
        break;
1,191,656✔
546
    }
547
  }
548

549
  // if we get through the loop without finding an appropriate entry, throw
550
  // an error
551
  if (cell_it == search_univ.cells_.crend()) {
1,191,656!
552
    fatal_error(
×
553
      fmt::format("Failed to generate a text label for distribcell with ID {}."
×
554
                  "The current label is: '{}'",
555
        model::cells[target_cell]->id_, path.str()));
×
556
  }
557

558
  // Add the cell to the path string.
559
  Cell& c = *model::cells[*cell_it];
1,191,656✔
560
  path << "c" << c.id_ << "->";
1,191,656✔
561

562
  if (c.type_ == Fill::UNIVERSE) {
1,191,656!
563
    // Recurse into the fill cell.
564
    offset += c.offset_[map];
×
565
    path << distribcell_path_inner(
×
566
      target_cell, map, target_offset, *model::universes[c.fill_], offset);
×
567
    return path.str();
×
568
  } else {
569
    // Recurse into the lattice cell.
570
    Lattice& lat = *model::lattices[c.fill_];
1,191,656✔
571
    path << "l" << lat.id_;
1,191,656✔
572
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
210,217,280!
573
      int32_t indx = lat.universes_.size() * map + it.indx_;
210,217,280✔
574
      int32_t temp_offset = offset + lat.offsets_[indx] + c.offset_[map];
210,217,280✔
575
      if (temp_offset <= target_offset) {
210,217,280✔
576
        offset = temp_offset;
1,191,656✔
577
        path << "(" << lat.index_to_string(it.indx_) << ")->";
1,191,656✔
578
        path << distribcell_path_inner(
2,383,312✔
579
          target_cell, map, target_offset, *model::universes[*it], offset);
2,383,312✔
580
        return path.str();
2,383,312✔
581
      }
582
    }
583
    throw std::runtime_error {"Error determining distribcell path."};
×
584
  }
585
}
1,865,872✔
586

587
std::string distribcell_path(
674,216✔
588
  int32_t target_cell, int32_t map, int32_t target_offset)
589
{
590
  auto& root_univ = *model::universes[model::root_universe];
674,216✔
591
  return distribcell_path_inner(target_cell, map, target_offset, root_univ, 0);
674,216✔
592
}
593

594
//==============================================================================
595

596
int maximum_levels(int32_t univ)
722,954✔
597
{
598

599
  const auto level_count = model::universe_level_counts.find(univ);
722,954✔
600
  if (level_count != model::universe_level_counts.end()) {
722,954✔
601
    return level_count->second;
710,876✔
602
  }
603

604
  int levels_below {0};
12,078✔
605

606
  for (int32_t cell_indx : model::universes[univ]->cells_) {
34,937✔
607
    Cell& c = *model::cells[cell_indx];
22,859✔
608
    if (c.type_ == Fill::UNIVERSE) {
22,859✔
609
      int32_t next_univ = c.fill_;
3,944✔
610
      levels_below = std::max(levels_below, maximum_levels(next_univ));
3,944✔
611
    } else if (c.type_ == Fill::LATTICE) {
18,915✔
612
      Lattice& lat = *model::lattices[c.fill_];
1,454✔
613
      for (auto it = lat.begin(); it != lat.end(); ++it) {
714,550✔
614
        int32_t next_univ = *it;
713,096✔
615
        levels_below = std::max(levels_below, maximum_levels(next_univ));
713,096✔
616
      }
617
    }
618
  }
619

620
  ++levels_below;
12,078✔
621
  model::universe_level_counts[univ] = levels_below;
12,078✔
622
  return levels_below;
12,078✔
623
}
624

UNCOV
625
bool is_root_universe(int32_t univ_id)
×
626
{
UNCOV
627
  return model::universe_map[univ_id] == model::root_universe;
×
628
}
629

630
//==============================================================================
631

632
void free_memory_geometry()
5,990✔
633
{
634
  model::cells.clear();
5,990✔
635
  model::cell_map.clear();
5,990✔
636

637
  model::universes.clear();
5,990✔
638
  model::universe_map.clear();
5,990✔
639

640
  model::lattices.clear();
5,990✔
641
  model::lattice_map.clear();
5,990✔
642

643
  model::overlap_check_count.clear();
5,990✔
644
}
5,990✔
645

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