42#define CHECK_VAC_FSCANF_EOF(arg) if (arg == EOF)\
43throw GeneralClassicException("Vacuum::getPressureFromFile",\
44 "fscanf returned EOF at " #arg);
55 pressure_m(right.pressure_m),
56 pmapfn_m(right.pmapfn_m),
57 pscale_m(right.pscale_m),
58 temperature_m(right.temperature_m),
91constexpr std::array<std::pair<ResidualGas, std::string_view>, 2>
residualGasMap {{
107 "Residual gas not set");
122 "Pressure must be positive");
143 "PScale must be positive");
156 "Temperature must be positive");
171 double rpos = std::sqrt(R(0) * R(0) + R(1) * R(1));
192 bool flagNeedUpdate =
false;
196 std::pair<Vector_t, double> boundingSphere;
197 boundingSphere.first = 0.5 * (rmax + rmin);
198 boundingSphere.second =
euclidean_norm(rmax - boundingSphere.first);
206 for (
unsigned int i = 0; i < tempnum; ++i) {
208 if ( (pflag != 0) && (bunch->
Bin[i] != -1) )
209 flagNeedUpdate =
true;
219 return flagNeedUpdate;
241 if (std::filesystem::exists(
pmapfn_m)) {
267 <<
": " <<
getName() <<
" -> Residual gas = "
270 <<
": " <<
getName() <<
" -> Pressure level = "
289 const double x = R(0);
290 const double y = R(1);
291 double pressure = 0.0;
296 const double rad = std::sqrt(x * x + y * y);
300 const int ir = (int)xir;
302 const double wr1 = xir - (double)ir;
304 const double wr2 = 1.0 - wr1;
306 const double tempv = std::atan(y / x);
308 if ((x < 0) && (y >= 0)) tet =
Physics::pi + tempv;
309 else if ((x < 0) && (y <= 0)) tet =
Physics::pi + tempv;
311 else if ((x == 0) && (y > 0)) tet =
Physics::pi / 2.0;
312 else if ((x == 0) && (y < 0)) tet = 1.5 *
Physics::pi;
321 const double wt1 = xit - (double)it;
322 const double wt2 = 1.0 - wt1;
326 double epsilon = 0.06;
327 if (tet > 360 - epsilon && tet < 360 + epsilon) it = 0;
329 int r1t1, r2t1, r1t2, r2t2;
334 r2t1 =
idx(ir + 1, it);
335 r1t2 =
idx(ir, it + 1);
336 r2t2 =
idx(ir + 1, it + 1);
343 if (pressure <= 0.0) {
349 *
gmsg <<
level4 <<
getName() <<
": Particle out of maximum radial position of pressure field map." <<
endl;
354 "Pressure data not found");
363 for (
int i = 0; i < nrad_m; i++) {
373 *
gmsg <<
"* Reading pressure field map " <<
endl;
377 if ((f = std::fopen(
pmapfn_m.c_str(),
"r")) ==
nullptr) {
379 "failed to open file '" +
pmapfn_m +
380 "', please check if it exists");
384 *
gmsg <<
"* --- Minimal radius of measured pressure map: " <<
PP_m.
rmin_m <<
" [mm]" <<
endl;
397 *
gmsg <<
"* --- Stepsize in azimuthal direction: " <<
PP_m.
dtet_m <<
" [deg]" <<
endl;
409 *
gmsg <<
"* --- Adding a guard cell along azimuth" <<
endl;
426#undef CHECK_VAC_FSCANF_EOF
#define CHECK_VAC_FSCANF_EOF(arg)
constexpr std::array< std::pair< ResidualGas, std::string_view >, 2 > residualGasMap
T euclidean_norm(const Vector< T > &)
Euclidean norm.
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
Inform & level2(Inform &inf)
Inform & level4(Inform &inf)
Inform & endl(Inform &inf)
constexpr double two_pi
The value of.
constexpr double q_e
The elementary charge in As.
constexpr double pi
The value of.
constexpr Enum stringToEnum(std::string_view str, const std::array< std::pair< Enum, std::string_view >, N > &map, Enum defaultEnum) noexcept
constexpr std::string_view enumToString(Enum e, const std::array< std::pair< Enum, std::string_view >, N > &map, std::string_view defaultStr) noexcept
ParticleAttrib< int > Bin
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
double getQ() const
Access to reference data.
size_t getLocalNum() const
ParticleAttrib< double > M
ParticleAttrib< double > Q
static OpalData * getInstance()
virtual void visitVacuum(const Vacuum &)=0
Apply the algorithm to a vacuum space.
Interface for a single beam element.
PartBunchBase< double, 3 > * RefPartBunch_m
virtual double getMaxR() const
virtual double getMaxZ() const
virtual double getMinZ() const
virtual double getMinR() const
virtual const std::string & getName() const
Get element name.
virtual ParticleMatterInteractionHandler * getParticleMatterInteraction() const
virtual double getElementLength() const
Get design length.
std::string getTypeString() const
std::vector< double > pfld_m
std::vector< double > rarr_m
double minr_m
Flag if particles should be stripped or stopped.
double pressure_m
Type of gas for residual vacuum.
ResidualGas getResidualGas() const noexcept
void setPScale(double ps)
double pscale_m
stores the filename of the pressure map
void setResidualGas(std::string_view gas) noexcept
virtual void goOffline() override
double getPressure() const
std::string getPressureMapFN() const
virtual void getDimensions(double &zBegin, double &zEnd) const override
void initR(double rmin, double dr, int nrad)
void setTemperature(double temperature)
virtual void goOnline(const double &kineticEnergy) override
int idx(int irad, int ktet)
double temperature_m
a scale factor for the P-field
virtual ElementType getType() const override
Get element type std::string.
void getPressureFromFile()
void setPressureMapFN(std::string pmapfn)
double checkPressure(const Vector_t &R)
virtual void finalise() override
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Vacuum.
void setPressure(double pressure)
std::string getResidualGasName() const
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
void updateParticleAttributes()
virtual bool checkVacuum(PartBunchBase< double, 3 > *bunch, Cyclotron *cycl)
ParticleMatterInteractionHandler * parmatint_m
mm
double getTemperature() const
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
bool checkPoint(const Vector_t &R)
ResidualGas gas_m
parameters for Vacuum
void setStop(bool stopflag)
virtual void print(Inform &os)=0
ElementBase * getElement()
virtual void apply(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere)=0