Changeset 482 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src/softwareMadx.cc
- Timestamp:
- Jan 21, 2014, 1:52:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/softwareMadx.cc
r472 r482 3 3 #include "dataManager.h" 4 4 5 #include "mathematicalConstants.h" 6 #include "PhysicalConstants.h" 7 5 8 softwareMadx::softwareMadx() : abstractSoftware() 6 9 { … … 12 15 nameOfSoftware_ = nomDeLogiciel("madx"); 13 16 17 registerElement(nomdElements::RFgun,TBoolOk); 14 18 registerElement(nomdElements::drift,TBoolOk); 15 19 registerElement(nomdElements::mpole,TBoolOk); 16 20 } 17 21 18 bool softwareMadx::createInputFile(particleBeam* beamBefore, 22 bool softwareMadx::createInputFile(particleBeam* beamBefore,string workingDir) 19 23 { 20 24 cout << "***********************************" << endl; 21 25 cout << " softwareMadx::createInputFile(...) " << endl << endl; 22 23 26 dataManager_->consoleMessage(" softwareMadx::createInputFile"); 24 27 … … 32 35 } 33 36 34 cout << " softwareMadx::createInputFile(...) lecture des elts " << endl; 35 37 sector* sector= getSectionToExecute()->getSector(); 38 cout << " softwareMadx::createInputFile sector " << sector->getName() << endl; 39 /////////////////////////////////////////// 40 41 unsigned firstIndex= 0; 42 string sbeam; 43 abstractElement* elPtr; 44 elPtr = getSectionToExecute()->getElements().front(); 45 46 // le 1er elt n'est pas RFGun 47 if(elPtr->getNomdElement().getElementType() != nomdElements::RFgun) { 48 49 if(beamBefore == NULL) { 50 // il n'y a pas de faisceau : erreur 51 dataManager_->consoleMessage(" softwareMadx::createInputFile : no input beam, input file not created"); 52 return false; 53 } else { 54 // il y a un faisceau : on le met au format madx 55 dataManager_->consoleMessage(" softwareMadx::createInputFile : extract from input beam the quantities to be supplied to the madx BEAM command"); 56 57 if (beamBefore->particleRepresentationOk()) { 58 // le faisceau est représenté à la "parmela" 59 cout << "passsage de la représentation macroparticules à la representation moments" << endl; 60 beamBefore->buildMomentRepresentation(); 61 } else if(beamBefore->momentRepresentationOk()) { 62 // le faisceau est représenté à la "transport" 63 cout << "le faisceau est représenté par moments" << endl; 64 } else { 65 // représentation ni "macroparticules" ni "moments" 66 dataManager_->consoleMessage(" softwareMadx::createInputFile : that's unclear: the beam is represented neither by macroparticles neither by moments"); 67 return false; 68 } 69 70 sbeam = BEAMcommand(beamBefore); 71 } 72 73 // le 1er elt est RFGun 74 } else { 75 firstIndex = 1; 76 dataManager_->consoleMessage(" softwareMadx::createInputFile : set from RF cavity the quantities to be supplied to the madx BEAM command"); 77 sbeam = RFGunData(elPtr->parametersToSoftware()); 78 } 79 /////////////////////////////////////////// 80 36 81 // element label ////////////////////////// 37 38 82 outfile << endl; // saut de ligne 39 83 40 abstractElement* elPtr; 41 std::vector <abstractElement*> elements = getSectionToExecute()->getElements(); 42 for(unsigned k = 0; k < elements.size(); k++) 84 ostringstream os; 85 os << "L: line=("; 86 unsigned nElts= getSectionToExecute()->getElements().size(); 87 for(unsigned k = firstIndex; k < nElts; k++) 43 88 { 44 elPtr = elements[k];45 //cout << " debug:: element [" << k << "] " << elPtr->getNomdElement().getExpandedName() << endl;89 elPtr = getSectionToExecute()->getElements()[k]; 90 cout << " debug:: element [" << k << "] " << elPtr->getNomdElement().getExpandedName() << endl; 46 91 vector<statements> v= elPtr->parametersToSoftware(); 47 92 outfile << inputFormat(v); 48 } 49 50 // sublines /////////////////////////////// 51 93 94 if(k < nElts-1) 95 os << elPtr->getLabel() << ","; 96 else 97 os << elPtr->getLabel() << ");" << endl; 98 } 99 100 // lines/sublines /////////////////////////////// 52 101 outfile << endl; // saut de ligne 53 54 //_______________________________________________________ 55 // FIXME Francois !!!!! 56 //_______________________________________________________ 57 /* 58 vector<statements> u = sectParamPtr_->getSectors(); 59 for(unsigned int i = 0; i < u.size(); i++) { 60 ostringstream os; 61 os << u.at(i).first << ": line=("; 62 unsigned ai = dataManager_->getNumeroFromElementLabel(u.at(i).second.at(0)); 63 unsigned bi = dataManager_->getNumeroFromElementLabel(u.at(i).second.at(1)); 64 65 std::vector <abstractElement*> elements = getSectionToExecute()->getElements(); 66 for(unsigned k = 0; k < elements.size(); k++) { 67 elPtr = elements[k]; 68 69 if(k >= ai && k <= bi) { 70 if(k == bi) 71 os << elPtr->getLabel() <<");"; 72 else 73 os << elPtr->getLabel() <<","; 74 } 75 }// k 76 77 outfile << os.str() << endl; 78 }// i 79 102 80 103 // relection and repetition /////////////// 81 104 os << "all: " << "line=(" << sector->getRepetitionNumber() << "*L);"; 105 /////////////////////////////////////////// 106 107 outfile << os.str() << endl; 82 108 outfile << endl; // saut de ligne 83 84 string *str= NULL; 85 if(u.size() > 0) { 86 str = new string[u.size()]; 87 for(unsigned int i = 0; i < u.size(); i++) str[i]= "false"; 88 } 89 90 ostringstream os; 91 os << "all: " << "line=("; 92 for(unsigned k = 0; k < elements.size(); k++) { 93 elPtr = elements[k]; 94 bool isMember = false; 95 96 for(unsigned int i = 0; i < u.size(); i++) { 97 unsigned ai = dataManager_->getNumeroFromElementLabel(u.at(i).second.at(0)); 98 unsigned bi = dataManager_->getNumeroFromElementLabel(u.at(i).second.at(1)); 99 if(k >= ai && k <= bi) { 100 isMember = true; 101 102 if(str[i] == "false") { 103 //int reflection = atoi(u.at(i).second.at(2).c_str()); 104 int reflection = ( (u.at(i).second.at(2) == "Unchecked") ? 0:1 ); 105 int repeat = atoi(u.at(i).second.at(3).c_str()); 106 if(reflection > 0) 107 os << "-" << repeat << "*" << u.at(i).first; 108 else 109 os << repeat << "*" << u.at(i).first; 110 111 if(i < u.size()-1) os << ", "; 112 } 113 114 str[i] = "true"; 115 break; 116 } 117 }// i 118 119 if(isMember && k == (elements.size()-1)) os << ");"; 120 121 if(!isMember) { 122 if(k == (elements.size()-1)) os << elPtr->getLabel() << ");"; 123 else os << elPtr->getLabel() << ","; 124 } 125 }// k 126 127 outfile << os.str() << endl; 128 /////////////////////////////////////////// 129 130 outfile << endl; // saut de ligne 131 132 outfile << "beam;" << endl; // beam data p46 109 /////////////////////////////////////////// 110 111 outfile << sbeam << endl; // beam commnd p46 133 112 outfile << "use, period = all;" << endl << endl; // action commands p45 134 113 … … 137 116 outfile << "stop;" << endl; 138 117 139 */140 //_______________________________________________________141 // FIXME Francois !!!!!142 //_______________________________________________________143 144 118 outfile.close(); 145 119 dataManager_->consoleMessage("input file done for madx"); 146 120 return true; 121 } 122 123 string softwareMadx::BEAMcommand(particleBeam* beam) const 124 { 125 // le 20 décembre : les commandes BEAM de madx sont : 126 // PARTICLE (defaut POSITRON) 127 // ENERGY (defaut 1 GeV) ou bien PC GeV/c 128 // EX et EY (defaut 1 m.rad) 129 // ET (defaut 1 m) 130 131 ostringstream os; 132 os << "beam, PARTICLE = ELECTRON"; 133 134 double pc = beam->getP0Transport(); 135 os << ", ENERGY = " << pc; // en GeV 136 137 const beam2Moments& mts = beam->getTransportMoments(); 138 const vector< vector<double> > rij= mts.getMoments(); 139 140 // emittance (x,x') 141 double r10= rij.at(1).at(0); // r10 et s10 = s01= r10*r00*r11 142 double rac= 0.0; 143 if(r10*r10 < 1.0) rac= sqrt(1.0-r10*r10); 144 double EX = rij.at(0).at(0)*rij.at(1).at(1)*rac; // r00*r11*sqrt(1-s01*s10) 145 // r00 en cm (= 1E-02 m) et r11 en mrad (= 1E-03 rad) 146 os << ", EX = " << EX*1.E-05; 147 148 // emittance (y,y') 149 double r32= rij.at(3).at(2); // r32 et s32 = s23= r32*r22*r33 150 rac= 0.0; 151 if(r32*r32 < 1.0) rac= sqrt(1.0-r32*r32); 152 double EY = rij.at(2).at(2)*rij.at(3).at(3)*rac; // r22*r33*sqrt(1-s23*s32) 153 os << ", EY = " << EY*1.E-05; 154 155 os << ";"; 156 return os.str(); 157 } 158 159 string softwareMadx::RFGunData(const vector<statements>& v) const 160 { 161 //NPART = v.at(1).second.at(0); 162 //SIGT (m) = v.at(2).second.at(0) (ps) 163 //?? = sigma_r = v.at(2).second.at(1); en cm 164 //EX (m.rad) = v.at(3).second.at(0) (pi.mm.mrad) 165 //EY (m.rad) = v.at(3).second.at(1) (pi.mm.mrad) 166 //ENERGY (GeV) = v.at(4).second.at(0) (MeV) 167 //SIGE (GeV) = v.at(4).second.at(1) (MeV) 168 //CHARGE = v.at(6).second.at(0); 169 170 ostringstream os; 171 os << "beam, PARTICLE = ELECTRON"; 172 173 // masse au repos (en GeV) E0 = 1.E-03*EREST_MeV 174 // energie cinetique (en GeV) T = 1.E-03*E_cin 175 // l'energie totale (en Gev) W = E0+T 176 double W = 1.E-03*(EREST_MeV + atof(v.at(4).second.at(0).c_str())); 177 os << ", ENERGY = " << W; // total energy in [Gev] 178 179 // pi*EX = 1E-06*emit_x en pi.m.rad 180 double EX = 1.E-06*atof(v.at(3).second.at(0).c_str())/PI; 181 os << ", EX = " << EX; // horizontal emittance in [rad.m] 182 double EY = 1.E-06*atof(v.at(3).second.at(1).c_str())/PI; 183 os << ", EY = " << EY; // vertical emittance in [rad.m] 184 185 // SIGT = c*sigma_t*1E-12 186 double SIGT = 1.E-04*CLIGHT_E8*atof(v.at(2).second.at(0).c_str()); 187 os << ", SIGT = " << SIGT; // bunch length in [m] 188 189 // SIGE = sigma_Ecin/(p0*c) ou p0 impulsion de la paricule de réf. 190 // os << ", SIGE = " << atof(v.at(4).second.at(1).c_str()); 191 192 os << ";"; 193 return os.str(); 147 194 } 148 195 … … 216 263 } 217 264 265 // bool softwareMadx::execute(string workingDir) 266 // { 267 // cout << "***********************************" << endl; 268 // cout << " softwareMadx::execute(...) " << endl << endl; 269 270 // dataManager_->consoleMessage(" softwareMadx::execute"); 271 // return false; 272 // } 273 218 274 bool softwareMadx::buildBeamAfterElements(string workingDir) 219 275 { … … 221 277 cout << " softwareMadx::buildBeamAfterElements(...) " << endl << endl; 222 278 223 dataManager_->consoleMessage(" softwareMadx::buildBeamAfterElements ");279 dataManager_->consoleMessage(" softwareMadx::buildBeamAfterElements: not programmed :O(("); 224 280 return false; 225 281 }
Note: See TracChangeset
for help on using the changeset viewer.