Class documentation of Concepts

Loading...
Searching...
No Matches
matrices.hh
Go to the documentation of this file.
1
8#ifndef matrices1D_hh
9#define matrices1D_hh
10
11#include "basics/typedefs.hh"
16#include "space/element.hh"
17
18namespace hp1D {
19
20 using concepts::Real;
21
22 // **************************************************** StiffElementMatrix **
23
31 public:
34 { resize(m); }
35
37 void resize(uint m);
38
43 template<typename F>
44 concepts::ElementMatrix<F> extract(uint m, uint n, const F factor) const;
45 protected:
46 virtual std::ostream& info(std::ostream& os) const;
47 private:
48 inline Real& A_(const uint i, const uint j) {
51 return this->data_[i * this->n_ + j];
52 }
53 };
54
55 template<typename F>
57 StiffElementMatrix::extract(uint m, uint n, const F factor) const
58 {
60 conceptsAssert(m <= this->m_ && n <= this->n_, concepts::Assertion());
61
63
64 em(0,0) = em(1,1) = factor;
65 em(1,0) = em(0,1) = -factor;
66 for(uint j = 2; j < std::min(m, n); ++j)
67 em(j,j) = (*this)(j,j)*factor;
68
69 return em;
70 }
71
72 // **************************************************** MassElementMatrix **
73
81 public:
83 MassElementMatrix(const uint m = 0) : concepts::ElementMatrixBase<Real>()
84 { resize(m); }
85
87 void resize(uint m);
88
93 template<typename F>
94 concepts::ElementMatrix<F> extract(uint m, uint n, const F factor) const;
95 protected:
96 virtual std::ostream& info(std::ostream& os) const;
97 private:
98 inline Real& M(const uint i, const uint j)
99 {
102 return this->data_[i * this->n_ + j];
103 }
104 };
105
106 template<typename F>
108 MassElementMatrix::extract(uint m, uint n, const F factor) const
109 {
110 conceptsAssert(m > 1 && n > 1, concepts::Assertion());
111 conceptsAssert(m <= this->m_ && n <= this->n_, concepts::Assertion());
112
114
115 em(0,0) = em(1,1) = (*this)(0,0)*factor;
116 em(1,0) = em(0,1) = (*this)(1,0)*factor;
117 if (m > 2) {
118 if (n > 2) {
119 em(0,2) = em(1,2) = em(2,1) = em(2,0) = (*this)(0,2)*factor;
120 em(2,2) = (*this)(2,2)*factor;
121 } else {
122 em(2,1) = em(2,0) = (*this)(2,0)*factor;
123 }
124 } else if (n > 2) {
125 em(0,2) = em(1,2) = (*this)(0,2)*factor;
126 }
127 if (m > 3)
128 em(3,0) = (*this)(3,0)*factor;
129 if (n > 3)
130 em(0,3) = (*this)(0,3)*factor;
131
132 for(uint j = 3; j < std::min(m, n); ++j)
133 em(j,j) = (*this)(j,j) *factor;
134 for(uint j = 3; j < std::min(m+2, n); ++j)
135 em(j-2,j) = (*this)(j-2,j)*factor;
136 for(uint j = 3; j < std::min(m, n+2); ++j)
137 em(j,j-2) = (*this)(j,j-2)*factor;
138
139 return em;
140 }
141
142 // **************************************************** AdvectionElementMatrix **
143
151 public:
153 AdvectionElementMatrix(const uint m = 0)
154 : concepts::ElementMatrixBase<Real>() { resize(m); }
155
157 void resize(uint m);
158
163 template<typename F>
164 concepts::ElementMatrix<F> extract(uint m, uint n, const F factor) const;
165 protected:
166 virtual std::ostream& info(std::ostream& os) const;
167 private:
168 inline Real& C(const uint i, const uint j) {
171 return this->data_[i * this->n_ + j];
172 }
173 };
174
175 template<typename F>
177 AdvectionElementMatrix::extract(uint m, uint n, const F factor) const
178 {
179 conceptsAssert(m > 1 && n > 1, concepts::Assertion());
180 conceptsAssert(m <= this->m_ && n <= this->n_, concepts::Assertion());
181
183
184 em(0,0) = em(0,1) = (*this)(0,0)*factor;
185 em(1,0) = em(1,1) = (*this)(1,0)*factor;
186 if (n > 2)
187 em(0,2) = (*this)(0,2)*factor;
188 if (m > 2)
189 em(2,0) = -(*this)(0,2)*factor;
190 for(uint j = 2; j < std::min(m+1, n); ++j)
191 em(j-1,j) = (*this)(j-1,j)*factor;
192 for(uint j = 2; j < std::min(m, n+1); ++j)
193 em(j,j-1) = -(*this)(j-1,j)*factor;
194
195 return em;
196 }
197
199 static StiffElementMatrix stiffElemMatrix;
200 static MassElementMatrix massElemMatrix;
201 static AdvectionElementMatrix advElemMatrix;
202
203} // namespace hp1D
204
205#endif // matrices1D_hh
uint n() const
Returns the number of columns.
Definition element.hh:153
uint m() const
Returns the number of rows.
Definition element.hh:151
uint n_
Number of columns.
Definition element.hh:193
void zeros()
Fills the matrix with zeros.
Definition element.hh:295
concepts::ElementMatrix< F > extract(uint m, uint n, const F factor) const
Definition matrices.hh:177
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void resize(uint m)
Sets a new size and recomputes the missing entries.
AdvectionElementMatrix(const uint m=0)
Constructor.
Definition matrices.hh:153
MassElementMatrix(const uint m=0)
Constructor.
Definition matrices.hh:83
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void resize(uint m)
Sets a new size and recomputes the missing entries.
concepts::ElementMatrix< F > extract(uint m, uint n, const F factor) const
Definition matrices.hh:108
void resize(uint m)
Sets a new size and recomputes the missing entries.
StiffElementMatrix(const uint m=0)
Constructor.
Definition matrices.hh:33
concepts::ElementMatrix< F > extract(uint m, uint n, const F factor) const
Definition matrices.hh:57
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
#define conceptsAssert(cond, exc)
double Real
Definition typedefs.hh:39