1 | |
---|
2 | #include <iostream> |
---|
3 | |
---|
4 | #include "elementDrift.h" |
---|
5 | #include "mathematicalTools.h" |
---|
6 | #include "mixedTools.h" |
---|
7 | |
---|
8 | elementDrift::elementDrift() : abstractElement() |
---|
9 | { |
---|
10 | setDefaultValues(); |
---|
11 | setDefaults(); |
---|
12 | elementName_ = nomdElements("drift"); |
---|
13 | nbParam_ = elementName_.getElementNbParameters(); |
---|
14 | parametersString_ = new string[nbParam_+1]; |
---|
15 | registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
16 | registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
17 | registerAcceptableSoftware(nomDeLogiciel::test, TBoolOk); |
---|
18 | |
---|
19 | } |
---|
20 | |
---|
21 | void elementDrift::setDefaultValues() |
---|
22 | { |
---|
23 | defaultLabel_ = "drift"; |
---|
24 | } |
---|
25 | void elementDrift::setDefaults() |
---|
26 | { |
---|
27 | label_ = defaultLabel_; |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | string* elementDrift::getParametersString() const |
---|
32 | { |
---|
33 | int compteur = -1; |
---|
34 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
35 | parametersString_[++compteur] = label_; |
---|
36 | parametersString_[++compteur] = mixedTools::doubleToString(lenghtElem_); |
---|
37 | parametersString_[++compteur] = mixedTools::doubleToString(aperture_); |
---|
38 | if ( compteur != nbParam_ ) { |
---|
39 | cerr << " elementDrift::getParametersString() : ERROR nr pf parameters dosnt match " << endl; |
---|
40 | return NULL; |
---|
41 | } |
---|
42 | return parametersString_; |
---|
43 | } |
---|
44 | |
---|
45 | void elementDrift::setParametersString(string* param) |
---|
46 | { |
---|
47 | if ( param == NULL ) |
---|
48 | { |
---|
49 | cerr << " elementDrift::setParametersString parameters empty parameter set"; |
---|
50 | return; |
---|
51 | } |
---|
52 | int compteur = -1; |
---|
53 | int nbparam = atoi(param[++compteur].c_str()); |
---|
54 | if ( nbparam != nbParam_ ) |
---|
55 | { |
---|
56 | cerr << " elementDrift::setParametersString parameters do not match for a DRIFT"; |
---|
57 | return; |
---|
58 | } |
---|
59 | label_ = param[++compteur]; |
---|
60 | lenghtElem_ = atof(param[++compteur].c_str()); |
---|
61 | aperture_ = atof(param[++compteur].c_str()); |
---|
62 | } |
---|
63 | |
---|
64 | string elementDrift::parmelaOutputFlow() const |
---|
65 | { |
---|
66 | ostringstream sortie; |
---|
67 | sortie << "DRIFT /l=" << lenghtElem_ << " /aper=" << aperture_ << " /iout=1" << endl; |
---|
68 | return sortie.str(); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | string elementDrift::transportOutputFlow() const |
---|
73 | { |
---|
74 | ostringstream sortie; |
---|
75 | // longueur en m |
---|
76 | sortie << label_ << ":" << " DRIFT, L=" << 0.01*lenghtElem_ << ";" << endl; |
---|
77 | return sortie.str(); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | string elementDrift::FileOutputFlow() const |
---|
82 | { |
---|
83 | ostringstream sortie; |
---|
84 | // sortie << elementName_.getElementType() << endl; |
---|
85 | sortie << elementName_.getElementLabel() << endl; |
---|
86 | sortie << label_ << endl; |
---|
87 | sortie << lenghtElem_ << " " << aperture_ <<endl; |
---|
88 | return sortie.str(); |
---|
89 | } |
---|
90 | |
---|
91 | void elementDrift::FileInput(ifstream& ifs) |
---|
92 | { |
---|
93 | ifs >> label_; |
---|
94 | ifs >> lenghtElem_ >> aperture_; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | string elementDrift::print() { |
---|
99 | string txt = ""; |
---|
100 | |
---|
101 | txt += label_; |
---|
102 | txt += "\nlength (cm) : "; |
---|
103 | txt += mixedTools::doubleToString(lenghtElem_); |
---|
104 | txt += "\naperture (cm) : "; |
---|
105 | txt += mixedTools::doubleToString(aperture_); |
---|
106 | |
---|
107 | return txt; |
---|
108 | } |
---|