16 #include <boost/filesystem.hpp>
21 #define HITMATERIAL 0x80000000
22 #define EOL 0x40000000
23 #define EVERYTHINGFINE 0x00000000
41 maxIntegSteps_m(maxIntegSteps),
43 itsOpalBeamline_m(bl),
52 !boost::filesystem::exists(fileName)) {
55 << std::setw(17) <<
"1 - s"
56 << std::setw(18) <<
"2 - Rx"
57 << std::setw(18) <<
"3 - Ry"
58 << std::setw(18) <<
"4 - Rz"
59 << std::setw(18) <<
"5 - Px"
60 << std::setw(18) <<
"6 - Py"
61 << std::setw(18) <<
"7 - Pz"
62 << std::setw(18) <<
"8 - Efx"
63 << std::setw(18) <<
"9 - Efy"
64 << std::setw(18) <<
"10 - Efz"
65 << std::setw(18) <<
"11 - Bfx"
66 << std::setw(18) <<
"12 - Bfy"
67 << std::setw(18) <<
"13 - Bfz"
68 << std::setw(18) <<
"14 - Ekin"
69 << std::setw(18) <<
"15 - t"
72 logger_m.open(fileName, std::ios_base::app);
88 std::set<std::string> visitedElements;
120 IndexMap::value_t::const_iterator it = elementSet.begin();
121 const IndexMap::value_t::const_iterator end = elementSet.end();
122 for (; it != end; ++ it) {
123 visitedElements.insert((*it)->getName());
146 static size_t step = 0;
153 IndexMap::value_t::const_iterator it = activeSet.begin();
154 const IndexMap::value_t::const_iterator end = activeSet.end();
162 std::string names(
"\t");
163 for (; it != end; ++ it) {
168 if ((*it)->applyToReferenceParticle(localR, localP,
time_m + 0.5 * dt_m, localE, localB)) {
172 names += (*it)->getName() +
", ";
183 << std::setw(18) << std::setprecision(8) <<
r_m(0)
184 << std::setw(18) << std::setprecision(8) <<
r_m(1)
185 << std::setw(18) << std::setprecision(8) <<
r_m(2)
186 << std::setw(18) << std::setprecision(8) <<
p_m(0)
187 << std::setw(18) << std::setprecision(8) <<
p_m(1)
188 << std::setw(18) << std::setprecision(8) <<
p_m(2)
189 << std::setw(18) << std::setprecision(8) << Ef(0)
190 << std::setw(18) << std::setprecision(8) << Ef(1)
191 << std::setw(18) << std::setprecision(8) << Ef(2)
192 << std::setw(18) << std::setprecision(8) << Bf(0)
193 << std::setw(18) << std::setprecision(8) << Bf(1)
194 << std::setw(18) << std::setprecision(8) << Bf(2)
196 << std::setw(18) << std::setprecision(8) << (
time_m + 0.5 *
dt_m) * 1e9
225 IndexMap::value_t::const_iterator it = activeSet.begin();
226 const IndexMap::value_t::const_iterator end = activeSet.end();
228 for (; it != end; ++ it) {
239 const std::set<std::string> &visitedElements) {
242 IndexMap::value_t::const_iterator it = activeSet.begin();
243 const IndexMap::value_t::const_iterator end = activeSet.end();
245 for (; it != end; ++ it) {
248 visitedElements.find((*it)->getName()) == visitedElements.end()) {
265 IndexMap::value_t::const_iterator it = elementSet.begin();
266 const IndexMap::value_t::const_iterator end = elementSet.end();
268 double designEnergy = 0.0;
269 for (; it != end; ++ it) {
307 IndexMap::value_t::const_iterator it = elementSet.begin();
308 const IndexMap::value_t::const_iterator end = elementSet.end();
310 for (; it != end; ++ it) {
312 std::string
name = (*it)->getName();
315 for (
auto pit = prior.first; pit != prior.second; ++ pit) {
316 if (
std::abs((*pit).second.endField_m - start) < 1
e-10) {
327 double elementEdge = start - initialR(2) *
euclidean_norm(initialP) / initialP(2);
335 std::map<std::string, std::set<elementPosition, elementPositionComp> > tmpRegistry;
338 const std::string &
name = (*it).first;
341 auto prior = tmpRegistry.find(name);
342 if (prior == tmpRegistry.end()) {
343 std::set<elementPosition, elementPositionComp> tmpSet;
345 tmpRegistry.insert(std::make_pair(name, tmpSet));
349 std::set<elementPosition, elementPositionComp> &set = (*prior).second;
356 for (; it != end; ++ it) {
357 std::string
name = (*it).getElement()->getName();
358 auto trit = tmpRegistry.find(name);
359 if (trit == tmpRegistry.end())
continue;
361 std::queue<std::pair<double, double> > range;
362 std::set<elementPosition, elementPositionComp> &set = (*trit).second;
364 for (
auto sit = set.begin(); sit != set.end(); ++ sit) {
365 range.push(std::make_pair((*sit).elementEdge_m, (*sit).endField_m));
367 (*it).getElement()->setActionRange(range);
376 for (; it != end; ++ it) {
377 std::shared_ptr<Component> element = (*it).getElement();
378 if (visitedElements.find(element->getName()) == visitedElements.end() &&
382 element->setDesignEnergy(kineticEnergyeV);
389 double maxDrift = 0.0;
395 std::shared_ptr<Component> startPtr(static_cast<Marker*>(start.
clone()));
396 allElements.push_front(
ClassicField(startPtr, 0.0, 0.0));
401 for (; it != end; ++ it) {
402 auto element1 = it->getElement();
403 const auto &toEdge = element1->getCSTrafoGlobal2Local();
404 auto toEnd = element1->getEdgeToEnd() * toEdge;
410 auto toBegin = element1->getEdgeToBegin() * toEdge;
414 directionEnd = toBegin.rotateFrom(
Vector_t(
sin(angleRelativeToFace), 0,
cos(angleRelativeToFace)));
419 for (; it2 != end; ++ it2) {
420 if (it == it2)
continue;
422 auto element2 = it2->getElement();
423 const auto &toEdge = element2->getCSTrafoGlobal2Local();
424 auto toBegin = element2->getEdgeToBegin() * toEdge;
425 auto toEnd = element2->getEdgeToEnd() * toEdge;
434 directionBegin = toBegin.rotateFrom(
Vector_t(
sin(E1), 0,
cos(E1)));
439 double directionProjection =
dot(directionEnd, directionBegin);
440 bool overlapping =
dot(begin2 - end1, directionBegin) < 0.0?
true:
false;
443 directionProjection > 0.999 &&
444 minDistanceLocal > distance) {
445 minDistanceLocal = distance;
449 if (maxDrift < minDistanceLocal &&
451 maxDrift = minDistanceLocal;
const size_t maxIntegSteps_m
the number of time steps to track
Representation for a marker element.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
size_t loggingFrequency_m
constexpr double e
The value of .
void autophaseCavities(const IndexMap::value_t &activeSet, const std::set< std::string > &visitedElements)
double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const
Vector_t p_m
momentum of reference particle
void trackBack(double maxDrift)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Tps< T > sin(const Tps< T > &x)
Sine.
PETE_TBTree< FnCopysign, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > copysign(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
std::list< ClassicField > FieldList
void setDesignEnergy(FieldList &allElements, const std::set< std::string > &visitedElements)
Vector_t r_m
position of reference particle in lab coordinates
double getPhaseAtMaxEnergy(const Vector_t &R, const Vector_t &P, double t, double dt)
virtual void setElementLength(double length)
Set design length.
Quaternion getQuaternion(Vector_t u, Vector_t ref)
const PartData & reference_m
Vector_t rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
std::multimap< std::string, elementPosition > elementRegistry_m
void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p)
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
double computeMaximalImplicitDrift()
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
void processElementRegister()
double getBendAngle() const
OpalBeamline & itsOpalBeamline_m
static OpalData * getInstance()
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
const double zstop_m
final position in path length
double time_m
the simulated time
constexpr double c
The velocity of light in m/s.
void saveSDDS(double startS) const
void kick(const Vector_t &R, Vector_t &P, const Vector_t &Ef, const Vector_t &Bf, const double &dt) const
OrbitThreader(const PartData &ref, const Vector_t &r, const Vector_t &p, double s, double maxDiffZBunch, double t, double dT, size_t maxIntegSteps, double zstop, OpalBeamline &bl)
FieldList getElementByType(ElementBase::ElementType)
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
bool containsCavity(const IndexMap::value_t &activeSet)
Vektor< double, 3 > Vector_t
Tps< T > sqrt(const Tps< T > &x)
Square root.
void integrate(const IndexMap::value_t &activeSet, size_t maxSteps, double maxDrift=10.0)
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
double getM() const
The constant mass per particle.
Tps< T > cos(const Tps< T > &x)
Cosine.
CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr< Component > &comp) const
T euclidean_norm(const Vector< T > &)
Euclidean norm.
double pathLength_m
position of reference particle in path length
std::string::iterator iterator
virtual ElementBase * clone() const
Return clone.
double getEntranceAngle() const
std::string getInputBasename()
get input file name without extension
virtual double getDesignEnergy() const override
Inform & level1(Inform &inf)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
void push(Vector_t &R, const Vector_t &P, const double &dt) const
void tidyUp(double zstop)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
std::set< std::shared_ptr< Component > > value_t