diff --git a/.gitsuper b/.gitsuper index c7a7458df2f44a6e0ee901a2fe98a204f92380b4..955bbeae166fef98ee7a12c223aa4fd3d5e949b2 100644 --- a/.gitsuper +++ b/.gitsuper @@ -1,26 +1,6 @@ [supermodule] remote = git@github.com:dune-community/dune-gdt-super.git -status = 1a3bcab04b011a5d6e44f9983cae6ff89fa695e8 bin (heads/master) - 20a673b9dad7e2e25bd97defa8849debb59d247c config.opts (heads/master) - 8f2c5aba441417bf2c42f22272f538c68a89cc4a dune-alugrid (remotes/origin/releases/2.5) - 707acf201d5a754c80f87cc4d71aa36bf29a6e3f dune-common (v2.5.1-9-g707acf20) - +77d61b26ac2fd2dc04d3a4332d8703e27ac81617 dune-gdt (heads/releases/18.10) - 390a2c503783bbed778a8ff610f8c5ca09c238d0 dune-geometry (v2.5.1-5-g390a2c5) - d7b20bbc5f6fdcfc312beb0ea5d16d39ea26904e dune-grid (v2.5.1-2-gd7b20bbc5) - 9e29a333e8af02382d80b95335a784d5ce1ea2c8 dune-grid-glue (v2.4.0-70-g9e29a33) - 63df56a54f81eda308233a683eb329e77e69f0a9 dune-istl (v2.5.1rc1) - 0d757d65e5d57134a7ecf304e35d063f4ccc7116 dune-localfunctions (v2.5.1rc1) - 8a69fc68165780921bbba77da338b6932daf983c dune-pybindxi (v2.2.1-16-g8a69fc6) - 741e4f8e53bdd3e1b6e19d84eb22b6e3dc48526c dune-python (remotes/origin/releases/2.5) - 26cc8cb4161a3a51002ab2a81b8c81d2c951ee79 dune-testtools (remotes/origin/p/renemilk/testname_listing_hack_no-skiptest) - 0a74e7dd0b2115778a5d490dab08a2ed07fcaa1e dune-uggrid (v2.5.2) - effefc7695eba0c0ca94fff0f93026b86501027e dune-xt-common (heads/master) - +3ab45d16f85e6728945587d325c26fe99a5e10f5 dune-xt-data (heads/dailywork_tleibner) - 11dd720c49554afc5049909dda427bc544d0c6fe dune-xt-functions (heads/master) - +f2c9ac7a62fa71121e9fcd8879d3edb4e5453ebc dune-xt-grid (heads/dailywork_tleibner) - +521222730e5b8ccd197e0dbc65c735ba3e8c7850 dune-xt-la (heads/dailywork_tleibner) - 09d0378f616b94d68bcdd9fc6114813181849ec0 scripts (heads/master) -commit = 61c5eaaa515d6b6b82697589bcca874e709e5928 +commit = 5ddf130cadaff3379b27a6fa8f82a47f7a594e9f [submodule.bin] remote = git@github.com:dune-community/local-bin.git @@ -30,92 +10,87 @@ commit = 1a3bcab04b011a5d6e44f9983cae6ff89fa695e8 [submodule.config.opts] remote = git@github.com:dune-community/config.opts.git status = -commit = 20a673b9dad7e2e25bd97defa8849debb59d247c +commit = 5147d438044a772a07fd89ff142d861cfc82212e [submodule.dune-alugrid] remote = https://github.com/dune-mirrors/dune-alugrid.git status = -commit = 8f2c5aba441417bf2c42f22272f538c68a89cc4a +commit = f308c6637edd65dcb83c4c1a46feaf05b958130e [submodule.dune-common] remote = git@github.com:dune-community/dune-common.git status = -commit = 707acf201d5a754c80f87cc4d71aa36bf29a6e3f +commit = 76d7f0c9886a061571cb8dc66dd45a4ef86e7a58 [submodule.dune-gdt] remote = git@github.com:dune-community/dune-gdt.git status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) -commit = 77d61b26ac2fd2dc04d3a4332d8703e27ac81617 +commit = 3f67b50e93884a65644086e3a2d7373d7e98942c [submodule.dune-geometry] remote = git@github.com:dune-community/dune-geometry.git status = -commit = 390a2c503783bbed778a8ff610f8c5ca09c238d0 +commit = 5235397bc16d24c759a1672fed7b8cfde4852e52 [submodule.dune-grid] remote = git@github.com:dune-community/dune-grid.git status = -commit = d7b20bbc5f6fdcfc312beb0ea5d16d39ea26904e +commit = af5766f0df47e3d0b62ea486efb9cdbf8e1cfc52 [submodule.dune-grid-glue] remote = https://github.com/dune-mirrors/dune-grid-glue.git status = -commit = 9e29a333e8af02382d80b95335a784d5ce1ea2c8 +commit = 1369ae9329d0928480d6b18ed772fc77e1abf752 [submodule.dune-istl] remote = https://github.com/dune-mirrors/dune-istl.git status = -commit = 63df56a54f81eda308233a683eb329e77e69f0a9 +commit = ef68ae0ec40f9d369e4ea9b31e560af6af545bf6 [submodule.dune-localfunctions] remote = https://github.com/dune-mirrors/dune-localfunctions.git status = -commit = 0d757d65e5d57134a7ecf304e35d063f4ccc7116 +commit = 5a1f77d7a0a41c2d065b29f00dda0871ec70337b [submodule.dune-pybindxi] remote = git@github.com:dune-community/dune-pybindxi.git status = a18500d497d2ffa2f627bc6e7da0aa1169b81ea3 .vcsetup (a18500d) -commit = 8a69fc68165780921bbba77da338b6932daf983c - -[submodule.dune-python] -remote = https://github.com/dune-mirrors/dune-python.git -status = -commit = 741e4f8e53bdd3e1b6e19d84eb22b6e3dc48526c +commit = 6ae2466a8dba39bfa760fd99ce775450c704b03d [submodule.dune-testtools] remote = https://github.com/dune-mirrors/dune-testtools.git status = -commit = 26cc8cb4161a3a51002ab2a81b8c81d2c951ee79 +commit = 58bd932e2311a288e0163d041f836b50f19111cb [submodule.dune-uggrid] remote = https://github.com/dune-mirrors/dune-uggrid.git status = -commit = 0a74e7dd0b2115778a5d490dab08a2ed07fcaa1e +commit = 07f9700459c616186737a9a34277f2edee76f475 [submodule.dune-xt-common] remote = git@github.com:dune-community/dune-xt-common.git status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) -commit = effefc7695eba0c0ca94fff0f93026b86501027e +commit = b399b2b9fea3d23bec2762db2d2560b00b81077a [submodule.dune-xt-data] remote = git@github.com:dune-community/dune-xt-data status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) -commit = 3ab45d16f85e6728945587d325c26fe99a5e10f5 +commit = 19d69fe20c7dc539341d84ac87c4cad0cbe15d95 [submodule.dune-xt-functions] remote = git@github.com:dune-community/dune-xt-functions.git status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) -commit = 11dd720c49554afc5049909dda427bc544d0c6fe +commit = 2b1d09ae365d09b71ece0809f53a653c21d702a8 [submodule.dune-xt-grid] remote = git@github.com:dune-community/dune-xt-grid.git status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) -commit = f2c9ac7a62fa71121e9fcd8879d3edb4e5453ebc +commit = ec0722213eb73e8b06f1a220c2d3b890ce7f8b6d [submodule.dune-xt-la] remote = git@github.com:dune-community/dune-xt-la.git status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) -commit = 521222730e5b8ccd197e0dbc65c735ba3e8c7850 +commit = 8418afaa81ce88b0122af7857e8198b6d079f0ee [submodule.scripts] remote = https://github.com/wwu-numerik/scripts.git diff --git a/.travis.script.bash b/.travis.script.bash index a9484b0d6e7c6c474922e98cf6f50dd7311a1cbc..2d6331f3f9ec6c8b17f8921e2e1076744e9b05b1 100755 --- a/.travis.script.bash +++ b/.travis.script.bash @@ -28,9 +28,6 @@ else ${SRC_DCTRL} ${BLD} --only=${MY_MODULE} bexec ${CTEST} -L "^builder_${TESTS}$" fi -${SRC_DCTRL} ${BLD} --only=${MY_MODULE} bexec ${BUILD_CMD} install | grep -v "Installing" -${SRC_DCTRL} ${BLD} --only=${MY_MODULE} bexec ${BUILD_CMD} package_source - # clang coverage currently disabled for being to mem hungry if [[ ${CC} == *"clang"* ]] ; then exit 0 @@ -38,7 +35,7 @@ fi pushd ${DUNE_BUILD_DIR}/${MY_MODULE} COVERAGE_INFO=${PWD}/coverage.info -lcov --directory . --output-file ${COVERAGE_INFO} -c +lcov --directory . --output-file ${COVERAGE_INFO} --ignore-errors gcov -c for d in "dune-common" "dune-pybindxi" "dune-geometry" "dune-istl" "dune-grid" "dune-alugrid" "dune-uggrid" "dune-localfunctions" ; do lcov --directory . --output-file ${COVERAGE_INFO} -r ${COVERAGE_INFO} "${SUPERDIR}/${d}/*" done diff --git a/dune/xt/la/container/common/vector/dense.hh b/dune/xt/la/container/common/vector/dense.hh index 0f4a6ce6e19da6c3eb27dd6a6e9436d8847655e1..3af1d73f2e560681fbd6a59e8957e25aa4b48ebf 100644 --- a/dune/xt/la/container/common/vector/dense.hh +++ b/dune/xt/la/container/common/vector/dense.hh @@ -225,6 +225,11 @@ public: return backend_->size(); } + inline void resize(const size_t new_size) + { + backend_->resize(new_size); + } + void add_to_entry(const size_t ii, const ScalarType& value) { internal::LockGuard DUNE_UNUSED(lock)(*mutexes_, ii, size()); diff --git a/dune/xt/la/container/common/vector/sparse.hh b/dune/xt/la/container/common/vector/sparse.hh index 9c29f05ba695865b6cee2c1f43576e9338770e41..736e23637970509c58ba023e991b9c07f1827c26 100644 --- a/dune/xt/la/container/common/vector/sparse.hh +++ b/dune/xt/la/container/common/vector/sparse.hh @@ -255,6 +255,23 @@ public: return size_; } + inline void resize(const size_t new_size) + { + if (new_size != size()) { + EntriesVectorType new_entries; + IndicesVectorType new_indices; + for (size_t ii = 0; ii < indices_->size(); ++ii) { + if ((*indices_)[ii] < new_size) { + new_entries.push_back((*entries_)[ii]); + new_indices.push_back((*indices_)[ii]); + } + } + *entries_ = new_entries; + *indices_ = new_indices; + size_ = new_size; + } + } + void add_to_entry(const size_t ii, const ScalarType& value) { internal::LockGuard DUNE_UNUSED(lock)(*mutexes_, ii, size()); diff --git a/dune/xt/la/container/container-interface.hh b/dune/xt/la/container/container-interface.hh index 0313c45f7a30cee60fa79cb7e793e4b3de60772d..191e5679fcf422b834811e69c2b0b01b7cedff34 100644 --- a/dune/xt/la/container/container-interface.hh +++ b/dune/xt/la/container/container-interface.hh @@ -23,66 +23,14 @@ #include <dune/xt/common/crtp.hh> #include <dune/xt/common/math.hh> #include <dune/xt/common/exceptions.hh> -#include <dune/xt/common/type_traits.hh> +#include <dune/xt/la/type_traits.hh> namespace Dune { namespace XT { namespace LA { - - -enum class Backends -{ - common_dense, - common_sparse, - istl_dense, - istl_sparse, - eigen_dense, - eigen_sparse, - none -}; // enum class Backends - -static constexpr Backends default_backend = -#if HAVE_EIGEN - Backends::eigen_sparse; -#else - Backends::istl_sparse; -#endif - -static constexpr Backends default_sparse_backend = -#if HAVE_EIGEN - Backends::eigen_sparse; -#else - Backends::istl_sparse; -#endif - -static constexpr Backends default_dense_backend = -#if HAVE_EIGEN - Backends::eigen_dense; -#else - Backends::common_dense; -#endif - - namespace internal { -/** - * \brief Tries a boost::numeric_cast and throws an Exceptions::wrong_input_given on failure. - * - * This can be used in the ctor initializer list. - */ -template <class Out, class In> -static Out boost_numeric_cast(const In& in) -{ - try { - return boost::numeric_cast<Out>(in); - } catch (boost::bad_numeric_cast& ee) { - DUNE_THROW(Common::Exceptions::wrong_input_given, - "There was an error in boost converting '" << in << "' to '" << Common::Typename<Out>::value() << "': " - << ee.what()); - } -} // ... boost_numeric_cast(...) - struct VectorLockGuard { VectorLockGuard(std::vector<std::mutex>& mutexes) @@ -100,6 +48,7 @@ struct VectorLockGuard std::vector<std::mutex>& mutexes_; }; // VectorLockGuard + struct LockGuard { LockGuard(std::vector<std::mutex>& mutexes, const size_t ii, const size_t container_size) @@ -230,6 +179,14 @@ public: ret.scal(alpha); return ret; } + + virtual derived_type operator/(const ScalarType& alpha) const + { + auto ret = this->copy(); + ret.scal(1. / alpha); + return ret; + } + /// \} }; // class ContainerInterface diff --git a/dune/xt/la/container/conversion.hh b/dune/xt/la/container/conversion.hh index 35a5507fb5aa4656a106c04f3aea7bd8b1160c12..f598ce759bef0395ab5b7506542d4131fc008f39 100644 --- a/dune/xt/la/container/conversion.hh +++ b/dune/xt/la/container/conversion.hh @@ -14,6 +14,7 @@ #include <dune/xt/common/matrix.hh> #include <dune/xt/common/numeric_cast.hh> +#include <dune/xt/common/vector.hh> #include <dune/xt/common/type_traits.hh> #include <dune/xt/la/container/matrix-interface.hh> @@ -23,7 +24,19 @@ namespace Dune { namespace XT { namespace LA { + +// "pull in" the vector variant from Common, cannot be done with using (would pull the matrix one, too) +template <class RangeType, class SourceType> +typename std::enable_if<Common::is_vector<SourceType>::value && Common::is_vector<RangeType>::value, RangeType>::type +convert_to(const SourceType& source) +{ + return Common::convert_to<RangeType>(source); +} + + /** + Matrix variants + | Source | Range | convert_to | |----------------|----------------|------------| | Common, not LA | Common or LA | 1st | @@ -31,6 +44,7 @@ namespace LA { | LA, not Common | LA, not Common | 3rd | */ + //! 1st convert_to template <class RangeType, class SourceType> typename std::enable_if<Common::is_matrix<SourceType>::value && !is_matrix<SourceType>::value diff --git a/dune/xt/la/container/eigen/base.hh b/dune/xt/la/container/eigen/base.hh index 85a47585d3bd4b3bda821a297dc048cd0508943b..720926af8db7f6ced217b36a9efb2339d93d2f76 100644 --- a/dune/xt/la/container/eigen/base.hh +++ b/dune/xt/la/container/eigen/base.hh @@ -48,8 +48,6 @@ class EigenRowMajorSparseMatrix; #if HAVE_EIGEN -template <class Traits, class ScalarImp> -class EigenBaseVector; /** * \brief Base class for all eigen implementations of VectorInterface. diff --git a/dune/xt/la/container/eigen/dense.hh b/dune/xt/la/container/eigen/dense.hh index a63ccf516a45485a1e87947ae656287b7081e464..5125b4e43e039367b103f441c7b57e2f7c53c1c0 100644 --- a/dune/xt/la/container/eigen/dense.hh +++ b/dune/xt/la/container/eigen/dense.hh @@ -33,8 +33,9 @@ #include <dune/common/ftraits.hh> #include <dune/common/unused.hh> -#include <dune/xt/common/exceptions.hh> #include <dune/xt/common/crtp.hh> +#include <dune/xt/common/exceptions.hh> +#include <dune/xt/common/numeric_cast.hh> #include "dune/xt/la/container/interfaces.hh" #include "dune/xt/la/container/pattern.hh" @@ -144,7 +145,7 @@ public: explicit EigenDenseVector(const std::vector<ScalarType>& other, const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(internal::boost_numeric_cast<EIGEN_size_t>(other.size())); + backend_ = std::make_shared<BackendType>(Common::numeric_cast<EIGEN_size_t>(other.size())); for (size_t ii = 0; ii < other.size(); ++ii) backend_->operator[](ii) = other[ii]; } @@ -152,7 +153,7 @@ public: explicit EigenDenseVector(const std::initializer_list<ScalarType>& other, const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(internal::boost_numeric_cast<EIGEN_size_t>(other.size())); + backend_ = std::make_shared<BackendType>(Common::numeric_cast<EIGEN_size_t>(other.size())); size_t ii = 0; for (auto element : other) backend_->operator[](ii++) = element; @@ -197,6 +198,22 @@ public: using InterfaceType::operator*; using BaseType::backend; + /// \name Required by VectorInterface + /// \{ + + inline void resize(const size_t new_size) + { + // Eigens resize loses all values, so we have to store them before... + auto stored_size = new_size > this->size() ? this->size() : new_size; + std::vector<ScalarType> old_values(stored_size); + for (size_t ii = 0; ii < stored_size; ++ii) + old_values[ii] = this->get_entry(ii); + backend_->resize(new_size, 1); + for (size_t ii = 0; ii < stored_size; ++ii) + this->set_entry(ii, old_values[ii]); + } + + /// \} /// \name Required by ProvidesDataAccess. /// \{ @@ -247,7 +264,7 @@ public: EigenMappedDenseVector(ScalarType* data, size_t data_size, const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(data, internal::boost_numeric_cast<EIGEN_size_t>(data_size)); + backend_ = std::make_shared<BackendType>(data, Common::numeric_cast<EIGEN_size_t>(data_size)); } /** @@ -258,7 +275,7 @@ public: const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(new ScalarType[ss], internal::boost_numeric_cast<EIGEN_size_t>(ss)); + backend_ = std::make_shared<BackendType>(new ScalarType[ss], Common::numeric_cast<EIGEN_size_t>(ss)); backend_->setOnes(); backend_->operator*=(value); } @@ -266,8 +283,8 @@ public: explicit EigenMappedDenseVector(const std::vector<ScalarType>& other, const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(new ScalarType[other.size()], - internal::boost_numeric_cast<EIGEN_size_t>(other.size())); + backend_ = + std::make_shared<BackendType>(new ScalarType[other.size()], Common::numeric_cast<EIGEN_size_t>(other.size())); for (size_t ii = 0; ii < other.size(); ++ii) (*backend_)[ii] = other[ii]; } @@ -275,8 +292,8 @@ public: explicit EigenMappedDenseVector(const std::initializer_list<ScalarType>& other, const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(new ScalarType[other.size()], - internal::boost_numeric_cast<EIGEN_size_t>(other.size())); + backend_ = + std::make_shared<BackendType>(new ScalarType[other.size()], Common::numeric_cast<EIGEN_size_t>(other.size())); size_t ii = 0; for (auto element : other) (*backend_)[ii++] = element; @@ -285,8 +302,8 @@ public: EigenMappedDenseVector(const ThisType& other) : BaseType(other) { - backend_ = std::make_shared<BackendType>(new ScalarType[other.size()], - internal::boost_numeric_cast<EIGEN_size_t>(other.size())); + backend_ = + std::make_shared<BackendType>(new ScalarType[other.size()], Common::numeric_cast<EIGEN_size_t>(other.size())); backend_->operator=(other.backend()); } @@ -296,8 +313,8 @@ public: const size_t num_mutexes = 1) : BaseType(num_mutexes) { - backend_ = std::make_shared<BackendType>(new ScalarType[other.size()], - internal::boost_numeric_cast<EIGEN_size_t>(other.size())); + backend_ = + std::make_shared<BackendType>(new ScalarType[other.size()], Common::numeric_cast<EIGEN_size_t>(other.size())); backend_->operator=(other); } @@ -331,6 +348,12 @@ public: return *this; } + inline void resize(const size_t new_size) + { + if (new_size != this->size()) + DUNE_THROW(XT::Common::Exceptions::you_are_using_this_wrong, "This does not make sense for mapped memory!"); + } + using InterfaceType::add; using InterfaceType::sub; using InterfaceType::operator+; @@ -387,8 +410,7 @@ public: const size_t cc, const SparsityPatternDefault& /*pattern*/, const size_t num_mutexes = 1) - : backend_(new BackendType(internal::boost_numeric_cast<EIGEN_size_t>(rr), - internal::boost_numeric_cast<EIGEN_size_t>(cc))) + : backend_(new BackendType(Common::numeric_cast<EIGEN_size_t>(rr), Common::numeric_cast<EIGEN_size_t>(cc))) , mutexes_(std::make_unique<MutexesType>(num_mutexes)) { backend_->setZero(); diff --git a/dune/xt/la/container/eigen/sparse.hh b/dune/xt/la/container/eigen/sparse.hh index 2bf349f742652f71b1491697ca109c7e9513031e..d1680c38e9baf7afce389e55038ca2aae60d325d 100644 --- a/dune/xt/la/container/eigen/sparse.hh +++ b/dune/xt/la/container/eigen/sparse.hh @@ -31,10 +31,11 @@ #include <dune/common/ftraits.hh> #include <dune/common/unused.hh> -#include <dune/xt/common/math.hh> -#include <dune/xt/common/exceptions.hh> #include <dune/xt/common/crtp.hh> +#include <dune/xt/common/exceptions.hh> #include <dune/xt/common/float_cmp.hh> +#include <dune/xt/common/math.hh> +#include <dune/xt/common/numeric_cast.hh> #include "dune/xt/la/container/interfaces.hh" #include "dune/xt/la/container/pattern.hh" @@ -107,8 +108,8 @@ public: const size_t cc, const SparsityPatternDefault& pattern_in, const size_t num_mutexes = 1) - : backend_(std::make_shared<BackendType>(internal::boost_numeric_cast<EIGEN_size_t>(rr), - internal::boost_numeric_cast<EIGEN_size_t>(cc))) + : backend_( + std::make_shared<BackendType>(Common::numeric_cast<EIGEN_size_t>(rr), Common::numeric_cast<EIGEN_size_t>(cc))) , mutexes_(std::make_unique<MutexesType>(num_mutexes)) { if (rr > 0 && cc > 0) { @@ -118,7 +119,7 @@ public: << rr << ")!"); for (size_t row = 0; row < size_t(pattern_in.size()); ++row) { - backend_->startVec(internal::boost_numeric_cast<EIGEN_size_t>(row)); + backend_->startVec(Common::numeric_cast<EIGEN_size_t>(row)); const auto& columns = pattern_in.inner(row); for (auto& column : columns) { #ifndef NDEBUG @@ -128,12 +129,12 @@ public: << cc << ")!"); #endif // NDEBUG - backend_->insertBackByOuterInner(internal::boost_numeric_cast<EIGEN_size_t>(row), - internal::boost_numeric_cast<EIGEN_size_t>(column)); + backend_->insertBackByOuterInner(Common::numeric_cast<EIGEN_size_t>(row), + Common::numeric_cast<EIGEN_size_t>(column)); } // create entry (insertBackByOuterInner() can not handle empty rows) if (columns.size() == 0) - backend_->insertBackByOuterInner(internal::boost_numeric_cast<EIGEN_size_t>(row), 0); + backend_->insertBackByOuterInner(Common::numeric_cast<EIGEN_size_t>(row), 0); } backend_->finalize(); backend_->makeCompressed(); @@ -305,23 +306,20 @@ public: { internal::LockGuard DUNE_UNUSED(lock)(*mutexes_, ii, rows()); assert(these_are_valid_indices(ii, jj)); - backend().coeffRef(internal::boost_numeric_cast<EIGEN_size_t>(ii), - internal::boost_numeric_cast<EIGEN_size_t>(jj)) += value; + backend().coeffRef(Common::numeric_cast<EIGEN_size_t>(ii), Common::numeric_cast<EIGEN_size_t>(jj)) += value; } void set_entry(const size_t ii, const size_t jj, const ScalarType& value) { assert(these_are_valid_indices(ii, jj)); - backend().coeffRef(internal::boost_numeric_cast<EIGEN_size_t>(ii), internal::boost_numeric_cast<EIGEN_size_t>(jj)) = - value; + backend().coeffRef(Common::numeric_cast<EIGEN_size_t>(ii), Common::numeric_cast<EIGEN_size_t>(jj)) = value; } ScalarType get_entry(const size_t ii, const size_t jj) const { assert(ii < rows()); assert(jj < cols()); - return backend().coeff(internal::boost_numeric_cast<EIGEN_size_t>(ii), - internal::boost_numeric_cast<EIGEN_size_t>(jj)); + return backend().coeff(Common::numeric_cast<EIGEN_size_t>(ii), Common::numeric_cast<EIGEN_size_t>(jj)); } void clear_row(const size_t ii) @@ -329,7 +327,7 @@ public: if (ii >= rows()) DUNE_THROW(Common::Exceptions::index_out_of_range, "Given ii (" << ii << ") is larger than the rows of this (" << rows() << ")!"); - backend().row(internal::boost_numeric_cast<EIGEN_size_t>(ii)) *= ScalarType(0); + backend().row(Common::numeric_cast<EIGEN_size_t>(ii)) *= ScalarType(0); } void clear_col(const size_t jj) @@ -337,14 +335,13 @@ public: if (jj >= cols()) DUNE_THROW(Common::Exceptions::index_out_of_range, "Given jj (" << jj << ") is larger than the cols of this (" << cols() << ")!"); - for (size_t row = 0; internal::boost_numeric_cast<EIGEN_size_t>(row) < backend().outerSize(); ++row) { - for (typename BackendType::InnerIterator row_it(backend(), internal::boost_numeric_cast<EIGEN_size_t>(row)); - row_it; + for (size_t row = 0; Common::numeric_cast<EIGEN_size_t>(row) < backend().outerSize(); ++row) { + for (typename BackendType::InnerIterator row_it(backend(), Common::numeric_cast<EIGEN_size_t>(row)); row_it; ++row_it) { const size_t col = row_it.col(); if (col == jj) { - backend().coeffRef(internal::boost_numeric_cast<EIGEN_size_t>(row), - internal::boost_numeric_cast<EIGEN_size_t>(jj)) = ScalarType(0); + backend().coeffRef(Common::numeric_cast<EIGEN_size_t>(row), Common::numeric_cast<EIGEN_size_t>(jj)) = + ScalarType(0); break; } else if (col > jj) break; @@ -363,9 +360,8 @@ public: if (!these_are_valid_indices(ii, ii)) DUNE_THROW(Common::Exceptions::index_out_of_range, "Diagonal entry (" << ii << ", " << ii << ") is not contained in the sparsity pattern!"); - backend().row(internal::boost_numeric_cast<EIGEN_size_t>(ii)) *= ScalarType(0); - backend().coeffRef(internal::boost_numeric_cast<EIGEN_size_t>(ii), internal::boost_numeric_cast<EIGEN_size_t>(ii)) = - ScalarType(1); + backend().row(Common::numeric_cast<EIGEN_size_t>(ii)) *= ScalarType(0); + backend().coeffRef(Common::numeric_cast<EIGEN_size_t>(ii), Common::numeric_cast<EIGEN_size_t>(ii)) = ScalarType(1); } // ... unit_row(...) void unit_col(const size_t jj) @@ -376,18 +372,17 @@ public: if (jj >= rows()) DUNE_THROW(Common::Exceptions::index_out_of_range, "Given jj (" << jj << ") is larger than the rows of this (" << rows() << ")!"); - for (size_t row = 0; internal::boost_numeric_cast<EIGEN_size_t>(row) < backend().outerSize(); ++row) { - for (typename BackendType::InnerIterator row_it(backend(), internal::boost_numeric_cast<EIGEN_size_t>(row)); - row_it; + for (size_t row = 0; Common::numeric_cast<EIGEN_size_t>(row) < backend().outerSize(); ++row) { + for (typename BackendType::InnerIterator row_it(backend(), Common::numeric_cast<EIGEN_size_t>(row)); row_it; ++row_it) { const size_t col = row_it.col(); if (col == jj) { if (col == row) - backend().coeffRef(internal::boost_numeric_cast<EIGEN_size_t>(row), - internal::boost_numeric_cast<EIGEN_size_t>(col)) = ScalarType(1); + backend().coeffRef(Common::numeric_cast<EIGEN_size_t>(row), Common::numeric_cast<EIGEN_size_t>(col)) = + ScalarType(1); else - backend().coeffRef(internal::boost_numeric_cast<EIGEN_size_t>(row), - internal::boost_numeric_cast<EIGEN_size_t>(jj)) = ScalarType(0); + backend().coeffRef(Common::numeric_cast<EIGEN_size_t>(row), Common::numeric_cast<EIGEN_size_t>(jj)) = + ScalarType(0); break; } else if (col > jj) break; @@ -494,9 +489,8 @@ private: return false; if (jj >= cols()) return false; - for (size_t row = ii; internal::boost_numeric_cast<EIGEN_size_t>(row) < backend().outerSize(); ++row) { - for (typename BackendType::InnerIterator row_it(backend(), internal::boost_numeric_cast<EIGEN_size_t>(row)); - row_it; + for (size_t row = ii; Common::numeric_cast<EIGEN_size_t>(row) < backend().outerSize(); ++row) { + for (typename BackendType::InnerIterator row_it(backend(), Common::numeric_cast<EIGEN_size_t>(row)); row_it; ++row_it) { const size_t col = row_it.col(); if ((ii == row) && (jj == col)) diff --git a/dune/xt/la/container/istl.hh b/dune/xt/la/container/istl.hh index 80e1cf3076d79288a06bc0e97ba6a1779ab14501..0416e93cbd6bee97b8b7bd47e45ae6ee71057a2d 100644 --- a/dune/xt/la/container/istl.hh +++ b/dune/xt/la/container/istl.hh @@ -252,6 +252,11 @@ public: return backend_->N(); } + inline void resize(const size_t new_size) + { + backend_->resize(new_size); + } + void add_to_entry(const size_t ii, const ScalarType& value) { internal::LockGuard DUNE_UNUSED(lock)(*mutexes_, ii, size()); @@ -357,6 +362,8 @@ private: /** * \brief A sparse matrix implementation of the MatrixInterface using the Dune::BCRSMatrix from dune-istl. + * + * \todo Rename to IstlSparseMatrix */ template <class ScalarImp = double> class IstlRowMajorSparseMatrix : public MatrixInterface<internal::IstlRowMajorSparseMatrixTraits<ScalarImp>, ScalarImp>, diff --git a/dune/xt/la/container/matrix-interface.hh b/dune/xt/la/container/matrix-interface.hh index 301b28d10f11c86c4aefa6b6196a0073da482158..b35e38f073d9ba3d6e25258db92d944a31b8c530 100644 --- a/dune/xt/la/container/matrix-interface.hh +++ b/dune/xt/la/container/matrix-interface.hh @@ -159,7 +159,7 @@ public: typename XX::derived_type operator*(const VectorInterface<XX, ScalarType>& xx) const { typename XX::derived_type yy(rows()); - mv(xx.as_imp(xx), yy); + mv(xx.as_imp(), yy); return yy; } diff --git a/dune/xt/la/container/vector-array/list.hh b/dune/xt/la/container/vector-array/list.hh index 7fd817535a8c645baab2f83fefd736cbf3ec1bc9..f8a897cda83b52cbfc74c12003d2b8720afb8c9f 100644 --- a/dune/xt/la/container/vector-array/list.hh +++ b/dune/xt/la/container/vector-array/list.hh @@ -12,7 +12,10 @@ #include <vector> -#include "interface.hh" +#include <dune/xt/common/parameter.hh> +#include <dune/xt/la/exceptions.hh> + +//#include "interface.hh" namespace Dune { namespace XT { @@ -24,6 +27,7 @@ template <class Vector> class ListVectorArray; +#if 0 namespace internal { @@ -41,32 +45,125 @@ public: } // namespace internal +#endif // 0 /** - * \brief Implementation of VectorArrayInterface as an array of vectors derived from XT::LA::VectorInterface + * \brief Implementation of VectorArrayInterface as an array of vectors */ template <class Vector> -class ListVectorArray : public VectorArrayInterface<internal::ListVectorArrayTraits<Vector>> +class ListVectorArray /*: public VectorArrayInterface<internal::ListVectorArrayTraits<Vector>>*/ { - using BaseType = VectorArrayInterface<internal::ListVectorArrayTraits<Vector>>; + // using BaseType = VectorArrayInterface<internal::ListVectorArrayTraits<Vector>>; + using ThisType = ListVectorArray<Vector>; public: - using Traits = typename BaseType::Traits; - using derived_type = typename BaseType::derived_type; + // using Traits = typename BaseType::Traits; + // using derived_type = typename BaseType::derived_type; + + // using typename BaseType::VectorType; + // using typename BaseType::const_iterator; + // using typename BaseType::iterator; + + using VectorType = Vector; - using typename BaseType::VectorType; - using typename BaseType::const_iterator; - using typename BaseType::iterator; +private: + class AnnotatedVector + { + public: + AnnotatedVector(std::vector<Vector>& vectors, std::vector<Common::Parameter>& notes, const size_t ii) + : vectors_(vectors) + , notes_(notes) + , ii_(ii) + { + } + + const VectorType& vector() const + { + DUNE_THROW_IF(ii_ >= vectors_.size(), + InvalidStateException, + "This should not happen: ii_ = " << ii_ << "\n vectors_.size() = " << vectors_.size()); + return vectors_[ii_]; + } + + VectorType& vector() + { + DUNE_THROW_IF(ii_ >= vectors_.size(), + InvalidStateException, + "This should not happen: ii_ = " << ii_ << "\n vectors_.size() = " << vectors_.size()); + return vectors_[ii_]; + } + + const Common::Parameter& note() const + { + DUNE_THROW_IF(ii_ >= vectors_.size(), + InvalidStateException, + "This should not happen: ii_ = " << ii_ << "\n notes_.size() = " << notes_.size()); + return notes_[ii_]; + } + + Common::Parameter& note() + { + DUNE_THROW_IF(ii_ >= vectors_.size(), + InvalidStateException, + "This should not happen: ii_ = " << ii_ << "\n notes_.size() = " << notes_.size()); + return notes_[ii_]; + } + + private: + std::vector<Vector>& vectors_; + std::vector<Common::Parameter>& notes_; + const size_t ii_; + }; // class AnnotatedVector + +public: + using iterator = typename std::vector<AnnotatedVector>::iterator; + using const_iterator = typename std::vector<AnnotatedVector>::const_iterator; + using reverse_iterator = typename std::vector<AnnotatedVector>::reverse_iterator; + using const_reverse_iterator = typename std::vector<AnnotatedVector>::const_reverse_iterator; + using reference = typename std::vector<AnnotatedVector>::reference; + using const_reference = typename std::vector<AnnotatedVector>::const_reference; ListVectorArray(const size_t dm, const size_t lngth = 0, const size_t resrv = 0) : dim_(dm) - , array_(lngth) + , len_(lngth) + , vectors_() + , notes_() + , pairs_() { - for (auto& v : array_) - v = VectorType(dm, 0.); - array_.reserve(resrv); - } + vectors_.reserve(resrv); + notes_.reserve(resrv); + pairs_.reserve(resrv); + for (size_t ii = 0; ii < len_; ++ii) { + vectors_.emplace_back(dim_, 0); + notes_.emplace_back(); + pairs_.emplace_back(vectors_, notes_, ii); + } + } // ListVectorArray(...) + + ListVectorArray(const ThisType& other) + : dim_(other.dim_) + , len_(other.len_) + , vectors_(other.vectors_) + , notes_(other.notes_) + , pairs_() + { + pairs_.reserve(len_); + for (size_t ii = 0; ii < len_; ++ii) + pairs_.emplace_back(vectors_, notes_, ii); + } // ListVectorArray(...) + + ListVectorArray(ThisType&& source) + : dim_(source.dim_) + , len_(source.len_) + , vectors_(std::move(source.vectors_)) + , notes_(std::move(source.notes_)) + , pairs_() + { + pairs_.reserve(len_); + for (size_t ii = 0; ii < len_; ++ii) + pairs_.emplace_back(vectors_, notes_, ii); + } // ListVectorArray(...) size_t dim() const { @@ -75,57 +172,140 @@ public: size_t length() const { - return array_.size(); + return len_; + } + + const std::vector<VectorType>& vectors() const + { + return vectors_; + } + + const std::vector<Common::Parameter>& notes() const + { + return notes_; } void reserve(const size_t len) { - array_.reserve(len); + vectors_.reserve(len); + notes_.reserve(len); + pairs_.reserve(len); } - void append(const VectorType& vec) + void append(const VectorType& vec, const Common::Parameter& note = {}) { - array_.emplace_back(vec); + vectors_.emplace_back(vec); + notes_.emplace_back(note); + pairs_.emplace_back(vectors_, notes_, len_); + ++len_; } - void append(VectorType&& vec) + void append(VectorType&& vec, const Common::Parameter& note = {}) { - array_.emplace_back(std::move(vec)); + vectors_.emplace_back(std::move(vec)); + notes_.emplace_back(note); + pairs_.emplace_back(vectors_, notes_, len_); + ++len_; } - const VectorType& operator[](const size_t ii) const + const AnnotatedVector& operator[](const size_t ii) const { - return array_[ii]; + DUNE_THROW_IF(ii >= len_, Common::Exceptions::index_out_of_range, "ii = " << ii << "\n len_ = " << len_); + return pairs_[ii]; } - VectorType& operator[](const size_t ii) + AnnotatedVector& operator[](const size_t ii) { - return array_[ii]; + DUNE_THROW_IF(ii >= len_, Common::Exceptions::index_out_of_range, "ii = " << ii << "\n len_ = " << len_); + return pairs_[ii]; } - const_iterator begin() const + reference front() + { + return pairs_.front(); + } + + const_reference front() const + { + return pairs_.front(); + } + + reference back() { - return array_.begin(); + return pairs_.back(); + } + + const_reference back() const + { + return pairs_.back(); } iterator begin() { - return array_.begin(); + return pairs_.begin(); } - const_iterator end() const + const_iterator begin() const { - return array_.end(); + return pairs_.begin(); + } + + const_iterator cbegin() const + { + return pairs_.cbegin(); } iterator end() { - return array_.end(); + return pairs_.end(); + } + + const_iterator end() const + { + return pairs_.end(); + } + + const_iterator cend() const + { + return pairs_.cend(); + } + + reverse_iterator rbegin() + { + return pairs_.rbegin(); + } + + const_reverse_iterator rbegin() const + { + return pairs_.rbegin(); + } + + const_reverse_iterator crbegin() const + { + return pairs_.crbegin(); + } + + reverse_iterator rend() + { + return pairs_.rend(); + } + + const_reverse_iterator rend() const + { + return pairs_.end(); + } + + const_reverse_iterator crend() const + { + return pairs_.crend(); } private: const size_t dim_; - std::vector<Vector> array_; + size_t len_; + std::vector<Vector> vectors_; + std::vector<Common::Parameter> notes_; + std::vector<AnnotatedVector> pairs_; }; // class ListVectorArray diff --git a/dune/xt/la/container/vector-interface.hh b/dune/xt/la/container/vector-interface.hh index a32d0408a51da0a3fdf951fd3e121fbc2af1e646..00c9aff9d7a4d5a437ec8a6804208f757412fd1f 100644 --- a/dune/xt/la/container/vector-interface.hh +++ b/dune/xt/la/container/vector-interface.hh @@ -76,8 +76,6 @@ public: using typename BaseType::derived_type; using typename BaseType::RealType; using typename BaseType::ScalarType; - static constexpr Backends dense_matrix_type = Traits::dense_matrix_type; - static constexpr Backends sparse_matrix_type = Traits::sparse_matrix_type; using const_iterator = internal::VectorInputIterator<Traits, ScalarType>; using iterator = internal::VectorOutputIterator<Traits, ScalarType>; friend const_iterator; @@ -88,6 +86,15 @@ public: { } + template <class Vector> + std::enable_if_t<Common::is_vector<Vector>::value, derived_type&> assign_from(const Vector& other) + { + this->resize(other.size()); + for (size_t ii = 0; ii < other.size(); ++ii) + this->set_entry(ii, other[ii]); + return this->as_imp(); + } + /// \name Have to be implemented by a derived class in addition to the ones required by ContainerInterface! /// \{ @@ -101,6 +108,14 @@ public: return this->as_imp().size(); } + /** + * \note This is supposed to do nothing if new_size == size() + */ + inline void resize(const size_t new_size) + { + CHECK_AND_CALL_CRTP(this->as_imp().resize(new_size)); + } + /** * \brief Add a scalar to the iith entry. */ diff --git a/dune/xt/la/solver.hh b/dune/xt/la/solver.hh index 2b7ee12853662e19d0555443aab2d8610b9fd171..ef6683dfdef312018eee279887b7c77e9174d6cd 100644 --- a/dune/xt/la/solver.hh +++ b/dune/xt/la/solver.hh @@ -51,6 +51,19 @@ public: } // namespace internal +template <class MatrixType, class CommunicatorType = SequentialCommunication> +class SolverOptions +{ + static_assert(AlwaysFalse<MatrixType>::value, + "Please implement for given MatrixType and add the respective include below!"); + +public: + static std::vector<std::string> types(); + + static Common::Configuration options(const std::string /*type*/ = ""); +}; // class SolverOptions + + template <class MatrixImp, class CommunicatorType = SequentialCommunication> class Solver { @@ -134,41 +147,45 @@ public: template <class M> -typename std::enable_if<XT::LA::is_matrix<M>::value, Solver<M>>::type make_solver(const M& matrix) +typename std::enable_if<is_matrix<M>::value, Solver<M>>::type make_solver(const M& matrix) { return Solver<M>(matrix); } -template <class M, class V, class... Args> -typename std::enable_if<XT::LA::is_matrix<M>::value && XT::LA::is_vector<V>::value, void>::type -solve(const M& A, const V& b, V& x, Args&&... args) -{ - make_solver(A).apply(b, x, std::forward<Args>(args)...); -} +// template <class M, class V, class... Args> +// typename std::enable_if<is_matrix<M>::value && is_vector<V>::value, void>::type +// solve(const M& A, const V& b, V& x, Args&&... args) +//{ +// make_solver(A).apply(b, x, std::forward<Args>(args)...); +//} -template <class M, class C> -typename std::enable_if<XT::LA::is_matrix<M>::value, Solver<M, C>>::type make_solver(const M& matrix, const C& dof_comm) -{ - return Solver<M, C>(matrix, dof_comm); -} +// template <class M, class C> +// typename std::enable_if<is_matrix<M>::value, Solver<M, C>>::type make_solver(const M& matrix, const C& +// dof_comm) +//{ +// return Solver<M, C>(matrix, dof_comm); +//} -template <class M, class V, class C, class... Args> -typename std::enable_if<XT::LA::is_matrix<M>::value && XT::LA::is_vector<V>::value, void>::type -solve(const M& A, const V& b, V& x, const C& dof_comm, Args&&... args) -{ - make_solver(A, dof_comm).apply(b, x, std::forward<Args>(args)...); -} +// template <class M, class V, class C, class... Args> +// typename std::enable_if<is_matrix<M>::value && is_vector<V>::value, void>::type +// solve(const M& A, const V& b, V& x, const C& dof_comm, Args&&... args) +//{ +// make_solver(A, dof_comm).apply(b, x, std::forward<Args>(args)...); +//} -template <class M, class V, class... Args> -typename std::enable_if<XT::LA::is_matrix<M>::value && XT::LA::is_vector<V>::value, V>::type -solve(const M& A, const V& b, Args&&... args) +template <class M, class V, class S> +typename VectorInterface<V, S>::derived_type +solve(const MatrixInterface<M, S>& A, + const VectorInterface<V, S>& b, + const Common::Configuration& opts = SolverOptions<typename MatrixInterface<M, S>::derived_type>::options()) { - V x(A.cols()); - solve(A, b, x, std::forward<Args>(args)...); + typename VectorInterface<V, S>::derived_type x(A.cols(), 0.); + Solver<typename MatrixInterface<M, S>::derived_type> solver(A.as_imp()); + solver.apply(b.as_imp(), x, opts); return x; } diff --git a/dune/xt/la/solver/common.hh b/dune/xt/la/solver/common.hh index e6c3c37657a64645f9349e6741891758b4091c57..d585d2155ec9c281169fd3521d0022304684ff2a 100644 --- a/dune/xt/la/solver/common.hh +++ b/dune/xt/la/solver/common.hh @@ -32,6 +32,26 @@ namespace XT { namespace LA { +template <class S, class CommunicatorType> +class SolverOptions<CommonDenseMatrix<S>, CommunicatorType> : protected internal::SolverUtils +{ +public: + using MatrixType = CommonDenseMatrix<S>; + + static std::vector<std::string> types() + { + return {"qr.householder"}; + } + + static Common::Configuration options(const std::string type = "") + { + const std::string tp = !type.empty() ? type : types()[0]; + internal::SolverUtils::check_given(tp, types()); + return Common::Configuration({"type", "post_check_solves_system"}, {tp.c_str(), "1e-5"}); + } +}; // class SolverOptions<CommonDenseMatrix<...>> + + template <class S, class CommunicatorType> class Solver<CommonDenseMatrix<S>, CommunicatorType> : protected internal::SolverUtils { diff --git a/dune/xt/la/solver/istl.hh b/dune/xt/la/solver/istl.hh index 3f01479565f46747695a3cc3677fe28f4c89d887..8afc09684919991bff300767bc3b6206b03662dd 100644 --- a/dune/xt/la/solver/istl.hh +++ b/dune/xt/la/solver/istl.hh @@ -97,6 +97,67 @@ struct IstlSolverTraits<S, SequentialCommunication> } // namespace internal + +template <class S, class CommunicatorType> +class SolverOptions<IstlRowMajorSparseMatrix<S>, CommunicatorType> : protected internal::SolverUtils +{ +public: + using MatrixType = IstlRowMajorSparseMatrix<S>; + + static std::vector<std::string> types() + { + std::vector<std::string> ret{ + "bicgstab.ssor", "bicgstab.amg.ssor", "bicgstab.amg.ilu0", "bicgstab.ilut", "bicgstab"}; + + if (std::is_same<CommunicatorType, XT::SequentialCommunication>::value) { +#if HAVE_SUPERLU + ret.insert(ret.begin(), "superlu"); +#endif +#if HAVE_UMFPACK + ret.push_back("umfpack"); +#endif + } + return ret; + } // ... types(...) + + static Common::Configuration options(const std::string type = "") + { + const std::string tp = !type.empty() ? type : types()[0]; + internal::SolverUtils::check_given(tp, types()); + Common::Configuration general_opts({"type", "post_check_solves_system", "verbose"}, {tp.c_str(), "1e-5", "0"}); + Common::Configuration iterative_options({"max_iter", "precision"}, {"10000", "1e-10"}); + iterative_options += general_opts; + if (tp.substr(0, 13) == "bicgstab.amg." || tp == "bicgstab") { + iterative_options.set("smoother.iterations", "1"); + iterative_options.set("smoother.relaxation_factor", "1"); + iterative_options.set("smoother.verbose", "0"); + iterative_options.set("preconditioner.max_level", "100"); + iterative_options.set("preconditioner.coarse_target", "1000"); + iterative_options.set("preconditioner.min_coarse_rate", "1.2"); + iterative_options.set("preconditioner.prolong_damp", "1.6"); + iterative_options.set("preconditioner.anisotropy_dim", "2"); // <- this should be the dimDomain of the problem! + iterative_options.set("preconditioner.isotropy_dim", "2"); // <- this as well + iterative_options.set("preconditioner.verbose", "0"); + return iterative_options; + } else if (tp == "bicgstab.ilut" || tp == "bicgstab.ssor") { + iterative_options.set("preconditioner.iterations", "2"); + iterative_options.set("preconditioner.relaxation_factor", "1.0"); + return iterative_options; +#if HAVE_UMFPACK + } else if (tp == "umfpack") { + return general_opts; +#endif +#if HAVE_SUPERLU + } else if (tp == "superlu") { + return general_opts; +#endif + } else + DUNE_THROW(Common::Exceptions::internal_error, "Given solver type '" << tp << "' has no default options"); + return Common::Configuration(); + } +}; // class SolverOptions + + template <class S, class CommunicatorType> class Solver<IstlRowMajorSparseMatrix<S>, CommunicatorType> : protected internal::SolverUtils { @@ -116,11 +177,7 @@ public: { } - Solver(Solver&& source) - : matrix_(source.matrix_) - , communicator_(source.communicator_.access()) - { - } + Solver(Solver&& source) = default; static std::vector<std::string> types() { diff --git a/dune/xt/la/test/container_vector.tpl b/dune/xt/la/test/container_vector.tpl index 4a1fb83d40009052db88e6ffab34ea76b3fcb5b2..a4fb562482c79e76f9c513991ac601a505486c16 100644 --- a/dune/xt/la/test/container_vector.tpl +++ b/dune/xt/la/test/container_vector.tpl @@ -10,6 +10,7 @@ // Tobias Leibner (2014 - 2017) #include <dune/xt/common/test/main.hxx> +#include <dune/xt/common/vector.hh> #include <dune/xt/la/test/container.hh> @@ -127,6 +128,7 @@ struct VectorTest_{{T_NAME}} : public ::testing::Test { typedef typename VectorImp::ScalarType ScalarType; typedef typename VectorImp::RealType RealType; + using V = XT::Common::VectorAbstraction<VectorImp>; // create test vectors VectorImp zeros(dim); // [0, 0, 0, 0] @@ -160,6 +162,23 @@ struct VectorTest_{{T_NAME}} : public ::testing::Test testvector_5.set_entry(2, ScalarType(2.5)); testvector_5.set_entry(3, ScalarType(-3.5)); + // test resize, should not change existing entries + if (!V::has_static_size) { + try { + auto testvector_1_saved = testvector_1; + testvector_1.resize(dim-1); + EXPECT_EQ(dim-1, testvector_1.size()); + EXPECT_EQ(dim, testvector_1_saved.size()); + for (size_t ii = 0; ii < dim-1; ++ii) + EXPECT_DOUBLE_OR_COMPLEX_EQ(std::real(testvector_1_saved.get_entry(ii)), testvector_1.get_entry(ii)); + testvector_1.resize(dim); + testvector_1.set_entry(dim-1, testvector_1_saved[dim-1]); + for (size_t ii = 0; ii < dim; ++ii) + EXPECT_DOUBLE_OR_COMPLEX_EQ(std::real(testvector_1_saved.get_entry(ii)), testvector_1.get_entry(ii)); + } catch(XT::Common::Exceptions::you_are_using_this_wrong) { + } + } + // test get_entry() EXPECT_DOUBLE_OR_COMPLEX_EQ(RealType(0), testvector_1.get_entry(0)); EXPECT_DOUBLE_OR_COMPLEX_EQ(RealType(-2), testvector_1.get_entry(1)); diff --git a/dune/xt/la/type_traits.hh b/dune/xt/la/type_traits.hh index 19742e7b33eb6dabb4b5f9e0f4259c8ad3815d68..f2d7ba9f23465771c6869e18403751dcdf89633e 100644 --- a/dune/xt/la/type_traits.hh +++ b/dune/xt/la/type_traits.hh @@ -19,6 +19,23 @@ namespace XT { namespace LA { +enum class Backends +{ + common_dense, + common_sparse, + istl_dense, + istl_sparse, + eigen_dense, + eigen_sparse, + none +}; // enum class Backends + + +static constexpr Backends default_backend = Backends::istl_sparse; +static constexpr Backends default_sparse_backend = Backends::istl_sparse; +static constexpr Backends default_dense_backend = Backends::common_dense; + + // forwards template <class Traits> class ProvidesBackend; @@ -35,6 +52,9 @@ class MatrixInterface; template <class Traits, class ScalarImp> class VectorInterface; +template <class ScalarType, Backends backend> +struct Container; + namespace internal { @@ -146,6 +166,44 @@ struct provides_data_access<C, false> : public std::false_type }; +template <class V, bool = is_vector<V>::value> +struct extract_matrix; + +template <class V> +struct extract_matrix<V, false> +{ + static_assert(AlwaysFalse<V>::value, "V is not a vector!"); +}; + +template <class V> +struct extract_matrix<V, true> +{ + using type = typename Container<typename V::ScalarType, V::sparse_matrix_type>::MatrixType; +}; + +template <class V> +using matrix_t = typename extract_matrix<V>::type; + + +template <class M, bool = is_matrix<M>::value> +struct extract_vector; + +template <class M> +struct extract_vector<M, false> +{ + static_assert(AlwaysFalse<M>::value, "M is not a matrix!"); +}; + +template <class M> +struct extract_vector<M, true> +{ + using type = typename Container<typename M::ScalarType, M::vector_type>::VectorType; +}; + +template <class M> +using vector_t = typename extract_vector<M>::type; + + } // namespace LA } // namespace XT } // namespace Dune diff --git a/python/dune/xt/la/container/vector-interface.hh b/python/dune/xt/la/container/vector-interface.hh index a11e091be7ed4dfb7016fa382ae63bc9e3e156d8..157ea2783bbe5edb0e24877c105b7bb0fdd553f7 100644 --- a/python/dune/xt/la/container/vector-interface.hh +++ b/python/dune/xt/la/container/vector-interface.hh @@ -20,7 +20,7 @@ #include <dune/xt/common/string.hh> #include <dune/xt/la/type_traits.hh> -#include <dune/xt/la/container.bindings.hh> +#include <python/dune/xt/la/container.bindings.hh> #include <dune/xt/la/container/io.hh> #include <dune/xt/la/container/vector-interface.hh> @@ -131,7 +131,7 @@ typename std::enable_if<is_vector<C>::value, pybind11::class_<C>>::type bind_Vec "jj"_a); c.def("set_all", [](C& self, const S& value) { self.set_all(value); }, "value"_a); c.def("valid", [](const C& self) { return self.valid(); }); - c.def("dim", [](const C& self) { return self.dim(); }); + c.def("dim", [](const C& self) { return self.size(); }); c.def("mean", [](const C& self) { return self.mean(); }); c.def("amax", [](const C& self) { return self.amax(); }); c.def("almost_equal",