Changeset 7 in ZHANGProjects


Ignore:
Timestamp:
Mar 25, 2014, 11:22:11 AM (10 years ago)
Author:
zhangj
Message:

Fix the bugs to read the collimator files and optics files.

Location:
ICOSIM/CPP/trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • ICOSIM/CPP/trunk

    • Property svn:ignore set to
      outputs
  • ICOSIM/CPP/trunk/sample

    • Property svn:ignore set to
      crossSectionInfos

  • ICOSIM/CPP/trunk/source

    • Property svn:ignore set to
      icosim++
      twiss_optics
      testCollimator
      debug
      testElement
      testParticle
      source.kdev4
      testLattice
      readme

  • ICOSIM/CPP/trunk/source/.kdev4/source.kdev4

    r5 r7  
    11[Buildset]
    2 BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x10\x00I\x00C\x00O\x00S\x00Y\x00M\x00+\x00+)
     2BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
     3
     4[Launch]
     5Launch Configurations=Launch Configuration 0
     6
     7[Launch][Launch Configuration 0]
     8Configured Launch Modes=execute
     9Configured Launchers=nativeAppLauncher
     10Name=New Native Application Configuration
     11Type=Native Application
     12
     13[Launch][Launch Configuration 0][Data]
     14Arguments=../sample/collimatorfile_standard_ions_nominal.csv   ../outputs
     15Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
     16Dependency Action=Nothing
     17EnvironmentGroup=default
     18Executable=icosim++
     19External Terminal=konsole --noclose --workdir %workdir -e %exe
     20Project Target=
     21Use External Terminal=false
     22Working Directory=file:///home/jfz/codes/ICOSIMPP/CPP/source
     23isExecutable=true
     24
     25[Project]
     26VersionControlSupport=kdevsubversion
  • ICOSIM/CPP/trunk/source/Particle.cc

    r5 r7  
    99//==================================Constructors, destructor====================================
    1010
     11/*
     12   Initialize the 6-D particle coordinates.
     13 */
    1114Particle::Particle(double x, double dx, double y, double dy, double deltaE, double t, double mass, double charge, double moment)
    1215    : Ap0(mass), Zp0(charge), dpoporiginal(moment)
     
    123126}
    124127
    125 
     128/*
     129   set the ID of the registed particle ID.
     130 */
    126131void Particle::setidentification(int id)
    127132{
  • ICOSIM/CPP/trunk/source/StandardCollimator.cc

    r5 r7  
    2525{
    2626
    27     long double ca, sa;
     27    long double ca=0.0, sa=0.0;
    2828
    2929    sa = sin(this->tcang);
     
    3434    p1.coordonnees[0][2] = p1.coordonnees[0][2] - scaleorbit * this->YC;
    3535
    36     long double xl, xsl, alf, lcolleff;
     36    long double xl=0.0, xsl=0.0, alf=0.0, lcolleff=0.0;
    3737
    3838
     
    109109
    110110        //Apply thin collimator at impact position
    111 
     111          /* Initialize the 6-D particle coordinates*/
    112112        Particle ptemp(xint, xsint, yint, ysint, p1.coordonnees[0][4], 0, p1.Ap0, p1.Zp0, p1.coordonnees[0][4]);
    113113
  • ICOSIM/CPP/trunk/source/lattice.cc

    r5 r7  
    269269
    270270
    271 
     271/*
     272 *
     273 */
    272274void Lattice::trackensemblelinearnew(vector <Particle>& bunch, vector <Particle>& bunchhit, const int& nrev, const double& blowup2, const int& blowupperiod)
    273275{
    274276
    275     int nip, niph, nrevhitp;
     277  /*nip: number of primary collimators in the accelerator; niph: number of primary collimators hit by the particles; nrevhitp: number of turns when the particle hit the primary collimators */
     278    int nip=0, niph=0, nrevhitp=0;
    276279    vector <int> iph;
    277     double blowup;
     280    double blowup=0.0; /* sqrt(blowup2), beam blow up strength*/
    278281
    279282    //we only take the primary collimators into account here, as well as the first and the last elements of the lattice
     
    331334                if (bunch[p].in == 1) { //to assure the particle is still remainding in the accelerator
    332335
    333                     long double pdepth, pdepth2;
     336                    long double pdepth=0.0, pdepth2=0.0;
    334337
    335338                    bunch[p].coordonnees[1][0] = R11X[i] * bunch[p].coordonnees[0][0] + R12X[i] * bunch[p].coordonnees[0][1] + (reseau[iph[i + 1]]->DX - R11X[i] * reseau[iph[i]]->DX - R12X[i] * reseau[iph[i]]->DPX) * bunch[p].coordonnees[0][4];
     
    339342
    340343                    if (i < niph - 1) {
    341                         long double lcoll, sa, ca;
     344                        long double lcoll=0.0, sa=0.0, ca=0.0;
    342345
    343346                        sa = sin(resColli[ipcoll[i]]->tcang);//sinus of the collimator's angle
     
    416419            if ((k + 1) % blowupperiod == 0) { //blowup/diffusion
    417420                if (bunch[p].in == 1) {
    418                     //cout << "Blow-up!!" << k+1 << endl;
     421                  //  cout << "Blow-up!!" << k+1 << endl;
    419422                    int im;
    420423                    im = reseau.size() - 1;
  • ICOSIM/CPP/trunk/source/simulation.cc

    r5 r7  
    3535
    3636    for (int l(0); l < sizeBunch; ++l) {
    37 
     37        /* generate the particle distributions */
    3838        p1.genpartdist(1, 1, genere, 1.00095, 1.2e-8, 1.2e-8, 0.00011, bx, ax, dx, dpx, by, ay, dy, dpy, 6);
    3939        p1.afficheFirstCoordonnees();
     
    6767
    6868
     69/*
     70 void Simulation::readParticle(const double& Apr, const double& Zpr, string inputfile)
     71 
     72 */
    6973void Simulation::readParticle(const double& Apr, const double& Zpr, string inputfile)
    7074{
     
    536540
    537541
    538     double Apr, Zpr, mass, energyPerIon, emix, emiy, sigdpp, r1r2skin, blowup2, thicknessmagneticfield, Bmax, deltaGap, gamma, betgam, W, PlossPb, freqrf, rfvoltage, rfharmonic, wecolli, nsigi, momentum;
    539     int npart, kbunch, taubeam, nparti, nrev1, nrev2, blowupperiod, scaleorbit, beamflag, stopLinearTrackingNo, RunWithFluka, RunWithCrystal, RunningFlag, outcoord, idpart, idelt, RFflag;
    540     string partdistr, stoplineartracking, crosssectionspath, opticsFile, plotflag, inputpath;
     542    double Apr=0.0, Zpr=0.0, mass=0.0, energyPerIon=0.0, emix=0.0, emiy=0.0, sigdpp=0.0,
     543    r1r2skin=0.0, blowup2=0.0, thicknessmagneticfield=0.0, Bmax=0.0, deltaGap=0.0,
     544    gamma=0.0, betgam=0.0, W, PlossPb, freqrf=0.0, rfvoltage=0.0, rfharmonic=0.0,
     545    wecolli=0.0, nsigi=0.0, momentum=0.0;
     546    int npart=0, kbunch=0, taubeam=0, nparti=0, nrev1=0, nrev2=0, blowupperiod=0, scaleorbit=0,
     547    beamflag=1, stopLinearTrackingNo=0, RunWithFluka=0, RunWithCrystal=0, RunningFlag=1,
     548    outcoord=0, idpart=0, idelt=0, RFflag=0;
     549    string partdistr="", stoplineartracking="", crosssectionspath="", opticsFile="", plotflag="", inputpath="";
    541550
    542551    int indication(1);
     
    11731182{
    11741183
    1175 
    1176     int JohnJaperFlag;
     1184//for the moment, ICOSIM++ cannot run without aperture parameters, so JohnJaperflag is fixed to 1; the variable is still here to facilitate further developpment
     1185    int JohnJaperFlag=1;
    11771186
    11781187    defineParameters(opticsFile, beamflag, JohnJaperFlag);
    11791188
    11801189    bool apertureIsZero(false);
    1181     int temp1(0);
    1182     int temp2(0);
    1183     int temp3;
    1184 
     1190    int temp1 = 0;
     1191    int temp2 = 0;
     1192    int temp3 = 0;
     1193     
     1194   
    11851195    if (JohnJaperFlag == 1) { //JohnJaperflag=1 if we have information about the aperture
    11861196
    11871197        for (int w(0); w < nbre_elts; ++w) {
    11881198            if (lat.reseau[w]->APERTYPE == "RECTELLIPSE") {
    1189                 ++temp1;
     1199                temp1 = temp1 + 1;
    11901200                if ((lat.reseau[w]->APER_1 == 0) && (lat.reseau[w]->APER_2 == 0) && (lat.reseau[w]->APER_3 == 0) && (lat.reseau[w]->APER_4 == 0)) {
    1191                     ++temp2;
    1192                 } else {
    1193                     break;
    1194                 }
    1195             } else {
    1196                 break;
    1197             }
     1201                    temp2 = temp2 + 1;
     1202                }
     1203//                 else {
     1204//                     break;
     1205//                 }
     1206            }
     1207//             else {
     1208//                 break;
     1209//             }
    11981210        }
    11991211
    12001212        //If all apertures are RECTELLIPSES:
    1201         //If an apeture variable is 0, it takes the value of the preceeding aperture variable.
    1202         //If all the apertures are 0, we define them to be 1 instead.
     1213           //If all the aperture variables of all lattice elements are 0, we define them to be 1 instead.
     1214        //  If an apeture variable is 0, it takes the value of the preceeding aperture variable.
    12031215
    12041216        if (temp1 == nbre_elts) {
     
    12141226            if (lat.reseau[0]->APER_1 == 0) {
    12151227                apertureIsZero = true;
    1216                 temp3 = nbre_elts;
    1217                 while (lat.reseau[temp3]->APER_1 == 0) {
     1228                temp3 = nbre_elts -1;
     1229                if (lat.reseau[temp3]->APER_1 == 0) {
    12181230                    temp3 = temp3 - 1;
    12191231                }
     
    12221234            if (lat.reseau[0]->APER_2 == 0) {
    12231235                apertureIsZero = true;
    1224                 temp3 = nbre_elts;
    1225                 while (lat.reseau[temp3]->APER_2 == 0) {
     1236                temp3 = nbre_elts -1;
     1237                if (lat.reseau[temp3]->APER_2 == 0) {
    12261238                    temp3 = temp3 - 1;
    12271239                }
     
    12301242            if (lat.reseau[0]->APER_3 == 0) {
    12311243                apertureIsZero = true;
    1232                 temp3 = nbre_elts;
    1233                 while (lat.reseau[temp3]->APER_3 == 0) {
     1244                temp3 = nbre_elts -1;
     1245                if (lat.reseau[temp3]->APER_3 == 0) {
    12341246                    temp3 = temp3 - 1;
    12351247                }
     
    12381250            if (lat.reseau[0]->APER_4 == 0) {
    12391251                apertureIsZero = true;
    1240                 temp3 = nbre_elts;
    1241                 while (lat.reseau[temp3]->APER_4 == 0) {
     1252                temp3 = nbre_elts - 1;
     1253                if (lat.reseau[temp3]->APER_4 == 0) {
    12421254                    temp3 = temp3 - 1;
    12431255                }
     
    12791291                }
    12801292            } else if (lat.reseau[r]->APERTYPE == "NONE") {
     1293             
     1294                if(r==0){
     1295                  lat.reseau[r]->APER_1 = lat.reseau[nbre_elts]->APER_1;
     1296                  lat.reseau[r]->APER_2 = lat.reseau[nbre_elts]->APER_2;
     1297                  lat.reseau[r]->APER_3 = lat.reseau[nbre_elts]->APER_3;
     1298                  lat.reseau[r]->APER_4 = lat.reseau[nbre_elts]->APER_4;
     1299                  lat.reseau[r]->APERTYPE = lat.reseau[nbre_elts]->APERTYPE;
     1300                }else{
    12811301                lat.reseau[r]->APER_1 = lat.reseau[r - 1]->APER_1;
    12821302                lat.reseau[r]->APER_2 = lat.reseau[r - 1]->APER_2;
     
    12841304                lat.reseau[r]->APER_4 = lat.reseau[r - 1]->APER_4;
    12851305                lat.reseau[r]->APERTYPE = lat.reseau[r - 1]->APERTYPE;
     1306                }
    12861307            }
    12871308        }
     
    12911312        }
    12921313
    1293         //we compute the final apertures
     1314        //we compute the final apertures; different aperture type
    12941315        for (int i(0); i < lat.reseau.size(); ++i) {
    12951316            if (lat.reseau[i]->APERTYPE == "CIRCLE") {
     
    15041525    }
    15051526
    1506     double hk;
     1527    double hk=0.0;
    15071528
    15081529    for (int k(0); k < indice.size(); ++k) {
     
    15291550    }
    15301551
    1531     double vk;
     1552    double vk=0.0;
    15321553
    15331554    for (int k(0); k < indice.size(); ++k) {
     
    15411562
    15421563}
    1543 
     1564/***************************************************************************
     1565 *
     1566 * Read the lattice elements parameters
     1567 *
     1568 *
     1569 *
     1570 *
     1571 *  Jianfeng Zhang @ LAL, 21/03/2014
     1572 *   Fix the bug to read the lattice element parameters.
     1573 *
     1574 ***************************************************************************/
    15441575void Simulation::defineParameters(string opticsFile, const int& beamflag, int& JohnJaperFlag)
    15451576{
    15461577
    15471578    ifstream entree;
    1548     string APERTYPE, name, KEYWORD, PARENT;
     1579    string APERTYPE="", name="", KEYWORD="", PARENT="";
    15491580    entree.open(opticsFile.c_str());
    15501581
     
    15531584    } else {
    15541585
    1555         string name, temp;
    1556         string strtemp, strtemp1;
    1557 
     1586        string name="", temp="";
     1587        string strtemp="", strtemp1="";
     1588         /* read the parameters at the beginning of the MADX twiss file*/
    15581589        getline(entree, strtemp, ',');
    15591590        while ((strtemp != "NAME") && (strtemp != "ALFX") && (strtemp != "S") && (strtemp != "L") && (strtemp != "K0L") && (strtemp != "K0SL") && (strtemp != "K1L") && (strtemp != "K1SL") && (strtemp != "K2L") && (strtemp != "K2SL") && (strtemp != "XC") && (strtemp != "PXC") && (strtemp != "KEYWORD") && (strtemp != "PARENT") && (strtemp != "YC") && (strtemp != "PYC") && (strtemp != "TC") && (strtemp != "PTC") && (strtemp != "BETX") && (strtemp != "MUX") && (strtemp != "DX") && (strtemp != "DPX") && (strtemp != "BETY") && (strtemp != "ALFY") && (strtemp != "MUY") && (strtemp != "DY") && (strtemp != "DPY") && (strtemp != "APERTYPE") && (strtemp != "APER_1") && (strtemp != "APER_2") && (strtemp != "APER_3") && (strtemp != "APER_4")) {
     
    15611592            getline(entree, strtemp, ',');
    15621593        }
    1563 
    1564         double S, L, K0L, K0SL, K1L, K1SL, K2L, K2SL, XC, PXC, YC, PYC, TC, PTC, BETX, ALFX, MUX, DX, DPX, BETY, ALFY, MUY, DY, DPY, APER_1, APER_2, APER_3, APER_4;
     1594         /* read the parameters of the lattice elements*/
     1595        double S=0.0, L=0.0, K0L=0.0, K0SL=0.0, K1L=0.0, K1SL=0.0, K2L=0.0, K2SL=0.0, XC=0.0, PXC=0.0, YC=0.0, PYC=0.0, TC=0.0, PTC=0.0,
     1596               BETX=0.0, ALFX=0.0, MUX=0.0, DX=0.0, DPX=0.0, BETY=0.0, ALFY=0.0, MUY=0.0, DY=0.0, DPY=0.0, APER_1=0.0, APER_2=0.0, APER_3=0.0, APER_4=0.0;
    15651597
    15661598        int taille(0);
     
    16121644        }
    16131645        getline(entree, strtemp);
     1646        /* remove the "\r" symbol from the last variable in the "*.csv file",
     1647               maybe this is a potential bug for other file format... By jianfeng Zhang @ LAL, 21/03/2014*/
     1648            strtemp = strtemp.substr(0,strtemp.size()-1);
    16141649        header.push_back(strtemp);
    16151650
     
    16231658        }
    16241659
     1660        /*start read the lattice elements parameters*/
    16251661        while (!entree.eof()) {
    1626             ++taille;
     1662           
     1663         
     1664               ++taille;
     1665            /* lattice elment*/
    16271666            for (int n(0); n < 31; ++n) {
    16281667                getline(entree, strtemp, ',');
    16291668                vectemp.push_back(strtemp);
    16301669            }
     1670            /* last variable of the lattice element */
    16311671            getline(entree, strtemp);
     1672            /* remove the "\r" symbol from the last variable in the "*.csv file",
     1673               maybe this is a potential bug for other file format... By jianfeng Zhang @ LAL, 21/03/2014*/
     1674            strtemp = strtemp.substr(0,strtemp.size()-1);
    16321675            vectemp.push_back(strtemp);
    16331676
     1677           
    16341678            for (int h(0); h < order.size(); ++h) {
    16351679
     
    17011745            }
    17021746
     1747             /*to fix the bug that: the c++ code can't stop when the end of fine is reached in the *.csv files
     1748               by Jianfeng zhang @ LAL, 21/03/2014
     1749             */
     1750            if(name.substr(0, 1) =="\r" || name.substr(0, 1) =="\n")
     1751            {
     1752              vectemp.clear();
     1753              taille = taille - 1;
     1754              break;
     1755            }
     1756           
     1757             
     1758           
    17031759            Element elt(ALFX, ALFY, APER_1, APER_2, APER_3, APER_4, APERTYPE, BETX, BETY, DPX, DPY, DX, DY, KEYWORD, L, MUX, MUY, name, PTC, PXC, PYC, S, TC, XC, YC, K0L, K0SL, K1L, K1SL, K2L, K2SL, PARENT);
    17041760
     
    17071763            vectemp.clear();
    17081764
    1709             if ((name.substr(0, 3) == "END") || (name.substr(name.size() - 3, 3) == "END")) {
    1710                 break;
    1711             }
    1712 
    1713         }
     1765             if (name == "LHCB1$END") {
     1766                 cout << name << "         "<<taille<<endl;
     1767             }
     1768
     1769        }
     1770       
     1771        /*number of lattice elements*/
    17141772        this ->nbre_elts = taille;
    17151773    }
Note: See TracChangeset for help on using the changeset viewer.