1 | #include "elementRfgun.h" |
---|
2 | |
---|
3 | |
---|
4 | #include "mathematicalTools.h" |
---|
5 | #include "PhysicalConstants.h" |
---|
6 | #include "mixedTools.h" |
---|
7 | |
---|
8 | |
---|
9 | elementRfgun::elementRfgun() : abstractElement() |
---|
10 | { |
---|
11 | setDefaultValues(); |
---|
12 | setDefaults(); |
---|
13 | elementName_ = nomdElements("rfgun"); |
---|
14 | nbParam_ = elementName_.getElementNbParameters(); |
---|
15 | parametersString_ = new string[nbParam_+1]; |
---|
16 | // parmelaOk_ = true; |
---|
17 | } |
---|
18 | |
---|
19 | void elementRfgun::setDefaultValues() |
---|
20 | { |
---|
21 | defaultLabel_ = "rfgun"; |
---|
22 | defaultPhaseStep_ = 1.0; |
---|
23 | defaultNmacrop_ = 0; |
---|
24 | defaultSigma_t_ = 0.0; |
---|
25 | defaultSigma_r_ = 0.0; |
---|
26 | defaultEmit_x_ = 0.0; |
---|
27 | defaultEmit_y_ = 0.0; |
---|
28 | defaultE_cin_ = 0.0; |
---|
29 | defaultSigma_E_ = 0.0; |
---|
30 | // defaultNb_true_particles_ = 1.0; |
---|
31 | defaultTotalCharge_ = 0.0; |
---|
32 | } |
---|
33 | |
---|
34 | void elementRfgun::setDefaults() |
---|
35 | { |
---|
36 | label_ = defaultLabel_; |
---|
37 | phaseStep_ = defaultPhaseStep_; |
---|
38 | nmacrop_ = defaultNmacrop_; |
---|
39 | sigma_t_ = defaultSigma_t_; |
---|
40 | sigma_r_ = defaultSigma_r_ ; |
---|
41 | emit_x_ = defaultEmit_x_; |
---|
42 | emit_y_ = defaultEmit_y_; |
---|
43 | E_cin_ = defaultE_cin_; |
---|
44 | sigma_E_ = defaultSigma_E_; |
---|
45 | // nb_true_particles_ = defaultNb_true_particles_ ; |
---|
46 | totalCharge_ = defaultTotalCharge_; |
---|
47 | } |
---|
48 | |
---|
49 | trivaluedBool elementRfgun::is_accepted_by_software(nomDeLogiciel soft) const { |
---|
50 | cout << " elementRfgun : c'est le bon is_accepted_by_software " << endl; |
---|
51 | if ( soft == nomDeLogiciel::parmela ) return ok; |
---|
52 | else if ( soft == nomDeLogiciel::generator ) return ok; |
---|
53 | else return error; |
---|
54 | } |
---|
55 | |
---|
56 | string* elementRfgun::getParametersString() const |
---|
57 | { |
---|
58 | int compteur = -1; |
---|
59 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
60 | parametersString_[++compteur] = label_; |
---|
61 | parametersString_[++compteur] = mixedTools::intToString(nmacrop_); |
---|
62 | parametersString_[++compteur] = mixedTools::doubleToString(sigma_t_); |
---|
63 | parametersString_[++compteur] = mixedTools::doubleToString(sigma_r_); |
---|
64 | parametersString_[++compteur] = mixedTools::doubleToString(emit_x_); |
---|
65 | parametersString_[++compteur] = mixedTools::doubleToString(emit_y_); |
---|
66 | parametersString_[++compteur] = mixedTools::doubleToString(E_cin_); |
---|
67 | parametersString_[++compteur] = mixedTools::doubleToString(sigma_E_); |
---|
68 | parametersString_[++compteur] = mixedTools::doubleToString(totalCharge_); |
---|
69 | return parametersString_; |
---|
70 | } |
---|
71 | |
---|
72 | void elementRfgun::setParametersString(string* param) |
---|
73 | { |
---|
74 | if ( param == NULL ) |
---|
75 | { |
---|
76 | cerr << " elementRfgun::setParametersString parameters empty parameter set"; |
---|
77 | return; |
---|
78 | } |
---|
79 | int compteur = -1; |
---|
80 | int nbparam = atoi(param[++compteur].c_str()); |
---|
81 | if ( nbparam != nbParam_ ) |
---|
82 | { |
---|
83 | cerr << " elementRfgun::setParametersString parameters do not match for a DRIFT"; |
---|
84 | return; |
---|
85 | } |
---|
86 | |
---|
87 | label_ = param[++compteur]; |
---|
88 | nmacrop_ = atoi(param[++compteur].c_str()); |
---|
89 | sigma_t_ = atof(param[++compteur].c_str()); |
---|
90 | sigma_r_ = atof(param[++compteur].c_str()); |
---|
91 | emit_x_ = atof(param[++compteur].c_str()); |
---|
92 | emit_y_ = atof(param[++compteur].c_str()); |
---|
93 | E_cin_ = atof(param[++compteur].c_str()); |
---|
94 | sigma_E_ = atof(param[++compteur].c_str()); |
---|
95 | totalCharge_ = atof(param[++compteur].c_str()); |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | string elementRfgun::parmelaOutputFlow() const |
---|
100 | { |
---|
101 | ostringstream sortie; |
---|
102 | // on prend les troncatures tmax et rmax à 3 sigmas |
---|
103 | sortie << "INPUT 10 /np=" << nmacrop_ << " /sigt=" << sigma_t_ << endl; |
---|
104 | sortie << " /tmax=" << 3.3*sigma_t_ << " /sigr=" << sigma_r_ << endl; |
---|
105 | sortie << " /rmax=" << 3.0*sigma_r_ << " /W0=" << E_cin_ << " /dw0=" << sigma_E_ << endl; |
---|
106 | sortie << " /dwt=" << phaseStep_ << " /ran=2" << endl; |
---|
107 | |
---|
108 | // on doit entrer le nb vrai de part. (avec signe moins) |
---|
109 | |
---|
110 | |
---|
111 | sortie << "SCHEFF /beami=" << -fabs(totalCharge_)/ELECTRONANOCOULOMB << " /nprog=2 /point=-1.7"; |
---|
112 | |
---|
113 | return sortie.str(); |
---|
114 | } |
---|
115 | |
---|
116 | string elementRfgun::generatorOutputFlow() const { |
---|
117 | ostringstream sortie; |
---|
118 | sortie << "Ipart=" << nmacrop_ << endl; |
---|
119 | |
---|
120 | sortie << "Probe=.True." << endl; |
---|
121 | sortie << "Noise_reduc=.T" << endl; |
---|
122 | sortie << "Cathode=.T." << endl; |
---|
123 | sortie << "Q_total=" << totalCharge_ << endl; |
---|
124 | sortie << "Ref_zpos=0.0" << endl; |
---|
125 | sortie << "Ref_clock=0.0" << endl; |
---|
126 | sortie << "Ref_Ekin=" << E_cin_ << endl; // tjs en MeV |
---|
127 | sortie << "Dist_z='g'" << endl; |
---|
128 | sortie << "sig_clock=" << 1.0e-3*sigma_t_ << endl; // passage de ps en ns |
---|
129 | sortie << "Dist_pz='g', sig_Ekin=" << 1000.*sigma_E_ << ", emit_z=0.0 , cor_Ekin=0.0 " << endl; // passage en keV |
---|
130 | sortie << "Dist_x='gauss', sig_x=" << 10.*sigma_r_ << endl; // passage en mm |
---|
131 | sortie << "Dist_px='g', Nemit_x=" << emit_x_ << ", cor_px=0.0" << endl; |
---|
132 | sortie << "Dist_y='gauss', sig_y=" << 10.*sigma_r_ << endl; // passage en mm |
---|
133 | sortie << "Dist_py='g', Nemit_y=" << emit_y_ << ", cor_py=0.0" << endl; |
---|
134 | return sortie.str(); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | string elementRfgun::FileOutputFlow() const |
---|
140 | { |
---|
141 | ostringstream sortie; |
---|
142 | // on prend les troncatures tmax et rmax à 3 sigmas |
---|
143 | // sortie << elementName_.getElementType() << endl; |
---|
144 | sortie << elementName_.getElementLabel() << endl; |
---|
145 | sortie << label_ << endl; |
---|
146 | sortie << nmacrop_ << " " << sigma_t_ << " " << sigma_r_ << endl; |
---|
147 | sortie << emit_x_ << " " << emit_y_ << endl; |
---|
148 | sortie << E_cin_ << " " << sigma_E_ << endl; |
---|
149 | sortie << phaseStep_ << " " << totalCharge_ << endl; |
---|
150 | return sortie.str(); |
---|
151 | } |
---|
152 | |
---|
153 | void elementRfgun::FileInput(ifstream& ifs) |
---|
154 | { |
---|
155 | ifs >> label_; |
---|
156 | ifs >> nmacrop_ >> sigma_t_ >> sigma_r_; |
---|
157 | ifs >> emit_x_ >> emit_y_; |
---|
158 | ifs >> E_cin_ >> sigma_E_; |
---|
159 | ifs >> phaseStep_ >> totalCharge_; |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | string elementRfgun::print() { |
---|
164 | string txt = ""; |
---|
165 | |
---|
166 | txt += label_; |
---|
167 | txt += "\ntotal charge : "; |
---|
168 | txt += mixedTools::doubleToString(totalCharge_); |
---|
169 | txt += "\nsigma_t (ps) : "; |
---|
170 | txt += mixedTools::doubleToString(sigma_t_); |
---|
171 | txt += "\nsigma_r (cm) : "; |
---|
172 | txt += mixedTools::doubleToString(sigma_r_); |
---|
173 | txt += "\nemittance x (pi.mm.mrad) : "; |
---|
174 | txt += mixedTools::doubleToString(emit_x_); |
---|
175 | txt += "\nemittance y (pi.mm.mrad) : "; |
---|
176 | txt += mixedTools::doubleToString(emit_y_); |
---|
177 | txt += "\ninitial kinetic energy (MeV) : "; |
---|
178 | txt += mixedTools::doubleToString(E_cin_); |
---|
179 | txt += "\nsigma_Ecin (MeV) : "; |
---|
180 | txt += mixedTools::doubleToString(sigma_E_); |
---|
181 | txt += "\ntrue number of part. in beam : "; |
---|
182 | txt += mixedTools::boolToString(nmacrop_); |
---|
183 | |
---|
184 | return txt; |
---|
185 | } |
---|