Commit fa0d0bc8 authored by frey_m's avatar frey_m
Browse files

Matched-Gauss: Update rinit and prinit for tracking

parent e8cfad52
......@@ -1281,7 +1281,12 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub
throw OpalException("Distribution::createMatchedGaussDistribution",
"didn't find any Cyclotron element in line");
}
const Cyclotron* CyclotronElement = CyclotronVisitor.front();
/* FIXME we need to remove const-ness otherwise we can't update the injection radius
* and injection radial momentum. However, there should be a better solutions ..
* Using const_cast is bad!
*/
Cyclotron* CyclotronElement = const_cast<Cyclotron*>(CyclotronVisitor.front());
bool full = !Attributes::getBool(itsAttr[Attrib::Distribution::SECTOR]);
......@@ -1407,6 +1412,11 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub
correlationMatrix_m(5, 1) = sigma(1, 5) / (sqrt(sigma(1, 1) * sigma(5, 5)));
createDistributionGauss(numberOfParticles, massIneV);
// update injection radius and radial momentum
double angle = CyclotronElement->getPHIinit();
CyclotronElement->setRinit(siggen->getInjectionRadius(angle));
CyclotronElement->setPRinit(siggen->getInjectionMomentum(angle));
}
else {
*gmsg << "* Not converged for " << E_m*1E-6 << " MeV" << endl;
......
......@@ -189,6 +189,14 @@ class SigmaGenerator
/// Returns the emittances (ex,ey,ez) in \f$ \pi\ mm\ mrad \f$ for which the code converged
///(since the whole simulation is done on normalized emittances)
std::array<value_type,3> getEmittances() const;
const double& getInjectionRadius(const double& angle) const {
return rinit_m;
}
const double& getInjectionMomentum(const double& angle) const {
return prinit_m;
}
private:
/// Stores the value of the current, \f$ \left[I\right] = A \f$
......@@ -261,6 +269,10 @@ class SigmaGenerator
/// All variables x, px, y, py, z, delta
Series x_m, px_m, y_m, py_m, z_m, delta_m;
double rinit_m;
double prinit_m;
/// Stores the dimension of the matrix
unsigned short const matrixDimension{6};
......@@ -396,7 +408,9 @@ SigmaGenerator<Value_type, Size_type>::SigmaGenerator(value_type I, value_type e
error_m(1),
fieldmap_m(fieldmap), truncOrder_m(truncOrder), write_m(write),
scaleFactor_m(scaleFactor), sigmas_m(0),permutations_m{{0,1,2,3},{1,2,3,0},{0,1,3,2},{1,0,2,3},{0,2,3,1},{0,3,2,1},
{1,0,3,2},{1,3,2,0},{2,1,0,3},{2,0,1,3},{2,3,0,1},{2,3,1,0},{3,1,0,2},{3,2,0,1}, {3,2,1,0},{3,0,1,2}}
{1,0,3,2},{1,3,2,0},{2,1,0,3},{2,0,1,3},{2,3,0,1},{2,3,1,0},{3,1,0,2},{3,2,0,1}, {3,2,1,0},{3,0,1,2}},
rinit_m(0.0),
prinit_m(0.0)
// The permutations up converge to a matched distribution, but the first four give the 4 unique solutions
// Following permutations threw an OPAL error, whose reason I still don't know.
//{0,2,1,3},{0,3,1,2},{1,2,0,3},{1,3,0,2},{2,1,3,0},{2,0,3,1},{3,1,2,0},{3,0,2,1}
......@@ -537,6 +551,9 @@ template<typename Value_type, typename Size_type>
fidx[i] = fidx_turn[i];
ds[i] = ds_turn[i];
}
rinit_m = r[0];
prinit_m = peo[0];
if(write_m){
writeOrbitOutput_m(tunes,ravg, cof.getFrequencyError(),r_turn,peo,h_turn,fidx_turn,ds_turn);
......
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