Commit a9204e3d authored by snuverink_j's avatar snuverink_j
Browse files

add average radius to tune output; align printing; comments and spacing

parent 01d6dea7
......@@ -441,8 +441,9 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
std::ofstream out(tunefile, std::ios::out);
out << std::left
<< std::setw(15) << "energy [MeV]"
<< std::setw(15) << "radius [m]"
<< std::setw(15) << "energy[MeV]"
<< std::setw(15) << "radius_ini[m]"
<< std::setw(15) << "radius_avg[m]"
<< std::setw(15) << "nu_r"
<< std::setw(15) << "nu_z"
<< std::endl;
......@@ -483,9 +484,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
vpz_m[0] = init[3];
if ( !this->findOrbitOfEnergy_m(E, init, error, accuracy, maxit) ) {
/* throw OpalException("ClosedOrbitFinder::findOrbitOfEnergy()", */
/* "Didn't converge for energy " + std::to_string(E) + " MeV."); */
*gmsg << "Didn't converge for energy " + std::to_string(E) + " MeV." << endl;
*gmsg << "ClosedOrbitFinder didn't converge for energy " + std::to_string(E) + " MeV." << endl;
continue;
}
......@@ -493,17 +492,17 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
this->computeOrbitProperties(E);
std::pair<value_type , value_type > tunes = this->getTunes();
value_type reo = this->getOrbit( cycl_m->getPHIinit())[0];
value_type peo = this->getMomentum(cycl_m->getPHIinit())[0];
*gmsg << "* ----------------------------" << endl
*gmsg << std::left
<< "* ----------------------------" << endl
<< "* Closed orbit info (Gordon units):" << endl
<< "*" << endl
<< "* kinetic energy: " << E << " [MeV]" << endl
<< "* average radius: " << ravg_m << " [m]" << endl
<< "* initial radius: " << reo << " [m]" << endl
<< "* initial momentum: " << peo << " [Beta Gamma]" << endl
<< "* kinetic energy: " << std::setw(12) << E << " [MeV]" << endl
<< "* average radius: " << std::setw(12) << ravg_m << " [m]" << endl
<< "* initial radius: " << std::setw(12) << reo << " [m]" << endl
<< "* initial momentum: " << std::setw(12) << peo << " [Beta Gamma]" << endl
<< "* frequency error: " << phase_m << endl
<< "* horizontal tune: " << tunes.first << endl
<< "* vertical tune: " << tunes.second << endl
......@@ -513,6 +512,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
out << std::left
<< std::setw(15) << E
<< std::setw(15) << reo
<< std::setw(15) << ravg_m
<< std::setw(15) << tunes.first
<< std::setw(15) << tunes.second << std::endl;
out.close();
......@@ -592,12 +592,11 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbitOfEnergy_m(
value_type p = acon_m(wo_m) * std::sqrt(en * (2.0 + en)); // momentum [p] = m; Gordon, formula (3)
value_type gamma2 = gamma * gamma; // = gamma^2
value_type invgamma4 = 1.0 / (gamma2 * gamma2); // = 1/gamma^4
value_type p2 = p * p; // p^2 = p*p
// helper constants
value_type p2 = p * p; // p^2 = p*p
value_type pr2; // squared radial momentum (pr^2 = pr*pr)
value_type ptheta, invptheta; // Gordon, formula (5c)
value_type ptheta, invptheta; // azimuthal momentum
// define the six ODEs (using lambda function)
function_t orbit_integration = [&](const state_type &y,
......@@ -621,7 +620,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbitOfEnergy_m(
// Gordon, formula (5a)
dydt[0] = y[0] * y[1] * invptheta;
// Gordon, formula (5b)
// Gordon, formula (5b) (typo in paper! second equal sign is a minus)
dydt[1] = ptheta - y[0] * bint;
// Gordon, formulas (9a) and (9b)
for (size_type i = 2; i < 5; i += 2) {
......@@ -640,7 +639,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbitOfEnergy_m(
};
// integrate until error smaller than user-define accuracy
// integrate until error smaller than user-defined accuracy
do {
// (re-)set initial values
x_m[0] = 1.0; // x1; Gordon, formula (10)
......@@ -667,7 +666,8 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbitOfEnergy_m(
try {
// integrate from 0 to 2*pi (one has to get back to the "origin")
boost::numeric::odeint::integrate_n_steps(stepper_m, orbit_integration,y,0.0,dtheta_m,N_m,store);
} catch(OpalException &) {
} catch(OpalException & ex) {
*gmsg << ex.where() << " " << ex.what() << endl;
break;
}
......@@ -691,18 +691,21 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbitOfEnergy_m(
// correct initial values of r and pr
value_type invdenom = 1.0 / (x_m[0] + px_m[1] - 2.0);
delta[0] = ((px_m[1] - 1.0) * err[0] - x_m[1] * err[1]) * invdenom; // dr; Gordon, formula (16a)
delta[1] = ((x_m[0] - 1.0) * err[1] - px_m[0] * err[0]) * invdenom; // dpr; Gordon, formula (16b)
delta[1] = (( x_m[0] - 1.0) * err[1] - px_m[0] * err[0]) * invdenom; // dpr; Gordon, formula (16b)
// improved initial values; Gordon, formula (17) (here it's used for higher energies)
init[0] += delta[0];
init[1] += delta[1];
// compute amplitude of the error
// compute amplitude of the error (Gordon, formula (18)
error = std::sqrt(delta[0] * delta[0] + delta[1] * delta[1] * invgamma4) / r_m[0];
} while (error > accuracy && niterations++ < maxit);
// *gmsg << "iteration " << niterations << " error: " << error << endl;
} while ((error > accuracy) && (niterations++ < maxit));
if (error > accuracy)
*gmsg << "findOrbit not converged after " << maxit << " iterations with error: " << error << ". Needed accuracy " << accuracy << endl;
*gmsg << "findOrbit not converged after " << niterations << " iterations with error: " << error << ". Needed accuracy " << accuracy << endl;
return (error < accuracy);
}
......
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