Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef spcElement_hh
00006 #define spcElement_hh
00007
00008 #if __GNUC__ == 2
00009 # include <float.h>
00010 # define EPS DBL_EPSILON
00011 #else
00012 # include <limits>
00013 # define EPS std::numeric_limits<double>::epsilon()
00014 #endif
00015
00016 #include <cstring>
00017 #include "basics/typedefs.hh"
00018 #include "basics/outputOperator.hh"
00019 #include "basics/exceptions.hh"
00020 #include "basics/vectorsMatricesForward.hh"
00021 #include "toolbox/array.hh"
00022 #include "geometry/cell.hh"
00023
00024 #include "basics/debug.hh"
00025
00026
00027 #define ElementMatrixAppl_D 0
00028
00029 namespace concepts {
00030
00031
00032 template<class F>
00033 class ElementGraphics;
00034
00035 template<class F>
00036 class TMatrixBase;
00037
00038 class Cell;
00039
00040
00041
00050 template<class F>
00051 class Element : public OutputOperator {
00052 public:
00053 typedef F type;
00054
00056 Element() : tag_(0) {}
00057 virtual ~Element() {}
00058
00060 virtual const TMatrixBase<F>& T() const = 0;
00061
00062 virtual const ElementGraphics<F>* graphics() const { return 0; }
00063
00065 inline uint& tag() { return tag_; }
00066 private:
00068 uint tag_;
00069 };
00070
00071
00072
00077 template<typename F>
00078 class ElementWithCell : public Element<F> {
00079 public:
00081 virtual const Cell& cell() const = 0;
00082
00083 Real3d elemMap(const Real coord_local) const {
00084 return cell().elemMap(coord_local);
00085 }
00086
00087 Real3d elemMap(const Real2d& coord_local) const {
00088 return cell().elemMap(coord_local);
00089 }
00090
00091 Real3d elemMap(const Real3d& coord_local) const {
00092 return cell().elemMap(coord_local);
00093 }
00094
00095 };
00096
00097
00098
00099
00106 template<class F>
00107 class ElementAndFacette : public concepts::OutputOperator {
00108 public:
00109 ElementAndFacette(const F* elm, const uint k)
00110 : elm(elm), k(k) {}
00112 const F* elm;
00114 uint k;
00115 protected:
00116 virtual std::ostream& info(std::ostream& os) const {
00117 conceptsAssert(elm, concepts::Assertion());
00118 return os << "ElementAndFacette(" << *elm << ", k = " << k << ")";
00119 }
00120 };
00121
00122
00123
00124
00132 template<class F>
00133 class ElementMatrixBase {
00134 public:
00135 typedef F value_type;
00136
00137 ElementMatrixBase() : data_(0), m_(0), n_(0), t_(false) {}
00138
00140 uint m() const { return t_ ? n_ : m_; }
00142 uint n() const { return t_ ? m_ : n_; }
00143
00145 inline F operator()(const uint i, const uint j) const {
00146 DEBUGL(ElementMatrixAppl_D, '(' << (t_ ? n_ : m_) << 'x'
00147 << (t_ ? m_ : n_) << ") - " << (t_ ? j : i) << ", "
00148 << (t_ ? i : j));
00149 conceptsAssert(t_ ? j < m_ : i < m_, Assertion());
00150 conceptsAssert(t_ ? i < n_ : j < n_, Assertion());
00151 return t_ ? data_[j * n_ + i] : data_[i * n_ + j];
00152 }
00153
00155 uint size() const { return data_.size(); }
00156
00158 operator const F*() const { return (const F*)data_; }
00159
00161 const Array<F>& getData() const { return data_; }
00162
00164 bool isTranspose() const { return t_; }
00165
00172 bool storeMatlab(const std::string filename, std::string name = "",
00173 bool append = false) const;
00174 protected:
00176 Array<F> data_;
00178 uint m_;
00180 uint n_;
00182 bool t_;
00183 };
00184
00185
00186
00192 template<class F>
00193 class ElementMatrix : public ElementMatrixBase<F> {
00194 public:
00195 typedef F value_type;
00196
00197 ElementMatrix(const uint m = 0, const uint n = 0);
00198
00199 ElementMatrix(const uint m, const uint n, const F* data);
00200
00202 ElementMatrix<F>& operator=(const ElementMatrixBase<F>& A);
00204 void add(const ElementMatrix<F>& A, uint offm = 0, uint offn = 0);
00205
00207 inline F operator()(const uint i, const uint j) const {
00208 return ElementMatrixBase<F>::operator()(i, j);
00209 }
00210 inline F& operator()(const uint i, const uint j) {
00211 DEBUGL(ElementMatrixAppl_D, '(' << this->m() << 'x' << this->n() << ") - "
00212 << (this->t_ ? j : i) << ", " << (this->t_ ? i : j));
00213 conceptsAssert(this->t_ ? j < this->m_ : i < this->m_, Assertion());
00214 conceptsAssert(this->t_ ? i < this->n_ : j < this->n_, Assertion());
00215 return this->t_ ? this->data_[j * this->n_ + i]
00216 : this->data_[i * this->n_ + j];
00217 }
00218
00220 template<class G>
00221 ElementMatrix<F>& operator=(const ElementMatrix<G>& other)
00222 {
00223 this->data_ = other.getData();
00224 i_ = other.getIndex();
00225 this->m_ = other.isTranspose() ? other.n() : other.m();
00226 this->n_ = other.isTranspose() ? other.m() : other.n();
00227 this->t_ = other.isTranspose();
00228 return *this;
00229 }
00230
00232 void resize(uint m, uint n);
00233
00237 bool transpose() { return this->t_ ^= 1; }
00238
00239 void setTranspose(bool t) { this->t_ = t; }
00240
00242 int getIndex() const { return i_; }
00243
00245 void setIndex(int i) { i_ = i; }
00246
00248 void zeros() { std::memset((F*)this->data_, 0, this->n_*this->m_*sizeof(F)); }
00249
00251 operator F*() { return (F*)this->data_; }
00252
00254 ElementMatrix<F>& operator*=(const F n) {
00255 this->data_ *= n;
00256 return *this;
00257 }
00258
00260 uint row() const { return this->t_ ? i_ % this->n_ : i_ / this->n_; }
00262 uint col() const { return this->t_ ? i_ / this->n_ : i_ % this->n_; }
00263
00269 void compress(const Real threshold = EPS);
00270
00271 std::ostream& info(std::ostream& os) const;
00272 private:
00274 uint i_;
00275 };
00276
00277 template<class F>
00278 std::ostream& operator<<(std::ostream& os, const ElementMatrix<F>& o) {
00279 #ifdef DEBUG
00280 os << std::flush;
00281 #endif
00282 return o.info(os);
00283 }
00284
00285 }
00286
00287 #endif // spcElement_hh