6#if HAVE_UMFPACK || defined DOXYGEN
21#include"colcompmatrix.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>
55 struct UMFPackMethodChooser
59 struct UMFPackMethodChooser<double>
61 template<
typename... A>
62 static void defaults(A... args)
64 umfpack_di_defaults(args...);
66 template<
typename... A>
67 static void free_numeric(A... args)
69 umfpack_di_free_numeric(args...);
71 template<
typename... A>
72 static void free_symbolic(A... args)
74 umfpack_di_free_symbolic(args...);
76 template<
typename... A>
77 static int load_numeric(A... args)
79 return umfpack_di_load_numeric(args...);
81 template<
typename... A>
82 static void numeric(A... args)
84 umfpack_di_numeric(args...);
86 template<
typename... A>
87 static void report_info(A... args)
89 umfpack_di_report_info(args...);
91 template<
typename... A>
92 static void report_status(A... args)
94 umfpack_di_report_status(args...);
96 template<
typename... A>
97 static int save_numeric(A... args)
99 return umfpack_di_save_numeric(args...);
101 template<
typename... A>
102 static void solve(A... args)
104 umfpack_di_solve(args...);
106 template<
typename... A>
107 static void symbolic(A... args)
109 umfpack_di_symbolic(args...);
114 struct UMFPackMethodChooser<
std::complex<double> >
116 template<
typename... A>
117 static void defaults(A... args)
119 umfpack_zi_defaults(args...);
121 template<
typename... A>
122 static void free_numeric(A... args)
124 umfpack_zi_free_numeric(args...);
126 template<
typename... A>
127 static void free_symbolic(A... args)
129 umfpack_zi_free_symbolic(args...);
131 template<
typename... A>
132 static int load_numeric(A... args)
134 return umfpack_zi_load_numeric(args...);
136 template<
typename... A>
137 static void numeric(
const int* cs,
const int* ri,
const double* val, A... args)
139 umfpack_zi_numeric(cs,ri,val,NULL,args...);
141 template<
typename... A>
142 static void report_info(A... args)
144 umfpack_zi_report_info(args...);
146 template<
typename... A>
147 static void report_status(A... args)
149 umfpack_zi_report_status(args...);
151 template<
typename... A>
152 static int save_numeric(A... args)
154 return umfpack_zi_save_numeric(args...);
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);
160 umfpack_zi_solve(m,cs,ri,cval,NULL,x,NULL,b,NULL,args...);
162 template<
typename... A>
163 static void symbolic(
int m,
int n,
const int* cs,
const int* ri,
const double* val, A... args)
165 umfpack_zi_symbolic(m,n,cs,ri,val,NULL,args...);
177 template<
typename T,
typename A,
int n,
int m>
180 BlockVector<FieldVector<T,m>,
181 typename A::template rebind<FieldVector<T,m> >::other>,
182 BlockVector<FieldVector<T,n>,
183 typename A::template rebind<FieldVector<T,n> >::other> >
196 typename A::template rebind<FieldVector<T,m> >::other>
domain_type;
200 typename A::template rebind<FieldVector<T,n> >::other>
range_type;
209 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
210 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
211 Caller::defaults(UMF_Control);
212 setVerbosity(verbose);
223 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
224 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
225 Caller::defaults(UMF_Control);
226 setVerbosity(verbose);
235 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
236 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
237 Caller::defaults(UMF_Control);
252 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
253 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
254 Caller::defaults(UMF_Control);
255 setVerbosity(verbose);
256 int errcode = Caller::load_numeric(&UMF_Numeric,
const_cast<char*
>(file));
257 if ((errcode == UMFPACK_ERROR_out_of_memory) || (errcode == UMFPACK_ERROR_file_IO))
259 mat_is_loaded =
false;
261 saveDecomposition(file);
265 mat_is_loaded =
true;
266 std::cout <<
"UMFPack decomposition successfully loaded from " << file << std::endl;
279 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
280 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
281 Caller::defaults(UMF_Control);
282 int errcode = Caller::load_numeric(&UMF_Numeric,
const_cast<char*
>(file));
283 if (errcode == UMFPACK_ERROR_out_of_memory)
285 if (errcode == UMFPACK_ERROR_file_IO)
287 mat_is_loaded =
true;
288 std::cout <<
"UMFPack decomposition successfully loaded from " << file << std::endl;
289 setVerbosity(verbose);
294 if ((mat.N() + mat.M() > 0) || (mat_is_loaded))
303 double UMF_Apply_Info[UMFPACK_INFO];
304 Caller::solve(UMFPACK_A,
308 reinterpret_cast<double*
>(&x[0]),
309 reinterpret_cast<double*
>(&b[0]),
318 printOnApply(UMF_Apply_Info);
337 double UMF_Apply_Info[UMFPACK_INFO];
338 Caller::solve(UMFPACK_A,
347 printOnApply(UMF_Apply_Info);
363 if (option >= UMFPACK_CONTROL)
366 UMF_Control[option] = value;
374 int errcode = Caller::save_numeric(UMF_Numeric,
const_cast<char*
>(file));
375 if (errcode != UMFPACK_OK)
382 if ((mat.N() + mat.M() > 0) || (mat_is_loaded))
389 void setSubMatrix(
const Matrix& _mat,
const S& rowIndexSet)
391 if ((mat.N() + mat.M() > 0) || (mat_is_loaded))
393 mat.setMatrix(_mat,rowIndexSet);
409 UMF_Control[UMFPACK_PRL] = 1;
411 UMF_Control[UMFPACK_PRL] = 2;
413 UMF_Control[UMFPACK_PRL] = 4;
424 Caller::free_symbolic(&UMF_Symbolic);
427 Caller::free_numeric(&UMF_Numeric);
428 mat_is_loaded =
false;
431 const char* name() {
return "UMFPACK"; }
434 typedef typename Dune::UMFPackMethodChooser<T> Caller;
436 template<
class M,
class X,
class TM,
class TD,
class T1>
437 friend class SeqOverlappingSchwarz;
438 friend struct SeqOverlappingSchwarzAssemblerHelper<UMFPack<Matrix>,true>;
443 double UMF_Decomposition_Info[UMFPACK_INFO];
444 Caller::symbolic(
static_cast<int>(mat.N()),
445 static_cast<int>(mat.N()),
448 reinterpret_cast<double*
>(mat.getValues()),
451 UMF_Decomposition_Info);
452 Caller::numeric(mat.getColStart(),
454 reinterpret_cast<double*
>(mat.getValues()),
458 UMF_Decomposition_Info);
459 Caller::report_status(UMF_Control,UMF_Decomposition_Info[UMFPACK_STATUS]);
462 std::cout <<
"[UMFPack Decomposition]" << std::endl;
463 std::cout <<
"Wallclock Time taken: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_WALLTIME] <<
" (CPU Time: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_TIME] <<
")" << std::endl;
464 std::cout <<
"Flops taken: " << UMF_Decomposition_Info[UMFPACK_FLOPS] << std::endl;
465 std::cout <<
"Peak Memory Usage: " << UMF_Decomposition_Info[UMFPACK_PEAK_MEMORY]*UMF_Decomposition_Info[UMFPACK_SIZE_OF_UNIT] <<
" bytes" << std::endl;
466 std::cout <<
"Condition number estimate: " << 1./UMF_Decomposition_Info[UMFPACK_RCOND] << std::endl;
467 std::cout <<
"Numbers of non-zeroes in decomposition: L: " << UMF_Decomposition_Info[UMFPACK_LNZ] <<
" U: " << UMF_Decomposition_Info[UMFPACK_UNZ] << std::endl;
471 Caller::report_info(UMF_Control,UMF_Decomposition_Info);
475 void printOnApply(
double* UMF_Info)
477 Caller::report_status(UMF_Control,UMF_Info[UMFPACK_STATUS]);
480 std::cout <<
"[UMFPack Solve]" << std::endl;
481 std::cout <<
"Wallclock Time: " << UMF_Info[UMFPACK_SOLVE_WALLTIME] <<
" (CPU Time: " << UMF_Info[UMFPACK_SOLVE_TIME] <<
")" << std::endl;
482 std::cout <<
"Flops Taken: " << UMF_Info[UMFPACK_SOLVE_FLOPS] << std::endl;
483 std::cout <<
"Iterative Refinement steps taken: " << UMF_Info[UMFPACK_IR_TAKEN] << std::endl;
484 std::cout <<
"Error Estimate: " << UMF_Info[UMFPACK_OMEGA1] <<
" resp. " << UMF_Info[UMFPACK_OMEGA2] << std::endl;
493 double UMF_Control[UMFPACK_CONTROL];
496 template<
typename T,
typename A,
int n,
int m>
497 struct IsDirectSolver<UMFPack<BCRSMatrix<FieldMatrix<T,n,m>,A> > >
502 template<
typename T,
typename A,
int n,
int m>
503 struct StoresColumnCompressed<UMFPack<BCRSMatrix<FieldMatrix<T,n,m>,A> > >
505 enum { value =
true };
Implementation of the BCRSMatrix class.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:414
A vector of blocks with memory management.
Definition: bvector.hh:254
Base class for Dune-Exceptions.
Definition: exceptions.hh:92
A dense n x m matrix.
Definition: fmatrix.hh:67
vector space out of a tensor product of fields.
Definition: fvector.hh:92
Abstract base class for all solvers.
Definition: solver.hh:79
A generic dynamic dense matrix.
Definition: matrix.hh:25
Default exception class for range errors.
Definition: exceptions.hh:280
Use the UMFPack package to directly solve linear systems – empty default class.
Definition: umfpack.hh:50
A few common exception classes.
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.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
void setVerbosity(int v)
sets the verbosity level for the UMFPack solver
Definition: umfpack.hh:404
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:249
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:196
virtual void apply(domain_type &x, range_type &b, InverseOperatorResult &res)
Apply inverse operator,.
Definition: umfpack.hh:301
void setMatrix(const Matrix &_mat)
Initialize data from given matrix.
Definition: umfpack.hh:380
void free()
free allocated space.
Definition: umfpack.hh:420
UMFPack(const Matrix &mat_, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition: umfpack.hh:220
ColCompMatrixInitializer< BCRSMatrix< FieldMatrix< T, n, m >, A > > MatrixInitializer
Type of an associated initializer class.
Definition: umfpack.hh:192
void setOption(unsigned int option, double value)
Set UMFPack-specific options.
Definition: umfpack.hh:361
Dune::ColCompMatrix< Matrix > UMFPackMatrix
The corresponding SuperLU Matrix type.
Definition: umfpack.hh:190
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:200
UMFPack(const Matrix &mat_, int verbose=0)
construct a solver object from a BCRSMatrix
Definition: umfpack.hh:206
void apply(T *x, T *b)
additional apply method with c-arrays in analogy to superlu
Definition: umfpack.hh:335
UMFPack()
default constructor
Definition: umfpack.hh:232
UMFPack(const char *file, int verbose=0)
try loading a decomposition from file
Definition: umfpack.hh:276
virtual void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res)
apply inverse operator, with given convergence criteria.
Definition: umfpack.hh:324
void saveDecomposition(const char *file)
saves a decomposition to a file
Definition: umfpack.hh:372
Dune namespace.
Definition: alignment.hh:14
Implementations of the inverse operator interface.
Templates characterizing the type of a solver.
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:154
Statistics about the application of an inverse operator.
Definition: solver.hh:32
int iterations
Number of iterations.
Definition: solver.hh:50
bool converged
True if convergence criterion has been met.
Definition: solver.hh:56
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18