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