source: PSPA/Interface_Web/trunk/pspaWT/sources/controler/src/elementBeam.cc @ 418

Last change on this file since 418 was 418, checked in by lemeur, 11 years ago

definition des compatibilites des elements dans les software

File size: 5.6 KB
Line 
1#include "elementBeam.h"
2#include "beam2Moments.h"
3#include "mixedTools.h"
4
5elementBeam::elementBeam() :  abstractElement() {
6    setDefaultValues();
7    setDefaults();
8    elementName_ = nomdElements("beam");
9    nbParam_ = elementName_.getElementNbParameters();
10    parametersString_ = new string[nbParam_+1];
11    //  transportOk_ = true;
12    //    registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk);
13}
14
15elementBeam::~elementBeam() {;}
16
17void elementBeam::setDefaultValues() {
18    defaultSpecificName_ = "beam";
19    xDef_ = 0.0;
20    xpDef_ = 0.0;
21    yDef_ = 0.0;
22    ypDef_ = 0.0;
23    dlDef_ = 0.0;
24    delDef_ = 0.0;
25    p0Def_ = 0.0;
26}
27
28void elementBeam::setDefaults() {
29    specificName_ = defaultSpecificName_;
30    x_ = xDef_;
31    xp_ = xpDef_;
32    y_ = yDef_;
33    yp_ = ypDef_;
34    dl_ = dlDef_;
35    del_ = delDef_;
36    p0_ = p0Def_;
37}
38
39
40string* elementBeam::getParametersString() const {
41    int compteur = -1;
42    parametersString_[++compteur] = mixedTools::intToString(nbParam_);
43    parametersString_[++compteur] = specificName_;
44    parametersString_[++compteur] = mixedTools::doubleToString(x_);
45    parametersString_[++compteur] = mixedTools::doubleToString(xp_);
46    parametersString_[++compteur] = mixedTools::doubleToString(y_);
47    parametersString_[++compteur] = mixedTools::doubleToString(yp_);
48    parametersString_[++compteur] = mixedTools::doubleToString(dl_);
49    parametersString_[++compteur] = mixedTools::doubleToString(del_);
50    parametersString_[++compteur] = mixedTools::doubleToString(p0_);
51    if ( compteur != nbParam_ ) {
52        cerr << " elementBeam::getParametersString() : ERROR nr pf parameters doesnt match " << endl;
53        return NULL;
54    }
55    return parametersString_;
56}
57
58
59
60
61void elementBeam::setParametersString(string* param) {
62    if ( param == NULL )
63    {
64        cerr << "  elementBeam::setParametersString parameters empty parameter set";
65        return;
66    }
67    int compteur = -1;
68    int nbparam = atoi(param[++compteur].c_str());
69    if ( nbparam != nbParam_ )
70    {
71        cerr << "  elementBeam::setParametersString parameters do not match for a BEAM";
72        return;
73    }
74   
75    specificName_ = param[++compteur];
76    x_ = atof(param[++compteur].c_str());
77    xp_ = atof(param[++compteur].c_str());
78    y_ = atof(param[++compteur].c_str());
79    yp_ = atof(param[++compteur].c_str());
80    dl_ = atof(param[++compteur].c_str());
81    del_ = atof(param[++compteur].c_str());
82    p0_ = atof(param[++compteur].c_str());
83}
84
85// string elementBeam::parmelaOutputFlow() const
86// {
87//     ostringstream sortie;
88//     cout << " BEAM sortie parmela non programmee " << endl;
89//     return sortie.str();
90// }
91
92// string elementBeam::transportOutputFlow() const {
93//     ostringstream sortie;
94//     beam2Moments moments(x_, xp_, y_, yp_, dl_, del_);
95//     cout << " elementBeam::transportOutputFlow(), p0 = " << p0_ << endl;
96//     sortie << specificName_ << ":" << moments.writeToTransportInput(p0_) << endl;
97//     return sortie.str();
98// }
99
100string elementBeam::FileOutputFlow() const {
101    ostringstream sortie;
102    // sortie << elementName_.getElementType() << endl;
103    sortie << elementName_.getGenericLabel() << endl;
104    sortie  << specificName_ << endl;
105    sortie << x_ << "  " << xp_ << " " <<  y_  << " " <<  yp_  << endl;
106    sortie << dl_ << "  " << del_ << " " <<  p0_  << endl;
107    cout << " elementBeam::FileOutputFlow, p0 = " << p0_ << endl;
108    return sortie.str();
109}
110
111vector< pair<string, vector<string> > > elementBeam::parametersToSoftware () const {
112  vector< pair<string, vector<string> > >  sortie;
113  sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific",  vector<string>() ) );
114  sortie.back().second.push_back(elementName_.getGenericLabel());
115  sortie.back().second.push_back(specificName_);
116  sortie.push_back( pair<string, vector<string> >("transverseCoordinates",  vector<string>() ) );
117  sortie.back().second.push_back(mixedTools::doubleToString(x_));
118  sortie.back().second.push_back(mixedTools::doubleToString(xp_));
119  sortie.back().second.push_back(mixedTools::doubleToString(y_));
120  sortie.back().second.push_back(mixedTools::doubleToString(xp_));
121  sortie.push_back( pair<string, vector<string> >("longitudinalCoordinates",  vector<string>() ) );
122  sortie.back().second.push_back(mixedTools::doubleToString(dl_));
123  sortie.back().second.push_back(mixedTools::doubleToString(del_));                 
124  sortie.push_back( pair<string, vector<string> >("momentum",  vector<string>() ) );
125  sortie.back().second.push_back(mixedTools::doubleToString(p0_));
126  return sortie;
127}
128
129
130void elementBeam::elementBeam::FileInput(ifstream& ifs) {
131    ifs >> specificName_;
132    ifs >> x_ >> xp_ >>  y_ >> yp_;
133    ifs >> dl_ >> del_ >> p0_;
134    cout << " elementBeam::FileFileInput, p0 = " << p0_ << endl;
135    lenghtElem_ = getLenghtOfElement();
136    cout << " elementBeam::FileInput calcule longueur = " << lenghtElem_ << endl;
137}
138
139
140string elementBeam::print() {
141    string txt = "";
142    txt += specificName_;
143    txt += "\n 1/2 horizontal beam extend rms (cm) : ";
144    txt += mixedTools::doubleToString(x_);
145    txt += "\n 1/2 horizontal beam divergence rms (mrad) : ";
146    txt += mixedTools::doubleToString(xp_);
147    txt += "\n1/2 vertical beam extend rms (cm) : ";
148    txt += mixedTools::doubleToString(y_);
149    txt += "\n1/2 horizontal beam divergence rms (mrad) : ";
150    txt += mixedTools::doubleToString(yp_);
151    txt += "\n1/2 longitudinal beam extend rms (cm) : ";
152    txt += mixedTools::doubleToString(dl_);
153    txt += "\n1/2 momentum spread rms (mrad) : ";
154    txt += mixedTools::doubleToString(del_);
155    txt += "\nmomentum of the central trajectory (GeV/c) : ";
156    txt += mixedTools::doubleToString(p0_);
157   
158    return txt;
159}
Note: See TracBrowser for help on using the repository browser.