3#ifndef DUNE_ISTL_SUPERMATRIX_HH
4#define DUNE_ISTL_SUPERMATRIX_HH
8#include "bcrsmatrix.hh"
15#include <dune/istl/bccsmatrixinitializer.hh>
17#include "superlufunctions.hh"
23 struct SuperMatrixCreateSparseChooser
27 struct SuperMatrixPrinter
30#if __has_include("slu_sdefs.h")
32 struct SuperMatrixCreateSparseChooser<float>
34 static void create(SuperMatrix *mat,
int n,
int m,
int offset,
35 float *values,
int *rowindex,
int* colindex,
36 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
38 sCreate_CompCol_Matrix(mat, n, m, offset, values, rowindex, colindex,
44 struct SuperMatrixPrinter<float>
46 static void print(
char* name, SuperMatrix* mat)
48 sPrint_CompCol_Matrix(name, mat);
53#if __has_include("slu_ddefs.h")
55 struct SuperMatrixCreateSparseChooser<double>
57 static void create(SuperMatrix *mat,
int n,
int m,
int offset,
58 double *values,
int *rowindex,
int* colindex,
59 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
61 dCreate_CompCol_Matrix(mat, n, m, offset, values, rowindex, colindex,
67 struct SuperMatrixPrinter<double>
69 static void print(
char* name, SuperMatrix* mat)
71 dPrint_CompCol_Matrix(name, mat);
76#if __has_include("slu_cdefs.h")
78 struct SuperMatrixCreateSparseChooser<
std::complex<float> >
80 static void create(SuperMatrix *mat,
int n,
int m,
int offset,
81 std::complex<float> *values,
int *rowindex,
int* colindex,
82 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
84 cCreate_CompCol_Matrix(mat, n, m, offset,
reinterpret_cast< ::complex*
>(values),
85 rowindex, colindex, stype, dtype, mtype);
90 struct SuperMatrixPrinter<
std::complex<float> >
92 static void print(
char* name, SuperMatrix* mat)
94 cPrint_CompCol_Matrix(name, mat);
99#if __has_include("slu_zdefs.h")
101 struct SuperMatrixCreateSparseChooser<
std::complex<double> >
103 static void create(SuperMatrix *mat,
int n,
int m,
int offset,
104 std::complex<double> *values,
int *rowindex,
int* colindex,
105 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
107 zCreate_CompCol_Matrix(mat, n, m, offset,
reinterpret_cast<doublecomplex*
>(values),
108 rowindex, colindex, stype, dtype, mtype);
113 struct SuperMatrixPrinter<
std::complex<double> >
115 static void print(
char* name, SuperMatrix* mat)
117 zPrint_CompCol_Matrix(name, mat);
123 struct BaseGetSuperLUType
125 static const Dtype_t type;
129 struct GetSuperLUType
133 const Dtype_t BaseGetSuperLUType<T>::type =
134 std::is_same<T,float>::value ? SLU_S :
135 ( std::is_same<T,std::complex<double> >::value ? SLU_Z :
136 ( std::is_same<T,std::complex<float> >::value ? SLU_C : SLU_D ));
139 struct GetSuperLUType<double>
140 :
public BaseGetSuperLUType<double>
142 typedef double float_type;
146 struct GetSuperLUType<float>
147 :
public BaseGetSuperLUType<float>
149 typedef float float_type;
153 struct GetSuperLUType<
std::complex<double> >
154 :
public BaseGetSuperLUType<std::complex<double> >
156 typedef double float_type;
160 struct GetSuperLUType<
std::complex<float> >
161 :
public BaseGetSuperLUType<std::complex<float> >
163 typedef float float_type;
176 struct SuperMatrixInitializer
182 template<
class M,
class X,
class TM,
class TD,
class T1>
183 class SeqOverlappingSchwarz;
185 template<
class T,
bool flag>
186 struct SeqOverlappingSchwarzAssemblerHelper;
191 template<
class B,
class TA>
193 :
public ISTL::Impl::BCCSMatrix<typename BCRSMatrix<B,TA>::field_type, int>
195 template<
class M,
class X,
class TM,
class TD,
class T1>
197 friend struct SuperMatrixInitializer<
BCRSMatrix<B,TA> >;
202 friend struct SeqOverlappingSchwarzAssemblerHelper<
SuperLU<
Matrix>, true>;
219 if (this->N_+this->M_*this->Nnz_ != 0)
224 operator SuperMatrix&()
230 operator const SuperMatrix&()
const
237 if (this->N_ + this->M_ + this->Nnz_!=0)
241 this->N_ = MatrixDimension<Matrix>::rowdim(mat);
242 this->M_ = MatrixDimension<Matrix>::coldim(mat);
243 ISTL::Impl::BCCSMatrixInitializer<Matrix, int> initializer(*
this);
245 copyToBCCSMatrix(initializer, mat);
247 SuperMatrixCreateSparseChooser<typename Matrix::field_type>
248 ::create(&A, this->N_, this->M_, this->colstart[this->N_],
249 this->values,this->rowindex, this->colstart, SLU_NC,
250 static_cast<Dtype_t
>(GetSuperLUType<typename Matrix::field_type>::type), SLU_GE);
254 SuperLUMatrix<BCRSMatrix<B,TA> >& operator=(
const SuperLUMatrix <BCRSMatrix<B,TA> >& mat)
256 if (this->N_ + this->M_ + this->Nnz_!=0)
259 using Matrix = BCRSMatrix<B,TA>;
260 this->N_ = MatrixDimension<Matrix>::rowdim(mat);
261 this->M_ = MatrixDimension<Matrix>::coldim(mat);
262 ISTL::Impl::BCCSMatrixInitializer<Matrix, int> initializer(*
this);
264 copyToBCCSMatrix(initializer, mat);
266 SuperMatrixCreateSparseChooser<B>
267 ::create(&A, this->N_, this->M_, this->colstart[this->N_],
268 this->values,this->rowindex, this->colstart, SLU_NC,
269 static_cast<Dtype_t
>(GetSuperLUType<B>::type), SLU_GE);
281 if(this->N_+this->M_+this->Nnz_!=0)
283 this->N_=mrs.size()*MatrixDimension<typename Matrix::block_type>::rowdim(*(mat[0].begin()));
284 this->M_=mrs.size()*MatrixDimension<typename Matrix::block_type>::coldim(*(mat[0].begin()));
285 SuperMatrixInitializer<Matrix> initializer(*
this);
287 copyToBCCSMatrix(initializer, ISTL::Impl::MatrixRowSubset<
Matrix,std::set<std::size_t> >(mat,mrs));
293 this->N_=MatrixDimension<Matrix>::rowdim(mat);
294 this->M_=MatrixDimension<Matrix>::coldim(mat);
295 SuperMatrixInitializer<Matrix> initializer(*
this);
297 copyToBCCSMatrix(initializer, mat);
303 ISTL::Impl::BCCSMatrix<typename BCRSMatrix<B,TA>::field_type,
int>::free();
304 SUPERLU_FREE(A.Store);
310 template<
class B,
class A>
311 class SuperMatrixInitializer<BCRSMatrix<B,A> >
312 :
public ISTL::Impl::BCCSMatrixInitializer<BCRSMatrix<B,A>, int>
314 template<
class I,
class S,
class D>
315 friend class OverlappingSchwarzInitializer;
317 typedef BCRSMatrix<B,A> Matrix;
320 SuperMatrixInitializer(SuperLUMatrix& lum) : ISTL::Impl::BCCSMatrixInitializer<BCRSMatrix<B,A>, int>(lum)
324 SuperMatrixInitializer() : ISTL::Impl::BCCSMatrixInitializer<BCRSMatrix<B,A>, int>()
327 virtual void createMatrix()
const
329 ISTL::Impl::BCCSMatrixInitializer<BCRSMatrix<B,A>,
int>::createMatrix();
330 SuperMatrixCreateSparseChooser<typename Matrix::field_type>
331 ::create(&slumat->A, slumat->N_, slumat->M_, slumat->colstart[this->cols],
332 slumat->values,slumat->rowindex, slumat->colstart, SLU_NC,
333 static_cast<Dtype_t
>(GetSuperLUType<typename Matrix::field_type>::type), SLU_GE);
336 SuperLUMatrix* slumat;
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:464
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:498
A generic dynamic dense matrix.
Definition: matrix.hh:559
Sequential overlapping Schwarz preconditioner.
Definition: overlappingschwarz.hh:753
virtual void free()
free allocated space.
Definition: supermatrix.hh:301
SuperLUMatrix(const Matrix &mat)
Constructor that initializes the data.
Definition: supermatrix.hh:210
virtual void setMatrix(const Matrix &mat)
Initialize data from given matrix.
Definition: supermatrix.hh:291
BCRSMatrix< B, TA > Matrix
The type of the matrix to convert.
Definition: supermatrix.hh:200
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:279
virtual ~SuperLUMatrix()
Destructor.
Definition: supermatrix.hh:217
SuperLu Solver.
Definition: superlu.hh:269
Traits for type conversions and type information.
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: alignedallocator.hh:11
Utility class for converting an ISTL Matrix into a SuperLU Matrix.
Definition: supermatrix.hh:173