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