Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MoleculeDef.cpp
Go to the documentation of this file.
1#include <iomanip>
6
7/*
81998-2004 I. Smirnov
9*/
10
11namespace Heed {
12
13VanDerVaals::VanDerVaals(double fPk, double fTk) : Pkh(fPk), Tkh(fTk) {
14 double R = k_Boltzmann * Avogadro; // more precise
15
16 Vkh = R * 3.0 / 8.0 * Tkh / Pkh;
17 ah = 3 * Pkh * Vkh * Vkh;
18 bh = 1.0 / 3.0 * Vkh;
19
20}
21
22double VanDerVaals::volume_of_mole(double T, double p, int& s_not_single) {
23 mfunname("VanDerVaals::volume_of_mole(...)");
24
25 double Tr = T / Tkh;
26 double Pr = p / Pkh;
27 Iprint2n(mcout, Tr, Pr);
28 Cubic cb(Pr, -1.0 / 3.0 * (Pr + 8 * Tr), 3, -1);
29 double r[3];
30 int q = cb.find_real_zero(r);
31 check_econd11(q, <= 0, mcerr);
32 //check_econd11a(q , == 0 , "uncertainty: at horizontal plato\n", mcerr);
33 double x = r[q - 1]; // this is the relative volume taken by one mole
34 double res = x * Vkh; // this is the absolute volume taken by one mole
35 Iprint2n(mcout, x, res);
36 if (q == 2) {
37 s_not_single = 1;
38 } else {
39 s_not_single = 0;
40 }
41 return res;
42}
43
44macro_copy_body(VanDerVaals)
45
46std::ostream& operator<<(std::ostream& file, const VanDerVaals& f) {
48 "std::ostream& operator << (std::ostream& file, const VanDerVaals& f)");
49 Ifile << "VanDerVaals:\n";
50 indn.n += 2;
51 Iprintn(file, f.Pk() / (atmosphere));
52 Iprintn(file, f.Tk() / (kelvin));
53 Iprintn(file, f.Vk() / (cm3));
54 Ifile << "For comparison, the volume of a mole of ideal gas\n";
55 Ifile << "at the same conditions takes\n";
56 Iprintn(file, (k_Boltzmann * Avogadro * f.Tk() / f.Pk()) / (cm3 * mole));
57 Iprintn(file, f.a() / (atmosphere * cm3 * cm3));
58 Iprintn(file, f.b() / (cm3));
59 indn.n -= 2;
60 return file;
61}
62
63/*
64//This is not finished
65
66double VanDerVaals::pressure(double M, // the number of moles
67 double volume,
68 double T)
69{
70 mfunname("double VanDerVaals::pressure(double M, double volume, double T)");
71
72 double ridberg1=8.314 * (joule/(kelvin*mole)); // for debug
73 double ridberg2 = k_Boltzmann * Avogadro; // more precise
74 mcout<<"ridberg1/(joule/(kelvin*mole)) ="
75 << ridberg1/(joule/(kelvin*mole))<<'\n';
76 mcout<<"ridberg2/(joule/(kelvin*mole)) ="
77 << ridberg2/(joule/(kelvin*mole))<<'\n';
78
79 double pa = M * (
80
81 Parabol par(
82*/
83
84MoleculeDef::MoleculeDef(void) : nameh("none"), notationh("none") {
85 MoleculeDef::get_logbook().append(this);
86}
87/*
88MoleculeDef::MoleculeDef(const MoleculeDef& f)
89{
90 mfunnamep("MoleculeDef::MoleculeDef(const MoleculeDef& f)");
91 funnw.ehdr(cerr);
92 mcerr<<"The copy constructor is not allowed, "
93 <<"since it would create second molecula with the same name and
94notation\n";
95 spexit(mcerr);
96}
97
98MoleculeDef& MoleculeDef::operator=(const MoleculeDef& f)
99{
100 mfunnamep("MoleculeDef& MoleculeDef::operator=(const MoleculeDef& f)");
101 funnw.ehdr(cerr);
102 mcerr<<"The assignment operator is not allowed, "
103 <<"since it would create second molecula with the same name and
104notation\n";
105 spexit(mcerr);
106}
107*/
108MoleculeDef::MoleculeDef(const String& fname, const String& fnotation,
109 long fqatom, const DynLinArr<String>& fatom_not,
110 const DynLinArr<long>& fqatom_ps,
111 ActivePtr<VanDerVaals> fawls)
112 : AtomMixDef(fqatom, fatom_not, fqatom_ps),
113 nameh(fname),
114 notationh(fnotation),
115 qatom_psh(fqatom_ps),
116 Z_totalh(0),
117 A_totalh(0.0),
118 tqatomh(0),
119 awlsh(fawls) {
120 mfunname("MoleculeDef::MoleculeDef(...)");
121 long n;
122 for (n = 0; n < qatom(); n++) {
123 Z_totalh += qatom_psh[n] * atom(n)->Z();
124 A_totalh += qatom_psh[n] * atom(n)->A();
125 tqatomh += qatom_psh[n];
126 check_econd11(qatom_psh[n], <= 0, mcerr);
127 }
128 check_econd11(s, <= 0, mcerr);
129 verify();
130 MoleculeDef::get_logbook().append(this);
131}
132
133// one atom in molecule
134MoleculeDef::MoleculeDef(const String& fname, const String& fnotation,
135 const String& fatom_not, long fqatom_ps,
136 ActivePtr<VanDerVaals> fawls)
137 : AtomMixDef(fatom_not),
138 nameh(fname),
139 notationh(fnotation),
140 qatom_psh(1, fqatom_ps),
141 Z_totalh(0),
142 A_totalh(0.0),
143 tqatomh(fqatom_ps),
144 awlsh(fawls) {
145 mfunname("MoleculeDef::MoleculeDef(...)");
146 Z_totalh = atom(0)->Z() * fqatom_ps;
147 A_totalh = atom(0)->A() * fqatom_ps;
148 verify();
149 MoleculeDef::get_logbook().append(this);
150}
151
152// two atoms
153MoleculeDef::MoleculeDef(const String& fname, const String& fnotation,
154 const String& fatom_not1, long fqatom_ps1,
155 const String& fatom_not2, long fqatom_ps2,
156 ActivePtr<VanDerVaals> fawls)
157 : AtomMixDef(fatom_not1, fqatom_ps1, fatom_not2, fqatom_ps2),
158 nameh(fname),
159 notationh(fnotation),
160 qatom_psh(2),
161 Z_totalh(0),
162 A_totalh(0.0),
163 tqatomh(0),
164 awlsh(fawls) {
165 mfunname("MoleculeDef::MoleculeDef(...)");
166 qatom_psh[0] = fqatom_ps1;
167 qatom_psh[1] = fqatom_ps2;
168 long n;
169 for (n = 0; n < qatom(); n++) {
170 check_econd11(qatom_psh[n], <= 0, mcerr);
171 Z_totalh += qatom_psh[n] * atom(n)->Z();
172 A_totalh += qatom_psh[n] * atom(n)->A();
173 tqatomh += qatom_psh[n];
174 }
175 verify();
176 MoleculeDef::get_logbook().append(this);
177}
178
179// three atoms
180MoleculeDef::MoleculeDef(const String& fname, const String& fnotation,
181 const String& fatom_not1, long fqatom_ps1,
182 const String& fatom_not2, long fqatom_ps2,
183 const String& fatom_not3, long fqatom_ps3,
184 ActivePtr<VanDerVaals> fawls)
185 : AtomMixDef(fatom_not1, fqatom_ps1, fatom_not2, fqatom_ps2, fatom_not3,
186 fqatom_ps3),
187 nameh(fname),
188 notationh(fnotation),
189 qatom_psh(3),
190 Z_totalh(0),
191 A_totalh(0.0),
192 tqatomh(0),
193 awlsh(fawls) {
194 mfunname("MoleculeDef::MoleculeDef(...)");
195 qatom_psh[0] = fqatom_ps1;
196 qatom_psh[1] = fqatom_ps2;
197 qatom_psh[2] = fqatom_ps3;
198 long n;
199 for (n = 0; n < qatom(); n++) {
200 check_econd11(qatom_psh[n], <= 0, mcerr);
201 Z_totalh += qatom_psh[n] * atom(n)->Z();
202 A_totalh += qatom_psh[n] * atom(n)->A();
203 tqatomh += qatom_psh[n];
204 }
205 verify();
206 MoleculeDef::get_logbook().append(this);
207}
208
209void MoleculeDef::print(std::ostream& file, int l) const {
210 if (l > 0) file << (*this);
211}
212
213void MoleculeDef::printall(std::ostream& file) {
214 Ifile << "MoleculeDef::printall:\n";
215 AbsListNode<MoleculeDef*>* an = NULL;
217 while ((an = logbook.get_next_node(an)) != NULL) {
218 file << (*(an->el));
219 }
220}
221
223 mfunnamep("void MoleculeDef::verify(void)");
224 if (nameh == "none" && notationh == "none") return;
225 AbsListNode<MoleculeDef*>* an = NULL;
226 while ((an = MoleculeDef::get_logbook().get_next_node(an)) != NULL) {
227 if (an->el->nameh == nameh || an->el->notationh == notationh) {
228 funnw.ehdr(mcerr);
229 mcerr << "can not initialize two molecules "
230 << "with the same name or notation\n";
231 mcerr << "name=" << nameh << " notation=" << notationh << '\n';
232 spexit(mcerr);
233 }
234 }
235}
236
238 static AbsList<MoleculeDef*> logbook;
239 return logbook;
240}
241
244}
245
248 AbsListNode<MoleculeDef*>* an = NULL;
249 while ((an = logbook.get_next_node(an)) != NULL) {
250 if (an->el->notation() == fnotation) return an->el;
251 }
252 return NULL;
253}
254
255std::ostream& operator<<(std::ostream& file, const MoleculeDef& f) {
256 mfunnamep(
257 "std::ostream& operator << (std::ostream& file, const MoleculeDef& f)");
258 Ifile << "MoleculeDef: name=" << std::setw(10) << f.name()
259 << " notation=" << std::setw(3) << f.notation() << '\n';
260 indn.n += 2;
261 Ifile << "Z_total()=" << std::setw(3) << f.Z_total()
262 << " A_total()/(gram/mole)=" << f.A_total() / (gram / mole)
263 << " tqatom()=" << f.tqatom() << '\n';
264 Iprintn(file, f.qatom());
265 indn.n += 2;
266 long n;
267 for (n = 0; n < f.qatom(); n++) {
268 Ifile << "n=" << n << " atom(n)->notation=" << f.atom(n)->notation()
269 << " qatom_ps(n)=" << f.qatom_ps(n) << '\n';
270 }
271 indn.n -= 2;
272 f.AtomMixDef::print(file, 1);
273 Iprintn(mcout, f.awls());
274 VanDerVaals* at = f.awls().get();
275 if (at != NULL) {
276 Ifile << "Density at the crutial conditions for ideal gas (for debug):\n";
277 double ridberg = k_Boltzmann * Avogadro; // more precise
278 //mcout<<"ridberg/(joule/(kelvin*mole)) ="
279 // << ridberg/(joule/(kelvin*mole))<<'\n';
280 //double sa = f.A_total();
282 f.A_total() * at->Pk() / (ridberg * at->Tk()) / (gram / cm3));
283 Ifile << "For the Waals:\n";
284 Iprintn(mcout, f.A_total() / at->Vk() / (gram / cm3));
285 }
286 indn.n -= 2;
287 return file;
288}
289
291
292}
#define macro_copy_body(type)
Definition: AbsPtr.h:297
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define mfunnamep(string)
Definition: FunNameStack.h:77
#define spexit(stream)
Definition: FunNameStack.h:536
#define mfunname(string)
Definition: FunNameStack.h:67
std::string String
Definition: String.h:75
AbsListNode< T > * get_next_node(AbsListNode< T > *an) const
Definition: AbsList.h:175
Definition: cubic.h:18
long qatom(void) const
Definition: AtomDef.h:142
const DynLinArr< PassivePtr< AtomDef > > & atom(void) const
Definition: AtomDef.h:143
const ActivePtr< VanDerVaals > & awls(void) const
Definition: MoleculeDef.h:74
long tqatom(void) const
Definition: MoleculeDef.h:73
static MoleculeDef * get_MoleculeDef(const String &fnotation)
const DynLinArr< long > & qatom_ps(void) const
Definition: MoleculeDef.h:69
static void printall(std::ostream &file)
static AbsList< MoleculeDef * > & get_logbook(void)
long Z_total(void) const
Definition: MoleculeDef.h:71
void print(std::ostream &file, int l) const
const String & name(void) const
Definition: MoleculeDef.h:67
const String & notation(void) const
Definition: MoleculeDef.h:68
static const AbsList< MoleculeDef * > & get_const_logbook(void)
double A_total(void) const
Definition: MoleculeDef.h:72
Definition: BGMesh.cpp:3
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:22
indentation indn
Definition: prstream.cpp:13
#define mcout
Definition: prstream.h:133
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216
#define Iprint2n(file, name1, name2)
Definition: prstream.h:236
std::ostream & operator<<(std::ostream &file, const trajestep &f)
Definition: trajestep.cpp:137