denseMatrix.hh

Go to the documentation of this file.
1 
6 #ifndef denseMatrix_hh
7 #define denseMatrix_hh
8 
9 #include "space/element.hh"
10 #include "compositions.hh"
11 #include "matrix.hh"
12 #include <new> // exception handling for function new
13 
14 #include <type_traits>
15 #include <typeinfo>
16 
17 namespace concepts {
18 
19  // forward declaration
20  template<class F>
21  class Space;
22 
23  template<class F, class G>
24  class BilinearForm;
25 
26  // *********************************************************** DenseMatrix **
27 
43  template<class F>
44  class DenseMatrix : public Matrix<F>, public ElementMatrix<F> {
45  public:
47  typedef typename Realtype<F>::type r_type;
49  typedef typename Cmplxtype<F>::type c_type;
51  typedef typename std::conditional<std::is_same<typename Realtype<F>::type, F>::value ,
52  typename Realtype<F>::type, typename Cmplxtype<F>::type >::type d_type;
53 
76  template<class G>
77  DenseMatrix(const Space<G>& spcX, const Space<G>& spcY,
78  const BilinearForm<F,G>& bf, const bool single=true);
79 
92  template<class G>
93  DenseMatrix(const Space<G>& spc, const BilinearForm<F,G>& bf);
104  template<class G>
105  DenseMatrix(const Space<G>& spc, const BilinearForm<F,G>& bf,
106  const Sequence<ElementWithCell<G> * > & seq);
112  template<class G>
113  DenseMatrix(const Space<G>& spcX, const Space<G>& spcY);
114 
121  DenseMatrix(int m = 0, int n = 0, bool transpose = false)
122  : Matrix<F>(m, n), ElementMatrix<F>(transpose ? n : m, transpose ? m : n)
123  {
124  if(transpose)
125  this->transpose();
126  }
127 
131  DenseMatrix(const LiCo<F>& L);
141  DenseMatrix(const Matrix<F>& m, bool t = false);
146  DenseMatrix(const Vector<F>& v, bool t = false);
147 
148  virtual void operator()(const Function<r_type>& fncY,
149  Function<F>& fncX);
150  virtual void operator()(const Function<c_type>& fncY,
151  Function<c_type>& fncX);
152 
153  template<class H, class I>
154  void operator()(const Vector<H>& fncY, Vector<I>& fncX);
155 
156  virtual void transpMult(const Vector<r_type>& fncY,
157  Vector<F>& fncX);
158  virtual void transpMult(const Vector<c_type>& fncY,
159  Vector<c_type>& fncX);
160 
161  virtual F operator()(const uint i, const uint j) const {
162  return ElementMatrix<F>::operator()(i,j);
163  }
164 
165  virtual F& operator()(const uint i, const uint j) {
166  return ElementMatrix<F>::operator()(i,j);
167  }
168 
169  virtual DenseMatrix<F>& operator=(const F& v)
170  {
172  return *this;
173  }
174 
178  virtual void resize(uint m, uint n) {
179  ElementMatrix<F>::resize(this->dimX_ = m, this->dimY_ = n);
180  }
181 
182  virtual void setTranspose(bool t) {
183  if(this->isTranspose() != t) std::swap(this->dimX_,this->dimY_);
185  }
186 
191  void addInto(Matrix<F>& dest, const F fact,
192  const uint rowoffset = 0, const uint coloffset = 0) const;
193 
195  template<class T>
196  void addInto(Matrix<T>& dest, const T fact,
197  const uint rowoffset = 0, const uint coloffset = 0) const
198  {
199  conceptsAssert(dest.dimX() >= this->dimX() + rowoffset, Assertion());
200  conceptsAssert3(dest.dimY() >= this->dimY() + coloffset, Assertion(),
201  "dest.dimY() = " << dest.dimY() << ", dimY() = " <<
202  this->dimY() << ", coloffset = " << coloffset);
203  for (uint i = 0; i < this->dimX(); ++i)
204  for (uint j = 0; j < this->dimY(); ++j) {
205  const F a = operator()(i,j);
206  dest(i+rowoffset,j+coloffset) += a*fact;
207  }
208  };
209 
211  template<class T>
212  void addIntoT(Matrix<T>& dest, const T fact,
213  const uint rowoffset = 0, const uint coloffset = 0) const {
214  conceptsAssert(dest.dimY() >= this->dimX() + coloffset, Assertion());
215  conceptsAssert3(dest.dimX() >= this->dimY() + rowoffset, Assertion(),
216  "dest.dimY() = " << dest.dimY() << ", dimY() = " <<
217  this->dimY() << ", coloffset = " << coloffset);
218  for (uint i = 0; i < this->dimX(); ++i)
219  for (uint j = 0; j < this->dimY(); ++j) {
220  const F a = operator()(i,j);
221  dest(j+rowoffset,i+coloffset) += a*fact;
222  }
223  };
224 
225  protected:
226  virtual std::ostream& info(std::ostream& os) const;
227  };
228 
229  template<class F>
230  template<class H, class I>
232  {
233  conceptsAssert(ElementMatrix<F>::m() == fncX.dim(), Assertion());
234  conceptsAssert(ElementMatrix<F>::n() == fncY.dim(), Assertion());
235  const F* m = (const F*)this->getData();
236  I* x(fncX);
237  for (uint i = 0; i < ElementMatrix<F>::m(); ++i) {
238  H* y(fncY);
239  I fi = 0.0;
240  for (uint j = 0; j < ElementMatrix<F>::n(); ++j)
241  fi += *m++ * *y++;
242  *x++ = fi;
243  }
244  }
245 
246 } // namespace concepts
247 
248 #endif // senseMatrix_hh
virtual void transpMult(const Vector< c_type > &fncY, Vector< c_type > &fncX)
void setTranspose(bool t)
Sets the transpose status to t.
Definition: element.hh:286
DenseMatrix(const Space< G > &spcX, const Space< G > &spcY, const BilinearForm< F, G > &bf, const bool single=true)
Constructor.
virtual F operator()(const uint i, const uint j) const
Definition: denseMatrix.hh:161
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
virtual void transpMult(const Vector< r_type > &fncY, Vector< F > &fncX)
DenseMatrix(const LiCo< F > &L)
Constructor.
Abstract class for a function.
Definition: basis.hh:21
const F & operator()(const uint i, const uint j) const
Returns element (i, j)
Definition: element.hh:222
DenseMatrix(const Vector< F > &v, bool t=false)
Transformation constructor from a vector of length n.
virtual DenseMatrix< F > & operator=(const F &v)
Definition: denseMatrix.hh:169
DenseMatrix(const Space< G > &spcX, const Space< G > &spcY)
Constructor for an empty matrix.
DenseMatrix(const Compose< F > &L)
Constructor.
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
virtual void setTranspose(bool t)
Definition: denseMatrix.hh:182
Element with cell.
Abstract function class to evaluate a bilinear form.
Definition: bilinearForm.hh:33
std::conditional< std::is_same< typename Realtype< F >::type, F >::value, typename Realtype< F >::type, typename Cmplxtype< F >::type >::type d_type
Data type, depending if F is real or complex.
Definition: denseMatrix.hh:52
DenseMatrix(int m=0, int n=0, bool transpose=false)
Constructor for an empty matrix.
Definition: denseMatrix.hh:121
void addInto(Matrix< F > &dest, const F fact, const uint rowoffset=0, const uint coloffset=0) const
This matrix is added into to the given matrix.
virtual std::ostream & info(std::ostream &os) const
Realtype< F >::type r_type
Real type of data type.
Definition: denseMatrix.hh:47
Exception class for assertions.
Definition: exceptions.hh:258
DenseMatrix(const Space< G > &spc, const BilinearForm< F, G > &bf)
Constructor.
virtual void resize(uint m, uint n)
Resize to m rows and n columns.
Definition: denseMatrix.hh:178
Abstract class for an operator.
Definition: compositions.hh:31
Sequence with operations, output operator, and method of the particular element types.
Definition: sequence.hh:39
void addInto(Matrix< T > &dest, const T fact, const uint rowoffset=0, const uint coloffset=0) const
allows to add a Real Matrix to a complex one.
Definition: denseMatrix.hh:196
Mapping< F, dim > & transpose(Mapping< F, dim > &m)
Definition: operations.hh:54
void addIntoT(Matrix< T > &dest, const T fact, const uint rowoffset=0, const uint coloffset=0) const
allows to add a Real Matrix to a complex one.
Definition: denseMatrix.hh:212
virtual void resize(uint m, uint n)
Sets a new size.
Element matrix.
Definition: linearForm.hh:18
DenseMatrix(const Matrix< F > &m, bool t=false)
Copy constructor.
Cmplxtype< F >::type c_type
Complex type of data type.
Definition: denseMatrix.hh:49
virtual void operator()(const Function< r_type > &fncY, Function< F > &fncX)
std::complex< F > type
Definition: typedefs.hh:116
ElementMatrix< F > & operator=(const ElementMatrixBase< F > &A)
Assignement operator.
virtual F & operator()(const uint i, const uint j)
Definition: denseMatrix.hh:165
#define conceptsAssert3(cond, exc, msg)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:442
Linear combination of two operators.
DenseMatrix(const Space< G > &spc, const BilinearForm< F, G > &bf, const Sequence< ElementWithCell< G > * > &seq)
Constructor.
DenseMatrix(const DenseMatrix< F > &m)
Copy constructor.
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich