Commit 7ff5909f authored by snuverink_j's avatar snuverink_j

code improvements for #62

parent 31d34d73
......@@ -129,9 +129,8 @@ std::pair<double, double> CavityAutophaser::optimizeCavityPhase(double initialPh
double t,
double dt) {
double originalPhase = 0.0;
RFCavity *element = static_cast<RFCavity *>(itsCavity_m.get());
originalPhase = element->getPhasem();
double originalPhase = element->getPhasem();
if (element->getAutophaseVeto()) {
std::pair<double, double> status(originalPhase, Util::getEnergy(initialP_m, itsReference_m.getM() * 1e-6));
......@@ -197,11 +196,10 @@ double CavityAutophaser::track(Vector_t R,
const double dt,
const double phase) const {
const Vector_t &refP = initialP_m;
double initialPhase = 0.0;
double finalMomentum = 0.0;
RFCavity *rfc = static_cast<RFCavity *>(itsCavity_m.get());
initialPhase = rfc->getPhasem();
double initialPhase = rfc->getPhasem();
rfc->setPhasem(phase);
std::pair<double, double> pe = rfc->trackOnAxisParticle(refP(2),
......
......@@ -2415,9 +2415,7 @@ void ParallelCyclotronTracker::Tracker_RK4() {
<< variable_m[4] << " " << variable_m[2] << " " << variable_m[5] << std::endl;
}
double OldTheta = 0.0;
OldTheta = calculateAngle(variable_m[0], variable_m[1]);
double OldTheta = calculateAngle(variable_m[0], variable_m[1]);
r_tuning[i] = variable_m[0] * cos(OldTheta) + variable_m[1] * sin(OldTheta);
z_tuning[i] = variable_m[2];
......@@ -3304,9 +3302,7 @@ void ParallelCyclotronTracker::Tracker_Generic() {
<< " " << variable_m[5] << std::endl;
}
double OldTheta = 0.0;
OldTheta = calculateAngle(variable_m[0], variable_m[1]);
double OldTheta = calculateAngle(variable_m[0], variable_m[1]);
r_tuning[i] = variable_m[0] * cos(OldTheta) + variable_m[1] * sin(OldTheta);
z_tuning[i] = variable_m[2];
......@@ -3792,7 +3788,6 @@ bool ParallelCyclotronTracker::rk4(double x[], const double &t, const double &ta
// tau Step size (usually time step)
// Pindex index of particel, not used yet
bool outOfBound = false;
double deriv1[PSdim];
double deriv2[PSdim];
double deriv3[PSdim];
......@@ -3801,7 +3796,7 @@ bool ParallelCyclotronTracker::rk4(double x[], const double &t, const double &ta
// Evaluate f1 = f(x,t).
outOfBound = derivate(x, t, deriv1 , Pindex);
bool outOfBound = derivate(x, t, deriv1 , Pindex);
if (outOfBound) {
return false;
}
......
......@@ -462,8 +462,7 @@ void Collimator::setGeom() {
geom_m[4].y = geom_m[0].y;
if (zstart_m > zend_m){
double tempz = 0.0;
tempz = zstart_m;
double tempz = zstart_m;
zstart_m = zend_m;
zend_m = tempz;
}
......
......@@ -510,10 +510,8 @@ void RFCavity::getMomentaKick(const double normalRadius, double momentum[], cons
Voltage *= Ufactor;
double dgam = 0.0;
double nphase = (frequency * (t + dtCorrt) * 1.0e-9) - phi0_m / 180.0 * pi ; // rad/s, ns --> rad
dgam = Voltage * cos(nphase) / (restMass);
double dgam = Voltage * cos(nphase) / (restMass);
double tempdegree = fmod(nphase * 360.0 / two_pi, 360.0);
if(tempdegree > 270.0) tempdegree -= 360.0;
......@@ -711,12 +709,12 @@ double RFCavity::getAutoPhaseEstimate(const double &E0, const double &t0, const
E2[i] += q * scale_m * getdE(i, t2, dz, phi + dphi, frequency_m, F);
}
double totalEz0 = 0.0, cosine_part = 0.0, sine_part = 0.0;
double cosine_part = 0.0, sine_part = 0.0;
double p0 = sqrt((E0 / mass + 1) * (E0 / mass + 1) - 1);
cosine_part += scale_m * cos(frequency_m * t0) * F[0];
sine_part += scale_m * sin(frequency_m * t0) * F[0];
totalEz0 = cos(phi) * cosine_part - sin(phi) * sine_part;
double totalEz0 = cos(phi) * cosine_part - sin(phi) * sine_part;
if(p0 + q * totalEz0 * (t[1] - t[0]) * Physics::c / mass < 0) {
// make totalEz0 = 0
......
......@@ -361,7 +361,6 @@ void FM3DH5Block::setFrequency(double freq) {
void FM3DH5Block::getOnaxisEz(vector<pair<double, double> > & F) {
double Ez_max = 0.0, dz = (zend_m - zbegin_m) / (num_gridpz_m - 1);
std::string tmpString;
const int index_x = -static_cast<int>(floor(xbegin_m / hx_m));
const double lever_x = -xbegin_m / hx_m - index_x;
......
......@@ -548,7 +548,6 @@ bool Fieldmap::interpreteEOF(std::ifstream &in) {
++lines_read_m;
in.getline(buffer_m, READ_BUFFER_LENGTH);
std::string buffer(buffer_m);
std::string rest;
size_t comment = buffer.find_first_of("#");
buffer = buffer.substr(0, comment);
size_t lasto = buffer.find_first_of(alpha_numeric);
......@@ -564,11 +563,10 @@ void Fieldmap::interpreteWarning(const std::string &error_msg,
const std::string &expecting,
const std::string &found) {
std::stringstream errormsg;
std::stringstream tmpmsg;
errormsg << "THERE SEEMS TO BE SOMETHING WRONG WITH YOUR FIELD MAP '" << Filename_m << "'.\n"
<< "expecting: '" << expecting << "' on line " << lines_read_m << ",\n"
<< "found instead: '" << found << "'.";
std::string errormsg_str = typeset_msg(errormsg.str(), "error");
// std::string errormsg_str = typeset_msg(errormsg.str(), "error");
throw GeneralClassicException("Fieldmap::interpretWarning()",
errormsg.str());
}
......@@ -593,8 +591,7 @@ void Fieldmap::missingValuesWarning() {
errormsg << "THERE SEEMS TO BE SOMETHING WRONG WITH YOUR FIELD MAP '" << Filename_m << "'.\n"
<< "There are only " << lines_read_m - 1 << " lines in the file, expecting more.\n"
<< "Please check the section about field maps in the user manual.";
std::string errormsg_str = typeset_msg(errormsg.str(), "error");
// std::string errormsg_str = typeset_msg(errormsg.str(), "error");
throw GeneralClassicException("Fieldmap::missingValuesWarning()",
errormsg.str());
}
......@@ -604,8 +601,7 @@ void Fieldmap::exceedingValuesWarning() {
errormsg << "THERE SEEMS TO BE SOMETHING WRONG WITH YOUR FIELD MAP '" << Filename_m << "'.\n"
<< "There are too many lines in the file, expecting only " << lines_read_m << " lines.\n"
<< "Please check the section about field maps in the user manual.";
std::string errormsg_str = typeset_msg(errormsg.str(), "error");
// std::string errormsg_str = typeset_msg(errormsg.str(), "error");
throw GeneralClassicException("Fieldmap::exceedingValuesWarning()",
errormsg.str());
}
......@@ -613,8 +609,7 @@ void Fieldmap::exceedingValuesWarning() {
void Fieldmap::disableFieldmapWarning() {
std::stringstream errormsg;
errormsg << "DISABLING FIELD MAP '" + Filename_m + "' DUE TO PARSING ERRORS." ;
std::string errormsg_str = typeset_msg(errormsg.str(), "error");
// std::string errormsg_str = typeset_msg(errormsg.str(), "error");
throw GeneralClassicException("Fieldmap::disableFieldmapsWarning()",
errormsg.str());
}
......@@ -622,8 +617,7 @@ void Fieldmap::disableFieldmapWarning() {
void Fieldmap::noFieldmapWarning() {
std::stringstream errormsg;
errormsg << "DISABLING FIELD MAP '" << Filename_m << "' SINCE FILE COULDN'T BE FOUND!";
std::string errormsg_str = typeset_msg(errormsg.str(), "error");
// std::string errormsg_str = typeset_msg(errormsg.str(), "error");
throw GeneralClassicException("Fieldmap::noFieldmapsWarning()",
errormsg.str());
}
......
......@@ -474,8 +474,8 @@ bool SectorMagneticFieldMap::IO::floatGreaterEqual(double in1, double in2) {
ThreeDGrid* SectorMagneticFieldMap::IO::generateGrid
(const std::vector< std::vector<double> > field_points,
SectorMagneticFieldMap::symmetry sym) {
std::vector<double> r_grid(1, field_points[0][0]);
std::vector<double> y_grid(1, field_points[0][1]), y_grid_neg;
std::vector<double> r_grid(1, field_points[0][0]);
std::vector<double> y_grid(1, field_points[0][1]);
std::vector<double> phi_grid(1, field_points[0][2]);
for (size_t i = 0; i < field_points.size(); ++i) {
if (floatGreaterEqual(field_points[i][0], r_grid.back())) {
......
......@@ -46,8 +46,7 @@ void CSRIGFWakeFunction::apply(PartBunch &bunch) {
double minPathLength = smin(2) + bunch.get_sPos() - FieldBegin_m;
for(unsigned int i = 1; i < numOfSlices; i++) {
double pathLengthOfSlice = minPathLength + i * meshSpacing;
double angleOfSlice = 0.0;
angleOfSlice = pathLengthOfSlice/bendRadius_m;
double angleOfSlice = pathLengthOfSlice/bendRadius_m;
if (angleOfSlice > 0.0 && angleOfSlice <= totalBendAngle_m){
calculateGreenFunction(bunch, meshSpacing);
}
......
......@@ -2342,15 +2342,13 @@ void Distribution::generateBinomial(size_t numberOfParticles) {
Vector_t p = Vector_t(0.0);
for (size_t partIndex = 0; partIndex < numberOfParticles; partIndex++) {
double S1 = 0.0;
double S2 = 0.0;
double A = 0.0;
double AL = 0.0;
double U = 0.0;
double V = 0.0;
S1 = IpplRandom();
S2 = IpplRandom();
double S1 = IpplRandom();
double S2 = IpplRandom();
if (mBinomial_m[0] <= 10000) {
......@@ -4508,9 +4506,8 @@ void Distribution::setupParticleBins(double massIneV, PartBunch &beam) {
WARNMSG("PT & PZ are obsolet and will be ignored. The moments of the beam is defined with PC or use OFFSETPZ" << endl);
// we get gamma from PC of the beam
double gamma = 0.0;
const double pz = beam.getP()/beam.getM();
gamma = sqrt(pow(pz, 2.0) + 1.0);
double gamma = sqrt(pow(pz, 2.0) + 1.0);
energyBins_m->setGamma(gamma);
} else {
......
......@@ -508,7 +508,6 @@ namespace Expressions {
std::vector<std::string> parseStringArray(Statement &stat) {
std::vector<std::string> array;
std::string value;
if(stat.delimiter('{')) {
// List of string values within braces.
......
......@@ -101,8 +101,6 @@ void Macro::parseFormals(Statement &stat) {
// We start after the opening '('.
formals.clear();
if(! stat.delimiter(')')) {
std::string form;
do {
std::string form =
Expressions::parseString(stat, "Expected formal argument name.");
......
......@@ -494,7 +494,6 @@ Token OpalParser::readToken() {
Statement *OpalParser::readStatement(TokenStream *is) const {
Statement *stat = 0;
Token token = is->readToken();
std::string name;
try {
if(token.isDel('{')) {
......
......@@ -115,7 +115,7 @@ namespace MakeSequenceNS {
SequenceWriter::SequenceWriter(const Beamline &beamline, const std::string &name,
std::ostream &os):
DefaultVisitor(beamline, false, false),
itsName(name), itsStream(os)
itsName(name), itsStream(os), sum_length(0.0)
{}
void SequenceWriter::execute() {
......
......@@ -562,7 +562,6 @@ void ArbitraryDomain::linearInterpolation(int idx, int idy, int idz, double& W,
C = 0.0;
std::tuple<int, int, int> coordxyz(idx, idy, idz);
std::multimap < std::tuple<int, int, int>, double >::iterator itrH, itrL;
if (idx == nr[0]-1)
dx_e = fabs(IntersectHiX.find(coordxyz)->second - cx);
......
......@@ -419,7 +419,7 @@ void P3MPoissonSolver::test(PartBunch &bunch) {
OpalData *opal = OpalData::getInstance();
DataSink *ds = opal->getDataSink();
std::vector<std::pair<std::string, unsigned int> > collimatorLosses; // just empty
// std::vector<std::pair<std::string, unsigned int> > collimatorLosses; // just empty
Vector_t FDext[6];
bunch.Q = qi;
......
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