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

openmc-dev / openmc / 6619919005

23 Oct 2023 10:50PM UTC coverage: 84.501%. Remained the same
6619919005

push

github

web-flow
Skip BC check for volume calculations (#2743)

2 of 2 new or added lines in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

46969 of 55584 relevant lines covered (84.5%)

81787427.24 hits per line

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

92.52
/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, std::unordered_map<int32_t, int32_t>>
29
  universe_cell_counts;
30
std::unordered_map<int32_t, int32_t> universe_level_counts;
31
} // namespace model
32

33
// adds the cell counts of universe b to universe a
34
void update_universe_cell_count(int32_t a, int32_t b)
250,519✔
35
{
36
  auto& universe_a_counts = model::universe_cell_counts[a];
250,519✔
37
  const auto& universe_b_counts = model::universe_cell_counts[b];
250,519✔
38
  for (const auto& it : universe_b_counts) {
1,346,316✔
39
    universe_a_counts[it.first] += it.second;
1,095,797✔
40
  }
41
}
250,519✔
42

43
void read_geometry_xml()
1,967✔
44
{
45
  // Display output message
46
  write_message("Reading geometry XML file...", 5);
1,967✔
47

48
  // Check if geometry.xml exists
49
  std::string filename = settings::path_input + "geometry.xml";
1,967✔
50
  if (!file_exists(filename)) {
1,967✔
51
    fatal_error("Geometry XML file '" + filename + "' does not exist!");
×
52
  }
53

54
  // Parse settings.xml file
55
  pugi::xml_document doc;
1,967✔
56
  auto result = doc.load_file(filename.c_str());
1,967✔
57
  if (!result) {
1,967✔
58
    fatal_error("Error processing geometry.xml file.");
×
59
  }
60

61
  // Get root element
62
  pugi::xml_node root = doc.document_element();
1,967✔
63

64
  read_geometry_xml(root);
1,967✔
65
}
1,967✔
66

67
void read_geometry_xml(pugi::xml_node root)
6,814✔
68
{
69
  // Read surfaces, cells, lattice
70
  read_surfaces(root);
6,814✔
71
  read_cells(root);
6,814✔
72
  read_lattices(root);
6,812✔
73

74
  // Check to make sure a boundary condition was applied to at least one
75
  // surface
76
  bool boundary_exists = false;
6,812✔
77
  for (const auto& surf : model::surfaces) {
14,817✔
78
    if (surf->bc_) {
14,789✔
79
      boundary_exists = true;
6,784✔
80
      break;
6,784✔
81
    }
82
  }
83

84
  if (settings::run_mode != RunMode::PLOTTING &&
6,812✔
85
      settings::run_mode != RunMode::VOLUME && !boundary_exists) {
6,588✔
UNCOV
86
    fatal_error("No boundary conditions were applied to any surfaces!");
×
87
  }
88

89
  // Allocate universes, universe cell arrays, and assign base universe
90
  model::root_universe = find_root_universe();
6,812✔
91

92
  // if the root universe is DAGMC geometry, make sure the model is well-formed
93
  check_dagmc_root_univ();
6,812✔
94
}
6,812✔
95

96
//==============================================================================
97

98
void adjust_indices()
6,814✔
99
{
100
  // Adjust material/fill idices.
101
  for (auto& c : model::cells) {
36,699✔
102
    if (c->fill_ != C_NONE) {
29,885✔
103
      int32_t id = c->fill_;
5,381✔
104
      auto search_univ = model::universe_map.find(id);
5,381✔
105
      auto search_lat = model::lattice_map.find(id);
5,381✔
106
      if (search_univ != model::universe_map.end()) {
5,381✔
107
        c->type_ = Fill::UNIVERSE;
4,145✔
108
        c->fill_ = search_univ->second;
4,145✔
109
      } else if (search_lat != model::lattice_map.end()) {
1,236✔
110
        c->type_ = Fill::LATTICE;
1,236✔
111
        c->fill_ = search_lat->second;
1,236✔
112
      } else {
113
        fatal_error(fmt::format("Specified fill {} on cell {} is neither a "
×
114
                                "universe nor a lattice.",
115
          id, c->id_));
×
116
      }
117
    } else {
118
      c->type_ = Fill::MATERIAL;
24,504✔
119
      for (auto& mat_id : c->material_) {
51,817✔
120
        if (mat_id != MATERIAL_VOID) {
27,313✔
121
          auto search = model::material_map.find(mat_id);
19,245✔
122
          if (search == model::material_map.end()) {
19,245✔
123
            fatal_error(
×
124
              fmt::format("Could not find material {} specified on cell {}",
×
125
                mat_id, c->id_));
×
126
          }
127
          // Change from ID to index
128
          mat_id = search->second;
19,245✔
129
        }
130
      }
131
    }
132
  }
133

134
  // Change cell.universe values from IDs to indices.
135
  for (auto& c : model::cells) {
36,699✔
136
    auto search = model::universe_map.find(c->universe_);
29,885✔
137
    if (search != model::universe_map.end()) {
29,885✔
138
      c->universe_ = search->second;
29,885✔
139
    } else {
140
      fatal_error(fmt::format("Could not find universe {} specified on cell {}",
×
141
        c->universe_, c->id_));
×
142
    }
143
  }
144

145
  // Change all lattice universe values from IDs to indices.
146
  for (auto& l : model::lattices) {
8,036✔
147
    l->adjust_indices();
1,222✔
148
  }
149
}
6,814✔
150

151
//==============================================================================
152
//! Partition some universes with many z-planes for faster find_cell searches.
153

154
void partition_universes()
6,814✔
155
{
156
  // Iterate over universes with more than 10 cells.  (Fewer than 10 is likely
157
  // not worth partitioning.)
158
  for (const auto& univ : model::universes) {
23,284✔
159
    if (univ->cells_.size() > 10) {
16,470✔
160
      // Collect the set of surfaces in this universe.
161
      std::unordered_set<int32_t> surf_inds;
233✔
162
      for (auto i_cell : univ->cells_) {
3,841✔
163
        for (auto token : model::cells[i_cell]->surfaces()) {
13,710✔
164
          surf_inds.insert(std::abs(token) - 1);
10,102✔
165
        }
3,608✔
166
      }
167

168
      // Partition the universe if there are more than 5 z-planes.  (Fewer than
169
      // 5 is likely not worth it.)
170
      int n_zplanes = 0;
233✔
171
      for (auto i_surf : surf_inds) {
2,933✔
172
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
2,814✔
173
          ++n_zplanes;
760✔
174
          if (n_zplanes > 5) {
760✔
175
            univ->partitioner_ = make_unique<UniversePartitioner>(*univ);
114✔
176
            break;
114✔
177
          }
178
        }
179
      }
180
    }
233✔
181
  }
182
}
6,814✔
183

184
//==============================================================================
185

186
void assign_temperatures()
6,814✔
187
{
188
  for (auto& c : model::cells) {
36,699✔
189
    // Ignore non-material cells and cells with defined temperature.
190
    if (c->material_.size() == 0)
29,885✔
191
      continue;
5,381✔
192
    if (c->sqrtkT_.size() > 0)
24,504✔
193
      continue;
416✔
194

195
    c->sqrtkT_.reserve(c->material_.size());
24,088✔
196
    for (auto i_mat : c->material_) {
50,985✔
197
      if (i_mat == MATERIAL_VOID) {
26,897✔
198
        // Set void region to 0K.
199
        c->sqrtkT_.push_back(0);
8,068✔
200
      } else {
201
        const auto& mat {model::materials[i_mat]};
18,829✔
202
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
18,829✔
203
      }
204
    }
205
  }
206
}
6,814✔
207

208
//==============================================================================
209

210
void get_temperatures(
6,590✔
211
  vector<vector<double>>& nuc_temps, vector<vector<double>>& thermal_temps)
212
{
213
  for (const auto& cell : model::cells) {
35,985✔
214
    // Skip non-material cells.
215
    if (cell->fill_ != C_NONE)
29,395✔
216
      continue;
5,367✔
217

218
    for (int j = 0; j < cell->material_.size(); ++j) {
50,865✔
219
      // Skip void materials
220
      int i_material = cell->material_[j];
26,837✔
221
      if (i_material == MATERIAL_VOID)
26,837✔
222
        continue;
8,026✔
223

224
      // Get temperature(s) of cell (rounding to nearest integer)
225
      vector<double> cell_temps;
18,811✔
226
      if (cell->sqrtkT_.size() == 1) {
18,811✔
227
        double sqrtkT = cell->sqrtkT_[0];
15,639✔
228
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
15,639✔
229
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
3,172✔
230
        double sqrtkT = cell->sqrtkT_[j];
3,153✔
231
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
3,153✔
232
      } else {
233
        for (double sqrtkT : cell->sqrtkT_)
95✔
234
          cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
76✔
235
      }
236

237
      const auto& mat {model::materials[i_material]};
18,811✔
238
      for (const auto& i_nuc : mat->nuclide_) {
109,146✔
239
        for (double temperature : cell_temps) {
180,727✔
240
          // Add temperature if it hasn't already been added
241
          if (!contains(nuc_temps[i_nuc], temperature))
90,392✔
242
            nuc_temps[i_nuc].push_back(temperature);
34,376✔
243
        }
244
      }
245

246
      for (const auto& table : mat->thermal_tables_) {
22,543✔
247
        // Get index in data::thermal_scatt array
248
        int i_sab = table.index_table;
3,732✔
249

250
        for (double temperature : cell_temps) {
7,464✔
251
          // Add temperature if it hasn't already been added
252
          if (!contains(thermal_temps[i_sab], temperature))
3,732✔
253
            thermal_temps[i_sab].push_back(temperature);
1,352✔
254
        }
255
      }
256
    }
18,811✔
257
  }
258
}
6,590✔
259

260
//==============================================================================
261

262
void finalize_geometry()
6,814✔
263
{
264
  // Perform some final operations to set up the geometry
265
  adjust_indices();
6,814✔
266
  count_cell_instances(model::root_universe);
6,814✔
267
  partition_universes();
6,814✔
268

269
  // Assign temperatures to cells that don't have temperatures already assigned
270
  assign_temperatures();
6,814✔
271

272
  // Determine number of nested coordinate levels in the geometry
273
  model::n_coord_levels = maximum_levels(model::root_universe);
6,814✔
274
}
6,814✔
275

276
//==============================================================================
277

278
int32_t find_root_universe()
6,814✔
279
{
280
  // Find all the universes listed as a cell fill.
281
  std::unordered_set<int32_t> fill_univ_ids;
6,814✔
282
  for (const auto& c : model::cells) {
36,699✔
283
    fill_univ_ids.insert(c->fill_);
29,885✔
284
  }
285

286
  // Find all the universes contained in a lattice.
287
  for (const auto& lat : model::lattices) {
8,036✔
288
    for (auto it = lat->begin(); it != lat->end(); ++it) {
247,540✔
289
      fill_univ_ids.insert(*it);
246,318✔
290
    }
291
    if (lat->outer_ != NO_OUTER_UNIVERSE) {
1,222✔
292
      fill_univ_ids.insert(lat->outer_);
309✔
293
    }
294
  }
295

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

316
  return root_univ;
6,814✔
317
}
6,814✔
318

319
//==============================================================================
320

321
void prepare_distribcell(const std::vector<int32_t>* user_distribcells)
6,831✔
322
{
323
  write_message("Preparing distributed cell instances...", 5);
6,831✔
324

325
  std::unordered_set<int32_t> distribcells;
6,831✔
326

327
  // start with any cells manually specified via the C++ API
328
  if (user_distribcells) {
6,831✔
329
    distribcells.insert(user_distribcells->begin(), user_distribcells->end());
19✔
330
  }
331

332
  // Find all cells listed in a DistribcellFilter or CellInstanceFilter
333
  for (auto& filt : model::tally_filters) {
14,180✔
334
    auto* distrib_filt = dynamic_cast<DistribcellFilter*>(filt.get());
7,349✔
335
    auto* cell_inst_filt = dynamic_cast<CellInstanceFilter*>(filt.get());
7,349✔
336
    if (distrib_filt) {
7,349✔
337
      distribcells.insert(distrib_filt->cell());
171✔
338
    }
339
    if (cell_inst_filt) {
7,349✔
340
      const auto& filter_cells = cell_inst_filt->cells();
38✔
341
      distribcells.insert(filter_cells.begin(), filter_cells.end());
38✔
342
    }
343
  }
344

345
  // By default, add material cells to the list of distributed cells
346
  if (settings::material_cell_offsets) {
6,831✔
347
    for (gsl::index i = 0; i < model::cells.size(); ++i) {
36,801✔
348
      if (model::cells[i]->type_ == Fill::MATERIAL)
29,970✔
349
        distribcells.insert(i);
24,551✔
350
    }
351
  }
352

353
  // Make sure that the number of materials/temperatures matches the number of
354
  // cell instances.
355
  for (int i = 0; i < model::cells.size(); i++) {
36,801✔
356
    Cell& c {*model::cells[i]};
29,970✔
357

358
    if (c.material_.size() > 1) {
29,970✔
359
      if (c.material_.size() != c.n_instances_) {
363✔
360
        fatal_error(fmt::format(
×
361
          "Cell {} was specified with {} materials but has {} distributed "
362
          "instances. The number of materials must equal one or the number "
363
          "of instances.",
364
          c.id_, c.material_.size(), c.n_instances_));
×
365
      }
366
    }
367

368
    if (c.sqrtkT_.size() > 1) {
29,970✔
369
      if (c.sqrtkT_.size() != c.n_instances_) {
382✔
370
        fatal_error(fmt::format(
×
371
          "Cell {} was specified with {} temperatures but has {} distributed "
372
          "instances. The number of temperatures must equal one or the number "
373
          "of instances.",
374
          c.id_, c.sqrtkT_.size(), c.n_instances_));
×
375
      }
376
    }
377
  }
378

379
  // Search through universes for material cells and assign each one a
380
  // unique distribcell array index.
381
  int distribcell_index = 0;
6,831✔
382
  vector<int32_t> target_univ_ids;
6,831✔
383
  for (const auto& u : model::universes) {
23,356✔
384
    for (auto idx : u->cells_) {
46,495✔
385
      if (distribcells.find(idx) != distribcells.end()) {
29,970✔
386
        model::cells[idx]->distribcell_index_ = distribcell_index++;
24,646✔
387
        target_univ_ids.push_back(u->id_);
24,646✔
388
      }
389
    }
390
  }
391

392
  // Allocate the cell and lattice offset tables.
393
  int n_maps = target_univ_ids.size();
6,831✔
394
  for (auto& c : model::cells) {
36,801✔
395
    if (c->type_ != Fill::MATERIAL) {
29,970✔
396
      c->offset_.resize(n_maps, C_NONE);
5,419✔
397
    }
398
  }
399
  for (auto& lat : model::lattices) {
8,072✔
400
    lat->allocate_offset_table(n_maps);
1,241✔
401
  }
402

403
// Fill the cell and lattice offset tables.
404
#pragma omp parallel for
3,189✔
405
  for (int map = 0; map < target_univ_ids.size(); map++) {
13,554✔
406
    auto target_univ_id = target_univ_ids[map];
9,912✔
407
    std::unordered_map<int32_t, int32_t> univ_count_memo;
9,912✔
408
    for (const auto& univ : model::universes) {
47,283✔
409
      int32_t offset = 0;
37,371✔
410
      for (int32_t cell_indx : univ->cells_) {
208,444✔
411
        Cell& c = *model::cells[cell_indx];
171,073✔
412

413
        if (c.type_ == Fill::UNIVERSE) {
171,073✔
414
          c.offset_[map] = offset;
56,903✔
415
          int32_t search_univ = c.fill_;
56,903✔
416
          offset += count_universe_instances(
56,903✔
417
            search_univ, target_univ_id, univ_count_memo);
418

419
        } else if (c.type_ == Fill::LATTICE) {
114,170✔
420
          c.offset_[map] = offset;
8,128✔
421
          Lattice& lat = *model::lattices[c.fill_];
8,128✔
422
          offset +=
8,128✔
423
            lat.fill_offset_table(offset, target_univ_id, map, univ_count_memo);
8,128✔
424
        }
425
      }
426
    }
427
  }
9,912✔
428
}
6,831✔
429

430
//==============================================================================
431

432
void count_cell_instances(int32_t univ_indx)
257,333✔
433
{
434
  const auto univ_counts = model::universe_cell_counts.find(univ_indx);
257,333✔
435
  if (univ_counts != model::universe_cell_counts.end()) {
257,333✔
436
    for (const auto& it : univ_counts->second) {
1,312,752✔
437
      model::cells[it.first]->n_instances_ += it.second;
1,071,673✔
438
    }
439
  } else {
440
    for (int32_t cell_indx : model::universes[univ_indx]->cells_) {
45,915✔
441
      Cell& c = *model::cells[cell_indx];
29,661✔
442
      ++c.n_instances_;
29,661✔
443
      model::universe_cell_counts[univ_indx][cell_indx] += 1;
29,661✔
444

445
      if (c.type_ == Fill::UNIVERSE) {
29,661✔
446
        // This cell contains another universe.  Recurse into that universe.
447
        count_cell_instances(c.fill_);
4,145✔
448
        update_universe_cell_count(univ_indx, c.fill_);
4,145✔
449
      } else if (c.type_ == Fill::LATTICE) {
25,516✔
450
        // This cell contains a lattice.  Recurse into the lattice universes.
451
        Lattice& lat = *model::lattices[c.fill_];
1,236✔
452
        for (auto it = lat.begin(); it != lat.end(); ++it) {
247,610✔
453
          count_cell_instances(*it);
246,374✔
454
          update_universe_cell_count(univ_indx, *it);
246,374✔
455
        }
456
      }
457
    }
458
  }
459
}
257,333✔
460

461
//==============================================================================
462

463
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
12,673,590✔
464
  std::unordered_map<int32_t, int32_t>& univ_count_memo)
465
{
466
  // If this is the target, it can't contain itself.
467
  if (model::universes[search_univ]->id_ == target_univ_id) {
12,673,590✔
468
    return 1;
1,062,398✔
469
  }
470

471
  // If we have already counted the number of instances, reuse that value.
472
  auto search = univ_count_memo.find(search_univ);
11,611,192✔
473
  if (search != univ_count_memo.end()) {
11,611,192✔
474
    return search->second;
5,573,216✔
475
  }
476

477
  int count {0};
6,037,976✔
478
  for (int32_t cell_indx : model::universes[search_univ]->cells_) {
12,210,835✔
479
    Cell& c = *model::cells[cell_indx];
6,172,859✔
480

481
    if (c.type_ == Fill::UNIVERSE) {
6,172,859✔
482
      int32_t next_univ = c.fill_;
103,696✔
483
      count +=
103,696✔
484
        count_universe_instances(next_univ, target_univ_id, univ_count_memo);
103,696✔
485

486
    } else if (c.type_ == Fill::LATTICE) {
6,069,163✔
487
      Lattice& lat = *model::lattices[c.fill_];
6,270✔
488
      for (auto it = lat.begin(); it != lat.end(); ++it) {
1,687,428✔
489
        int32_t next_univ = *it;
1,681,158✔
490
        count +=
1,681,158✔
491
          count_universe_instances(next_univ, target_univ_id, univ_count_memo);
1,681,158✔
492
      }
493
    }
494
  }
495

496
  // Remember the number of instances in this universe.
497
  univ_count_memo[search_univ] = count;
6,037,976✔
498

499
  return count;
6,037,976✔
500
}
501

502
//==============================================================================
503

504
std::string distribcell_path_inner(int32_t target_cell, int32_t map,
3,264,324✔
505
  int32_t target_offset, const Universe& search_univ, int32_t offset)
506
{
507
  std::stringstream path;
3,264,324✔
508

509
  path << "u" << search_univ.id_ << "->";
3,264,324✔
510

511
  // Check to see if this universe directly contains the target cell.  If so,
512
  // write to the path and return.
513
  for (int32_t cell_indx : search_univ.cells_) {
15,147,342✔
514
    if ((cell_indx == target_cell) && (offset == target_offset)) {
13,062,420✔
515
      Cell& c = *model::cells[cell_indx];
1,179,402✔
516
      path << "c" << c.id_;
1,179,402✔
517
      return path.str();
2,358,804✔
518
    }
519
  }
520

521
  // The target must be further down the geometry tree and contained in a fill
522
  // cell or lattice cell in this universe.  Find which cell contains the
523
  // target.
524
  vector<std::int32_t>::const_reverse_iterator cell_it {
525
    search_univ.cells_.crbegin()};
2,084,922✔
526
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
11,883,018✔
527
    Cell& c = *model::cells[*cell_it];
11,883,018✔
528

529
    // Material cells don't contain other cells so ignore them.
530
    if (c.type_ != Fill::MATERIAL) {
11,883,018✔
531
      int32_t temp_offset;
532
      if (c.type_ == Fill::UNIVERSE) {
2,975,658✔
533
        temp_offset = offset + c.offset_[map];
×
534
      } else {
535
        Lattice& lat = *model::lattices[c.fill_];
2,975,658✔
536
        int32_t indx = lat.universes_.size() * map + lat.begin().indx_;
2,975,658✔
537
        temp_offset = offset + lat.offsets_[indx];
2,975,658✔
538
      }
539

540
      // The desired cell is the first cell that gives an offset smaller or
541
      // equal to the target offset.
542
      if (temp_offset <= target_offset)
2,975,658✔
543
        break;
2,084,922✔
544
    }
545
  }
546

547
  // Add the cell to the path string.
548
  Cell& c = *model::cells[*cell_it];
2,084,922✔
549
  path << "c" << c.id_ << "->";
2,084,922✔
550

551
  if (c.type_ == Fill::UNIVERSE) {
2,084,922✔
552
    // Recurse into the fill cell.
553
    offset += c.offset_[map];
×
554
    path << distribcell_path_inner(
×
555
      target_cell, map, target_offset, *model::universes[c.fill_], offset);
×
556
    return path.str();
×
557
  } else {
558
    // Recurse into the lattice cell.
559
    Lattice& lat = *model::lattices[c.fill_];
2,084,922✔
560
    path << "l" << lat.id_;
2,084,922✔
561
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
367,878,756✔
562
      int32_t indx = lat.universes_.size() * map + it.indx_;
367,878,756✔
563
      int32_t temp_offset = offset + lat.offsets_[indx];
367,878,756✔
564
      if (temp_offset <= target_offset) {
367,878,756✔
565
        offset = temp_offset;
2,084,922✔
566
        path << "(" << lat.index_to_string(it.indx_) << ")->";
2,084,922✔
567
        path << distribcell_path_inner(
4,169,844✔
568
          target_cell, map, target_offset, *model::universes[*it], offset);
4,169,844✔
569
        return path.str();
4,169,844✔
570
      }
571
    }
572
    throw std::runtime_error {"Error determining distribcell path."};
×
573
  }
574
}
3,264,324✔
575

576
std::string distribcell_path(
1,179,402✔
577
  int32_t target_cell, int32_t map, int32_t target_offset)
578
{
579
  auto& root_univ = *model::universes[model::root_universe];
1,179,402✔
580
  return distribcell_path_inner(target_cell, map, target_offset, root_univ, 0);
1,179,402✔
581
}
582

583
//==============================================================================
584

585
int maximum_levels(int32_t univ)
257,333✔
586
{
587

588
  const auto level_count = model::universe_level_counts.find(univ);
257,333✔
589
  if (level_count != model::universe_level_counts.end()) {
257,333✔
590
    return level_count->second;
241,079✔
591
  }
592

593
  int levels_below {0};
16,254✔
594

595
  for (int32_t cell_indx : model::universes[univ]->cells_) {
45,915✔
596
    Cell& c = *model::cells[cell_indx];
29,661✔
597
    if (c.type_ == Fill::UNIVERSE) {
29,661✔
598
      int32_t next_univ = c.fill_;
4,145✔
599
      levels_below = std::max(levels_below, maximum_levels(next_univ));
4,145✔
600
    } else if (c.type_ == Fill::LATTICE) {
25,516✔
601
      Lattice& lat = *model::lattices[c.fill_];
1,236✔
602
      for (auto it = lat.begin(); it != lat.end(); ++it) {
247,610✔
603
        int32_t next_univ = *it;
246,374✔
604
        levels_below = std::max(levels_below, maximum_levels(next_univ));
246,374✔
605
      }
606
    }
607
  }
608

609
  ++levels_below;
16,254✔
610
  model::universe_level_counts[univ] = levels_below;
16,254✔
611
  return levels_below;
16,254✔
612
}
613

614
bool is_root_universe(int32_t univ_id)
×
615
{
616
  return model::universe_map[univ_id] == model::root_universe;
×
617
}
618

619
//==============================================================================
620

621
void free_memory_geometry()
6,935✔
622
{
623
  model::cells.clear();
6,935✔
624
  model::cell_map.clear();
6,935✔
625

626
  model::universes.clear();
6,935✔
627
  model::universe_map.clear();
6,935✔
628

629
  model::lattices.clear();
6,935✔
630
  model::lattice_map.clear();
6,935✔
631

632
  model::overlap_check_count.clear();
6,935✔
633
}
6,935✔
634

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