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

openmc-dev / openmc / 21936904098

12 Feb 2026 07:04AM UTC coverage: 81.707% (-0.1%) from 81.846%
21936904098

Pull #3800

github

web-flow
Merge a4f57df32 into 26b13083f
Pull Request #3800: Improve install time

16828 of 23309 branches covered (72.2%)

Branch coverage included in aggregate %.

55497 of 65209 relevant lines covered (85.11%)

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

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

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

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

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

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

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

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

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

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

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

91
void adjust_indices()
6,451✔
92
{
93
  // Adjust material/fill idices.
94
  for (auto& c : model::cells) {
32,864✔
95
    if (c->fill_ != C_NONE) {
26,413✔
96
      int32_t id = c->fill_;
5,660✔
97
      auto search_univ = model::universe_map.find(id);
5,660✔
98
      auto search_lat = model::lattice_map.find(id);
5,660✔
99
      if (search_univ != model::universe_map.end()) {
5,660✔
100
        c->type_ = Fill::UNIVERSE;
4,141✔
101
        c->fill_ = search_univ->second;
4,141✔
102
      } else if (search_lat != model::lattice_map.end()) {
1,519!
103
        c->type_ = Fill::LATTICE;
1,519✔
104
        c->fill_ = search_lat->second;
1,519✔
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;
20,753✔
112
      for (auto& mat_id : c->material_) {
42,601✔
113
        if (mat_id != MATERIAL_VOID) {
21,848✔
114
          auto search = model::material_map.find(mat_id);
15,719✔
115
          if (search == model::material_map.end()) {
15,719!
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;
15,719✔
122
        }
123
      }
124
    }
125
  }
126

127
  // Change cell.universe values from IDs to indices.
128
  for (auto& c : model::cells) {
32,864✔
129
    auto search = model::universe_map.find(c->universe_);
26,413✔
130
    if (search != model::universe_map.end()) {
26,413!
131
      c->universe_ = search->second;
26,413✔
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,943✔
140
    l->adjust_indices();
1,492✔
141
  }
142
}
6,451✔
143

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

147
void partition_universes()
6,451✔
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) {
21,361✔
152
    if (univ->cells_.size() > 10) {
14,910✔
153
      // Collect the set of surfaces in this universe.
154
      std::unordered_set<int32_t> surf_inds;
135✔
155
      for (auto i_cell : univ->cells_) {
2,280✔
156
        for (auto token : model::cells[i_cell]->surfaces()) {
8,124✔
157
          surf_inds.insert(std::abs(token) - 1);
5,979✔
158
        }
2,145✔
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;
135✔
164
      for (auto i_surf : surf_inds) {
1,743✔
165
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
1,680!
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
    }
135✔
174
  }
175
}
6,451✔
176

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

179
void assign_temperatures()
6,451✔
180
{
181
  for (auto& c : model::cells) {
32,864✔
182
    // Ignore non-material cells and cells with defined temperature.
183
    if (c->material_.size() == 0)
26,413✔
184
      continue;
5,660✔
185
    if (c->sqrtkT_.size() > 0)
20,753✔
186
      continue;
309✔
187

188
    c->sqrtkT_.reserve(c->material_.size());
20,444✔
189
    for (auto i_mat : c->material_) {
41,983✔
190
      if (i_mat == MATERIAL_VOID) {
21,539✔
191
        // Set void region to 0K.
192
        c->sqrtkT_.push_back(0);
6,129✔
193
      } else {
194
        const auto& mat {model::materials[i_mat]};
15,410✔
195
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
15,410✔
196
      }
197
    }
198
  }
199
}
6,451✔
200

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

203
void finalize_cell_densities()
6,451✔
204
{
205
  for (auto& c : model::cells) {
32,864✔
206
    // Convert to density multipliers.
207
    if (!c->density_mult_.empty()) {
26,413✔
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};
26,353✔
215
    }
216
  }
217
}
6,451✔
218

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

221
void get_temperatures(
6,354✔
222
  vector<vector<double>>& nuc_temps, vector<vector<double>>& thermal_temps)
223
{
224
  for (const auto& cell : model::cells) {
32,503✔
225
    // Skip non-material cells.
226
    if (cell->fill_ != C_NONE)
26,149✔
227
      continue;
5,651✔
228

229
    for (int j = 0; j < cell->material_.size(); ++j) {
42,091✔
230
      // Skip void materials
231
      int i_material = cell->material_[j];
21,593✔
232
      if (i_material == MATERIAL_VOID)
21,593✔
233
        continue;
6,111✔
234

235
      // Get temperature(s) of cell (rounding to nearest integer)
236
      vector<double> cell_temps;
15,482✔
237
      if (cell->sqrtkT_.size() == 1) {
15,482✔
238
        double sqrtkT = cell->sqrtkT_[0];
14,186✔
239
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
14,186✔
240
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
1,296✔
241
        double sqrtkT = cell->sqrtkT_[j];
1,248✔
242
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
1,248✔
243
      } else {
244
        for (double sqrtkT : cell->sqrtkT_)
960✔
245
          cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
912✔
246
      }
247

248
      const auto& mat {model::materials[i_material]};
15,482✔
249
      for (const auto& i_nuc : mat->nuclide_) {
69,720✔
250
        for (double temperature : cell_temps) {
109,340✔
251
          // Add temperature if it hasn't already been added
252
          if (!contains(nuc_temps[i_nuc], temperature))
55,102✔
253
            nuc_temps[i_nuc].push_back(temperature);
24,370✔
254
        }
255
      }
256

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

261
        for (double temperature : cell_temps) {
5,148✔
262
          // Add temperature if it hasn't already been added
263
          if (!contains(thermal_temps[i_sab], temperature))
2,574✔
264
            thermal_temps[i_sab].push_back(temperature);
1,011✔
265
        }
266
      }
267
    }
15,482✔
268
  }
269
}
6,354✔
270

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

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

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

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

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

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

297
  // Find all the universes contained in a lattice.
298
  for (const auto& lat : model::lattices) {
7,943✔
299
    for (auto it = lat->begin(); it != lat->end(); ++it) {
728,408✔
300
      fill_univ_ids.insert(*it);
726,916✔
301
    }
302
    if (lat->outer_ != NO_OUTER_UNIVERSE) {
1,492✔
303
      fill_univ_ids.insert(lat->outer_);
333✔
304
    }
305
  }
306

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

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

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

336
  std::unordered_set<int32_t> distribcells;
6,449✔
337

338
  // start with any cells manually specified via the C++ API
339
  if (user_distribcells) {
6,449✔
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) {
13,949✔
345
    auto* distrib_filt = dynamic_cast<DistribcellFilter*>(filt.get());
7,500!
346
    auto* cell_inst_filt = dynamic_cast<CellInstanceFilter*>(filt.get());
7,500!
347
    if (distrib_filt) {
7,500✔
348
      distribcells.insert(distrib_filt->cell());
144✔
349
    }
350
    if (cell_inst_filt) {
7,500✔
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) {
6,449!
358
    for (int64_t i = 0; i < model::cells.size(); ++i) {
32,908✔
359
      if (model::cells[i]->type_ == Fill::MATERIAL)
26,459✔
360
        distribcells.insert(i);
20,775✔
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++) {
32,908✔
367
    Cell& c {*model::cells[i]};
26,459✔
368

369
    if (c.material_.size() > 1) {
26,459✔
370
      if (c.material_.size() != c.n_instances()) {
165!
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) {
26,459✔
380
      if (c.sqrtkT_.size() != c.n_instances()) {
213!
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) {
26,459✔
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;
6,449✔
404
  for (const auto& u : model::universes) {
21,381✔
405
    for (auto idx : u->cells_) {
41,391✔
406
      if (distribcells.find(idx) != distribcells.end()) {
26,459✔
407
        if (!contains(target_univ_ids, u->id_)) {
20,835✔
408
          target_univ_ids.push_back(u->id_);
12,798✔
409
        }
410
        model::cells[idx]->distribcell_index_ =
20,835✔
411
          std::find(target_univ_ids.begin(), target_univ_ids.end(), u->id_) -
20,835✔
412
          target_univ_ids.begin();
41,670✔
413
      }
414
    }
415
  }
416

417
  // Allocate the cell and lattice offset tables.
418
  int n_maps = target_univ_ids.size();
6,449✔
419
  for (auto& c : model::cells) {
32,908✔
420
    if (c->type_ != Fill::MATERIAL) {
26,459✔
421
      c->offset_.resize(n_maps, C_NONE);
5,684✔
422
    }
423
  }
424
  for (auto& lat : model::lattices) {
7,953✔
425
    lat->allocate_offset_table(n_maps);
1,504✔
426
  }
427

428
// Fill the cell and lattice offset tables.
429
#pragma omp parallel for
3,653✔
430
  for (int map = 0; map < target_univ_ids.size(); map++) {
6,589✔
431
    auto target_univ_id = target_univ_ids[map];
3,793✔
432
    std::unordered_map<int32_t, int32_t> univ_count_memo;
3,793✔
433
    for (const auto& univ : model::universes) {
17,402✔
434
      int32_t offset = 0;
13,609✔
435
      for (int32_t cell_indx : univ->cells_) {
60,701✔
436
        Cell& c = *model::cells[cell_indx];
47,092✔
437

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

444
        } else if (c.type_ == Fill::LATTICE) {
21,147✔
445
          c.offset_[map] = offset;
2,214✔
446
          Lattice& lat = *model::lattices[c.fill_];
2,214✔
447
          offset += lat.fill_offset_table(target_univ_id, map, univ_count_memo);
2,214✔
448
        }
449
      }
450
    }
451
  }
3,793✔
452
}
6,449✔
453

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

456
void count_universe_instances()
6,451✔
457
{
458
  for (auto& univ : model::universes) {
21,361✔
459
    std::unordered_map<int32_t, int32_t> univ_count_memo;
14,910✔
460
    univ->n_instances_ = count_universe_instances(
14,910✔
461
      model::root_universe, univ->id_, univ_count_memo);
14,910✔
462
  }
14,910✔
463
}
6,451✔
464

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

467
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
16,062,125✔
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) {
16,062,125✔
472
    return 1;
2,049,782✔
473
  }
474

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

481
  int count {0};
8,051,691✔
482
  for (int32_t cell_indx : model::universes[search_univ]->cells_) {
16,241,627✔
483
    Cell& c = *model::cells[cell_indx];
8,189,936✔
484

485
    if (c.type_ == Fill::UNIVERSE) {
8,189,936✔
486
      int32_t next_univ = c.fill_;
127,414✔
487
      count +=
127,414✔
488
        count_universe_instances(next_univ, target_univ_id, univ_count_memo);
127,414✔
489

490
    } else if (c.type_ == Fill::LATTICE) {
8,062,522✔
491
      Lattice& lat = *model::lattices[c.fill_];
15,988✔
492
      for (auto it = lat.begin(); it != lat.end(); ++it) {
9,315,632✔
493
        int32_t next_univ = *it;
9,299,644✔
494
        count +=
9,299,644✔
495
          count_universe_instances(next_univ, target_univ_id, univ_count_memo);
9,299,644✔
496
      }
497
    }
498
  }
499

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

503
  return count;
8,051,691✔
504
}
505

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

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

513
  path << "u" << search_univ.id_ << "->";
2,099,106✔
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_) {
9,738,765✔
518
    if ((cell_indx == target_cell) && (offset == target_offset)) {
8,398,152!
519
      Cell& c = *model::cells[cell_indx];
758,493✔
520
      path << "c" << c.id_;
758,493✔
521
      return path.str();
1,516,986✔
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,340,613✔
530
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
7,639,524!
531
    Cell& c = *model::cells[*cell_it];
7,639,524✔
532

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

562
  if (c.type_ == Fill::UNIVERSE) {
1,340,613!
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,340,613✔
571
    path << "l" << lat.id_;
1,340,613✔
572
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
236,494,440!
573
      int32_t indx = lat.universes_.size() * map + it.indx_;
236,494,440✔
574
      int32_t temp_offset = offset + lat.offsets_[indx] + c.offset_[map];
236,494,440✔
575
      if (temp_offset <= target_offset) {
236,494,440✔
576
        offset = temp_offset;
1,340,613✔
577
        path << "(" << lat.index_to_string(it.indx_) << ")->";
1,340,613✔
578
        path << distribcell_path_inner(
2,681,226✔
579
          target_cell, map, target_offset, *model::universes[*it], offset);
2,681,226✔
580
        return path.str();
2,681,226✔
581
      }
582
    }
583
    throw std::runtime_error {"Error determining distribcell path."};
×
584
  }
585
}
2,099,106✔
586

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

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

596
int maximum_levels(int32_t univ)
737,643✔
597
{
598

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

604
  int levels_below {0};
14,787✔
605

606
  for (int32_t cell_indx : model::universes[univ]->cells_) {
41,077✔
607
    Cell& c = *model::cells[cell_indx];
26,290✔
608
    if (c.type_ == Fill::UNIVERSE) {
26,290✔
609
      int32_t next_univ = c.fill_;
4,141✔
610
      levels_below = std::max(levels_below, maximum_levels(next_univ));
4,141✔
611
    } else if (c.type_ == Fill::LATTICE) {
22,149✔
612
      Lattice& lat = *model::lattices[c.fill_];
1,519✔
613
      for (auto it = lat.begin(); it != lat.end(); ++it) {
728,570✔
614
        int32_t next_univ = *it;
727,051✔
615
        levels_below = std::max(levels_below, maximum_levels(next_univ));
727,051✔
616
      }
617
    }
618
  }
619

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

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

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

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

637
  model::universes.clear();
6,552✔
638
  model::universe_map.clear();
6,552✔
639

640
  model::lattices.clear();
6,552✔
641
  model::lattice_map.clear();
6,552✔
642

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