Commit 7b037737 authored by kraus's avatar kraus
Browse files

polishing output

parent b5a1eedf
......@@ -41,6 +41,7 @@ double CavityAutophaser::getPhaseAtMaxEnergy(const Vector_t &R,
RFCavity *element = static_cast<RFCavity *>(itsCavity_m.get());
bool apVeto = element->getAutophaseVeto();
bool isDCGun = false;
double originalPhase = element->getPhasem();
double tErr = (initialR_m(2) - R(2)) * sqrt(dot(P,P) + 1.0) / (P(2) * Physics::c);
double optimizedPhase = 0.0;
......@@ -48,7 +49,27 @@ double CavityAutophaser::getPhaseAtMaxEnergy(const Vector_t &R,
double newPhase = 0.0;
double amplitude = element->getAmplitudem();
double basePhase = std::fmod(element->getFrequencym() * (t + tErr), Physics::two_pi);
double frequency = element->getFrequencym();
if (frequency <= (1.0 + 1e-6) * Physics::two_pi) { // DC gun
optimizedPhase = (amplitude * itsReference_m.getQ() > 0.0? 0.0: Physics::pi);
element->setPhasem(optimizedPhase + originalPhase);
element->setAutophaseVeto();
originalPhase += optimizedPhase;
OpalData::getInstance()->setMaxPhase(itsCavity_m->getName(), originalPhase);
apVeto = true;
isDCGun = true;
}
std::stringstream ss;
for (char c: itsCavity_m->getName()) {
ss << std::setw(2) << std::left << c;
}
INFOMSG(level1 << "\n* ************* "
<< std::left << std::setw(68) << std::setfill('*') << ss.str()
<< std::setfill(' ') << endl);
if (!apVeto) {
double initialEnergy = Util::getEnergy(P, itsReference_m.getM()) * 1e-6;
double AstraPhase = 0.0;
......@@ -99,7 +120,7 @@ double CavityAutophaser::getPhaseAtMaxEnergy(const Vector_t &R,
optimizedPhase = status.first;
finalEnergy = status.second;
AstraPhase = std::fmod(optimizedPhase + Physics::pi / 2, Physics::two_pi);
AstraPhase = std::fmod(optimizedPhase + Physics::pi / 2 + Physics::two_pi, Physics::two_pi);
newPhase = std::fmod(originalPhase + optimizedPhase + Physics::two_pi, Physics::two_pi);
element->setPhasem(newPhase);
element->setAutophaseVeto();
......@@ -111,7 +132,6 @@ double CavityAutophaser::getPhaseAtMaxEnergy(const Vector_t &R,
track(initialR_m, initialP_m, t + tErr, dt, newPhase, &out);
out.close();
INFOMSG(level1 << endl);
INFOMSG(level1 << std::fixed << std::setprecision(4)
<< itsCavity_m->getName() << "_phi = " << newPhase * Physics::rad2deg << " [deg], "
<< "corresp. in Astra = " << AstraPhase * Physics::rad2deg << " [deg],\n"
......@@ -122,20 +142,28 @@ double CavityAutophaser::getPhaseAtMaxEnergy(const Vector_t &R,
} else {
auto status = optimizeCavityPhase(originalPhase, t + tErr, dt);
optimizedPhase = originalPhase;
finalEnergy = status.second;
newPhase = std::fmod(originalPhase + basePhase, Physics::two_pi);
originalPhase = std::fmod(originalPhase, Physics::two_pi);
double AstraPhase = std::fmod(optimizedPhase + Physics::pi / 2 + Physics::two_pi, Physics::two_pi);
INFOMSG(level1 << "\n"
<< ">>>>>> APVETO >>>>>> " << endl);
if (!isDCGun) {
INFOMSG(level1 << ">>>>>> APVETO >>>>>> " << endl);
}
INFOMSG(level1 << std::fixed << std::setprecision(4)
<< itsCavity_m->getName() << "_phi = " << newPhase * Physics::rad2deg << " [deg],\n"
<< itsCavity_m->getName() << "_phi = " << originalPhase * Physics::rad2deg << " [deg], "
<< "corresp. in Astra = " << AstraPhase * Physics::rad2deg << " [deg],\n"
<< "E = " << finalEnergy << " [MeV], " << "phi_nom = " << originalPhase * Physics::rad2deg << " [deg]\n"
<< "Ez_0 = " << amplitude << " [MV/m]" << "\n"
<< "time = " << (t + tErr) * 1e9 << " [ns], dt = " << dt * 1e12 << " [ps]" << endl);
INFOMSG(level1 << " <<<<<< APVETO <<<<<< " << endl);
if (!isDCGun) {
INFOMSG(level1 << " <<<<<< APVETO <<<<<< " << endl);
}
optimizedPhase = originalPhase;
}
INFOMSG(level1 << "* " << std::right << std::setw(83) << std::setfill('*') << "*\n"
<< std::setfill(' ') << endl);
return optimizedPhase;
}
......
......@@ -28,12 +28,21 @@ void IndexMap::print(std::ostream &out) const {
out << std::fixed << std::setprecision(6);
auto mapIti = mapRange2Element_m.begin();
auto mapItf = mapRange2Element_m.end();
double totalLength = (*mapRange2Element_m.rbegin()).first.second;
unsigned int numDigits = std::floor(std::max(0.0, log(totalLength) / log(10.0))) + 1;
for (; mapIti != mapItf; mapIti++) {
const auto key = (*mapIti).first;
const auto val = (*mapIti).second;
out << "Key: (" << std::setw(14) << key.first << "-" << std::setw(14) << key.second << ") number of overlapping elements " << val.size() << "\n";
out << "Key: ("
<< std::setw(numDigits + 7) << std::right << key.first
<< " - "
<< std::setw(numDigits + 7) << std::right << key.second
<< ") number of overlapping elements " << val.size() << "\n";
for (auto element: val) {
out << std::setw(37) << " " << element->getName() << "\n";
out << std::setw(25 + 2 * numDigits) << " " << element->getName() << "\n";
}
}
}
......@@ -381,4 +390,4 @@ IndexMap::value_t IndexMap::getTouchingElements(const std::pair<double, double>
bool IndexMap::almostEqual(double x, double y) {
return (std::abs(x - y) < std::numeric_limits<double>::epsilon() * std::abs(x + y) * 2 ||
std::abs(x - y) < std::numeric_limits<double>::min());
}
}
\ No newline at end of file
......@@ -640,10 +640,10 @@ double RFCavity::getAutoPhaseEstimateFallback(double E0, double t0, double q, do
phimax = fmod(phimax, Physics::two_pi);
const int prevPrecision = Ippl::Info->precision(8);
INFOMSG(level2 << "\n"
INFOMSG(level2
<< "estimated phase= " << phimax << " rad = "
<< phimax * Physics::rad2deg << " deg \n"
<< "Ekin= " << Emax << " MeV" << setprecision(prevPrecision) << endl);
<< "Ekin= " << Emax << " MeV" << setprecision(prevPrecision) << "\n" << endl);
setPhasem(origPhase);
return phimax;
......@@ -725,9 +725,9 @@ double RFCavity::getAutoPhaseEstimate(const double &E0, const double &t0, const
E[i] += q * scale_m * getdE(i, t, dz, phi, frequency_m, F) ;
}
const int prevPrecision = Ippl::Info->precision(8);
INFOMSG(level2 << "\nestimated phase= " << tmp_phi << " rad = "
INFOMSG(level2 << "estimated phase= " << tmp_phi << " rad = "
<< tmp_phi * Physics::rad2deg << " deg \n"
<< "Ekin= " << E[N - 1] << " MeV" << setprecision(prevPrecision) << endl);
<< "Ekin= " << E[N - 1] << " MeV" << setprecision(prevPrecision) << "\n" << endl);
return tmp_phi;
}
......@@ -770,10 +770,10 @@ double RFCavity::getAutoPhaseEstimate(const double &E0, const double &t0, const
}
const int prevPrecision = Ippl::Info->precision(8);
INFOMSG(level2 << "\n"
INFOMSG(level2
<< "estimated phase= " << tmp_phi << " rad = "
<< tmp_phi * Physics::rad2deg << " deg \n"
<< "Ekin= " << E[N - 1] << " MeV" << setprecision(prevPrecision) << endl);
<< "Ekin= " << E[N - 1] << " MeV" << setprecision(prevPrecision) << "\n" << endl);
return phi;
}
......
......@@ -522,7 +522,7 @@ double TravelingWave::getAutoPhaseEstimate(const double &E0, const double &t0, c
const int prevPrecision = Ippl::Info->precision(8);
INFOMSG(level2 << "estimated phase= " << tmp_phi << " rad = "
<< tmp_phi * Physics::rad2deg << " deg,\n"
<< "Ekin= " << E[N3 - 1] << " MeV" << std::setprecision(prevPrecision) << endl);
<< "Ekin= " << E[N3 - 1] << " MeV" << std::setprecision(prevPrecision) << "\n" << endl);
return tmp_phi;
}
phi = tmp_phi - floor(tmp_phi / Physics::two_pi + 0.5) * Physics::two_pi;
......@@ -562,7 +562,7 @@ double TravelingWave::getAutoPhaseEstimate(const double &E0, const double &t0, c
const int prevPrecision = Ippl::Info->precision(8);
INFOMSG(level2 << "estimated phase= " << tmp_phi << " rad = "
<< tmp_phi * Physics::rad2deg << " deg,\n"
<< "Ekin= " << E[N3 - 1] << " MeV" << std::setprecision(prevPrecision) << endl);
<< "Ekin= " << E[N3 - 1] << " MeV" << std::setprecision(prevPrecision) << "\n" << endl);
return phi;
}
......@@ -666,4 +666,4 @@ std::pair<double, double> TravelingWave::trackOnAxisParticle(const double &p0,
bool TravelingWave::isInside(const Vector_t &r) const {
return (isInsideTransverse(r) && r(2) >= -0.5 * PeriodLength_m && r(2) < startExitField_m);
}
}
\ No newline at end of file
......@@ -706,7 +706,8 @@ double Distribution::getTEmission() {
Inform &Distribution::printInfo(Inform &os) const {
os << "* ************* D I S T R I B U T I O N ********************************************" << endl;
os << "\n"
<< "* ************* D I S T R I B U T I O N ********************************************" << endl;
os << "* " << endl;
if (OpalData::getInstance()->inRestartRun()) {
os << "* In restart. Distribution read in from .h5 file." << endl;
......@@ -744,9 +745,9 @@ Inform &Distribution::printInfo(Inform &os) const {
os << "* Delta t during emission = " << tBin_m / numberOfSampleBins_m << " [sec]" << endl;
os << "* " << endl;
printEmissionModel(os);
os << "* " << endl;
} else
} else {
os << "* Distribution is injected." << endl;
}
}
os << "* " << endl;
os << "* **********************************************************************************" << endl;
......@@ -4034,7 +4035,6 @@ void Distribution::setDistParametersFlattop(double massIneV) {
if (emitting_m) {
INFOMSG("emitting"<<endl);
sigmaR_m = Vector_t(std::abs(Attributes::getReal(itsAttr[Attrib::Distribution::SIGMAX])),
std::abs(Attributes::getReal(itsAttr[Attrib::Distribution::SIGMAY])),
0.0);
......@@ -4451,9 +4451,12 @@ void Distribution::writeOutFileHeader() {
return;
std::string fname = "data/" + OpalData::getInstance()->getInputBasename() + "_" + getOpalName() + ".dat";
*gmsg << "* **********************************************************************************" << endl;
*gmsg << "* Write initial distribution to file \"" << fname << "\"" << endl;
*gmsg << "* **********************************************************************************" << endl;
*gmsg << "\n"
<< std::left << std::setw(84) << std::setfill('*') << "* " << "\n"
<< "* Write initial distribution to file \"" << fname << "\"\n"
<< std::left << std::setw(84) << std::setfill('*') << "* "
<< std::setfill(' ') << endl;
std::ofstream outputFile(fname);
if (outputFile.bad()) {
*gmsg << "Unable to open output file \"" << fname << "\"" << endl;
......
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