3#ifndef DUNE_ISTL_UMFPACK_HH
4#define DUNE_ISTL_UMFPACK_HH
6#if HAVE_SUITESPARSE_UMFPACK || defined DOXYGEN
13#include<dune/common/exceptions.hh>
14#include<dune/common/fmatrix.hh>
15#include<dune/common/fvector.hh>
16#include<dune/common/unused.hh>
37 template<
class M,
class T,
class TM,
class TD,
class TA>
38 class SeqOverlappingSchwarz;
40 template<
class T,
bool tag>
41 struct SeqOverlappingSchwarzAssemblerHelper;
48 template<
class Matrix>
61 template<
typename... A>
66 template<
typename... A>
71 template<
typename... A>
76 template<
typename... A>
81 template<
typename... A>
86 template<
typename... A>
91 template<
typename... A>
96 template<
typename... A>
101 template<
typename... A>
106 template<
typename... A>
116 template<
typename... A>
121 template<
typename... A>
126 template<
typename... A>
131 template<
typename... A>
136 template<
typename... A>
141 template<
typename... A>
146 template<
typename... A>
151 template<
typename... A>
156 template<
typename... A>
157 static void solve(
int m,
const int*
cs,
const int* ri, std::complex<double>*
val,
double* x,
const double* b,A...
args)
159 const double*
cval =
reinterpret_cast<const double*
>(
val);
162 template<
typename... A>
182 template<
typename T,
typename A,
int n,
int m>
185 BlockVector<FieldVector<T,m>,
186 typename A::template rebind<FieldVector<T,m> >::other>,
187 BlockVector<FieldVector<T,n>,
188 typename A::template rebind<FieldVector<T,n> >::other> >
218 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
219 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
220 Caller::defaults(UMF_Control);
221 setVerbosity(verbose);
236 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
237 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
238 Caller::defaults(UMF_Control);
239 setVerbosity(verbose);
248 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
249 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
250 Caller::defaults(UMF_Control);
266 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
267 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
268 Caller::defaults(UMF_Control);
269 setVerbosity(verbose);
270 int errcode = Caller::load_numeric(&UMF_Numeric,
const_cast<char*
>(
file));
273 matrixIsLoaded_ =
false;
275 saveDecomposition(
file);
279 matrixIsLoaded_ =
true;
280 std::cout <<
"UMFPack decomposition successfully loaded from " <<
file << std::endl;
293 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
294 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
295 Caller::defaults(UMF_Control);
296 int errcode = Caller::load_numeric(&UMF_Numeric,
const_cast<char*
>(
file));
298 DUNE_THROW(Dune::Exception,
"ran out of memory while loading UMFPack decomposition");
300 DUNE_THROW(Dune::Exception,
"IO error while loading UMFPack decomposition");
301 matrixIsLoaded_ =
true;
302 std::cout <<
"UMFPack decomposition successfully loaded from " <<
file << std::endl;
303 setVerbosity(verbose);
308 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
317 if (umfpackMatrix_.N() != b.
dim())
319 if (umfpackMatrix_.M() != x.
dim())
324 umfpackMatrix_.getColStart(),
325 umfpackMatrix_.getRowIndex(),
326 umfpackMatrix_.getValues(),
327 reinterpret_cast<double*
>(&x[0]),
328 reinterpret_cast<double*
>(&b[0]),
335 res.converged =
true;
359 umfpackMatrix_.getColStart(),
360 umfpackMatrix_.getRowIndex(),
361 umfpackMatrix_.getValues(),
386 UMF_Control[
option] = value;
394 int errcode = Caller::save_numeric(UMF_Numeric,
const_cast<char*
>(
file));
396 DUNE_THROW(Dune::Exception,
"IO ERROR while trying to save UMFPack decomposition");
402 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
404 umfpackMatrix_ = matrix;
411 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
413 umfpackMatrix_.setMatrix(
_mat,rowIndexSet);
451 return umfpackMatrix_;
460 if (!matrixIsLoaded_)
462 Caller::free_symbolic(&UMF_Symbolic);
463 umfpackMatrix_.free();
465 Caller::free_numeric(&UMF_Numeric);
466 matrixIsLoaded_ =
false;
469 const char*
name() {
return "UMFPACK"; }
474 template<
class M,
class X,
class TM,
class TD,
class T1>
482 Caller::symbolic(
static_cast<int>(umfpackMatrix_.N()),
483 static_cast<int>(umfpackMatrix_.N()),
484 umfpackMatrix_.getColStart(),
485 umfpackMatrix_.getRowIndex(),
486 reinterpret_cast<double*
>(umfpackMatrix_.getValues()),
490 Caller::numeric(umfpackMatrix_.getColStart(),
491 umfpackMatrix_.getRowIndex(),
492 reinterpret_cast<double*
>(umfpackMatrix_.getValues()),
500 std::cout <<
"[UMFPack Decomposition]" << std::endl;
513 void printOnApply(
double* UMF_Info)
515 Caller::report_status(UMF_Control,UMF_Info[UMFPACK_STATUS]);
518 std::cout <<
"[UMFPack Solve]" << std::endl;
519 std::cout <<
"Wallclock Time: " << UMF_Info[UMFPACK_SOLVE_WALLTIME] <<
" (CPU Time: " << UMF_Info[UMFPACK_SOLVE_TIME] <<
")" << std::endl;
520 std::cout <<
"Flops Taken: " << UMF_Info[UMFPACK_SOLVE_FLOPS] << std::endl;
521 std::cout <<
"Iterative Refinement steps taken: " << UMF_Info[UMFPACK_IR_TAKEN] << std::endl;
522 std::cout <<
"Error Estimate: " << UMF_Info[UMFPACK_OMEGA1] <<
" resp. " << UMF_Info[UMFPACK_OMEGA2] << std::endl;
526 UMFPackMatrix umfpackMatrix_;
527 bool matrixIsLoaded_;
531 double UMF_Control[UMFPACK_CONTROL];
534 template<
typename T,
typename A,
int n,
int m>
540 template<
typename T,
typename A,
int n,
int m>
Implementations of the inverse operator interface.
Templates characterizing the type of a solver.
Implementation of the BCRSMatrix class.
UMFPack(const Matrix &matrix, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition umfpack.hh:233
void setVerbosity(int v)
sets the verbosity level for the UMFPack solver
Definition umfpack.hh:424
void * getFactorization()
Return the matrix factorization.
Definition umfpack.hh:440
static void report_info(A... args)
Definition umfpack.hh:142
Dune::BCRSMatrix< FieldMatrix< T, n, m >, A > Matrix
The matrix type.
Definition umfpack.hh:192
static int load_numeric(A... args)
Definition umfpack.hh:132
Dune::BCRSMatrix< FieldMatrix< T, n, m >, A > matrix_type
Definition umfpack.hh:193
static int load_numeric(A... args)
Definition umfpack.hh:77
static void report_status(A... args)
Definition umfpack.hh:92
UMFPack(const Matrix &mat_, const char *file, int verbose=0)
Try loading a decomposition from file and do a decomposition if unsuccessful.
Definition umfpack.hh:263
Dune::BlockVector< FieldVector< T, m >, typename A::template rebind< FieldVector< T, m > >::other > domain_type
The type of the domain of the solver.
Definition umfpack.hh:201
void setMatrix(const Matrix &matrix)
Initialize data from given matrix.
Definition umfpack.hh:400
virtual void apply(domain_type &x, range_type &b, InverseOperatorResult &res)
Apply inverse operator,.
Definition umfpack.hh:315
static void symbolic(A... args)
Definition umfpack.hh:107
static void report_info(A... args)
Definition umfpack.hh:87
void free()
free allocated space.
Definition umfpack.hh:458
static void free_symbolic(A... args)
Definition umfpack.hh:72
static int save_numeric(A... args)
Definition umfpack.hh:152
static void free_numeric(A... args)
Definition umfpack.hh:122
void setSubMatrix(const Matrix &_mat, const S &rowIndexSet)
Definition umfpack.hh:409
static int save_numeric(A... args)
Definition umfpack.hh:97
static void report_status(A... args)
Definition umfpack.hh:147
static void defaults(A... args)
Definition umfpack.hh:117
static void free_numeric(A... args)
Definition umfpack.hh:67
ColCompMatrixInitializer< BCRSMatrix< FieldMatrix< T, n, m >, A > > MatrixInitializer
Type of an associated initializer class.
Definition umfpack.hh:197
static void numeric(A... args)
Definition umfpack.hh:82
UMFPackMatrix & getInternalMatrix()
Return the column compress matrix from UMFPack.
Definition umfpack.hh:449
UMFPack(const Matrix &matrix, int verbose=0)
Construct a solver object from a BCRSMatrix.
Definition umfpack.hh:215
void setOption(unsigned int option, double value)
Set UMFPack-specific options.
Definition umfpack.hh:381
const char * name()
Definition umfpack.hh:469
virtual ~UMFPack()
Definition umfpack.hh:306
Dune::ColCompMatrix< Matrix > UMFPackMatrix
The corresponding SuperLU Matrix type.
Definition umfpack.hh:195
Dune::BlockVector< FieldVector< T, n >, typename A::template rebind< FieldVector< T, n > >::other > range_type
The type of the range of the solver.
Definition umfpack.hh:205
void apply(T *x, T *b)
additional apply method with c-arrays in analogy to superlu
Definition umfpack.hh:355
static void numeric(const int *cs, const int *ri, const double *val, A... args)
Definition umfpack.hh:137
static void solve(int m, const int *cs, const int *ri, std::complex< double > *val, double *x, const double *b, A... args)
Definition umfpack.hh:157
static void free_symbolic(A... args)
Definition umfpack.hh:127
UMFPack()
default constructor
Definition umfpack.hh:245
UMFPack(const char *file, int verbose=0)
try loading a decomposition from file
Definition umfpack.hh:290
static void defaults(A... args)
Definition umfpack.hh:62
static void solve(A... args)
Definition umfpack.hh:102
virtual void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res)
apply inverse operator, with given convergence criteria.
Definition umfpack.hh:344
void saveDecomposition(const char *file)
saves a decomposition to a file
Definition umfpack.hh:392
static void symbolic(int m, int n, const int *cs, const int *ri, const double *val, A... args)
Definition umfpack.hh:163
Definition basearray.hh:19
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:412
size_type dim() const
dimension of the vector space
Definition bvector.hh:279
A vector of blocks with memory management.
Definition bvector.hh:309
Sequential overlapping Schwarz preconditioner.
Definition overlappingschwarz.hh:742
Definition overlappingschwarz.hh:683
derive error class from the base class in common
Definition istlexception.hh:16
Definition matrixutils.hh:25
Statistics about the application of an inverse operator.
Definition solver.hh:32
Abstract base class for all solvers.
Definition solver.hh:79
Definition solvertype.hh:14
@ value
Whether this is a direct solver.
Definition solvertype.hh:22
Definition solvertype.hh:28
@ value
whether the solver internally uses column compressed storage
Definition solvertype.hh:34
Use the UMFPack package to directly solve linear systems – empty default class.
Definition umfpack.hh:50