matrices.hh

Go to the documentation of this file.
1 
8 #ifndef matrices1D_hh
9 #define matrices1D_hh
10 
11 #include "basics/typedefs.hh"
13 #include "basics/outputOperator.hh"
16 #include "space/element.hh"
17 
18 namespace 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  {
59  conceptsAssert(m > 1 && n > 1, concepts::Assertion());
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:
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  {
100  conceptsAssert(i < this->m_, concepts::Assertion());
101  conceptsAssert(j < this->n_, concepts::Assertion());
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)
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) {
169  conceptsAssert(i < this->m_, concepts::Assertion());
170  conceptsAssert(j < this->n_, concepts::Assertion());
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 
202 
203 } // namespace hp1D
204 
205 #endif // matrices1D_hh
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
static MassElementMatrix massElemMatrix
Definition: matrices.hh:200
Real & M(const uint i, const uint j)
Definition: matrices.hh:98
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
Returns the part of the first m rows and n columns multiplied by factor.
Definition: matrices.hh:177
Real & C(const uint i, const uint j)
Definition: matrices.hh:168
Element stiffness matrix for hp 1D FEM with Karniadakis basis on the reference intervall.
Definition: matrices.hh:30
static AdvectionElementMatrix advElemMatrix
Definition: matrices.hh:201
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
void resize(uint m)
Sets a new size and recomputes the missing entries.
Element mass matrix for hp 1D FEM with Karniadakis basis on the reference intervall.
Definition: matrices.hh:80
concepts::ElementMatrix< F > extract(uint m, uint n, const F factor) const
Returns the part of the first m rows and n columns multiplied by factor.
Definition: matrices.hh:57
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Base class for element matrices.
Definition: element.hh:139
Exception class for assertions.
Definition: exceptions.hh:258
void resize(uint m)
Sets a new size and recomputes the missing entries.
F min(const concepts::Array< F > &a)
Returns the minimal value in array a.
Definition: arrayOp.hh:67
Real & A_(const uint i, const uint j)
Definition: matrices.hh:48
uint n_
Number of columns.
Definition: element.hh:193
Element matrix.
Definition: linearForm.hh:18
StiffElementMatrix(const uint m=0)
Constructor.
Definition: matrices.hh:33
void zeros()
Fills the matrix with zeros.
Definition: element.hh:295
uint n() const
Returns the number of columns.
Definition: element.hh:153
MassElementMatrix(const uint m=0)
Constructor.
Definition: matrices.hh:83
Element mass matrix for hp 1D FEM with Karniadakis basis on the reference intervall.
Definition: matrices.hh:150
Class providing an output operator.
static StiffElementMatrix stiffElemMatrix
Declaration of static element matrices.
Definition: matrices.hh:199
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
concepts::ElementMatrix< F > extract(uint m, uint n, const F factor) const
Returns the part of the first m rows and n columns multiplied by factor.
Definition: matrices.hh:108
1D hp-FEM
AdvectionElementMatrix(const uint m=0)
Constructor.
Definition: matrices.hh:153
uint m() const
Returns the number of rows.
Definition: element.hh:151
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich