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

openmc-dev / openmc / 17637711185

11 Sep 2025 07:44AM UTC coverage: 85.193% (-0.02%) from 85.209%
17637711185

Pull #3566

github

web-flow
Merge 03f6b5b26 into ca4295748
Pull Request #3566: Resolve merge conflicts for PR #3516 - Implement Virtual Lattice Method for Efficient Simulation of Dispersed Fuels

268 of 326 new or added lines in 9 files covered. (82.21%)

175 existing lines in 3 files now uncovered.

53205 of 62452 relevant lines covered (85.19%)

37768560.15 hits per line

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

88.85
/src/geometry.cpp
1
#include "openmc/geometry.h"
2

3
#include <fmt/core.h>
4
#include <fmt/ostream.h>
5

6
#include "openmc/array.h"
7
#include "openmc/cell.h"
8
#include "openmc/constants.h"
9
#include "openmc/error.h"
10
#include "openmc/lattice.h"
11
#include "openmc/settings.h"
12
#include "openmc/simulation.h"
13
#include "openmc/string_utils.h"
14
#include "openmc/surface.h"
15

16
namespace openmc {
17

18
//==============================================================================
19
// Global variables
20
//==============================================================================
21

22
namespace model {
23

24
int root_universe {-1};
25
int n_coord_levels;
26

27
vector<int64_t> overlap_check_count;
28

29
} // namespace model
30

31
//==============================================================================
32
// Non-member functions
33
//==============================================================================
34

35
bool check_cell_overlap(GeometryState& p, bool error)
1,320,000✔
36
{
37
  int n_coord = p.n_coord();
1,320,000✔
38

39
  // Loop through each coordinate level
40
  for (int j = 0; j < n_coord; j++) {
2,266,044✔
41
    Universe& univ = *model::universes[p.coord(j).universe()];
1,320,000✔
42

43
    // Loop through each cell on this level
44
    for (auto index_cell : univ.cells_) {
4,466,044✔
45
      Cell& c = *model::cells[index_cell];
3,520,000✔
46
      if (c.contains(p.coord(j).r(), p.coord(j).u(), p.surface())) {
3,520,000✔
47
        if (index_cell != p.coord(j).cell()) {
1,249,622✔
48
          if (error) {
373,956✔
49
            fatal_error(
×
50
              fmt::format("Overlapping cells detected: {}, {} on universe {}",
×
51
                c.id_, model::cells[p.coord(j).cell()]->id_, univ.id_));
×
52
          }
53
          return true;
373,956✔
54
        }
55
#pragma omp atomic
477,636✔
56
        ++model::overlap_check_count[index_cell];
875,666✔
57
      }
58
    }
59
  }
60

61
  return false;
946,044✔
62
}
63

64
//==============================================================================
65

66
int cell_instance_at_level(const GeometryState& p, int level)
2,147,483,647✔
67
{
68
  // throw error if the requested level is too deep for the geometry
69
  if (level > model::n_coord_levels) {
2,147,483,647✔
70
    fatal_error(fmt::format("Cell instance at level {} requested, but only {} "
×
71
                            "levels exist in the geometry.",
72
      level, p.n_coord()));
73
  }
74

75
  // determine the cell instance
76
  Cell& c {*model::cells[p.coord(level).cell()]};
2,147,483,647✔
77

78
  // quick exit if this cell doesn't have distribcell instances
79
  if (c.distribcell_index_ == C_NONE)
2,147,483,647✔
80
    return C_NONE;
×
81

82
  // compute the cell's instance
83
  int instance = 0;
2,147,483,647✔
84
  for (int i = 0; i < level; i++) {
2,147,483,647✔
85
    const auto& c_i {*model::cells[p.coord(i).cell()]};
1,992,575,316✔
86
    if (c_i.type_ == Fill::UNIVERSE) {
1,992,575,316✔
87
      instance += c_i.offset_[c.distribcell_index_];
857,066,310✔
88
    } else if (c_i.type_ == Fill::LATTICE) {
1,135,509,006✔
89
      instance += c_i.offset_[c.distribcell_index_];
1,135,509,006✔
90
      auto& lat {*model::lattices[p.coord(i + 1).lattice()]};
1,135,509,006✔
91
      const auto& i_xyz {p.coord(i + 1).lattice_index()};
1,135,509,006✔
92
      if (lat.are_valid_indices(i_xyz)) {
1,135,509,006✔
93
        instance += lat.offset(c.distribcell_index_, i_xyz);
1,130,623,081✔
94
      }
95
    }
96
  }
97
  return instance;
2,147,483,647✔
98
}
99

100
//==============================================================================
101

102
bool find_cell_inner(
2,147,483,647✔
103
  GeometryState& p, const NeighborList* neighbor_list, bool verbose)
104
{
105
  // Find which cell of this universe the particle is in.  Use the neighbor list
106
  // to shorten the search if one was provided.
107
  bool found = false;
2,147,483,647✔
108
  int32_t i_cell = C_NONE;
2,147,483,647✔
109
  if (neighbor_list) {
2,147,483,647✔
110
    for (auto it = neighbor_list->cbegin(); it != neighbor_list->cend(); ++it) {
1,642,692,452✔
111
      i_cell = *it;
1,641,095,602✔
112

113
      // Make sure the search cell is in the same universe.
114
      int i_universe = p.lowest_coord().universe();
1,641,095,602✔
115
      if (model::cells[i_cell]->universe_ != i_universe)
1,641,095,602✔
116
        continue;
×
117

118
      // Check if this cell contains the particle.
119
      Position r {p.r_local()};
1,641,095,602✔
120
      Direction u {p.u_local()};
1,641,095,602✔
121
      auto surf = p.surface();
1,641,095,602✔
122
      if (model::cells[i_cell]->contains(r, u, surf)) {
1,641,095,602✔
123
        p.lowest_coord().cell() = i_cell;
1,328,286,086✔
124
        found = true;
1,328,286,086✔
125
        break;
1,328,286,086✔
126
      }
127
    }
128

129
    // If we're attempting a neighbor list search and fail, we
130
    // now know we should return false. This will trigger an
131
    // exhaustive search from neighbor_list_find_cell and make
132
    // the result from that be appended to the neighbor list.
133
    if (!found) {
1,329,882,936✔
134
      return found;
1,596,850✔
135
    }
136
  }
137

138
  // Check successively lower coordinate levels until finding material fill
139
  for (;; ++p.n_coord()) {
692,379,430✔
140
    // If we did not attempt to use neighbor lists, i_cell is still C_NONE.  In
141
    // that case, we should now do an exhaustive search to find the right value
142
    // of i_cell.
143
    //
144
    // Alternatively, neighbor list searches could have succeeded, but we found
145
    // that the fill of the neighbor cell was another universe. As such, in the
146
    // code below this conditional, we set i_cell back to C_NONE to indicate
147
    // that.
148
    if (i_cell == C_NONE) {
2,147,483,647✔
149
      int i_universe = p.lowest_coord().universe();
1,531,553,026✔
150
      const auto& univ {model::universes[i_universe]};
1,531,553,026✔
151
      found = univ->find_cell(p);
1,531,553,026✔
152
    }
153

154
    if (!found) {
2,147,483,647✔
155
      return found;
173,081,851✔
156
    }
157
    i_cell = p.lowest_coord().cell();
2,147,483,647✔
158

159
    // Announce the cell that the particle is entering.
160
    if (found && verbose) {
2,147,483,647✔
161
      auto msg = fmt::format("    Entering cell {}", model::cells[i_cell]->id_);
×
162
      write_message(msg, 1);
×
163
    }
164

165
    Cell& c {*model::cells[i_cell]};
2,147,483,647✔
166
    if (c.type_ == Fill::MATERIAL) {
2,147,483,647✔
167
      // Found a material cell which means this is the lowest coord level.
168

169
      p.cell_instance() = 0;
2,147,483,647✔
170
      // Find the distribcell instance number.
171
      if (c.distribcell_index_ >= 0) {
2,147,483,647✔
172
        p.cell_instance() = cell_instance_at_level(p, p.n_coord() - 1);
2,147,483,647✔
173
      }
174

175
      // Set the material and temperature.
176
      p.material_last() = p.material();
2,147,483,647✔
177
      p.material() = c.material(p.cell_instance());
2,147,483,647✔
178
      p.sqrtkT_last() = p.sqrtkT();
2,147,483,647✔
179
      p.sqrtkT() = c.sqrtkT(p.cell_instance());
2,147,483,647✔
180

181
      return true;
2,147,483,647✔
182

183
    } else if (c.type_ == Fill::UNIVERSE) {
346,189,715✔
184
      //========================================================================
185
      //! Found a lower universe, update this coord level then search the next.
186

187
      // Set the lower coordinate level universe.
188
      auto& coord {p.coord(p.n_coord())};
196,970,383✔
189
      coord.universe() = c.fill_;
196,970,383✔
190

191
      // Set the position and direction.
192
      coord.r() = p.r_local();
196,970,383✔
193
      coord.u() = p.u_local();
196,970,383✔
194

195
      // Apply translation.
196
      coord.r() -= c.translation_;
196,970,383✔
197

198
      // Apply rotation.
199
      if (!c.rotation_.empty()) {
196,970,383✔
200
        coord.rotate(c.rotation_);
2,189,110✔
201
      }
202

203
    } else if (c.type_ == Fill::LATTICE) {
149,219,332✔
204
      //========================================================================
205
      //! Found a lower lattice, update this coord level then search the next.
206

207
      Lattice& lat {*model::lattices[c.fill_]};
149,219,332✔
208

209
      // Set the position and direction.
210
      auto& coord {p.coord(p.n_coord())};
149,219,332✔
211
      coord.r() = p.r_local();
149,219,332✔
212
      coord.u() = p.u_local();
149,219,332✔
213

214
      // Apply translation.
215
      coord.r() -= c.translation_;
149,219,332✔
216

217
      // Apply rotation.
218
      if (!c.rotation_.empty()) {
149,219,332✔
219
        coord.rotate(c.rotation_);
354,519✔
220
      }
221

222
      // Determine lattice indices.
223
      auto& i_xyz {coord.lattice_index()};
149,219,332✔
224
      lat.get_indices(coord.r(), coord.u(), i_xyz);
149,219,332✔
225

226
      // Get local position in appropriate lattice cell
227
      coord.r() = lat.get_local_position(coord.r(), i_xyz);
149,219,332✔
228

229
      // Set lattice indices.
230
      coord.lattice() = c.fill_;
149,219,332✔
231

232
      // Set the lower coordinate level universe.
233
      if (lat.are_valid_indices(i_xyz)) {
149,219,332✔
234
        coord.universe() = lat[i_xyz];
144,333,407✔
235
      } else {
236
        if (lat.outer_ != NO_OUTER_UNIVERSE) {
4,885,925✔
237
          coord.universe() = lat.outer_;
4,885,925✔
238
        } else {
239
          p.mark_as_lost(fmt::format(
×
240
            "Particle {} left lattice {}, but it has no outer definition.",
241
            p.id(), lat.id_));
×
242
        }
243
      }
244
    }
245
    i_cell = C_NONE; // trip non-neighbor cell search at next iteration
346,189,715✔
246
    found = false;
346,189,715✔
247
  }
346,189,715✔
248

249
  return found;
250
}
251

252
//==============================================================================
253

254
bool neighbor_list_find_cell(GeometryState& p, bool verbose)
1,329,882,936✔
255
{
256

257
  // Reset all the deeper coordinate levels.
258
  for (int i = p.n_coord(); i < model::n_coord_levels; i++) {
2,021,072,110✔
259
    p.coord(i).reset();
691,189,174✔
260
  }
261

262
  // Get the cell this particle was in previously.
263
  auto coord_lvl = p.n_coord() - 1;
1,329,882,936✔
264
  auto i_cell = p.coord(coord_lvl).cell();
1,329,882,936✔
265
  Cell& c {*model::cells[i_cell]};
1,329,882,936✔
266

267
  // Search for the particle in that cell's neighbor list.  Return if we
268
  // found the particle.
269
  bool found = find_cell_inner(p, &c.neighbors_, verbose);
1,329,882,936✔
270
  if (found)
1,329,882,936✔
271
    return found;
1,328,286,086✔
272

273
  // The particle could not be found in the neighbor list.  Try searching all
274
  // cells in this universe, and update the neighbor list if we find a new
275
  // neighboring cell.
276
  found = find_cell_inner(p, nullptr, verbose);
1,596,850✔
277
  if (found)
1,596,850✔
278
    c.neighbors_.push_back(p.coord(coord_lvl).cell());
27,819✔
279
  return found;
1,596,850✔
280
}
281

282
bool exhaustive_find_cell(GeometryState& p, bool verbose)
1,183,766,461✔
283
{
284
  int i_universe = p.lowest_coord().universe();
1,183,766,461✔
285
  if (i_universe == C_NONE) {
1,183,766,461✔
286
    p.coord(0).universe() = model::root_universe;
265,710,420✔
287
    p.n_coord() = 1;
265,710,420✔
288
    i_universe = model::root_universe;
265,710,420✔
289
  }
290
  // Reset all the deeper coordinate levels.
291
  for (int i = p.n_coord(); i < model::n_coord_levels; i++) {
1,276,772,978✔
292
    p.coord(i).reset();
93,006,517✔
293
  }
294
  return find_cell_inner(p, nullptr, verbose);
1,183,766,461✔
295
}
296

297
bool find_cell_in_virtual_lattice(GeometryState& p, bool verbose)
2,375,824✔
298
{
299
  int i_surface = std::abs(p.surface());
2,375,824✔
300
  if (p.surface() > 0) {
2,375,824✔
301
    for (int i = p.n_coord(); i < model::n_coord_levels; i++) {
2,374,768✔
302
      p.coord(i).reset();
1,187,384✔
303
    }
304
    p.coord(p.n_coord() - 1).cell() =
1,187,384✔
305
      model::cell_map[model::surfaces[i_surface - 1]->triso_base_index_];
1,187,384✔
306
  } else if (p.surface() < 0) {
1,188,440✔
307
    for (int i = p.n_coord(); i < model::n_coord_levels; i++) {
2,376,880✔
308
      p.coord(i).reset();
1,188,440✔
309
    }
310
    if (model::surfaces[i_surface - 1]->triso_particle_index_ == -1) {
1,188,440✔
NEW
311
      fatal_error(fmt::format("Particle cell of surface {} is not defined",
×
NEW
312
        model::surfaces[i_surface - 1]->id_));
×
313
    }
314
    p.lowest_coord().cell() =
1,188,440✔
315
      model::cell_map[model::surfaces[i_surface - 1]->triso_particle_index_];
1,188,440✔
316
  }
317

318
  // find material
319
  bool found = true;
2,375,824✔
320
  int i_cell = p.lowest_coord().cell();
2,375,824✔
321
  for (;; ++p.n_coord()) {
1,188,440✔
322
    if (i_cell == C_NONE) {
3,564,264✔
323
      int i_universe = p.lowest_coord().universe();
1,188,440✔
324
      const auto& univ {model::universes[i_universe]};
1,188,440✔
325

326
      if (univ->filled_with_triso_base_ != -1) {
1,188,440✔
NEW
327
        p.lowest_coord().cell() =
×
NEW
328
          model::cell_map[univ->filled_with_triso_base_];
×
NEW
329
        found = true;
×
330
      } else {
331
        found = univ->find_cell(p);
1,188,440✔
332
      }
333
      if (!found) {
1,188,440✔
NEW
334
        return found;
×
335
      }
336
    }
337

338
    i_cell = p.lowest_coord().cell();
3,564,264✔
339

340
    Cell& c {*model::cells[i_cell]};
3,564,264✔
341
    if (c.type_ == Fill::MATERIAL) {
3,564,264✔
342
      // Found a material cell which means this is the lowest coord level.
343

344
      p.cell_instance() = 0;
2,375,824✔
345
      // Find the distribcell instance number.
346
      if (c.distribcell_index_ >= 0) {
2,375,824✔
347
        p.cell_instance() = cell_instance_at_level(p, p.n_coord() - 1);
2,375,824✔
348
      }
349

350
      // Set the material and temperature.
351
      p.material_last() = p.material();
2,375,824✔
352
      if (c.material_.size() > 1) {
2,375,824✔
NEW
353
        p.material() = c.material_[p.cell_instance()];
×
354
      } else {
355
        p.material() = c.material_[0];
2,375,824✔
356
      }
357
      p.sqrtkT_last() = p.sqrtkT();
2,375,824✔
358
      if (c.sqrtkT_.size() > 1) {
2,375,824✔
NEW
359
        p.sqrtkT() = c.sqrtkT_[p.cell_instance()];
×
360
      } else {
361
        p.sqrtkT() = c.sqrtkT_[0];
2,375,824✔
362
      }
363
      return found;
2,375,824✔
364

365
    } else if (c.type_ == Fill::UNIVERSE) {
1,188,440✔
366
      //========================================================================
367
      //! Found a lower universe, update this coord level then search the
368
      //! next.
369

370
      // Set the lower coordinate level universe.
371
      auto& coor {p.coord(p.n_coord())};
1,188,440✔
372
      coor.universe() = c.fill_;
1,188,440✔
373

374
      // Set the position and direction.
375
      coor.r() = p.r_local();
1,188,440✔
376
      coor.u() = p.u_local();
1,188,440✔
377

378
      // Apply translation.
379
      coor.r() -= c.translation_;
1,188,440✔
380

381
      // Apply rotation.
382
      if (!c.rotation_.empty()) {
1,188,440✔
NEW
383
        coor.rotate(c.rotation_);
×
384
      }
385
      i_cell = C_NONE;
1,188,440✔
386
    }
387
  }
1,188,440✔
388
}
389
//==============================================================================
390

391
void cross_lattice(GeometryState& p, const BoundaryInfo& boundary, bool verbose)
679,289,366✔
392
{
393
  auto& coord {p.lowest_coord()};
679,289,366✔
394
  auto& lat {*model::lattices[coord.lattice()]};
679,289,366✔
395

396
  if (verbose) {
679,289,366✔
397
    write_message(
×
398
      fmt::format("    Crossing lattice {}. Current position ({},{},{}). r={}",
×
399
        lat.id_, coord.lattice_index()[0], coord.lattice_index()[1],
×
400
        coord.lattice_index()[2], p.r()),
×
401
      1);
402
  }
403

404
  // Set the lattice indices.
405
  coord.lattice_index()[0] += boundary.lattice_translation()[0];
679,289,366✔
406
  coord.lattice_index()[1] += boundary.lattice_translation()[1];
679,289,366✔
407
  coord.lattice_index()[2] += boundary.lattice_translation()[2];
679,289,366✔
408

409
  // Set the new coordinate position.
410
  const auto& upper_coord {p.coord(p.n_coord() - 2)};
679,289,366✔
411
  const auto& cell {model::cells[upper_coord.cell()]};
679,289,366✔
412
  Position r = upper_coord.r();
679,289,366✔
413
  r -= cell->translation_;
679,289,366✔
414
  if (!cell->rotation_.empty()) {
679,289,366✔
415
    r = r.rotate(cell->rotation_);
470,965✔
416
  }
417
  p.r_local() = lat.get_local_position(r, coord.lattice_index());
679,289,366✔
418

419
  if (!lat.are_valid_indices(coord.lattice_index())) {
679,289,366✔
420
    // The particle is outside the lattice.  Search for it from the base coords.
421
    p.n_coord() = 1;
3,726,107✔
422
    bool found = exhaustive_find_cell(p);
3,726,107✔
423

424
    if (!found) {
3,726,107✔
425
      p.mark_as_lost(fmt::format("Particle {} could not be located after "
×
426
                                 "crossing a boundary of lattice {}",
427
        p.id(), lat.id_));
×
428
    }
429

430
  } else {
431
    // Find cell in next lattice element.
432
    p.lowest_coord().universe() = lat[coord.lattice_index()];
675,563,259✔
433
    bool found = exhaustive_find_cell(p);
675,563,259✔
434

435
    if (!found) {
675,563,259✔
436
      // A particle crossing the corner of a lattice tile may not be found.  In
437
      // this case, search for it from the base coords.
438
      p.n_coord() = 1;
×
439
      bool found = exhaustive_find_cell(p);
×
440
      if (!found) {
×
441
        p.mark_as_lost(fmt::format("Particle {} could not be located after "
×
442
                                   "crossing a boundary of lattice {}",
443
          p.id(), lat.id_));
×
444
      }
445
    }
446
  }
447
}
679,289,366✔
448

449
//==============================================================================
450

451
BoundaryInfo distance_to_boundary(GeometryState& p)
2,147,483,647✔
452
{
453
  BoundaryInfo info;
2,147,483,647✔
454
  double d_lat = INFINITY;
2,147,483,647✔
455
  double d_surf = INFINITY;
2,147,483,647✔
456
  int32_t level_surf_cross;
457
  array<int, 3> level_lat_trans {};
2,147,483,647✔
458

459
  // Loop over each coordinate level.
460
  for (int i = 0; i < p.n_coord(); i++) {
2,147,483,647✔
461
    const auto& coord {p.coord(i)};
2,147,483,647✔
462
    const Position& r {coord.r()};
2,147,483,647✔
463
    const Direction& u {coord.u()};
2,147,483,647✔
464
    Cell& c {*model::cells[coord.cell()]};
2,147,483,647✔
465

466
    // Find the oncoming surface in this cell and the distance to it.
467
    auto surface_distance = c.distance(r, u, p.surface(), &p);
2,147,483,647✔
468
    d_surf = surface_distance.first;
2,147,483,647✔
469
    level_surf_cross = surface_distance.second;
2,147,483,647✔
470

471
    // Find the distance to the next lattice tile crossing.
472
    if (coord.lattice() != C_NONE) {
2,147,483,647✔
473
      auto& lat {*model::lattices[coord.lattice()]};
1,151,872,868✔
474
      // TODO: refactor so both lattice use the same position argument (which
475
      // also means the lat.type attribute can be removed)
476
      std::pair<double, array<int, 3>> lattice_distance;
1,151,872,868✔
477
      switch (lat.type_) {
1,151,872,868✔
478
      case LatticeType::rect:
1,064,842,598✔
479
        lattice_distance = lat.distance(r, u, coord.lattice_index());
1,064,842,598✔
480
        break;
1,064,842,598✔
481
      case LatticeType::hex:
87,030,270✔
482
        auto& cell_above {model::cells[p.coord(i - 1).cell()]};
87,030,270✔
483
        Position r_hex {p.coord(i - 1).r()};
87,030,270✔
484
        r_hex -= cell_above->translation_;
87,030,270✔
485
        if (coord.rotated()) {
87,030,270✔
486
          r_hex = r_hex.rotate(cell_above->rotation_);
681,417✔
487
        }
488
        r_hex.z = coord.r().z;
87,030,270✔
489
        lattice_distance = lat.distance(r_hex, u, coord.lattice_index());
87,030,270✔
490
        break;
87,030,270✔
491
      }
492
      d_lat = lattice_distance.first;
1,151,872,868✔
493
      level_lat_trans = lattice_distance.second;
1,151,872,868✔
494

495
      if (d_lat < 0) {
1,151,872,868✔
496
        p.mark_as_lost(fmt::format("Particle {} had a negative distance "
×
497
                                   "to a lattice boundary.",
498
          p.id()));
×
499
      }
500
    }
501

502
    // If the boundary on this coordinate level is coincident with a boundary on
503
    // a higher level then we need to make sure that the higher level boundary
504
    // is selected.  This logic must consider floating point precision.
505
    double& d = info.distance();
2,147,483,647✔
506
    if (d_surf < d_lat - FP_COINCIDENT) {
2,147,483,647✔
507
      if (d == INFINITY || (d - d_surf) / d >= FP_REL_PRECISION) {
2,147,483,647✔
508
        // Update closest distance
509
        d = d_surf;
2,147,483,647✔
510

511
        // If the cell is not simple, it is possible that both the negative and
512
        // positive half-space were given in the region specification. Thus, we
513
        // have to explicitly check which half-space the particle would be
514
        // traveling into if the surface is crossed
515
        if (c.is_simple() || d == INFTY) {
2,147,483,647✔
516
          info.surface() = level_surf_cross;
2,147,483,647✔
517
        } else {
518
          Position r_hit = r + d_surf * u;
12,758,199✔
519
          Surface& surf {*model::surfaces[std::abs(level_surf_cross) - 1]};
12,758,199✔
520
          Direction norm = surf.normal(r_hit);
12,758,199✔
521
          if (u.dot(norm) > 0) {
12,758,199✔
522
            info.surface() = std::abs(level_surf_cross);
6,324,629✔
523
          } else {
524
            info.surface() = -std::abs(level_surf_cross);
6,433,570✔
525
          }
526
        }
527

528
        info.lattice_translation()[0] = 0;
2,147,483,647✔
529
        info.lattice_translation()[1] = 0;
2,147,483,647✔
530
        info.lattice_translation()[2] = 0;
2,147,483,647✔
531
        info.coord_level() = i + 1;
2,147,483,647✔
532
      }
533
    } else {
534
      if (d == INFINITY || (d - d_lat) / d >= FP_REL_PRECISION) {
948,133,794✔
535
        d = d_lat;
764,487,456✔
536
        info.surface() = SURFACE_NONE;
764,487,456✔
537
        info.lattice_translation() = level_lat_trans;
764,487,456✔
538
        info.coord_level() = i + 1;
764,487,456✔
539
      }
540
    }
541
  }
542
  return info;
2,147,483,647✔
543
}
544

545
//==============================================================================
546
// C API
547
//==============================================================================
548

549
extern "C" int openmc_find_cell(
600,753✔
550
  const double* xyz, int32_t* index, int32_t* instance)
551
{
552
  GeometryState geom_state;
600,753✔
553

554
  geom_state.r() = Position {xyz};
600,753✔
555
  geom_state.u() = {0.0, 0.0, 1.0};
600,753✔
556

557
  if (!exhaustive_find_cell(geom_state)) {
600,753✔
558
    set_errmsg(
12✔
559
      fmt::format("Could not find cell at position {}.", geom_state.r()));
34✔
560
    return OPENMC_E_GEOMETRY;
12✔
561
  }
562

563
  *index = geom_state.lowest_coord().cell();
600,741✔
564
  *instance = geom_state.cell_instance();
600,741✔
565
  return 0;
600,741✔
566
}
600,753✔
567

568
extern "C" int openmc_global_bounding_box(double* llc, double* urc)
12✔
569
{
570
  auto bbox = model::universes.at(model::root_universe)->bounding_box();
12✔
571

572
  // set lower left corner values
573
  llc[0] = bbox.xmin;
12✔
574
  llc[1] = bbox.ymin;
12✔
575
  llc[2] = bbox.zmin;
12✔
576

577
  // set upper right corner values
578
  urc[0] = bbox.xmax;
12✔
579
  urc[1] = bbox.ymax;
12✔
580
  urc[2] = bbox.zmax;
12✔
581

582
  return 0;
12✔
583
}
584

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