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

openmc-dev / openmc / 17598200653

09 Sep 2025 11:18PM UTC coverage: 85.18% (-0.03%) from 85.209%
17598200653

Pull #3546

github

web-flow
Merge c6e1ade8d into 366509051
Pull Request #3546: Add distributed cell density multipliers

147 of 192 new or added lines in 12 files covered. (76.56%)

166 existing lines in 8 files now uncovered.

53068 of 62301 relevant lines covered (85.18%)

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

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

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

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

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

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

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

72
  if (settings::run_mode != RunMode::PLOTTING &&
7,378✔
73
      settings::run_mode != RunMode::VOLUME && !boundary_exists) {
7,102✔
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,378✔
79

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

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

86
void adjust_indices()
7,380✔
87
{
88
  // Adjust material/fill idices.
89
  for (auto& c : model::cells) {
40,552✔
90
    if (c->fill_ != C_NONE) {
33,172✔
91
      int32_t id = c->fill_;
6,935✔
92
      auto search_univ = model::universe_map.find(id);
6,935✔
93
      auto search_lat = model::lattice_map.find(id);
6,935✔
94
      if (search_univ != model::universe_map.end()) {
6,935✔
95
        c->type_ = Fill::UNIVERSE;
4,993✔
96
        c->fill_ = search_univ->second;
4,993✔
97
      } else if (search_lat != model::lattice_map.end()) {
1,942✔
98
        c->type_ = Fill::LATTICE;
1,942✔
99
        c->fill_ = search_lat->second;
1,942✔
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,237✔
107
      for (auto& mat_id : c->material_) {
54,080✔
108
        if (mat_id != MATERIAL_VOID) {
27,843✔
109
          auto search = model::material_map.find(mat_id);
19,245✔
110
          if (search == model::material_map.end()) {
19,245✔
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,245✔
117
        }
118
      }
119
    }
120
  }
121

122
  // Change cell.universe values from IDs to indices.
123
  for (auto& c : model::cells) {
40,552✔
124
    auto search = model::universe_map.find(c->universe_);
33,172✔
125
    if (search != model::universe_map.end()) {
33,172✔
126
      c->universe_ = search->second;
33,172✔
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,247✔
135
    l->adjust_indices();
1,867✔
136
  }
137
}
7,380✔
138

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

142
void partition_universes()
7,380✔
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,126✔
147
    if (univ->cells_.size() > 10) {
18,746✔
148
      // Collect the set of surfaces in this universe.
149
      std::unordered_set<int32_t> surf_inds;
182✔
150
      for (auto i_cell : univ->cells_) {
3,064✔
151
        for (auto token : model::cells[i_cell]->surfaces()) {
10,920✔
152
          surf_inds.insert(std::abs(token) - 1);
8,038✔
153
        }
2,882✔
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;
182✔
159
      for (auto i_surf : surf_inds) {
2,342✔
160
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
2,256✔
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
    }
182✔
169
  }
170
}
7,380✔
171

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

174
void assign_temperatures()
7,380✔
175
{
176
  for (auto& c : model::cells) {
40,552✔
177
    // Ignore non-material cells and cells with defined temperature.
178
    if (c->material_.size() == 0)
33,172✔
179
      continue;
6,935✔
180
    if (c->sqrtkT_.size() > 0)
26,237✔
181
      continue;
479✔
182

183
    c->sqrtkT_.reserve(c->material_.size());
25,758✔
184
    for (auto i_mat : c->material_) {
53,104✔
185
      if (i_mat == MATERIAL_VOID) {
27,346✔
186
        // Set void region to 0K.
187
        c->sqrtkT_.push_back(0);
8,598✔
188
      } else {
189
        const auto& mat {model::materials[i_mat]};
18,748✔
190
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
18,748✔
191
      }
192
    }
193
  }
194
}
7,380✔
195

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

198
void finalize_cell_densities()
5,759✔
199
{
200
  for (auto& c : model::cells) {
27,471✔
201
    // Convert to density multipliers.
202
    if (c->xml_set_density_) {
21,712✔
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,759✔
210

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

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

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

227
      // Get temperature(s) of cell (rounding to nearest integer)
228
      vector<double> cell_temps;
18,801✔
229
      if (cell->sqrtkT_.size() == 1) {
18,801✔
230
        double sqrtkT = cell->sqrtkT_[0];
16,977✔
231
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
16,977✔
232
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
1,824✔
233
        double sqrtkT = cell->sqrtkT_[j];
1,808✔
234
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
1,808✔
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]};
18,801✔
241
      for (const auto& i_nuc : mat->nuclide_) {
87,086✔
242
        for (double temperature : cell_temps) {
136,618✔
243
          // Add temperature if it hasn't already been added
244
          if (!contains(nuc_temps[i_nuc], temperature))
68,333✔
245
            nuc_temps[i_nuc].push_back(temperature);
28,023✔
246
        }
247
      }
248

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

253
        for (double temperature : cell_temps) {
6,456✔
254
          // Add temperature if it hasn't already been added
255
          if (!contains(thermal_temps[i_sab], temperature))
3,228✔
256
            thermal_temps[i_sab].push_back(temperature);
1,134✔
257
        }
258
      }
259
    }
18,801✔
260
  }
261
}
7,104✔
262

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

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

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

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

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

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

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

299
  // Figure out which universe is not in the set.  This is the root universe.
300
  bool root_found {false};
7,380✔
301
  int32_t root_univ;
302
  for (int32_t i = 0; i < model::universes.size(); i++) {
26,126✔
303
    auto search = fill_univ_ids.find(model::universes[i]->id_);
18,746✔
304
    if (search == fill_univ_ids.end()) {
18,746✔
305
      if (root_found) {
7,380✔
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,380✔
311
        root_univ = i;
7,380✔
312
      }
313
    }
314
  }
315
  if (!root_found)
7,380✔
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,380✔
320
}
7,380✔
321

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

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

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

330
  // start with any cells manually specified via the C++ API
331
  if (user_distribcells) {
7,376✔
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,315✔
337
    auto* distrib_filt = dynamic_cast<DistribcellFilter*>(filt.get());
7,939✔
338
    auto* cell_inst_filt = dynamic_cast<CellInstanceFilter*>(filt.get());
7,939✔
339
    if (distrib_filt) {
7,939✔
340
      distribcells.insert(distrib_filt->cell());
219✔
341
    }
342
    if (cell_inst_filt) {
7,939✔
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,376✔
350
    for (int64_t i = 0; i < model::cells.size(); ++i) {
40,600✔
351
      if (model::cells[i]->type_ == Fill::MATERIAL)
33,224✔
352
        distribcells.insert(i);
26,257✔
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++) {
40,600✔
359
    Cell& c {*model::cells[i]};
33,224✔
360

361
    if (c.material_.size() > 1) {
33,224✔
362
      if (c.material_.size() != c.n_instances()) {
242✔
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,224✔
372
      if (c.sqrtkT_.size() != c.n_instances()) {
252✔
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,224✔
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,376✔
396
  for (const auto& u : model::universes) {
26,150✔
397
    for (auto idx : u->cells_) {
51,998✔
398
      if (distribcells.find(idx) != distribcells.end()) {
33,224✔
399
        if (!contains(target_univ_ids, u->id_)) {
26,337✔
400
          target_univ_ids.push_back(u->id_);
16,124✔
401
        }
402
        model::cells[idx]->distribcell_index_ =
26,337✔
403
          std::find(target_univ_ids.begin(), target_univ_ids.end(), u->id_) -
26,337✔
404
          target_univ_ids.begin();
52,674✔
405
      }
406
    }
407
  }
408

409
  // Allocate the cell and lattice offset tables.
410
  int n_maps = target_univ_ids.size();
7,376✔
411
  for (auto& c : model::cells) {
40,600✔
412
    if (c->type_ != Fill::MATERIAL) {
33,224✔
413
      c->offset_.resize(n_maps, C_NONE);
6,967✔
414
    }
415
  }
416
  for (auto& lat : model::lattices) {
9,259✔
417
    lat->allocate_offset_table(n_maps);
1,883✔
418
  }
419

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

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

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

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

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

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

459
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
22,084,603✔
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,084,603✔
464
    return 1;
2,510,083✔
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,574,520✔
469
  if (search != univ_count_memo.end()) {
19,574,520✔
470
    return search->second;
7,508,948✔
471
  }
472

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

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

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

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

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

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

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

505
  path << "u" << search_univ.id_ << "->";
2,566,410✔
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,651✔
510
    if ((cell_indx == target_cell) && (offset == target_offset)) {
10,265,706✔
511
      Cell& c = *model::cells[cell_indx];
927,465✔
512
      path << "c" << c.id_;
927,465✔
513
      return path.str();
1,854,930✔
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,945✔
522
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
9,337,845✔
523
    Cell& c = *model::cells[*cell_it];
9,337,845✔
524

525
    // Material cells don't contain other cells so ignore them.
526
    if (c.type_ != Fill::MATERIAL) {
9,337,845✔
527
      int32_t temp_offset = offset + c.offset_[map];
2,339,205✔
528
      if (c.type_ == Fill::LATTICE) {
2,339,205✔
529
        Lattice& lat = *model::lattices[c.fill_];
2,339,205✔
530
        int32_t indx = lat.universes_.size() * map + lat.begin().indx_;
2,339,205✔
531
        temp_offset += lat.offsets_[indx];
2,339,205✔
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,205✔
537
        break;
1,638,945✔
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,945✔
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,945✔
552
  path << "c" << c.id_ << "->";
1,638,945✔
553

554
  if (c.type_ == Fill::UNIVERSE) {
1,638,945✔
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,945✔
563
    path << "l" << lat.id_;
1,638,945✔
564
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
289,050,246✔
565
      int32_t indx = lat.universes_.size() * map + it.indx_;
289,050,246✔
566
      int32_t temp_offset = offset + lat.offsets_[indx] + c.offset_[map];
289,050,246✔
567
      if (temp_offset <= target_offset) {
289,050,246✔
568
        offset = temp_offset;
1,638,945✔
569
        path << "(" << lat.index_to_string(it.indx_) << ")->";
1,638,945✔
570
        path << distribcell_path_inner(
3,277,890✔
571
          target_cell, map, target_offset, *model::universes[*it], offset);
3,277,890✔
572
        return path.str();
3,277,890✔
573
      }
574
    }
UNCOV
575
    throw std::runtime_error {"Error determining distribcell path."};
×
576
  }
577
}
2,566,410✔
578

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

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

588
int maximum_levels(int32_t univ)
902,587✔
589
{
590

591
  const auto level_count = model::universe_level_counts.find(univ);
902,587✔
592
  if (level_count != model::universe_level_counts.end()) {
902,587✔
593
    return level_count->second;
884,009✔
594
  }
595

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

598
  for (int32_t cell_indx : model::universes[univ]->cells_) {
51,574✔
599
    Cell& c = *model::cells[cell_indx];
32,996✔
600
    if (c.type_ == Fill::UNIVERSE) {
32,996✔
601
      int32_t next_univ = c.fill_;
4,993✔
602
      levels_below = std::max(levels_below, maximum_levels(next_univ));
4,993✔
603
    } else if (c.type_ == Fill::LATTICE) {
28,003✔
604
      Lattice& lat = *model::lattices[c.fill_];
1,942✔
605
      for (auto it = lat.begin(); it != lat.end(); ++it) {
892,156✔
606
        int32_t next_univ = *it;
890,214✔
607
        levels_below = std::max(levels_below, maximum_levels(next_univ));
890,214✔
608
      }
609
    }
610
  }
611

612
  ++levels_below;
18,578✔
613
  model::universe_level_counts[univ] = levels_below;
18,578✔
614
  return levels_below;
18,578✔
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,622✔
625
{
626
  model::cells.clear();
7,622✔
627
  model::cell_map.clear();
7,622✔
628

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

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

635
  model::overlap_check_count.clear();
7,622✔
636
}
7,622✔
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