Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
MoleculeDef.cpp
Go to the documentation of this file.
1#include <iomanip>
6
7// 1998-2004 I. Smirnov
8
9namespace Heed {
10
11using CLHEP::k_Boltzmann;
12using CLHEP::Avogadro;
13using CLHEP::cm3;
14using CLHEP::gram;
15using CLHEP::mole;
16
17VanDerWaals::VanDerWaals(double fPk, double fTk) : Pkh(fPk), Tkh(fTk) {
18 // Rydberg constant
19 const double R = k_Boltzmann * Avogadro;
20
21 Vkh = R * 3.0 / 8.0 * Tkh / Pkh;
22 ah = 3 * Pkh * Vkh * Vkh;
23 bh = 1.0 / 3.0 * Vkh;
24}
25
26double VanDerWaals::volume_of_mole(double T, double p, int& s_not_single) {
27 mfunname("VanDerWaals::volume_of_mole(...)");
28
29 double Tr = T / Tkh;
30 double Pr = p / Pkh;
31 Iprint2n(mcout, Tr, Pr);
32 Cubic cb(Pr, -1.0 / 3.0 * (Pr + 8 * Tr), 3, -1);
33 double r[3];
34 int q = cb.find_real_zero(r);
35 check_econd11(q, <= 0, mcerr);
36 double x = r[q - 1]; // this is the relative volume taken by one mole
37 double res = x * Vkh; // this is the absolute volume taken by one mole
38 Iprint2n(mcout, x, res);
39 s_not_single = q == 2 ? 1 : 0;
40 return res;
41}
42
43VanDerWaals* VanDerWaals::copy() const { return new VanDerWaals(*this); }
44
45std::ostream& operator<<(std::ostream& file, const VanDerWaals& f) {
47 "std::ostream& operator << (std::ostream& file, const VanDerWaals& f)");
48 Ifile << "VanDerWaals:\n";
49 indn.n += 2;
50 Iprintn(file, f.Pk() / (CLHEP::atmosphere));
51 Iprintn(file, f.Tk() / (CLHEP::kelvin));
52 Iprintn(file, f.Vk() / (cm3));
53 Ifile << "For comparison, the volume of a mole of ideal gas\n";
54 Ifile << "at the same conditions takes\n";
55 Iprintn(file, (k_Boltzmann * Avogadro * f.Tk() / f.Pk()) / (cm3 * mole));
56 Iprintn(file, f.a() / (CLHEP::atmosphere * cm3 * cm3));
57 Iprintn(file, f.b() / (cm3));
58 indn.n -= 2;
59 return file;
60}
61
62/*
63//This is not finished
64double VanDerWaals::pressure(double M, // the number of moles
65 double volume,
66 double T)
67{
68 mfunname("double VanDerWaals::pressure(double M, double volume, double T)");
69 const double rydberg = k_Boltzmann * Avogadro;
70 double pa = M * (
71 Parabol par(
72}
73*/
74
75MoleculeDef::MoleculeDef() : nameh("none"), notationh("none") {
76 MoleculeDef::get_logbook().push_back(this);
77}
78
79MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
80 long fqatom, const std::vector<std::string>& fatom_not,
81 const std::vector<long>& fqatom_ps,
83 : AtomMixDef(fqatom, fatom_not, fqatom_ps),
84 nameh(fname),
85 notationh(fnotation),
86 qatom_psh(fqatom_ps),
87 Z_totalh(0),
88 A_totalh(0.0),
89 tqatomh(0),
90 awlsh(fawls) {
91 mfunname("MoleculeDef::MoleculeDef(...)");
92 for (long n = 0; n < qatom(); n++) {
93 Z_totalh += qatom_psh[n] * atom(n)->Z();
94 A_totalh += qatom_psh[n] * atom(n)->A();
95 tqatomh += qatom_psh[n];
96 check_econd11(qatom_psh[n], <= 0, mcerr);
97 }
98 verify();
99 MoleculeDef::get_logbook().push_back(this);
100}
101
102// one atom in molecule
103MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
104 const std::string& fatom_not, long fqatom_ps,
106 : AtomMixDef(fatom_not),
107 nameh(fname),
108 notationh(fnotation),
109 qatom_psh(1, fqatom_ps),
110 Z_totalh(0),
111 A_totalh(0.0),
112 tqatomh(fqatom_ps),
113 awlsh(fawls) {
114 mfunname("MoleculeDef::MoleculeDef(...)");
115 Z_totalh = atom(0)->Z() * fqatom_ps;
116 A_totalh = atom(0)->A() * fqatom_ps;
117 verify();
118 MoleculeDef::get_logbook().push_back(this);
119}
120
121// two atoms
122MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
123 const std::string& fatom_not1, long fqatom_ps1,
124 const std::string& fatom_not2, long fqatom_ps2,
126 : AtomMixDef(fatom_not1, fqatom_ps1, fatom_not2, fqatom_ps2),
127 nameh(fname),
128 notationh(fnotation),
129 qatom_psh(2),
130 Z_totalh(0),
131 A_totalh(0.0),
132 tqatomh(0),
133 awlsh(fawls) {
134 mfunname("MoleculeDef::MoleculeDef(...)");
135 qatom_psh[0] = fqatom_ps1;
136 qatom_psh[1] = fqatom_ps2;
137 for (long n = 0; n < qatom(); n++) {
138 check_econd11(qatom_psh[n], <= 0, mcerr);
139 Z_totalh += qatom_psh[n] * atom(n)->Z();
140 A_totalh += qatom_psh[n] * atom(n)->A();
141 tqatomh += qatom_psh[n];
142 }
143 verify();
144 MoleculeDef::get_logbook().push_back(this);
145}
146
147// three atoms
148MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
149 const std::string& fatom_not1, long fqatom_ps1,
150 const std::string& fatom_not2, long fqatom_ps2,
151 const std::string& fatom_not3, long fqatom_ps3,
153 : AtomMixDef(fatom_not1, fqatom_ps1, fatom_not2, fqatom_ps2, fatom_not3,
154 fqatom_ps3),
155 nameh(fname),
156 notationh(fnotation),
157 qatom_psh(3),
158 Z_totalh(0),
159 A_totalh(0.0),
160 tqatomh(0),
161 awlsh(fawls) {
162 mfunname("MoleculeDef::MoleculeDef(...)");
163 qatom_psh[0] = fqatom_ps1;
164 qatom_psh[1] = fqatom_ps2;
165 qatom_psh[2] = fqatom_ps3;
166 for (long n = 0; n < qatom(); n++) {
167 check_econd11(qatom_psh[n], <= 0, mcerr);
168 Z_totalh += qatom_psh[n] * atom(n)->Z();
169 A_totalh += qatom_psh[n] * atom(n)->A();
170 tqatomh += qatom_psh[n];
171 }
172 verify();
173 MoleculeDef::get_logbook().push_back(this);
174}
175
176void MoleculeDef::print(std::ostream& file, int l) const {
177 if (l > 0) file << (*this);
178}
179
180void MoleculeDef::printall(std::ostream& file) {
181 Ifile << "MoleculeDef::printall:\n";
182 std::list<MoleculeDef*>& logbook = MoleculeDef::get_logbook();
183 std::list<MoleculeDef*>::const_iterator it;
184 std::list<MoleculeDef*>::const_iterator end = logbook.end();
185 for (it = logbook.begin(); it != end; ++it) file << (*it);
186}
187
189 mfunnamep("void MoleculeDef::verify()");
190 if (nameh == "none" && notationh == "none") return;
191 std::list<MoleculeDef*>& logbook = MoleculeDef::get_logbook();
192 std::list<MoleculeDef*>::const_iterator it;
193 std::list<MoleculeDef*>::const_iterator end = logbook.end();
194 for (it = logbook.begin(); it != end; ++it) {
195 if ((*it)->nameh == nameh || (*it)->notationh == notationh) {
196 funnw.ehdr(mcerr);
197 mcerr << "can not initialize two molecules "
198 << "with the same name or notation\n";
199 mcerr << "name=" << nameh << " notation=" << notationh << '\n';
200 spexit(mcerr);
201 }
202 }
203}
204
205std::list<MoleculeDef*>& MoleculeDef::get_logbook() {
206 static std::list<MoleculeDef*> logbook;
207 return logbook;
208}
209
210const std::list<MoleculeDef*>& MoleculeDef::get_const_logbook() {
212}
213
214MoleculeDef* MoleculeDef::get_MoleculeDef(const std::string& fnotation) {
215 std::list<MoleculeDef*>& logbook = MoleculeDef::get_logbook();
216 std::list<MoleculeDef*>::const_iterator it;
217 std::list<MoleculeDef*>::const_iterator end = logbook.end();
218 for (it = logbook.begin(); it != end; ++it) {
219 if ((*it)->notation() == fnotation) return *it;
220 }
221 return NULL;
222}
223
224std::ostream& operator<<(std::ostream& file, const MoleculeDef& f) {
225 mfunnamep(
226 "std::ostream& operator << (std::ostream& file, const MoleculeDef& f)");
227 Ifile << "MoleculeDef: name=" << std::setw(10) << f.name()
228 << " notation=" << std::setw(3) << f.notation() << '\n';
229 indn.n += 2;
230 Ifile << "Z_total()=" << std::setw(3) << f.Z_total()
231 << " A_total()/(gram/mole)=" << f.A_total() / (gram / mole)
232 << " tqatom()=" << f.tqatom() << '\n';
233 Iprintn(file, f.qatom());
234 indn.n += 2;
235 for (long n = 0; n < f.qatom(); n++) {
236 Ifile << "n=" << n << " atom(n)->notation=" << f.atom(n)->notation()
237 << " qatom_ps(n)=" << f.qatom_ps(n) << '\n';
238 }
239 indn.n -= 2;
240 f.AtomMixDef::print(file, 1);
241 Iprintn(mcout, f.awls());
242 VanDerWaals* at = f.awls().get();
243 if (at) {
244 Ifile << "Density at the crucial conditions for ideal gas (for debug):\n";
245 double rydberg = k_Boltzmann * Avogadro; // more precise
246 // mcout<<"rydberg/(joule/(kelvin*mole)) ="
247 // << rydberg/(joule/(kelvin*mole))<<'\n';
248 // double sa = f.A_total();
250 f.A_total() * at->Pk() / (rydberg * at->Tk()) / (gram / cm3));
251 Ifile << "For the Waals:\n";
252 Iprintn(mcout, f.A_total() / at->Vk() / (gram / cm3));
253 }
254 indn.n -= 2;
255 return file;
256}
257
258// TODO
260}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:155
#define mfunnamep(string)
Definition: FunNameStack.h:49
#define spexit(stream)
Definition: FunNameStack.h:256
#define mfunname(string)
Definition: FunNameStack.h:45
Active pointer or automatic container or controlling pointer.
Definition: AbsPtr.h:199
const std::vector< PassivePtr< AtomDef > > & atom() const
Definition: AtomDef.h:144
long qatom() const
Definition: AtomDef.h:143
Find solution to cubic equation.
Definition: cubic.h:22
int find_real_zero(double z[3]) const
Definition: cubic.cpp:74
const std::vector< long > & qatom_ps() const
Definition: MoleculeDef.h:68
const std::string & name() const
Definition: MoleculeDef.h:66
void verify()
Check that there is no molecule with the same name in the container.
static MoleculeDef * get_MoleculeDef(const std::string &fnotation)
static void printall(std::ostream &file)
long tqatom() const
Definition: MoleculeDef.h:72
void print(std::ostream &file, int l) const
long Z_total() const
Definition: MoleculeDef.h:70
const std::string & notation() const
Definition: MoleculeDef.h:67
const ActivePtr< VanDerWaals > & awls() const
Definition: MoleculeDef.h:73
static std::list< MoleculeDef * > & get_logbook()
static const std::list< MoleculeDef * > & get_const_logbook()
double A_total() const
Definition: MoleculeDef.h:71
Helper class for Van-der-Waals equation.
Definition: MoleculeDef.h:9
double a() const
Definition: MoleculeDef.h:20
virtual VanDerWaals * copy() const
Definition: MoleculeDef.cpp:43
double b() const
Definition: MoleculeDef.h:21
double Vk() const
Definition: MoleculeDef.h:22
double Tk() const
Definition: MoleculeDef.h:24
double volume_of_mole(double T, double p, int &s_not_single)
Definition: MoleculeDef.cpp:26
VanDerWaals(double fPk, double fTk)
Definition: MoleculeDef.cpp:17
double Pk() const
Definition: MoleculeDef.h:23
Definition: BGMesh.cpp:5
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:36
indentation indn
Definition: prstream.cpp:15
#define mcout
Definition: prstream.h:126
#define Ifile
Definition: prstream.h:196
#define mcerr
Definition: prstream.h:128
#define Iprintn(file, name)
Definition: prstream.h:205
#define Iprint2n(file, name1, name2)
Definition: prstream.h:220