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

openmc-dev / openmc / 21043587909

15 Jan 2026 07:25PM UTC coverage: 81.332% (-0.7%) from 82.044%
21043587909

Pull #3734

github

web-flow
Merge 0c6701672 into 179048b80
Pull Request #3734: Specify temperature from a field (structured mesh only)

16365 of 22657 branches covered (72.23%)

Branch coverage included in aggregate %.

157 of 180 new or added lines in 12 files covered. (87.22%)

681 existing lines in 43 files now uncovered.

54412 of 64365 relevant lines covered (84.54%)

23556062.71 hits per line

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

87.7
/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/simulation.h"
21
#include "openmc/surface.h"
22
#include "openmc/tallies/filter.h"
23
#include "openmc/tallies/filter_cell_instance.h"
24
#include "openmc/tallies/filter_distribcell.h"
25

26
namespace openmc {
27

28
namespace model {
29
std::unordered_map<int32_t, int32_t> universe_level_counts;
30
} // namespace model
31

32
void read_geometry_xml()
500✔
33
{
34
  // Display output message
35
  write_message("Reading geometry XML file...", 5);
500✔
36

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

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

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

53
  read_geometry_xml(root);
500✔
54
}
500✔
55

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

63
  read_surfaces(root, periodic_pairs, albedo_map, periodic_sense_map);
2,910✔
64
  read_cells(root);
2,910✔
65
  prepare_boundary_conditions(periodic_pairs, albedo_map, periodic_sense_map);
2,910✔
66
  read_lattices(root);
2,910✔
67

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

78
  if (settings::run_mode != RunMode::PLOTTING &&
2,910✔
79
      settings::run_mode != RunMode::VOLUME && !boundary_exists) {
2,866!
80
    fatal_error("No boundary conditions were applied to any surfaces!");
×
81
  }
82

83
  // Allocate universes, universe cell arrays, and assign base universe
84
  model::root_universe = find_root_universe();
2,910✔
85

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

90
//==============================================================================
91

92
void adjust_indices()
2,910✔
93
{
94
  // Adjust material/fill idices.
95
  for (auto& c : model::cells) {
13,256✔
96
    if (c->fill_ != C_NONE) {
10,346✔
97
      int32_t id = c->fill_;
2,694✔
98
      auto search_univ = model::universe_map.find(id);
2,694✔
99
      auto search_lat = model::lattice_map.find(id);
2,694✔
100
      if (search_univ != model::universe_map.end()) {
2,694✔
101
        c->type_ = Fill::UNIVERSE;
1,972✔
102
        c->fill_ = search_univ->second;
1,972✔
103
      } else if (search_lat != model::lattice_map.end()) {
722!
104
        c->type_ = Fill::LATTICE;
722✔
105
        c->fill_ = search_lat->second;
722✔
106
      } else {
107
        fatal_error(fmt::format("Specified fill {} on cell {} is neither a "
×
108
                                "universe nor a lattice.",
109
          id, c->id_));
×
110
      }
111
    } else {
112
      c->type_ = Fill::MATERIAL;
7,652✔
113
      for (auto& mat_id : c->material_) {
15,754✔
114
        if (mat_id != MATERIAL_VOID) {
8,102✔
115
          auto search = model::material_map.find(mat_id);
7,122✔
116
          if (search == model::material_map.end()) {
7,122!
117
            fatal_error(
×
118
              fmt::format("Could not find material {} specified on cell {}",
×
119
                mat_id, c->id_));
×
120
          }
121
          // Change from ID to index
122
          mat_id = search->second;
7,122✔
123
        }
124
      }
125
    }
126
  }
127

128
  // Change cell.universe values from IDs to indices.
129
  for (auto& c : model::cells) {
13,256✔
130
    auto search = model::universe_map.find(c->universe_);
10,346✔
131
    if (search != model::universe_map.end()) {
10,346!
132
      c->universe_ = search->second;
10,346✔
133
    } else {
134
      fatal_error(fmt::format("Could not find universe {} specified on cell {}",
×
135
        c->universe_, c->id_));
×
136
    }
137
  }
138

139
  // Change all lattice universe values from IDs to indices.
140
  for (auto& l : model::lattices) {
3,620✔
141
    l->adjust_indices();
710✔
142
  }
143
}
2,910✔
144

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

148
void partition_universes()
2,910✔
149
{
150
  // Iterate over universes with more than 10 cells.  (Fewer than 10 is likely
151
  // not worth partitioning.)
152
  for (const auto& univ : model::universes) {
7,950✔
153
    if (univ->cells_.size() > 10) {
5,040✔
154
      // Collect the set of surfaces in this universe.
155
      std::unordered_set<int32_t> surf_inds;
66✔
156
      for (auto i_cell : univ->cells_) {
1,122✔
157
        for (auto token : model::cells[i_cell]->surfaces()) {
3,996✔
158
          surf_inds.insert(std::abs(token) - 1);
2,940✔
159
        }
1,056✔
160
      }
161

162
      // Partition the universe if there are more than 5 z-planes.  (Fewer than
163
      // 5 is likely not worth it.)
164
      int n_zplanes = 0;
66✔
165
      for (auto i_surf : surf_inds) {
858✔
166
        if (dynamic_cast<const SurfaceZPlane*>(model::surfaces[i_surf].get())) {
828!
167
          ++n_zplanes;
240✔
168
          if (n_zplanes > 5) {
240✔
169
            univ->partitioner_ = make_unique<UniversePartitioner>(*univ);
36✔
170
            break;
36✔
171
          }
172
        }
173
      }
174
    }
66✔
175
  }
176
}
2,910✔
177

178
//==============================================================================
179

180
void assign_temperatures()
2,910✔
181
{
182
  for (auto& c : model::cells) {
13,256✔
183
    // Ignore non-material cells and cells with defined temperature.
184
    if (c->material_.size() == 0)
10,346✔
185
      continue;
2,694✔
186
    if (c->sqrtkT_.size() > 0)
7,652✔
187
      continue;
118✔
188

189
    c->sqrtkT_.reserve(c->material_.size());
7,534✔
190
    for (auto i_mat : c->material_) {
15,518✔
191
      if (i_mat == MATERIAL_VOID) {
7,984✔
192
        // Set void region to 0K.
193
        c->sqrtkT_.push_back(0);
980✔
194
      } else {
195
        const auto& mat {model::materials[i_mat]};
7,004✔
196
        c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature()));
7,004✔
197
      }
198
    }
199
  }
200
}
2,910✔
201

202
//==============================================================================
203

204
void finalize_cell_densities()
2,910✔
205
{
206
  for (auto& c : model::cells) {
13,256✔
207
    // Convert to density multipliers.
208
    if (!c->density_mult_.empty()) {
10,346✔
209
      for (int32_t instance = 0; instance < c->density_mult_.size();
492✔
210
           ++instance) {
211
        c->density_mult_[instance] /=
462✔
212
          model::materials[c->material(instance)]->density_gpcc();
462✔
213
      }
214
    } else {
215
      c->density_mult_ = {1.0};
10,316✔
216
    }
217
  }
218
}
2,910✔
219

220
//==============================================================================
221

222
void get_temperatures(
2,866✔
223
  vector<vector<double>>& nuc_temps, vector<vector<double>>& thermal_temps)
224
{
225
  for (const auto& cell : model::cells) {
13,092✔
226
    // Skip non-material cells.
227
    if (cell->fill_ != C_NONE)
10,226✔
228
      continue;
2,690✔
229

230
    for (int j = 0; j < cell->material_.size(); ++j) {
15,522✔
231
      // Skip void materials
232
      int i_material = cell->material_[j];
7,986✔
233
      if (i_material == MATERIAL_VOID)
7,986✔
234
        continue;
972✔
235

236
      // Get temperature(s) of cell (rounding to nearest integer)
237
      vector<double> cell_temps;
7,014✔
238
      if (cell->sqrtkT_.size() == 1) {
7,014✔
239
        double sqrtkT = cell->sqrtkT_[0];
6,494✔
240
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
6,494✔
241
      } else if (cell->sqrtkT_.size() == cell->material_.size()) {
520✔
242
        double sqrtkT = cell->sqrtkT_[j];
514✔
243
        cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
514✔
244
      } else {
245
        for (double sqrtkT : cell->sqrtkT_)
30✔
246
          cell_temps.push_back(sqrtkT * sqrtkT / K_BOLTZMANN);
24✔
247
      }
248

249
      const auto& mat {model::materials[i_material]};
7,014✔
250
      for (const auto& i_nuc : mat->nuclide_) {
31,648✔
251
        for (double temperature : cell_temps) {
49,286✔
252
          // Add temperature if it hasn't already been added
253
          if (!contains(nuc_temps[i_nuc], temperature))
24,652✔
254
            nuc_temps[i_nuc].push_back(temperature);
10,828✔
255
        }
256
      }
257

258
      for (const auto& table : mat->thermal_tables_) {
8,238✔
259
        // Get index in data::thermal_scatt array
260
        int i_sab = table.index_table;
1,224✔
261

262
        for (double temperature : cell_temps) {
2,448✔
263
          // Add temperature if it hasn't already been added
264
          if (!contains(thermal_temps[i_sab], temperature))
1,224✔
265
            thermal_temps[i_sab].push_back(temperature);
446✔
266
        }
267
      }
268
    }
7,014✔
269
  }
270

271
  // Add temperatures from a temperature field.
272
  // We assume that we do not know how geometric cells are impacted by the
273
  // temperature field in advance. If we had access to this information, we
274
  // could limit the declarations of temperature from the temperature field to
275
  // impacted nuclides only.
276
  if (settings::temperature_field_on) {
2,866✔
277
    for (auto t : simulation::temperature_field.values()) {
54✔
278
      // Nuclide temperatures
279
      for (size_t i = 0; i < nuc_temps.size(); i++) {
336✔
280
        if (!contains(nuc_temps[i], t)) {
288!
281
          nuc_temps[i].push_back(t);
288✔
282
        }
283
      }
284
      // Thermal scattering temperatures
285
      for (size_t i = 0; i < thermal_temps.size(); i++) {
96✔
286
        if (!contains(thermal_temps[i], t)) {
48!
287
          thermal_temps[i].push_back(t);
48✔
288
        }
289
      }
290
    }
291
  }
292
}
2,866✔
293

294
//==============================================================================
295

296
void finalize_geometry()
2,910✔
297
{
298
  // Perform some final operations to set up the geometry
299
  adjust_indices();
2,910✔
300
  count_universe_instances();
2,910✔
301
  partition_universes();
2,910✔
302

303
  // Assign temperatures to cells that don't have temperatures already assigned
304
  assign_temperatures();
2,910✔
305

306
  // Determine number of nested coordinate levels in the geometry
307
  model::n_coord_levels = maximum_levels(model::root_universe);
2,910✔
308
}
2,910✔
309

310
//==============================================================================
311

312
int32_t find_root_universe()
2,910✔
313
{
314
  // Find all the universes listed as a cell fill.
315
  std::unordered_set<int32_t> fill_univ_ids;
2,910✔
316
  for (const auto& c : model::cells) {
13,256✔
317
    fill_univ_ids.insert(c->fill_);
10,346✔
318
  }
319

320
  // Find all the universes contained in a lattice.
321
  for (const auto& lat : model::lattices) {
3,620✔
322
    for (auto it = lat->begin(); it != lat->end(); ++it) {
354,998✔
323
      fill_univ_ids.insert(*it);
354,288✔
324
    }
325
    if (lat->outer_ != NO_OUTER_UNIVERSE) {
710✔
326
      fill_univ_ids.insert(lat->outer_);
150✔
327
    }
328
  }
329

330
  // Figure out which universe is not in the set.  This is the root universe.
331
  bool root_found {false};
2,910✔
332
  int32_t root_univ;
333
  for (int32_t i = 0; i < model::universes.size(); i++) {
7,950✔
334
    auto search = fill_univ_ids.find(model::universes[i]->id_);
5,040✔
335
    if (search == fill_univ_ids.end()) {
5,040✔
336
      if (root_found) {
2,910!
337
        fatal_error("Two or more universes are not used as fill universes, so "
×
338
                    "it is not possible to distinguish which one is the root "
339
                    "universe.");
340
      } else {
341
        root_found = true;
2,910✔
342
        root_univ = i;
2,910✔
343
      }
344
    }
345
  }
346
  if (!root_found)
2,910!
347
    fatal_error("Could not find a root universe.  Make sure "
×
348
                "there are no circular dependencies in the geometry.");
349

350
  return root_univ;
2,910✔
351
}
2,910✔
352

353
//==============================================================================
354

355
void prepare_distribcell(const std::vector<int32_t>* user_distribcells)
2,908✔
356
{
357
  write_message("Preparing distributed cell instances...", 5);
2,908✔
358

359
  std::unordered_set<int32_t> distribcells;
2,908✔
360

361
  // start with any cells manually specified via the C++ API
362
  if (user_distribcells) {
2,908✔
363
    distribcells.insert(user_distribcells->begin(), user_distribcells->end());
6✔
364
  }
365

366
  // Find all cells listed in a DistribcellFilter or CellInstanceFilter
367
  for (auto& filt : model::tally_filters) {
6,074✔
368
    auto* distrib_filt = dynamic_cast<DistribcellFilter*>(filt.get());
3,166!
369
    auto* cell_inst_filt = dynamic_cast<CellInstanceFilter*>(filt.get());
3,166!
370
    if (distrib_filt) {
3,166✔
371
      distribcells.insert(distrib_filt->cell());
70✔
372
    }
373
    if (cell_inst_filt) {
3,166✔
374
      const auto& filter_cells = cell_inst_filt->cells();
12✔
375
      distribcells.insert(filter_cells.begin(), filter_cells.end());
12✔
376
    }
377
  }
378

379
  // By default, add material cells to the list of distributed cells
380
  if (settings::material_cell_offsets) {
2,908!
381
    for (int64_t i = 0; i < model::cells.size(); ++i) {
13,276✔
382
      if (model::cells[i]->type_ == Fill::MATERIAL)
10,368✔
383
        distribcells.insert(i);
7,662✔
384
    }
385
  }
386

387
  // Make sure that the number of materials/temperatures matches the number of
388
  // cell instances.
389
  for (int i = 0; i < model::cells.size(); i++) {
13,276✔
390
    Cell& c {*model::cells[i]};
10,368✔
391

392
    if (c.material_.size() > 1) {
10,368✔
393
      if (c.material_.size() != c.n_instances()) {
70!
394
        fatal_error(fmt::format(
×
395
          "Cell {} was specified with {} materials but has {} distributed "
396
          "instances. The number of materials must equal one or the number "
397
          "of instances.",
398
          c.id_, c.material_.size(), c.n_instances()));
×
399
      }
400
    }
401

402
    if (c.sqrtkT_.size() > 1) {
10,368✔
403
      if (c.sqrtkT_.size() != c.n_instances()) {
76!
404
        fatal_error(fmt::format(
×
405
          "Cell {} was specified with {} temperatures but has {} distributed "
406
          "instances. The number of temperatures must equal one or the number "
407
          "of instances.",
408
          c.id_, c.sqrtkT_.size(), c.n_instances()));
×
409
      }
410
    }
411

412
    if (c.density_mult_.size() > 1) {
10,368✔
413
      if (c.density_mult_.size() != c.n_instances()) {
24!
414
        fatal_error(fmt::format("Cell {} was specified with {} density "
×
415
                                "multipliers but has {} distributed "
416
                                "instances. The number of density multipliers "
417
                                "must equal one or the number "
418
                                "of instances.",
419
          c.id_, c.density_mult_.size(), c.n_instances()));
×
420
      }
421
    }
422
  }
423

424
  // Search through universes for material cells and assign each one a
425
  // distribcell array index according to the containing universe.
426
  vector<int32_t> target_univ_ids;
2,908✔
427
  for (const auto& u : model::universes) {
7,958✔
428
    for (auto idx : u->cells_) {
15,418✔
429
      if (distribcells.find(idx) != distribcells.end()) {
10,368✔
430
        if (!contains(target_univ_ids, u->id_)) {
7,692✔
431
          target_univ_ids.push_back(u->id_);
4,036✔
432
        }
433
        model::cells[idx]->distribcell_index_ =
7,692✔
434
          std::find(target_univ_ids.begin(), target_univ_ids.end(), u->id_) -
7,692✔
435
          target_univ_ids.begin();
15,384✔
436
      }
437
    }
438
  }
439

440
  // Allocate the cell and lattice offset tables.
441
  int n_maps = target_univ_ids.size();
2,908✔
442
  for (auto& c : model::cells) {
13,276✔
443
    if (c->type_ != Fill::MATERIAL) {
10,368✔
444
      c->offset_.resize(n_maps, C_NONE);
2,706✔
445
    }
446
  }
447
  for (auto& lat : model::lattices) {
3,624✔
448
    lat->allocate_offset_table(n_maps);
716✔
449
  }
450

451
// Fill the cell and lattice offset tables.
452
#pragma omp parallel for
453
  for (int map = 0; map < target_univ_ids.size(); map++) {
6,944✔
454
    auto target_univ_id = target_univ_ids[map];
4,036✔
455
    std::unordered_map<int32_t, int32_t> univ_count_memo;
4,036✔
456
    for (const auto& univ : model::universes) {
19,548✔
457
      int32_t offset = 0;
15,512✔
458
      for (int32_t cell_indx : univ->cells_) {
70,486✔
459
        Cell& c = *model::cells[cell_indx];
54,974✔
460

461
        if (c.type_ == Fill::UNIVERSE) {
54,974✔
462
          c.offset_[map] = offset;
30,938✔
463
          int32_t search_univ = c.fill_;
30,938✔
464
          offset += count_universe_instances(
30,938✔
465
            search_univ, target_univ_id, univ_count_memo);
466

467
        } else if (c.type_ == Fill::LATTICE) {
24,036✔
468
          c.offset_[map] = offset;
2,560✔
469
          Lattice& lat = *model::lattices[c.fill_];
2,560✔
470
          offset += lat.fill_offset_table(target_univ_id, map, univ_count_memo);
2,560✔
471
        }
472
      }
473
    }
474
  }
4,036✔
475
}
2,908✔
476

477
//==============================================================================
478

479
void count_universe_instances()
2,910✔
480
{
481
  for (auto& univ : model::universes) {
7,950✔
482
    std::unordered_map<int32_t, int32_t> univ_count_memo;
5,040✔
483
    univ->n_instances_ = count_universe_instances(
5,040✔
484
      model::root_universe, univ->id_, univ_count_memo);
5,040✔
485
  }
5,040✔
486
}
2,910✔
487

488
//==============================================================================
489

490
int count_universe_instances(int32_t search_univ, int32_t target_univ_id,
3,980,002✔
491
  std::unordered_map<int32_t, int32_t>& univ_count_memo)
492
{
493
  // If this is the target, it can't contain itself.
494
  if (model::universes[search_univ]->id_ == target_univ_id) {
3,980,002✔
495
    return 1;
1,003,646✔
496
  }
497

498
  // If we have already counted the number of instances, reuse that value.
499
  auto search = univ_count_memo.find(search_univ);
2,976,356✔
500
  if (search != univ_count_memo.end()) {
2,976,356✔
501
    return search->second;
2,948,930✔
502
  }
503

504
  int count {0};
27,426✔
505
  for (int32_t cell_indx : model::universes[search_univ]->cells_) {
123,554✔
506
    Cell& c = *model::cells[cell_indx];
96,128✔
507

508
    if (c.type_ == Fill::UNIVERSE) {
96,128✔
509
      int32_t next_univ = c.fill_;
63,372✔
510
      count +=
63,372✔
511
        count_universe_instances(next_univ, target_univ_id, univ_count_memo);
63,372✔
512

513
    } else if (c.type_ == Fill::LATTICE) {
32,756✔
514
      Lattice& lat = *model::lattices[c.fill_];
5,878✔
515
      for (auto it = lat.begin(); it != lat.end(); ++it) {
2,628,104✔
516
        int32_t next_univ = *it;
2,622,226✔
517
        count +=
2,622,226✔
518
          count_universe_instances(next_univ, target_univ_id, univ_count_memo);
2,622,226✔
519
      }
520
    }
521
  }
522

523
  // Remember the number of instances in this universe.
524
  univ_count_memo[search_univ] = count;
27,426✔
525

526
  return count;
27,426✔
527
}
528

529
//==============================================================================
530

531
std::string distribcell_path_inner(int32_t target_cell, int32_t map,
932,936✔
532
  int32_t target_offset, const Universe& search_univ, int32_t offset)
533
{
534
  std::stringstream path;
932,936✔
535

536
  path << "u" << search_univ.id_ << "->";
932,936✔
537

538
  // Check to see if this universe directly contains the target cell.  If so,
539
  // write to the path and return.
540
  for (int32_t cell_indx : search_univ.cells_) {
4,328,340✔
541
    if ((cell_indx == target_cell) && (offset == target_offset)) {
3,732,512!
542
      Cell& c = *model::cells[cell_indx];
337,108✔
543
      path << "c" << c.id_;
337,108✔
544
      return path.str();
674,216✔
545
    }
546
  }
547

548
  // The target must be further down the geometry tree and contained in a fill
549
  // cell or lattice cell in this universe.  Find which cell contains the
550
  // target.
551
  vector<std::int32_t>::const_reverse_iterator cell_it {
552
    search_univ.cells_.crbegin()};
595,828✔
553
  for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
3,395,344!
554
    Cell& c = *model::cells[*cell_it];
3,395,344✔
555

556
    // Material cells don't contain other cells so ignore them.
557
    if (c.type_ != Fill::MATERIAL) {
3,395,344✔
558
      int32_t temp_offset = offset + c.offset_[map];
850,384✔
559
      if (c.type_ == Fill::LATTICE) {
850,384!
560
        Lattice& lat = *model::lattices[c.fill_];
850,384✔
561
        int32_t indx = lat.universes_.size() * map + lat.begin().indx_;
850,384✔
562
        temp_offset += lat.offsets_[indx];
850,384✔
563
      }
564

565
      // The desired cell is the first cell that gives an offset smaller or
566
      // equal to the target offset.
567
      if (temp_offset <= target_offset)
850,384✔
568
        break;
595,828✔
569
    }
570
  }
571

572
  // if we get through the loop without finding an appropriate entry, throw
573
  // an error
574
  if (cell_it == search_univ.cells_.crend()) {
595,828!
575
    fatal_error(
×
576
      fmt::format("Failed to generate a text label for distribcell with ID {}."
×
577
                  "The current label is: '{}'",
578
        model::cells[target_cell]->id_, path.str()));
×
579
  }
580

581
  // Add the cell to the path string.
582
  Cell& c = *model::cells[*cell_it];
595,828✔
583
  path << "c" << c.id_ << "->";
595,828✔
584

585
  if (c.type_ == Fill::UNIVERSE) {
595,828!
586
    // Recurse into the fill cell.
587
    offset += c.offset_[map];
×
588
    path << distribcell_path_inner(
×
589
      target_cell, map, target_offset, *model::universes[c.fill_], offset);
×
590
    return path.str();
×
591
  } else {
592
    // Recurse into the lattice cell.
593
    Lattice& lat = *model::lattices[c.fill_];
595,828✔
594
    path << "l" << lat.id_;
595,828✔
595
    for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
105,108,640!
596
      int32_t indx = lat.universes_.size() * map + it.indx_;
105,108,640✔
597
      int32_t temp_offset = offset + lat.offsets_[indx] + c.offset_[map];
105,108,640✔
598
      if (temp_offset <= target_offset) {
105,108,640✔
599
        offset = temp_offset;
595,828✔
600
        path << "(" << lat.index_to_string(it.indx_) << ")->";
595,828✔
601
        path << distribcell_path_inner(
1,191,656✔
602
          target_cell, map, target_offset, *model::universes[*it], offset);
1,191,656✔
603
        return path.str();
1,191,656✔
604
      }
605
    }
606
    throw std::runtime_error {"Error determining distribcell path."};
×
607
  }
608
}
932,936✔
609

610
std::string distribcell_path(
337,108✔
611
  int32_t target_cell, int32_t map, int32_t target_offset)
612
{
613
  auto& root_univ = *model::universes[model::root_universe];
337,108✔
614
  return distribcell_path_inner(target_cell, map, target_offset, root_univ, 0);
337,108✔
615
}
616

617
//==============================================================================
618

619
int maximum_levels(int32_t univ)
359,230✔
620
{
621

622
  const auto level_count = model::universe_level_counts.find(univ);
359,230✔
623
  if (level_count != model::universe_level_counts.end()) {
359,230✔
624
    return level_count->second;
354,250✔
625
  }
626

627
  int levels_below {0};
4,980✔
628

629
  for (int32_t cell_indx : model::universes[univ]->cells_) {
15,266✔
630
    Cell& c = *model::cells[cell_indx];
10,286✔
631
    if (c.type_ == Fill::UNIVERSE) {
10,286✔
632
      int32_t next_univ = c.fill_;
1,972✔
633
      levels_below = std::max(levels_below, maximum_levels(next_univ));
1,972✔
634
    } else if (c.type_ == Fill::LATTICE) {
8,314✔
635
      Lattice& lat = *model::lattices[c.fill_];
722✔
636
      for (auto it = lat.begin(); it != lat.end(); ++it) {
355,070✔
637
        int32_t next_univ = *it;
354,348✔
638
        levels_below = std::max(levels_below, maximum_levels(next_univ));
354,348✔
639
      }
640
    }
641
  }
642

643
  ++levels_below;
4,980✔
644
  model::universe_level_counts[univ] = levels_below;
4,980✔
645
  return levels_below;
4,980✔
646
}
647

UNCOV
648
bool is_root_universe(int32_t univ_id)
×
649
{
UNCOV
650
  return model::universe_map[univ_id] == model::root_universe;
×
651
}
652

653
//==============================================================================
654

655
void free_memory_geometry()
2,944✔
656
{
657
  model::cells.clear();
2,944✔
658
  model::cell_map.clear();
2,944✔
659

660
  model::universes.clear();
2,944✔
661
  model::universe_map.clear();
2,944✔
662

663
  model::lattices.clear();
2,944✔
664
  model::lattice_map.clear();
2,944✔
665

666
  model::overlap_check_count.clear();
2,944✔
667
}
2,944✔
668

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