ug4
densematrix.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Martin Rupp
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 
34 #ifndef __H__UG__COMMON__DENSEMATRIX_H__
35 #define __H__UG__COMMON__DENSEMATRIX_H__
36 
37 #include <iostream>
38 #include <cassert>
39 #include "../storage/storage.h"
40 #include "densevector.h"
41 
42 namespace ug{
43 
46 
48 // DenseMatrix
55 template<typename TStorage>
56 class DenseMatrix : public TStorage
57 {
58 public:
59  typedef typename TStorage::value_type value_type;
60  typedef typename TStorage::size_type size_type;
61  static const eMatrixOrdering ordering = TStorage::ordering;
62  enum { is_static = TStorage::is_static};
63  enum { static_num_rows = TStorage::static_num_rows};
64  enum { static_num_cols = TStorage::static_num_cols};
65 
67  typedef TStorage base;
68  using base::operator ();
69  using base::at;
70  using base::num_rows;
71  using base::num_cols;
72  using base::resize;
73 
74 public:
75  // 'tors
76  DenseMatrix();
77  DenseMatrix(double val);
78  DenseMatrix(const this_type &rhs);
79 
80  //~DenseMatrix() {} // dont implement a destructor, since ~base may not be virtual
81 
82 public:
83  // matrix assignment operators
84 
85 
87  inline
88  this_type &
89  operator = (const this_type &t);
90 
91  template<typename T>
92  inline
93  this_type &
94  operator = (const T &t);
95 
96  inline
97  this_type &
98  operator = (double alpha);
99 
101  template<typename T>
102  inline
103  this_type &
104  operator += (const T &t);
105 
106  inline
107  this_type &
108  operator += (double alpha);
109 
111  template<typename T>
112  inline
113  this_type &
114  operator -= (const T &t);
115 
116  inline
117  this_type &
118  operator -= (double alpha);
119 
120 
122  inline
123  this_type&
124  operator*=(double alpha);
125 
126  inline
127  this_type&
128  operator *= (const this_type &mat);
129 
131  inline
132  this_type&
133  operator/=(double alpha);
134 
135  inline
136  this_type&
137  operator /= (this_type &other);
138 
139 
141  inline
142  this_type
143  operator + (const this_type &other ) const;
144 
146  inline
147  this_type
148  operator - (const this_type &other ) const;
149 
150  inline
151  this_type
152  T() const;
153 
155  inline
156  this_type
157  operator - () const;
158 
160 
161 
162  // multiply
163  template<typename TStorage2>
165  operator * (const DenseVector<TStorage2> &vec) const;
166 
167  inline
168  this_type
169  operator * (const this_type &mat) const;
170 
171  inline
172  this_type
173  operator * (double alpha ) const;
174 
176  this_type
177  operator / (this_type &other);
178 
179 // compare operators
181  inline
182  bool
183  operator == (double t) const;
184 
185 
186  template<typename TStorage2>
187  inline
188  bool
189  operator == (const DenseMatrix<TStorage2> &t) const;
190 
192  template<typename TStorage2>
193  inline
194  bool
195  operator != (const TStorage2 &t) const;
196 
198  inline
199  const value_type &
201  {
202  return operator()(r,c);
203  }
204 
205  inline
206  value_type &
208  {
209  return operator()(r,c);
210  }
211 
212 
213  template<typename TStorage2>
214  void
215  subassign(size_t r, size_t c, const TStorage2 &t)
216  {
217  UG_ASSERT(r+t.num_rows() <= num_rows() && c+t.num_cols() <= num_cols(), "");
218  for(size_t r1=0; r1<t.num_rows(); r1++)
219  for(size_t c1=0; c1<t.num_cols(); c1++)
220  entry(r+r1, c+c1) = t(r1, c1);
221  }
222 
223  void
224  subassign(size_t r, size_t c, const value_type &t)
225  {
226  entry(r, c) = t;
227  }
228 
229  void maple_print(const char *name);
230 };
231 
232 template<typename TStorage>
234 {
235  return b*a;
236 }
237 
238 
239 template<typename TStorage>
241 {
243  At.resize(A.num_cols(), A.num_rows());
244  for(size_t r=0; r < A.num_rows(); r++)
245  for(size_t c=0; c < A.num_cols(); c++)
246  At(c,r) = A(r, c);
247  return At;
248 }
249 
250 
251 inline double MatrixTranspose(const double &b)
252 {return b;}
253 // end group small_algebra
255 
256 }
257 
258 #include "densematrix_impl.h"
259 #include "densematrix_operations.h"
260 
261 #endif // __H__UG__COMMON__DENSEMATRIX_H__
location name
Definition: checkpoint_util.lua:128
Definition: densematrix.h:57
this_type & operator+=(const T &t)
static const eMatrixOrdering ordering
Definition: densematrix.h:61
TStorage::size_type size_type
Definition: densematrix.h:60
bool operator!=(const TStorage2 &t) const
void subassign(size_t r, size_t c, const TStorage2 &t)
Definition: densematrix.h:215
TStorage base
Definition: densematrix.h:67
@ static_num_cols
Definition: densematrix.h:64
this_type & operator-=(const T &t)
this_type & operator*=(double alpha)
Definition: densematrix_impl.h:164
this_type & operator/=(double alpha)
Definition: densematrix_impl.h:183
void maple_print(const char *name)
Definition: densematrix_impl.h:365
bool operator==(double t) const
Definition: densematrix_impl.h:330
this_type operator/(this_type &other)
Definition: densematrix_impl.h:318
@ is_static
Definition: densematrix.h:62
DenseMatrix()
Definition: densematrix_impl.h:56
DenseVector< TStorage2 > operator*(const DenseVector< TStorage2 > &vec) const
Definition: densematrix_impl.h:285
this_type T() const
Definition: densematrix_impl.h:272
DenseMatrix< TStorage > this_type
Definition: densematrix.h:66
this_type operator-() const
Definition: densematrix_impl.h:234
void subassign(size_t r, size_t c, const value_type &t)
Definition: densematrix.h:224
const value_type & entry(size_type r, size_type c) const
Definition: densematrix.h:200
value_type & entry(size_type r, size_type c)
Definition: densematrix.h:207
this_type & operator=(const this_type &t)
Definition: densematrix_impl.h:76
@ static_num_rows
Definition: densematrix.h:63
TStorage::value_type value_type
Definition: densematrix.h:59
this_type operator+(const this_type &other) const
Definition: densematrix_impl.h:206
Definition: densevector.h:101
DenseMatrix< TStorage > MatrixTranspose(const DenseMatrix< TStorage > &A)
Definition: densematrix.h:240
number alpha
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
the ug namespace
eMatrixOrdering
Definition: storage.h:47
MatVec_Expression< L, R > operator*(const AlphaMat_Expression< L > &l, const R &r)
create a MatVec_Expression by (alpha*MATRIX) * VECTOR
Definition: template_expressions.h:223
T value_type
Definition: sparsematrix_interface.h:2
bool resize(size_t newRows, size_t newCols)
size_t num_rows() const
Definition: sparsematrix_interface.h:38
value_type & operator()(size_t r, size_t c)
size_t num_cols() const
Definition: sparsematrix_interface.h:39