Class documentation of Concepts

Loading...
Searching...
No Matches
element.hh
Go to the documentation of this file.
1
6#ifndef aglowav2Element_hh
7#define aglowav2Element_hh
8
9#ifdef __GUNG__
10#pragma interface
11#endif
12
14#include "space/tmatrix.hh"
15#include "space/element.hh"
16#include "bem/element.hh"
17
18namespace aglowav2 {
19
20 // ************************************************************* Haar3dXXX **
21
25 template<class F = concepts::Real>
26 class Haar3dXXX : public concepts::Element<F> {
27 public:
30 class Key {
31 public:
32 inline Key() : l_(0), j_(0) {}
37 inline Key(uint l, uint j) : l_(l), j_(j) {}
38 inline Key(const Key& k) : l_(k.l()), j_(k.j()) {}
39
40 int operator==(const Key& k) const {return l_ == k.l() && j_ == k.j();}
41 int operator<(const Key& k) const {
42 return l_ < k.l() || (l_ == k.l() && j_ < k.j());
43 }
44 inline uint& l() {return l_;}
45 inline uint l() const {return l_;}
46 inline uint& j() {return j_;}
47 inline uint j() const {return j_;}
48
49 private:
50 uint l_;
51 uint j_;
52 };
53
56 concepts::Real sz, const Key& key = Key());
58 virtual ~Haar3dXXX(){};
59
61 inline const Key& key() const {return key_;}
62 inline Key& key() {return key_;}
64 inline const concepts::Real3d& center() const {return cntr_;}
66 inline concepts::Real radius() const {return rd_;}
68 inline concepts::Real size() const {return sz_;}
69
71 virtual Haar3dXXX<F>* child() const = 0;
73 virtual Haar3dXXX<F>* link() const = 0;
74
75 private:
76 concepts::Real3d cntr_;
78 Key key_;
80 };
81
82 template<class F>
84 concepts::Real sz, const Key& key)
85 : cntr_(cntr), rd_(rd), key_(key), sz_(sz) {
86 }
87
88 // **************************************************************** Matrix **
89
94 template<class F = concepts::Real>
95 class Matrix {
96 public:
103 inline Matrix(uint n, uint m, F* val, bool row)
104 : n_(n), m_(m), val_(val), row_(row) {}
105
106 inline const F* source() const {return val_;}
107 inline F* destination() const {return val_;}
108 inline uint nrow() const {return n_;}
109 inline uint ncol() const {return m_;}
110 inline bool roworder() const {return row_;}
111 inline void transpose() {
112 row_ = row_ ? 0 : 1; uint n = n_; n_ = m_; m_ = n;
113 }
114
115 private:
116 uint n_;
117 uint m_;
118 F* val_;
119 bool row_;
120 };
121
122
123 // ****************************************************************** M000 **
124
127 class M000 {
128 public:
129 friend std::ostream& operator<<(std::ostream& os, const M000& m);
130
135 M000(const concepts::Real* m, uint n);
137 ~M000() {if (m_) delete[] m_;}
138
144 template<class F>
145 void mult(const Matrix<F>& src, Matrix<F>& dst,
146 uint n = 0, uint m = 0) const;
147
153 template<class F>
154 void mult_T(const Matrix<F>& src, Matrix<F>& dst,
155 uint n = 0, uint m = 0) const;
156
166 template<class F>
167 void mult_T(const F* src, F* dst, const uint s, const uint t) const;
169 inline const concepts::Real& operator()(uint i, uint j) const {
170 return m_[i*n_ + j];
171 }
173 inline uint n() const {return n_;}
174
175 private:
177 concepts::Real* m_;
179 uint n_;
180 };
181
182 template<class F>
183 void M000::mult(const Matrix<F>& src, Matrix<F>& dst, uint n, uint m) const {
184 const F* sv = src.source();
185 F* dv = dst.destination();
186 const concepts::Real* mat = &(*this)(n, m);
187
188 if (src.roworder()) {
189 if (dst.roworder()) {
190
191 for(uint i = 0; i < dst.nrow(); i++) {
192 const concepts::Real* matrow = mat + i*n_;
193 for(uint j = 0; j < dst.ncol(); j++) {
194 *dv = 0.0;
195 const F* svj = sv + j;
196 for(uint k = 0; k < src.nrow(); k++) {
197 *dv += *svj * matrow[k]; svj += src.ncol();
198 }
199 dv++;
200 }
201 } // for i
202
203 } // if dst row order
204 else {
205
206 for(uint i = 0; i < dst.ncol(); i++) {
207 for(uint j = 0; j < dst.nrow(); j++) {
208 *dv = 0.0;
209 const concepts::Real* matrow = mat + j*n_;
210 const F* svi = sv + i;
211 for(uint k = 0; k < src.nrow(); k++) {
212 *dv += *svi * matrow[k]; svi += src.ncol();
213 }
214 dv++;
215 }
216 } // for i
217
218 } // if dst col order
219 } // if src row order
220 else {
221 if (dst.roworder()) {
222
223 for(uint i = 0; i < dst.nrow(); i++) {
224 const concepts::Real* matrow = mat + i*n_;
225 for(uint j = 0; j < dst.ncol(); j++) {
226 *dv = 0.0;
227 const F* svj = sv + j*src.nrow();
228 for(uint k = 0; k < src.nrow(); k++) {
229 *dv += *svj++ * matrow[k];
230 }
231 dv++;
232 }
233 } // for i
234
235 } // if dst row order
236 else {
237
238 for(uint i = 0; i < dst.ncol(); i++) {
239 for(uint j = 0; j < dst.nrow(); j++) {
240 *dv = 0.0;
241 const concepts::Real* matrow = mat + j*n_;
242 const F* svi = sv + i*src.nrow();
243 for(uint k = 0; k < src.nrow(); k++) {
244 *dv += *svi++ * matrow[k];
245 }
246 dv++;
247 }
248 } // for i
249
250 } // if dst col order
251 } // if src col order
252 }
253
254 template<class F>
255 void M000::mult_T(const Matrix<F>& src, Matrix<F>& dst,
256 uint n, uint m) const {
257 const F* sv = src.source();
258 F* dv = dst.destination();
259 const concepts::Real* mat = &(*this)(m, n);
260
261 if (src.roworder()) {
262 if (dst.roworder()) {
263
264 for(uint i = 0; i < dst.nrow(); i++) {
265 for(uint j = 0; j < dst.ncol(); j++) {
266 *dv = 0.0;
267 const concepts::Real* matrow = mat + i;
268 const F* svj = sv + j;
269 for(uint k = 0; k < src.nrow(); k++) {
270 *dv += *svj * *matrow; svj += src.ncol(); matrow += n_;
271 }
272 dv++;
273 }
274 } // for i
275
276 } // if dst row order
277 else {
278
279 for(uint i = 0; i < dst.ncol(); i++) {
280 for(uint j = 0; j < dst.nrow(); j++) {
281 *dv = 0.0;
282 const concepts::Real* matrow = mat + j;
283 const F* svi = sv + i;
284 for(uint k = 0; k < src.nrow(); k++) {
285 *dv += *svi * *matrow; svi += src.ncol(); matrow += n_;
286 }
287 dv++;
288 }
289 } // for i
290
291 } // if dst col order
292 } // if src row order
293 else {
294 if (dst.roworder()) {
295
296 for(uint i = 0; i < dst.nrow(); i++) {
297 for(uint j = 0; j < dst.ncol(); j++) {
298 *dv = 0.0;
299 const concepts::Real* matrow = mat + i;
300 const F* svj = sv + j*src.nrow();
301 for(uint k = 0; k < src.nrow(); k++) {
302 *dv += *svj++ * *matrow; matrow += n_;
303 }
304 dv++;
305 }
306 } // for i
307
308 } // if dst row order
309 else {
310
311 for(uint i = 0; i < dst.ncol(); i++) {
312 for(uint j = 0; j < dst.nrow(); j++) {
313 *dv = 0.0;
314 const concepts::Real* matrow = mat + j;
315 const F* svi = sv + i*src.nrow();
316 for(uint k = 0; k < src.nrow(); k++) {
317 *dv += *svi++ * *matrow; matrow += n_;
318 }
319 dv++;
320 }
321 } // for i
322
323 } // if dst col order
324 } // if src col order
325 }
326
327 template<class F>
328 void M000::mult_T(const F* src, F* dst, const uint s, const uint t) const {
329 for(uint i = 0; i < t; i++) {
330 for(uint j = 0; j < s; j++) {
331 concepts::Real* mi = m_ + i;
332 const F* sj = src + j;
333 *dst = 0.0;
334 for(uint k = 0; k < n_; k++, mi += n_, sj += s) *dst += *sj * *mi;
335 dst++;
336 }
337 }
338 }
339
340 // ************************************************************* Haar3d000 **
341
345 template<class F = concepts::Real>
346 class Haar3d000 : public Haar3dXXX<F> {
347 public:
362 const concepts::Real* m, uint n, uint idx[], uint idxn,
364 const bem::Constant3d002<F>** elm, uint nelm);
366 ~Haar3d000() {delete T_; if (nelm_) delete[] elm_;}
367
369 Haar3d000<F>* child() const {return chld_;}
371 Haar3d000<F>* link() const {return lnk_;}
372 inline Haar3d000<F>*& link() {return lnk_;}
374 const bem::Constant3d002<F>* element(uint j) const;
376 inline uint nelement() const {return nelm_;}
380 inline uint gamma() const {return gamma_;}
381 inline uint& gamma() {return gamma_;}
382
384 inline const concepts::TMatrixBase<F>& T() const {return *T_;}
386 inline void replaceT(uint idx[], uint idxn);
388 inline const M000& trafoM() const {return M_;}
390 inline uint index() const {return idx_;}
391
392 protected:
394 std::ostream& info(std::ostream& os) const;
395
396 private:
398 M000 M_;
400 const concepts::TIndex<F>* T_;
402 concepts::Real sz_;
404 Haar3d000* lnk_;
406 Haar3d000* chld_;
408 const bem::Constant3d002<F>** elm_;
410 uint nelm_;
412 uint gamma_;
414 uint idx_;
415
416 static uint index_;
417 };
418
419 template<class F>
421 const concepts::Real* m, uint n,
422 uint idx[], uint idxn, concepts::Real sz,
423 Haar3d000<F>* chld,
424 const bem::Constant3d002<F>** elm, uint nelm)
425 : Haar3dXXX<F>(cntr, rd, sz), M_(m, n),
426 lnk_(0), chld_(chld), nelm_(nelm), gamma_(1), idx_(index_++) {
427
428 T_ = new concepts::TIndex<F>(idxn, idxn, idx);
429
430 if (nelm) {
431 elm_ = new const bem::Constant3d002<F>*[nelm_];
432 std::memcpy(elm_, elm, nelm_*sizeof(elm[0]));
433 }
434 else elm_ = 0;
435 }
436
437 template<class F>
439 return (j < nelm_) ? elm_[j] : (bem::Constant3d002<F>*)0;
440 }
441
442 template<class F>
443 void Haar3d000<F>::replaceT(uint idx[], uint idxn) {
444 delete T_;
445 T_ = new concepts::TIndex<F>(idxn, idxn, idx);
446 }
447
448} // namespace aglowav2
449
450#endif //aglowav2Element_hh
uint nelement() const
Number of elements.
Definition element.hh:376
std::ostream & info(std::ostream &os) const
Information about the element.
Haar3d000(const concepts::Real3d &cntr, concepts::Real rd, const concepts::Real *m, uint n, uint idx[], uint idxn, concepts::Real sz, Haar3d000< F > *chld, const bem::Constant3d002< F > **elm, uint nelm)
Definition element.hh:420
const concepts::TMatrixBase< F > & T() const
Global degree of freedom.
Definition element.hh:384
Haar3d000< F > * child() const
Children.
Definition element.hh:369
~Haar3d000()
Destructor.
Definition element.hh:366
uint gamma() const
Definition element.hh:380
const M000 & trafoM() const
Local transformation matrix.
Definition element.hh:388
Haar3d000< F > * link() const
Elements on the same level.
Definition element.hh:371
uint index() const
Index defined and used by some operators.
Definition element.hh:390
const bem::Constant3d002< F > * element(uint j) const
-th element of the wavelet
Definition element.hh:438
void replaceT(uint idx[], uint idxn)
Replace the T matrix (used for the sparsity pattern of the operator)
Definition element.hh:443
Key(uint l, uint j)
Definition element.hh:37
const Key & key() const
Key of the element.
Definition element.hh:61
concepts::Real size() const
Size of the support.
Definition element.hh:68
concepts::Real radius() const
Radius of the element.
Definition element.hh:66
virtual Haar3dXXX< F > * child() const =0
children of the element
const concepts::Real3d & center() const
Center of the element.
Definition element.hh:64
Haar3dXXX(const concepts::Real3d &cntr, concepts::Real rd, concepts::Real sz, const Key &key=Key())
Constructor.
Definition element.hh:83
virtual Haar3dXXX< F > * link() const =0
elements on the same level
virtual ~Haar3dXXX()
Destructor.
Definition element.hh:58
~M000()
destructor
Definition element.hh:137
const concepts::Real & operator()(uint i, uint j) const
returns the matrix element
Definition element.hh:169
void mult_T(const Matrix< F > &src, Matrix< F > &dst, uint n=0, uint m=0) const
Definition element.hh:255
uint n() const
returns the matrix dimension
Definition element.hh:173
void mult(const Matrix< F > &src, Matrix< F > &dst, uint n=0, uint m=0) const
Definition element.hh:183
M000(const concepts::Real *m, uint n)
Matrix(uint n, uint m, F *val, bool row)
Definition element.hh:103
double Real
Definition typedefs.hh:39
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320