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

Last change on this file since 359 was 359, checked in by garnier, 11 years ago

Changement de la couleur des sections selectionnes + plein dautres choses

File size: 4.4 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    defaultLabel_ = "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    label_ = defaultLabel_;
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] = label_;
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
58void elementBeam::setParametersString(string* param) {
59    if ( param == NULL )
60    {
61        cerr << "  elementBeam::setParametersString parameters empty parameter set";
62        return;
63    }
64    int compteur = -1;
65    int nbparam = atoi(param[++compteur].c_str());
66    if ( nbparam != nbParam_ )
67    {
68        cerr << "  elementBeam::setParametersString parameters do not match for a BEAM";
69        return;
70    }
71   
72    label_ = param[++compteur];
73    x_ = atof(param[++compteur].c_str());
74    xp_ = atof(param[++compteur].c_str());
75    y_ = atof(param[++compteur].c_str());
76    yp_ = atof(param[++compteur].c_str());
77    dl_ = atof(param[++compteur].c_str());
78    del_ = atof(param[++compteur].c_str());
79    p0_ = atof(param[++compteur].c_str());
80}
81
82string elementBeam::parmelaOutputFlow() const
83{
84    ostringstream sortie;
85    cout << " BEAM sortie parmela non programmee " << endl;
86    return sortie.str();
87}
88
89string elementBeam::transportOutputFlow() const {
90    ostringstream sortie;
91    beam2Moments moments(x_, xp_, y_, yp_, dl_, del_);
92    cout << " elementBeam::transportOutputFlow(), p0 = " << p0_ << endl;
93    sortie << label_ << ":" << moments.writeToTransportInput(p0_);
94    return sortie.str();
95}
96
97string elementBeam::FileOutputFlow() const {
98    ostringstream sortie;
99    // sortie << elementName_.getElementType() << endl;
100    sortie << elementName_.getElementLabel() << endl;
101    sortie  << label_ << endl;
102    sortie << x_ << "  " << xp_ << " " <<  y_  << " " <<  yp_  << endl;
103    sortie << dl_ << "  " << del_ << " " <<  p0_  << endl;
104    cout << " elementBeam::FileOutputFlow, p0 = " << p0_ << endl;
105    return sortie.str();
106}
107
108void elementBeam::elementBeam::FileInput(ifstream& ifs) {
109    ifs >> label_;
110    ifs >> x_ >> xp_ >>  y_ >> yp_;
111    ifs >> dl_ >> del_ >> p0_;
112    cout << " elementBeam::FileFileInput, p0 = " << p0_ << endl;
113    lenghtElem_ = getLenghtOfElement();
114    cout << " elementBeam::FileInput calcule longueur = " << lenghtElem_ << endl;
115}
116
117
118string elementBeam::print() {
119    string txt = "";
120    txt += label_;
121    txt += "\n 1/2 horizontal beam extend rms (cm) : ";
122    txt += mixedTools::doubleToString(x_);
123    txt += "\n 1/2 horizontal beam divergence rms (mrad) : ";
124    txt += mixedTools::doubleToString(xp_);
125    txt += "\n1/2 vertical beam extend rms (cm) : ";
126    txt += mixedTools::doubleToString(y_);
127    txt += "\n1/2 horizontal beam divergence rms (mrad) : ";
128    txt += mixedTools::doubleToString(yp_);
129    txt += "\n1/2 longitudinal beam extend rms (cm) : ";
130    txt += mixedTools::doubleToString(dl_);
131    txt += "\n1/2 momentum spread rms (mrad) : ";
132    txt += mixedTools::doubleToString(del_);
133    txt += "\nmomentum of the central trajectory (GeV/c) : ";
134    txt += mixedTools::doubleToString(p0_);
135   
136    return txt;
137}
Note: See TracBrowser for help on using the repository browser.