Class documentation of Concepts

Loading...
Searching...
No Matches
tree.hh
Go to the documentation of this file.
1
6#ifndef clusterTree_hh
7#define clusterTree_hh
8
9#include <iostream>
10
11#include "basics/output.hh"
12#include "basics/typedefs.hh"
14#include "basics/exceptions.hh"
15#include "space/space.hh"
16#include "bem/element.hh"
17
18namespace cluster {
19
20 // *************************************************************** cebysev **
21
23 void cebysev(const concepts::Real3d& x0, const concepts::Real3d& x1,
25 void cebysev(const concepts::Real3d& x0, const concepts::Real3d& x1,
28
29 // ***************************************************************** BBall **
30
35 template<class F>
36 class BBall {
37 public:
43 virtual void operator()(const concepts::Element<F>& elm,
44 concepts::Real3d& c, concepts::Real& r) const = 0;
45 };
46
47 // ************************************************************** BBall000 **
48
52 template<class F>
53 class BBall000 : public BBall<F> {
54 public:
62 concepts::Real& r) const;
63 };
64
65 template<class F>
67 concepts::Real3d& c, concepts::Real& r) const {
68
69 const bem::Linear3d000<F>* elmA =
70 dynamic_cast<const bem::Linear3d000<F>*>(&elm);
71 if (elmA != 0) {
72 cebysev(elmA->vertex(0), elmA->vertex(1), elmA->vertex(2), c, r);
73 return;
74 }
75
76 const bem::Constant3d000<F>* elmB =
77 dynamic_cast<const bem::Constant3d000<F>*>(&elm);
78 if (elmB != 0) {
79 cebysev(elmB->vertex(0), elmB->vertex(1), elmB->vertex(2), c, r);
80 return;
81 }
82
83 const bem::Constant3d001<F>* elmC =
84 dynamic_cast<const bem::Constant3d001<F>*>(&elm);
85 if (elmC != 0) {
86 cebysev(elmC->vertex(0), elmC->vertex(1), elmC->vertex(2), c, r);
87 return;
88 }
89
90 const bem::Constant3d002<F>* elmD =
91 dynamic_cast<const bem::Constant3d002<F>*>(&elm);
92 if (elmD != 0) {
93 cebysev(elmD->vertex(0), elmD->vertex(1), elmD->vertex(2), c, r);
94 return;
95 }
96
97 const bem::Dirac3d000<F>* elmE =
98 dynamic_cast<const bem::Dirac3d000<F>*>(&elm);
99 if (elmE != 0) {
100 switch (elmE->T().n()) {
101 case 1:
102 c = elmE->vertex(0); r = 0.0;
103 break;
104 case 2:
105 cebysev(elmE->vertex(0), elmE->vertex(1), c, r);
106 break;
107 case 3:
108 cebysev(elmE->vertex(0), elmE->vertex(1), elmE->vertex(2), c, r);
109 break;
110 }
111 return;
112 }
113
114 throw conceptsException(concepts::MissingFeature("cell not supported"));
115 }
116
117 // *************************************************************** Cluster **
118
119 template<typename F>
120 class Cluster;
121
122 template<typename F>
123 std::ostream& operator<<(std::ostream& os, const Cluster<F>& clst);
124
128 template<class F>
129 class Cluster {
130 public:
132 typedef F CF;
133
139 Cluster(const concepts::Element<F>& elm, const BBall<F>& ball,
140 Cluster<F>* lnk);
148 Cluster(uint idx, Cluster<F>& chld, const concepts::Real3d& c,
149 concepts::Real r, uint nlf = 0);
150
152 inline Cluster<F>* child(uint j) const;
154 inline Cluster<F>* child() const;
156 inline Cluster<F>* link() const {return lnk_;}
157 inline Cluster<F>*& link() {return lnk_;}
159 inline const concepts::Element<F>* element() const;
161 inline const concepts::Real3d& center() const {return c_;}
163 inline concepts::Real radius() const {return r_;}
165 inline uint nleaf() const {return nlf_;}
167 inline uint index() const {return idx_;}
168 std::ostream& info(std::ostream& os) const;
169
170 private:
171 friend std::ostream& operator<< <>(std::ostream& os,
172 const Cluster<F>& clst);
174 union CE {
175 Cluster<F>* chld;
176 const concepts::Element<F>* elm;
177 };
178
180 Cluster<F>* lnk_;
182 CE ce_;
183
185 uint idx_;
187 uint nlf_;
188
193 };
194
195 template<class F>
196 inline Cluster<F>* Cluster<F>::child(uint j) const {
197 Cluster<F>* c = child();
198 while (c && j) {c = c->link(); j--;}
199 return (j) ? (Cluster<F>*)0 : c;
200 }
201
202 template<class F>
204 return (nlf_) ? ce_.chld : (Cluster<F>*)0;
205 }
206
207 template<class F>
209 return (nlf_) ? (concepts::Element<F>*)0 : ce_.elm;
210 }
211
212 template<class F>
213 inline std::ostream& operator<<(std::ostream& os, const Cluster<F>& clst) {
214 return clst.info(os);
215 }
216
217 template<class F>
219 concepts::Real r, uint nlf)
220 : lnk_(0), idx_(idx), nlf_(nlf), c_(c), r_(r) {
221
222 ce_.chld = &chld;
223
224 if (nlf_ == 0)
225 for(const Cluster<F>* c = &chld; c != 0; c = c->lnk_)
226 nlf_ += c->nlf_ ? c->nlf_ : 1;
227 }
228
229 template<class F>
231 const BBall<F>& ball, Cluster<F>* lnk)
232 : lnk_(lnk), idx_(0), nlf_(0) {
233
234 ce_.elm = &elm;
235 ball(elm, c_, r_);
236 }
237
238 template<class F>
239 std::ostream& Cluster<F>::info(std::ostream& os) const {
240 os << concepts::typeOf(*this) << "(idx = " << idx_ << ", r = " << r_ << ", c = " << c_;
241 os << ", nleaf = " << nlf_ << ", lnk = " << lnk_;
242 os << ", chld = " << child() << ')';
243 return os;
244 }
245
246 // ************************************************************ TreeTraits **
247
251 template<class Node>
253 public:
255 typedef typename Node::CF F;
256
257 static Node* child(const Node* nd, uint j) {return nd->child(j);}
258 static const concepts::Element<F>* element(const Node* nd) {
259 return nd->element();
260 }
261 static const concepts::Real3d& center(const Node* nd) {
262 return nd->center();}
263
264 static concepts::Real radius(const Node* nd) {
265 return nd->radius();
266 }
267 static uint nleaf(const Node* nd) {return nd->nleaf();}
268 static uint index(const Node* nd) {return nd->index();}
269 };
270
271 // ****************************************************************** Tree **
272
273 template<class CNode>
274 class Tree;
275
276 template<class CNode>
277 inline std::ostream& operator<<(std::ostream& os, const Tree<CNode>& t) {
278 return t.info(os);
279 }
280
284 template<class CNode>
285 class Tree {
286 friend std::ostream& operator<< <>(std::ostream& os, const Tree<CNode>& t);
287
288 public:
292 typedef typename Traits::F F;
294 typedef CNode Node;
295
299 inline Tree(const concepts::Space<F>& spc) : spc_(spc) {}
300 virtual ~Tree() {}
301
302 virtual std::ostream& info(std::ostream& os) const;
304 virtual uint nclst() const = 0;
306 virtual uint nleaf() const = 0;
308 virtual const Node* root() const = 0;
310 inline const concepts::Space<F>& space() const {return spc_;}
311
312 private:
314 const concepts::Space<F>& spc_;
315
324 void info_(const Node* clst, concepts::Real& rhomin,
325 concepts::Real& rhomax, concepts::Real& taumin,
326 concepts::Real& taumax, uint& h) const;
327 };
328
329 template<class CNode>
330 void Tree<CNode>::info_(const CNode* clst, concepts::Real& rhomin,
331 concepts::Real& rhomax, concepts::Real& taumin,
332 concepts::Real& taumax, uint& h) const {
333 uint j = 0;
334 const CNode* chld = Traits::child(clst, j);
335
336 while (chld) {
337 if (Traits::nleaf(chld)) {
338 uint hh = 0;
339 info_(chld, rhomin, rhomax, taumin, taumax, hh);
340
341 if (hh > h) h = hh;
342
343 concepts::Real rho = Traits::radius(chld) / Traits::radius(clst);
344 if (rho < rhomin) rhomin = rho;
345 if (rho > rhomax) rhomax = rho;
346
347 concepts::Real tau =
348 (concepts::Real)Traits::nleaf(chld) / Traits::nleaf(clst);
349 if (tau < taumin) taumin = tau;
350 if (tau > taumax) taumax = tau;
351
352 if (rho > 2) {
353 std::cout << *clst << std::endl;
354 std::cout << *chld << std::endl;
355 }
356
357 }
358 chld = Traits::child(clst, ++j);
359 }
360 ++h;
361 }
362
363 template<class CNode>
364 std::ostream& Tree<CNode>::info(std::ostream& os) const {
365
366 concepts::Real rhomin = 1, rhomax = 0;
367 concepts::Real taumin = 1, taumax = 0;
368 uint h = 0;
369
370 info_(root(), rhomin, rhomax, taumin, taumax, h);
371
372 os << "cluster::" << concepts::typeOf(*this) << "(nclst = " << nclst() << ", nleaf = " << nleaf();
373 os << ", h = " << h;
374
375 if (h > 1) {
376 os << ", rho in [" << rhomin << ", " << rhomax;
377 os << "], tau in [" << taumin << ", " << taumax << "])";
378 } else {
379 os << ')';
380 }
381
382 return os;
383 }
384
385} // namespace cluster
386
387#endif // clusterTree_hh
#define conceptsException(exc)
const concepts::Real3d & vertex(uint i) const
Definition element.hh:256
const concepts::Real3d & vertex(uint i) const
Definition element.hh:373
const concepts::Real3d & vertex(uint i) const
Definition element.hh:445
const concepts::Real3d & vertex(uint i) const
Definition element.hh:50
const concepts::TMatrixBase< F > & T() const
Returns T matrix of the element.
Definition element.hh:42
const concepts::Real3d & vertex(uint i) const
Definition element.hh:158
void operator()(const concepts::Element< F > &elm, concepts::Real3d &c, concepts::Real &r) const
Definition tree.hh:66
virtual void operator()(const concepts::Element< F > &elm, concepts::Real3d &c, concepts::Real &r) const =0
const concepts::Real3d & center() const
Center of the cluster.
Definition tree.hh:161
concepts::Real radius() const
Radius of the cluster.
Definition tree.hh:163
uint nleaf() const
Number of leafs of the cluster.
Definition tree.hh:165
Cluster< F > * link() const
Neighbouring cluster.
Definition tree.hh:156
uint index() const
Index (number) of the cluster.
Definition tree.hh:167
Cluster< F > * child() const
First child of the cluster if the cluster is not a leaf.
Definition tree.hh:203
Cluster(const concepts::Element< F > &elm, const BBall< F > &ball, Cluster< F > *lnk)
Definition tree.hh:230
const concepts::Element< F > * element() const
Returns element if the cluster is a leaf.
Definition tree.hh:208
F CF
Typedef used for interface (trait) of the cluster tree.
Definition tree.hh:132
Node::CF F
Field of the node (Real or Cmplx)
Definition tree.hh:255
TreeTraits< CNode > Traits
Interface of the tree.
Definition tree.hh:290
virtual uint nleaf() const =0
Number of leafs.
virtual const Node * root() const =0
Root node of the tree.
const concepts::Space< F > & space() const
Space of the tree.
Definition tree.hh:310
virtual uint nclst() const =0
Number of clusters.
Tree(const concepts::Space< F > &spc)
Definition tree.hh:299
Traits::F F
Field (Real or Cmplx)
Definition tree.hh:292
CNode Node
Node type of the tree used for the interface of the far field matrices.
Definition tree.hh:294
void cebysev(const concepts::Real3d &x0, const concepts::Real3d &x1, concepts::Real3d &c, concepts::Real &r)
Computes the Cebysev ball of two or three points.
std::string typeOf(const T &t)
Definition output.hh:43
double Real
Definition typedefs.hh:39