00001
00006 #ifndef matrices1D_hh
00007 #define matrices1D_hh
00008
00009 #include "basics/typedefs.hh"
00010 #include "basics/vectorsMatricesForward.hh"
00011 #include "basics/outputOperator.hh"
00012 #include "integration/quadrature.hh"
00013 #include "integration/karniadakis.hh"
00014 #include "space/element.hh"
00015
00016 namespace hp1D {
00017
00018 using concepts::Real;
00019
00020
00021
00027 class StiffElementMatrix :
00028 public concepts::ElementMatrixBase<Real>, public concepts::OutputOperator {
00029 public:
00031 StiffElementMatrix(const uint m = 0) : concepts::ElementMatrixBase<Real>()
00032 { resize(m); }
00033
00035 void resize(uint m);
00036
00041 template<typename F>
00042 concepts::ElementMatrix<F> extract(uint m, uint n, const F factor) const;
00043 protected:
00044 virtual std::ostream& info(std::ostream& os) const;
00045 private:
00046 inline Real& A_(const uint i, const uint j) {
00047 conceptsAssert(i < this->m_, concepts::Assertion());
00048 conceptsAssert(j < this->n_, concepts::Assertion());
00049 return this->data_[i * this->n_ + j];
00050 }
00051 };
00052
00053 template<typename F>
00054 concepts::ElementMatrix<F>
00055 StiffElementMatrix::extract(uint m, uint n, const F factor) const
00056 {
00057 conceptsAssert(m > 1 && n > 1, concepts::Assertion());
00058 conceptsAssert(m <= this->m_ && n <= this->n_, concepts::Assertion());
00059
00060 concepts::ElementMatrix<F> em(m,n); em.zeros();
00061
00062 em(0,0) = em(1,1) = factor;
00063 em(1,0) = em(0,1) = -factor;
00064 for(uint j = 2; j < std::min(m, n); ++j)
00065 em(j,j) = (*this)(j,j)*factor;
00066
00067 return em;
00068 }
00069
00070
00071
00077 class MassElementMatrix :
00078 public concepts::ElementMatrixBase<Real>, public concepts::OutputOperator {
00079 public:
00081 MassElementMatrix(const uint m = 0) : concepts::ElementMatrixBase<Real>()
00082 { resize(m); }
00083
00085 void resize(uint m);
00086
00091 template<typename F>
00092 concepts::ElementMatrix<F> extract(uint m, uint n, const F factor) const;
00093 protected:
00094 virtual std::ostream& info(std::ostream& os) const;
00095 private:
00096 inline Real& M(const uint i, const uint j)
00097 {
00098 conceptsAssert(i < this->m_, concepts::Assertion());
00099 conceptsAssert(j < this->n_, concepts::Assertion());
00100 return this->data_[i * this->n_ + j];
00101 }
00102 };
00103
00104 template<typename F>
00105 concepts::ElementMatrix<F>
00106 MassElementMatrix::extract(uint m, uint n, const F factor) const
00107 {
00108 conceptsAssert(m > 1 && n > 1, concepts::Assertion());
00109 conceptsAssert(m <= this->m_ && n <= this->n_, concepts::Assertion());
00110
00111 concepts::ElementMatrix<F> em(m,n); em.zeros();
00112
00113 em(0,0) = em(1,1) = (*this)(0,0)*factor;
00114 em(1,0) = em(0,1) = (*this)(1,0)*factor;
00115 if (m > 2) {
00116 if (n > 2) {
00117 em(0,2) = em(1,2) = em(2,1) = em(2,0) = (*this)(0,2)*factor;
00118 em(2,2) = (*this)(2,2)*factor;
00119 } else {
00120 em(2,1) = em(2,0) = (*this)(2,0)*factor;
00121 }
00122 } else if (n > 2) {
00123 em(0,2) = em(1,2) = (*this)(0,2)*factor;
00124 }
00125 if (m > 3)
00126 em(3,0) = (*this)(3,0)*factor;
00127 if (n > 3)
00128 em(0,3) = (*this)(0,3)*factor;
00129
00130 for(uint j = 3; j < std::min(m, n); ++j)
00131 em(j,j) = (*this)(j,j) *factor;
00132 for(uint j = 3; j < std::min(m+2, n); ++j)
00133 em(j-2,j) = (*this)(j-2,j)*factor;
00134 for(uint j = 3; j < std::min(m, n+2); ++j)
00135 em(j,j-2) = (*this)(j,j-2)*factor;
00136
00137 return em;
00138 }
00139
00140
00141
00147 class AdvectionElementMatrix :
00148 public concepts::ElementMatrixBase<Real>, public concepts::OutputOperator {
00149 public:
00151 AdvectionElementMatrix(const uint m = 0)
00152 : concepts::ElementMatrixBase<Real>() { resize(m); }
00153
00155 void resize(uint m);
00156
00161 template<typename F>
00162 concepts::ElementMatrix<F> extract(uint m, uint n, const F factor) const;
00163 protected:
00164 virtual std::ostream& info(std::ostream& os) const;
00165 private:
00166 inline Real& C(const uint i, const uint j) {
00167 conceptsAssert(i < this->m_, concepts::Assertion());
00168 conceptsAssert(j < this->n_, concepts::Assertion());
00169 return this->data_[i * this->n_ + j];
00170 }
00171 };
00172
00173 template<typename F>
00174 concepts::ElementMatrix<F>
00175 AdvectionElementMatrix::extract(uint m, uint n, const F factor) const
00176 {
00177 conceptsAssert(m > 1 && n > 1, concepts::Assertion());
00178 conceptsAssert(m <= this->m_ && n <= this->n_, concepts::Assertion());
00179
00180 concepts::ElementMatrix<F> em(m,n); em.zeros();
00181
00182 em(0,0) = em(0,1) = (*this)(0,0)*factor;
00183 em(1,0) = em(1,1) = (*this)(1,0)*factor;
00184 if (n > 2)
00185 em(0,2) = (*this)(0,2)*factor;
00186 if (m > 2)
00187 em(2,0) = -(*this)(0,2)*factor;
00188 for(uint j = 2; j < std::min(m+1, n); ++j)
00189 em(j-1,j) = (*this)(j-1,j)*factor;
00190 for(uint j = 2; j < std::min(m, n+1); ++j)
00191 em(j,j-1) = -(*this)(j-1,j)*factor;
00192
00193 return em;
00194 }
00195
00197 static StiffElementMatrix stiffElemMatrix;
00198 static MassElementMatrix massElemMatrix;
00199 static AdvectionElementMatrix advElemMatrix;
00200
00201 }
00202
00203 #endif // matrices1D_hh