Skip to content

Commit

Permalink
introduce real time into candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienDoerner committed Nov 17, 2023
1 parent f790e32 commit bad4c48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/crpropa/Candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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;

Expand Down
20 changes: 17 additions & 3 deletions src/Candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -57,6 +57,10 @@ double Candidate::getTrajectoryLength() const {
return trajectoryLength;
}

double Candidate::getTime() const {
return time;
}

double Candidate::getWeight() const {
return weight;
}
Expand All @@ -77,13 +81,18 @@ void Candidate::setTrajectoryLength(double a) {
trajectoryLength = a;
}

void Candidate::setTime(double t) {
time = t;
}

void Candidate::setWeight(double w) {
weight = w;
}

void Candidate::setCurrentStep(double lstep) {
currentStep = lstep;
trajectoryLength += lstep;
time += lstep / c_light; // adjust for v < c
}

void Candidate::setNextStep(double step) {
Expand Down Expand Up @@ -128,6 +137,7 @@ void Candidate::addSecondary(int id, double energy, double weight) {
ref_ptr<Candidate> secondary = new Candidate;
secondary->setRedshift(redshift);
secondary->setTrajectoryLength(trajectoryLength);
secondary->setTime(time);
secondary->setWeight(weight);
secondary->source = source;
secondary->previous = previous;
Expand All @@ -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<Candidate> 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;
Expand Down Expand Up @@ -180,6 +192,7 @@ ref_ptr<Candidate> 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) {
Expand Down Expand Up @@ -228,6 +241,7 @@ uint64_t Candidate::nextSerialNumber = 0;
void Candidate::restart() {
setActive(true);
setTrajectoryLength(0);
setTime(0);
previous = source;
current = source;
}
Expand Down

0 comments on commit bad4c48

Please sign in to comment.