34#include <boost/assign.hpp>
35#include <boost/filesystem.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>
63 pressure_m(right.pressure_m),
64 pmapfn_m(right.pmapfn_m),
65 pscale_m(right.pscale_m),
66 temperature_m(right.temperature_m),
120 "Residual gas not set");
133 "Pressure must be positive");
154 "PScale must be positive");
167 "Temperature must be positive");
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 (boost::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;
311 const int ir = (
int)xir;
313 const double wr1 = xir - (double)ir;
315 const double wr2 = 1.0 - wr1;
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;
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);
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");
374 for (
int i = 0; i < nrad_m; i++) {
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;
408 *
gmsg <<
"* --- Stepsize in azimuthal direction: " <<
PP_m.
dtet_m <<
" [deg]" <<
endl;
420 *
gmsg <<
"* --- Adding a guard cell along azimuth" <<
endl;
437#undef CHECK_VAC_FSCANF_EOF
#define CHECK_VAC_FSCANF_EOF(arg)
Tps< T > sqrt(const Tps< T > &x)
Square root.
T euclidean_norm(const Vector< T > &)
Euclidean norm.
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
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.
T rad(T x)
Convert degrees to radians.
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.
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)
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