Dune Core Modules (2.5.0)

supermatrix.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ISTL_SUPERMATRIX_HH
4#define DUNE_ISTL_SUPERMATRIX_HH
5
6#if HAVE_SUPERLU
7
8#ifndef SUPERLU_NTYPE
9#define SUPERLU_NTYPE 1
10#endif
11
12#if SUPERLU_NTYPE==0
13#include "slu_sdefs.h"
14#endif
15
16#if SUPERLU_NTYPE==1
17#include "slu_ddefs.h"
18#endif
19
20#if SUPERLU_NTYPE==2
21#include "slu_cdefs.h"
22#endif
23
24#if SUPERLU_NTYPE>=3
25#include "slu_zdefs.h"
26#endif
27
28#include "bcrsmatrix.hh"
29#include "bvector.hh"
33#include <limits>
34
35#include"colcompmatrix.hh"
36
37namespace Dune
38{
39
40 template<class T>
41 struct SuperMatrixCreateSparseChooser
42 {};
43
44 template<class T>
45 struct SuperMatrixPrinter
46 {};
47
48#if SUPERLU_NTYPE==0
49 template<>
50 struct SuperMatrixCreateSparseChooser<float>
51 {
52 static void create(SuperMatrix *mat, int n, int m, int offset,
53 float *values, int *rowindex, int* colindex,
54 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
55 {
56 sCreate_CompCol_Matrix(mat, n, m, offset, values, rowindex, colindex,
57 stype, dtype, mtype);
58 }
59 };
60
61 template<>
62 struct SuperMatrixPrinter<float>
63 {
64 static void print(char* name, SuperMatrix* mat)
65 {
66 sPrint_CompCol_Matrix(name, mat);
67 }
68 };
69#endif
70
71#if SUPERLU_NTYPE==1
72 template<>
73 struct SuperMatrixCreateSparseChooser<double>
74 {
75 static void create(SuperMatrix *mat, int n, int m, int offset,
76 double *values, int *rowindex, int* colindex,
77 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
78 {
79 dCreate_CompCol_Matrix(mat, n, m, offset, values, rowindex, colindex,
80 stype, dtype, mtype);
81 }
82 };
83
84 template<>
85 struct SuperMatrixPrinter<double>
86 {
87 static void print(char* name, SuperMatrix* mat)
88 {
89 dPrint_CompCol_Matrix(name, mat);
90 }
91 };
92#endif
93
94#if SUPERLU_NTYPE==2
95 template<>
96 struct SuperMatrixCreateSparseChooser<std::complex<float> >
97 {
98 static void create(SuperMatrix *mat, int n, int m, int offset,
99 std::complex<float> *values, int *rowindex, int* colindex,
100 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
101 {
102 cCreate_CompCol_Matrix(mat, n, m, offset, reinterpret_cast< ::complex*>(values),
103 rowindex, colindex, stype, dtype, mtype);
104 }
105 };
106
107 template<>
108 struct SuperMatrixPrinter<std::complex<float> >
109 {
110 static void print(char* name, SuperMatrix* mat)
111 {
112 cPrint_CompCol_Matrix(name, mat);
113 }
114 };
115#endif
116
117#if SUPERLU_NTYPE>=3
118 template<>
119 struct SuperMatrixCreateSparseChooser<std::complex<double> >
120 {
121 static void create(SuperMatrix *mat, int n, int m, int offset,
122 std::complex<double> *values, int *rowindex, int* colindex,
123 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
124 {
125 zCreate_CompCol_Matrix(mat, n, m, offset, reinterpret_cast<doublecomplex*>(values),
126 rowindex, colindex, stype, dtype, mtype);
127 }
128 };
129
130 template<>
131 struct SuperMatrixPrinter<std::complex<double> >
132 {
133 static void print(char* name, SuperMatrix* mat)
134 {
135 zPrint_CompCol_Matrix(name, mat);
136 }
137 };
138#endif
139
140 template<class T>
141 struct BaseGetSuperLUType
142 {
143 static const Dtype_t type;
144 };
145
146 template<class T>
147 struct GetSuperLUType
148 {};
149
150 template<class T>
151 const Dtype_t BaseGetSuperLUType<T>::type =
152 std::is_same<T,float>::value ? SLU_S :
153 ( std::is_same<T,std::complex<double> >::value ? SLU_Z :
154 ( std::is_same<T,std::complex<float> >::value ? SLU_C : SLU_D ));
155
156 template<>
157 struct GetSuperLUType<double>
158 : public BaseGetSuperLUType<double>
159 {
160 typedef double float_type;
161 };
162
163 template<>
164 struct GetSuperLUType<float>
165 : public BaseGetSuperLUType<float>
166 {
167 typedef float float_type;
168 };
169
170 template<>
171 struct GetSuperLUType<std::complex<double> >
172 : public BaseGetSuperLUType<std::complex<double> >
173 {
174 typedef double float_type;
175 };
176
177 template<>
178 struct GetSuperLUType<std::complex<float> >
179 : public BaseGetSuperLUType<std::complex<float> >
180 {
181 typedef float float_type;
182
183 };
184
189 template<class M>
191 {};
192
193 template<class M>
194 struct SuperMatrixInitializer
195 {};
196
197 template<class T>
198 class SuperLU;
199
203 template<class B, class TA, int n, int m>
205 : public ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
206 {
207 template<class M, class X, class TM, class TD, class T1>
208 friend class SeqOverlappingSchwarz;
209 friend struct SuperMatrixInitializer<BCRSMatrix<FieldMatrix<B,n,m>,TA> >;
210 public:
213
214 friend struct SeqOverlappingSchwarzAssemblerHelper<SuperLU<Matrix>, true>;
215
216 typedef typename Matrix::size_type size_type;
217
222 explicit SuperLUMatrix(const Matrix& mat) : ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >(mat)
223 {}
224
226 {}
227
230 {
231 if (this->N_+this->M_*this->Nnz_ != 0)
232 free();
233 }
234
236 operator SuperMatrix&()
237 {
238 return A;
239 }
240
242 operator const SuperMatrix&() const
243 {
244 return A;
245 }
246
248 {
249 this->ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::operator=(mat);
250 SuperMatrixCreateSparseChooser<B>
251 ::create(&A, this->N_, this->M_, this->colstart[this->N_],
252 this->values,this->rowindex, this->colstart, SLU_NC,
253 static_cast<Dtype_t>(GetSuperLUType<B>::type), SLU_GE);
254 return *this;
255 }
256
257 SuperLUMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >& operator=(const SuperLUMatrix <BCRSMatrix<FieldMatrix<B,n,m>,TA> >& mat)
258 {
259 this->ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::operator=(mat);
260 SuperMatrixCreateSparseChooser<B>
261 ::create(&A, this->N_, this->M_, this->colstart[this->N_],
262 this->values,this->rowindex, this->colstart, SLU_NC,
263 static_cast<Dtype_t>(GetSuperLUType<B>::type), SLU_GE);
264 return *this;
265 }
266
273 virtual void setMatrix(const Matrix& mat, const std::set<std::size_t>& mrs)
274 {
275 if(this->N_+this->M_+this->Nnz_!=0)
276 free();
277 this->N_=mrs.size()*n;
278 this->M_=mrs.size()*m;
279 SuperMatrixInitializer<Matrix> initializer(*this);
280
281 copyToColCompMatrix(initializer, MatrixRowSubset<Matrix,std::set<std::size_t> >(mat,mrs));
282 }
283
285 virtual void setMatrix(const Matrix& mat)
286 {
287 this->N_=n*mat.N();
288 this->M_=m*mat.M();
289 SuperMatrixInitializer<Matrix> initializer(*this);
290
291 copyToColCompMatrix(initializer, MatrixRowSet<Matrix>(mat));
292 }
293
295 virtual void free()
296 {
298 SUPERLU_FREE(A.Store);
299 }
300 private:
301 SuperMatrix A;
302 };
303
304 template<class T, class A, int n, int m>
305 class SuperMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >
306 : public ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >
307 {
308 template<class I, class S, class D>
309 friend class OverlappingSchwarzInitializer;
310 public:
311 typedef BCRSMatrix<FieldMatrix<T,n,m>,A> Matrix;
312 typedef Dune::SuperLUMatrix<Matrix> SuperLUMatrix;
313
314 SuperMatrixInitializer(SuperLUMatrix& lum) : ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >(lum)
315 ,slumat(&lum)
316 {}
317
318 SuperMatrixInitializer() : ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >()
319 {}
320
321 virtual void createMatrix() const
322 {
323 ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >::createMatrix();
324 SuperMatrixCreateSparseChooser<T>
325 ::create(&slumat->A, slumat->N_, slumat->M_, slumat->colstart[this->cols],
326 slumat->values,slumat->rowindex, slumat->colstart, SLU_NC,
327 static_cast<Dtype_t>(GetSuperLUType<T>::type), SLU_GE);
328 }
329 private:
330 SuperLUMatrix* slumat;
331 };
332}
333#endif // HAVE_SUPERLU
334#endif
Implementation of the BCRSMatrix class.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:423
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:457
A dense n x m matrix.
Definition: fmatrix.hh:68
Provides access to an iterator over all matrix rows.
Definition: colcompmatrix.hh:22
Provides access to an iterator over an arbitrary subset of matrix rows.
Definition: colcompmatrix.hh:60
Sequential overlapping Schwarz preconditioner.
Definition: overlappingschwarz.hh:742
virtual void setMatrix(const Matrix &mat)
Initialize data from given matrix.
Definition: supermatrix.hh:285
virtual ~SuperLUMatrix()
Destructor.
Definition: supermatrix.hh:229
SuperLUMatrix(const Matrix &mat)
Constructor that initializes the data.
Definition: supermatrix.hh:222
BCRSMatrix< FieldMatrix< B, n, m >, TA > Matrix
The type of the matrix to convert.
Definition: supermatrix.hh:212
virtual void setMatrix(const Matrix &mat, const std::set< std::size_t > &mrs)
Initialize data from a given set of matrix rows and columns.
Definition: supermatrix.hh:273
virtual void free()
free allocated space.
Definition: supermatrix.hh:295
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignment.hh:11
STL namespace.
Utility class for converting an ISTL Matrix into a column-compressed matrix.
Definition: colcompmatrix.hh:145
Utility class for converting an ISTL Matrix into a SuperLU Matrix.
Definition: supermatrix.hh:191
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)