34#include <boost/assign.hpp>
42#define CHECK_VAC_FSCANF_EOF(arg) if (arg == EOF)\
43throw GeneralClassicException("Vacuum::getPressureFromFile",\
44 "fscanf returned EOF at " #arg);
49 boost::assign::list_of<const boost::bimap<ResidualGas, std::string>::relation>
120 "Residual gas not set");
133 "Pressure must be positive");
154 "PScale must be positive");
167 "Temperature must be positive");
182 double rpos = std::sqrt(R(0) * R(0) + R(1) * R(1));
203 bool flagNeedUpdate =
false;
207 std::pair<Vector_t, double> boundingSphere;
208 boundingSphere.first = 0.5 * (rmax + rmin);
209 boundingSphere.second =
euclidean_norm(rmax - boundingSphere.first);
217 for (
unsigned int i = 0; i < tempnum; ++i) {
219 if ( (pflag != 0) && (bunch->
Bin[i] != -1) )
220 flagNeedUpdate =
true;
230 return flagNeedUpdate;
252 if (std::filesystem::exists(
pmapfn_m)) {
278 <<
": " <<
getName() <<
" -> Residual gas = "
281 <<
": " <<
getName() <<
" -> Pressure level = "
300 const double x = R(0);
301 const double y = R(1);
302 double pressure = 0.0;
307 const double rad = std::sqrt(x * x + y * y);
308 const double xir = (rad -
PP_m.rmin_m) /
PP_m.delr_m;
311 const int ir = (int)xir;
313 const double wr1 = xir - (double)ir;
315 const double wr2 = 1.0 - wr1;
317 const double tempv = std::atan(y / x);
319 if ((x < 0) && (y >= 0)) tet =
Physics::pi + tempv;
320 else if ((x < 0) && (y <= 0)) tet =
Physics::pi + tempv;
322 else if ((x == 0) && (y > 0)) tet =
Physics::pi / 2.0;
323 else if ((x == 0) && (y < 0)) tet = 1.5 *
Physics::pi;
330 double xit = tet /
PP_m.dtet_m;
332 const double wt1 = xit - (double)it;
333 const double wt2 = 1.0 - wt1;
337 double epsilon = 0.06;
338 if (tet > 360 - epsilon && tet < 360 + epsilon) it = 0;
340 int r1t1, r2t1, r1t2, r2t2;
345 r2t1 =
idx(ir + 1, it);
346 r1t2 =
idx(ir, it + 1);
347 r2t2 =
idx(ir + 1, it + 1);
349 if ((it >= 0) && (ir >= 0) && (it <
PField_m.ntetS_m) && (ir <
PField_m.nrad_m)) {
350 pressure = (
PField_m.pfld_m[r1t1] * wr2 * wt2 +
354 if (pressure <= 0.0) {
360 *
gmsg <<
level4 <<
getName() <<
": Particle out of maximum radial position of pressure field map." <<
endl;
365 "Pressure data not found");
373 PP_m.rarr_m.resize(nrad_m);
374 for (
int i = 0; i < nrad_m; i++) {
375 PP_m.rarr_m[i] = rmin_m + i * dr;
384 *
gmsg <<
"* Reading pressure field map " <<
endl;
388 if ((f = std::fopen(
pmapfn_m.c_str(),
"r")) ==
nullptr) {
390 "failed to open file '" +
pmapfn_m +
391 "', please check if it exists");
395 *
gmsg <<
"* --- Minimal radius of measured pressure map: " <<
PP_m.rmin_m <<
" [mm]" <<
endl;
399 if (
PP_m.delr_m < 0.0)
PP_m.delr_m = 1.0 / (-
PP_m.delr_m);
400 *
gmsg <<
"* --- Stepsize in radial direction: " <<
PP_m.delr_m <<
" [mm]" <<
endl;
403 *
gmsg <<
"* --- Minimal angle of measured pressure map: " <<
PP_m.tetmin_m <<
" [deg]" <<
endl;
407 if (
PP_m.dtet_m < 0.0)
PP_m.dtet_m = 1.0 / (-
PP_m.dtet_m);
408 *
gmsg <<
"* --- Stepsize in azimuthal direction: " <<
PP_m.dtet_m <<
" [deg]" <<
endl;
411 *
gmsg <<
"* --- Grid points along azimuth (ntet_m): " <<
PField_m.ntet_m <<
endl;
414 *
gmsg <<
"* --- Grid points along radius (nrad_m): " <<
PField_m.nrad_m <<
endl;
420 *
gmsg <<
"* --- Adding a guard cell along azimuth" <<
endl;
424 *
gmsg <<
"* --- Total stored grid point number ((ntet_m+1) * nrad_m) : " <<
PField_m.ntot_m <<
endl;
425 *
gmsg <<
"* --- Escale factor: " <<
PP_m.Pfact_m <<
endl;
427 for (
int i = 0; i <
PField_m.nrad_m; i++) {
428 for (
int k = 0; k <
PField_m.ntet_m; k++) {
437#undef CHECK_VAC_FSCANF_EOF
#define CHECK_VAC_FSCANF_EOF(arg)
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.
ParticleAttrib< int > Bin
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
size_t getLocalNum() const
static OpalData * getInstance()
virtual void visitVacuum(const Vacuum &)=0
Apply the algorithm to a vacuum space.
Component(const std::string &name)
Constructor with given name.
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.
double minr_m
Flag if particles should be stripped or stopped.
double pressure_m
Type of gas for residual vacuum.
void setPScale(double ps)
double pscale_m
stores the filename of the pressure map
virtual void goOffline() override
static const boost::bimap< ResidualGas, std::string > bmResidualGasString_s
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.
ResidualGas getResidualGas() const
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)
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
void setResidualGas(std::string gas)
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
std::string getResidualGasName()
bool checkPoint(const Vector_t &R)
Vacuum(const std::string &name)
Constructor with given name.
ResidualGas gas_m
parameters for Vacuum
void setStop(bool stopflag)
Vektor< double, 3 > Vector_t