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

openmc-dev / openmc / 17681453486

12 Sep 2025 05:21PM UTC coverage: 85.189% (-0.02%) from 85.206%
17681453486

Pull #3546

github

web-flow
Merge 454c67301 into c7175289e
Pull Request #3546: Add distributed cell density multipliers

160 of 200 new or added lines in 13 files covered. (80.0%)

153 existing lines in 7 files now uncovered.

53094 of 62325 relevant lines covered (85.19%)

39134622.1 hits per line

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

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

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

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

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

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

55
void read_geometry_xml(pugi::xml_node root)
7,516✔
56
{
57
  // Read surfaces, cells, lattice
58
  read_surfaces(root);
7,516✔
59
  read_cells(root);
7,516✔
60
  read_lattices(root);
7,514✔
61

62
  // Check to make sure a boundary condition was applied to at least one
63
  // surface
64
  bool boundary_exists = false;
7,514✔
65
  for (const auto& surf : model::surfaces) {
18,942✔
66
    if (surf->bc_) {
18,909✔
67
      boundary_exists = true;
7,481✔
68
      break;
7,481✔
69
    }
70
  }
71

72
  if (settings::run_mode != RunMode::PLOTTING &&
7,514✔
73
      settings::run_mode != RunMode::VOLUME && !boundary_exists) {
7,238✔
74
    fatal_error("No boundary conditions were applied to any surfaces!");
×
75
  }
76

77
  // Allocate universes, universe cell arrays, and assign base universe
78
  model::root_universe = find_root_universe();
7,514✔
79

80
  // if the root universe is DAGMC geometry, make sure the model is well-formed
81
  check_dagmc_root_univ();
7,514✔
82
}
7,514✔
83

84
//==============================================================================
85

86
void adjust_indices()
7,516✔
87
{
88
  // Adjust material/fill idices.
89
  for (auto& c : model::cells) {
41,306✔
90
    if (c->fill_ != C_NONE) {
33,790✔
91
      int32_t id = c->fill_;
7,003✔
92
      auto search_univ = model::universe_map.find(id);
7,003✔
93
      auto search_lat = model::lattice_map.find(id);
7,003✔
94
      if (search_univ != model::universe_map.end()) {
7,003✔
95
        c->type_ = Fill::UNIVERSE;
5,023✔
96
        c->fill_ = search_univ->second;
5,023✔
97
      } else if (search_lat != model::lattice_map.end()) {
1,980✔
98
        c->type_ = Fill::LATTICE;
1,980✔
99
        c->fill_ = search_lat->second;
1,980✔
100
      } else {
101
        fatal_error(fmt::format("Specified fill {} on cell {} is neither a "
×
102
                                "universe nor a lattice.",
103
          id, c->id_));
×
104
      }
105
    } else {
106
      c->type_ = Fill::MATERIAL;
26,787✔
107
      for (auto& mat_id : c->material_) {
55,277✔
108
        if (mat_id != MATERIAL_VOID) {
28,490✔
109
          auto search = model::material_map.find(mat_id);
19,815✔
110
          if (search == model::material_map.end()) {
19,815✔
111
            fatal_error(
×
112
              fmt::format("Could not find material {} specified on cell {}",
×
113
                mat_id, c->id_));
×
114
          }
115
          // Change from ID to index
116
          mat_id = search->second;
19,815✔
117
        }
118
      }
119
    }
120
  }
121

122
  // Change cell.universe values from IDs to indices.
123
  for (auto& c : model::cells) {
41,306✔
124
    auto search = model::universe_map.find(c->universe_);
33,790✔
125
    if (search != model::universe_map.end()) {
33,790✔
126
      c->universe_ = search->second;
33,790✔
127
    } else {
128
      fatal_error(fmt::format("Could not find universe {} specified on cell {}",
×
129
        c->universe_, c->id_));
×
130
    }
131
  }
132

133
  // Change all lattice universe values from IDs to indices.
134
  for (auto& l : model::lattices) {
9,423✔
135
    l->adjust_indices();
1,907✔
136
  }
137
}
7,516✔
138

139
//==============================================================================
140
//! Partition some universes with many z-planes for faster find_cell searches.
141

142
void partition_universes()
7,516✔
143
{
144
  // Iterate over universes with more than 10 cells.  (Fewer than 10 is likely
145
  // not worth partitioning.)
146
  for (const auto& univ : model::universes) {
26,473✔
147
    if (univ->cells_.size() > 10) {
18,957✔
148
      // Collect the set of surfaces in this universe.
149
      std::unordered_set<int32_t> surf_inds;
183✔
150
      for (auto i_cell : univ->cells_) {
3,076✔
151
        for (auto token : model::cells[i_cell]->surfaces()) {
10,964✔
152
          surf_inds.insert(std::abs(token) - 1);
8,071✔
153
        }
2,893✔
154
      }
155

156
      // Partition the universe if there are more than 5 z-planes.  (Fewer than
157
      // 5 is likely not worth it.)
158
      int n_zplanes = 0;
183✔
159
      for (auto i_surf : surf_inds) {
2,351✔
160
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
2,264✔
161
          ++n_zplanes;
640✔
162
          if (n_zplanes > 5) {
640✔
163
            univ->partitioner_ = make_unique<UniversePartitioner>(*univ);
96✔
164
            break;
96✔
165
          }
166
        }
167
      }
168
    }
183✔
169
  }
170
}
7,516✔
171

172
//==============================================================================
173

174
void assign_temperatures()
7,516✔
175
{
176
  for (auto& c : model::cells) {
41,306✔
177
    // Ignore non-material cells and cells with defined temperature.
178
    if (c->material_.size() == 0)
33,790✔
179
      continue;
7,003✔
180
    if (c->sqrtkT_.size() > 0)
26,787✔
181
      continue;
600✔
182

183
    c->sqrtkT_.reserve(c->material_.size());
26,187✔
184
    for (auto i_mat : c->material_) {
54,032✔
185
      if (i_mat == MATERIAL_VOID) {
27,845✔
186
        // Set void region to 0K.
187
        c->sqrtkT_.push_back(0);
8,675✔
188
      } else {
189
        const auto& mat {model::materials[i_mat]};
19,170✔
190
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
19,170✔
191
      }
192
    }
193
  }
194
}
7,516✔
195

196
//==============================================================================
197

198
void finalize_cell_densities()
5,829✔
199
{
200
  for (auto& c : model::cells) {
27,823✔
201
    // Convert to density multipliers.
202
    if (c->xml_set_density_) {
21,994✔
203
      for (int32_t instance = 0; instance < c->rho_mult_.size(); ++instance) {
80✔
204
        c->rho_mult_[instance] /=
64✔
205
          model::materials[c->material(instance)]->density_gpcc();
64✔
206
      }
207
    }
208
  }
209
}
5,829✔
210

211
//==============================================================================
212

213
void get_temperatures(
7,240✔
214
  vector<vector<double>>& nuc_temps, vector<vector<double>>& thermal_temps)
215
{
216
  for (const auto& cell : model::cells) {
40,457✔
217
    // Skip non-material cells.
218
    if (cell->fill_ != C_NONE)
33,217✔
219
      continue;
6,990✔
220

221
    for (int j = 0; j < cell->material_.size(); ++j) {
54,157✔
222
      // Skip void materials
223
      int i_material = cell->material_[j];
27,930✔
224
      if (i_material == MATERIAL_VOID)
27,930✔
225
        continue;
8,559✔
226

227
      // Get temperature(s) of cell (rounding to nearest integer)
228
      vector<double> cell_temps;
19,371✔
229
      if (cell->sqrtkT_.size() == 1) {
19,371✔
230
        double sqrtkT = cell->sqrtkT_[0];
17,467✔
231
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
17,467✔
232
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
1,904✔
233
        double sqrtkT = cell->sqrtkT_[j];
1,888✔
234
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
1,888✔
235
      } else {
236
        for (double sqrtkT : cell->sqrtkT_)
80✔
237
          cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
64✔
238
      }
239

240
      const auto& mat {model::materials[i_material]};
19,371✔
241
      for (const auto& i_nuc : mat->nuclide_) {
89,865✔
242
        for (double temperature : cell_temps) {
141,036✔
243
          // Add temperature if it hasn't already been added
244
          if (!contains(nuc_temps[i_nuc], temperature))
70,542✔
245
            nuc_temps[i_nuc].push_back(temperature);
29,248✔
246
        }
247
      }
248

249
      for (const auto& table : mat->thermal_tables_) {
22,687✔
250
        // Get index in data::thermal_scatt array
251
        int i_sab = table.index_table;
3,316✔
252

253
        for (double temperature : cell_temps) {
6,632✔
254
          // Add temperature if it hasn't already been added
255
          if (!contains(thermal_temps[i_sab], temperature))
3,316✔
256
            thermal_temps[i_sab].push_back(temperature);
1,204✔
257
        }
258
      }
259
    }
19,371✔
260
  }
261
}
7,240✔
262

263
//==============================================================================
264

265
void finalize_geometry()
7,516✔
266
{
267
  // Perform some final operations to set up the geometry
268
  adjust_indices();
7,516✔
269
  count_universe_instances();
7,516✔
270
  partition_universes();
7,516✔
271

272
  // Assign temperatures to cells that don't have temperatures already assigned
273
  assign_temperatures();
7,516✔
274

275
  // Determine number of nested coordinate levels in the geometry
276
  model::n_coord_levels = maximum_levels(model::root_universe);
7,516✔
277
}
7,516✔
278

279
//==============================================================================
280

281
int32_t find_root_universe()
7,516✔
282
{
283
  // Find all the universes listed as a cell fill.
284
  std::unordered_set<int32_t> fill_univ_ids;
7,516✔
285
  for (const auto& c : model::cells) {
41,306✔
286
    fill_univ_ids.insert(c->fill_);
33,790✔
287
  }
288

289
  // Find all the universes contained in a lattice.
290
  for (const auto& lat : model::lattices) {
9,423✔
291
    for (auto it = lat->begin(); it != lat->end(); ++it) {
893,027✔
292
      fill_univ_ids.insert(*it);
891,120✔
293
    }
294
    if (lat->outer_ != NO_OUTER_UNIVERSE) {
1,907✔
295
      fill_univ_ids.insert(lat->outer_);
387✔
296
    }
297
  }
298

299
  // Figure out which universe is not in the set.  This is the root universe.
300
  bool root_found {false};
7,516✔
301
  int32_t root_univ;
302
  for (int32_t i = 0; i < model::universes.size(); i++) {
26,473✔
303
    auto search = fill_univ_ids.find(model::universes[i]->id_);
18,957✔
304
    if (search == fill_univ_ids.end()) {
18,957✔
305
      if (root_found) {
7,516✔
UNCOV
306
        fatal_error("Two or more universes are not used as fill universes, so "
×
307
                    "it is not possible to distinguish which one is the root "
308
                    "universe.");
309
      } else {
310
        root_found = true;
7,516✔
311
        root_univ = i;
7,516✔
312
      }
313
    }
314
  }
315
  if (!root_found)
7,516✔
UNCOV
316
    fatal_error("Could not find a root universe.  Make sure "
×
317
                "there are no circular dependencies in the geometry.");
318

319
  return root_univ;
7,516✔
320
}
7,516✔
321

322
//==============================================================================
323

324
void prepare_distribcell(const std::vector<int32_t>* user_distribcells)
7,512✔
325
{
326
  write_message("Preparing distributed cell instances...", 5);
7,512✔
327

328
  std::unordered_set<int32_t> distribcells;
7,512✔
329

330
  // start with any cells manually specified via the C++ API
331
  if (user_distribcells) {
7,512✔
332
    distribcells.insert(user_distribcells->begin(), user_distribcells->end());
16✔
333
  }
334

335
  // Find all cells listed in a DistribcellFilter or CellInstanceFilter
336
  for (auto& filt : model::tally_filters) {
15,616✔
337
    auto* distrib_filt = dynamic_cast<DistribcellFilter*>(filt.get());
8,104✔
338
    auto* cell_inst_filt = dynamic_cast<CellInstanceFilter*>(filt.get());
8,104✔
339
    if (distrib_filt) {
8,104✔
340
      distribcells.insert(distrib_filt->cell());
217✔
341
    }
342
    if (cell_inst_filt) {
8,104✔
343
      const auto& filter_cells = cell_inst_filt->cells();
34✔
344
      distribcells.insert(filter_cells.begin(), filter_cells.end());
34✔
345
    }
346
  }
347

348
  // By default, add material cells to the list of distributed cells
349
  if (settings::material_cell_offsets) {
7,512✔
350
    for (int64_t i = 0; i < model::cells.size(); ++i) {
41,354✔
351
      if (model::cells[i]->type_ == Fill::MATERIAL)
33,842✔
352
        distribcells.insert(i);
26,807✔
353
    }
354
  }
355

356
  // Make sure that the number of materials/temperatures matches the number of
357
  // cell instances.
358
  for (int i = 0; i < model::cells.size(); i++) {
41,354✔
359
    Cell& c {*model::cells[i]};
33,842✔
360

361
    if (c.material_.size() > 1) {
33,842✔
362
      if (c.material_.size() != c.n_instances()) {
261✔
UNCOV
363
        fatal_error(fmt::format(
×
364
          "Cell {} was specified with {} materials but has {} distributed "
365
          "instances. The number of materials must equal one or the number "
366
          "of instances.",
UNCOV
367
          c.id_, c.material_.size(), c.n_instances()));
×
368
      }
369
    }
370

371
    if (c.sqrtkT_.size() > 1) {
33,842✔
372
      if (c.sqrtkT_.size() != c.n_instances()) {
262✔
UNCOV
373
        fatal_error(fmt::format(
×
374
          "Cell {} was specified with {} temperatures but has {} distributed "
375
          "instances. The number of temperatures must equal one or the number "
376
          "of instances.",
UNCOV
377
          c.id_, c.sqrtkT_.size(), c.n_instances()));
×
378
      }
379
    }
380

381
    if (c.rho_mult_.size() > 1) {
33,842✔
382
      if (c.rho_mult_.size() != c.n_instances()) {
16✔
NEW
383
        fatal_error(fmt::format("Cell {} was specified with {} density "
×
384
                                "multipliers but has {} distributed "
385
                                "instances. The number of density multipliers "
386
                                "must equal one or the number "
387
                                "of instances.",
NEW
388
          c.id_, c.rho_mult_.size(), c.n_instances()));
×
389
      }
390
    }
391
  }
392

393
  // Search through universes for material cells and assign each one a
394
  // distribcell array index according to the containing universe.
395
  vector<int32_t> target_univ_ids;
7,512✔
396
  for (const auto& u : model::universes) {
26,497✔
397
    for (auto idx : u->cells_) {
52,827✔
398
      if (distribcells.find(idx) != distribcells.end()) {
33,842✔
399
        if (!contains(target_univ_ids, u->id_)) {
26,887✔
400
          target_univ_ids.push_back(u->id_);
16,287✔
401
        }
402
        model::cells[idx]->distribcell_index_ =
26,887✔
403
          std::find(target_univ_ids.begin(), target_univ_ids.end(), u->id_) -
26,887✔
404
          target_univ_ids.begin();
53,774✔
405
      }
406
    }
407
  }
408

409
  // Allocate the cell and lattice offset tables.
410
  int n_maps = target_univ_ids.size();
7,512✔
411
  for (auto& c : model::cells) {
41,354✔
412
    if (c->type_ != Fill::MATERIAL) {
33,842✔
413
      c->offset_.resize(n_maps, C_NONE);
7,035✔
414
    }
415
  }
416
  for (auto& lat : model::lattices) {
9,435✔
417
    lat->allocate_offset_table(n_maps);
1,923✔
418
  }
419

420
// Fill the cell and lattice offset tables.
421
#pragma omp parallel for
4,257✔
422
  for (int map = 0; map < target_univ_ids.size(); map++) {
7,733✔
423
    auto target_univ_id = target_univ_ids[map];
4,478✔
424
    std::unordered_map<int32_t, int32_t> univ_count_memo;
4,478✔
425
    for (const auto& univ : model::universes) {
21,986✔
426
      int32_t offset = 0;
17,508✔
427
      for (int32_t cell_indx : univ->cells_) {
81,054✔
428
        Cell& c = *model::cells[cell_indx];
63,546✔
429

430
        if (c.type_ == Fill::UNIVERSE) {
63,546✔
431
          c.offset_[map] = offset;
35,879✔
432
          int32_t search_univ = c.fill_;
35,879✔
433
          offset += count_universe_instances(
35,879✔
434
            search_univ, target_univ_id, univ_count_memo);
435

436
        } else if (c.type_ == Fill::LATTICE) {
27,667✔
437
          c.offset_[map] = offset;
2,916✔
438
          Lattice& lat = *model::lattices[c.fill_];
2,916✔
439
          offset += lat.fill_offset_table(target_univ_id, map, univ_count_memo);
2,916✔
440
        }
441
      }
442
    }
443
  }
4,478✔
444
}
7,512✔
445

446
//==============================================================================
447

448
void count_universe_instances()
7,516✔
449
{
450
  for (auto& univ : model::universes) {
26,473✔
451
    std::unordered_map<int32_t, int32_t> univ_count_memo;
18,957✔
452
    univ->n_instances_ = count_universe_instances(
18,957✔
453
      model::root_universe, univ->id_, univ_count_memo);
18,957✔
454
  }
18,957✔
455
}
7,516✔
456

457
//==============================================================================
458

459
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
22,089,853✔
460
  std::unordered_map<int32_t, int32_t>& univ_count_memo)
461
{
462
  // If this is the target, it can't contain itself.
463
  if (model::universes[search_univ]->id_ == target_univ_id) {
22,089,853✔
464
    return 1;
2,512,874✔
465
  }
466

467
  // If we have already counted the number of instances, reuse that value.
468
  auto search = univ_count_memo.find(search_univ);
19,576,979✔
469
  if (search != univ_count_memo.end()) {
19,576,979✔
470
    return search->second;
7,511,284✔
471
  }
472

473
  int count {0};
12,065,695✔
474
  for (int32_t cell_indx : model::universes[search_univ]->cells_) {
24,313,844✔
475
    Cell& c = *model::cells[cell_indx];
12,248,149✔
476

477
    if (c.type_ == Fill::UNIVERSE) {
12,248,149✔
478
      int32_t next_univ = c.fill_;
168,157✔
479
      count +=
168,157✔
480
        count_universe_instances(next_univ, target_univ_id, univ_count_memo);
168,157✔
481

482
    } else if (c.type_ == Fill::LATTICE) {
12,079,992✔
483
      Lattice& lat = *model::lattices[c.fill_];
21,417✔
484
      for (auto it = lat.begin(); it != lat.end(); ++it) {
12,666,637✔
485
        int32_t next_univ = *it;
12,645,220✔
486
        count +=
12,645,220✔
487
          count_universe_instances(next_univ, target_univ_id, univ_count_memo);
12,645,220✔
488
      }
489
    }
490
  }
491

492
  // Remember the number of instances in this universe.
493
  univ_count_memo[search_univ] = count;
12,065,695✔
494

495
  return count;
12,065,695✔
496
}
497

498
//==============================================================================
499

500
std::string distribcell_path_inner(int32_t target_cell, int32_t map,
2,566,366✔
501
  int32_t target_offset, const Universe& search_univ, int32_t offset)
502
{
503
  std::stringstream path;
2,566,366✔
504

505
  path << "u" << search_univ.id_ << "->";
2,566,366✔
506

507
  // Check to see if this universe directly contains the target cell.  If so,
508
  // write to the path and return.
509
  for (int32_t cell_indx : search_univ.cells_) {
11,904,563✔
510
    if ((cell_indx == target_cell) && (offset == target_offset)) {
10,265,640✔
511
      Cell& c = *model::cells[cell_indx];
927,443✔
512
      path << "c" << c.id_;
927,443✔
513
      return path.str();
1,854,886✔
514
    }
515
  }
516

517
  // The target must be further down the geometry tree and contained in a fill
518
  // cell or lattice cell in this universe.  Find which cell contains the
519
  // target.
520
  vector<std::int32_t>::const_reverse_iterator cell_it {
521
    search_univ.cells_.crbegin()};
1,638,923✔
522
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
9,337,812✔
523
    Cell& c = *model::cells[*cell_it];
9,337,812✔
524

525
    // Material cells don't contain other cells so ignore them.
526
    if (c.type_ != Fill::MATERIAL) {
9,337,812✔
527
      int32_t temp_offset = offset + c.offset_[map];
2,339,172✔
528
      if (c.type_ == Fill::LATTICE) {
2,339,172✔
529
        Lattice& lat = *model::lattices[c.fill_];
2,339,172✔
530
        int32_t indx = lat.universes_.size() * map + lat.begin().indx_;
2,339,172✔
531
        temp_offset += lat.offsets_[indx];
2,339,172✔
532
      }
533

534
      // The desired cell is the first cell that gives an offset smaller or
535
      // equal to the target offset.
536
      if (temp_offset <= target_offset)
2,339,172✔
537
        break;
1,638,923✔
538
    }
539
  }
540

541
  // if we get through the loop without finding an appropriate entry, throw
542
  // an error
543
  if (cell_it == search_univ.cells_.crend()) {
1,638,923✔
UNCOV
544
    fatal_error(
×
UNCOV
545
      fmt::format("Failed to generate a text label for distribcell with ID {}."
×
546
                  "The current label is: '{}'",
547
        model::cells[target_cell]->id_, path.str()));
×
548
  }
549

550
  // Add the cell to the path string.
551
  Cell& c = *model::cells[*cell_it];
1,638,923✔
552
  path << "c" << c.id_ << "->";
1,638,923✔
553

554
  if (c.type_ == Fill::UNIVERSE) {
1,638,923✔
555
    // Recurse into the fill cell.
UNCOV
556
    offset += c.offset_[map];
×
UNCOV
557
    path << distribcell_path_inner(
×
UNCOV
558
      target_cell, map, target_offset, *model::universes[c.fill_], offset);
×
559
    return path.str();
×
560
  } else {
561
    // Recurse into the lattice cell.
562
    Lattice& lat = *model::lattices[c.fill_];
1,638,923✔
563
    path << "l" << lat.id_;
1,638,923✔
564
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
289,050,170✔
565
      int32_t indx = lat.universes_.size() * map + it.indx_;
289,050,170✔
566
      int32_t temp_offset = offset + lat.offsets_[indx] + c.offset_[map];
289,050,170✔
567
      if (temp_offset <= target_offset) {
289,050,170✔
568
        offset = temp_offset;
1,638,923✔
569
        path << "(" << lat.index_to_string(it.indx_) << ")->";
1,638,923✔
570
        path << distribcell_path_inner(
3,277,846✔
571
          target_cell, map, target_offset, *model::universes[*it], offset);
3,277,846✔
572
        return path.str();
3,277,846✔
573
      }
574
    }
UNCOV
575
    throw std::runtime_error {"Error determining distribcell path."};
×
576
  }
577
}
2,566,366✔
578

579
std::string distribcell_path(
927,443✔
580
  int32_t target_cell, int32_t map, int32_t target_offset)
581
{
582
  auto& root_univ = *model::universes[model::root_universe];
927,443✔
583
  return distribcell_path_inner(target_cell, map, target_offset, root_univ, 0);
927,443✔
584
}
585

586
//==============================================================================
587

588
int maximum_levels(int32_t univ)
904,044✔
589
{
590

591
  const auto level_count = model::universe_level_counts.find(univ);
904,044✔
592
  if (level_count != model::universe_level_counts.end()) {
904,044✔
593
    return level_count->second;
885,256✔
594
  }
595

596
  int levels_below {0};
18,788✔
597

598
  for (int32_t cell_indx : model::universes[univ]->cells_) {
52,401✔
599
    Cell& c = *model::cells[cell_indx];
33,613✔
600
    if (c.type_ == Fill::UNIVERSE) {
33,613✔
601
      int32_t next_univ = c.fill_;
5,023✔
602
      levels_below = std::max(levels_below, maximum_levels(next_univ));
5,023✔
603
    } else if (c.type_ == Fill::LATTICE) {
28,590✔
604
      Lattice& lat = *model::lattices[c.fill_];
1,980✔
605
      for (auto it = lat.begin(); it != lat.end(); ++it) {
893,485✔
606
        int32_t next_univ = *it;
891,505✔
607
        levels_below = std::max(levels_below, maximum_levels(next_univ));
891,505✔
608
      }
609
    }
610
  }
611

612
  ++levels_below;
18,788✔
613
  model::universe_level_counts[univ] = levels_below;
18,788✔
614
  return levels_below;
18,788✔
615
}
616

617
bool is_root_universe(int32_t univ_id)
16,882✔
618
{
619
  return model::universe_map[univ_id] == model::root_universe;
16,882✔
620
}
621

622
//==============================================================================
623

624
void free_memory_geometry()
7,797✔
625
{
626
  model::cells.clear();
7,797✔
627
  model::cell_map.clear();
7,797✔
628

629
  model::universes.clear();
7,797✔
630
  model::universe_map.clear();
7,797✔
631

632
  model::lattices.clear();
7,797✔
633
  model::lattice_map.clear();
7,797✔
634

635
  model::overlap_check_count.clear();
7,797✔
636
}
7,797✔
637

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