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 
18 namespace 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 
55  inline Haar3dXXX(const concepts::Real3d& cntr, concepts::Real rd,
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:
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:
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,
363  concepts::Real sz, Haar3d000<F>* chld,
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:
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 nelm_
Number of elements in elm_.
Definition: element.hh:410
Matrix class to convert an array to a matrix without copying.
Definition: element.hh:95
const concepts::TIndex< F > * T_
Global degree of freedom.
Definition: element.hh:400
An abstract class for an element of a space.
Definition: exceptions.hh:15
const concepts::Real & operator()(uint i, uint j) const
returns the matrix element
Definition: element.hh:169
const concepts::TMatrixBase< F > & T() const
Global degree of freedom.
Definition: element.hh:384
M000(const concepts::Real *m, uint n)
Constructor.
void transpose()
Definition: element.hh:111
concepts::Real size() const
Size of the support.
Definition: element.hh:68
uint n_
matrix dimension
Definition: element.hh:179
Local transformation matrix (square matrix, row wise)
Definition: element.hh:127
Key(const Key &k)
Definition: element.hh:38
F * destination() const
Definition: element.hh:107
void replaceT(uint idx[], uint idxn)
Replace the T matrix (used for the sparsity pattern of the operator)
Definition: element.hh:443
Key of a wavelet element.
Definition: element.hh:30
Haar3d000 * lnk_
Wavelets on the same level.
Definition: element.hh:404
Haar3d000 * chld_
Wavelets on the next finer level.
Definition: element.hh:406
uint index() const
Index defined and used by some operators.
Definition: element.hh:390
Abstract wavelet space element.
Definition: element.hh:26
uint idx_
Index defined and used by some operators.
Definition: element.hh:414
Matrix(uint n, uint m, F *val, bool row)
Constructor.
Definition: element.hh:103
Haar3d000< F > * link() const
Elements on the same level.
Definition: element.hh:371
virtual ~Haar3dXXX()
Destructor.
Definition: element.hh:58
Key(uint l, uint j)
Constructor.
Definition: element.hh:37
concepts::Real * m_
matrix entries
Definition: element.hh:177
void mult(const Matrix< F > &src, Matrix< F > &dst, uint n=0, uint m=0) const
Multiplication of src with a part of to dst.
Definition: element.hh:183
uint ncol() const
Definition: element.hh:109
const bem::Constant3d002< F > * element(uint j) const
-th element of the wavelet
Definition: element.hh:438
concepts::Real rd_
Definition: element.hh:77
const bem::Constant3d002< F > ** elm_
Elements belonging to the support.
Definition: element.hh:408
~M000()
destructor
Definition: element.hh:137
void mult_T(const Matrix< F > &src, Matrix< F > &dst, uint n=0, uint m=0) const
Multiplication of src with a part of to dst.
Definition: element.hh:255
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)
Constructor.
Definition: element.hh:420
virtual Haar3dXXX< F > * link() const =0
elements on the same level
const concepts::Real3d & center() const
Center of the element.
Definition: element.hh:64
Used for the aglowav2 classes for the boundary element method.
Definition: bform.hh:16
const Key & key() const
Key of the element.
Definition: element.hh:61
static uint index_
Definition: element.hh:416
Space element for the agglomerated wavelets.
Definition: element.hh:346
Haar3d000< F > * child() const
Children.
Definition: element.hh:369
Binary space element for the agglomerated wavelets.
Definition: element.hh:162
std::ostream & info(std::ostream &os) const
Information about the element.
uint n() const
returns the matrix dimension
Definition: element.hh:173
uint nrow() const
Definition: element.hh:108
const F * source() const
Definition: element.hh:106
concepts::Real sz_
Definition: element.hh:79
bool roworder() const
Definition: element.hh:110
uint gamma() const
Multiplication of the number of children of the elements on the coarser levels (used to approxiamte t...
Definition: element.hh:380
Haar3d000< F > *& link()
elements on the same level
Definition: element.hh:372
~Haar3d000()
Destructor.
Definition: element.hh:366
virtual Haar3dXXX< F > * child() const =0
children of the element
An abstract class for a T matrix.
Definition: element.hh:37
Constant triangular element with normed basis function.
Definition: element.hh:427
concepts::Real radius() const
Radius of the element.
Definition: element.hh:66
friend std::ostream & operator<<(std::ostream &os, const M000 &m)
M000 M_
Local transformation matrix.
Definition: element.hh:398
uint nelement() const
Number of elements.
Definition: element.hh:376
int operator==(const Key &k) const
Definition: element.hh:40
int operator<(const Key &k) const
Definition: element.hh:41
const M000 & trafoM() const
Local transformation matrix.
Definition: element.hh:388
concepts::Real sz_
Support size of the element.
Definition: element.hh:402
Haar3dXXX(const concepts::Real3d &cntr, concepts::Real rd, concepts::Real sz, const Key &key=Key())
Constructor.
Definition: element.hh:83
concepts::Real3d cntr_
Definition: element.hh:76
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
T matrix for linear and regular elements.
Definition: tmatrix.hh:428
uint gamma_
Multiplication of the number of children of elements on coarser levels.
Definition: element.hh:412
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich