Garfield++ 5.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;
16using CLHEP::bar;
17using CLHEP::hep_pascal;
18using CLHEP::kelvin;
19
20VanDerWaals::VanDerWaals(double fPk, double fTk) : Pkh(fPk), Tkh(fTk) {
21 // Rydberg constant
22 const double R = k_Boltzmann * Avogadro;
23
24 Vkh = R * 3.0 / 8.0 * Tkh / Pkh;
25 ah = 3 * Pkh * Vkh * Vkh;
26 bh = 1.0 / 3.0 * Vkh;
27}
28
29double VanDerWaals::volume_of_mole(double T, double p, int& s_not_single) {
30 mfunname("VanDerWaals::volume_of_mole(...)");
31
32 double Tr = T / Tkh;
33 double Pr = p / Pkh;
34 Iprint2n(mcout, Tr, Pr);
35 Cubic cb(Pr, -1.0 / 3.0 * (Pr + 8 * Tr), 3, -1);
36 double r[3];
37 int q = cb.find_real_zero(r);
38 check_econd11(q, <= 0, mcerr);
39 double x = r[q - 1]; // this is the relative volume taken by one mole
40 double res = x * Vkh; // this is the absolute volume taken by one mole
41 Iprint2n(mcout, x, res);
42 s_not_single = q == 2 ? 1 : 0;
43 return res;
44}
45
46VanDerWaals* VanDerWaals::copy() const { return new VanDerWaals(*this); }
47
48std::ostream& operator<<(std::ostream& file, const VanDerWaals& f) {
50 "std::ostream& operator << (std::ostream& file, const VanDerWaals& f)");
51 Ifile << "VanDerWaals:\n";
52 indn.n += 2;
53 Iprintn(file, f.Pk() / (CLHEP::atmosphere));
54 Iprintn(file, f.Tk() / (CLHEP::kelvin));
55 Iprintn(file, f.Vk() / (cm3));
56 Ifile << "For comparison, the volume of a mole of ideal gas\n";
57 Ifile << "at the same conditions takes\n";
58 Iprintn(file, (k_Boltzmann * Avogadro * f.Tk() / f.Pk()) / (cm3 * mole));
59 Iprintn(file, f.a() / (CLHEP::atmosphere * cm3 * cm3));
60 Iprintn(file, f.b() / (cm3));
61 indn.n -= 2;
62 return file;
63}
64
65MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
66 long fqatom, const std::vector<std::string>& fatom_not,
67 const std::vector<long>& fqatom_ps,
68 std::shared_ptr<VanDerWaals> fvdw)
69 : AtomMixDef(fqatom, fatom_not, fqatom_ps),
70 nameh(fname),
71 notationh(fnotation),
72 qatom_psh(fqatom_ps) {
73 mfunname("MoleculeDef::MoleculeDef(...)");
74 m_vdw = std::move(fvdw);
75 for (long n = 0; n < qatom(); n++) {
76 Z_totalh += qatom_psh[n] * atom(n)->Z();
77 A_totalh += qatom_psh[n] * atom(n)->A();
78 tqatomh += qatom_psh[n];
79 check_econd11(qatom_psh[n], <= 0, mcerr);
80 }
81}
82
83// one atom in molecule
84MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
85 const std::string& fatom_not, long fqatom_ps,
86 std::shared_ptr<VanDerWaals> fvdw) :
87 MoleculeDef(fname, fnotation, 1, {fatom_not}, {fqatom_ps}, fvdw) {
88}
89
90// two atoms
91MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
92 const std::string& fatom_not1, long fqatom_ps1,
93 const std::string& fatom_not2, long fqatom_ps2,
94 std::shared_ptr<VanDerWaals> fvdw) :
95 MoleculeDef(fname, fnotation, 2, {fatom_not1, fatom_not2},
96 {fqatom_ps1, fqatom_ps2}, fvdw) {
97
98}
99
100// three atoms
101MoleculeDef::MoleculeDef(const std::string& fname, const std::string& fnotation,
102 const std::string& fatom_not1, long fqatom_ps1,
103 const std::string& fatom_not2, long fqatom_ps2,
104 const std::string& fatom_not3, long fqatom_ps3,
105 std::shared_ptr<VanDerWaals> fvdw) :
106 MoleculeDef(fname, fnotation, 3, {fatom_not1, fatom_not2, fatom_not3},
107 {fqatom_ps1, fqatom_ps2, fqatom_ps3}, fvdw) {
108
109}
110
111void MoleculeDef::print(std::ostream& file, int l) const {
112 if (l > 0) file << (*this);
113}
114
115std::ostream& operator<<(std::ostream& file, const MoleculeDef& f) {
116 mfunnamep("std::ostream& operator << (std::ostream&, const MoleculeDef&)");
117 constexpr double gpm = gram / mole;
118 Ifile << "MoleculeDef: name=" << std::setw(10) << f.name()
119 << " notation=" << std::setw(3) << f.notation() << '\n';
120 indn.n += 2;
121 Ifile << "Z_total()=" << std::setw(3) << f.Z_total()
122 << " A_total()/(gram/mole)=" << f.A_total() / gpm
123 << " tqatom()=" << f.tqatom() << '\n';
124 Iprintn(file, f.qatom());
125 indn.n += 2;
126 for (long n = 0; n < f.qatom(); n++) {
127 Ifile << "n=" << n << " atom(n)->notation=" << f.atom(n)->notation()
128 << " qatom_ps(n)=" << f.qatom_ps(n) << '\n';
129 }
130 indn.n -= 2;
131 f.AtomMixDef::print(file, 1);
132 VanDerWaals* at = f.vdw().get();
133 if (at) {
134 Ifile << "Density at the crucial conditions for ideal gas (for debug):\n";
135 double rydberg = k_Boltzmann * Avogadro; // more precise
136 // mcout<<"rydberg/(joule/(kelvin*mole)) ="
137 // << rydberg/(joule/(kelvin*mole))<<'\n';
138 // double sa = f.A_total();
140 f.A_total() * at->Pk() / (rydberg * at->Tk()) / (gram / cm3));
141 Ifile << "For the Waals:\n";
142 Iprintn(mcout, f.A_total() / at->Vk() / (gram / cm3));
143 }
144 indn.n -= 2;
145 return file;
146}
147
148std::list<MoleculeDef> MoleculeDefs::molecules;
149
150void MoleculeDefs::printMolecules(std::ostream& file) {
151 Ifile << "MoleculeDefs::printMolecules:\n";
152 for (const auto& molecule : getMolecules()) {
153 file << molecule;
154 }
155}
156
157const MoleculeDef* MoleculeDefs::getMolecule(const std::string& fnotation) {
158 for (const auto& molecule : getMolecules()) {
159 if (molecule.notation() == fnotation) return &molecule;
160 }
161 return nullptr;
162}
163
164const std::list<MoleculeDef>& MoleculeDefs::getMolecules() {
165 if (!molecules.empty()) return molecules;
166 molecules.emplace_back(MoleculeDef("Hydrogen", "H2", "H", 2));
167 molecules.emplace_back(MoleculeDef("Helium", "He", "He", 1));
168 molecules.emplace_back(MoleculeDef("Nitrogen", "N2", "N", 2));
169 molecules.emplace_back(MoleculeDef("Oxygen", "O2", "O", 2));
170 molecules.emplace_back(MoleculeDef("Neon", "Ne", "Ne", 1));
171 // molecules.emplace_back(MoleculeDef("Argon_without_K", "Ar_without_K",
172 // "Ar_without_K", 1));
173 molecules.emplace_back(MoleculeDef("Argon", "Ar", "Ar", 1,
174 std::make_shared<VanDerWaals>(48.6 * bar, 150.7 * kelvin)));
175 molecules.emplace_back(MoleculeDef("Krypton", "Kr", "Kr", 1,
176 std::make_shared<VanDerWaals>(55.0 * bar, 209.4 * kelvin)));
177 molecules.emplace_back(MoleculeDef("Xenon", "Xe", "Xe", 1,
178 std::make_shared<VanDerWaals>(55.0 * bar, 209.4 * kelvin)));
179
180 molecules.emplace_back(MoleculeDef("NH3", "NH3", "N", 1, "H", 3));
181 molecules.emplace_back(MoleculeDef("N2O", "N2O", "N", 2, "O", 1));
182 molecules.emplace_back(MoleculeDef("CO2", "CO2", "C", 1, "O", 2));
183 molecules.emplace_back(MoleculeDef("CH4", "CH4", "C", 1, "H", 4,
184 std::make_shared<VanDerWaals>(4.64e6 * hep_pascal,
185 (273.15 - 82.5) * kelvin)));
186 molecules.emplace_back(MoleculeDef("CF4", "CF4", "C", 1, "F", 4,
187 std::make_shared<VanDerWaals>(42.5 * bar, 369.8 * kelvin)));
188 molecules.emplace_back(MoleculeDef("SF4", "SF4", "S", 1, "F", 4));
189 molecules.emplace_back(MoleculeDef("SF6", "SF6", "S", 1, "F", 6));
190 molecules.emplace_back(MoleculeDef("C2H2", "C2H2", "C", 2, "H", 2));
191 molecules.emplace_back(MoleculeDef("C2H4", "C2H4", "C", 2, "H", 4));
192 molecules.emplace_back(MoleculeDef("C2H6", "C2H6", "C", 2, "H", 6));
193 molecules.emplace_back(MoleculeDef("C3H8", "C3H8", "C", 3, "H", 8,
194 std::make_shared<VanDerWaals>(42.5 * bar, 369.8 * kelvin)));
195 molecules.emplace_back(MoleculeDef("C4H10", "C4H10", "C", 4, "H", 10,
196 std::make_shared<VanDerWaals>(40.0 * bar, 418.3 * kelvin)));
197 molecules.emplace_back(MoleculeDef("C2H2F4", "C2H2F4", "C", 2, "F", 4, "H", 2));
198 molecules.emplace_back(MoleculeDef("H2O", "H2O", "H", 2, "O", 1,
199 std::make_shared<VanDerWaals>(22.9e6 * hep_pascal, (273.15 + 374.15) * kelvin)));
200 molecules.emplace_back(MoleculeDef("Methylal", "Methylal", "O", 2, "C", 3, "H", 8,
201 std::make_shared<VanDerWaals>(39.5 * bar, 480.6 * kelvin)));
202
203 // Additional molecule definitions for compatibility with Magboltz
204 molecules.emplace_back(MoleculeDef("C5H12", "C5H12", "C", 5, "H", 12));
205 molecules.emplace_back(MoleculeDef("NO", "NO", "N", 1, "O", 1));
206 molecules.emplace_back(MoleculeDef("CO", "CO", "C", 1, "O", 1));
207 molecules.emplace_back(MoleculeDef("DME", "DME", "C", 2, "H", 6, "O", 1));
208 molecules.emplace_back(MoleculeDef("C2F6", "C2F6", "C", 2, "F", 6));
209 molecules.emplace_back(MoleculeDef("C3H6", "C3H6", "C", 3, "H", 6));
210 molecules.emplace_back(MoleculeDef("CH3OH", "CH3OH", "C", 1, "H", 4, "O", 1));
211 molecules.emplace_back(MoleculeDef("C2H5OH", "C2H5OH", "C", 2, "H", 6, "O", 1));
212 molecules.emplace_back(MoleculeDef("C3H7OH", "C3H7OH", "C", 3, "H", 8, "O", 1));
213 molecules.emplace_back(MoleculeDef("Cs", "Cs", "Cs", 1));
214 molecules.emplace_back(MoleculeDef("F2", "F2", "F", 2));
215 molecules.emplace_back(MoleculeDef("CS2", "CS2", "C", 1, "S", 2));
216 molecules.emplace_back(MoleculeDef("COS", "COS", "C", 1, "O", 1, "S", 1));
217 molecules.emplace_back(MoleculeDef("BF3", "BF3", "B", 1, "F", 3));
218 molecules.emplace_back(MoleculeDef("C2HF5", "C2HF5", "C", 2, "H", 1, "F", 5));
219 molecules.emplace_back(MoleculeDef("CHF3", "CHF3", "C", 1, "H", 1, "F", 3));
220 molecules.emplace_back(MoleculeDef("CF3Br", "CF3Br", "C", 1, "F", 3, "Br", 1));
221 molecules.emplace_back(MoleculeDef("C3F8", "C3F8", "C", 3, "F", 8));
222 molecules.emplace_back(MoleculeDef("O3", "O3", "O", 3));
223 molecules.emplace_back(MoleculeDef("Hg", "Hg", "Hg", 1));
224 molecules.emplace_back(MoleculeDef("H2S", "H2S", "H", 2, "S", 1));
225 molecules.emplace_back(MoleculeDef("GeH4", "GeH4", "Ge", 1, "H", 4));
226 molecules.emplace_back(MoleculeDef("SiH4", "SiH4", "Si", 1, "H", 4));
227 molecules.emplace_back(MoleculeDef("CCl4", "CCl4", "C", 1, "Cl", 4));
228 return molecules;
229}
230
231}
#define check_econd11(a, signb, stream)
#define mfunnamep(string)
#define mfunname(string)
AtomMixDef()=default
Default constructor.
long qatom() const
Definition AtomDef.h:101
const std::vector< const AtomDef * > & atom() const
Definition AtomDef.h:102
Find solution to cubic equation.
Definition cubic.h:22
int find_real_zero(double z[3]) const
Definition cubic.cpp:74
MoleculeDef()=default
const std::vector< long > & qatom_ps() const
Definition MoleculeDef.h:64
const std::string & name() const
Definition MoleculeDef.h:62
long tqatom() const
Definition MoleculeDef.h:68
void print(std::ostream &file, int l) const
long Z_total() const
Definition MoleculeDef.h:66
const std::string & notation() const
Definition MoleculeDef.h:63
double A_total() const
Definition MoleculeDef.h:67
const std::shared_ptr< VanDerWaals > & vdw() const
Definition MoleculeDef.h:69
static const MoleculeDef * getMolecule(const std::string &fnotation)
static const std::list< MoleculeDef > & getMolecules()
static void printMolecules(std::ostream &file)
Print all registered molecules.
Helper class for Van-der-Waals equation.
Definition MoleculeDef.h:10
double a() const
Definition MoleculeDef.h:20
VanDerWaals * copy() const
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)
VanDerWaals(double fPk, double fTk)
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:195
#define mcerr
Definition prstream.h:128
#define Iprintn(file, name)
Definition prstream.h:204
#define Iprint2n(file, name1, name2)
Definition prstream.h:219