From 0110707134774c01c143f7069a9065dd8d2f157b Mon Sep 17 00:00:00 2001 From: Vitaly Mogulian Date: Wed, 18 Feb 2026 17:48:53 +0400 Subject: [PATCH 1/5] Optimize ray tracing for the case of known starting cell and append the last cells init. for estimators' purposes --- include/openmc/plot.h | 4 ++++ src/plot.cpp | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index cd6be43b724..4d6a2ccda3c 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -502,8 +502,12 @@ class SolidRayTracePlot : public RayTracePlot { class Ray : public GeometryState { public: + // Initialize from location and diretion Ray(Position r, Direction u) { init_from_r_u(r, u); } + // Initialize from known geometry state + Ray(GeometryState& p) : GeometryState(p) {}; + // Called at every surface intersection within the model virtual void on_intersection() = 0; diff --git a/src/plot.cpp b/src/plot.cpp index ea0555202d5..5f6a02b1f10 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1413,9 +1413,9 @@ ImageData WireframeRayTracePlot::create_image() const if (wireframe_thickness_ == 1) data(horiz, vert) = wireframe_color_; for (int i = -wireframe_thickness_ / 2; i < wireframe_thickness_ / 2; - ++i) + ++i) for (int j = -wireframe_thickness_ / 2; j < wireframe_thickness_ / 2; - ++j) + ++j) if (i * i + j * j < wireframe_thickness_ * wireframe_thickness_) { // Check if wireframe pixel is out of bounds @@ -1667,9 +1667,19 @@ void Ray::trace() // After phase one is done, we can starting tracing from cell to cell within // the model. This step can use neighbor lists to accelerate the ray tracing. - // Attempt to initialize the particle. We may have to enter a loop to move - // it up to the edge of the model. - bool inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); + bool inside_cell; + // Check for location if the particle is already known + if (lowest_coord().cell() == C_NONE) { + // The geometry position of the particle is either unknown or outside of the + // edge of the model. + // Attempt to initialize the particle. We may have to + // enter a loop to move it up to the edge of the model. + inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); + } else { + // Avaliability of the cell means that the particle is located inside the + // edge. + inside_cell = true; + } // Advance to the boundary of the model while (!inside_cell) { @@ -1750,6 +1760,11 @@ void Ray::trace() coord(lev).r() += boundary().distance() * coord(lev).u(); } surface() = boundary().surface(); + // Initialize last cells from the current cell, because the cell() variable + // does not contain the data for the case of a single-segment ray + for (int j = 0; j < n_coord(); ++j) { + cell_last(j) = coord(j).cell(); + } n_coord_last() = n_coord(); n_coord() = boundary().coord_level(); if (boundary().lattice_translation()[0] != 0 || From 61be4fd618e216aeade0744991ee6c45af4e3214 Mon Sep 17 00:00:00 2001 From: Vitaly Mogulian Date: Wed, 18 Feb 2026 18:08:16 +0400 Subject: [PATCH 2/5] Add an optimization of tracing for cases of the ray origin located outside --- src/plot.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 5f6a02b1f10..d602a1f8735 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1672,9 +1672,15 @@ void Ray::trace() if (lowest_coord().cell() == C_NONE) { // The geometry position of the particle is either unknown or outside of the // edge of the model. - // Attempt to initialize the particle. We may have to - // enter a loop to move it up to the edge of the model. - inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); + if (p.lowest_coord().universe() == C_NONE) { + // Attempt to initialize the particle. We may have to + // enter a loop to move it up to the edge of the model. + inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); + } else { + // It has been already calculated that the current position is outside of + // the edge of the model. + inside_cell = false; + } } else { // Avaliability of the cell means that the particle is located inside the // edge. From 8f91bcf43549caee4716fc559e2391cf8b988d74 Mon Sep 17 00:00:00 2001 From: Vitaly Mogulian Date: Wed, 18 Feb 2026 19:40:50 +0400 Subject: [PATCH 3/5] Re-run clang-format --- src/plot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index d602a1f8735..5609d6415bc 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1413,9 +1413,9 @@ ImageData WireframeRayTracePlot::create_image() const if (wireframe_thickness_ == 1) data(horiz, vert) = wireframe_color_; for (int i = -wireframe_thickness_ / 2; i < wireframe_thickness_ / 2; - ++i) + ++i) for (int j = -wireframe_thickness_ / 2; j < wireframe_thickness_ / 2; - ++j) + ++j) if (i * i + j * j < wireframe_thickness_ * wireframe_thickness_) { // Check if wireframe pixel is out of bounds From c063e89419fb507d0f3959d5571a904e167c5d00 Mon Sep 17 00:00:00 2001 From: Vitaly Mogulian Date: Wed, 18 Feb 2026 23:57:23 +0400 Subject: [PATCH 4/5] Fix an editorial error --- src/plot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plot.cpp b/src/plot.cpp index 5609d6415bc..2d44c3fadbf 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1672,7 +1672,7 @@ void Ray::trace() if (lowest_coord().cell() == C_NONE) { // The geometry position of the particle is either unknown or outside of the // edge of the model. - if (p.lowest_coord().universe() == C_NONE) { + if (lowest_coord().universe() == C_NONE) { // Attempt to initialize the particle. We may have to // enter a loop to move it up to the edge of the model. inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); From 077b21446188c072c960562ec55593bdf86e0ffc Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 23 Feb 2026 21:57:08 -0600 Subject: [PATCH 5/5] Fix typos, take const ref in constructor --- include/openmc/plot.h | 4 ++-- src/plot.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 4d6a2ccda3c..aa373945317 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -502,11 +502,11 @@ class SolidRayTracePlot : public RayTracePlot { class Ray : public GeometryState { public: - // Initialize from location and diretion + // Initialize from location and direction Ray(Position r, Direction u) { init_from_r_u(r, u); } // Initialize from known geometry state - Ray(GeometryState& p) : GeometryState(p) {}; + Ray(const GeometryState& p) : GeometryState(p) {} // Called at every surface intersection within the model virtual void on_intersection() = 0; diff --git a/src/plot.cpp b/src/plot.cpp index 2d44c3fadbf..5e3342dd685 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1682,7 +1682,7 @@ void Ray::trace() inside_cell = false; } } else { - // Avaliability of the cell means that the particle is located inside the + // Availability of the cell means that the particle is located inside the // edge. inside_cell = true; }