Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2346e96
add field3d element
Gabrielrezende-asc Oct 29, 2025
ed79562
update elements with kx and ks
Gabrielrezende-asc Oct 30, 2025
224344c
add s0 property to element
Gabrielrezende-asc Oct 30, 2025
836294d
add field3d.h and field3d.cpp
Gabrielrezende-asc Oct 30, 2025
4d6fc60
add field3d passmethod
Gabrielrezende-asc Oct 30, 2025
6902e9e
fix semicolons errors
Gabrielrezende-asc Oct 30, 2025
d8cdf1d
change coefs in elements
Gabrielrezende-asc Oct 30, 2025
8b84a11
add field3d wrapper
Gabrielrezende-asc Oct 31, 2025
8f5145c
first compilation working
Gabrielrezende-asc Oct 31, 2025
56be44b
fix power in field3d.hpp
Gabrielrezende-asc Oct 31, 2025
866f0a4
calc D only once
Gabrielrezende-asc Nov 3, 2025
afcafe2
add more coefs to elements
Gabrielrezende-asc Nov 4, 2025
1d89061
add more coefs to passmethod interface
Gabrielrezende-asc Nov 4, 2025
6ecb86a
add more coefs to prop py and px functions
Gabrielrezende-asc Nov 4, 2025
912bcce
add more coeffs to potential vector
Gabrielrezende-asc Nov 4, 2025
3cc34aa
working with all coefficients
Gabrielrezende-asc Nov 4, 2025
8d4802a
change beta0 to 2 in field3d passmethod
Gabrielrezende-asc Nov 7, 2025
21bd85f
add id passmehotd flat_file
Gabrielrezende-asc Nov 18, 2025
30f531d
add prop_step to id_passmethod
Gabrielrezende-asc Nov 18, 2025
983e30e
change coefs to coefs1
Gabrielrezende-asc Jun 8, 2026
386fd27
change trackcpp structure to work only with 2 coefs set in symplectic…
Gabrielrezende-asc Jun 9, 2026
ffdd1d8
Merge branch 'master' into add-ID_sympletic
Gabrielrezende-asc Jun 9, 2026
a479d81
change field3d properties names
Gabrielrezende-asc Jun 23, 2026
bb9624b
add coefmatrix.h with CoefMatrix class
Gabrielrezende-asc Jul 17, 2026
81667bd
ENH: (FIELD3D) improve performance of ID passmethod.
fernandohds564 Jul 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions include/trackcpp/auxiliary.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class PassMethodsClass {
static const int pm_kickmap_pass = 8;
static const int pm_matrix_pass = 9;
static const int pm_drift_g2l_pass = 10;
static const int pm_nr_pms = 11; // counter for number of passmethods
static const int pm_field3d_pass = 11;
static const int pm_nr_pms = 12; // counter for number of passmethods
static const std::vector<int> time_aware_passmethods;
PassMethodsClass() {
passmethods.push_back("identity_pass");
Expand All @@ -52,6 +53,7 @@ class PassMethodsClass {
passmethods.push_back("kicktable_pass");
passmethods.push_back("matrix_pass");
passmethods.push_back("drift_g2l_pass");
passmethods.push_back("field3d_pass");
}
int size() const { return passmethods.size(); }
std::string operator[](const int i) const { return passmethods[i]; }
Expand All @@ -76,7 +78,8 @@ struct PassMethod {
pm_kickmap_pass = 8,
pm_matrix_pass = 9,
pm_drift_g2l_pass = 10,
pm_nr_pms = 11,
pm_field3d_pass = 11,
pm_nr_pms = 12,
};
};

Expand All @@ -94,6 +97,7 @@ const std::vector<std::string> pm_dict = {
"kicktable_pass",
"matrix_pass",
"drift_g2l_pass",
"field3d_pass",
};

struct RadiationState {
Expand Down
124 changes: 124 additions & 0 deletions include/trackcpp/coefmatrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// TRACKCPP - Particle tracking code
// Copyright (C) 2015 LNLS Accelerator Physics Group
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef COEFMATRIX_H
#define COEFMATRIX_H

#include <cstddef>
#include <vector>

#ifndef SWIG
template<typename T>
class MatrixRow {
public:
explicit MatrixRow(T* ptr)
: ptr_(ptr)
{}

T& operator[](size_t j)
{
return ptr_[j];
}

private:
T* ptr_;
};
#endif


class CoefMatrix {
public:

#ifndef SWIG
using Row = MatrixRow<double>;
using ConstRow = MatrixRow<const double>;
#endif

CoefMatrix() = default;

CoefMatrix(size_t rows, size_t cols)
: rows_(rows),
cols_(cols),
data_(rows * cols, 0.0)
{}

void resize(size_t rows, size_t cols)
{
rows_ = rows;
cols_ = cols;
data_.resize(rows * cols);
}

double& operator()(size_t i, size_t j)
{
return data_[i * cols_ + j];
}

const double& operator()(size_t i, size_t j) const
{
return data_[i * cols_ + j];
}

#ifndef SWIG
Row operator[](size_t i)
{
return Row(data_.data() + i * cols_);
}

ConstRow operator[](size_t i) const
{
return ConstRow(data_.data() + i * cols_);
}
#endif

size_t rows() const
{
return rows_;
}

size_t cols() const
{
return cols_;
}

size_t size() const
{
return data_.size();
}

bool empty() const
{
return data_.empty();
}

double* data()
{
return data_.data();
}

const double* data() const
{
return data_.data();
}

private:

size_t rows_ = 0;
size_t cols_ = 0;
std::vector<double> data_;
};

#endif
16 changes: 15 additions & 1 deletion include/trackcpp/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <fstream>
#include <cfloat>
#include "coefmatrix.h"


class Element {
Expand Down Expand Up @@ -63,7 +64,12 @@ class Element {
double phase_lag = 0; // [rad]
int kicktable_idx = -1; // index of kickmap object in kicktable_list
double rescale_kicks = 1.0; // for kickmaps

double field3d_hori_ks = 0; // [1/m]
double field3d_hori_kx = 0; // [1/m]
double field3d_hori_s0 = 0; // [m]
CoefMatrix field3d_hori_coefs_cos;
CoefMatrix field3d_hori_coefs_sin;

std::vector<double> polynom_a = default_polynom;
std::vector<double> polynom_b = default_polynom;
Matrix matrix66 = Matrix(6);
Expand Down Expand Up @@ -111,6 +117,10 @@ class Element {
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 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);
static Element field3d (const std::string& fam_name_, const double& length_, const double& field3d_hori_s0_, const double& field3d_hori_kx_, const double& field3d_hori_ks_,
const CoefMatrix& field3d_hori_coefs_cos_,
const CoefMatrix& field3d_hori_coefs_sin_,
const int nr_steps_ = 40);

bool operator==(const Element& o) const;
bool operator!=(const Element& o) const { return !(*this == o); };
Expand All @@ -132,5 +142,9 @@ void initialize_quadrupole(Element& element, const double& K, const int& nr_step
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_kickmap(Element& element, const int& kicktable_idx, const int& nr_steps, const double &rescale_kicks);
void initialize_field3d(Element& element, const double& field3d_hori_s0_, const double& field3d_hori_kx_, const double& field3d_hori_ks_,
const CoefMatrix& field3d_hori_coefs_cos_,
const CoefMatrix& field3d_hori_coefs_sin_,
const int nr_steps_);

#endif
Loading
Loading