Garfield++ v2r0
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() ? NULL : 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 const int qeid = eid.size();
33 for (int n = 0; n < qeid; ++n) if (eid[n].get() == amvol) return 1;
34 return 0;
35}
36
38 const int qeid = eid.size();
39 for (int n = 0; n < qeid; ++n) if (eid[n]->Gavol() == avol) return 1;
40 return 0;
41}
42
44 // First a quick check.
45 if (tid1.eid.size() != tid2.eid.size()) return 0;
46 // Check the last volume.
47 if (tid1.G_lamvol() != tid2.G_lamvol()) return 0;
48 // Check all volumes.
49 const int qeid = tid1.eid.size();
50 for (int n = 0; n < qeid - 1; ++n) {
51 if (tid1.eid[n].get() != tid2.eid[n].get()) return 0;
52 }
53 return 1;
54}
55
56void manip_absvol_treeid::print(std::ostream& file, int l) const {
57 if (l < 0) return;
58 if (eid.empty()) {
59 Ifile << "no volume defined\n";
60 } else {
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 file.flush();
72}
73
74// ******** absvol ********
75std::vector<manip_absvol*> absvol::Gamanip_embed() const {
76 return std::vector<manip_absvol*>();
77}
78
79int absvol::find_embed_vol(const point& fpt, const vec& dir,
80 manip_absvol_treeid* atid) const {
81 if (check_point_inside(fpt, dir) == 0) return 0;
82 const unsigned int s = atid->eid.size();
83 std::vector<manip_absvol*> aman = Gamanip_embed();
84 const int qaman = aman.size();
85 for (int n = 0; n < qaman; ++n) {
86 const int i = aman[n]->m_find_embed_vol(fpt, dir, atid);
87 if (i == 1) {
88 // TODO!
89 if (s < atid->eid.size()) break;
90 Imcout << "absvol::find_embed_vol:\n";
91 Imcout << " Warning: contradiction between "
92 << " i==1 and s == fnamvol\n";
93 }
94 }
95 return 1;
96}
97
98int absvol::range(trajestep& fts, int s_ext, int& sb,
99 PassivePtr<manip_absvol>& faeid) const {
100 faeid.put(NULL);
101 if (s_ext == 0) {
102 sb = 1;
103 return range_ext(fts, 0);
104 }
105 sb = range_ext(fts, 1) == 1 ? 1 : 0;
106 std::vector<manip_absvol*> aman = Gamanip_embed();
107 const int qaman = aman.size();
108 for (int n = 0; n < qaman; ++n) {
109 if (aman[n]->m_range_ext(fts, 0) == 1) {
110 sb = 2;
111 faeid.put(aman[n]);
112 }
113 }
114 if (sb == 1 || sb == 2) return 1;
115 return 0;
116}
117
118void absvol::print(std::ostream& file, int l) const {
119 if (l <= 0) return;
120 char s[1000];
121 chname(s);
122 Ifile << "absvol::print(l=" << l << "): name=" << s << '\n';
123 --l;
124 if (l > 0) {
125 std::vector<manip_absvol*> embed = Gamanip_embed();
126 indn.n += 2;
127 const int qembed = embed.size();
128 if (qembed > 0) {
129 Ifile << "The following volumes are embraced, q=" << embed.size() << '\n';
130 indn.n += 2;
131 for (int n = 0; n < qembed; ++n) {
132 Ifile << "n=" << n << '\n';
133 indn.n += 2;
134 embed[n]->m_print(file, l);
135 indn.n -= 2;
136 }
137 indn.n -= 2;
138 } else {
139 Ifile << "None of embraced volumes\n";
140 }
141 indn.n -= 2;
142 }
143 file.flush();
144}
145
147 mcerr << "absvol::copy() not defined\n";
148 spexit(mcerr);
149 return NULL;
150}
151
152// ********* manip_absvol *********
154 const vec& fdir) const {
155 const abssyscoor* asc = Gasc();
156 const absvol* avol = Gavol();
157 if (asc != NULL) {
158 point pt = fpt;
159 vec dir = fdir;
160 pt.up(asc);
161 dir.up(asc);
162 return avol->check_point_inside(pt, dir);
163 }
164 return avol->check_point_inside(fpt, fdir);
165}
166
167int manip_absvol::m_find_embed_vol(const point& fpt, const vec& fdir,
168 manip_absvol_treeid* atid) const {
169 mfunname("int manip_absvol::m_find_embed_vol(...)");
170 absvol* avol = Gavol();
171 point pt = fpt;
172 up_absref(&pt);
173 vec dir = fdir;
174 up_absref(&dir);
175 // TODO!
176 atid->eid.resize(atid->eid.size() + 1);
177 atid->eid.back().put((manip_absvol*)this);
178 unsigned int s = atid->eid.size();
179 int iret = avol->find_embed_vol(pt, dir, atid);
180 if (iret == 0) {
181 if (atid->eid.size() < s) {
182 mcerr << "manip_absvol::m_find_embed_vol: should never happen\n";
183 exit(1);
184 }
185 atid->eid.pop_back();
186 return 0;
187 } else {
188 if (atid->eid.size() < s) {
189 mcerr << "manip_absvol::m_find_embed_vol: should never happen\n";
190 exit(1);
191 }
192 return 1;
193 }
194}
195
196int manip_absvol::m_range(trajestep& fts, int s_ext, int& sb,
197 PassivePtr<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 aref_tran.pass(new 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
Active pointer or automatic container or controlling pointer.
Definition: AbsPtr.h:199
void pass(X *fptr)
Definition: AbsPtr.h:247
void put(X *fptr)
Definition: AbsPtr.h:1275
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:118
virtual int range(trajestep &fts, int s_ext, int &sb, PassivePtr< manip_absvol > &faeid) const
Definition: volume.cpp:98
virtual int find_embed_vol(const point &fpt, const vec &dir, manip_absvol_treeid *atid) const
Definition: volume.cpp:79
virtual absvol * copy() const
Definition: volume.cpp:146
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:75
virtual void chname(char *nm) const
Definition: volume.h:123
Basis.
Definition: vec.h:319
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:21
void print(std::ostream &file, int l) const
Definition: volume.cpp:56
void up_absref(absref *f)
Definition: volume.cpp:26
int check_manip_absvol_registered(manip_absvol *amvol)
Definition: volume.cpp:31
std::vector< PassivePtr< 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:178
virtual int m_check_point_inside(const point &fpt, const vec &dir) const
Definition: volume.cpp:153
virtual manip_absvol * copy() const
Definition: volume.cpp:250
void up_absref(absref *f) const
Definition: volume.h:205
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:183
virtual int m_range_ext(trajestep &fts, int s_ext) const
Definition: volume.cpp:210
void down_absref(absref *f) const
Definition: volume.h:201
virtual int m_range(trajestep &fts, int s_ext, int &sb, PassivePtr< manip_absvol > &faeid) const
Definition: volume.cpp:196
virtual int m_find_embed_vol(const point &fpt, const vec &fdir, manip_absvol_treeid *atid) const
Definition: volume.cpp:167
virtual void m_print(std::ostream &file, int l) const
Definition: volume.cpp:227
Point.
Definition: vec.h:374
virtual void up(const abssyscoor *fasc)
Convert numbering representation of objects to new system.
Definition: vec.cpp:422
fixsyscoor csys
Definition: volume.h:218
virtual void m_print(std::ostream &file, int l) const
Definition: volume.cpp:286
absref * aref_ptr[1]
Definition: volume.h:226
virtual const abssyscoor * Gasc() const
Get the coordinate system.
Definition: volume.cpp:262
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: volume.cpp:257
virtual sh_manip_absvol * copy() const
Definition: volume.cpp:280
virtual void m_chname(char *nm) const
Definition: volume.cpp:275
Definition: vec.h:186
void up(const basis *fabas_new)
Definition: vec.cpp:190
Definition: BGMesh.cpp:5
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