1 | #include "elementCell.h" |
---|
2 | |
---|
3 | #include <iostream> |
---|
4 | |
---|
5 | #include "mathematicalTools.h" |
---|
6 | #include "mixedTools.h" |
---|
7 | |
---|
8 | |
---|
9 | elementCell::elementCell() : abstractElement() |
---|
10 | { |
---|
11 | setDefaultValues(); |
---|
12 | setDefaults(); |
---|
13 | elementName_ = nomdElements("cell"); |
---|
14 | nbParam_ = elementName_.getElementNbParameters(); |
---|
15 | parametersString_ = new string[nbParam_+1]; |
---|
16 | // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
17 | } |
---|
18 | |
---|
19 | void elementCell::setDefaultValues() |
---|
20 | { |
---|
21 | defaultSpecificName_ = "cell"; |
---|
22 | initialPhaseDef_ = 0.0; |
---|
23 | acceleratingFieldDef_ = 1.0; |
---|
24 | acceleratingShapeFileDef_ = "xxxxxxx"; |
---|
25 | focusingMagFileDef_ = "xxxxxx"; |
---|
26 | offsetMagDef_ = 0.0; |
---|
27 | scaleFactorDef_ = 1.0; |
---|
28 | } |
---|
29 | |
---|
30 | void elementCell::setDefaults() |
---|
31 | { |
---|
32 | specificName_ = defaultSpecificName_; |
---|
33 | initialPhase_ = initialPhaseDef_; |
---|
34 | acceleratingField_ = acceleratingFieldDef_; |
---|
35 | acceleratingShapeFile_ = acceleratingShapeFileDef_; |
---|
36 | focusingMagFile_ = focusingMagFileDef_; |
---|
37 | offsetMag_ = offsetMagDef_; |
---|
38 | scaleFactor_ = scaleFactorDef_; |
---|
39 | } |
---|
40 | |
---|
41 | string* elementCell::getParametersString() const |
---|
42 | { |
---|
43 | int compteur = -1; |
---|
44 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
45 | parametersString_[++compteur] = specificName_; |
---|
46 | parametersString_[++compteur] = mixedTools::doubleToString(lenghtElem_); |
---|
47 | parametersString_[++compteur] = mixedTools::doubleToString(aperture_); |
---|
48 | parametersString_[++compteur] = mixedTools::doubleToString(initialPhase_); |
---|
49 | parametersString_[++compteur] = mixedTools::doubleToString( phaseStepMax_); |
---|
50 | parametersString_[++compteur] = mixedTools::doubleToString(acceleratingField_); |
---|
51 | parametersString_[++compteur] = acceleratingShapeFile_; |
---|
52 | parametersString_[++compteur] = focusingMagFile_; |
---|
53 | parametersString_[++compteur] = mixedTools::doubleToString(offsetMag_); |
---|
54 | parametersString_[++compteur] = mixedTools::doubleToString(scaleFactor_); |
---|
55 | if ( compteur != nbParam_ ) { |
---|
56 | cerr << " elementCell::getParametersString() : ERROR nr pf parameters dosnt match " << endl; |
---|
57 | return NULL; |
---|
58 | } |
---|
59 | return parametersString_; |
---|
60 | } |
---|
61 | |
---|
62 | void elementCell::setParametersString(string* param) |
---|
63 | { |
---|
64 | if ( param == NULL ) { |
---|
65 | cerr << " elementCell::setParametersString parameters empty parameter set"; |
---|
66 | return; |
---|
67 | } |
---|
68 | int compteur = -1; |
---|
69 | int nbparam = atoi(param[++compteur].c_str()); |
---|
70 | if ( nbparam != nbParam_ ) { |
---|
71 | cerr << " elementCell::setParametersString parameters do not match for a CELL"; |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | specificName_ = param[++compteur]; |
---|
76 | lenghtElem_ = atof(param[++compteur].c_str()); |
---|
77 | aperture_ = atof(param[++compteur].c_str()); |
---|
78 | initialPhase_ = atof(param[++compteur].c_str()); |
---|
79 | phaseStepMax_ = atof(param[++compteur].c_str()); |
---|
80 | acceleratingField_ = atof(param[++compteur].c_str()); |
---|
81 | acceleratingShapeFile_ = param[++compteur]; |
---|
82 | focusingMagFile_ = param[++compteur]; |
---|
83 | offsetMag_ = atof(param[++compteur].c_str()); |
---|
84 | scaleFactor_ = atof(param[++compteur].c_str()); |
---|
85 | } |
---|
86 | |
---|
87 | // string elementCell::parmelaOutputFlow() const |
---|
88 | // { |
---|
89 | // ostringstream sortie; |
---|
90 | // sortie << "CELL /l=" << lenghtElem_ << " /aper=" << aperture_ << endl; |
---|
91 | // sortie << " /iout=1 /phi0=" << initialPhase_ << " /E0=" << acceleratingField_ << endl; |
---|
92 | // sortie << " /nc=1 /dwtmax=" << phaseStepMax_ << " /sym=-1" << endl; |
---|
93 | // sortie << "CFIELD 1" << endl; |
---|
94 | // sortie << acceleratingShapeFile_ << endl; |
---|
95 | // if ( focusingMagFile_ != "") { |
---|
96 | // sortie << "POISSON /zoff=" << offsetMag_ << " /rmult=" << scaleFactor_ << endl; |
---|
97 | // sortie << focusingMagFile_ << endl; |
---|
98 | // } |
---|
99 | |
---|
100 | // return sortie.str(); |
---|
101 | // } |
---|
102 | |
---|
103 | |
---|
104 | string elementCell::FileOutputFlow() const |
---|
105 | { |
---|
106 | ostringstream sortie; |
---|
107 | // sortie << elementName_.getElementType() << endl; |
---|
108 | sortie << elementName_.getGenericLabel() << endl; |
---|
109 | sortie << specificName_ << endl; |
---|
110 | sortie << lenghtElem_ << " " << aperture_ << endl; |
---|
111 | sortie << initialPhase_ << " " << acceleratingField_ << endl; |
---|
112 | sortie << phaseStepMax_ << endl; |
---|
113 | sortie << acceleratingShapeFile_ << endl; |
---|
114 | sortie << focusingMagFile_ << endl; |
---|
115 | sortie << offsetMag_ << " " << scaleFactor_ << endl; |
---|
116 | return sortie.str(); |
---|
117 | } |
---|
118 | |
---|
119 | vector< pair<string, vector<string> > > elementCell::parametersToSoftware () const |
---|
120 | { |
---|
121 | vector< pair<string, vector<string> > > sortie; |
---|
122 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
123 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
124 | sortie.back().second.push_back(specificName_); |
---|
125 | sortie.push_back( pair<string, vector<string> >("lenghtAperture", vector<string>() ) ); |
---|
126 | sortie.back().second.push_back(mixedTools::doubleToString(lenghtElem_)); |
---|
127 | sortie.back().second.push_back(mixedTools::doubleToString( aperture_)); |
---|
128 | sortie.push_back( pair<string, vector<string> >("phaseInitialStepmax", vector<string>() ) ); |
---|
129 | sortie.back().second.push_back(mixedTools::doubleToString( initialPhase_)); |
---|
130 | sortie.back().second.push_back(mixedTools::doubleToString( phaseStepMax_)); |
---|
131 | sortie.push_back( pair<string, vector<string> >("fieldValueFile", vector<string>() ) ); |
---|
132 | sortie.back().second.push_back(mixedTools::doubleToString( acceleratingField_)); |
---|
133 | sortie.back().second.push_back(acceleratingShapeFile_); |
---|
134 | sortie.push_back( pair<string, vector<string> >("MagFocusingFileOffsetScale", vector<string>() ) ); |
---|
135 | sortie.back().second.push_back(focusingMagFile_); |
---|
136 | sortie.back().second.push_back(mixedTools::doubleToString( offsetMag_)); |
---|
137 | sortie.back().second.push_back(mixedTools::doubleToString( scaleFactor_)); |
---|
138 | |
---|
139 | return sortie; |
---|
140 | } |
---|
141 | |
---|
142 | void elementCell::FileInput(ifstream& ifs) |
---|
143 | { |
---|
144 | ifs >> specificName_; |
---|
145 | ifs >> lenghtElem_ >> aperture_; |
---|
146 | ifs >> initialPhase_ >> acceleratingField_; |
---|
147 | ifs >> phaseStepMax_; |
---|
148 | ifs >> acceleratingShapeFile_; |
---|
149 | ifs >> focusingMagFile_; |
---|
150 | ifs >> offsetMag_ >> scaleFactor_; |
---|
151 | } |
---|
152 | |
---|
153 | string elementCell::print() |
---|
154 | { |
---|
155 | string txt = ""; |
---|
156 | txt += specificName_; |
---|
157 | txt += "\nlength (cm) : "; |
---|
158 | txt += mixedTools::doubleToString(lenghtElem_); |
---|
159 | txt += "\naperture (cm) : "; |
---|
160 | txt += mixedTools::doubleToString(aperture_); |
---|
161 | txt += "\ninitial phase (deg.) : "; |
---|
162 | txt += mixedTools::doubleToString(initialPhase_); |
---|
163 | txt += "\nmax phase step (deg.) : "; |
---|
164 | txt += mixedTools::doubleToString(phaseStepMax_); |
---|
165 | txt += "\nmax accelerating field (MV/m) : "; |
---|
166 | txt += mixedTools::doubleToString(acceleratingField_); |
---|
167 | txt += "\nname of file for field shape : "; |
---|
168 | txt += acceleratingShapeFile_; |
---|
169 | txt += "\nname of file for focusing mag. field : "; |
---|
170 | txt += focusingMagFile_; |
---|
171 | txt += "\n z-offset for mag. field : "; |
---|
172 | txt += mixedTools::doubleToString(offsetMag_); |
---|
173 | txt += "\n scaling factor for mag. field : "; |
---|
174 | txt += mixedTools::doubleToString(scaleFactor_); |
---|
175 | return txt; |
---|
176 | } |
---|
177 | |
---|
178 | void elementCell::InputRep(UAPNode* root) |
---|
179 | { |
---|
180 | UAPNode* ele = root->addChild("element"); |
---|
181 | ele->addAttribute("name",specificName_); |
---|
182 | |
---|
183 | UAPNode* node = ele->addChild("methods"); |
---|
184 | node->addChild("tracking")->addAttribute("value","parmela"); |
---|
185 | |
---|
186 | string txt = ""; |
---|
187 | txt = mixedTools::doubleToString(lenghtElem_); |
---|
188 | ele->addChild("length")->addAttribute("design",txt); |
---|
189 | |
---|
190 | node = ele->addChild("aperture"); |
---|
191 | node->addAttribute("at","ENTRANCE"); |
---|
192 | node->addAttribute("shape","CIRCLE"); |
---|
193 | txt = mixedTools::doubleToString(aperture_); |
---|
194 | node->addChild("xy_limit")->addAttribute("design",txt); |
---|
195 | |
---|
196 | node = ele->addChild("linac_cavity"); |
---|
197 | txt = mixedTools::doubleToString(initialPhase_); |
---|
198 | node->addChild("phase0")->addAttribute("design",txt); |
---|
199 | txt = mixedTools::doubleToString(acceleratingField_); |
---|
200 | node->addChild("gradient")->addAttribute("design",txt); |
---|
201 | |
---|
202 | // données propres à Parmela |
---|
203 | ele->addChild("comment")->addAttribute("text","data specific to Parmela"); |
---|
204 | txt = mixedTools::doubleToString(phaseStepMax_); |
---|
205 | ele->addChild("phaseStepMax")->addAttribute("value",txt); |
---|
206 | txt = acceleratingShapeFile_; |
---|
207 | ele->addChild("acceleratingShapeField")->addAttribute("name",txt); |
---|
208 | |
---|
209 | if ( focusingMagFile_ != "") { |
---|
210 | txt = focusingMagFile_; |
---|
211 | ele->addChild("focusingMagneticField")->addAttribute("name",txt); |
---|
212 | txt = mixedTools::doubleToString(offsetMag_); |
---|
213 | ele->addChild("z_offset")->addAttribute("value",txt); |
---|
214 | txt = mixedTools::doubleToString(scaleFactor_); |
---|
215 | ele->addChild("scaling_factor")->addAttribute("value",txt); |
---|
216 | } |
---|
217 | } |
---|