38 #include <boost/filesystem.hpp>
44 #define HITMATERIAL 0x80000000
45 #define EOL 0x40000000
46 #define EVERYTHINGFINE 0x00000000
63 stepSizes_m(stepSizes),
64 zstop_m(stepSizes.getFinalZStop() +
std::
copysign(1.0, dt) * 2 * maxDiffZBunch),
65 itsOpalBeamline_m(bl),
73 opal->getAuxiliaryOutputDirectory(),
74 opal->getInputBasename() +
"_DesignPath.dat"
77 !boost::filesystem::exists(fileName)) {
80 << std::setw(17) <<
"1 - s"
81 << std::setw(18) <<
"2 - Rx"
82 << std::setw(18) <<
"3 - Ry"
83 << std::setw(18) <<
"4 - Rz"
84 << std::setw(18) <<
"5 - Px"
85 << std::setw(18) <<
"6 - Py"
86 << std::setw(18) <<
"7 - Pz"
87 << std::setw(18) <<
"8 - Efx"
88 << std::setw(18) <<
"9 - Efy"
89 << std::setw(18) <<
"10 - Efz"
90 << std::setw(18) <<
"11 - Bfx"
91 << std::setw(18) <<
"12 - Bfy"
92 << std::setw(18) <<
"13 - Bfz"
93 << std::setw(18) <<
"14 - Ekin"
94 << std::setw(18) <<
"15 - t"
97 logger_m.open(fileName, std::ios_base::app);
117 for (
const std::shared_ptr<Component>& field : fields) {
118 double length = field->getElementLength();
119 int numSteps = field->getRequiredNumberOfTimeSteps();
121 if (length < numSteps * driftLength) {
123 "The time step is too long compared to the length of the\n"
124 "element '" + field->getName() +
"'\n" +
125 "The length of the element is: " + std::to_string(length) +
"\n"
126 "The distance the particles drift in " + std::to_string(numSteps) +
127 " time step(s) is: " + std::to_string(numSteps * driftLength));
136 std::set<std::string> visitedElements;
171 IndexMap::value_t::const_iterator it = elementSet.begin();
172 const IndexMap::value_t::const_iterator
end = elementSet.end();
173 for (; it !=
end; ++ it) {
174 visitedElements.insert((*it)->getName());
197 static size_t step = 0;
204 IndexMap::value_t::const_iterator it = activeSet.begin();
205 const IndexMap::value_t::const_iterator
end = activeSet.end();
213 std::string names(
"\t");
214 for (; it !=
end; ++ it) {
219 if ((*it)->applyToReferenceParticle(localR, localP,
time_m + 0.5 *
dt_m, localE, localB)) {
223 names += (*it)->getName() +
", ";
234 << std::setw(18) << std::setprecision(8) <<
r_m(0)
235 << std::setw(18) << std::setprecision(8) <<
r_m(1)
236 << std::setw(18) << std::setprecision(8) <<
r_m(2)
237 << std::setw(18) << std::setprecision(8) <<
p_m(0)
238 << std::setw(18) << std::setprecision(8) <<
p_m(1)
239 << std::setw(18) << std::setprecision(8) <<
p_m(2)
240 << std::setw(18) << std::setprecision(8) << Ef(0)
241 << std::setw(18) << std::setprecision(8) << Ef(1)
242 << std::setw(18) << std::setprecision(8) << Ef(2)
243 << std::setw(18) << std::setprecision(8) << Bf(0)
244 << std::setw(18) << std::setprecision(8) << Bf(1)
245 << std::setw(18) << std::setprecision(8) << Bf(2)
247 << std::setw(18) << std::setprecision(8) << (
time_m + 0.5 *
dt_m) * 1e9
276 IndexMap::value_t::const_iterator it = activeSet.begin();
277 const IndexMap::value_t::const_iterator
end = activeSet.end();
279 for (; it !=
end; ++ it) {
290 const std::set<std::string> &visitedElements) {
293 IndexMap::value_t::const_iterator it = activeSet.begin();
294 const IndexMap::value_t::const_iterator
end = activeSet.end();
296 for (; it !=
end; ++ it) {
299 visitedElements.find((*it)->getName()) == visitedElements.end()) {
316 IndexMap::value_t::const_iterator it = elementSet.begin();
317 const IndexMap::value_t::const_iterator
end = elementSet.end();
319 double designEnergy = 0.0;
320 for (; it !=
end; ++ it) {
359 IndexMap::value_t::const_iterator it = elementSet.begin();
360 const IndexMap::value_t::const_iterator
end = elementSet.end();
362 for (; it !=
end; ++ it) {
364 std::string
name = (*it)->getName();
367 for (
auto pit = prior.first; pit != prior.second; ++ pit) {
368 if (
std::abs((*pit).second.endField_m - start) < 1
e-10) {
379 double elementEdge = start - initialR(2) *
euclidean_norm(initialP) / initialP(2);
387 std::map<std::string, std::set<elementPosition, elementPositionComp> > tmpRegistry;
390 const std::string &
name = (*it).first;
393 auto prior = tmpRegistry.find(
name);
394 if (prior == tmpRegistry.end()) {
395 std::set<elementPosition, elementPositionComp> tmpSet;
397 tmpRegistry.insert(std::make_pair(
name, tmpSet));
401 std::set<elementPosition, elementPositionComp> &set = (*prior).second;
408 for (; it !=
end; ++ it) {
409 std::string
name = (*it).getElement()->getName();
410 auto trit = tmpRegistry.find(
name);
411 if (trit == tmpRegistry.end())
continue;
413 std::queue<std::pair<double, double> > range;
414 std::set<elementPosition, elementPositionComp> &set = (*trit).second;
416 for (
auto sit = set.begin(); sit != set.end(); ++ sit) {
417 range.push(std::make_pair((*sit).elementEdge_m, (*sit).endField_m));
419 (*it).getElement()->setActionRange(range);
428 for (; it !=
end; ++ it) {
429 std::shared_ptr<Component> element = (*it).getElement();
430 if (visitedElements.find(element->getName()) == visitedElements.end() &&
434 element->setDesignEnergy(kineticEnergyeV);
447 for (; it !=
end; ++ it) {
469 (
elements.size() == 1 && (*
elements.begin())->getType() == ElementBase::ElementType::DRIFT)) {
471 return intersectionPoint ?
euclidean_norm(intersectionPoint.get() - position): 10.0;
Tps< T > sqrt(const Tps< T > &x)
Square root.
T euclidean_norm(const Vector< T > &)
Euclidean norm.
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
std::list< ClassicField > FieldList
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
PETE_TBTree< FnCopysign, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > copysign(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Inform & level1(Inform &inf)
Inform & endl(Inform &inf)
constexpr double e
The value of.
constexpr double c
The velocity of light in m/s.
std::string::iterator iterator
std::string combineFilePath(std::initializer_list< std::string > ilist)
double getGamma(Vector_t p)
static OpalData * getInstance()
double getPhaseAtMaxEnergy(const Vector_t &R, const Vector_t &P, double t, double dt)
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
void tidyUp(double zstop)
std::set< std::shared_ptr< Component > > value_t
void saveSDDS(double startS) const
void processElementRegister()
void updateBoundingBoxWithCurrentPosition()
void setDesignEnergy(FieldList &allElements, const std::set< std::string > &visitedElements)
double time_m
the simulated time
OpalBeamline & itsOpalBeamline_m
std::multimap< std::string, elementPosition > elementRegistry_m
Vector_t r_m
position of reference particle in lab coordinates
const PartData & reference_m
Vector_t p_m
momentum of reference particle
bool containsCavity(const IndexMap::value_t &activeSet)
void integrate(const IndexMap::value_t &activeSet, double maxDrift=10.0)
OrbitThreader(const PartData &ref, const Vector_t &r, const Vector_t &p, double s, double maxDiffZBunch, double t, double dT, StepSizeConfig stepSizes, OpalBeamline &bl)
StepSizeConfig stepSizes_m
final position in path length
ElementBase::BoundingBox globalBoundingBox_m
double computeDriftLengthToBoundingBox(const std::set< std::shared_ptr< Component >> &elements, const Vector_t &position, const Vector_t &direction) const
void checkElementLengths(const std::set< std::shared_ptr< Component >> &elements)
double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const
void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p)
double pathLength_m
position of reference particle in path length
void autophaseCavities(const IndexMap::value_t &activeSet, const std::set< std::string > &visitedElements)
void computeBoundingBox()
size_t loggingFrequency_m
Vector_t upperRightCorner
static BoundingBox getBoundingBox(const std::vector< Vector_t > &points)
void getCombinedBoundingBox(const BoundingBox &other)
boost::optional< Vector_t > getPointOfIntersection(const Vector_t &position, const Vector_t &direction) const
virtual double getDesignEnergy() const override
double getM() const
The constant mass per particle.
FieldList getElementByType(ElementBase::ElementType)
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Vector_t rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr< Component > &comp) const
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
void kick(const Vector_t &R, Vector_t &P, const Vector_t &Ef, const Vector_t &Bf, const double &dt) const
void push(Vector_t &R, const Vector_t &P, const double &dt) const
The base class for all OPAL exceptions.
Vektor< double, 3 > Vector_t