From 0667748727378d3ee2c40bffc737a6f0b22bf3ef Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 12 Sep 2025 03:44:34 -0300 Subject: [PATCH 1/8] ADD: add accelerator frequency property --- include/trackcpp/accelerator.h | 1 + src/accelerator.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/trackcpp/accelerator.h b/include/trackcpp/accelerator.h index 0653507..855a4b1 100644 --- a/include/trackcpp/accelerator.h +++ b/include/trackcpp/accelerator.h @@ -32,6 +32,7 @@ class Accelerator { int radiation_on = RadiationState::off; bool vchamber_on = false; int harmonic_number = 0; + double frequency = 0; // [Hz] std::vector lattice; std::string lattice_version = ""; diff --git a/src/accelerator.cpp b/src/accelerator.cpp index 0e83afe..49dbe0a 100644 --- a/src/accelerator.cpp +++ b/src/accelerator.cpp @@ -34,6 +34,7 @@ bool Accelerator::operator==(const Accelerator& o) const { if (this->radiation_on != o.radiation_on) return false; if (this->vchamber_on != o.vchamber_on) return false; if (this->harmonic_number != o.harmonic_number) return false; + if (this->frequency != o.frequency) return false; if (this->lattice != o.lattice) return false; if (this->lattice_version != o.lattice_version) return false; @@ -48,6 +49,7 @@ std::ostream& operator<< (std::ostream &out, const Accelerator& a) { out << std::endl << "radiation_on : " << a.radiation_on; out << std::endl << "vchamber_on : " << a.vchamber_on; out << std::endl << "harmonic_number: " << a.harmonic_number; + out << std::endl << "frequency : " << a.frequency; out << std::endl << "lattice : " << a.lattice.size() << " elements"; out << std::endl << "lattice_version: " << a.lattice_version; return out; From c2d47af83c679cd8fced44c1ca5e05ae9a25cb12 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 12 Sep 2025 03:46:46 -0300 Subject: [PATCH 2/8] MNT: swap element's frequency -> harmonic --- include/trackcpp/elements.h | 2 +- src/elements.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/trackcpp/elements.h b/include/trackcpp/elements.h index 94942d9..d552eb8 100644 --- a/include/trackcpp/elements.h +++ b/include/trackcpp/elements.h @@ -58,7 +58,7 @@ class Element { double fint_out = 0; double thin_KL = 0; // [1/m] double thin_SL = 0; // [1/m²] - double frequency = 0; // [Hz] + int harmonic = 0; // double voltage = 0; // [V] double phase_lag = 0; // [rad] int kicktable_idx = -1; // index of kickmap object in kicktable_list diff --git a/src/elements.cpp b/src/elements.cpp index 5d96fb1..4330b6e 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -196,7 +196,7 @@ bool Element::operator==(const Element& o) const { if (this->fint_out != o.fint_out) return false; if (this->thin_KL != o.thin_KL) return false; if (this->thin_SL != o.thin_SL) return false; - if (this->frequency != o.frequency) return false; + if (this->harmonic != o.harmonic) return false; if (this->voltage != o.voltage) return false; if (this->phase_lag != o.phase_lag) return false; if (this->polynom_a != o.polynom_a) return false; @@ -240,7 +240,7 @@ std::ostream& operator<< (std::ostream &out, const Element& el) { } print_polynom( out, "polynom_a : ", el.polynom_a); print_polynom( out, "polynom_b : ", el.polynom_b); - if (el.frequency != 0)out << std::endl << "frequency : " << el.frequency; + if (el.harmonic != 0) out << std::endl << "harmonic : " << el.harmonic; if (el.voltage != 0) out << std::endl << "voltage : " << el.voltage; if (el.phase_lag != 0)out << std::endl << "phase_lag : " << el.phase_lag; return out; From 48f5bb16418c1e4134d468eac8315e3a692cdcb0 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 12 Sep 2025 03:48:28 -0300 Subject: [PATCH 3/8] MNT: match Accelerator and Element properties in cavity pass method --- include/trackcpp/passmethods.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/trackcpp/passmethods.hpp b/include/trackcpp/passmethods.hpp index 9b315ea..f5fff2c 100644 --- a/include/trackcpp/passmethods.hpp +++ b/include/trackcpp/passmethods.hpp @@ -400,9 +400,10 @@ Status::type pm_cavity_pass(Pos &pos, const Element &elem, global_2_local(pos, elem); double nv = elem.voltage / accelerator.energy; + double freq = elem.harmonic * accelerator.frequency; if (elem.length == 0) { T &de = pos.de, &dl = pos.dl; - de += -nv * sin(TWOPI*elem.frequency * dl/ light_speed - elem.phase_lag); + de += -nv * sin(TWOPI*freq * dl/ light_speed - elem.phase_lag); } else { T &rx = pos.rx, &px = pos.px; T &ry = pos.ry, &py = pos.py; @@ -414,7 +415,7 @@ Status::type pm_cavity_pass(Pos &pos, const Element &elem, ry += norml * py; dl += 0.5 * norml * pnorm * (px*px + py*py); // longitudinal momentum kick - de += -nv * sin(TWOPI*elem.frequency*dl/light_speed - elem.phase_lag); + de += -nv * sin(TWOPI*freq*dl/light_speed - elem.phase_lag); // drift half length pnorm = 1.0 / (1.0 + de); norml = (0.5 * elem.length) * pnorm; From 0beb7620e052ff2aafc4a030099f2b3e8ca61624 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 12 Sep 2025 03:51:18 -0300 Subject: [PATCH 4/8] MNT: swap frequency -> harmonic in RF Cavity Element constructors --- include/trackcpp/elements.h | 4 ++-- python_package/interface.cpp | 4 ++-- python_package/interface.h | 2 +- src/elements.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/trackcpp/elements.h b/include/trackcpp/elements.h index d552eb8..75a32a2 100644 --- a/include/trackcpp/elements.h +++ b/include/trackcpp/elements.h @@ -109,7 +109,7 @@ class Element { const double& K_ = 0, const double& S_ = 0, const int nr_steps_ = 20); static Element quadrupole (const std::string& fam_name_, const double& length_, const double& K_, const int nr_steps_ = 10); static Element sextupole (const std::string& fam_name_, const double& length_, const double& S_, const int nr_steps_ = 5); - static Element rfcavity (const std::string& fam_name_, const double& length_, const double& frequency_, const double& voltage_, const double& phase_lag_); + static Element rfcavity (const std::string& fam_name_, const double& length_, const double& harmonic_, const double& voltage_, const double& phase_lag_); static Element kickmap (const std::string& fam_name_, const std::string& kicktable_fname_, const int nr_steps_ = 20, const double& rescale_length_ = 1.0, const double& rescale_kicks_ = 1.0); bool operator==(const Element& o) const; @@ -130,7 +130,7 @@ void initialize_rbend(Element& element, const double& angle, const double& angle const double& K, const double& S, const int nr_steps); void initialize_quadrupole(Element& element, const double& K, const int& nr_steps); void initialize_sextupole(Element& element, const double& S, const int& nr_steps); -void initialize_rfcavity(Element& element, const double& frequency, const double& voltage, const double& phase_lag); +void initialize_rfcavity(Element& element, const double& harmonic, const double& voltage, const double& phase_lag); void initialize_kickmap(Element& element, const int& kicktable_idx, const int& nr_steps, const double &rescale_kicks); #endif diff --git a/python_package/interface.cpp b/python_package/interface.cpp index 383c7fe..1df88f7 100644 --- a/python_package/interface.cpp +++ b/python_package/interface.cpp @@ -229,8 +229,8 @@ Element sextupole_wrapper(const std::string &fam_name_, const double &length_, c return Element::sextupole(fam_name_, length_, S_, nr_steps_); } -Element rfcavity_wrapper(const std::string &fam_name_, const double &length_, const double &frequency_, const double &voltage_, const double &phase_lag_) { - return Element::rfcavity(fam_name_, length_, frequency_, voltage_, phase_lag_); +Element rfcavity_wrapper(const std::string &fam_name_, const double &length_, const double &harmonic_, const double &voltage_, const double &phase_lag_) { + return Element::rfcavity(fam_name_, length_, harmonic_, voltage_, phase_lag_); } Element kickmap_wrapper(const std::string& fam_name_, const std::string& kicktable_fname_, const int nr_steps_, const double& rescale_length_, const double& rescale_kicks_) { diff --git a/python_package/interface.h b/python_package/interface.h index e35e092..6aed22e 100644 --- a/python_package/interface.h +++ b/python_package/interface.h @@ -89,7 +89,7 @@ Element drift_g2l_wrapper(const std::string& fam_name_, const double& length_); Element matrix_wrapper(const std::string& fam_name_, const double& length_); Element quadrupole_wrapper(const std::string& fam_name_, const double& length_, const double& K_, const int nr_steps_ = 10); Element sextupole_wrapper(const std::string& fam_name_, const double& length_, const double& S_, const int nr_steps_ = 5); -Element rfcavity_wrapper(const std::string& fam_name_, const double& length_, const double& frequency_, const double& voltage_, const double& phase_lag); +Element rfcavity_wrapper(const std::string& fam_name_, const double& length_, const double& harmonic_, const double& voltage_, const double& phase_lag); Element kickmap_wrapper(const std::string& fam_name_, const std::string& kicktable_fname_, const int nr_steps_ = 20, const double& rescale_length = 1.0, const double& rescale_kicks = 1.0); Element rbend_wrapper(const std::string& fam_name_, const double& length_, const double& angle_, const double& angle_in_, const double& angle_out_, diff --git a/src/elements.cpp b/src/elements.cpp index 4330b6e..253eb3c 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -140,9 +140,9 @@ Element Element::rbend (const std::string& fam_name_, const double& length_, return e; } -Element Element::rfcavity (const std::string& fam_name_, const double& length_, const double& frequency_, const double& voltage_, const double& phase_lag_) { +Element Element::rfcavity (const std::string& fam_name_, const double& length_, const double& harmonic_, const double& voltage_, const double& phase_lag_) { Element e = Element(fam_name_, length_); - initialize_rfcavity(e, frequency_, voltage_, phase_lag_); + initialize_rfcavity(e, harmonic_, voltage_, phase_lag_); return e; } @@ -295,9 +295,9 @@ void initialize_sextupole(Element &element, const double &S, const int &nr_steps element.nr_steps = nr_steps; } -void initialize_rfcavity(Element &element, const double &frequency, const double &voltage, const double &phase_lag) { +void initialize_rfcavity(Element &element, const double &harmonic, const double &voltage, const double &phase_lag) { element.pass_method = PassMethod::pm_cavity_pass; - element.frequency = frequency; + element.harmonic = harmonic; element.voltage = voltage; element.phase_lag = phase_lag; } From aa19a71a08f93180a7ced2c1cdc5627f7e8dce3d Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 12 Sep 2025 03:53:35 -0300 Subject: [PATCH 5/8] MNT: update lattice utils --- include/trackcpp/lattice.h | 2 +- src/lattice.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/trackcpp/lattice.h b/include/trackcpp/lattice.h index 97ef182..fd6ac0e 100644 --- a/include/trackcpp/lattice.h +++ b/include/trackcpp/lattice.h @@ -34,7 +34,7 @@ std::vector latt_read_flat_file(const std::string& filename); Status::type latt_read_flat_file(const std::string& filename, Accelerator& accelerator); std::vector latt_findcells_fam_name (const std::vector& lattice, const std::string& value, bool reverse = false); std::vector latt_findcells_angle (const std::vector& lattice, const double& value, bool reverse = false); -std::vector latt_findcells_frequency (const std::vector& lattice, const double& value, bool reverse = false); +std::vector latt_findcells_harmonic (const std::vector& lattice, const double& value, bool reverse = false); std::vector latt_findcells_polynom_b (const std::vector& lattice, unsigned int n, const double& value, bool reverse = false); std::vector latt_findcells_polynom_a (const std::vector& lattice, unsigned int n, const double& value, bool reverse = false); std::vector latt_findcells_pass_method (const std::vector& lattice, const std::string& value, bool reverse = false); diff --git a/src/lattice.cpp b/src/lattice.cpp index 910a841..57487f0 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -76,7 +76,7 @@ double latt_findspos(const std::vector& lattice, const int idx) { void latt_setcavity(std::vector& lattice, const std::string& state) { for(unsigned int i=0; i latt_findcells_fam_name(const std::vector& lattice, co return r; } -std::vector latt_findcells_frequency(const std::vector& lattice, const double& value, bool reverse) { +std::vector latt_findcells_harmonic(const std::vector& lattice, const double& value, bool reverse) { std::vector r; for(unsigned int i=0; i Date: Fri, 12 Sep 2025 03:54:50 -0300 Subject: [PATCH 6/8] MNT: match accelerator's frequency property in track_findorbit6 --- src/tracking.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tracking.cpp b/src/tracking.cpp index f751390..62daa34 100644 --- a/src/tracking.cpp +++ b/src/tracking.cpp @@ -149,9 +149,7 @@ Status::type track_findorbit6( // calcs longitudinal fixed point double L0 = latt_findspos(the_ring, 1+the_ring.size()); double T0 = L0 / light_speed; - std::vector cav_idx = latt_findcells_frequency(the_ring, 0, true); - double frf = the_ring[cav_idx[0]].frequency; - double fixedpoint = light_speed*((1.0*accelerator.harmonic_number)/frf - T0); + double fixedpoint = light_speed*((1.0*accelerator.harmonic_number)/accelerator.frequency - T0); // temporary vectors and matrices std::vector > co(7,0); From 988dce9507e084692ed6502001b4eafd931d52d1 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 12 Sep 2025 04:01:34 -0300 Subject: [PATCH 7/8] MNT: update sirius_v500 creation and usage --- src/sirius_v500.cpp | 13 ------------- src/tests.cpp | 1 + 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/sirius_v500.cpp b/src/sirius_v500.cpp index f8e4c95..30ad17f 100644 --- a/src/sirius_v500.cpp +++ b/src/sirius_v500.cpp @@ -21,10 +21,6 @@ void sirius_v500(std::vector& the_ring) { - int harmonic_number = 864; - - //double energy = 3e9; - // AC10_5 double qaf_strength = 2.536876; double qad_strength = -2.730416; @@ -257,15 +253,6 @@ void sirius_v500(std::vector& the_ring) { } } - //""" sets cavity frequency according to lattice length """ - double C = latt_findspos(the_ring, 1+the_ring.size()); - - double rev_freq = light_speed / C; - std::vector rf_idx = latt_findcells_fam_name(the_ring, "cav"); - - for(unsigned int idx = 0; idx Date: Fri, 12 Sep 2025 04:02:53 -0300 Subject: [PATCH 8/8] MNT: update flat_file read/write with Accelerator's frequency and Element's harmonic --- src/flat_file.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/flat_file.cpp b/src/flat_file.cpp index a6ecc4b..b7c961f 100644 --- a/src/flat_file.cpp +++ b/src/flat_file.cpp @@ -82,6 +82,7 @@ void write_flat_file_trackcpp(std::ostream& fp, const Accelerator& accelerator) fp << std::setw(hw) << "% energy" << accelerator.energy << " eV\n"; fp << std::setw(hw) << "% harmonic_number" << accelerator.harmonic_number << "\n"; + fp << std::setw(hw) << "% frequency" << accelerator.frequency << "\n"; fp << std::setw(hw) << "% cavity_on" << get_boolean_string(accelerator.cavity_on) << "\n"; fp << std::setw(hw) << "% radiation_on" << accelerator.radiation_on << "\n"; fp << std::setw(hw) << "% vchamber_on" << get_boolean_string(accelerator.vchamber_on) << "\n"; @@ -122,7 +123,7 @@ void write_flat_file_trackcpp(std::ostream& fp, const Accelerator& accelerator) if (e.fint_in != 0) { fp << std::setw(pw) << "fint_in" << e.fint_in << '\n'; } if (e.fint_out != 0) { fp << std::setw(pw) << "fint_out" << e.fint_out << '\n'; } if (e.voltage != 0) { fp << std::setw(pw) << "voltage" << e.voltage << '\n'; } - if (e.frequency != 0) { fp << std::setw(pw) << "frequency" << e.frequency << '\n'; } + if (e.harmonic != 0) { fp << std::setw(pw) << "harmonic" << e.harmonic << '\n'; } if (e.phase_lag != 0) { fp << std::setw(pw) << "phase_lag" << e.phase_lag << '\n'; } if (e.angle_in != 0) { fp << std::setw(pw) << "angle_in" << e.angle_in << '\n'; } if (e.angle_out != 0) { fp << std::setw(pw) << "angle_out" << e.angle_out << '\n'; } @@ -170,6 +171,7 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) bool found_hmin = false; bool found_vmin = false; unsigned int line_count = 0; + std::vector frequencies = {}; while (std::getline(fp, line)) { //std::cout << line << std::endl; line_count++; @@ -182,6 +184,7 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) ss >> cmd; if (cmd.compare("energy") == 0) { ss >> accelerator.energy; continue; } if (cmd.compare("harmonic_number") == 0) { ss >> accelerator.harmonic_number; continue; } + if (cmd.compare("frequency") == 0) { ss >> accelerator.frequency; continue; } if (cmd.compare("cavity_on") == 0) { accelerator.cavity_on = read_boolean_string(ss); continue; } // radiation_on needs its own processing function due backward compatibility if (cmd.compare("radiation_on") == 0){ accelerator.radiation_on = process_rad_property(ss); continue; } @@ -221,7 +224,13 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) if (cmd.compare("fint_in") == 0) { ss >> e.fint_in; continue; } if (cmd.compare("fint_out") == 0) { ss >> e.fint_out; continue; } if (cmd.compare("voltage") == 0) { ss >> e.voltage; continue; } - if (cmd.compare("frequency") == 0) { ss >> e.frequency; continue; } + if (cmd.compare("harmonic") == 0) { ss >> e.harmonic; continue; } + if (cmd.compare("frequency") == 0) { + double freq; + ss >> freq; + frequencies.push_back(freq); + continue; + } if (cmd.compare("phase_lag") == 0) { ss >> e.phase_lag; continue; } if (cmd.compare("angle_in") == 0) { ss >> e.angle_in; continue; } if (cmd.compare("angle_out") == 0) { ss >> e.angle_out; continue; } @@ -311,6 +320,10 @@ Status::type read_flat_file_trackcpp(std::istream& fp, Accelerator& accelerator) accelerator.lattice.push_back(e); } + if (frequencies.size() > 0) { + accelerator.frequency = frequencies[0]; + } + return Status::success; } @@ -364,11 +377,12 @@ static Status::type read_flat_file_tracy(const std::string& filename, Accelerato case FlatFileType::cavity: { e.pass_method = PassMethod::pm_cavity_pass; - int hnumber; double energy; - fp >> e.voltage >> e.frequency >> hnumber >> energy; - e.voltage *= energy; e.frequency *= light_speed / (2*M_PI); + int hnumber; double energy; double freq; + fp >> e.voltage >> freq >> hnumber >> energy; + e.voltage *= energy; freq *= light_speed / (2*M_PI); accelerator.harmonic_number = hnumber; accelerator.energy = energy; + accelerator.frequency = freq; }; break; case FlatFileType::mpole: {