Commit 5b3a63e3 by cortes_c

Fixed a bug in Sigma generator. In class Distribution, multiple simulations...

`Fixed a bug in Sigma generator. In class Distribution, multiple simulations are allowed without throwing an mpi - abort, when Option cloTuneOnly is active. ClosedOrbitFinder shouldn't have significant changes.`
parent f1aa535b
 ... @@ -511,7 +511,7 @@ bool ClosedOrbitFinder::findOrbit(value_type acc ... @@ -511,7 +511,7 @@ bool ClosedOrbitFinder::findOrbit(value_type acc dydt[0] = y[0] * y[1] * invptheta; dydt[0] = y[0] * y[1] * invptheta; // Gordon, formula (5b) // Gordon, formula (5b) dydt[1] = ptheta - y[0] * bint; dydt[1] = ptheta - y[0] * bint; // Gordon, formulas (9a) and (9b) // Gordon, formulas (9a) and (9b) for (size_type i = 2; i < 5; i += 2) { for (size_type i = 2; i < 5; i += 2) { dydt[i] = (y[1] * y[i] + y[0] * p2 * y[i+1] * invptheta * invptheta) * invptheta; dydt[i] = (y[1] * y[i] + y[0] * p2 * y[i+1] * invptheta * invptheta) * invptheta; dydt[i+1] = - y[1] * y[i+1] * invptheta - (bint + y[0] * brint) * y[i]; dydt[i+1] = - y[1] * y[i+1] * invptheta - (bint + y[0] * brint) * y[i]; ... ...
 ... @@ -1366,8 +1366,8 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub ... @@ -1366,8 +1366,8 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub */ */ if (Options::cloTuneOnly) //if (Options::cloTuneOnly) throw OpalException("Do only CLO and tune calculation","... "); // throw OpalException("Do only CLO and tune calculation","... "); auto sigma = siggen->getSigma(); auto sigma = siggen->getSigma(); ... ...
 ... @@ -471,6 +471,7 @@ template ... @@ -471,6 +471,7 @@ template * - tune nuz * - tune nuz */ */ // object for space cyclotron map // object for space cyclotron map maxit = 1000; try{ try{ MapGenerator mapgen(nStepsPerSector_m); MapGenerator mapgen(nStepsPerSector_m); ... @@ -531,25 +532,27 @@ template ... @@ -531,25 +532,27 @@ template return false; return false; } } if(Options::cloTuneOnly) if(Options::cloTuneOnly){ throw OpalException("Do only CLO and tune calculation","... "); //throw OpalException("Do only CLO and tune calculation","... "); *gmsg << "Doing just close orbit and tune calculation only" << endl; // computes the cyclotron maps for each angle and stores them into a vector } std::vector Mcycs(nStepsPerSector_m); else{ // computes the cyclotron maps for each angle and stores them into a vector // calculate only for a single sector (a nSector_-th) of the whole cyclotron std::vector Mcycs(nStepsPerSector_m); for (size_type i = 0; i < nStepsPerSector_m; ++i) Mcycs[i] = mapgen.generateMap(H_m(h[i],h[i]*h[i]+fidx[i],-fidx[i]),ds[i],truncOrder_m); // calculate only for a single sector (a nSector_-th) of the whole cyclotron for (size_type i = 0; i < nStepsPerSector_m; ++i) Mcycs[i] = mapgen.generateMap(H_m(h[i],h[i]*h[i]+fidx[i],-fidx[i]),ds[i],truncOrder_m); // search for a match distribution for each permutation // search for a match distribution for each permutation // Set to search for the permutation which converged to a matched distribution upon tracking // Set to search for the permutation which converged to a matched distribution upon tracking // Note that 4 permutations converge to the same matched distribution // Note that 4 permutations converge to the same matched distribution for(size_type permutation = 0; permutation < 1; permutation++){ for(size_type permutation = 0; permutation < 1; permutation++){ findMatchDistribution(accuracy,h,fidx,ds,tunes,ravg,maxit,Mcycs,harmonic,2); findMatchDistribution(accuracy,h,fidx,ds,tunes,ravg,maxit,Mcycs,harmonic,2); } std::cout << "OPAL> * Number of matched distributions: " < * Last matched distribution information: "< * Number of matched distributions: " < * Last matched distribution information: "< ... @@ -557,7 +560,7 @@ template if ( 0 < matchedSigmas_m.size()) return (0 < matchedSigmas_m.size()); if ( 0 < matchedSigmas_m.size()) return (0 < matchedSigmas_m.size()); //Returns an identity matrix, if no matched distribution was found //Returns an identity matrix, if no matched distribution was found else{ else{ *gmsg << "No matched distribution found, returning unity matrix instead."; *gmsg << "No matched distribution found, returning unity matrix instead or CLOTUNEONLY option"< ... @@ -789,6 +792,8 @@ template // for exiting the loop if maxit is reached // for exiting the loop if maxit is reached bool stop = false; bool stop = false; // checks if the eigenvector matrix E and E^-1 could be built bool isBuild = false; // initialize sigma matrices (for each angle one) (first guess) // initialize sigma matrices (for each angle one) (first guess) initialize(tunes.second,ravg); initialize(tunes.second,ravg); ... @@ -812,10 +817,11 @@ template ... @@ -812,10 +817,11 @@ template * and updateInitialSigma was changed according to Eq. 18 Sec. 2.4 * and updateInitialSigma was changed according to Eq. 18 Sec. 2.4 * Frey Semester thesis * Frey Semester thesis */ */ // Returns the Eigenvalues of the Twiss-Matrix, // Sets the Eigenvalues of the Twiss-Matrix, // orders them and computes R and invR // orders them and computes R and invR setEigenVectors(Mturn,R,invR,permutation); // Also checks if the Eigenvector matrix E is invertible isBuild = setEigenVectors(Mturn,R,invR,permutation); // computes the new sigma matrix // computes the new sigma matrix newSigma = updateInitialSigma(R,invR); newSigma = updateInitialSigma(R,invR); ... @@ -840,9 +846,9 @@ template ... @@ -840,9 +846,9 @@ template // construct new one turn transfer matrix M // construct new one turn transfer matrix M mapgen.combine(Mscs,Mcycs); mapgen.combine(Mscs,Mcycs); Mturn = mapgen.getMap(); Mturn = mapgen.getMap(); // check if number of iterations has maxit exceeded. // check if number of iterations has maxit exceeded or if the eigenvector matrix could be built stop = (niterations_m++ > maxit); stop = (niterations_m++ > maxit) || !isBuild; // check for convergence // check for convergence converged_m = error_m < accuracy; converged_m = error_m < accuracy; ... @@ -915,20 +921,17 @@ template ... @@ -915,20 +921,17 @@ template gsl_matrix_complex_free(eigenVectors); gsl_matrix_complex_free(eigenVectors); gsl_matrix_free(MTurngsl); gsl_matrix_free(MTurngsl); // Sorts the Eigenvectors such that // Sorts the Eigenvectors // Re(eig_x) < Re(eig_y) < Re(eig_z) std::vector permutation = permutations_m[perm]; std::vector permutation = permutations_m[perm]; value_type threshold = 10e-12; std::vector zVectors{}; std::vector xyVectors{}; bool isZdirection = false; bool isZdirection = false; std::vector zVectors; std::vector xyVectors; for(size_type i = 0; i < 6; i++){ for(size_type i = 0; i < 6; i++){ complex_number_type z = R(i,0); complex_number_type z = R(i,0); if(std::abs(z) < 1e-13) z = 0.; if(std::abs(z) < threshold) z = 0.; if(z == 0.) isZdirection = true; if(z == 0.) isZdirection = true; complex_vector_type v(6); complex_vector_type v(6); if(isZdirection){ if(isZdirection){ for(size_type j = 0;j < matrixDimension; j++){ for(size_type j = 0;j < matrixDimension; j++){ ... @@ -944,7 +947,17 @@ template ... @@ -944,7 +947,17 @@ template } } xyVectors.push_back(v); xyVectors.push_back(v); } } isZdirection = false; isZdirection = false; } //z-direction not found, then the system does not have the expected form if(zVectors.size() != 2){ *gmsg << "Could not found the vertical eigenvectors of the system"<
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