42 #define HITMATERIAL 0x80000000
43 #define EOL 0x40000000
44 #define EVERYTHINGFINE 0x00000000
61 stepSizes_m(stepSizes),
62 zstop_m(stepSizes.getFinalZStop() + std::
copysign(1.0, dt) * 2 * maxDiffZBunch),
63 itsOpalBeamline_m(bl),
71 opal->getAuxiliaryOutputDirectory(),
72 opal->getInputBasename() +
"_DesignPath.dat"
75 !std::filesystem::exists(fileName)) {
78 << std::setw(17) <<
"1 - s"
79 << std::setw(18) <<
"2 - Rx"
80 << std::setw(18) <<
"3 - Ry"
81 << std::setw(18) <<
"4 - Rz"
82 << std::setw(18) <<
"5 - Px"
83 << std::setw(18) <<
"6 - Py"
84 << std::setw(18) <<
"7 - Pz"
85 << std::setw(18) <<
"8 - Efx"
86 << std::setw(18) <<
"9 - Efy"
87 << std::setw(18) <<
"10 - Efz"
88 << std::setw(18) <<
"11 - Bfx"
89 << std::setw(18) <<
"12 - Bfy"
90 << std::setw(18) <<
"13 - Bfz"
91 << std::setw(18) <<
"14 - Ekin"
92 << std::setw(18) <<
"15 - t"
95 logger_m.open(fileName, std::ios_base::app);
119 for (
const std::shared_ptr<Component>& field :
fields) {
120 double length = field->getElementLength();
121 int numSteps = field->getRequiredNumberOfTimeSteps();
123 if (length < numSteps * driftLength) {
125 "The time step is too long compared to the length of the\n"
126 "element '" + field->getName() +
"'\n" +
127 "The length of the element is: " + std::to_string(length) +
"\n"
128 "The distance the particles drift in " + std::to_string(numSteps) +
129 " time step(s) is: " + std::to_string(numSteps * driftLength));
138 std::set<std::string> visitedElements;
151 std::set<std::shared_ptr<Component>> intersection, currentSet;
175 IndexMap::value_t::const_iterator
it = elementSet.begin();
176 const IndexMap::value_t::const_iterator
end = elementSet.end();
177 for (; it !=
end; ++
it) {
178 visitedElements.insert((*it)->getName());
183 currentSet = elementSet;
191 intersection.clear();
192 std::set_intersection(currentSet.begin(), currentSet.end(),
193 elementSet.begin(), elementSet.end(),
194 std::inserter(intersection, intersection.begin()));
199 intersection.empty() && !(elementSet.empty() || currentSet.empty())));
214 IndexMap::value_t::const_iterator
it = activeSet.begin();
215 const IndexMap::value_t::const_iterator
end = activeSet.end();
223 std::string
names(
"\t");
224 for (; it !=
end; ++
it) {
229 if ((*it)->applyToReferenceParticle(localR, localP,
time_m + 0.5 * dt_m, localE, localB)) {
233 names += (*it)->getName() +
", ";
244 << std::setw(18) << std::setprecision(8) <<
r_m(0)
245 << std::setw(18) << std::setprecision(8) <<
r_m(1)
246 << std::setw(18) << std::setprecision(8) <<
r_m(2)
247 << std::setw(18) << std::setprecision(8) <<
p_m(0)
248 << std::setw(18) << std::setprecision(8) <<
p_m(1)
249 << std::setw(18) << std::setprecision(8) <<
p_m(2)
250 << std::setw(18) << std::setprecision(8) << Ef(0)
251 << std::setw(18) << std::setprecision(8) << Ef(1)
252 << std::setw(18) << std::setprecision(8) << Ef(2)
253 << std::setw(18) << std::setprecision(8) << Bf(0)
254 << std::setw(18) << std::setprecision(8) << Bf(1)
255 << std::setw(18) << std::setprecision(8) << Bf(2)
275 if (activeSet.empty() &&
287 IndexMap::value_t::const_iterator
it = activeSet.begin();
288 const IndexMap::value_t::const_iterator
end = activeSet.end();
290 for (; it !=
end; ++
it) {
301 const std::set<std::string> &visitedElements) {
304 IndexMap::value_t::const_iterator
it = activeSet.begin();
305 const IndexMap::value_t::const_iterator
end = activeSet.end();
307 for (; it !=
end; ++
it) {
310 visitedElements.find((*it)->getName()) == visitedElements.end()) {
327 IndexMap::value_t::const_iterator
it = elementSet.begin();
328 const IndexMap::value_t::const_iterator
end = elementSet.end();
330 double designEnergy = 0.0;
331 for (; it !=
end; ++
it) {
375 IndexMap::value_t::const_iterator
it = elementSet.begin();
376 const IndexMap::value_t::const_iterator
end = elementSet.end();
378 for (; it !=
end; ++
it) {
380 std::string
name = (*it)->getName();
383 for (
auto pit = prior.first; pit != prior.second; ++ pit) {
384 if (
std::abs((*pit).second.endField_m - start) < 1
e-10) {
395 double elementEdge = start - initialR(2) *
euclidean_norm(initialP) / initialP(2);
403 std::map<std::string, std::set<elementPosition, elementPositionComp> > tmpRegistry;
406 const std::string &
name = (*it).first;
409 auto prior = tmpRegistry.find(name);
410 if (prior == tmpRegistry.end()) {
411 std::set<elementPosition, elementPositionComp> tmpSet;
413 tmpRegistry.insert(std::make_pair(name, tmpSet));
417 std::set<elementPosition, elementPositionComp> &
set = (*prior).second;
424 for (; it !=
end; ++
it) {
425 std::string
name = (*it).getElement()->getName();
426 auto trit = tmpRegistry.find(name);
427 if (trit == tmpRegistry.end())
continue;
429 std::queue<std::pair<double, double> > range;
430 std::set<elementPosition, elementPositionComp> &
set = (*trit).second;
432 for (
auto sit = set.begin(); sit != set.end(); ++ sit) {
433 range.push(std::make_pair((*sit).elementEdge_m, (*sit).endField_m));
435 (*it).getElement()->setActionRange(range);
444 for (; it !=
end; ++
it) {
445 std::shared_ptr<Component> element = (*it).getElement();
446 if (visitedElements.find(element->getName()) == visitedElements.end() &&
450 element->setDesignEnergy(kineticEnergyeV);
460 for (; it !=
end; ++
it) {
464 BoundingBox other = it->getBoundingBoxInLabCoords();
486 return intersectionPoint ?
euclidean_norm(intersectionPoint.get() - position): 10.0;
ValueRange< long > stepRange_m
static OpalData * getInstance()
Tps< T > sqrt(const Tps< T > &x)
Square root.
constexpr double c
The velocity of light in m/s.
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
PETE_TBTree< FnCopysign, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > copysign(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
double pathLength_m
position of reference particle in path length
void processElementRegister()
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
BoundingBox globalBoundingBox_m
void autophaseCavities(const IndexMap::value_t &activeSet, const std::set< std::string > &visitedElements)
std::set< std::shared_ptr< Component > > value_t
void updateBoundingBoxWithCurrentPosition()
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)
ValueRange< double > getPathLengthRange() const
void enlargeToContainPosition(const Vector_t &position)
void computeBoundingBox()
CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr< Component > &comp) const
void push(Vector_t &R, const Vector_t &P, const double &dt) const
double getM() const
The constant mass per particle.
Inform & endl(Inform &inf)
virtual double getDesignEnergy() const override
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
std::multimap< std::string, elementPosition > elementRegistry_m
std::string::iterator iterator
T euclidean_norm(const Vector< T > &)
Euclidean norm.
void setDesignEnergy(FieldList &allElements, const std::set< std::string > &visitedElements)
bool isInside(T value) const
void enlargeToContainBoundingBox(const BoundingBox &boundingBox)
void tidyUp(double zstop)
The base class for all OPAL exceptions.
OpalBeamline & itsOpalBeamline_m
void checkElementLengths(const std::set< std::shared_ptr< Component >> &elements)
set(_SRCS Action.cpp Attribute.cpp AttributeBase.cpp AttributeHandler.cpp BeamSequence.cpp Definition.cpp Directory.cpp Element.cpp Invalidator.cpp OpalData.cpp Object.cpp ObjectFunction.cpp PlaceRep.cpp RangeRep.cpp Table.cpp TableRowRep.cpp ValueDefinition.cpp) include_directories($
unsigned long long getNumStepsFinestResolution() const
OrbitThreader(const PartData &ref, const Vector_t &r, const Vector_t &p, double s, double maxDiffZBunch, double t, double dT, StepSizeConfig stepSizes, OpalBeamline &bl)
double getGamma(Vector_t p)
boost::optional< Vector_t > getIntersectionPoint(const Vector_t &position, const Vector_t &direction) const
void saveSDDS(double startS) const
ValueRange< double > pathLengthRange_m
without end fields(Default:1 m)\item[ANGLE] Physical angle of the magnet(radians).If not specified
Vector_t rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
std::string combineFilePath(std::initializer_list< std::string > ilist)
FieldList getElementByType(ElementType)
double computeDriftLengthToBoundingBox(const std::set< std::shared_ptr< Component >> &elements, const Vector_t &position, const Vector_t &direction) const
StepSizeConfig stepSizes_m
final position in path length
double time_m
the simulated time
size_t loggingFrequency_m
double getPhaseAtMaxEnergy(const Vector_t &R, const Vector_t &P, double t, double dt)
std::list< ClassicField > FieldList
constexpr double e
The value of .
Vector_t p_m
momentum of reference particle
double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const
Vector_t r_m
position of reference particle in lab coordinates
void kick(const Vector_t &R, Vector_t &P, const Vector_t &Ef, const Vector_t &Bf, const double &dt) const
bool containsCavity(const IndexMap::value_t &activeSet)
Inform & level1(Inform &inf)
void integrate(const IndexMap::value_t &activeSet, double maxDrift=10.0)
void enlargeIfOutside(T value)
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
bool isOutside(T value) const
const PartData & reference_m
void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p)