[342] | 1 | |
---|
[304] | 2 | #include "softwareGenerator.h" |
---|
| 3 | #include "abstractElement.h" |
---|
[312] | 4 | #include "generatorParticle.h" |
---|
| 5 | #include "mathematicalConstants.h" |
---|
| 6 | #include "PhysicalConstants.h" |
---|
[359] | 7 | #include "dataManager.h" |
---|
[304] | 8 | |
---|
| 9 | softwareGenerator::softwareGenerator() : abstractSoftware() |
---|
[386] | 10 | { |
---|
| 11 | nameOfSoftware_ = nomDeLogiciel("generator"); |
---|
| 12 | } |
---|
[304] | 13 | |
---|
[316] | 14 | softwareGenerator::softwareGenerator(string inputFileName, globalParameters* globals, dataManager* dt) : abstractSoftware(inputFileName, globals, dt) |
---|
[386] | 15 | { |
---|
| 16 | nameOfSoftware_ = nomDeLogiciel("generator"); |
---|
| 17 | } |
---|
[304] | 18 | |
---|
[316] | 19 | bool softwareGenerator::createInputFile(particleBeam* beamBefore, unsigned int numeroDeb, unsigned int numeroFin, string workingDir) |
---|
[304] | 20 | { |
---|
[386] | 21 | if ( !initComputationLimits(numeroDeb,numeroFin) ) return false; |
---|
[304] | 22 | |
---|
[386] | 23 | if ( numeroDeb_ != numeroFin_ ) return false; |
---|
| 24 | |
---|
[304] | 25 | abstractElement* elPtr; |
---|
[386] | 26 | elPtr = dataManager_->getElementPointerFromNumero(numeroDeb_); |
---|
[304] | 27 | |
---|
| 28 | if ( elPtr->getNomdElement().getElementType() != RFgun ) { |
---|
[313] | 29 | dataManager_->consoleMessage(" softwareGenerator::createInputFile : the element must be rfgun " ); |
---|
[304] | 30 | cerr << " softwareGenerator::createInputFile : the element must be rfgun" << endl; |
---|
| 31 | return false; |
---|
| 32 | } |
---|
[342] | 33 | |
---|
[304] | 34 | ofstream outfile; |
---|
[316] | 35 | string name = workingDir + inputFileName_; |
---|
[304] | 36 | outfile.open(name.c_str(), ios::out); |
---|
| 37 | if (!outfile) { |
---|
[313] | 38 | dataManager_->consoleMessage(" softwareGenerator::createInputFile : error opening output stream " ); |
---|
[304] | 39 | cerr << " error opening output stream " << name << endl; |
---|
| 40 | return false; |
---|
| 41 | } |
---|
| 42 | outfile << "&INPUT" << endl; |
---|
| 43 | string fichier = "'" + workingDir + "faisceau.ini" + "'"; |
---|
| 44 | outfile << " FNAME = " << fichier << endl; |
---|
| 45 | outfile << " Add=FALSE, N_add=0" << endl; |
---|
| 46 | outfile << " Species='electrons'" << endl; |
---|
| 47 | outfile << elPtr->generatorOutputFlow() << endl; |
---|
| 48 | outfile << "/" << endl; |
---|
| 49 | outfile.close(); |
---|
[313] | 50 | dataManager_->consoleMessage("fichier input termine pour GENERATOR"); |
---|
[304] | 51 | return true; |
---|
| 52 | } |
---|
[312] | 53 | |
---|
[386] | 54 | bool softwareGenerator::execute(string workingDir) { |
---|
[342] | 55 | |
---|
| 56 | bool ExecuteStatus = true; |
---|
| 57 | |
---|
[312] | 58 | ostringstream sortie; |
---|
[386] | 59 | sortie << " EXECUTION DE GENERATOR DE l'ELEMENT " << numeroDeb_ << " A L'ELEMENT " << numeroFin_ << endl; |
---|
[312] | 60 | |
---|
| 61 | string generatorJob = workingDir + "generator"; |
---|
| 62 | generatorJob += string(" "); |
---|
[316] | 63 | generatorJob += workingDir + inputFileName_; |
---|
[312] | 64 | |
---|
| 65 | string resultOfRun; |
---|
[342] | 66 | bool success = launchJob(generatorJob,resultOfRun); |
---|
[312] | 67 | sortie << resultOfRun << endl; |
---|
[342] | 68 | if ( !success ) { |
---|
[312] | 69 | sortie << " launching of generator failed " << endl; |
---|
| 70 | ExecuteStatus = false; |
---|
[342] | 71 | } else { |
---|
[312] | 72 | cout << " execution generator MARCHE " << endl; |
---|
| 73 | sortie << resultOfRun; |
---|
[342] | 74 | string nameOut = workingDir + "generator.output"; |
---|
| 75 | ofstream outfile; |
---|
[312] | 76 | outfile.open(nameOut.c_str(), ios::out); |
---|
[342] | 77 | if (!outfile) { |
---|
| 78 | sortie << " error first opening transport output stream " << nameOut << endl; |
---|
| 79 | ExecuteStatus = false; |
---|
| 80 | } else { |
---|
[312] | 81 | // on copie la sortie dans un fichier 'generator.out' |
---|
| 82 | outfile << resultOfRun << endl; |
---|
| 83 | outfile.close(); |
---|
| 84 | } |
---|
| 85 | } |
---|
[342] | 86 | |
---|
| 87 | dataManager_->consoleMessage(sortie.str()); |
---|
[312] | 88 | return ExecuteStatus; |
---|
| 89 | } |
---|
| 90 | |
---|
[386] | 91 | bool softwareGenerator::buildBeamAfterElements( string workingDir) { |
---|
[312] | 92 | |
---|
| 93 | bool result = true; |
---|
[386] | 94 | if ( !ComputationLimitsOk() ) return false; |
---|
| 95 | |
---|
| 96 | if ( numeroDeb_ != numeroFin_ ) { |
---|
[313] | 97 | dataManager_->consoleMessage(" softwareGenerator::buildBeamAfterElements : only one element (rfgun) must be calculated " ); |
---|
| 98 | return false; |
---|
| 99 | } |
---|
[386] | 100 | // on initialise une nouvelle sortie diagnostic |
---|
| 101 | particleBeam* newDiag = dataManager_->updateCurrentDiagnostic(true); |
---|
[312] | 102 | |
---|
[386] | 103 | // beams.push_back(particleBeam()); |
---|
[312] | 104 | vector<double> centroid; |
---|
| 105 | bareParticle refPart; |
---|
| 106 | vector<bareParticle> particles; |
---|
| 107 | vector<bareParticle> particlesPassives; // on ne fait rien de ces particules pour l'instant |
---|
| 108 | if (beamFromGenerator(string("faisceau.ini"),workingDir, centroid, refPart,particles, particlesPassives )) { |
---|
[386] | 109 | newDiag->setWithParticles(centroid, refPart,particles); |
---|
[312] | 110 | } else { |
---|
[313] | 111 | dataManager_->consoleMessage(" softwareGenerator::buildBeamAfterElements : error " ); |
---|
[312] | 112 | result = false; |
---|
| 113 | } |
---|
| 114 | return result; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | bool softwareGenerator::beamFromGenerator(string beamFileName, string workingDir, vector<double>& centroid, bareParticle& refPart,vector<bareParticle>& particles, vector<bareParticle>& passiveParticles ) { |
---|
| 118 | unsigned k; |
---|
| 119 | FILE* filefais; |
---|
| 120 | string nomfilefais = workingDir + beamFileName; |
---|
| 121 | cout << " nom fichier sortie generator : " << nomfilefais << endl; |
---|
| 122 | filefais = fopen(nomfilefais.c_str(), "r"); |
---|
| 123 | if ( filefais == (FILE*)0 ) { |
---|
[313] | 124 | dataManager_->consoleMessage(" softwareGenerator::beamFromGenerator : error openig the file " + nomfilefais ); |
---|
[312] | 125 | cerr << " beamFromGenerator() erreur a l'ouverture du fichier" << nomfilefais << endl;; |
---|
| 126 | return false; |
---|
| 127 | } |
---|
| 128 | else cout << " beamFromGenerator() : ouverture du fichier " << nomfilefais << endl; |
---|
| 129 | |
---|
| 130 | generatorParticle partic; |
---|
| 131 | std::vector<generatorParticle> faisceau; |
---|
| 132 | int nbProbPart =0; |
---|
| 133 | double timeRef = 0.0; |
---|
| 134 | double betagammaZRef = 0.0; |
---|
| 135 | // lecture part. de reference |
---|
| 136 | if ( partic.readFromGeneratorFile(filefais) > 0 ) |
---|
| 137 | { |
---|
| 138 | if ( partic.index != 1 ) { |
---|
[313] | 139 | dataManager_->consoleMessage(" softwareGenerator::beamFromGenerator : particles are not electrons, we have to reconsider this method beamFromGenerator" ); |
---|
| 140 | cout << " ERROR softwareGenerator::beamFromGenerator : particles are not electrons, we have to reconsider this method " << endl; |
---|
[312] | 141 | return false; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if ( partic.flag != -1 ) { |
---|
| 145 | cout << " ATTENTION softwareGenerator::beamFromGenerator : flag different de -1 " << endl; |
---|
| 146 | } |
---|
| 147 | if (fabs(partic.xx) > EPSILON || fabs(partic.yy) > EPSILON || fabs(partic.px) > EPSILON || fabs(partic.py) > EPSILON) { |
---|
| 148 | printf(" ATTENTION softwareGenerator::beamFromGenerator : part. reference douteuse \n"); |
---|
| 149 | partic.imprim(); |
---|
| 150 | } |
---|
| 151 | timeRef = partic.clock; |
---|
| 152 | TRIDVECTOR posRef(100.*partic.xx,100.*partic.yy,100.*partic.zz); // en cm |
---|
[356] | 153 | betagammaZRef = partic.pz/EREST_eV; |
---|
[312] | 154 | // l'impulsion donnee par generator est en eV/c |
---|
[356] | 155 | TRIDVECTOR betagammaRef(partic.px/EREST_eV , partic.py/EREST_eV, betagammaZRef); |
---|
[312] | 156 | refPart = bareParticle(posRef, betagammaRef); |
---|
| 157 | |
---|
| 158 | // seule la part. de reference a un pz absolu (les autres pat. on un pz relatif a la ref) |
---|
| 159 | // je mets ici a zero, pour homogeneiser |
---|
| 160 | partic.pz = 0.0; |
---|
| 161 | faisceau.push_back(partic); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | while( partic.readFromGeneratorFile(filefais) > 0 ) { |
---|
| 165 | faisceau.push_back(partic); |
---|
| 166 | if ( partic.flag != -1 ) nbProbPart++; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | if ( faisceau.size() == 0) |
---|
| 170 | { |
---|
[313] | 171 | dataManager_->consoleMessage(" softwareGenerator::beamFromGenerator : error no particle found" ); |
---|
[312] | 172 | cerr << " softwareGenerator::beamFromGenerator echec lecture " << endl; |
---|
| 173 | return false; |
---|
| 174 | } |
---|
| 175 | // pour l'instant on choisit un centroid nul; |
---|
| 176 | centroid.clear(); |
---|
| 177 | centroid = vector<double>(6,0.0); |
---|
| 178 | |
---|
| 179 | particles.clear(); |
---|
| 180 | passiveParticles.clear(); |
---|
| 181 | // particles.resize(faisceau.size() - nbProbPart, bareParticle()); |
---|
| 182 | // passiveParticles.resize(nbProbPart, bareParticle()); |
---|
| 183 | double x,y; |
---|
| 184 | double deltaz; |
---|
| 185 | double deltat; |
---|
| 186 | TRIDVECTOR pos; |
---|
| 187 | TRIDVECTOR betagamma; |
---|
| 188 | double pxPart; |
---|
| 189 | double pyPart; |
---|
| 190 | double pzPartRel; |
---|
| 191 | double deltaPzPart; |
---|
| 192 | |
---|
| 193 | for ( k=0; k < faisceau.size(); k++) { |
---|
| 194 | |
---|
| 195 | pxPart = faisceau.at(k).px; |
---|
| 196 | pyPart = faisceau.at(k).py; |
---|
| 197 | pzPartRel = faisceau.at(k).pz; |
---|
| 198 | deltaPzPart = faisceau.at(k).pz; |
---|
| 199 | x=faisceau.at(k).xx; |
---|
| 200 | y=faisceau.at(k).yy; |
---|
| 201 | |
---|
| 202 | // tout ce qui suit sera a clarifier |
---|
[356] | 203 | double betaGammax = pxPart/EREST_eV; |
---|
| 204 | double betaGammay = pyPart/EREST_eV; |
---|
| 205 | double betaGammaz = betagammaZRef + pzPartRel/EREST_eV; |
---|
[312] | 206 | betagamma.setComponents(betaGammax, betaGammay, betaGammaz); |
---|
| 207 | double gamma = sqrt(1.0 + betagamma.norm2()); |
---|
| 208 | |
---|
| 209 | // decalage temporel par rapport a la reference |
---|
| 210 | deltat = faisceau.at(k).clock - timeRef; // nanoseondes |
---|
| 211 | double ds = CLIGHT_m_per_ns * deltat /gamma; |
---|
| 212 | x += betaGammax * ds; // en metres |
---|
| 213 | y += betaGammay * ds; |
---|
| 214 | |
---|
| 215 | // ici on neglige la difference entre gamma de la part. et gamma de la ref. |
---|
[356] | 216 | deltaz = (pzPartRel/EREST_eV) * CLIGHT_m_per_ns * deltat; // en metres |
---|
[312] | 217 | |
---|
| 218 | pos.setComponents(100.*x,100.*y,100.*deltaz); // en cm |
---|
| 219 | if ( faisceau.at(k).flag == -1 ) { |
---|
| 220 | particles.push_back(bareParticle(pos,betagamma)); |
---|
| 221 | } else { |
---|
| 222 | passiveParticles.push_back(bareParticle(pos,betagamma)); |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | return true; |
---|
| 228 | } |
---|