OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalBeamline.h
Go to the documentation of this file.
1//
2// Class OpalBeamline
3// :FIXME: add class description
4//
5// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef OPAL_BEAMLINE_H
19#define OPAL_BEAMLINE_H
20
21#include <map>
22#include <memory>
23#include <set>
24#include <string>
25
27#include "PartBunch/PartBunch.h"
28
29#include "AbsBeamline/Marker.h"
31#include "Beamlines/Beamline.h"
33
35
36#include "OPALTypes.h"
37
38class ParticleMatterInteractionHandler;
40
42public:
44 OpalBeamline(const Vector_t<double, 3>& origin, const Quaternion& rotation);
46
47 void activateElements();
48 std::set<std::shared_ptr<Component>> getElements(const Vector_t<double, 3>& x);
49
54 std::set<std::shared_ptr<Component>> getElements();
55
60
62 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const;
64 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const;
66 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const;
68 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const;
69
77 PlacedElement getPlacedElement(const std::shared_ptr<Component>& comp) const;
78
87 CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr<Component>& comp) const;
89 CoordinateSystemTrafo getMisalignment(const std::shared_ptr<Component>& comp) const;
90 CoordinateSystemTrafo getNominalEntryTransform(const std::shared_ptr<Component>& comp) const;
91 CoordinateSystemTrafo getNominalExitTransform(const std::shared_ptr<Component>& comp) const;
92
93 double getStart(const Vector_t<double, 3>&) const;
94 double getEnd(const Vector_t<double, 3>&) const;
95
96 void switchElements(
97 const double&, const double&, const double& kineticEnergy,
98 const bool& nomonitors = false);
99 void switchElementsOff();
100
101 ParticleMatterInteractionHandler* getParticleMatterInteractionHandler(const unsigned int&);
102
104
105 unsigned long getFieldAt(
106 const unsigned int&, const Vector_t<double, 3>&, const long&, const double&,
108 unsigned long getFieldAt(
109 const Vector_t<double, 3>&, const Vector_t<double, 3>&, const double&,
111
112 template <class T>
113 void visit(const T&, BeamlineVisitor&, PartBunch_t&);
114
115 void prepareSections();
116 void positionElementRelative(std::shared_ptr<ElementBase>);
117 void compute3DLattice();
118 void save3DLattice();
119 void save3DInput();
120 void print(Inform&) const;
121 void apply(
122 const Vector_t<double, 3>& R, const Vector_t<double, 3>& /*P*/, const double& t,
124
126
127 void swap(OpalBeamline& rhs);
128 void merge(OpalBeamline& rhs);
129
130private:
131 using PlacementAssembly = std::map<const ElementBase*, PlacedElement>;
132
142 const std::shared_ptr<ElementBase>& element, const CoordinateSystemTrafo& parentToBody);
143
152 void storePlacedElement(const std::shared_ptr<ElementBase>& element);
153
164
169
171};
172
173template <class T>
174inline void OpalBeamline::visit(const T& element, BeamlineVisitor&, PartBunch_t& bunch) {
175 Inform msg("OPAL ");
176 double startField = 0.0;
177 double endField = 0.0;
178 std::shared_ptr<T> elptr(dynamic_cast<T*>(element.clone()));
179
181
182 if (elptr->isElementPositionSet()) startField = elptr->getElementPosition();
183
184 elptr->initialise(&bunch, startField, endField);
185 elements_m.push_back(BeamlineFieldElement(elptr, startField, endField));
186 placementAssembly_m.insert_or_assign(elptr.get(), elptr->getPlacedElement());
187 prepared_m = false;
189}
190
191template <>
192inline void OpalBeamline::visit<Marker>(const Marker& /*element*/, BeamlineVisitor&, PartBunch_t&) {
193}
194
198
202
206
210
212 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const {
214}
215
217 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const {
219}
220
222 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const {
224}
225
227 const std::shared_ptr<Component>& comp, const Vector_t<double, 3>& r) const {
229}
230
231inline PlacedElement OpalBeamline::getPlacedElement(const std::shared_ptr<Component>& comp) const {
232 const auto found = placementAssembly_m.find(comp.get());
233 if (found != placementAssembly_m.end()) {
234 return found->second;
235 }
236 return comp->getPlacedElement();
237}
238
240 const std::shared_ptr<Component>& comp) const {
242}
243
247
249 const std::shared_ptr<Component>& comp) const {
251}
252
254 const std::shared_ptr<Component>& comp) const {
256}
257
259 const std::shared_ptr<Component>& comp) const {
261}
262
263#endif // OPAL_BEAMLINE_H
std::list< BeamlineFieldElement > FieldList
Defines the abstract interface for a single beamline component in the accelerator model.
ippl::Vector< T, Dim > Vector_t
ElementType
Definition ElementBase.h:94
double T
Definition OPALTypes.h:8
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
Beamline component together with its active longitudinal field interval.
Rigid spatial transform between a parent frame and a local frame.
ippl::Vector< double, 3 > transformFrom(const ippl::Vector< double, 3 > &r) const
Map a point from the local frame back to the parent frame.
ippl::Vector< double, 3 > rotateFrom(const ippl::Vector< double, 3 > &r) const
Rotate a vector from the local frame back into the parent frame.
ippl::Vector< double, 3 > rotateTo(const ippl::Vector< double, 3 > &r) const
Rotate a vector from the parent frame into the local frame.
ippl::Vector< double, 3 > transformTo(const ippl::Vector< double, 3 > &r) const
Map a point from the parent frame to the local frame.
Interface for a marker.
Definition Marker.h:31
const CoordinateSystemTrafo & getNominalToActual() const
FieldList getElementByType(ElementType)
Vector_t< double, 3 > rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t< double, 3 > &r) const
void positionElementRelative(std::shared_ptr< ElementBase >)
CoordinateSystemTrafo getMisalignment(const std::shared_ptr< Component > &comp) const
void merge(OpalBeamline &rhs)
bool compatibilityPlacementCompiled_m
ParticleMatterInteractionHandler * getParticleMatterInteractionHandler(const unsigned int &)
unsigned long getFieldAt(const unsigned int &, const Vector_t< double, 3 > &, const long &, const double &, Vector_t< double, 3 > &, Vector_t< double, 3 > &)
std::map< const ElementBase *, PlacedElement > PlacementAssembly
Vector_t< double, 3 > transformTo(const Vector_t< double, 3 > &r) const
Vector_t< double, 3 > transformFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t< double, 3 > &r) const
CoordinateSystemTrafo getNominalExitTransform(const std::shared_ptr< Component > &comp) const
CoordinateSystemTrafo coordTransformationTo_m
CoordinateSystemTrafo getNominalEntryTransform(const std::shared_ptr< Component > &comp) const
PlacedElement getPlacedElement(const std::shared_ptr< Component > &comp) const
Return the placed-element view used by the bridge stage.
double getEnd(const Vector_t< double, 3 > &) const
Vector_t< double, 3 > rotateTo(const Vector_t< double, 3 > &r) const
void prepareSections()
void print(Inform &) const
void compute3DLattice()
Vector_t< double, 3 > transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t< double, 3 > &r) const
void setNominalPlacement(const std::shared_ptr< ElementBase > &element, const CoordinateSystemTrafo &parentToBody)
Update the nominal rigid placement transform of one element.
void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors=false)
void compileCompatibilityPlacement()
Compile legacy reference-order placement into explicit nominal poses.
void switchElementsOff()
void storePlacedElement(const std::shared_ptr< ElementBase > &element)
Refresh the beamline-owned placed-element assembly record.
void apply(const Vector_t< double, 3 > &R, const Vector_t< double, 3 > &, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B)
Vector_t< double, 3 > transformFrom(const Vector_t< double, 3 > &r) const
FieldList elements_m
double getStart(const Vector_t< double, 3 > &) const
CoordinateSystemTrafo getCSTrafoLab2Local() const
void visit(const T &, BeamlineVisitor &, PartBunch_t &)
BoundaryGeometry * getBoundaryGeometry(const unsigned int &)
Vector_t< double, 3 > rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t< double, 3 > &r) const
Vector_t< double, 3 > rotateFrom(const Vector_t< double, 3 > &r) const
void activateElements()
PlacementAssembly placementAssembly_m
std::set< std::shared_ptr< Component > > getElements()
void swap(OpalBeamline &rhs)
Geometric placement record for an element instance.
const Misalignment & getMisalignment() const
CoordinateSystemTrafo getNominalEntryTransform() const
CoordinateSystemTrafo getNominalExitTransform() const
CoordinateSystemTrafo getNominalBodyTransform() const
Quaternion storage and rotation algebra used by OPALX geometry code.