56 #include <boost/algorithm/string.hpp>
57 #include <boost/regex.hpp>
58 #include <boost/filesystem.hpp>
65 using namespace Physics;
93 "The \"RUN\" sub-command tracks the defined particles through "
94 "the given lattice."),
99 phaseSpaceSink_m(NULL) {
101 (
"METHOD",
"Name of tracking algorithm to use:\n"
102 "\t\t\t\"THIN\" (default) or \"THICK, OPAL-T,OPAL-T3D, OPAL-CYCL\".",
"THIN");
104 (
"TURNS",
"Number of turns to be tracked; Number of neighboring bunches to be tracked in cyclotron", 1.0);
107 (
"MBMODE",
"The working way for multi-bunch mode for OPAL-cycl: FORCE or AUTO ",
"FORCE");
110 (
"PARAMB",
"Control parameter to define when to start multi-bunch mode, only available in \"AUTO\" mode ", 5.0);
113 "The scale parameter for binning in multi-bunch mode",
117 (
"MB_BINNING",
"Type of energy binning in multi-bunch mode: GAMMA or BUNCH",
"GAMMA");
120 (
"BEAM",
"Name of beam ",
"BEAM");
122 (
"FIELDSOLVER",
"Field solver to be used ",
"FIELDSOLVER");
124 (
"BOUNDARYGEOMETRY",
"Boundary geometry to be used NONE (default)",
"NONE");
126 (
"DISTRIBUTION",
"List of particle distributions to be used ");
128 (
"MULTIPACTING",
"Multipacting flag, default: false. Set true to initialize primary particles according to BoundaryGeometry",
false);
130 (
"TRACKBACK",
"Track in reverse direction, default: false",
false);
143 phaseSpaceSink_m(NULL) {
163 bool newerChanges =
false;
165 if (it->first > fileVersion) {
172 errorMsg <<
"\n******************** V E R S I O N M I S M A T C H ***********************\n" <<
endl;
174 if (it->first > fileVersion) {
175 errorMsg << it->second <<
endl;
179 <<
"* Make sure you do understand these changes and adjust your input file \n"
180 <<
"* accordingly. Then add\n"
181 <<
"* OPTION, VERSION = " << currentVersion <<
";\n"
182 <<
"* to your input file. " <<
endl;
183 errorMsg <<
"\n****************************************************************************\n" <<
endl;
184 throw OpalException(
"TrackRun::execute",
"Version mismatch");
190 if(method ==
"THIN") {
191 *gmsg <<
" Method == \"THIN\"" <<
endl;
195 }
else if(method ==
"THICK") {
197 }
else if(method ==
"PARALLEL-SLICE" || method ==
"OPAL-E") {
199 }
else if(method ==
"PARALLEL-T" || method ==
"OPAL-T") {
201 }
else if(method ==
"CYCLOTRON-T" || method ==
"OPAL-CYCL") {
205 "Method name \"" + method +
"\" unknown.");
208 if(method ==
"THIN" || method ==
"THICK") {
212 for(
int turn = 1; turn < turns; ++turn) {
226 if(method ==
"PARALLEL-SLICE")
237 *gmsg <<
"* ********************************************************************************** " <<
endl;
238 *gmsg <<
"* Selected Tracking Method == PARALLEL-SLICE, NEW TRACK" <<
endl;
239 *gmsg <<
"* ********************************************************************************** " <<
endl;
240 }
else if(isFollowupTrack) {
241 *gmsg <<
"* ********************************************************************************** " <<
endl;
242 *gmsg <<
"* Selected Tracking Method == PARALLEL-SLICE, FOLLOWUP TRACK" <<
endl;
243 *gmsg <<
"* ********************************************************************************** " <<
endl;
254 }
else if (isFollowupTrack) {
265 const size_t numberOfDistributions = distr_str.size();
266 if (numberOfDistributions == 0) {
326 while (i + 1 < zstop.size() && zstop[i + 1] < spos) {
338 *gmsg << *beam <<
endl;
364 if(isFollowupTrack) {
365 *gmsg <<
"* ********************************************************************************** " <<
endl;
366 *gmsg <<
"* Selected Tracking Method == THICK, FOLLOWUP TRACK" <<
endl;
367 *gmsg <<
"* ********************************************************************************** " <<
endl;
370 *gmsg <<
"* ********************************************************************************** " <<
endl;
371 *gmsg <<
"* Selected Tracking Method == THICK, NEW TRACK" <<
endl;
372 *gmsg <<
"* ********************************************************************************** " <<
endl;
393 }
else if (isFollowupTrack) {
436 while (i + 1 < zstop.size() && zstop[i + 1] < spos) {
440 zstop.erase(zstop.begin(), zstop.begin() + i);
441 timeStep.erase(timeStep.begin(), timeStep.begin() + i);
442 dT.erase(dT.begin(), dT.begin() + i);
449 *gmsg << *beam <<
endl;
467 if(isFollowupTrack) {
468 *gmsg <<
"* ********************************************************************************** " <<
endl;
469 *gmsg <<
"* Selected Tracking Method == PARALLEL-T, FOLLOWUP TRACK" <<
endl;
470 *gmsg <<
"* ********************************************************************************** " <<
endl;
473 *gmsg <<
"* ********************************************************************************** " <<
endl;
474 *gmsg <<
"* Selected Tracking Method == PARALLEL-T, NEW TRACK" <<
endl;
475 *gmsg <<
"* ********************************************************************************** " <<
endl;
498 }
else if (isFollowupTrack) {
541 *gmsg << std::scientific;
544 *gmsg <<
"* Multipacting flag is true. The particle distribution in the run command will be ignored " <<
endl;
554 while (i + 1 < zstop.size() && zstop[i + 1] < spos) {
564 *gmsg << *beam <<
endl;
611 if (distr_str.size() == 0) {
618 double macromass = 0.0;
619 double macrocharge = 0.0;
682 *gmsg <<
"* Mass of simulation particle= " << macromass <<
" GeV/c^2" <<
endl;
683 *gmsg <<
"* Charge of simulation particle= " << macrocharge <<
" [C]" <<
endl;
698 *gmsg <<
"* ********************************************************************************** " <<
endl;
699 *gmsg <<
"* Selected Tracking Method == CYCLOTRON-T, NEW TRACK" <<
endl;
700 *gmsg <<
"* ********************************************************************************** " <<
endl;
702 *gmsg <<
"* ********************************************************************************** " <<
endl;
703 *gmsg <<
"* Selected Tracking Method == CYCLOTRON-T, FOLLOWUP TRACK" <<
endl;
704 *gmsg <<
"* ********************************************************************************** " <<
endl;
706 *gmsg <<
"* Number of neighbour bunches= " << specifiedNumBunch <<
endl;
711 *gmsg <<
"* ********************************************************************************** " <<
endl;
717 specifiedNumBunch, mbEta, mbPara, mbMode, mbBinning);
739 if ( specifiedNumBunch > 1 ) {
748 *gmsg << *beam <<
endl;
770 "The number of simulation particles (" + std::to_string(numParticles) +
") \n" +
771 "is smaller than the number of gridpoints (" + std::to_string(numGridPoints) +
").\n" +
772 "Please increase the number of particles or reduce the size of the mesh.\n");
816 std::vector<std::string> distributionArray
818 const size_t numberOfDistributions = distributionArray.size();
820 if (numberOfDistributions == 0) {
826 if (numberOfDistributions > 1) {
828 <<
"---------------------------------" <<
endl
829 <<
"Found more than one distribution:" <<
endl <<
endl;
830 *gmsg <<
"Main Distribution" << endl
831 <<
"---------------------------------" << endl
832 << distributionArray.at(0) << endl << endl
833 <<
"Secondary Distribution(s)" << endl
834 <<
"---------------------------------" <<
endl;
836 for (
size_t i = 1; i < numberOfDistributions; ++ i) {
841 *gmsg << distributionArray.at(i) <<
endl;
844 <<
"---------------------------------" << endl <<
endl;
std::vector< double > zstop
The location at which the simulation stops.
void doRestartOpalCycl(PartBunchBase< double, 3 > *p, size_t Np, int restartStep, const int specifiedNumBunch, H5PartWrapper *h5wrapper)
double Round(double value)
Round the double argument.
std::string getRestartFileName()
get opals restart h5 format filename
double zstart
The location at which the simulation starts.
double getAzimuth() const
static FieldSolver * find(const std::string &name)
Find named FieldSolver.
double setDistributionParallelT(Beam *beam)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
void doRestartOpalE(EnvelopeBunch *p, size_t Np, int restartStep, H5PartWrapper *h5wrapper)
double getReferenceR() const
std::vector< Distribution * > distrs_m
double getMT() const
Return meshsize.
core of the envelope tracker based on Rene Bakkers BET implementation
double getMass() const
Return Particle's rest mass in GeV.
void setRestartRun(const bool &value=true)
set OPAL in restart mode
The base class for all OPAL actions.
void createOpalCycl(PartBunchBase< double, 3 > *beam, size_t numberOfParticles, double current, const Beamline &bl)
int timeIntegrator
The ID of time integrator.
std::vector< double > dT
The initial timestep.
void setCharge(double _Q)
set the charge of the bunch
The base class for all OPAL exceptions.
bool inRestartRun()
true if we do a restart run
void setDistribution(Distribution *d, std::vector< Distribution * > addedDistributions, size_t &np)
void changeH5Wrapper(H5PartWrapper *h5wrapper)
double getCurrent() const
Return the beam current in A.
double getReferencePz() const
bool hasSLBunchAllocated()
true if we already allocated a ParticleBunch object
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
std::string toUpper(const std::string &str)
int getRestartStep()
get the step where to restart
double getEmissionTimeShift() const
static Distribution * find(const std::string &name)
double getReferencePr() const
void setLocalTrackStep(long long n)
step in a TRACK command
TrackRun()
Exemplar constructor.
bool getPreviousH5Local() const
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
#define OPAL_VERSION_MINOR
double getMY() const
Return meshsize.
void setDataSink(DataSink *s)
int statDumpFreq
The frequency to dump statistical values, e.e. dump data when stepstatDumpFreq==0.
virtual void setBCAllOpen()
std::vector< unsigned long long > localTimeSteps
Maximal number of timesteps.
double getReferencePt() const
bool getBool(const Attribute &attr)
Return logical value.
Inform & level2(Inform &inf)
size_t getNumberOfParticles()
Return the number of (macro)particles.
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
static OpalData * getInstance()
const std::string & getOpalName() const
Return object name.
double getCharge() const
Return the charge number in elementary charge.
void setCouplingConstant(double c)
void calcBeamParameters()
double getReferenceT() const
virtual TrackRun * clone(const std::string &name)
Make clone.
int version
opal version of input file
ParticleAttrib< short > PType
void setGlobalGeometry(BoundaryGeometry *bg)
bool hasBunchAllocated()
true if we already allocated a ParticleBunch object
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
void initDataSink(const int &numBunch=1)
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
static Beam * find(const std::string &name)
Find named BEAM.
double getFrequency() const
Return the beam frequency in MHz.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
static BoundaryGeometry * find(const std::string &name)
virtual Beamline * fetchLine() const =0
Return the embedded CLASSIC beam line.
void setStepsPerTurn(int n)
static Track * block
The block of track data.
H5PartWrapper * phaseSpaceSink_m
std::string getInputFn()
get opals input filename
std::map< unsigned int, std::string > changes
void setMass(double mass)
int truncOrder
Trunction order for map tracking.
PartBunchBase< double, 3 > * bunch
The particle bunch to be tracked.
virtual void execute()
Apply the algorithm to the top-level beamline.
int psDumpFreq
The frequency to dump the phase space, i.e.dump data when steppsDumpFreq==0.
BeamSequence * use
The lattice to be tracked through.
#define OPAL_VERSION_MAJOR
Track using thick-lens algorithm.
double getMeanMomentum() const
static const std::string defaultDistribution
void setGlobalPhaseShift(double shift)
units: (sec)
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
constexpr double q_e
The elementary charge in As.
void doRestartOpalT(PartBunchBase< double, 3 > *p, size_t Np, int restartStep, H5PartWrapper *h5wrapper)
void createOpalE(Beam *beam, std::vector< Distribution * > addedDistributions, EnvelopeBunch *envelopeBunch, double distCenter, double Bz0)
void initCartesianFields()
double getReferenceZ() const
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
virtual void setSolver(FieldSolver *fs)
double getMX() const
Return meshsize.
void setBeamFrequency(double v)
void setupCyclotronTracker()
double getReal(const Attribute &attr)
Return real value.
std::string getInputBasename()
get input file name without extension
double getElevation() const
void calcBeamParametersInitial()
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
void setNumberOfDistributions(unsigned int n)
virtual void execute()
Execute the command.
PartData reference
The reference data.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
void setChargeZeroPart(double q)
void slbunchIsAllocated()
Inform & endl(Inform &inf)
Track with thin lens algorithm.
std::string getString(const Attribute &attr)
Get string value.