Class documentation of Concepts

Loading...
Searching...
No Matches
element.hh
Go to the documentation of this file.
1
6#ifndef spcElement_hh
7#define spcElement_hh
8
9#if __GNUC__ == 2
10# include <float.h>
11# define EPS DBL_EPSILON
12#else
13# include <limits>
14# define EPS std::numeric_limits<double>::epsilon()
15#endif
16
17#include <cstring>
18#include "basics/typedefs.hh"
20#include "basics/exceptions.hh"
22#include "toolbox/array.hh"
23#include "geometry/cell.hh"
24
25#include "basics/debug.hh"
26
27// debugging
28#define ElementMatrixAppl_D 0
29
30namespace concepts {
31
32 // forward declaration
33 template<class F>
34 class ElementGraphics;
35
36 template<class F>
37 class TMatrixBase;
38
39 class Cell;
40
41 // *************************************************************** Element **
42
51 template<class F>
52 class Element : public virtual OutputOperator {
53 public:
54 typedef F type;
55
57 Element() : tag_(0) {}
58 virtual ~Element() {}
59
61 virtual const TMatrixBase<F>& T() const = 0;
62
63 virtual const ElementGraphics<F>* graphics() const { return 0; }
64
66 inline uint& tag() { return tag_; }
67 private:
69 uint tag_;
70 };
71
72 // ******************************************************* ElementWithCell **
73
78 template<typename F>
79 class ElementWithCell : public Element<F> {
80 public:
81 typedef F type;
82
84 virtual const Cell& cell() const = 0;
85
86 Real3d elemMap(const Real coord_local) const {
87 return cell().elemMap(coord_local);
88 }
89
90 Real3d elemMap(const Real2d& coord_local) const {
91 return cell().elemMap(coord_local);
92 }
93
94 Real3d elemMap(const Real3d& coord_local) const {
95 return cell().elemMap(coord_local);
96 }
97
99 virtual const TMatrixBase<F>& T() const = 0;
100
101 };
102
103
104 // ****************************************************** ElementAndFacette **
105
112 template<class F>
113 class ElementAndFacette : public virtual OutputOperator {
114 public:
115 ElementAndFacette(const F* elm, const uint k)
116 : elm(elm), k(k) {}
118 const F* elm;
121 protected:
122 virtual std::ostream& info(std::ostream& os) const {
124 return os << concepts::typeOf(*this)<<"(" << *elm << ", k = " << k << ")";
125 }
126 };
127
128
129 // ***************************************************** ElementMatrixBase **
130
138 template<class F>
140 public:
141 typedef F value_type;
142
148 ElementMatrixBase() : data_(0), m_(0), n_(0), t_(false) {}
149
151 uint m() const { return t_ ? n_ : m_; }
153 uint n() const { return t_ ? m_ : n_; }
154
156 inline const F& operator()(const uint i, const uint j) const {
157 DEBUGL(ElementMatrixAppl_D, '(' << (t_ ? n_ : m_) << 'x'
158 << (t_ ? m_ : n_) << ") - " << (t_ ? j : i) << ", "
159 << (t_ ? i : j));
160 conceptsAssert(t_ ? j < m_ : i < m_, Assertion());
161 conceptsAssert(t_ ? i < n_ : j < n_, Assertion());
162 return t_ ? data_[j * n_ + i] : data_[i * n_ + j];
163 }
164
166 uint size() const { return data_.size(); }
167
169 operator const F*() const { return (const F*)data_; }
170
172 const Array<F>& getData() const { return data_; }
173
177 bool isTranspose() const { return t_; }
178
185 bool storeMatlab(const std::string filename, std::string name = "",
186 bool append = false) const;
187 protected:
195 bool t_;
196 };
197
198 // ********************************************************* ElementMatrix **
199
205 template<class F>
207 public:
208 typedef F value_type;
209
210 ElementMatrix(const uint m = 0, const uint n = 0);
211
212 ElementMatrix(const uint m, const uint n, const F* data);
213
214 virtual ~ElementMatrix() {}
215
219 void add(const ElementMatrix<F>& A, uint offm = 0, uint offn = 0);
220
222 inline const F& operator()(const uint i, const uint j) const {
224 }
225 inline F& operator()(const uint i, const uint j) {
226 DEBUGL(ElementMatrixAppl_D, '(' << this->m() << 'x' << this->n() << ") - "
227 << (this->t_ ? j : i) << ", " << (this->t_ ? i : j));
228 conceptsAssert(this->t_ ? j < this->m_ : i < this->m_, Assertion());
229 conceptsAssert(this->t_ ? i < this->n_ : j < this->n_, Assertion());
230 return this->t_ ? this->data_[j * this->n_ + i]
231 : this->data_[i * this->n_ + j];
232 }
233
235 template<class G>
237 {
238 this->data_ = other.getData();
239 i_ = other.getIndex();
240 this->m_ = other.isTranspose() ? other.n() : other.m();
241 this->n_ = other.isTranspose() ? other.m() : other.n();
242 this->t_ = other.isTranspose();
243 return *this;
244 }
245
246 virtual ElementMatrix<F>& operator=(const F& v)
247 {
248 this->data_ = v;
249 return *this;
250 }
251
257 virtual void resize(uint m, uint n);
258
260 template<uint dim>
261 void writeColumn(uint col, const Point<F,dim>& val);
262
264 void writeColumn(uint col, const Array<F>& val);
265
267 void writeColumn(uint col, const F val);
268
277 bool transpose() { return this->t_ ^= 1; }
278
286 void setTranspose(bool t) { this->t_ = t; }
287
289 int getIndex() const { return i_; }
290
292 void setIndex(int i) { i_ = i; }
293
295 void zeros() { std::memset((F*)this->data_, 0, this->n_*this->m_*sizeof(F)); }
296
298 operator F*() { return (F*)this->data_; }
299
302 this->data_ *= n;
303 return *this;
304 }
305
307 uint row() const { return this->t_ ? i_ % this->n_ : i_ / this->n_; }
309 uint col() const { return this->t_ ? i_ / this->n_ : i_ % this->n_; }
310
316 void compress(const Real threshold = EPS);
317
318 std::ostream& info(std::ostream& os) const;
319 private:
321 uint i_;
322 };
323
324 template<class F>
325 template<uint dim>
327 {
328 conceptsAssert(this->m() >= dim, Assertion());
329 for(uint i = 0; i < dim; ++i)
330 (*this)(i, col) = val[i];
331 }
332
333 template<class F>
334 std::ostream& operator<<(std::ostream& os, const ElementMatrix<F>& o) {
335#ifdef DEBUG
336 os << std::flush;
337#endif
338 return o.info(os);
339 }
340
341} // namespace concepts
342
343#endif // spcElement_hh
virtual Real3d elemMap(const Real coord_local) const
Element map from point local coordinates in 1D.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition element.hh:122
uint k
number of the edge in the underlying element
Definition element.hh:120
const F * elm
underlying 2D element
Definition element.hh:118
uint m_
Number of rows.
Definition element.hh:191
const F & operator()(const uint i, const uint j) const
Returns element (i, j)
Definition element.hh:156
const Array< F > & getData() const
Returns the data array
Definition element.hh:172
Array< F > data_
Data.
Definition element.hh:189
uint n() const
Returns the number of columns.
Definition element.hh:153
uint m() const
Returns the number of rows.
Definition element.hh:151
bool storeMatlab(const std::string filename, std::string name="", bool append=false) const
uint n_
Number of columns.
Definition element.hh:193
uint size() const
Returns the number of entries in the matrix.
Definition element.hh:166
void writeColumn(uint col, const Point< F, dim > &val)
Writes a vector to a column in case of m() >= dim.
Definition element.hh:326
const F & operator()(const uint i, const uint j) const
Returns element (i, j)
Definition element.hh:222
ElementMatrix< F > & operator=(const ElementMatrix< G > &other)
Definition element.hh:236
void writeColumn(uint col, const F val)
Writes a value to a column in case of m() >= 1.
void zeros()
Fills the matrix with zeros.
Definition element.hh:295
void add(const ElementMatrix< F > &A, uint offm=0, uint offn=0)
Addition of another element matrix with possible offset.
void writeColumn(uint col, const Array< F > &val)
Writes an array to a column.
ElementMatrix< F > & operator*=(const F n)
Scaling operator.
Definition element.hh:301
virtual void resize(uint m, uint n)
uint row() const
Returns current row.
Definition element.hh:307
void compress(const Real threshold=EPS)
ElementMatrix< F > & operator=(const ElementMatrixBase< F > &A)
Assignement operator.
void setTranspose(bool t)
Definition element.hh:286
uint col() const
Returns current column.
Definition element.hh:309
virtual const Cell & cell() const =0
Returns the cell on which the element is built.
virtual const TMatrixBase< F > & T() const =0
Returns the T matrix of the element.
uint & tag()
Returns the tag.
Definition element.hh:66
Element()
Default constructor.
Definition element.hh:57
virtual const TMatrixBase< F > & T() const =0
Returns the T matrix of the element.
#define conceptsAssert(cond, exc)
#define DEBUGL(doit, msg)
Definition debug.hh:40
std::string typeOf(const T &t)
Definition output.hh:43
double Real
Definition typedefs.hh:39
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320