1 | #include "elementSoleno.h" |
---|
2 | #include "mixedTools.h" |
---|
3 | |
---|
4 | |
---|
5 | elementSoleno::elementSoleno() : abstractElement() |
---|
6 | { |
---|
7 | cout << " passage constructeur elementSoleno " << endl; |
---|
8 | setDefaultValues(); |
---|
9 | setDefaults(); |
---|
10 | elementName_ = nomdElements("soleno"); |
---|
11 | nbParam_ = elementName_.getElementNbParameters(); |
---|
12 | parametersString_ = new string[nbParam_+1]; |
---|
13 | // registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
14 | // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
15 | } |
---|
16 | |
---|
17 | void elementSoleno::setDefaultValues() |
---|
18 | { |
---|
19 | defaultSpecificName_ = "solnd"; |
---|
20 | B0Def_ = 0.0; |
---|
21 | varyB0Def_ = false; |
---|
22 | } |
---|
23 | |
---|
24 | void elementSoleno::setDefaults() |
---|
25 | { |
---|
26 | specificName_ = defaultSpecificName_; |
---|
27 | B0_ = B0Def_; |
---|
28 | varyB0_ = varyB0Def_; |
---|
29 | } |
---|
30 | |
---|
31 | string* elementSoleno::getParametersString() const |
---|
32 | { |
---|
33 | cout << " passage elementSoleno::getParametersString() B0_= " << B0_ << endl; |
---|
34 | int compteur = -1; |
---|
35 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
36 | parametersString_[++compteur] = specificName_; |
---|
37 | parametersString_[++compteur] = mixedTools::doubleToString(lenghtElem_); |
---|
38 | parametersString_[++compteur] = mixedTools::doubleToString(aperture_); |
---|
39 | parametersString_[++compteur] = mixedTools::doubleToString(B0_); |
---|
40 | parametersString_[++compteur] = mixedTools::intToString(varyB0_); |
---|
41 | if ( compteur != nbParam_ ) { |
---|
42 | cerr << " elementSoleno::getParametersString() : ERROR nr pf parameters dosnt match " << endl; |
---|
43 | return NULL; |
---|
44 | } |
---|
45 | return parametersString_; |
---|
46 | } |
---|
47 | |
---|
48 | void elementSoleno::setParametersString(string* param) |
---|
49 | { |
---|
50 | if ( param == NULL ) { |
---|
51 | cerr << " elementSoleno::setParametersString parameters empty parameter set"; |
---|
52 | return; |
---|
53 | } |
---|
54 | int compteur = -1; |
---|
55 | int nbparam = atoi(param[++compteur].c_str()); |
---|
56 | if ( nbparam != nbParam_ ) { |
---|
57 | cerr << " elementSoleno::setParametersString parameters do not match for a SOLENOID"; |
---|
58 | return; |
---|
59 | } |
---|
60 | specificName_ = param[++compteur]; |
---|
61 | lenghtElem_ = atof(param[++compteur].c_str()); |
---|
62 | aperture_ = atof(param[++compteur].c_str()); |
---|
63 | B0_ = atof(param[++compteur].c_str()); |
---|
64 | varyB0_ = atoi(param[++compteur].c_str()); |
---|
65 | } |
---|
66 | |
---|
67 | // string elementSoleno::parmelaOutputFlow() const |
---|
68 | // { |
---|
69 | // ostringstream sortie; |
---|
70 | // // on passe l'induction magnetique en Gauss |
---|
71 | // sortie << "SOLENOID /l=" << lenghtElem_ << " /aper=" << aperture_ << " /iout=1 /h=" << 1000.*B0_ << endl; |
---|
72 | // return sortie.str(); |
---|
73 | // } |
---|
74 | |
---|
75 | // string elementSoleno::transportOutputFlow() const |
---|
76 | // { |
---|
77 | // ostringstream sortie; |
---|
78 | // // on passe la longueur en metres |
---|
79 | // sortie << specificName_ << ":" << " SOLENOID, L=" << 0.01*lenghtElem_ << ", B=" << B0_ << ";" << endl; |
---|
80 | // if ( varyB0_ ) { |
---|
81 | // sortie << " VARY, " << specificName_+"[B]" << ";" << endl; |
---|
82 | // } |
---|
83 | // return sortie.str(); |
---|
84 | // } |
---|
85 | |
---|
86 | string elementSoleno::FileOutputFlow() const |
---|
87 | { |
---|
88 | ostringstream sortie; |
---|
89 | // sortie << elementName_.getElementType() << endl; |
---|
90 | sortie << elementName_.getGenericLabel() << endl; |
---|
91 | sortie << specificName_ << endl; |
---|
92 | sortie << lenghtElem_ << " " << aperture_<< " " << B0_ << " " << varyB0_ << endl; |
---|
93 | return sortie.str(); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | vector< pair<string, vector<string> > > elementSoleno::parametersToSoftware () const { |
---|
98 | vector< pair<string, vector<string> > > sortie; |
---|
99 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
100 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
101 | sortie.back().second.push_back(specificName_); |
---|
102 | sortie.push_back( pair<string, vector<string> >("lenghtAperture", vector<string>() ) ); |
---|
103 | sortie.back().second.push_back(mixedTools::doubleToString(lenghtElem_)); |
---|
104 | sortie.back().second.push_back(mixedTools::doubleToString(aperture_)); |
---|
105 | sortie.push_back( pair<string, vector<string> >("field", vector<string>() ) ); |
---|
106 | sortie.back().second.push_back(mixedTools::doubleToString(B0_)); |
---|
107 | sortie.push_back( pair<string, vector<string> >("isBvariable", vector<string>() ) ); |
---|
108 | sortie.back().second.push_back(mixedTools::intToString(varyB0_)); |
---|
109 | return sortie; |
---|
110 | } |
---|
111 | |
---|
112 | void elementSoleno::FileInput(ifstream& ifs) |
---|
113 | { |
---|
114 | ifs >> specificName_; |
---|
115 | ifs >> lenghtElem_ >> aperture_ >> B0_ >> varyB0_ ; |
---|
116 | } |
---|
117 | |
---|
118 | string elementSoleno::print() |
---|
119 | { |
---|
120 | string txt = ""; |
---|
121 | txt += specificName_; |
---|
122 | txt += "\nlength (cm) : "; |
---|
123 | txt += mixedTools::doubleToString(lenghtElem_); |
---|
124 | txt += "\naperture (cm) : "; |
---|
125 | txt += mixedTools::doubleToString(aperture_); |
---|
126 | txt += "\nfield (kG) : "; |
---|
127 | txt += mixedTools::doubleToString(B0_); |
---|
128 | txt += "\n : may vary ? "; |
---|
129 | txt += mixedTools::boolToString(varyB0_); |
---|
130 | return txt; |
---|
131 | } |
---|
132 | |
---|
133 | void elementSoleno::InputRep(UAPNode* root) |
---|
134 | { |
---|
135 | UAPNode* ele = root->addChild("element"); |
---|
136 | ele->addAttribute("name",specificName_); |
---|
137 | |
---|
138 | string txt = ""; |
---|
139 | txt = mixedTools::doubleToString(lenghtElem_); |
---|
140 | ele->addChild("length")->addAttribute("design",txt); |
---|
141 | |
---|
142 | // pour Parmela /aper : radius of aperture at exit (gap) |
---|
143 | UAPNode* node = ele->addChild("aperture"); |
---|
144 | node->addAttribute("at","EXIT"); |
---|
145 | node->addAttribute("shape","CIRCLE"); |
---|
146 | txt = mixedTools::doubleToString(aperture_); |
---|
147 | node->addChild("xy_limit")->addAttribute("design",txt); |
---|
148 | |
---|
149 | node = ele->addChild("solenoid"); |
---|
150 | txt = mixedTools::doubleToString(B0_); |
---|
151 | node->addChild("ksol")->addAttribute("design",txt); |
---|
152 | |
---|
153 | // faire varier ou pas l'induction pour l'ajuster |
---|
154 | if ( varyB0_ ) { |
---|
155 | node->addChild("vary")->addAttribute("is_on","true"); |
---|
156 | } else { |
---|
157 | node->addChild("vary")->addAttribute("is_on","false"); |
---|
158 | } |
---|
159 | } |
---|