Skip to content

Commit d1ee645

Browse files
author
skywalker_cn
committed
Refactor cell and particle data classes to adapt the virtual lattice function
1 parent 309841e commit d1ee645

8 files changed

Lines changed: 215 additions & 90 deletions

File tree

include/openmc/cell.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ class Region {
9999
//! Get Boolean of if the cell is simple or not
100100
bool is_simple() const { return simple_; }
101101

102+
//! Get a vector of the region expression in postfix notation
103+
vector<int32_t> generate_postfix(int32_t cell_id) const;
104+
102105
private:
103106
//----------------------------------------------------------------------------
104107
// Private Methods
105108

106-
//! Get a vector of the region expression in postfix notation
107-
vector<int32_t> generate_postfix(int32_t cell_id) const;
108-
109109
//! Determine if a particle is inside the cell for a simple cell (only
110110
//! intersection operators)
111111
bool contains_simple(Position r, Direction u, int32_t on_surface) const;
@@ -314,15 +314,14 @@ class Cell {
314314
//----------------------------------------------------------------------------
315315
// Data members
316316

317-
int32_t id_; //!< Unique ID
318-
std::string name_; //!< User-defined name
319-
Fill type_; //!< Material, universe, or lattice
320-
int32_t universe_; //!< Universe # this cell is in
321-
int32_t fill_; //!< Universe # filling this cell
322-
bool virtual_lattice_; //!< If the cell is the base of a virtual triso lattice
317+
int32_t id_; //!< Unique ID
318+
std::string name_; //!< User-defined name
319+
Fill type_; //!< Material, universe, or lattice
320+
int32_t universe_; //!< Universe # this cell is in
321+
int32_t fill_; //!< Universe # filling this cell
322+
bool virtual_lattice_; //!< If the cell is the base of a virtual triso lattice
323323
bool triso_particle_;
324324

325-
326325
//! \brief Specification of the virtual lattice
327326
vector<double> vl_lower_left_;
328327
vector<double> vl_pitch_;
@@ -380,10 +379,7 @@ class CSGCell : public Cell {
380379
vector<int32_t> surfaces() const override { return region_.surfaces(); }
381380

382381
std::pair<double, int32_t> distance(Position r, Direction u,
383-
int32_t on_surface, GeometryState* p) const override
384-
{
385-
return region_.distance(r, u, on_surface);
386-
}
382+
int32_t on_surface, GeometryState* p) const override;
387383

388384
bool contains(Position r, Direction u, int32_t on_surface) const override
389385
{

include/openmc/particle_data.h

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,52 @@ class GeometryState {
372372
// Boundary information
373373
BoundaryInfo& boundary() { return boundary_; }
374374

375+
// Distance to the next collision
376+
double& collision_distance() { return collision_distance_; }
377+
375378
#ifdef OPENMC_DAGMC_ENABLED
376379
// DagMC state variables
377-
moab::DagMC::RayHistory& history() { return history_; }
378-
Direction& last_dir() { return last_dir_; }
380+
moab::DagMC::RayHistory& history()
381+
{
382+
return history_;
383+
}
384+
Direction& last_dir()
385+
{
386+
return last_dir_;
387+
}
379388
#endif
380389

381390
// material of current and last cell
382-
int& material() { return material_; }
383-
const int& material() const { return material_; }
384-
int& material_last() { return material_last_; }
385-
const int& material_last() const { return material_last_; }
391+
int& material()
392+
{
393+
return material_;
394+
}
395+
const int& material() const
396+
{
397+
return material_;
398+
}
399+
int& material_last()
400+
{
401+
return material_last_;
402+
}
403+
const int& material_last() const
404+
{
405+
return material_last_;
406+
}
386407

387408
// temperature of current and last cell
388-
double& sqrtkT() { return sqrtkT_; }
389-
const double& sqrtkT() const { return sqrtkT_; }
390-
double& sqrtkT_last() { return sqrtkT_last_; }
409+
double& sqrtkT()
410+
{
411+
return sqrtkT_;
412+
}
413+
const double& sqrtkT() const
414+
{
415+
return sqrtkT_;
416+
}
417+
double& sqrtkT_last()
418+
{
419+
return sqrtkT_last_;
420+
}
391421

392422
private:
393423
int64_t id_ {-1}; //!< Unique ID
@@ -417,6 +447,8 @@ class GeometryState {
417447
double sqrtkT_ {-1.0}; //!< sqrt(k_Boltzmann * temperature) in eV
418448
double sqrtkT_last_ {0.0}; //!< last temperature
419449

450+
double collision_distance_ {INFTY};
451+
420452
#ifdef OPENMC_DAGMC_ENABLED
421453
moab::DagMC::RayHistory history_;
422454
Direction last_dir_;
@@ -528,8 +560,6 @@ class ParticleData : public GeometryState {
528560

529561
bool trace_ {false};
530562

531-
double collision_distance_;
532-
533563
int n_event_ {0};
534564

535565
int n_split_ {0};
@@ -695,9 +725,6 @@ class ParticleData : public GeometryState {
695725
// Shows debug info
696726
bool& trace() { return trace_; }
697727

698-
// Distance to the next collision
699-
double& collision_distance() { return collision_distance_; }
700-
701728
// Number of events particle has undergone
702729
int& n_event() { return n_event_; }
703730

include/openmc/surface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ class SurfaceSphere : public Surface {
274274
bool triso_in_mesh(
275275
vector<double> mesh_center, vector<double> lattice_pitch) const override;
276276
BoundingBox bounding_box(bool pos_side) const override;
277+
vector<double> get_center() const override;
278+
double get_radius() const override;
279+
void connect_to_triso_base(int triso_index, std::string key) override;
277280

278281
double x0_, y0_, z0_, radius_;
279282
// int triso_base_index_ = -1;

include/openmc/universe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Universe {
2929
public:
3030
int32_t id_; //!< Unique ID
3131
vector<int32_t> cells_; //!< Cells within this universe
32+
int filled_with_triso_base_ = -1; //!< ID of cell filled with virtual lattice
3233
int32_t n_instances_; //!< Number of instances of this universe
3334

3435
//! \brief Write universe information to an HDF5 group.

src/cell.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,19 @@ CSGCell::CSGCell(pugi::xml_node cell_node)
422422
// Morgans law
423423
Region region(region_spec, id_);
424424
region_ = region;
425+
vector<int32_t> rpn = region_.generate_postfix(id_);
425426

426427
if (virtual_lattice_) {
427428
vl_triso_distribution_ = generate_triso_distribution(
428-
vl_shape_, vl_pitch_, vl_lower_left_, rpn_, id_);
429+
vl_shape_, vl_pitch_, vl_lower_left_, rpn, id_);
429430
}
430431

431432
if (triso_particle_) {
432-
if (rpn_.size() != 1) {
433+
if (rpn.size() != 1) {
433434
fatal_error(
434435
fmt::format("Wrong surface definition of triso particle cell {}", id_));
435436
} else {
436-
model::surfaces[abs(rpn_[0]) - 1]->connect_to_triso_base(id_, "particle");
437+
model::surfaces[abs(rpn[0]) - 1]->connect_to_triso_base(id_, "particle");
437438
}
438439
}
439440

@@ -591,7 +592,7 @@ std::pair<double, int32_t> CSGCell::distance(
591592
}
592593

593594
} else {
594-
region_.distance(r, u, on_surface);
595+
return region_.distance(r, u, on_surface);
595596
}
596597

597598
return {min_dist, i_surf};

src/particle.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ void Particle::event_calculate_xs()
225225

226226
void Particle::event_advance()
227227
{
228-
// Find the distance to the nearest boundary
229-
230228
// Sample a distance to collision
231229
if (type() == ParticleType::electron || type() == ParticleType::positron) {
232230
collision_distance() = 0.0;
@@ -236,6 +234,7 @@ void Particle::event_advance()
236234
collision_distance() = -std::log(prn(current_seed())) / macro_xs().total;
237235
}
238236

237+
// Find the distance to the nearest boundary
239238
boundary() = distance_to_boundary(*this);
240239

241240
double speed = this->speed();
@@ -575,14 +574,14 @@ void Particle::cross_surface(const Surface& surf)
575574
return;
576575
}
577576
#endif
578-
577+
int i_surface = std::abs(surface());
579578
bool verbose = settings::verbosity >= 10 || trace();
580-
if (surf->is_triso_surface_) {
579+
if (surf.is_triso_surface_) {
581580
if (surface() > 0) {
582581
for (int i = n_coord(); i < model::n_coord_levels; i++) {
583582
coord(i).reset();
584583
}
585-
coord(n_coord() - 1).cell =
584+
coord(n_coord() - 1).cell() =
586585
model::cell_map[model::surfaces[i_surface - 1]->triso_base_index_];
587586
} else if (surface() < 0) {
588587
for (int i = n_coord(); i < model::n_coord_levels; i++) {
@@ -592,20 +591,20 @@ void Particle::cross_surface(const Surface& surf)
592591
fatal_error(fmt::format("Particle cell of surface {} is not defined",
593592
model::surfaces[i_surface - 1]->id_));
594593
}
595-
coord(n_coord() - 1).cell =
594+
coord(n_coord() - 1).cell() =
596595
model::cell_map[model::surfaces[i_surface - 1]->triso_particle_index_];
597596
}
598597

599598
// find material
600599
bool found = true;
601-
int i_cell = coord(n_coord() - 1).cell;
600+
int i_cell = coord(n_coord() - 1).cell();
602601
for (;; ++n_coord()) {
603602
if (i_cell == C_NONE) {
604-
int i_universe = coord(n_coord() - 1).universe;
603+
int i_universe = coord(n_coord() - 1).universe();
605604
const auto& univ {model::universes[i_universe]};
606605

607606
if (univ->filled_with_triso_base_ != -1) {
608-
coord(n_coord() - 1).cell =
607+
coord(n_coord() - 1).cell() =
609608
model::cell_map[univ->filled_with_triso_base_];
610609
found = true;
611610
} else {
@@ -616,7 +615,7 @@ void Particle::cross_surface(const Surface& surf)
616615
}
617616
}
618617

619-
i_cell = coord(n_coord() - 1).cell;
618+
i_cell = coord(n_coord() - 1).cell();
620619

621620
Cell& c {*model::cells[i_cell]};
622621
if (c.type_ == Fill::MATERIAL) {
@@ -650,14 +649,14 @@ void Particle::cross_surface(const Surface& surf)
650649

651650
// Set the lower coordinate level universe.
652651
auto& coor {coord(n_coord())};
653-
coor.universe = c.fill_;
652+
coor.universe() = c.fill_;
654653

655654
// Set the position and direction.
656-
coor.r = r_local();
657-
coor.u = u_local();
655+
coor.r() = r_local();
656+
coor.u() = u_local();
658657

659658
// Apply translation.
660-
coor.r -= c.translation_;
659+
coor.r() -= c.translation_;
661660

662661
// Apply rotation.
663662
if (!c.rotation_.empty()) {

0 commit comments

Comments
 (0)