Loading...
Searching...
No Matches
umfpack.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_UMFPACK_HH
#define DUNE_ISTL_UMFPACK_HH
#if HAVE_SUITESPARSE_UMFPACK || defined DOXYGEN
#include<complex>
#include<type_traits>
#include<umfpack.h>
#include<dune/common/exceptions.hh>
#include<dune/common/fmatrix.hh>
#include<dune/common/fvector.hh>
#include<dune/istl/bccsmatrixinitializer.hh>
#include<dune/istl/bcrsmatrix.hh>
#include<dune/istl/matrix.hh>
#include<dune/istl/foreach.hh>
#include<dune/istl/multitypeblockmatrix.hh>
#include<dune/istl/multitypeblockvector.hh>
#include<dune/istl/solvers.hh>
#include<dune/istl/solvertype.hh>
#include <dune/istl/solverfactory.hh>
namespace Dune {
// FORWARD DECLARATIONS
template<class M, class T, class TM, class TD, class TA>
class SeqOverlappingSchwarz;
template<class T, bool tag>
struct SeqOverlappingSchwarzAssemblerHelper;
// wrapper class for C-Function Calls in the backend. Choose the right function namespace
// depending on the template parameter used.
template<typename T>
struct UMFPackMethodChooser
{
static constexpr bool valid = false ;
};
template<>
struct UMFPackMethodChooser<double>
{
static constexpr bool valid = true ;
template<typename... A>
static void defaults(A... args)
{
umfpack_dl_defaults(args...);
}
template<typename... A>
static void free_numeric(A... args)
{
umfpack_dl_free_numeric(args...);
}
template<typename... A>
static void free_symbolic(A... args)
{
umfpack_dl_free_symbolic(args...);
}
template<typename... A>
static int load_numeric(A... args)
{
return umfpack_dl_load_numeric(args...);
}
template<typename... A>
static void numeric(A... args)
{
umfpack_dl_numeric(args...);
}
template<typename... A>
static void report_info(A... args)
{
umfpack_dl_report_info(args...);
}
template<typename... A>
static void report_status(A... args)
{
umfpack_dl_report_status(args...);
}
template<typename... A>
static int save_numeric(A... args)
{
return umfpack_dl_save_numeric(args...);
}
template<typename... A>
static void solve(A... args)
{
umfpack_dl_solve(args...);
}
template<typename... A>
static void symbolic(A... args)
{
umfpack_dl_symbolic(args...);
}
};
template<>
struct UMFPackMethodChooser<std::complex<double> >
{
static constexpr bool valid = true ;
using size_type = SuiteSparse_long;
template<typename... A>
static void defaults(A... args)
{
umfpack_zl_defaults(args...);
}
template<typename... A>
static void free_numeric(A... args)
{
umfpack_zl_free_numeric(args...);
}
template<typename... A>
static void free_symbolic(A... args)
{
umfpack_zl_free_symbolic(args...);
}
template<typename... A>
static int load_numeric(A... args)
{
return umfpack_zl_load_numeric(args...);
}
template<typename... A>
static void numeric(const size_type* cs, const size_type* ri, const double* val, A... args)
{
umfpack_zl_numeric(cs,ri,val,NULL,args...);
}
template<typename... A>
static void report_info(A... args)
{
umfpack_zl_report_info(args...);
}
template<typename... A>
static void report_status(A... args)
{
umfpack_zl_report_status(args...);
}
template<typename... A>
static int save_numeric(A... args)
{
return umfpack_zl_save_numeric(args...);
}
template<typename... A>
static void solve(size_type m, const size_type* cs, const size_type* ri, std::complex<double>* val, double* x, const double* b,A... args)
{
const double* cval = reinterpret_cast<const double*>(val);
umfpack_zl_solve(m,cs,ri,cval,NULL,x,NULL,b,NULL,args...);
}
template<typename... A>
static void symbolic(size_type m, size_type n, const size_type* cs, const size_type* ri, const double* val, A... args)
{
umfpack_zl_symbolic(m,n,cs,ri,val,NULL,args...);
}
};
namespace Impl
{
template<class M, class = void>
struct UMFPackVectorChooser;
template<class M> using UMFPackDomainType = typename UMFPackVectorChooser<M>::domain_type;
template<class M> using UMFPackRangeType = typename UMFPackVectorChooser<M>::range_type;
template<class M>
struct UMFPackVectorChooser<M,
std::enable_if_t<(std::is_same<M,double>::value) || (std::is_same<M,std::complex<double> >::value)>>
{
using domain_type = M;
using range_type = M;
};
template<typename T, int n, int m>
struct UMFPackVectorChooser<FieldMatrix<T,n,m>,
std::enable_if_t<(std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value)>>
{
using domain_type = FieldVector<T,m>;
using range_type = FieldVector<T,n>;
};
template<typename T, typename A>
struct UMFPackVectorChooser<BCRSMatrix<T,A>,
std::void_t<UMFPackDomainType<T>, UMFPackRangeType<T>>>
{
// In case of recursive deduction (e.g., BCRSMatrix<FieldMatrix<...>, Allocator<FieldMatrix<...>>>)
// the allocator needs to be converted to the sub-block allocator type too (e.g., Allocator<FieldVector<...>>).
// Note that matrix allocator is assumed to be the same as the domain/range type of allocators
using domain_type = BlockVector<UMFPackDomainType<T>, typename std::allocator_traits<A>::template rebind_alloc<UMFPackDomainType<T>>>;
using range_type = BlockVector<UMFPackRangeType<T>, typename std::allocator_traits<A>::template rebind_alloc<UMFPackRangeType<T>>>;
};
template<typename T, typename A>
struct UMFPackVectorChooser<Matrix<T,A>,
std::void_t<UMFPackDomainType<T>, UMFPackRangeType<T>>>
: public UMFPackVectorChooser<BCRSMatrix<T,A>, std::void_t<UMFPackDomainType<T>, UMFPackRangeType<T>>>
{};
// to make the `UMFPackVectorChooser` work with `MultiTypeBlockMatrix`, we need to add an intermediate step for the rows, which are typically `MultiTypeBlockVector`
template<typename FirstBlock, typename... Blocks>
struct UMFPackVectorChooser<MultiTypeBlockVector<FirstBlock, Blocks...>,
std::void_t<UMFPackDomainType<FirstBlock>, UMFPackRangeType<FirstBlock>, UMFPackDomainType<Blocks>...>>
{
using domain_type = MultiTypeBlockVector<UMFPackDomainType<FirstBlock>, UMFPackDomainType<Blocks>...>;
using range_type = UMFPackRangeType<FirstBlock>;
};
// specialization for `MultiTypeBlockMatrix` with `MultiTypeBlockVector` rows
template<typename FirstRow, typename... Rows>
struct UMFPackVectorChooser<MultiTypeBlockMatrix<FirstRow, Rows...>,
std::void_t<UMFPackDomainType<FirstRow>, UMFPackRangeType<FirstRow>, UMFPackRangeType<Rows>...>>
{
using domain_type = UMFPackDomainType<FirstRow>;
using range_type = MultiTypeBlockVector< UMFPackRangeType<FirstRow>, UMFPackRangeType<Rows>... >;
};
// dummy class to represent no BitVector
struct NoBitVector
{};
}
template<typename M>
class UMFPack : public InverseOperator<Impl::UMFPackDomainType<M>,Impl::UMFPackRangeType<M>>
{
using T = typename M::field_type;
public:
using size_type = SuiteSparse_long;
using Matrix = M;
using matrix_type = M;
using UMFPackMatrix = ISTL::Impl::BCCSMatrix<typename Matrix::field_type, size_type>;
using MatrixInitializer = ISTL::Impl::BCCSMatrixInitializer<M, size_type>;
using domain_type = Impl::UMFPackDomainType<M>;
using range_type = Impl::UMFPackRangeType<M>;
SolverCategory::Category category() const override
{
return SolverCategory::Category::sequential;
}
UMFPack(const Matrix& matrix, int verbose=0) : matrixIsLoaded_(false)
{
//check whether T is a supported type
static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
"Unsupported Type in UMFPack (only double and std::complex<double> supported)");
Caller::defaults(UMF_Control);
setVerbosity(verbose);
setMatrix(matrix);
}
UMFPack(const Matrix& matrix, int verbose, bool) : matrixIsLoaded_(false)
{
//check whether T is a supported type
static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
"Unsupported Type in UMFPack (only double and std::complex<double> supported)");
Caller::defaults(UMF_Control);
setVerbosity(verbose);
setMatrix(matrix);
}
UMFPack(const Matrix& mat_, const ParameterTree& config)
: UMFPack(mat_, config.get<int>("verbose", 0))
{}
UMFPack() : matrixIsLoaded_(false), verbosity_(0)
{
//check whether T is a supported type
static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
"Unsupported Type in UMFPack (only double and std::complex<double> supported)");
Caller::defaults(UMF_Control);
}
UMFPack(const Matrix& mat_, const char* file, int verbose=0)
{
//check whether T is a supported type
static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
"Unsupported Type in UMFPack (only double and std::complex<double> supported)");
Caller::defaults(UMF_Control);
setVerbosity(verbose);
int errcode = Caller::load_numeric(&UMF_Numeric, const_cast<char*>(file));
if ((errcode == UMFPACK_ERROR_out_of_memory) || (errcode == UMFPACK_ERROR_file_IO))
{
matrixIsLoaded_ = false;
setMatrix(mat_);
saveDecomposition(file);
}
else
{
matrixIsLoaded_ = true;
std::cout << "UMFPack decomposition successfully loaded from " << file << std::endl;
}
}
UMFPack(const char* file, int verbose=0)
{
//check whether T is a supported type
static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
"Unsupported Type in UMFPack (only double and std::complex<double> supported)");
Caller::defaults(UMF_Control);
int errcode = Caller::load_numeric(&UMF_Numeric, const_cast<char*>(file));
if (errcode == UMFPACK_ERROR_out_of_memory)
DUNE_THROW(Dune::Exception, "ran out of memory while loading UMFPack decomposition");
if (errcode == UMFPACK_ERROR_file_IO)
DUNE_THROW(Dune::Exception, "IO error while loading UMFPack decomposition");
matrixIsLoaded_ = true;
std::cout << "UMFPack decomposition successfully loaded from " << file << std::endl;
setVerbosity(verbose);
}
virtual ~UMFPack()
{
if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
free();
}
void apply(domain_type& x, range_type& b, InverseOperatorResult& res) override
{
if (umfpackMatrix_.N() != b.dim())
DUNE_THROW(Dune::ISTLError, "Size of right-hand-side vector b does not match the number of matrix rows!");
if (umfpackMatrix_.M() != x.dim())
DUNE_THROW(Dune::ISTLError, "Size of solution vector x does not match the number of matrix columns!");
if (b.size() == 0)
return;
// we have to convert x and b into flat structures
// however, this is linear in time
std::vector<T> xFlat(x.dim()), bFlat(b.dim());
flatVectorForEach(x, [&](auto&& entry, auto&& offset)
{
xFlat[ offset ] = entry;
});
flatVectorForEach(b, [&](auto&& entry, auto&& offset)
{
bFlat[ offset ] = entry;
});
double UMF_Apply_Info[UMFPACK_INFO];
Caller::solve(UMFPACK_A,
umfpackMatrix_.getColStart(),
umfpackMatrix_.getRowIndex(),
umfpackMatrix_.getValues(),
reinterpret_cast<double*>(&xFlat[0]),
reinterpret_cast<double*>(&bFlat[0]),
UMF_Numeric,
UMF_Control,
UMF_Apply_Info);
// copy back to blocked vector
flatVectorForEach(x, [&](auto&& entry, auto offset)
{
entry = xFlat[offset];
});
//this is a direct solver
res.iterations = 1;
res.converged = true;
res.elapsed = UMF_Apply_Info[UMFPACK_SOLVE_WALLTIME];
printOnApply(UMF_Apply_Info);
}
void apply (domain_type& x, range_type& b, [[maybe_unused]] double reduction, InverseOperatorResult& res) override
{
apply(x,b,res);
}
void apply(T* x, T* b)
{
double UMF_Apply_Info[UMFPACK_INFO];
Caller::solve(UMFPACK_A,
umfpackMatrix_.getColStart(),
umfpackMatrix_.getRowIndex(),
umfpackMatrix_.getValues(),
x,
b,
UMF_Numeric,
UMF_Control,
UMF_Apply_Info);
printOnApply(UMF_Apply_Info);
}
void setOption(unsigned int option, double value)
{
if (option >= UMFPACK_CONTROL)
DUNE_THROW(RangeError, "Requested non-existing UMFPack option");
UMF_Control[option] = value;
}
void saveDecomposition(const char* file)
{
int errcode = Caller::save_numeric(UMF_Numeric, const_cast<char*>(file));
if (errcode != UMFPACK_OK)
DUNE_THROW(Dune::Exception,"IO ERROR while trying to save UMFPack decomposition");
}
template<class BitVector = Impl::NoBitVector>
void setMatrix(const Matrix& matrix, const BitVector& bitVector = {})
{
if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
free();
if (matrix.N() == 0 or matrix.M() == 0)
return;
if (umfpackMatrix_.N() + umfpackMatrix_.M() + umfpackMatrix_.nonzeroes() != 0)
umfpackMatrix_.free();
constexpr bool useBitVector = not std::is_same_v<BitVector,Impl::NoBitVector>;
// use a dynamic flat vector for the bitset
std::vector<bool> flatBitVector;
// and a mapping from the compressed indices
std::vector<size_type> subIndices;
[[maybe_unused]] int numberOfIgnoredDofs = 0;
int nonZeros = 0;
if constexpr ( useBitVector )
{
auto flatSize = flatVectorForEach(bitVector, [](auto&&, auto&&){});
flatBitVector.resize(flatSize);
flatVectorForEach(bitVector, [&](auto&& entry, auto&& offset)
{
flatBitVector[ offset ] = entry;
if ( entry )
{
numberOfIgnoredDofs++;
}
});
}
// compute the flat dimension and the number of nonzeros of the matrix
auto [flatRows,flatCols] = flatMatrixForEach( matrix, [&](auto&& /*entry*/, auto&& row, auto&& col){
// do not count ignored entries
if constexpr ( useBitVector )
if ( flatBitVector[row] or flatBitVector[col] )
return;
nonZeros++;
});
if constexpr ( useBitVector )
{
// use the original flatRows!
subIndices.resize(flatRows,std::numeric_limits<std::size_t>::max());
size_type subIndexCounter = 0;
for ( size_type i=0; i<size_type(flatRows); i++ )
if ( not flatBitVector[ i ] )
subIndices[ i ] = subIndexCounter++;
// update the original matrix size
flatRows -= numberOfIgnoredDofs;
flatCols -= numberOfIgnoredDofs;
}
umfpackMatrix_.setSize(flatRows,flatCols);
umfpackMatrix_.Nnz_ = nonZeros;
// prepare the arrays
umfpackMatrix_.colstart = new size_type[flatCols+1];
umfpackMatrix_.rowindex = new size_type[nonZeros];
umfpackMatrix_.values = new T[nonZeros];
for ( size_type i=0; i<size_type(flatCols+1); i++ )
{
umfpackMatrix_.colstart[i] = 0;
}
// at first, we need to compute the column start indices
// therefore, we count all entries in each column and in the end we accumulate everything
flatMatrixForEach(matrix, [&](auto&& /*entry*/, auto&& flatRowIndex, auto&& flatColIndex)
{
// do nothing if entry is excluded
if constexpr ( useBitVector )
if ( flatBitVector[flatRowIndex] or flatBitVector[flatColIndex] )
return;
// pick compressed or uncompressed index
// compiler will hopefully do some constexpr optimization here
auto colIdx = useBitVector ? subIndices[flatColIndex] : flatColIndex;
umfpackMatrix_.colstart[colIdx+1]++;
});
// now accumulate
for ( size_type i=0; i<(size_type)flatCols; i++ )
{
umfpackMatrix_.colstart[i+1] += umfpackMatrix_.colstart[i];
}
// we need a compressed position counter in each column
std::vector<size_type> colPosition(flatCols,0);
// now we can set the entries: the procedure below works with both row- or column major index ordering
flatMatrixForEach(matrix, [&](auto&& entry, auto&& flatRowIndex, auto&& flatColIndex)
{
// do nothing if entry is excluded
if constexpr ( useBitVector )
if ( flatBitVector[flatRowIndex] or flatBitVector[flatColIndex] )
return;
// pick compressed or uncompressed index
// compiler will hopefully do some constexpr optimization here
auto rowIdx = useBitVector ? subIndices[flatRowIndex] : flatRowIndex;
auto colIdx = useBitVector ? subIndices[flatColIndex] : flatColIndex;
// the start index of each column is already fixed
auto colStart = umfpackMatrix_.colstart[colIdx];
// get the current number of picked elements in this column
auto colPos = colPosition[colIdx];
// assign the corresponding row index and the value of this element
umfpackMatrix_.rowindex[ colStart + colPos ] = rowIdx;
umfpackMatrix_.values[ colStart + colPos ] = entry;
// increase the number of picked elements in this column
colPosition[colIdx]++;
});
decompose();
}
// Keep legacy version using a set of scalar indices
// The new version using a bitVector type for marking the active matrix indices is
// directly given in `setMatrix` with an additional BitVector argument.
// The new version is more flexible and allows, e.g., marking single components of a matrix block.
void setSubMatrix(const Matrix& _mat, const std::set<typename Matrix::size_type>& rowIndexSet)
{
if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
free();
if (umfpackMatrix_.N() + umfpackMatrix_.M() + umfpackMatrix_.nonzeroes() != 0)
umfpackMatrix_.free();
umfpackMatrix_.setSize(rowIndexSet.size()*MatrixDimension<Matrix>::rowdim(_mat) / _mat.N(),
rowIndexSet.size()*MatrixDimension<Matrix>::coldim(_mat) / _mat.M());
ISTL::Impl::BCCSMatrixInitializer<Matrix, SuiteSparse_long> initializer(umfpackMatrix_);
copyToBCCSMatrix(initializer, ISTL::Impl::MatrixRowSubset<Matrix,std::set<typename Matrix::size_type> >(_mat,rowIndexSet));
decompose();
}
void setVerbosity(int v)
{
verbosity_ = v;
// set the verbosity level in UMFPack
if (verbosity_ == 0)
UMF_Control[UMFPACK_PRL] = 1;
if (verbosity_ == 1)
UMF_Control[UMFPACK_PRL] = 2;
if (verbosity_ == 2)
UMF_Control[UMFPACK_PRL] = 4;
}
void* getFactorization()
{
return UMF_Numeric;
}
UMFPackMatrix& getInternalMatrix()
{
return umfpackMatrix_;
}
void free()
{
if (!matrixIsLoaded_)
{
Caller::free_symbolic(&UMF_Symbolic);
umfpackMatrix_.free();
}
Caller::free_numeric(&UMF_Numeric);
matrixIsLoaded_ = false;
}
const char* name() { return "UMFPACK"; }
private:
typedef typename Dune::UMFPackMethodChooser<T> Caller;
template<class Mat,class X, class TM, class TD, class T1>
friend class SeqOverlappingSchwarz;
friend struct SeqOverlappingSchwarzAssemblerHelper<UMFPack<Matrix>,true>;
void decompose()
{
double UMF_Decomposition_Info[UMFPACK_INFO];
Caller::symbolic(static_cast<SuiteSparse_long>(umfpackMatrix_.N()),
static_cast<SuiteSparse_long>(umfpackMatrix_.N()),
umfpackMatrix_.getColStart(),
umfpackMatrix_.getRowIndex(),
reinterpret_cast<double*>(umfpackMatrix_.getValues()),
&UMF_Symbolic,
UMF_Control,
UMF_Decomposition_Info);
Caller::numeric(umfpackMatrix_.getColStart(),
umfpackMatrix_.getRowIndex(),
reinterpret_cast<double*>(umfpackMatrix_.getValues()),
UMF_Symbolic,
&UMF_Numeric,
UMF_Control,
UMF_Decomposition_Info);
Caller::report_status(UMF_Control,UMF_Decomposition_Info[UMFPACK_STATUS]);
if (verbosity_ == 1)
{
std::cout << "[UMFPack Decomposition]" << std::endl;
std::cout << "Wallclock Time taken: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_WALLTIME] << " (CPU Time: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_TIME] << ")" << std::endl;
std::cout << "Flops taken: " << UMF_Decomposition_Info[UMFPACK_FLOPS] << std::endl;
std::cout << "Peak Memory Usage: " << UMF_Decomposition_Info[UMFPACK_PEAK_MEMORY]*UMF_Decomposition_Info[UMFPACK_SIZE_OF_UNIT] << " bytes" << std::endl;
std::cout << "Condition number estimate: " << 1./UMF_Decomposition_Info[UMFPACK_RCOND] << std::endl;
std::cout << "Numbers of non-zeroes in decomposition: L: " << UMF_Decomposition_Info[UMFPACK_LNZ] << " U: " << UMF_Decomposition_Info[UMFPACK_UNZ] << std::endl;
}
if (verbosity_ == 2)
{
Caller::report_info(UMF_Control,UMF_Decomposition_Info);
}
}
void printOnApply(double* UMF_Info)
{
Caller::report_status(UMF_Control,UMF_Info[UMFPACK_STATUS]);
if (verbosity_ > 0)
{
std::cout << "[UMFPack Solve]" << std::endl;
std::cout << "Wallclock Time: " << UMF_Info[UMFPACK_SOLVE_WALLTIME] << " (CPU Time: " << UMF_Info[UMFPACK_SOLVE_TIME] << ")" << std::endl;
std::cout << "Flops Taken: " << UMF_Info[UMFPACK_SOLVE_FLOPS] << std::endl;
std::cout << "Iterative Refinement steps taken: " << UMF_Info[UMFPACK_IR_TAKEN] << std::endl;
std::cout << "Error Estimate: " << UMF_Info[UMFPACK_OMEGA1] << " resp. " << UMF_Info[UMFPACK_OMEGA2] << std::endl;
}
}
UMFPackMatrix umfpackMatrix_;
bool matrixIsLoaded_;
int verbosity_;
void *UMF_Symbolic;
void *UMF_Numeric;
double UMF_Control[UMFPACK_CONTROL];
};
template<typename M>
struct IsDirectSolver<UMFPack<M>>
{
enum { value=true};
};
template<typename T, typename A>
struct StoresColumnCompressed<UMFPack<BCRSMatrix<T,A> > >
{
enum { value = true };
};
namespace UMFPackImpl {
template<class OpTraits, class=void> struct isValidBlock : std::false_type{};
template<class OpTraits> struct isValidBlock<OpTraits,
std::enable_if_t<
std::is_same_v<Impl::UMFPackDomainType<typename OpTraits::matrix_type>, typename OpTraits::domain_type>
&& std::is_same_v<Impl::UMFPackRangeType<typename OpTraits::matrix_type>, typename OpTraits::range_type>
&& std::is_same_v<typename FieldTraits<typename OpTraits::domain_type::field_type>::real_type, double>
&& std::is_same_v<typename FieldTraits<typename OpTraits::range_type::field_type>::real_type, double>
>> : std::true_type {};
}
DUNE_REGISTER_SOLVER("umfpack",
[](auto opTraits, const auto& op, const Dune::ParameterTree& config)
-> std::shared_ptr<typename decltype(opTraits)::solver_type>
{
using OpTraits = decltype(opTraits);
// works only for sequential operators
if constexpr (OpTraits::isParallel){
if(opTraits.getCommOrThrow(op).communicator().size() > 1)
DUNE_THROW(Dune::InvalidStateException, "UMFPack works only for sequential operators.");
}
if constexpr (OpTraits::isAssembled){
using M = typename OpTraits::matrix_type;
// check if UMFPack<M>* is convertible to
// InverseOperator*. This checks compatibility of the
// domain and range types
if constexpr (UMFPackImpl::isValidBlock<OpTraits>::value) {
const auto& A = opTraits.getAssembledOpOrThrow(op);
const M& mat = A->getmat();
int verbose = config.get("verbose", 0);
return std::make_shared<Dune::UMFPack<M>>(mat,verbose);
}
}
DUNE_THROW(UnsupportedType,
"Unsupported Type in UMFPack (only double and std::complex<double> supported)");
return nullptr;
});
} // end namespace Dune
#endif // HAVE_SUITESPARSE_UMFPACK
#endif //DUNE_ISTL_UMFPACK_HH
bcrsmatrix.hh
Implementation of the BCRSMatrix class.
matrix.hh
A dynamic dense block matrix class.
solverfactory.hh
solvers.hh
Implementations of the inverse operator interface.
foreach.hh
multitypeblockvector.hh
solvertype.hh
Templates characterizing the type of a solver.
bccsmatrixinitializer.hh
multitypeblockmatrix.hh
DUNE_REGISTER_SOLVER
#define DUNE_REGISTER_SOLVER(name,...)
Definition solverregistry.hh:16
Dune::UMFPack::setSubMatrix
void setSubMatrix(const Matrix &_mat, const std::set< typename Matrix::size_type > &rowIndexSet)
Definition umfpack.hh:657
Dune::UMFPack::free
void free()
free allocated space.
Definition umfpack.hh:715
Dune::UMFPack::SeqOverlappingSchwarz
friend class SeqOverlappingSchwarz
Definition umfpack.hh:732
Dune::UMFPack::size_type
SuiteSparse_long size_type
Definition umfpack.hh:269
Dune::UMFPackMethodChooser< std::complex< double > >::symbolic
static void symbolic(size_type m, size_type n, const size_type *cs, const size_type *ri, const double *val, A... args)
Definition umfpack.hh:167
Dune::UMFPackMethodChooser< std::complex< double > >::solve
static void solve(size_type m, const size_type *cs, const size_type *ri, std::complex< double > *val, double *x, const double *b, A... args)
Definition umfpack.hh:161
Dune::UMFPack::matrix_type
M matrix_type
Definition umfpack.hh:273
Dune::UMFPackMethodChooser< std::complex< double > >::numeric
static void numeric(const size_type *cs, const size_type *ri, const double *val, A... args)
Definition umfpack.hh:141
Dune::UMFPackMethodChooser< std::complex< double > >::report_info
static void report_info(A... args)
Definition umfpack.hh:146
Dune::UMFPack::UMFPack
UMFPack(const Matrix &mat_, const ParameterTree &config)
Construct a solver object from a matrix.
Definition umfpack.hh:334
Dune::UMFPackMethodChooser< std::complex< double > >::load_numeric
static int load_numeric(A... args)
Definition umfpack.hh:136
Dune::UMFPackMethodChooser< double >::load_numeric
static int load_numeric(A... args)
Definition umfpack.hh:78
Dune::UMFPackMethodChooser< double >::report_status
static void report_status(A... args)
Definition umfpack.hh:93
Dune::UMFPack::UMFPack
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:358
Dune::UMFPack::range_type
Impl::UMFPackRangeType< M > range_type
The type of the range of the solver.
Definition umfpack.hh:281
Dune::UMFPack::UMFPack
UMFPack()
default constructor
Definition umfpack.hh:340
Dune::UMFPackMethodChooser< double >::symbolic
static void symbolic(A... args)
Definition umfpack.hh:108
Dune::UMFPackMethodChooser< double >::report_info
static void report_info(A... args)
Definition umfpack.hh:88
Dune::UMFPackMethodChooser< double >::free_symbolic
static void free_symbolic(A... args)
Definition umfpack.hh:73
Dune::UMFPackMethodChooser< std::complex< double > >::save_numeric
static int save_numeric(A... args)
Definition umfpack.hh:156
Dune::UMFPackMethodChooser< std::complex< double > >::free_numeric
static void free_numeric(A... args)
Definition umfpack.hh:126
Dune::UMFPackMethodChooser< double >::save_numeric
static int save_numeric(A... args)
Definition umfpack.hh:98
Dune::UMFPackMethodChooser< std::complex< double > >::report_status
static void report_status(A... args)
Definition umfpack.hh:151
Dune::UMFPack::domain_type
Impl::UMFPackDomainType< M > domain_type
The type of the domain of the solver.
Definition umfpack.hh:279
Dune::UMFPack::apply
void apply(T *x, T *b)
additional apply method with c-arrays in analogy to superlu
Definition umfpack.hh:473
Dune::UMFPack::category
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category).
Definition umfpack.hh:284
Dune::UMFPackMethodChooser< std::complex< double > >::defaults
static void defaults(A... args)
Definition umfpack.hh:121
Dune::UMFPackMethodChooser< double >::free_numeric
static void free_numeric(A... args)
Definition umfpack.hh:68
Dune::UMFPack::setVerbosity
void setVerbosity(int v)
sets the verbosity level for the UMFPack solver
Definition umfpack.hh:681
Dune::UMFPack::UMFPack
UMFPack(const char *file, int verbose=0)
try loading a decomposition from file
Definition umfpack.hh:385
Dune::UMFPackMethodChooser< double >::numeric
static void numeric(A... args)
Definition umfpack.hh:83
Dune::UMFPackMethodChooser< double >::valid
static constexpr bool valid
Definition umfpack.hh:60
Dune::UMFPack::apply
void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res) override
apply inverse operator, with given convergence criteria.
Definition umfpack.hh:461
Dune::UMFPackMethodChooser::valid
static constexpr bool valid
Definition umfpack.hh:54
Dune::UMFPack::~UMFPack
virtual ~UMFPack()
Definition umfpack.hh:401
Dune::UMFPack::name
const char * name()
Definition umfpack.hh:726
Dune::UMFPack::setMatrix
void setMatrix(const Matrix &matrix, const BitVector &bitVector={})
Initialize data from given matrix.
Definition umfpack.hh:527
Dune::UMFPack::saveDecomposition
void saveDecomposition(const char *file)
saves a decomposition to a file
Definition umfpack.hh:510
Dune::UMFPack::getInternalMatrix
UMFPackMatrix & getInternalMatrix()
Return the column compress matrix from UMFPack.
Definition umfpack.hh:706
Dune::UMFPackMethodChooser< std::complex< double > >::size_type
SuiteSparse_long size_type
Definition umfpack.hh:118
Dune::UMFPack::UMFPack
UMFPack(const Matrix &matrix, int verbose=0)
Construct a solver object from a matrix.
Definition umfpack.hh:297
Dune::UMFPack::MatrixInitializer
ISTL::Impl::BCCSMatrixInitializer< M, size_type > MatrixInitializer
Type of an associated initializer class.
Definition umfpack.hh:277
Dune::UMFPack::UMFPackMatrix
ISTL::Impl::BCCSMatrix< typename Matrix::field_type, size_type > UMFPackMatrix
The corresponding (scalar) UMFPack matrix type.
Definition umfpack.hh:275
Dune::UMFPack::setOption
void setOption(unsigned int option, double value)
Set UMFPack-specific options.
Definition umfpack.hh:499
Dune::UMFPackMethodChooser< std::complex< double > >::free_symbolic
static void free_symbolic(A... args)
Definition umfpack.hh:131
Dune::UMFPack::Matrix
M Matrix
The matrix type.
Definition umfpack.hh:272
Dune::UMFPackMethodChooser< double >::defaults
static void defaults(A... args)
Definition umfpack.hh:63
Dune::UMFPack::apply
void apply(domain_type &x, range_type &b, InverseOperatorResult &res) override
Apply inverse operator,.
Definition umfpack.hh:410
Dune::UMFPackMethodChooser< double >::solve
static void solve(A... args)
Definition umfpack.hh:103
Dune::UMFPackMethodChooser< std::complex< double > >::valid
static constexpr bool valid
Definition umfpack.hh:117
Dune::UMFPack::UMFPack
UMFPack(const Matrix &matrix, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition umfpack.hh:315
Dune::UMFPack::getFactorization
void * getFactorization()
Return the matrix factorization.
Definition umfpack.hh:697
Dune::StoresColumnCompressed< UMFPack< BCRSMatrix< T, A > > >::value
@ value
Definition umfpack.hh:800
Dune::IsDirectSolver< UMFPack< M > >::value
@ value
Definition umfpack.hh:794
std
STL namespace.
Dune
Definition allocator.hh:11
Dune::flatMatrixForEach
std::pair< std::size_t, std::size_t > flatMatrixForEach(Matrix &&matrix, F &&f, std::size_t rowOffset=0, std::size_t colOffset=0)
Traverse a blocked matrix and call a functor at each scalar entry.
Definition foreach.hh:132
Dune::get
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get(const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition dependency.hh:293
Dune::col
MatrixSparsityPatternGatherScatter< M, I >::ColIter MatrixSparsityPatternGatherScatter< M, I >::col
Definition matrixredistribute.hh:591
Dune::flatVectorForEach
std::size_t flatVectorForEach(Vector &&vector, F &&f, std::size_t offset=0)
Traverse a blocked vector and call a functor at each scalar entry.
Definition foreach.hh:95
Dune::UMFPackImpl
Definition umfpack.hh:803
Dune::MatrixDimension::coldim
static auto coldim(const M &)
Definition matrixutils.hh:219
Dune::MatrixDimension::rowdim
static auto rowdim(const M &)
Definition matrixutils.hh:214
Dune::BCRSMatrix
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:467
Dune::ISTLError
derive error class from the base class in common
Definition istlexception.hh:19
Dune::SeqOverlappingSchwarz
Sequential overlapping Schwarz preconditioner.
Definition overlappingschwarz.hh:755
Dune::SeqOverlappingSchwarzAssemblerHelper
Definition overlappingschwarz.hh:694
Dune::InverseOperatorResult
Statistics about the application of an inverse operator.
Definition solver.hh:50
Dune::InverseOperatorResult::elapsed
double elapsed
Elapsed time in seconds.
Definition solver.hh:84
Dune::InverseOperatorResult::iterations
int iterations
Number of iterations.
Definition solver.hh:69
Dune::InverseOperatorResult::converged
bool converged
True if convergence criterion has been met.
Definition solver.hh:75
Dune::InverseOperator
Abstract base class for all solvers.
Definition solver.hh:101
Dune::SolverCategory::Category
Category
Definition solvercategory.hh:23
Dune::SolverCategory::sequential
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:25
Dune::UnsupportedType
Definition solverregistry.hh:97
Dune::IsDirectSolver
Definition solvertype.hh:16
Dune::StoresColumnCompressed
Definition solvertype.hh:30
Dune::UMFPackMethodChooser
Definition umfpack.hh:53
Dune::UMFPack
The UMFPack direct sparse solver.
Definition umfpack.hh:265
Dune::UMFPackImpl::isValidBlock
Definition umfpack.hh:804