From bad4c484397bb1ec09f341d866fda9ca1d177405 Mon Sep 17 00:00:00 2001 From: Julien Date: Fri, 17 Nov 2023 12:49:45 +0200 Subject: [PATCH] introduce real time into candidate --- include/crpropa/Candidate.h | 7 +++++++ src/Candidate.cpp | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/crpropa/Candidate.h b/include/crpropa/Candidate.h index 1ddb995b6..14bcac0a6 100644 --- a/include/crpropa/Candidate.h +++ b/include/crpropa/Candidate.h @@ -44,6 +44,7 @@ class Candidate: public Referenced { double weight; /**< Weight of the candidate */ double redshift; /**< Current simulation time-point in terms of redshift z */ double trajectoryLength; /**< Comoving distance [m] the candidate has traveled so far */ + double time; /**< Current simulation time in [s] */ double currentStep; /**< Size of the currently performed step in [m] comoving units */ double nextStep; /**< Proposed size of the next propagation step in [m] comoving units */ @@ -72,6 +73,12 @@ class Candidate: public Referenced { void setTrajectoryLength(double length); double getTrajectoryLength() const; + /** + Set the total time. + */ + void setTime(double time); + double getTime() const; + void setRedshift(double z); double getRedshift() const; diff --git a/src/Candidate.cpp b/src/Candidate.cpp index d9a6c6d20..be4527223 100644 --- a/src/Candidate.cpp +++ b/src/Candidate.cpp @@ -7,7 +7,7 @@ namespace crpropa { Candidate::Candidate(int id, double E, Vector3d pos, Vector3d dir, double z, double weight) : - redshift(z), trajectoryLength(0), weight(1), currentStep(0), nextStep(0), active(true), parent(0) { + redshift(z), trajectoryLength(0), weight(1), currentStep(0), nextStep(0), active(true), parent(0), time(0) { ParticleState state(id, E, pos, dir); source = state; created = state; @@ -27,7 +27,7 @@ Candidate::Candidate(int id, double E, Vector3d pos, Vector3d dir, double z, dou } Candidate::Candidate(const ParticleState &state) : - source(state), created(state), current(state), previous(state), redshift(0), trajectoryLength(0), currentStep(0), nextStep(0), active(true), parent(0) { + source(state), created(state), current(state), previous(state), redshift(0), trajectoryLength(0), currentStep(0), nextStep(0), active(true), parent(0), time(0) { #if defined(OPENMP_3_1) #pragma omp atomic capture @@ -57,6 +57,10 @@ double Candidate::getTrajectoryLength() const { return trajectoryLength; } +double Candidate::getTime() const { + return time; +} + double Candidate::getWeight() const { return weight; } @@ -77,6 +81,10 @@ void Candidate::setTrajectoryLength(double a) { trajectoryLength = a; } +void Candidate::setTime(double t) { + time = t; +} + void Candidate::setWeight(double w) { weight = w; } @@ -84,6 +92,7 @@ void Candidate::setWeight(double w) { void Candidate::setCurrentStep(double lstep) { currentStep = lstep; trajectoryLength += lstep; + time += lstep / c_light; // adjust for v < c } void Candidate::setNextStep(double step) { @@ -128,6 +137,7 @@ void Candidate::addSecondary(int id, double energy, double weight) { ref_ptr secondary = new Candidate; secondary->setRedshift(redshift); secondary->setTrajectoryLength(trajectoryLength); + secondary->setTime(time); secondary->setWeight(weight); secondary->source = source; secondary->previous = previous; @@ -142,7 +152,9 @@ void Candidate::addSecondary(int id, double energy, double weight) { void Candidate::addSecondary(int id, double energy, Vector3d position, double weight) { ref_ptr secondary = new Candidate; secondary->setRedshift(redshift); - secondary->setTrajectoryLength(trajectoryLength - (current.getPosition() - position).getR() ); + double dR = (current.getPosition() - position).getR(); + secondary->setTrajectoryLength(trajectoryLength - dR); + secondary->setTime(time - dR / c_light); // adjust for v < c secondary->setWeight(weight); secondary->source = source; secondary->previous = previous; @@ -180,6 +192,7 @@ ref_ptr Candidate::clone(bool recursive) const { cloned->redshift = redshift; cloned->weight = weight; cloned->trajectoryLength = trajectoryLength; + cloned->time = time; cloned->currentStep = currentStep; cloned->nextStep = nextStep; if (recursive) { @@ -228,6 +241,7 @@ uint64_t Candidate::nextSerialNumber = 0; void Candidate::restart() { setActive(true); setTrajectoryLength(0); + setTime(0); previous = source; current = source; }