Changeset 484 in PSPA


Ignore:
Timestamp:
Jan 22, 2014, 3:43:41 PM (10 years ago)
Author:
touze
Message:

softawareMadx:: faisceau donné par l'élément beam

Location:
Interface_Web/trunk/pspaWT/sources/controler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/sources/controler/include/softwareMadx.h

    r482 r484  
    88class softwareMadx : public abstractSoftware
    99{
    10   string BEAMcommand(particleBeam*) const;
    11   string RFGunData(const vector<statements>&) const;
     10  string emittances(const beam2Moments&) const;
     11  string beamData(particleBeam*) const;
     12  string beamData(const vector<statements>&) const;
     13  string RFgunData(const vector<statements>&) const;
    1214  string inputFormat(const vector<statements>&) const;
    1315
  • Interface_Web/trunk/pspaWT/sources/controler/src/softwareMadx.cc

    r482 r484  
    55#include "mathematicalConstants.h"
    66#include "PhysicalConstants.h"
     7
     8#include <boost/filesystem.hpp>
    79
    810softwareMadx::softwareMadx() : abstractSoftware()
     
    4345  abstractElement* elPtr;
    4446  elPtr = getSectionToExecute()->getElements().front();
    45 
    46   // le 1er elt n'est pas RFGun
    47   if(elPtr->getNomdElement().getElementType() != nomdElements::RFgun) {
    48    
     47  nomdElements::typedElement eType = elPtr->getNomdElement().getElementType();
     48
     49  if(eType == nomdElements::RFgun) {
     50    // le 1er elt est RFgun
     51    firstIndex = 1;
     52    dataManager_->consoleMessage(" softwareMadx::createInputFile : set from RF cavity the quantities to be supplied to the madx BEAM command");
     53    sbeam = RFgunData(elPtr->parametersToSoftware());
     54  } else if(eType == nomdElements::beam) {
     55    // le 1er elt est beam
     56    firstIndex = 1;
     57    dataManager_->consoleMessage(" softwareMadx::createInputFile : set from beam the quantities to be supplied to the madx BEAM command");
     58    sbeam = beamData(elPtr->parametersToSoftware());
     59  } else {
     60    // on suppose qu'il y a déjà un faisceau
    4961    if(beamBefore == NULL) {
    5062      // il n'y a pas de faisceau : erreur
     
    6779        return false;
    6880      }
    69 
    70       sbeam = BEAMcommand(beamBefore);
     81      sbeam = beamData(beamBefore);
    7182    }
    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());
    7883  }
    7984  ///////////////////////////////////////////
     
    121126}
    122127
    123 string softwareMadx::BEAMcommand(particleBeam* beam) const
    124 {
    125   // le 20 décembre : les commandes BEAM de madx sont :
     128string softwareMadx::beamData(const vector<statements>& v) const
     129{
     130  // x  (cm)   = v.at(1).second.at(0)
     131  // xp (mrad) = v.at(1).second.at(1)
     132  // y  (cm)   = v.at(1).second.at(2)
     133  // yp (mrad) = v.at(1).second.at(3)
     134  // dl  (cm)   = v.at(2).second.at(0)
     135  // del (mrad) = v.at(2).second.at(1)
     136  // p0 (GeV/c) = v.at(3).second.at(0)
     137 
     138  ostringstream os;
     139  os << "beam, PARTICLE = ELECTRON";
     140
     141  double PC = atof(v.at(3).second.at(0).c_str());
     142  os << ", ENERGY = " << PC; // momentum of the central trajectory [GeV/c]
     143
     144  double x  = atof(v.at(1).second.at(0).c_str());
     145  double xp = atof(v.at(1).second.at(1).c_str());
     146  double y  = atof(v.at(1).second.at(2).c_str());
     147  double yp = atof(v.at(1).second.at(3).c_str());
     148  double dl = atof(v.at(2).second.at(0).c_str());
     149  double del= atof(v.at(2).second.at(1).c_str());
     150  beam2Moments mts(x,xp,y,yp,dl,del);
     151  os << emittances(mts) << ";";
     152  return os.str(); 
     153}
     154
     155string softwareMadx::beamData(particleBeam* beam) const
     156{
     157  // les commandes BEAM de madx sont :
    126158  // PARTICLE (defaut POSITRON)
    127159  // ENERGY (defaut 1 GeV) ou bien PC GeV/c
     
    132164  os << "beam, PARTICLE = ELECTRON";
    133165
    134   double pc = beam->getP0Transport();
    135   os << ", ENERGY = " << pc; // en GeV
     166  double PC = beam->getP0Transport();
     167  os << ", ENERGY = " << PC; // en GeV/c
    136168
    137169  const beam2Moments& mts = beam->getTransportMoments();
     170  os << emittances(mts) << ";";
     171  return os.str();
     172}
     173
     174string softwareMadx::emittances(const beam2Moments& mts) const
     175{
    138176  const vector< vector<double> > rij= mts.getMoments();
     177  ostringstream os;
    139178
    140179  // emittance (x,x')
     
    153192  os << ", EY = " << EY*1.E-05;
    154193
    155   os << ";";
    156194  return os.str();
    157195}
    158196
    159 string softwareMadx::RFGunData(const vector<statements>& v) const
     197string softwareMadx::RFgunData(const vector<statements>& v) const
    160198{
    161199  //NPART = v.at(1).second.at(0);
     
    228266
    229267  dataManager_->consoleMessage(" softwareMadx::execute");
     268  ostringstream sortie;
    230269  bool status= true;
    231 
    232   ostringstream sortie;
    233   sortie << " run madx " << endl;
    234 
    235270  string mjob = workingDir + "madx64";
    236   mjob += string(" <  ");
    237   mjob += workingDir + inputFileName_;
    238   cout << " job madx = " << mjob << endl;
    239  
    240   string resultOfRun;
    241   bool success = launchJob(mjob,resultOfRun);
    242   // xx sortie << resultOfRun << endl;
    243   if ( !success ) {
    244     //sortie << " launching of madx failed " << endl;
     271 
     272  if(!boost::filesystem::exists(mjob.c_str())) { 
     273    sortie << "Error:: " << mjob << " does not exist\n";
    245274    status = false;
    246275  } else {
    247     sortie << " madx finished normally" << endl;
    248     string nameOut = workingDir + "madx.output";
    249     ofstream outfile;
    250     outfile.open(nameOut.c_str(),ios::out);
    251     if (!outfile) {
    252       sortie << " error in opening madx output stream " << nameOut << endl;
     276    mjob += string(" <  ");
     277    mjob += workingDir + inputFileName_;
     278    sortie << " run " << mjob << endl;
     279    string resultOfRun;
     280    bool success = launchJob(mjob,resultOfRun);
     281    // xx sortie << resultOfRun << endl;
     282    if ( !success ) {
     283      //sortie << " launching of madx failed " << endl;
    253284      status = false;
    254285    } else {
    255       // on copie la sortie dans un fichier 'madx.out'
    256       outfile << resultOfRun << endl;
    257       outfile.close();
     286      sortie << " madx finished normally" << endl;
     287      string nameOut = workingDir + "madx.output";
     288      ofstream outfile;
     289      outfile.open(nameOut.c_str(),ios::out);
     290      if (!outfile) {
     291        sortie << " error in opening madx output stream " << nameOut << endl;
     292        status = false;
     293      } else {
     294        // on copie la sortie dans un fichier 'madx.out'
     295        outfile << resultOfRun << endl;
     296        outfile.close();
     297      }
    258298    }
    259299  }
     
    263303}
    264304
    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 
    274305bool softwareMadx::buildBeamAfterElements(string workingDir)
    275306{
Note: See TracChangeset for help on using the changeset viewer.