Commit ec091d6a authored by snuverink_j's avatar snuverink_j
Browse files

fix charge per macroparticle for multicharged particles for OPAL-T; refactor

parent ec94d26a
......@@ -154,7 +154,7 @@ Beam *Beam::find(const std::string &name) {
return beam;
}
size_t Beam::getNumberOfParticles() {
size_t Beam::getNumberOfParticles() const {
return (size_t)Attributes::getReal(itsAttr[NPART]);
}
......@@ -199,6 +199,16 @@ double Beam::getFrequency() const {
return Attributes::getReal(itsAttr[BFREQ]);
}
double Beam::getChargePerParticle() const {
return std::copysign(1.0, getCharge()) * getCurrent()
/ (getFrequency() * 1.0e6)
/ getNumberOfParticles();
}
double Beam::getMassPerParticle() const {
return getMass() * getChargePerParticle() / (getCharge() * Physics::q_e);
}
void Beam::setEX(double value) {
Attributes::setReal(itsAttr[EX], value);
}
......
......@@ -70,7 +70,7 @@ public:
double getPC() const;
/// Return the number of (macro)particles
size_t getNumberOfParticles();
size_t getNumberOfParticles() const;
/// Return the embedded CLASSIC PartData.
const PartData &getReference() const;
......@@ -90,6 +90,12 @@ public:
/// Return Particle's rest mass in GeV
double getMass() const;
/// Charge per macro particle in C
double getChargePerParticle() const;
/// Mass per macro particle in GeV/c^2
double getMassPerParticle() const;
/// Store emittance for mode 1.
void setEX(double);
......
......@@ -53,8 +53,6 @@
extern Inform *gmsg;
using namespace Physics;
// ------------------------------------------------------------------------
namespace {
......@@ -271,7 +269,7 @@ void TrackRun::setupThickTracker()
Track::block->bunch->setCharge(charge);
}
// set coupling constant
double coefE = 1.0 / (4 * pi * epsilon_0);
double coefE = 1.0 / (4 * Physics::pi * Physics::epsilon_0);
Track::block->bunch->setCouplingConstant(coefE);
......@@ -377,7 +375,7 @@ void TrackRun::setupTTracker(){
Track::block->bunch->setCharge(charge);
}
// set coupling constant
double coefE = 1.0 / (4 * pi * epsilon_0);
double coefE = 1.0 / (4 * Physics::pi * Physics::epsilon_0);
Track::block->bunch->setCouplingConstant(coefE);
// statistical data are calculated (rms, eps etc.)
......@@ -484,7 +482,7 @@ void TrackRun::setupCyclotronTracker(){
}
if(beam->getNumberOfParticles() < 3 || beam->getCurrent() == 0.0) {
macrocharge = beam->getCharge() * q_e;
macrocharge = beam->getCharge() * Physics::q_e;
macromass = beam->getMass();
dist->createOpalCycl(Track::block->bunch,
beam->getNumberOfParticles(),
......@@ -497,12 +495,11 @@ void TrackRun::setupCyclotronTracker(){
getCurrent() gets beamcurrent [A]
*/
macrocharge = beam->getCurrent() / (beam->getFrequency() * 1.0e6); // [MHz]-->[Hz]
macrocharge = beam->getChargePerParticle();
macromass = beam->getMassPerParticle();
if(!opal->hasBunchAllocated()) {
if(!opal->inRestartRun()) {
macrocharge /= beam->getNumberOfParticles();
macromass = beam->getMass() * macrocharge / (beam->getCharge() * q_e);
dist->createOpalCycl(Track::block->bunch,
beam->getNumberOfParticles(),
beam->getCurrent(),
......@@ -514,8 +511,6 @@ void TrackRun::setupCyclotronTracker(){
opal->getRestartStep(),
specifiedNumBunch,
phaseSpaceSink_m);
macrocharge /= beam->getNumberOfParticles();
macromass = beam->getMass() * macrocharge / (beam->getCharge() * q_e);
}
}
}
......@@ -529,7 +524,7 @@ void TrackRun::setupCyclotronTracker(){
Track::block->bunch->setStepsPerTurn(Track::block->stepsPerTurn);
// set coupling constant
double coefE = 1.0 / (4 * pi * epsilon_0);
double coefE = 1.0 / (4 * Physics::pi * Physics::epsilon_0);
Track::block->bunch->setCouplingConstant(coefE);
// statistical data are calculated (rms, eps etc.)
......@@ -711,6 +706,6 @@ double TrackRun::setDistributionParallelT(Beam *beam) {
}
// Return charge per macroparticle.
return beam->getCharge() * beam->getCurrent() / (beam->getFrequency()*1.0e6) / numberOfParticles;
return beam->getChargePerParticle();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment