add option to stop after some distance

This commit is contained in:
GuySten 2026-05-11 10:55:49 +03:00
parent 71da8ed745
commit e6d096390f
2 changed files with 17 additions and 3 deletions

View file

@ -24,7 +24,7 @@ public:
* Traces the ray through the geometry, calling on_intersection
* at every surface boundary.
*/
void trace();
void trace(double max_distance = INFTY);
// Stops the ray and exits tracing when called from on_intersection
void stop() { stop_ = true; }
@ -58,6 +58,8 @@ public:
type() = type_;
time() = time_;
E() = E_;
E_last() = E_;
r_last() = r;
}
void on_intersection() override;

View file

@ -13,7 +13,7 @@ void Ray::compute_distance()
boundary() = distance_to_boundary(*this);
}
void Ray::trace()
void Ray::trace(double max_distance)
{
// To trace the ray from its origin all the way through the model, we have
// to proceed in two phases. In the first, the ray may or may not be found
@ -26,6 +26,8 @@ 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.
double max = max_distance;
bool inside_cell;
// Check for location if the particle is already known
if (lowest_coord().cell() == C_NONE) {
@ -120,10 +122,20 @@ void Ray::trace()
// distance to properly check cell inclusion.
boundary().distance() += TINY_BIT;
double distance = std::min(boundary().distance(), max);
// Advance particle, prepare for next intersection
for (int lev = 0; lev < n_coord(); ++lev) {
coord(lev).r() += boundary().distance() * coord(lev).u();
coord(lev).r() += distance * coord(lev).u();
}
max -= distance;
if (max == 0.0) {
update_distance();
break;
}
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