Garfield++ 3.0
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
63 MoleculeDef::get_logbook().push_back(this);
64}
65
66MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
67 long fqatom, const std::vector<std::string>& fatom_not,
68 const std::vector<long>& fqatom_ps,
69 std::shared_ptr<VanDerWaals> fvdw)
70 : AtomMixDef(fqatom, fatom_not, fqatom_ps),
71 nameh(fname),
72 notationh(fnotation),
73 qatom_psh(fqatom_ps) {
74 mfunname("MoleculeDef::MoleculeDef(...)");
75 m_vdw = std::move(fvdw);
76 for (long n = 0; n < qatom(); n++) {
77 Z_totalh += qatom_psh[n] * atom(n)->Z();
78 A_totalh += qatom_psh[n] * atom(n)->A();
79 tqatomh += qatom_psh[n];
80 check_econd11(qatom_psh[n], <= 0, mcerr);
81 }
82 verify();
83 MoleculeDef::get_logbook().push_back(this);
84}
85
86// one atom in molecule
87MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
88 const std::string& fatom_not, long fqatom_ps,
89 std::shared_ptr<VanDerWaals> fvdw)
90 : AtomMixDef(fatom_not),
91 nameh(fname),
92 notationh(fnotation),
93 qatom_psh(1, fqatom_ps),
94 tqatomh(fqatom_ps) {
95 mfunname("MoleculeDef::MoleculeDef(...)");
96 m_vdw = std::move(fvdw);
97 Z_totalh = atom(0)->Z() * fqatom_ps;
98 A_totalh = atom(0)->A() * fqatom_ps;
99 verify();
100 MoleculeDef::get_logbook().push_back(this);
101}
102
103// two atoms
104MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
105 const std::string& fatom_not1, long fqatom_ps1,
106 const std::string& fatom_not2, long fqatom_ps2,
107 std::shared_ptr<VanDerWaals> fvdw)
108 : AtomMixDef(fatom_not1, fqatom_ps1, fatom_not2, fqatom_ps2),
109 nameh(fname),
110 notationh(fnotation),
111 qatom_psh(2) {
112 mfunname("MoleculeDef::MoleculeDef(...)");
113 m_vdw = std::move(fvdw);
114 qatom_psh[0] = fqatom_ps1;
115 qatom_psh[1] = fqatom_ps2;
116 for (long n = 0; n < qatom(); n++) {
117 check_econd11(qatom_psh[n], <= 0, mcerr);
118 Z_totalh += qatom_psh[n] * atom(n)->Z();
119 A_totalh += qatom_psh[n] * atom(n)->A();
120 tqatomh += qatom_psh[n];
121 }
122 verify();
123 MoleculeDef::get_logbook().push_back(this);
124}
125
126// three atoms
127MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
128 const std::string& fatom_not1, long fqatom_ps1,
129 const std::string& fatom_not2, long fqatom_ps2,
130 const std::string& fatom_not3, long fqatom_ps3,
131 std::shared_ptr<VanDerWaals> fvdw)
132 : AtomMixDef(fatom_not1, fqatom_ps1, fatom_not2, fqatom_ps2, fatom_not3,
133 fqatom_ps3),
134 nameh(fname),
135 notationh(fnotation),
136 qatom_psh(3) {
137 mfunname("MoleculeDef::MoleculeDef(...)");
138 m_vdw = std::move(fvdw);
139 qatom_psh[0] = fqatom_ps1;
140 qatom_psh[1] = fqatom_ps2;
141 qatom_psh[2] = fqatom_ps3;
142 for (long n = 0; n < qatom(); n++) {
143 check_econd11(qatom_psh[n], <= 0, mcerr);
144 Z_totalh += qatom_psh[n] * atom(n)->Z();
145 A_totalh += qatom_psh[n] * atom(n)->A();
146 tqatomh += qatom_psh[n];
147 }
148 verify();
149 MoleculeDef::get_logbook().push_back(this);
150}
151
152void MoleculeDef::print(std::ostream& file, int l) const {
153 if (l > 0) file << (*this);
154}
155
156void MoleculeDef::printall(std::ostream& file) {
157 Ifile << "MoleculeDef::printall:\n";
158 for (auto molecule : MoleculeDef::get_logbook()) {
159 file << molecule;
160 }
161}
162
164 mfunnamep("void MoleculeDef::verify()");
165 if (nameh == "none" && notationh == "none") return;
166 for (auto molecule : MoleculeDef::get_logbook()) {
167 if (molecule->nameh != nameh && molecule->notationh != notationh) continue;
168 funnw.ehdr(mcerr);
169 mcerr << "cannot initialize two molecules with the same name or notation\n";
170 mcerr << "name=" << nameh << " notation=" << notationh << '\n';
171 spexit(mcerr);
172 }
173}
174
175std::list<MoleculeDef*>& MoleculeDef::get_logbook() {
176 static std::list<MoleculeDef*> logbook;
177 return logbook;
178}
179
180const std::list<MoleculeDef*>& MoleculeDef::get_const_logbook() {
182}
183
184MoleculeDef* MoleculeDef::get_MoleculeDef(const std::string& fnotation) {
185 for (auto molecule : MoleculeDef::get_logbook()) {
186 if (molecule->notation() == fnotation) return molecule;
187 }
188 return nullptr;
189}
190
191std::ostream& operator<<(std::ostream& file, const MoleculeDef& f) {
192 mfunnamep("std::ostream& operator << (std::ostream&, const MoleculeDef&)");
193 constexpr double gpm = gram / mole;
194 Ifile << "MoleculeDef: name=" << std::setw(10) << f.name()
195 << " notation=" << std::setw(3) << f.notation() << '\n';
196 indn.n += 2;
197 Ifile << "Z_total()=" << std::setw(3) << f.Z_total()
198 << " A_total()/(gram/mole)=" << f.A_total() / gpm
199 << " tqatom()=" << f.tqatom() << '\n';
200 Iprintn(file, f.qatom());
201 indn.n += 2;
202 for (long n = 0; n < f.qatom(); n++) {
203 Ifile << "n=" << n << " atom(n)->notation=" << f.atom(n)->notation()
204 << " qatom_ps(n)=" << f.qatom_ps(n) << '\n';
205 }
206 indn.n -= 2;
207 f.AtomMixDef::print(file, 1);
208 VanDerWaals* at = f.vdw().get();
209 if (at) {
210 Ifile << "Density at the crucial conditions for ideal gas (for debug):\n";
211 double rydberg = k_Boltzmann * Avogadro; // more precise
212 // mcout<<"rydberg/(joule/(kelvin*mole)) ="
213 // << rydberg/(joule/(kelvin*mole))<<'\n';
214 // double sa = f.A_total();
216 f.A_total() * at->Pk() / (rydberg * at->Tk()) / (gram / cm3));
217 Ifile << "For the Waals:\n";
218 Iprintn(mcout, f.A_total() / at->Vk() / (gram / cm3));
219 }
220 indn.n -= 2;
221 return file;
222}
223
224// TODO
226}
#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
long qatom() const
Definition: AtomDef.h:133
const std::vector< AtomDef * > & atom() const
Definition: AtomDef.h:134
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
static std::list< MoleculeDef * > & get_logbook()
static const std::list< MoleculeDef * > & get_const_logbook()
double A_total() const
Definition: MoleculeDef.h:71
const std::shared_ptr< VanDerWaals > & vdw() const
Definition: MoleculeDef.h:73
Helper class for Van-der-Waals equation.
Definition: MoleculeDef.h:10
double a() const
Definition: MoleculeDef.h:20
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:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:37
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