Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
volume.cpp
Go to the documentation of this file.
1#include <cstddef>
3
4/*
5Copyright (c) 2000 Igor B. Smirnov
6
7The file can be used, copied, modified, and distributed
8according to the terms of GNU Lesser General Public License version 2.1
9as published by the Free Software Foundation,
10and provided that the above copyright notice, this permission notice,
11and notices about any modifications of the original text
12appear in all copies and in supporting documentation.
13The file is provided "as is" without express or implied warranty.
14*/
15
16namespace Heed {
17
19 return eid.empty() ? nullptr : eid.back()->Gavol();
20}
21
23 const int qeid = eid.size();
24 for (int n = qeid - 1; n >= 1; n--) eid[n]->down_absref(f);
25}
26
28 const int qeid = eid.size();
29 for (int n = 1; n < qeid; ++n) eid[n]->up_absref(f);
30}
31
33 for (auto vol : eid) if (vol == amvol) return 1;
34 return 0;
35}
36
38 for (auto vol : eid) if (vol->Gavol() == avol) return 1;
39 return 0;
40}
41
43 // First a quick check.
44 if (tid1.eid.size() != tid2.eid.size()) return 0;
45 // Check the last volume.
46 if (tid1.G_lamvol() != tid2.G_lamvol()) return 0;
47 // Check all volumes.
48 const int qeid = tid1.eid.size();
49 for (int n = 0; n < qeid - 1; ++n) {
50 if (tid1.eid[n] != tid2.eid[n]) return 0;
51 }
52 return 1;
53}
54
55void manip_absvol_treeid::print(std::ostream& file, int l) const {
56 if (l < 0) return;
57 if (eid.empty()) {
58 Ifile << "no volume defined\n";
59 } else {
60 // TODO!
61 /*
62 const int qeid = eid.size();
63 if (l > 0) {
64 for (int n = 0; n < qeid - 1; ++n) {
65 Ifile << "n=" << n;
66 eid[n]->print(file, 0);
67 }
68 }
69 Ifile << "n=" << qeid - 1;
70 eid.back()->print(file, 0);
71 */
72 }
73 file.flush();
74}
75
76// ******** absvol ********
77std::vector<manip_absvol*> absvol::Gamanip_embed() const {
78 return std::vector<manip_absvol*>();
79}
80
81int absvol::find_embed_vol(const point& fpt, const vec& dir,
82 manip_absvol_treeid* atid) const {
83 if (check_point_inside(fpt, dir) == 0) return 0;
84 const size_t s = atid->eid.size();
85 std::vector<manip_absvol*> aman = Gamanip_embed();
86 const size_t qaman = aman.size();
87 for (size_t n = 0; n < qaman; ++n) {
88 const int i = aman[n]->m_find_embed_vol(fpt, dir, atid);
89 if (i == 1) {
90 // TODO!
91 if (s < atid->eid.size()) break;
92 Imcout << "absvol::find_embed_vol:\n";
93 Imcout << " Warning: contradiction between "
94 << " i==1 and s == fnamvol\n";
95 }
96 }
97 return 1;
98}
99
100int absvol::range(trajestep& fts, int s_ext, int& sb,
101 manip_absvol*& faeid) const {
102 faeid = nullptr;
103 if (s_ext == 0) {
104 sb = 1;
105 return range_ext(fts, 0);
106 }
107 sb = range_ext(fts, 1) == 1 ? 1 : 0;
108 std::vector<manip_absvol*> aman = Gamanip_embed();
109 const int qaman = aman.size();
110 for (int n = 0; n < qaman; ++n) {
111 if (aman[n]->m_range_ext(fts, 0) == 1) {
112 sb = 2;
113 faeid = aman[n];
114 }
115 }
116 if (sb == 1 || sb == 2) return 1;
117 return 0;
118}
119
120void absvol::print(std::ostream& file, int l) const {
121 if (l <= 0) return;
122 char s[1000];
123 chname(s);
124 Ifile << "absvol::print(l=" << l << "): name=" << s << '\n';
125 --l;
126 if (l > 0) {
127 std::vector<manip_absvol*> embed = Gamanip_embed();
128 indn.n += 2;
129 const int qembed = embed.size();
130 if (qembed > 0) {
131 Ifile << "The following volumes are embraced, q=" << embed.size() << '\n';
132 indn.n += 2;
133 for (int n = 0; n < qembed; ++n) {
134 Ifile << "n=" << n << '\n';
135 indn.n += 2;
136 embed[n]->m_print(file, l);
137 indn.n -= 2;
138 }
139 indn.n -= 2;
140 } else {
141 Ifile << "None of embraced volumes\n";
142 }
143 indn.n -= 2;
144 }
145 file.flush();
146}
147
149 mcerr << "absvol::copy() not defined\n";
150 spexit(mcerr);
151 return NULL;
152}
153
154// ********* manip_absvol *********
156 const vec& fdir) const {
157 const abssyscoor* asc = Gasc();
158 const absvol* avol = Gavol();
159 if (asc) {
160 point pt = fpt;
161 vec dir = fdir;
162 pt.up(asc);
163 dir.up(asc);
164 return avol->check_point_inside(pt, dir);
165 }
166 return avol->check_point_inside(fpt, fdir);
167}
168
169int manip_absvol::m_find_embed_vol(const point& fpt, const vec& fdir,
170 manip_absvol_treeid* atid) const {
171 mfunname("int manip_absvol::m_find_embed_vol(...)");
172 absvol* avol = Gavol();
173 point pt = fpt;
174 up_absref(&pt);
175 vec dir = fdir;
176 up_absref(&dir);
177 // TODO!
178 atid->eid.push_back((manip_absvol*)this);
179 const size_t s = atid->eid.size();
180 int iret = avol->find_embed_vol(pt, dir, atid);
181 if (iret == 0) {
182 if (atid->eid.size() < s) {
183 mcerr << "manip_absvol::m_find_embed_vol: should never happen\n";
184 exit(1);
185 }
186 atid->eid.pop_back();
187 return 0;
188 }
189 if (atid->eid.size() < s) {
190 mcerr << "manip_absvol::m_find_embed_vol: should never happen\n";
191 exit(1);
192 }
193 return 1;
194}
195
196int manip_absvol::m_range(trajestep& fts, int s_ext, int& sb,
197 manip_absvol*& faeid) const {
198 trajestep ts(fts);
199 up_absref(&ts);
200 absvol* avol = Gavol();
201
202 const int s = avol->range(ts, s_ext, sb, faeid);
203 if (s == 1) {
204 down_absref(&ts);
205 fts = ts;
206 }
207 return s;
208}
209
210int manip_absvol::m_range_ext(trajestep& fts, int s_ext) const {
211 trajestep ts(fts);
212 up_absref(&ts);
213 absvol* avol = Gavol();
214 int s = avol->range_ext(ts, s_ext);
215 if (s == 1) {
216 down_absref(&ts);
217 fts = ts;
218 }
219 return s;
220}
221
222void manip_absvol::m_chname(char* nm) const {
223 strcpy(nm, "mvol->");
224 Gavol()->chname(&nm[6]);
225}
226
227void manip_absvol::m_print(std::ostream& file, int l) const {
228 if (l <= 0) return;
229 char s[1000];
230 m_chname(s);
231 Ifile << "manip_absvol::m_print(l=" << l << "): " << s << '\n';
232 --l;
233 if (l > 0) {
234 indn.n += 2;
235 const abssyscoor* asys = Gasc();
236 if (asys)
237 asys->print(file, l - 1);
238 else
239 mcout << "manip_absvol::m_print: system==NULL\n";
240 absvol* avol = Gavol();
241 if (avol)
242 avol->print(file, l - 1);
243 else
244 mcout << "manip_absvol::m_print: avol==NULL\n";
245 indn.n -= 2;
246 }
247 file.flush();
248}
249
251 mcerr << "manip_absvol_copy() not defined\n";
252 spexit(mcerr);
253 return NULL;
254}
255
256// ********* sh_manip_absvol *********
258 aref_ptr[0] = &csys;
259 return absref_transmit(1, aref_ptr);
260}
261
262const abssyscoor* sh_manip_absvol::Gasc() const { return &csys; }
263
266 : absref(f), manip_absvol(f), csys(f.csys) {}
268 : absref(f), manip_absvol(f), csys(f.csys) {}
270
272 const std::string& fname)
273 : csys(fc, fbas, fname) {}
274
275void sh_manip_absvol::m_chname(char* nm) const {
276 strcpy(nm, "mvol->");
277 Gavol()->chname(&nm[6]);
278}
279
281 mcerr << "sh_manip_absvol_copy() not defined\n";
282 spexit(mcerr);
283 return NULL;
284}
285
286void sh_manip_absvol::m_print(std::ostream& file, int l) const {
287 if (l <= 0) return;
288 char s[1000];
289 m_chname(s);
290 Ifile << "sh_manip_absvol::m_print(l=" << l << "): " << s << '\n';
291 if (l > 1) {
292 indn.n += 2;
293 Ifile << "csys=" << noindent << csys;
294 absvol* avol = Gavol();
295 if (avol)
296 avol->print(file, l - 1);
297 else
298 mcout << "manip_absvol::m_print: avol==NULL\n";
299 indn.n -= 2;
300 }
301 file.flush();
302}
303}
#define spexit(stream)
Definition: FunNameStack.h:256
#define mfunname(string)
Definition: FunNameStack.h:45
virtual void print(std::ostream &file, int l) const
Definition: vec.cpp:439
virtual void print(std::ostream &file, int l) const
Definition: volume.cpp:120
virtual int range(trajestep &fts, int s_ext, int &sb, manip_absvol *&faeid) const
Definition: volume.cpp:100
virtual int find_embed_vol(const point &fpt, const vec &dir, manip_absvol_treeid *atid) const
Definition: volume.cpp:81
virtual absvol * copy() const
Definition: volume.cpp:148
virtual int range_ext(trajestep &fts, int s_ext) const =0
virtual int check_point_inside(const point &fpt, const vec &dir) const =0
virtual std::vector< manip_absvol * > Gamanip_embed() const
Definition: volume.cpp:77
virtual void chname(char *nm) const
Definition: volume.h:121
Basis.
Definition: vec.h:313
Service class (array of manip_absvol).
Definition: volume.h:32
int check_absvol_registered(absvol *avol)
Definition: volume.cpp:37
void down_absref(absref *f)
Definition: volume.cpp:22
void print(std::ostream &file, int l) const
Definition: volume.cpp:55
void up_absref(absref *f)
Definition: volume.cpp:27
int check_manip_absvol_registered(manip_absvol *amvol)
Definition: volume.cpp:32
std::vector< manip_absvol * > eid
List of volumes.
Definition: volume.h:37
absvol * G_lavol() const
Get last address of volume.
Definition: volume.cpp:18
manip_absvol * G_lamvol() const
Get last address of manipulator.
Definition: volume.h:39
Abstract base classs for volume "manipulators".
Definition: volume.h:128
virtual int m_check_point_inside(const point &fpt, const vec &dir) const
Definition: volume.cpp:155
manip_absvol * copy() const
Definition: volume.cpp:250
void up_absref(absref *f) const
Definition: volume.h:155
virtual absvol * Gavol() const =0
Get the volume.
void m_chname(char *nm) const
Definition: volume.cpp:222
virtual const abssyscoor * Gasc() const
Get the coordinate system.
Definition: volume.h:133
virtual int m_range_ext(trajestep &fts, int s_ext) const
Definition: volume.cpp:210
virtual int m_range(trajestep &fts, int s_ext, int &sb, manip_absvol *&faeid) const
Definition: volume.cpp:196
void down_absref(absref *f) const
Definition: volume.h:151
virtual int m_find_embed_vol(const point &fpt, const vec &fdir, manip_absvol_treeid *atid) const
Definition: volume.cpp:169
virtual void m_print(std::ostream &file, int l) const
Definition: volume.cpp:227
Point.
Definition: vec.h:368
void up(const abssyscoor *fasc) override
Convert numbering representation of objects to new system.
Definition: vec.cpp:422
fixsyscoor csys
Definition: volume.h:168
virtual absref_transmit get_components() override
Definition: volume.cpp:257
virtual void m_print(std::ostream &file, int l) const override
Definition: volume.cpp:286
absref * aref_ptr[1]
Definition: volume.h:176
virtual const abssyscoor * Gasc() const override
Get the coordinate system.
Definition: volume.cpp:262
sh_manip_absvol * copy() const
Definition: volume.cpp:280
virtual void m_chname(char *nm) const
Definition: volume.cpp:275
Definition: vec.h:179
void up(const basis *fabas_new)
Definition: vec.cpp:190
Definition: BGMesh.cpp:6
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:17
int operator==(const circumf &f1, const circumf &f2)
Definition: circumf.cpp:34
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 Imcout
Definition: prstream.h:196