3 #ifndef DUNE_ISTL_LDL_HH
4 #define DUNE_ISTL_LDL_HH
6 #if HAVE_SUITESPARSE_LDL || defined DOXYGEN
19 #include <dune/common/exceptions.hh>
20 #include <dune/common/unused.hh>
40 template<
class M,
class T,
class TM,
class TD,
class TA>
41 class SeqOverlappingSchwarz;
43 template<
class T,
bool tag>
44 struct SeqOverlappingSchwarzAssemblerHelper;
52 template<
class Matrix>
69 template<
typename T,
typename A,
int n,
int m>
71 :
public InverseOperator<BlockVector<FieldVector<T,m>, typename A::template rebind<FieldVector<T,m> >::other>,
72 BlockVector<FieldVector<T,n>, typename A::template rebind<FieldVector<T,n> >::other> >
90 return SolverCategory::Category::sequential;
102 LDL(
const Matrix& matrix,
int verbose=0) : matrixIsLoaded_(false), verbose_(verbose)
105 static_assert(std::is_same<T,double>::value,
"Unsupported Type in LDL (only double supported)");
118 LDL(
const Matrix& matrix,
int verbose,
bool) : matrixIsLoaded_(false), verbose_(verbose)
121 static_assert(std::is_same<T,double>::value,
"Unsupported Type in LDL (only double supported)");
126 LDL() : matrixIsLoaded_(false), verbose_(0)
132 if ((ldlMatrix_.N() + ldlMatrix_.M() > 0) || matrixIsLoaded_)
139 const int dimMat(ldlMatrix_.N());
140 ldl_perm(dimMat, Y_,
reinterpret_cast<double*
>(&b[0]), P_);
141 ldl_lsolve(dimMat, Y_, Lp_, Li_, Lx_);
142 ldl_dsolve(dimMat, Y_, D_);
143 ldl_ltsolve(dimMat, Y_, Lp_, Li_, Lx_);
144 ldl_permt(dimMat,
reinterpret_cast<double*
>(&x[0]), Y_, P_);
153 DUNE_UNUSED_PARAMETER(reduction);
164 const int dimMat(ldlMatrix_.N());
165 ldl_perm(dimMat, Y_, b, P_);
166 ldl_lsolve(dimMat, Y_, Lp_, Li_, Lx_);
167 ldl_dsolve(dimMat, Y_, D_);
168 ldl_ltsolve(dimMat, Y_, Lp_, Li_, Lx_);
169 ldl_permt(dimMat, x, Y_, P_);
174 DUNE_UNUSED_PARAMETER(option);
175 DUNE_UNUSED_PARAMETER(value);
181 if ((ldlMatrix_.N() + ldlMatrix_.M() > 0) || matrixIsLoaded_)
190 if ((ldlMatrix_.N() + ldlMatrix_.M() > 0) || matrixIsLoaded_)
192 ldlMatrix_.setMatrix(matrix,rowIndexSet);
228 matrixIsLoaded_ =
false;
274 template<
class M,
class X,
class TM,
class TD,
class T1>
283 const int dimMat(ldlMatrix_.N());
284 D_ =
new double [dimMat];
285 Y_ =
new double [dimMat];
286 Lp_ =
new int [dimMat + 1];
287 Parent_ =
new int [dimMat];
288 Lnz_ =
new int [dimMat];
289 Flag_ =
new int [dimMat];
290 Pattern_ =
new int [dimMat];
291 P_ =
new int [dimMat];
292 Pinv_ =
new int [dimMat];
294 double Info [AMD_INFO];
295 if(amd_order (dimMat, ldlMatrix_.getColStart(), ldlMatrix_.getRowIndex(), P_, (
double *) NULL, Info) < AMD_OK)
296 DUNE_THROW(InvalidStateException,
"Error: AMD failed!");
300 ldl_symbolic(dimMat, ldlMatrix_.getColStart(), ldlMatrix_.getRowIndex(), Lp_, Parent_, Lnz_, Flag_, P_, Pinv_);
302 Lx_ =
new double [Lp_[dimMat]];
303 Li_ =
new int [Lp_[dimMat]];
305 const int rank(ldl_numeric(dimMat, ldlMatrix_.getColStart(), ldlMatrix_.getRowIndex(), ldlMatrix_.getValues(),
306 Lp_, Parent_, Lnz_, Li_, Lx_, D_, Y_, Pattern_, Flag_, P_, Pinv_));
314 DUNE_THROW(InvalidStateException,
"Error: LDL factorisation failed!");
317 LDLMatrix ldlMatrix_;
318 bool matrixIsLoaded_;
333 template<
typename T,
typename A,
int n,
int m>
339 template<
typename T,
typename A,
int n,
int m>
347 template<
int k>
struct isValidBlock<FieldVector<double,k>> : std::true_type{};
349 template<
typename TL,
typename M>
350 std::shared_ptr<Dune::InverseOperator<typename Dune::TypeListElement<1, TL>::type,
351 typename Dune::TypeListElement<2, TL>::type>>
354 isValidBlock<
typename Dune::TypeListElement<1, TL>::type::block_type>::value,
int> = 0)
const
356 int verbose = config.get(
"verbose", 0);
357 return std::make_shared<Dune::LDL<M>>(
mat,verbose);
361 template<
typename TL,
typename M>
362 std::shared_ptr<Dune::InverseOperator<typename Dune::TypeListElement<1, TL>::type,
363 typename Dune::TypeListElement<2, TL>::type>>
366 !
isValidBlock<
typename Dune::TypeListElement<1, TL>::type::block_type>::value,
int> = 0)
const
369 "Unsupported Type in LDL (only double and std::complex<double> supported)");
377 #endif //HAVE_SUITESPARSE_LDL
378 #endif //DUNE_ISTL_LDL_HH