Skip to content

Commit ffdd1d8

Browse files
Merge branch 'master' into add-ID_sympletic
2 parents 386fd27 + 4e09dc1 commit ffdd1d8

18 files changed

Lines changed: 215 additions & 15 deletions

‎include/trackcpp/accelerator.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ class Accelerator {
3434
int harmonic_number = 0;
3535
std::vector<Element> lattice;
3636
std::string lattice_version = "";
37+
mutable std::vector<unsigned int> time_aware_indices;
38+
mutable std::vector<double> time_aware_dl_kicks;
3739

3840
bool operator==(const Accelerator& o) const;
3941
bool operator!=(const Accelerator& o) const { return !(*this == o); };
4042
bool isequal(const Accelerator& a) const { return *this == a; } // necessary for python_package
4143
double get_length() const;
4244
friend std::ostream& operator<< (std::ostream &out, const Accelerator& a);
45+
void update_time_aware_info(void) const;
4346
};
4447

4548
#endif

‎include/trackcpp/auxiliary.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <iostream>
2424
#include <cmath>
2525
#include <random>
26+
#include <algorithm>
2627

2728
class PassMethodsClass {
2829
public:
@@ -39,6 +40,7 @@ class PassMethodsClass {
3940
static const int pm_drift_g2l_pass = 10;
4041
static const int pm_field3d_pass = 11;
4142
static const int pm_nr_pms = 12; // counter for number of passmethods
43+
static const std::vector<int> time_aware_passmethods;
4244
PassMethodsClass() {
4345
passmethods.push_back("identity_pass");
4446
passmethods.push_back("drift_pass");
@@ -55,6 +57,9 @@ class PassMethodsClass {
5557
}
5658
int size() const { return passmethods.size(); }
5759
std::string operator[](const int i) const { return passmethods[i]; }
60+
bool is_time_aware_pm(const int i) const {
61+
return std::find(time_aware_passmethods.begin(), time_aware_passmethods.end(), i) != time_aware_passmethods.end();
62+
};
5863
private:
5964
std::vector<std::string> passmethods;
6065
};

‎include/trackcpp/passmethods.hpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "linalg.h"
3434
#include "field3d.hpp"
3535
#include <cmath>
36+
#include <algorithm>
3637

3738
template <typename T> inline T SQR(const T& X) { return X*X; }
3839
template <typename T> inline T POW3(const T& X) { return X*X*X; }
@@ -518,4 +519,17 @@ Status::type pm_matrix_pass(Pos<T> &pos, const Element &elem,
518519
return Status::success;
519520
}
520521

522+
template <typename T>
523+
inline void adjust_path_length(
524+
const Accelerator& accelerator,
525+
unsigned int& element_index,
526+
Pos<T>& pos
527+
) {
528+
auto it = std::find(accelerator.time_aware_indices.begin(), accelerator.time_aware_indices.end(), element_index);
529+
if (it != accelerator.time_aware_indices.end()) {
530+
auto idx = std::distance(accelerator.time_aware_indices.begin(), it);
531+
pos.dl -= accelerator.time_aware_dl_kicks[idx];
532+
}
533+
}
534+
521535
#endif

‎include/trackcpp/tracking.h‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ Status::type track_linepass (
167167
// syntactic-sugar for read-only access to element object parameters
168168
const Element& element = line[element_offset];
169169

170+
// adjust dl to keep the arrival-time in sync with wall clock
171+
// note: for performance reasons, the adjustment of the path length
172+
// is done only at the beginning of "time aware" elements (e.g. RF cavities)
173+
adjust_path_length(accelerator, element_offset, orig_pos);
174+
170175
// stores trajectory at entrance of each element
171176
if (indcs[i]) pos.push_back(orig_pos);
172177

@@ -292,7 +297,12 @@ Status::type track_linepass (
292297
unsigned int le = element_offset;
293298

294299
status2 = track_linepass(
295-
accelerator, orig_pos[i], indices, le, final_pos, lp
300+
accelerator,
301+
orig_pos[i],
302+
indices,
303+
le,
304+
final_pos,
305+
lp
296306
);
297307

298308
if (status2 != Status::success){
@@ -372,6 +382,9 @@ Status::type track_ringpass (
372382
Status::type status = Status::success;
373383
std::vector<Pos<T> > final_pos;
374384

385+
// adjust dl to keep the arrival-time in sync with wall clock
386+
accelerator.update_time_aware_info();
387+
375388
if (turn_by_turn) pos.reserve(nr_turns+1);
376389

377390
for(lost_turn=0; lost_turn<nr_turns; ++lost_turn) {

‎python_package/LICENSE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

‎python_package/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

‎python_package/interface.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ Status::type track_linepass_wrapper(
6161
orig_pos[4*ni2 + i], orig_pos[5*ni2 + i]
6262
);
6363
}
64+
65+
// adjust dl to keep the arrival-time in sync with wall clock
66+
accelerator.update_time_aware_info();
67+
6468
Status::type status = track_linepass(
6569
accelerator,
6670
orig_post,

‎python_package/pyproject.toml‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[build-system]
2+
requires = ["setuptools>=44"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "trackcpp"
7+
authors = [ { name = "lnls-fac" }, ]
8+
maintainers = [
9+
{name = "Ana Oliveira", email = "ana.clara@lnls.br"},
10+
{name = "Ximenes Resende", email = "xresende@gmail.com"},
11+
{name = "Fernando H. de Sá", email = "fernandohds564@gmail.com"},
12+
{name = "Murilo Barbosa Alves", email= "alvesb.murilo@gmail.com"}
13+
]
14+
description = "trackcpp python package"
15+
readme = "README.md"
16+
dynamic = ["version", "dependencies"]
17+
requires-python = ">=3.6"
18+
classifiers = [
19+
"Intended Audience :: Science/Research",
20+
"Programming Language :: Python",
21+
"Topic :: Scientific/Engineering",
22+
]
23+
license = "MIT"
24+
license-files= [ "LICENSE", ]
25+
26+
[project.urls]
27+
Homepage = "https://github.com/lnls-fac/trackcpp"
28+
Download = "https://github.com/lnls-fac/trackcpp"
29+
Repository = "https://github.com/lnls-fac/trackcpp.git"
30+
Issues = "https://github.com/lnls-fac/trackcpp/issues"
31+
32+
# --- Configurações específicas do Setuptools ---
33+
[tool.setuptools]
34+
include-package-data = true
35+
36+
[tool.setuptools.dynamic]
37+
version = { file = "VERSION" }
38+
dependencies = { file = "requirements.txt" }
39+
40+
[tool.setuptools.package-data]
41+
trackcpp = ["VERSION", "_trackcpp.so"]
42+
43+
# --- linter and formatter configurations ---
44+
[tool.ruff]
45+
select = [
46+
"W", "E", "A", "B", "C90", "D", "I002", "N", "F", "G", "ARG", "S", "NPY"]
47+
ignore = [
48+
"D203", "D204", "D213", "D215", "D400", "D401", "D404", "D406", "D407",
49+
"D408", "D409", "D413", "E203", "E226"]
50+
ignore-init-module-imports = true
51+
preview = true
52+
line-length = 79
53+
fix = true
54+
55+
[tool.ruff.extend-per-file-ignores]
56+
"__init__.py" = ["F401", "F821"]
57+
58+
[tool.ruff.format]
59+
skip-magic-trailing-comma = true
60+
61+
[tool.ruff.lint.isort]
62+
split-on-trailing-comma = false
63+
combine-as-imports = true
64+
65+
[tool.isort]
66+
split_on_trailing_comma = false
67+
combine_as_imports = true
68+
combine_star = true
69+
multi_line_output = "HANGING_INDENT"
70+
order_by_type = false
71+
72+
[tool.black]
73+
line-length = 79

‎python_package/requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
numpy>=1.8

‎python_package/setup.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
#!/usr/bin/env python-sirius
22

33
from setuptools import setup
4+
import pathlib
45

5-
with open('VERSION','r') as _f:
6+
7+
def get_abs_path(relative):
8+
return str(pathlib.Path(__file__).parent / relative)
9+
10+
11+
with open(get_abs_path("README.md"), "r") as _f:
12+
_long_description = _f.read().strip()
13+
14+
with open(get_abs_path("VERSION"), "r") as _f:
615
__version__ = _f.read().strip()
716

17+
with open(get_abs_path("requirements.txt"), "r") as _f:
18+
_requirements = _f.read().strip().split("\n")
19+
820
setup(
921
name='trackcpp',
1022
version=__version__,
1123
author='lnls-fac',
1224
description='trackcpp python package',
25+
long_description=_long_description,
1326
url='https://github.com/lnls-fac/trackcpp',
1427
download_url='https://github.com/lnls-fac/trackcpp',
1528
classifiers=[
1629
'Intended Audience :: Science/Research',
1730
'Programming Language :: Python',
1831
'Topic :: Scientific/Engineering'
1932
],
33+
install_requires=_requirements,
2034
packages=['trackcpp'],
2135
package_data={'trackcpp': ['_trackcpp.so', 'VERSION']},
2236
zip_safe=False

0 commit comments

Comments
 (0)