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

openmc-dev / openmc / 21240277645

22 Jan 2026 07:46AM UTC coverage: 80.906% (-1.1%) from 81.998%
21240277645

Pull #3745

github

web-flow
Merge b47b53e16 into c5df2bf62
Pull Request #3745: Add n_elements to the MeshBase protocol and deprecate num_mesh_cells

16262 of 22513 branches covered (72.23%)

Branch coverage included in aggregate %.

15 of 21 new or added lines in 2 files covered. (71.43%)

1061 existing lines in 55 files now uncovered.

53902 of 64210 relevant lines covered (83.95%)

7933045.48 hits per line

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

87.56
/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()
147✔
32
{
33
  // Display output message
34
  write_message("Reading geometry XML file...", 5);
147✔
35

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

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

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

52
  read_geometry_xml(root);
147✔
53
}
147✔
54

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

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

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

77
  if (settings::run_mode != RunMode::PLOTTING &&
834✔
78
      settings::run_mode != RunMode::VOLUME && !boundary_exists) {
823!
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();
834✔
84

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

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

91
void adjust_indices()
834✔
92
{
93
  // Adjust material/fill idices.
94
  for (auto& c : model::cells) {
3,997✔
95
    if (c->fill_ != C_NONE) {
3,163✔
96
      int32_t id = c->fill_;
878✔
97
      auto search_univ = model::universe_map.find(id);
878✔
98
      auto search_lat = model::lattice_map.find(id);
878✔
99
      if (search_univ != model::universe_map.end()) {
878✔
100
        c->type_ = Fill::UNIVERSE;
644✔
101
        c->fill_ = search_univ->second;
644✔
102
      } else if (search_lat != model::lattice_map.end()) {
234!
103
        c->type_ = Fill::LATTICE;
234✔
104
        c->fill_ = search_lat->second;
234✔
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;
2,285✔
112
      for (auto& mat_id : c->material_) {
4,655✔
113
        if (mat_id != MATERIAL_VOID) {
2,370✔
114
          auto search = model::material_map.find(mat_id);
2,097✔
115
          if (search == model::material_map.end()) {
2,097!
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;
2,097✔
122
        }
123
      }
124
    }
125
  }
126

127
  // Change cell.universe values from IDs to indices.
128
  for (auto& c : model::cells) {
3,997✔
129
    auto search = model::universe_map.find(c->universe_);
3,163✔
130
    if (search != model::universe_map.end()) {
3,163!
131
      c->universe_ = search->second;
3,163✔
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) {
1,065✔
140
    l->adjust_indices();
231✔
141
  }
142
}
834✔
143

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

147
void partition_universes()
834✔
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) {
2,354✔
152
    if (univ->cells_.size() > 10) {
1,520✔
153
      // Collect the set of surfaces in this universe.
154
      std::unordered_set<int32_t> surf_inds;
21✔
155
      for (auto i_cell : univ->cells_) {
362✔
156
        for (auto token : model::cells[i_cell]->surfaces()) {
1,288✔
157
          surf_inds.insert(std::abs(token) - 1);
947✔
158
        }
341✔
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;
21✔
164
      for (auto i_surf : surf_inds) {
277✔
165
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
268!
166
          ++n_zplanes;
80✔
167
          if (n_zplanes > 5) {
80✔
168
            univ->partitioner_ = make_unique<UniversePartitioner>(*univ);
12✔
169
            break;
12✔
170
          }
171
        }
172
      }
173
    }
21✔
174
  }
175
}
834✔
176

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

179
void assign_temperatures()
834✔
180
{
181
  for (auto& c : model::cells) {
3,997✔
182
    // Ignore non-material cells and cells with defined temperature.
183
    if (c->material_.size() == 0)
3,163✔
184
      continue;
878✔
185
    if (c->sqrtkT_.size() > 0)
2,285✔
186
      continue;
39✔
187

188
    c->sqrtkT_.reserve(c->material_.size());
2,246✔
189
    for (auto i_mat : c->material_) {
4,577✔
190
      if (i_mat == MATERIAL_VOID) {
2,331✔
191
        // Set void region to 0K.
192
        c->sqrtkT_.push_back(0);
273✔
193
      } else {
194
        const auto& mat {model::materials[i_mat]};
2,058✔
195
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
2,058✔
196
      }
197
    }
198
  }
199
}
834✔
200

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

203
void finalize_cell_densities()
834✔
204
{
205
  for (auto& c : model::cells) {
3,997✔
206
    // Convert to density multipliers.
207
    if (!c->density_mult_.empty()) {
3,163✔
208
      for (int32_t instance = 0; instance < c->density_mult_.size();
164✔
209
           ++instance) {
210
        c->density_mult_[instance] /=
154✔
211
          model::materials[c->material(instance)]->density_gpcc();
154✔
212
      }
213
    } else {
214
      c->density_mult_ = {1.0};
3,153✔
215
    }
216
  }
217
}
834✔
218

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

221
void get_temperatures(
823✔
222
  vector<vector<double>>& nuc_temps, vector<vector<double>>& thermal_temps)
223
{
224
  for (const auto& cell : model::cells) {
3,956✔
225
    // Skip non-material cells.
226
    if (cell->fill_ != C_NONE)
3,133✔
227
      continue;
877✔
228

229
    for (int j = 0; j < cell->material_.size(); ++j) {
4,597✔
230
      // Skip void materials
231
      int i_material = cell->material_[j];
2,341✔
232
      if (i_material == MATERIAL_VOID)
2,341✔
233
        continue;
271✔
234

235
      // Get temperature(s) of cell (rounding to nearest integer)
236
      vector<double> cell_temps;
2,070✔
237
      if (cell->sqrtkT_.size() == 1) {
2,070✔
238
        double sqrtkT = cell->sqrtkT_[0];
1,970✔
239
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
1,970✔
240
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
100✔
241
        double sqrtkT = cell->sqrtkT_[j];
98✔
242
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
98✔
243
      } else {
244
        for (double sqrtkT : cell->sqrtkT_)
10✔
245
          cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
8✔
246
      }
247

248
      const auto& mat {model::materials[i_material]};
2,070✔
249
      for (const auto& i_nuc : mat->nuclide_) {
9,070✔
250
        for (double temperature : cell_temps) {
14,006✔
251
          // Add temperature if it hasn't already been added
252
          if (!contains(nuc_temps[i_nuc], temperature))
7,006✔
253
            nuc_temps[i_nuc].push_back(temperature);
3,097✔
254
        }
255
      }
256

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

261
        for (double temperature : cell_temps) {
774✔
262
          // Add temperature if it hasn't already been added
263
          if (!contains(thermal_temps[i_sab], temperature))
387✔
264
            thermal_temps[i_sab].push_back(temperature);
130✔
265
        }
266
      }
267
    }
2,070✔
268
  }
269
}
823✔
270

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

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

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

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

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

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

297
  // Find all the universes contained in a lattice.
298
  for (const auto& lat : model::lattices) {
1,065✔
299
    for (auto it = lat->begin(); it != lat->end(); ++it) {
116,663✔
300
      fill_univ_ids.insert(*it);
116,432✔
301
    }
302
    if (lat->outer_ != NO_OUTER_UNIVERSE) {
231✔
303
      fill_univ_ids.insert(lat->outer_);
48✔
304
    }
305
  }
306

307
  // Figure out which universe is not in the set.  This is the root universe.
308
  bool root_found {false};
834✔
309
  int32_t root_univ;
310
  for (int32_t i = 0; i < model::universes.size(); i++) {
2,354✔
311
    auto search = fill_univ_ids.find(model::universes[i]->id_);
1,520✔
312
    if (search == fill_univ_ids.end()) {
1,520✔
313
      if (root_found) {
834!
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;
834✔
319
        root_univ = i;
834✔
320
      }
321
    }
322
  }
323
  if (!root_found)
834!
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;
834✔
328
}
834✔
329

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

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

336
  std::unordered_set<int32_t> distribcells;
834✔
337

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

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

356
  // By default, add material cells to the list of distributed cells
357
  if (settings::material_cell_offsets) {
834!
358
    for (int64_t i = 0; i < model::cells.size(); ++i) {
4,005✔
359
      if (model::cells[i]->type_ == Fill::MATERIAL)
3,171✔
360
        distribcells.insert(i);
2,289✔
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++) {
4,005✔
367
    Cell& c {*model::cells[i]};
3,171✔
368

369
    if (c.material_.size() > 1) {
3,171✔
370
      if (c.material_.size() != c.n_instances()) {
15!
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) {
3,171✔
380
      if (c.sqrtkT_.size() != c.n_instances()) {
17!
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) {
3,171✔
390
      if (c.density_mult_.size() != c.n_instances()) {
8!
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;
834✔
404
  for (const auto& u : model::universes) {
2,358✔
405
    for (auto idx : u->cells_) {
4,695✔
406
      if (distribcells.find(idx) != distribcells.end()) {
3,171✔
407
        if (!contains(target_univ_ids, u->id_)) {
2,299✔
408
          target_univ_ids.push_back(u->id_);
1,196✔
409
        }
410
        model::cells[idx]->distribcell_index_ =
2,299✔
411
          std::find(target_univ_ids.begin(), target_univ_ids.end(), u->id_) -
2,299✔
412
          target_univ_ids.begin();
4,598✔
413
      }
414
    }
415
  }
416

417
  // Allocate the cell and lattice offset tables.
418
  int n_maps = target_univ_ids.size();
834✔
419
  for (auto& c : model::cells) {
4,005✔
420
    if (c->type_ != Fill::MATERIAL) {
3,171✔
421
      c->offset_.resize(n_maps, C_NONE);
882✔
422
    }
423
  }
424
  for (auto& lat : model::lattices) {
1,067✔
425
    lat->allocate_offset_table(n_maps);
233✔
426
  }
427

428
// Fill the cell and lattice offset tables.
429
#pragma omp parallel for
430
  for (int map = 0; map < target_univ_ids.size(); map++) {
2,030✔
431
    auto target_univ_id = target_univ_ids[map];
1,196✔
432
    std::unordered_map<int32_t, int32_t> univ_count_memo;
1,196✔
433
    for (const auto& univ : model::universes) {
6,169✔
434
      int32_t offset = 0;
4,973✔
435
      for (int32_t cell_indx : univ->cells_) {
22,943✔
436
        Cell& c = *model::cells[cell_indx];
17,970✔
437

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

444
        } else if (c.type_ == Fill::LATTICE) {
7,681✔
445
          c.offset_[map] = offset;
841✔
446
          Lattice& lat = *model::lattices[c.fill_];
841✔
447
          offset += lat.fill_offset_table(target_univ_id, map, univ_count_memo);
841✔
448
        }
449
      }
450
    }
451
  }
1,196✔
452
}
834✔
453

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

456
void count_universe_instances()
834✔
457
{
458
  for (auto& univ : model::universes) {
2,354✔
459
    std::unordered_map<int32_t, int32_t> univ_count_memo;
1,520✔
460
    univ->n_instances_ = count_universe_instances(
1,520✔
461
      model::root_universe, univ->id_, univ_count_memo);
1,520✔
462
  }
1,520✔
463
}
834✔
464

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

467
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
1,313,461✔
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) {
1,313,461✔
472
    return 1;
329,900✔
473
  }
474

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

481
  int count {0};
9,079✔
482
  for (int32_t cell_indx : model::universes[search_univ]->cells_) {
41,013✔
483
    Cell& c = *model::cells[cell_indx];
31,934✔
484

485
    if (c.type_ == Fill::UNIVERSE) {
31,934✔
486
      int32_t next_univ = c.fill_;
21,108✔
487
      count +=
21,108✔
488
        count_universe_instances(next_univ, target_univ_id, univ_count_memo);
21,108✔
489

490
    } else if (c.type_ == Fill::LATTICE) {
10,826✔
491
      Lattice& lat = *model::lattices[c.fill_];
1,945✔
492
      for (auto it = lat.begin(); it != lat.end(); ++it) {
867,787✔
493
        int32_t next_univ = *it;
865,842✔
494
        count +=
865,842✔
495
          count_universe_instances(next_univ, target_univ_id, univ_count_memo);
865,842✔
496
      }
497
    }
498
  }
499

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

503
  return count;
9,079✔
504
}
505

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

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

513
  path << "u" << search_univ.id_ << "->";
233,234✔
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_) {
1,082,085✔
518
    if ((cell_indx == target_cell) && (offset == target_offset)) {
933,128!
519
      Cell& c = *model::cells[cell_indx];
84,277✔
520
      path << "c" << c.id_;
84,277✔
521
      return path.str();
168,554✔
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()};
148,957✔
530
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
848,836!
531
    Cell& c = *model::cells[*cell_it];
848,836✔
532

533
    // Material cells don't contain other cells so ignore them.
534
    if (c.type_ != Fill::MATERIAL) {
848,836✔
535
      int32_t temp_offset = offset + c.offset_[map];
212,596✔
536
      if (c.type_ == Fill::LATTICE) {
212,596!
537
        Lattice& lat = *model::lattices[c.fill_];
212,596✔
538
        int32_t indx = lat.universes_.size() * map + lat.begin().indx_;
212,596✔
539
        temp_offset += lat.offsets_[indx];
212,596✔
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)
212,596✔
545
        break;
148,957✔
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()) {
148,957!
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];
148,957✔
560
  path << "c" << c.id_ << "->";
148,957✔
561

562
  if (c.type_ == Fill::UNIVERSE) {
148,957!
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_];
148,957✔
571
    path << "l" << lat.id_;
148,957✔
572
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
26,277,160!
573
      int32_t indx = lat.universes_.size() * map + it.indx_;
26,277,160✔
574
      int32_t temp_offset = offset + lat.offsets_[indx] + c.offset_[map];
26,277,160✔
575
      if (temp_offset <= target_offset) {
26,277,160✔
576
        offset = temp_offset;
148,957✔
577
        path << "(" << lat.index_to_string(it.indx_) << ")->";
148,957✔
578
        path << distribcell_path_inner(
297,914✔
579
          target_cell, map, target_offset, *model::universes[*it], offset);
297,914✔
580
        return path.str();
297,914✔
581
      }
582
    }
583
    throw std::runtime_error {"Error determining distribcell path."};
×
584
  }
585
}
233,234✔
586

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

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

596
int maximum_levels(int32_t univ)
117,925✔
597
{
598

599
  const auto level_count = model::universe_level_counts.find(univ);
117,925✔
600
  if (level_count != model::universe_level_counts.end()) {
117,925✔
601
    return level_count->second;
116,424✔
602
  }
603

604
  int levels_below {0};
1,501✔
605

606
  for (int32_t cell_indx : model::universes[univ]->cells_) {
4,645✔
607
    Cell& c = *model::cells[cell_indx];
3,144✔
608
    if (c.type_ == Fill::UNIVERSE) {
3,144✔
609
      int32_t next_univ = c.fill_;
644✔
610
      levels_below = std::max(levels_below, maximum_levels(next_univ));
644✔
611
    } else if (c.type_ == Fill::LATTICE) {
2,500✔
612
      Lattice& lat = *model::lattices[c.fill_];
234✔
613
      for (auto it = lat.begin(); it != lat.end(); ++it) {
116,681✔
614
        int32_t next_univ = *it;
116,447✔
615
        levels_below = std::max(levels_below, maximum_levels(next_univ));
116,447✔
616
      }
617
    }
618
  }
619

620
  ++levels_below;
1,501✔
621
  model::universe_level_counts[univ] = levels_below;
1,501✔
622
  return levels_below;
1,501✔
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()
843✔
633
{
634
  model::cells.clear();
843✔
635
  model::cell_map.clear();
843✔
636

637
  model::universes.clear();
843✔
638
  model::universe_map.clear();
843✔
639

640
  model::lattices.clear();
843✔
641
  model::lattice_map.clear();
843✔
642

643
  model::overlap_check_count.clear();
843✔
644
}
843✔
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