Line data Source code
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 :
44 : /// \addtogroup small_algebra
45 : /// \{
46 :
47 : /////////////////////////////////////////////////////////////////////////////////////////////
48 : // DenseMatrix
49 : /**
50 : * DenseMatrix is a mathematical matrix class, which inherits its storage behaviour
51 : * (fixed/variable size, RowMajor/ColMajor ordering) from TStorage.
52 : * \param TStorage storage policy with interface of VariableArray2.
53 : * \sa FixedArray2, VariableArray2, eMatrixOrdering
54 : */
55 : template<typename TStorage>
56 0 : 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 :
66 : typedef DenseMatrix<TStorage> this_type;
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 :
86 : ////// =
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 :
100 : ////// +=
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 :
110 : ////// -=
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 :
121 : ////// *=
122 : inline
123 : this_type&
124 : operator*=(double alpha);
125 :
126 : inline
127 : this_type&
128 : operator *= (const this_type &mat);
129 :
130 : ////// /=
131 : inline
132 : this_type&
133 : operator/=(double alpha);
134 :
135 : inline
136 : this_type&
137 : operator /= (this_type &other);
138 :
139 :
140 : ////// +
141 : inline
142 : this_type
143 : operator + (const this_type &other ) const;
144 :
145 : ////// -
146 : inline
147 : this_type
148 : operator - (const this_type &other ) const;
149 :
150 : inline
151 : this_type
152 : T() const;
153 :
154 : ////// unary -
155 : inline
156 : this_type
157 : operator - () const;
158 :
159 : ////// *
160 :
161 :
162 : // multiply
163 : template<typename TStorage2>
164 : DenseVector<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 :
175 : ///// /
176 : this_type
177 : operator / (this_type &other);
178 :
179 : // compare operators
180 : ////// ==
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 :
191 : ///// !=
192 : template<typename TStorage2>
193 : inline
194 : bool
195 : operator != (const TStorage2 &t) const;
196 :
197 : ////// other
198 : inline
199 : const value_type &
200 : entry(size_type r, size_type c) const
201 : {
202 : return operator()(r,c);
203 : }
204 :
205 : inline
206 : value_type &
207 : entry(size_type r, size_type c)
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 0 : for(size_t r1=0; r1<t.num_rows(); r1++)
219 0 : for(size_t c1=0; c1<t.num_cols(); c1++)
220 0 : 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 0 : entry(r, c) = t;
227 0 : }
228 :
229 : void maple_print(const char *name);
230 : };
231 :
232 : template<typename TStorage>
233 : DenseMatrix<TStorage> operator *(number a, const DenseMatrix<TStorage> &b)
234 : {
235 : return b*a;
236 : }
237 :
238 :
239 : template<typename TStorage>
240 : DenseMatrix<TStorage> MatrixTranspose(const DenseMatrix<TStorage> &A)
241 : {
242 : DenseMatrix<TStorage> At;
243 : At.resize(A.num_cols(), A.num_rows());
244 0 : for(size_t r=0; r < A.num_rows(); r++)
245 0 : for(size_t c=0; c < A.num_cols(); c++)
246 0 : At(c,r) = A(r, c);
247 : return At;
248 : }
249 :
250 :
251 : inline double MatrixTranspose(const double &b)
252 0 : {return b;}
253 : // end group small_algebra
254 : /// \}
255 :
256 : }
257 :
258 : #include "densematrix_impl.h"
259 : #include "densematrix_operations.h"
260 :
261 : #endif // __H__UG__COMMON__DENSEMATRIX_H__
|