From 420ace050c4b718b306dcd9cdb9041327e541d47 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 27 Mar 2026 20:16:16 -0300 Subject: [PATCH 1/2] BUGFIX: operate on time_aware vectors only if they are not empty --- src/accelerator.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/accelerator.cpp b/src/accelerator.cpp index 04a7f4d..afa0f22 100644 --- a/src/accelerator.cpp +++ b/src/accelerator.cpp @@ -81,18 +81,18 @@ void Accelerator::update_time_aware_info(void) const { if (this->time_aware_indices.size() > 0) { time_aware_displacements[0] += s_pos; - } - - //? NOTE : The diference between "line_length" and the sum of "time_aware_displacements" (cum_length) is on the order of - //? 1e-15 ~ 1e-16. The propagation of this tiny error affects the tracking. The following lines avoid losing precision. - double cum_length = std::accumulate(time_aware_displacements.begin(), time_aware_displacements.end(), 0.0); - double line_length = this->get_length(); - time_aware_displacements.back() += line_length - cum_length; - - double ddl = 0.0; - for (size_t i=0; itime_aware_indices.size(); i++) { - ddl = light_speed*this->harmonic_number/this->lattice[this->time_aware_indices[i]].frequency - line_length; - this->time_aware_dl_kicks.push_back(ddl * time_aware_displacements[i] / line_length); + + //? NOTE : The diference between "line_length" and the sum of "time_aware_displacements" (cum_length) is on the order of + //? 1e-15 ~ 1e-16. The propagation of this tiny error affects the tracking. The following lines avoid losing precision. + double cum_length = std::accumulate(time_aware_displacements.begin(), time_aware_displacements.end(), 0.0); + double line_length = this->get_length(); + time_aware_displacements.back() += line_length - cum_length; + + double ddl = 0.0; + for (size_t i=0; itime_aware_indices.size(); i++) { + ddl = light_speed*this->harmonic_number/this->lattice[this->time_aware_indices[i]].frequency - line_length; + this->time_aware_dl_kicks.push_back(ddl * time_aware_displacements[i] / line_length); + } } } From a99ef49f24b9394f2b6a099f4f111aa3f35f494f Mon Sep 17 00:00:00 2001 From: Vitor Date: Tue, 31 Mar 2026 13:17:27 -0300 Subject: [PATCH 2/2] MNT: reorder code ("if" condition on "update_time_aware_info" --- src/accelerator.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/accelerator.cpp b/src/accelerator.cpp index afa0f22..ca87ca9 100644 --- a/src/accelerator.cpp +++ b/src/accelerator.cpp @@ -79,20 +79,20 @@ void Accelerator::update_time_aware_info(void) const { } } - if (this->time_aware_indices.size() > 0) { - time_aware_displacements[0] += s_pos; - - //? NOTE : The diference between "line_length" and the sum of "time_aware_displacements" (cum_length) is on the order of - //? 1e-15 ~ 1e-16. The propagation of this tiny error affects the tracking. The following lines avoid losing precision. - double cum_length = std::accumulate(time_aware_displacements.begin(), time_aware_displacements.end(), 0.0); - double line_length = this->get_length(); - time_aware_displacements.back() += line_length - cum_length; + if (this->time_aware_indices.size() == 0) return; + + time_aware_displacements[0] += s_pos; - double ddl = 0.0; - for (size_t i=0; itime_aware_indices.size(); i++) { - ddl = light_speed*this->harmonic_number/this->lattice[this->time_aware_indices[i]].frequency - line_length; - this->time_aware_dl_kicks.push_back(ddl * time_aware_displacements[i] / line_length); - } + //? NOTE : The diference between "line_length" and the sum of "time_aware_displacements" (cum_length) is on the order of + //? 1e-15 ~ 1e-16. The propagation of this tiny error affects the tracking. The following lines avoid losing precision. + double cum_length = std::accumulate(time_aware_displacements.begin(), time_aware_displacements.end(), 0.0); + double line_length = this->get_length(); + time_aware_displacements.back() += line_length - cum_length; + + double ddl = 0.0; + for (size_t i=0; itime_aware_indices.size(); i++) { + ddl = light_speed*this->harmonic_number/this->lattice[this->time_aware_indices[i]].frequency - line_length; + this->time_aware_dl_kicks.push_back(ddl * time_aware_displacements[i] / line_length); } }