Unverified Commit d4c5983a authored by René Fritze's avatar René Fritze

Merge remote-tracking branch 'la/merger'

parents 34f493b8 9bf9de06
# ~~~
man
# This file is part of the dune-xt-la project:
# https://github.com/dune-community/dune-xt-la
# Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
# Authors:
# Felix Schindler (2012 - 2013, 2016 - 2017)
# René Fritze (2009 - 2012, 2015, 2017 - 2018)
# Tobias Leibner (2018)
# ~~~
doc/doxygen
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
......
# ~~~
# This file is part of the dune-xt-la project:
# https://github.com/dune-community/dune-xt-la
# Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
# Authors:
# Felix Schindler (2016 - 2017)
# René Fritze (2018)
#
# File for module specific CMake tests.
# ~~~
......@@ -14,3 +14,4 @@
add_subdirectory(grid)
add_subdirectory(common)
add_subdirectory(functions)
add_subdirectory(la)
# ~~~
# This file is part of the dune-xt-la project:
# https://github.com/dune-community/dune-xt-la
# Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
# Authors:
# Felix Schindler (2016 - 2017)
# René Fritze (2016, 2018)
# Tobias Leibner (2016 - 2018)
# ~~~
set(lib_dune_xt_la_sources container/pattern.cc eigen-solver/internal/numpy.cc)
if(DUNE_XT_WITH_PYTHON_BINDINGS)
list(APPEND lib_dune_xt_la_sources
container/common.cc
container/eigen/dense.cc
container/eigen/sparse.cc
container/istl.cc
solver/common.cc
solver/eigen.cc
solver/istl.cc)
endif()
find_package(LAPACKE)
dune_library_add_sources(dunextla SOURCES ${lib_dune_xt_la_sources})
add_subdirectory(test EXCLUDE_FROM_ALL)
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2017)
// Rene Milk (2018)
// Tobias Leibner (2017 - 2018)
#ifndef DUNE_XT_LA_ALGORITHMS_HH
#define DUNE_XT_LA_ALGORITHMS_HH
#include "algorithms/cholesky.hh"
#include "algorithms/solve_sym_tridiag_posdef.hh"
#include "algorithms/qr.hh"
#include "algorithms/triangular_solves.hh"
#endif // DUNE_XT_LA_ALGORITHMS_HH
This diff is collapsed.
This diff is collapsed.
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Rene Milk (2018)
// Tobias Leibner (2017 - 2018)
#ifndef DUNE_XT_LA_ALGORITHMS_SOLVE_SYM_TRIDIAG_POSDEF_HH
#define DUNE_XT_LA_ALGORITHMS_SOLVE_SYM_TRIDIAG_POSDEF_HH
#include <cstddef>
#include <dune/common/exceptions.hh>
#include <dune/xt/common/lapacke.hh>
#include <dune/xt/common/matrix.hh>
#include <dune/xt/common/vector.hh>
#include <dune/xt/la/algorithms/cholesky.hh>
namespace Dune {
namespace XT {
namespace LA {
/** \brief Solves linear equation for tridiagonal symmetric positive definite matrix.
* \param[in] diag vector containing the diagonal elements of the matrix (length dimRange)
* \param[in] subdiag vector containing the sub-diagonal elements of the matrix (length dimRange-1)
* \param[in/out] b vector containing the rhs (length dimRange). Is overwritten by the solution of the equation.
*/
template <class VectorType, class SecondVectorType, class RhsVectorType>
std::enable_if_t<Common::is_vector<VectorType>::value && Common::is_vector<SecondVectorType>::value
&& Common::is_vector<RhsVectorType>::value,
void>
solve_sym_tridiag_posdef(VectorType& diag, SecondVectorType& subdiag, RhsVectorType& b)
{
tridiagonal_ldlt(diag, subdiag);
solve_tridiagonal_ldlt_factorized(diag, subdiag, b);
}
template <class MatrixType, class VectorType, class RhsVectorType>
std::enable_if_t<Common::is_matrix<MatrixType>::value && Common::is_vector<VectorType>::value
&& Common::is_vector<RhsVectorType>::value,
void>
solve_sym_tridiag_posdef(const MatrixType& A, VectorType& x, const RhsVectorType& y)
{
typedef Common::MatrixAbstraction<MatrixType> Mat;
typedef typename Mat::ScalarType ScalarType;
const size_t num_rows = Mat::rows(A);
std::vector<ScalarType> diag(num_rows, 0.);
std::vector<ScalarType> sub_diag(num_rows - 1, 0.);
for (size_t rr = 0; rr < num_rows; ++rr)
diag[rr] = Mat::get_entry(A, rr, rr);
for (size_t rr = 0; rr < num_rows - 1; ++rr)
sub_diag[rr] = Mat::get_entry(A, rr + 1, rr);
// copy y to x
x = Common::convert_to<VectorType>(y);
solve_sym_tridiag_posdef(diag, sub_diag, x);
}
} // namespace LA
} // namespace XT
} // namespace Dune
#endif // DUNE_XT_LA_ALGORITHMS_SOLVE_SYM_TRIDIAG_POSDEF_HH
This diff is collapsed.
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2013 - 2014, 2016 - 2017)
// Rene Milk (2015 - 2016, 2018)
// Tobias Leibner (2017 - 2018)
#ifndef DUNE_XT_LA_CONTAINER_HH
#define DUNE_XT_LA_CONTAINER_HH
#include <boost/tuple/tuple.hpp>
#include "container/interfaces.hh"
#include "container/common.hh"
#include "container/eigen.hh"
#include "container/istl.hh"
namespace Dune {
namespace XT {
namespace LA {
template <class ScalarType, Backends backend = default_backend>
struct Container;
template <class ScalarType>
struct Container<ScalarType, Backends::common_dense>
{
typedef CommonDenseVector<ScalarType> VectorType;
typedef CommonDenseMatrix<ScalarType> MatrixType;
}; // struct Container<..., common_dense>
template <class ScalarType>
struct Container<ScalarType, Backends::common_sparse>
{
typedef CommonDenseVector<ScalarType> VectorType;
typedef CommonSparseMatrix<ScalarType> MatrixType;
}; // struct Container<..., common_sparse>
template <class ScalarType>
struct Container<ScalarType, Backends::eigen_dense>
{
typedef EigenDenseVector<ScalarType> VectorType;
typedef EigenDenseMatrix<ScalarType> MatrixType;
}; // struct Container<..., eigen_dense>
template <class ScalarType>
struct Container<ScalarType, Backends::eigen_sparse>
{
typedef EigenDenseVector<ScalarType> VectorType;
typedef EigenRowMajorSparseMatrix<ScalarType> MatrixType;
}; // struct Container<..., eigen_sparse>
template <class ScalarType>
struct Container<ScalarType, Backends::istl_dense>
{
typedef IstlDenseVector<ScalarType> VectorType;
typedef IstlRowMajorSparseMatrix<ScalarType> MatrixType;
}; // struct Container<..., istl_dense>
template <class ScalarType>
struct Container<ScalarType, Backends::istl_sparse>
{
typedef IstlDenseVector<ScalarType> VectorType;
typedef IstlRowMajorSparseMatrix<ScalarType> MatrixType;
}; // struct Container<..., istl_sparse>
template <class S>
using AvailableVectorTypes = boost::tuple<CommonDenseVector<S>,
IstlDenseVector<S>
#if HAVE_EIGEN
,
EigenDenseVector<S>
#endif
>;
template <class S>
using AvailableDenseMatrixTypes = boost::tuple<CommonDenseMatrix<S>
#if HAVE_EIGEN
,
EigenDenseMatrix<S>
#endif
>;
template <class S>
using AvailableSparseMatrixTypes = boost::tuple<CommonSparseMatrix<S>,
IstlRowMajorSparseMatrix<S>
#if HAVE_EIGEN
,
EigenRowMajorSparseMatrix<S>
#endif
>;
} // namespace LA
} // namespace XT
} // namespace Dune
#endif // DUNE_XT_LA_CONTAINER_HH
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2017)
// Rene Milk (2018)
// TiKeil (2018)
// Tobias Leibner (2017)
#include <config.h>
#include "common.hh"
template class Dune::XT::LA::CommonDenseVector<double>;
template class Dune::XT::LA::CommonDenseMatrix<double>;
template class Dune::XT::LA::CommonSparseVector<double>;
template class Dune::XT::LA::CommonSparseMatrix<double, Dune::XT::Common::StorageLayout::csr>;
template class Dune::XT::LA::CommonSparseMatrix<double, Dune::XT::Common::StorageLayout::csc>;
// template void Dune::XT::LA::CommonSparseMatrix<double>::mv(const Dune::XT::LA::CommonDenseVector<double>&,
// Dune::XT::LA::CommonDenseVector<double>) const;
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Barbara Verfürth (2015)
// Felix Schindler (2013 - 2017)
// Rene Milk (2014 - 2016, 2018)
// Tobias Leibner (2014, 2016 - 2017)
#ifndef DUNE_XT_LA_CONTAINER_COMMON_HH
#define DUNE_XT_LA_CONTAINER_COMMON_HH
#include "common/vector.hh"
#include "common/matrix.hh"
#endif // DUNE_XT_LA_CONTAINER_COMMON_HH
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2017)
// Rene Milk (2018)
// Tobias Leibner (2017)
#ifndef DUNE_XT_LA_CONTAINER_COMMON_MATRIX_HH
#define DUNE_XT_LA_CONTAINER_COMMON_MATRIX_HH
#include "matrix/dense.hh"
#include "matrix/sparse.hh"
#endif // DUNE_XT_LA_CONTAINER_COMMON_MATRIX_HH
This diff is collapsed.
This diff is collapsed.
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2017)
// Rene Milk (2018)
// Tobias Leibner (2017)
#ifndef DUNE_XT_LA_CONTAINER_COMMON_VECTOR_HH
#define DUNE_XT_LA_CONTAINER_COMMON_VECTOR_HH
#include "vector/dense.hh"
#include "vector/sparse.hh"
#endif // DUNE_XT_LA_CONTAINER_COMMON_VECTOR_HH
// This file is part of the dune-xt-la project:
// https://github.com/dune-community/dune-xt-la
// Copyright 2009-2018 dune-xt-la developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Rene Milk (2018)
// Tobias Leibner (2017)
#ifndef DUNE_XT_LA_CONTAINER_COMMON_VECTOR_DENSE_HH
#define DUNE_XT_LA_CONTAINER_COMMON_VECTOR_DENSE_HH
#include <cmath>
#include <initializer_list>
#include <memory>
#include <type_traits>
#include <vector>
#include <complex>
#include <mutex>
#include <dune/common/dynvector.hh>
#include <dune/common/float_cmp.hh>
#include <dune/common/ftraits.hh>
#include <dune/common/unused.hh>
#include <dune/xt/common/exceptions.hh>
#include <dune/xt/la/container/vector-interface.hh>
namespace Dune {
namespace XT {
namespace LA {
// forwards
template <class ScalarImp>
class CommonDenseVector;
namespace internal {
/// Traits for CommonDenseVector
template <class ScalarImp>
class CommonDenseVectorTraits
: public VectorTraitsBase<ScalarImp,
CommonDenseVector<ScalarImp>,
Dune::DynamicVector<ScalarImp>,
Backends::common_dense,
Backends::common_dense,
Backends::common_sparse>
{};
} // namespace internal
/**
* \brief A dense vector implementation of VectorInterface using the Dune::DynamicVector.
*/
template <class ScalarImp = double>
class CommonDenseVector
: public VectorInterface<internal::CommonDenseVectorTraits<ScalarImp>, ScalarImp>
, public ProvidesBackend<internal::CommonDenseVectorTraits<ScalarImp>>
, public ProvidesDataAccess<internal::CommonDenseVectorTraits<ScalarImp>>
{
using ThisType = CommonDenseVector;
using InterfaceType = VectorInterface<internal::CommonDenseVectorTraits<ScalarImp>, ScalarImp>;
public:
using typename InterfaceType::RealType;
using typename InterfaceType::ScalarType;
using Traits = typename InterfaceType::Traits;
using typename ProvidesBackend<Traits>::BackendType;
using typename ProvidesDataAccess<Traits>::DataType;
// needed to fix gcc compilation error due to ambiguous lookup of derived type
using derived_type = typename Traits::derived_type;
private:
using MutexesType = typename Traits::MutexesType;
public:
explicit CommonDenseVector(const size_t ss = 0, const ScalarType& value = ScalarType(), const size_t num_mutexes = 1)
: backend_(new BackendType(ss, value))
, mutexes_(std::make_unique<MutexesType>(num_mutexes))
{}
explicit CommonDenseVector(const std::vector<ScalarType>& other, const size_t num_mutexes = 1)
: backend_(new BackendType(other.size()))
, mutexes_(std::make_unique<MutexesType>(num_mutexes))
{
for (size_t ii = 0; ii < other.size(); ++ii)
backend_->operator[](ii) = other[ii];
}
explicit CommonDenseVector(const std::initializer_list<ScalarType>& other, const size_t num_mutexes = 1)
: backend_(new BackendType(other.size()))
, mutexes_(std::make_unique<MutexesType>(num_mutexes))
{
size_t ii = 0;
for (auto element : other) {
backend_->operator[](ii) = element;
++ii;
}
} // CommonDenseVector(...)
CommonDenseVector(const ThisType& other)
: backend_(std::make_shared<BackendType>(*other.backend_))
, mutexes_(std::make_unique<MutexesType>(other.mutexes_->size()))
{}
explicit CommonDenseVector(const BackendType& other,
const bool /*prune*/ = false,
const ScalarType /*eps*/ = Common::FloatCmp::DefaultEpsilon<ScalarType>::value(),
const size_t num_mutexes = 1)
: backend_(new BackendType(other))
, mutexes_(std::make_unique<MutexesType>(num_mutexes))
{}
/**
* \note Takes ownership of backend_ptr in the sense that you must not delete it afterwards!
*/
explicit CommonDenseVector(BackendType* backend_ptr, const size_t num_mutexes = 1)
: backend_(backend_ptr)
, mutexes_(std::make_unique<MutexesType>(num_mutexes))
{}
explicit CommonDenseVector(std::shared_ptr<BackendType> backend_ptr, const size_t num_mutexes = 1)
: backend_(backend_ptr)
, mutexes_(std::make_unique<MutexesType>(num_mutexes))
{}
ThisType& operator=(const ThisType& other)
{
if (this != &other) {
*backend_ = *other.backend_;
mutexes_ = std::make_unique<MutexesType>(other.mutexes_->size());
}
return *this;
}
ThisType& operator=(const ScalarType& value)
{
for (auto& element : *this)
element = value;
return *this;
} // ... operator=(...)
/**
* \note Does a deep copy.
*/
ThisType& operator=(const BackendType& other)
{
*backend_ = other;
return *this;
}
/// \name Required by the ProvidesBackend interface.
/// \{
BackendType& backend()
{
return *backend_;
}
const BackendType& backend() const
{
return *backend_;
}
/// \}
/// \name Required by ProvidesDataAccess.
/// \{
/** \attention This makes only sense for scalar data types, not for complex! **/
ScalarType* data()
{
return &(backend()[0]);
}
size_t data_size() const
{
return size();
}
/// \}
/// \name Required by ContainerInterface.
/// \{
ThisType copy() const
{
return ThisType(*backend_);
}
void scal(const ScalarType& alpha)
{
const internal::VectorLockGuard DUNE_UNUSED(guard)(*mutexes_);
backend() *= alpha;
}
void axpy(const ScalarType& alpha, const ThisType& xx)
{
if (xx.size() != size())
DUNE_THROW(Common::Exceptions::shapes_do_not_match,
"The size of x (" << xx.size() << ") does not match the size of this (" << size() << ")!");
const internal::VectorLockGuard DUNE_UNUSED(guard)(*mutexes_);
for (size_t ii = 0; ii < backend().size(); ++ii)
backend()[ii] += alpha * xx.backend()[ii];
} // ... axpy(...)
bool has_equal_shape(const ThisType& other) const
{
return size() == other.size();
}