diff --git a/src/amdis/common/Access.hpp b/src/amdis/common/Access.hpp deleted file mode 100644 index a99de1075b441bb498d993ee0ff39103045b220e..0000000000000000000000000000000000000000 --- a/src/amdis/common/Access.hpp +++ /dev/null @@ -1,125 +0,0 @@ -#pragma once - -#include <dune/common/typeutilities.hh> - -#include <amdis/common/Concepts.hpp> -#include <amdis/common/Logical.hpp> -#include <amdis/common/TypeTraits.hpp> - -namespace AMDiS -{ - namespace Concepts - { - namespace Definition - { - struct HasVectorAccess - { - template <class V, class I> - auto require(V&& v, I&& i, Dune::PriorityTag<2>) -> decltype( v[i] ); - - template <class V, class I> - auto require(V&& v, I&& i, Dune::PriorityTag<1>) -> decltype( v(i) ); - }; - - struct HasMatrixAccess - { - template <class M, class I, class J> - auto require(M&& m, I&& i, J&& j, Dune::PriorityTag<2>) -> decltype( m[i][j] ); - - template <class M, class I, class J> - auto require(M&& m, I&& i, J&& j, Dune::PriorityTag<1>) -> decltype( m(i,j) ); - }; - - } // end namespace Definition - - /// Vector component can be accessed either with [.] or (.) - template <class V, class I> - using VectorAccessible_t = models_t<Definition::HasVectorAccess(V, I, Dune::PriorityTag<42>)>; - - /// Matrix component can be accessed either with [.][.] or (.,.) - template <class M, class I, class J> - using MatrixAccessible_t = models_t<Definition::HasMatrixAccess(M, I, J, Dune::PriorityTag<42>)>; - - } // end namespace Concepts - - -#ifdef DOXYGEN - /// \brief Uniform vector access using [.] or (.) - template <class Vector, class I> - decltype(auto) access(Vector&& vec, I const& i); - - /// \brief Uniform matrix access using either [.][.] or (.,.) - template <class Matrix, class I, class J> - decltype(auto) access(Matrix&& mat, I const& i, J const& j); -#else - - namespace Impl - { - // access i'th component of a vector using [.] - template <class Vector, class I, - class = void_t<decltype(std::declval<Vector>()[std::declval<I>()])> > - decltype(auto) access_impl(Vector&& vec, I const& i, Dune::PriorityTag<2>) - { - return vec[i]; - } - - // access i'th component of a vector using (.) - template <class Vector, class I, - class = void_t<decltype(std::declval<Vector>()(std::declval<I>()))> > - decltype(auto) access_impl(Vector&& vec, I const& i, Dune::PriorityTag<1>) - { - return vec(i); - } - - // fall-back implementation for scalars - template <class Vector, class I> - decltype(auto) access_impl(Vector&& vec, I const& /*i*/, Dune::PriorityTag<0>) - { - return FWD(vec); - } - } - - // access i'th component of a vector - template <class Vector, class I> - decltype(auto) access(Vector&& vec, I const& i) - { - return Impl::access_impl(FWD(vec), i, Dune::PriorityTag<42>{}); - } - - - namespace Impl - { - // access (i,j)'th component of a matrix using [.][.] - template <class Matrix, class I, class J, - class = void_t<decltype(std::declval<Matrix>()[std::declval<I>(),std::declval<J>()])> > - decltype(auto) access_impl(Matrix&& mat, I const& i, J const& j, Dune::PriorityTag<2>) - { - return mat[i][j]; - } - - // access (i,j)'th component of a matrix using (.,.) - template <class Matrix, class I, class J, - class = void_t<decltype(std::declval<Matrix>()(std::declval<I>(),std::declval<J>()))> > - decltype(auto) access_impl(Matrix&& mat, I const& i, J const& j, Dune::PriorityTag<1>) - { - return mat(i,j); - } - - // fall-back implementation for scalars - template <class Matrix, class I, class J> - decltype(auto) access_impl(Matrix&& mat, I const& /*i*/, J const& /*j*/, Dune::PriorityTag<0>) - { - return FWD(mat); - } - } - - // access (i,j)'th component of a matrix - template <class Matrix, class I, class J> - decltype(auto) access(Matrix&& mat, I const& i, J const& j) - { - return Impl::access_impl(FWD(mat), i, j, Dune::PriorityTag<42>{}); - } - -#endif - -} // end namespace AMDiS diff --git a/src/amdis/common/CMakeLists.txt b/src/amdis/common/CMakeLists.txt index 8f345538998147c05d1ff8860127b303f2d565b4..fc7b8788a66c00e5a23e213fe3757bf7e3f98af8 100644 --- a/src/amdis/common/CMakeLists.txt +++ b/src/amdis/common/CMakeLists.txt @@ -4,7 +4,6 @@ dune_library_add_sources(amdis SOURCES ) install(FILES - Access.hpp Algorithm.hpp Apply.hpp Concepts.hpp @@ -19,15 +18,11 @@ install(FILES FlatMatrix.hpp FlatVector.hpp ForEach.hpp - HybridSize.hpp Index.hpp Literals.hpp Logical.hpp Math.hpp - MultiTypeMatrix.hpp - MultiTypeVector.hpp Range.hpp - Resize.hpp QuadMath.hpp SharedPtr.hpp StaticSize.hpp diff --git a/src/amdis/common/HybridSize.hpp b/src/amdis/common/HybridSize.hpp deleted file mode 100644 index b93c622a5cbfd999f43175abaec324ca138c9995..0000000000000000000000000000000000000000 --- a/src/amdis/common/HybridSize.hpp +++ /dev/null @@ -1,188 +0,0 @@ -#pragma once - -#include <utility> - -#include <dune/common/rangeutilities.hh> -#include <dune/common/typeutilities.hh> - -#include <amdis/common/Access.hpp> -#include <amdis/common/Concepts.hpp> -#include <amdis/common/StaticSize.hpp> - -namespace AMDiS -{ - namespace Concepts - { - /// Vector can be accessed with dynamic indices. See \ref VectorAccessible_t - template <class V> - using DynamicVectorAccessible_t = VectorAccessible_t<V, std::size_t>; - - /// Matrix can be accessed with dynamic indices. See \ref MatrixAccessible_t - template <class M> - using DynamicMatrixAccessible_t = MatrixAccessible_t<M, std::size_t, std::size_t>; - - } // end namespace Concept - - -#ifdef DOXYGEN - /// \brief Return the size of the vector `vec`. - /** - * If the vector `vec` can be accessed using (dynamic) indices, the function returns the number - * of entries as integer value. Otherwise a `std::integral_constant` is returned. - **/ - template <class Vector> - implementation-defined hybrid_size(Vector const& vec); - - /// Return either an IntegralRange or a StaticIntegralRange of the indices to - /// access the vector, depending on the type of \ref hybrid_size(vec) - template <class Vector> - implementation-defined hybridElements(Vector const& vec); - - /// \brief Return the number of rows of the matrix `mat`. - /** - * If the matrix `mat` can be accessed using (dynamic) indices, the function returns the number - * of rows as integer value. Otherwise a `std::integral_constant` is returned. - **/ - template <class Matrix> - implementation-defined hybrid_num_rows(Matrix const& mat); - - /// Return either an IntegralRange or a StaticIntegralRange of the indices to - /// access the rows of the matrix, depending on the type of \ref hybrid_num_rows(mat) - template <class Matrix> - implementation-defined hybridRows(Matrix const& mat); - - /// \brief Return the number of columns of the matrix `mat`. - /** - * If the matrix `mat` can be accessed using (dynamic) indices, the function returns the number - * of columns as integer value. Otherwise a `std::integral_constant` is returned. - **/ - template <class Matrix> - implementation-defined hybrid_num_cols(Matrix const& mat); - - /// Return either an IntegralRange or a StaticIntegralRange of the indices to - /// access the columns of the matrix, depending on the type of \ref hybrid_num_cols(mat) - template <class Matrix> - implementation-defined hybridCols(Matrix const& mat); -#else - - namespace Impl - { - template <class Vector, - REQUIRES(Concepts::DynamicVectorAccessible_t<Vector>::value)> - auto hybrid_size(Vector const& vec, Dune::PriorityTag<2>) - -> decltype(vec.size()) { return vec.size(); } - - template <class Vector, - REQUIRES(Concepts::DynamicVectorAccessible_t<Vector>::value)> - auto hybrid_size(Vector const& vec, Dune::PriorityTag<1>) - -> decltype(size(vec)) { return size(vec); } - - template <class Vector> - auto hybrid_size(Vector const& vec, Dune::PriorityTag<0>) - { - return AMDiS::static_size(vec); - } - - } // end namespace Impl - - template <class Vector> - auto hybrid_size(Vector const& vec) - { - return Impl::hybrid_size(vec, Dune::PriorityTag<42>{}); - } - - template <class Vector> - auto hybridElements(Vector const& vec) - { - return Dune::range(hybrid_size(vec)); - } - - - namespace Impl - { - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<5>) - -> decltype(mat.num_rows()) { return mat.num_rows(); } - - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<4>) - -> decltype(mat.N()) { return mat.N(); } - - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<3>) - -> decltype(mat.rows()) { return mat.rows(); } - - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<2>) - -> decltype(num_rows(mat)) { return num_rows(mat); } - - template <class Matrix> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<0>) - { - return AMDiS::static_num_rows(mat); - } - - } // end namespace Impl - - template <class Matrix> - auto hybrid_num_rows(Matrix const& mat) - { - return Impl::hybrid_num_rows(mat, Dune::PriorityTag<42>{}); - } - - template <class Matrix> - auto hybridRows(Matrix const& mat) - { - return Dune::range(hybrid_num_rows(mat)); - } - - - namespace Impl - { - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<5>) - -> decltype(mat.num_rows()) { return mat.num_cols(); } - - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<4>) - -> decltype(mat.M()) { return mat.M(); } - - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<3>) - -> decltype(mat.cols()) { return mat.cols(); } - - template <class Matrix, - REQUIRES(Concepts::DynamicMatrixAccessible_t<Matrix>::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<2>) - -> decltype(num_cols(mat)) { return num_cols(mat); } - - template <class Matrix> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<0>) - { - return AMDiS::static_num_cols(mat); - } - - } // end namespace Impl - - template <class Matrix> - auto hybrid_num_cols(Matrix const& mat) - { - return Impl::hybrid_num_cols(mat, Dune::PriorityTag<42>{}); - } - - template <class Matrix> - auto hybridCols(Matrix const& mat) - { - return Dune::range(hybrid_num_cols(mat)); - } - -#endif // DOXYGEN - -} // end namespace AMDiS diff --git a/src/amdis/common/MultiTypeMatrix.hpp b/src/amdis/common/MultiTypeMatrix.hpp deleted file mode 100644 index a3a5682864bc197157e1b8852c8f5dde387190ba..0000000000000000000000000000000000000000 --- a/src/amdis/common/MultiTypeMatrix.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#pragma once - -#include <tuple> -#include <type_traits> - -#include <dune/common/ftraits.hh> - -#include <amdis/common/Concepts.hpp> -#include <amdis/common/ForEach.hpp> -#include <amdis/common/Index.hpp> -#include <amdis/common/Math.hpp> -#include <amdis/common/MultiTypeVector.hpp> -#include <amdis/common/Range.hpp> -#include <amdis/common/StaticSize.hpp> -#include <amdis/common/TypeTraits.hpp> -#include <amdis/typetree/MultiIndex.hpp> - -namespace AMDiS -{ - // forward declaration - template <class... Rows> - class MultiTypeMatrix; -} - -namespace Dune -{ - template <class... Rows> - struct FieldTraits<AMDiS::MultiTypeMatrix<Rows...>> - { - using field_type = std::common_type_t<typename Dune::FieldTraits<Rows>::field_type...>; - using real_type = std::common_type_t<typename Dune::FieldTraits<Rows>::real_type...>; - }; -} - - -namespace AMDiS -{ - // Rows should be of type MultiTypeVector - template <class... Rows> - class MultiTypeMatrix - : public std::tuple<Rows...> - { - using Self = MultiTypeMatrix; - using Super = std::tuple<Rows...>; - - static_assert(IsEqual<int, Rows::dimension...>::value, - "All columns must have the same length."); - - public: - using field_type = typename Dune::FieldTraits<Self>::field_type; - using real_type = typename Dune::FieldTraits<Self>::real_type; - using size_type = std::size_t; - - static constexpr int rows = std::tuple_size<Super>::value; - static constexpr int cols = Math::max(Rows::dimension...); - - template <class... Rows_, - REQUIRES( Concepts::Similar<Types<Rows...>, Types<Rows_...>> )> - MultiTypeMatrix(Rows_&&... rows) - : Super(FWD(rows)...) - {} - - /// Default construction of tuple of FieldVectors - MultiTypeMatrix() = default; - - /// Construct tuple by initializing all tuple elements with a constant value - explicit MultiTypeMatrix(real_type value) - { - *this = value; - } - - /// Assignment of real number to all tuple elements - MultiTypeMatrix& operator=(real_type value) - { - Tools::for_each(as_tuple(), [value](auto& fv) { fv = value; }); - return *this; - } - - // Compound assignment operator += - MultiTypeMatrix& operator+=(MultiTypeMatrix const& that) - { - Tools::for_range<0,rows>([&that,this](auto const _i) { (*this)[_i] += that[_i]; }); - return *this; - } - - // Compound assignment operator -= - MultiTypeMatrix& operator-=(MultiTypeMatrix const& that) - { - Tools::for_range<0,rows>([&that,this](auto const _i) { (*this)[_i] -= that[_i]; }); - return *this; - } - - // Scaling of all tuple elements by a constant value - MultiTypeMatrix& operator*=(real_type value) - { - Tools::for_each(as_tuple(), [value](auto& fv) { fv *= value; }); - return *this; - } - - // Scaling of all tuple elements by the inverse of a constant value - MultiTypeMatrix& operator/=(real_type value) - { - Tools::for_each(as_tuple(), [value](auto& fv) { fv /= value; }); - return *this; - } - - /// Const access to the tuple elements - template <std::size_t I, std::size_t J> - decltype(auto) operator()(index_t<I> const i, index_t<J> const j) const - { - return (*this)[i][j]; - } - - /// Mutable access to the tuple elements - template <std::size_t I, std::size_t J> - decltype(auto) operator()(index_t<I> const i, index_t<J> const j) - { - return (*this)[i][j]; - } - - - /// Const access to the rows - template <std::size_t I> - decltype(auto) operator[](index_t<I> const) const - { - return std::get<I>(as_tuple()); - } - - /// Mutable access to the rows - template <std::size_t I> - decltype(auto) operator[](index_t<I> const) - { - return std::get<I>(as_tuple()); - } - - /// Return number of elements of the tuple - static constexpr std::size_t num_rows() - { - return rows; - } - - /// Return number of elements of the tuple - static constexpr std::size_t num_cols() - { - return cols; - } - - static constexpr std::size_t size() - { - return rows; - } - - private: - std::tuple<Rows...>& as_tuple() { return *this; } - std::tuple<Rows...> const& as_tuple() const { return *this; } - }; - -} // end namespace AMDiS diff --git a/src/amdis/common/MultiTypeVector.hpp b/src/amdis/common/MultiTypeVector.hpp deleted file mode 100644 index 723453474283dd574da2e0bac00176f08628f1f1..0000000000000000000000000000000000000000 --- a/src/amdis/common/MultiTypeVector.hpp +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once - -#include <tuple> -#include <type_traits> - -#include <dune/common/ftraits.hh> -#include <dune/functions/common/indexaccess.hh> - -#include <amdis/common/Concepts.hpp> -#include <amdis/common/ForEach.hpp> -#include <amdis/common/Index.hpp> -#include <amdis/common/Range.hpp> -#include <amdis/common/StaticSize.hpp> -#include <amdis/common/TypeTraits.hpp> - -namespace AMDiS -{ - // forward declaration - template <class... FV> - class MultiTypeVector; -} - -namespace Dune -{ - template <class... FV> - struct FieldTraits<AMDiS::MultiTypeVector<FV...>> - { - using field_type = std::common_type_t<typename Dune::FieldTraits<FV>::field_type...>; - using real_type = std::common_type_t<typename Dune::FieldTraits<FV>::real_type...>; - }; -} - - -namespace AMDiS -{ - template <class... FV> - class MultiTypeVector - : public std::tuple<FV...> - { - using Self = MultiTypeVector; - using Super = std::tuple<FV...>; - - public: - using field_type = typename Dune::FieldTraits<Self>::field_type; - using real_type = typename Dune::FieldTraits<Self>::real_type; - using size_type = std::size_t; - - static constexpr int dimension = std::tuple_size<Super>::value; - - template <class... FV_, - REQUIRES( Concepts::Similar<Types<FV...>, Types<FV_...>> )> - MultiTypeVector(FV_&&... fv) - : Super(FWD(fv)...) - {} - - /// Default construction of tuple of FieldVectors - MultiTypeVector() = default; - - /// Construct tuple by initializing all tuple elements with a constant value - explicit MultiTypeVector(real_type value) - { - *this = value; - } - - /// Assignment of real number to all tuple elements - MultiTypeVector& operator=(real_type value) - { - Tools::for_each(as_tuple(), [value](auto& fv) { fv = value; }); - return *this; - } - - // Compound assignment operator += - MultiTypeVector& operator+=(MultiTypeVector const& that) - { - Tools::for_range<0,dimension>([&that,this](auto const i) { (*this)[i] += that[i]; }); - return *this; - } - - // Compound assignment operator -= - MultiTypeVector& operator-=(MultiTypeVector const& that) - { - Tools::for_range<0,dimension>([&that,this](auto const i) { (*this)[i] -= that[i]; }); - return *this; - } - - // Scaling of all tuple elements by a constant value - MultiTypeVector& operator*=(real_type value) - { - Tools::for_each(as_tuple(), [value](auto& fv) { fv *= value; }); - return *this; - } - - // Scaling of all tuple elements by the inverse of a constant value - MultiTypeVector& operator/=(real_type value) - { - Tools::for_each(as_tuple(), [value](auto& fv) { fv /= value; }); - return *this; - } - - /// Const access to the tuple elements - template <std::size_t I> - decltype(auto) operator[](index_t<I> const) const - { - return std::get<I>(as_tuple()); - } - - /// Mutable access to the tuple elements - template <std::size_t I> - decltype(auto) operator[](index_t<I> const) - { - return std::get<I>(as_tuple()); - } - - /// Const access to the vector using multi-indices - template <class Index, - REQUIRES( Concepts::MultiIndex<Index> )> - decltype(auto) operator[](Index const& index) const - { - return Dune::Functions::hybridMultiIndexAccess<field_type const&>(*this, index); - } - - /// Mutable access to the vector using multi-indices - template <class Index, - REQUIRES( Concepts::MultiIndex<Index> )> - decltype(auto) operator[](Index const& index) - { - return Dune::Functions::hybridMultiIndexAccess<field_type&>(*this, index); - } - - /// Return number of elements of the tuple - static constexpr std::size_t size() - { - return dimension; - } - - private: - std::tuple<FV...>& as_tuple() { return *this; } - std::tuple<FV...> const& as_tuple() const { return *this; } - }; - -} // end namespace AMDiS diff --git a/src/amdis/common/Resize.hpp b/src/amdis/common/Resize.hpp deleted file mode 100644 index a894792c96b77faeb828df4a64d9660de21a5ff2..0000000000000000000000000000000000000000 --- a/src/amdis/common/Resize.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#pragma once - -#include <dune/common/typeutilities.hh> - -#include <amdis/common/ConceptsBase.hpp> -#include <amdis/common/Logical.hpp> - -namespace AMDiS -{ - namespace Concepts - { - namespace Definition - { - struct VectorResizable - { - template <class V> - auto require(V const& vec, Dune::PriorityTag<2>) -> decltype( const_cast<V&>(vec).resize(0u), 0); - - template <class V> - auto require(V const& vec, Dune::PriorityTag<1>) -> decltype( const_cast<V&>(vec).change_dim(0u), 0); - }; - - struct MatrixResizable - { - template <class M> - auto require(M const& mat, Dune::PriorityTag<3>) -> decltype( const_cast<M&>(mat).resize(0u,0u), 0); - - template <class M> - auto require(M const& mat, Dune::PriorityTag<2>) -> decltype( const_cast<M&>(mat).change_dim(0u,0u), 0); - - template <class M> - auto require(M const& mat, Dune::PriorityTag<1>) -> decltype( const_cast<M&>(mat).setSize(0u,0u), 0); - }; - } - - /// Checks whether a vector can be resized by various resize methods - template <class Vector> - using VectorResizable_t = models_t<Definition::VectorResizable(Vector, Dune::PriorityTag<42>)>; - - /// Checks whether a matrix can be resized by various resize methods - template <class Matrix> - using MatrixResizable_t = models_t<Definition::MatrixResizable(Matrix, Dune::PriorityTag<42>)>; - - } // end namespace Concepts - -#ifdef DOXYGEN - /// \brief Uniform vector resize, using either vector.resize() or vector.change_dim() - template <class Vector> - void resize(Vector& vec, std::size_t size); - - /// \brief Uniform matrix resize, using either matrix.resize(), matrix.setSize() or matrix.change_dim() - template <class Matrix> - void resize(Matrix& mat, std::size_t r, std::size_t c); -#else - - namespace Impl - { - template <class Vector, - class = void_t<decltype(std::declval<Vector&>().resize(0u))> > - void resize_impl(Vector& vec, std::size_t size, Dune::PriorityTag<2>) - { - vec.resize(size); - } - - template <class Vector, - class = void_t<decltype(std::declval<Vector&>().change_dim(0u))> > - void resize_impl(Vector& vec, std::size_t size, Dune::PriorityTag<1>) - { - vec.change_dim(size); - } - - template <class Vector> - void resize_impl(Vector& /*vec*/, std::size_t /*size*/, Dune::PriorityTag<0>) - { - /* do nothing */ - } - } - - template <class Vector> - void resize(Vector& vec, std::size_t size) - { - Impl::resize_impl(vec, size, Dune::PriorityTag<42>{}); - } - - - namespace Impl - { - template <class Matrix, - class = void_t<decltype(std::declval<Matrix&>().resize(0u,0u))> > - void resize_impl(Matrix& mat, std::size_t rows, std::size_t cols, Dune::PriorityTag<3>) - { - mat.resize(rows, cols); - } - - template <class Matrix, - class = void_t<decltype(std::declval<Matrix&>().change_dim(0u,0u))> > - void resize_impl(Matrix& mat, std::size_t rows, std::size_t cols, Dune::PriorityTag<2>) - { - mat.change_dim(rows, cols); - } - - template <class Matrix, - class = void_t<decltype(std::declval<Matrix&>().setSize(0u,0u))> > - void resize_impl(Matrix& mat, std::size_t rows, std::size_t cols, Dune::PriorityTag<1>) - { - mat.setSize(rows, cols); - } - - template <class Matrix> - void resize_impl(Matrix& /*mat*/, std::size_t /*rows*/, std::size_t /*cols*/, Dune::PriorityTag<0>) - { - /* do nothing */ - } - } - - template <class Matrix> - void resize(Matrix& mat, std::size_t rows, std::size_t cols) - { - Impl::resize_impl(mat, rows, cols, Dune::PriorityTag<42>{}); - } - -#endif - -} // end namespace AMDiS diff --git a/src/amdis/functions/CMakeLists.txt b/src/amdis/functions/CMakeLists.txt index c8ef39134d3d71bb3d0287c90e00fbe3eb04e40c..73697b6352cfe82f81c4258f7bf7ecc4ea1ef8af 100644 --- a/src/amdis/functions/CMakeLists.txt +++ b/src/amdis/functions/CMakeLists.txt @@ -6,5 +6,4 @@ install(FILES NodeIndices.hpp Nodes.hpp ParallelGlobalBasis.hpp - SizeInfo.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amdis/functions) diff --git a/src/amdis/functions/SizeInfo.hpp b/src/amdis/functions/SizeInfo.hpp deleted file mode 100644 index 5f1d27777a5d8376dec29ad9c41ad421748113a2..0000000000000000000000000000000000000000 --- a/src/amdis/functions/SizeInfo.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include <algorithm> -#include <functional> -#include <iostream> -#include <iterator> -#include <utility> -#include <vector> - -#include <dune/common/typetraits.hh> - -namespace AMDiS -{ - /// \brief Type-erased wrapper around size providers - class SizeInfo - { - public: - using size_type = std::size_t; - - // The SizePrefix can be created from any container with begin-end iterators. - // It just stores a copy of the given prefix in a `std::vector` and copies its - // content back on request of the `SizeProvider::size` method, where the actual - // `SizeProvider::SizePrefix` is known. - class SizePrefix - : public std::vector<size_type> - { - using Super = std::vector<size_type>; - - public: - SizePrefix() = default; - - // Constructor copies the content of the passed container to the internal storage - template <class Container, - Dune::disableCopyMove<SizePrefix, Container> = 0, - Dune::disableCopyMove<Super, Container> = 0> - SizePrefix(Container const& container) - : Super(container.begin(), container.end()) - {} - - using Super::Super; - - friend std::ostream& operator<<(std::ostream& out, SizePrefix const& prefix) - { - std::copy(prefix.begin(), prefix.end(), std::ostream_iterator<size_type>(out, " ")); - return out; - } - }; - - public: - /// Store the passed `Dune::SizeInfo` object in a type-erased manner - /// by providing an own `SizePrefix` and `size_type` type, that can be - /// filled from the actual objects. - template <class SizeProvider, - class = void_t<decltype(std::declval<SizeProvider>()(std::declval<typename SizeProvider::SizePrefix>()))> > - explicit SizeInfo(SizeProvider const& provider) - : size_([provider](SizePrefix const& prefix) -> size_type { - typename SizeProvider::SizePrefix sizePrefix; - sizePrefix.resize(prefix.size()); - std::copy(prefix.begin(), prefix.end(), sizePrefix.begin()); - return provider(sizePrefix); - }) - , dimension_([provider]() -> size_type { - return size_type(provider); - }) - {} - - /// Return number possible values for next position in multi index - size_type size(SizePrefix prefix) const - { - return size_(prefix); - } - - /// Return number possible values for next position in multi index - size_type operator()(SizePrefix prefix) const - { - return size_(prefix); - } - - /// Return the total dimension of the associated size-provider (basis) - operator size_type() const - { - return dimension_(); - } - - private: - std::function<size_type(SizePrefix const&)> size_; - std::function<size_type()> dimension_; - }; -} \ No newline at end of file diff --git a/src/amdis/typetree/MultiIndex.hpp b/src/amdis/typetree/MultiIndex.hpp index 3ef8048fa9a411c572c6d862eddf562211a7ebfc..b148d9ab42ca942932e3d1b9616ee71b69cd6cbd 100644 --- a/src/amdis/typetree/MultiIndex.hpp +++ b/src/amdis/typetree/MultiIndex.hpp @@ -35,13 +35,4 @@ namespace AMDiS return idx[0]; } - template <class MultiIndex> - void multiIndexPushFront(MultiIndex& M, std::size_t M0) - { - M.resize(M.size() + 1); - for (std::size_t i = M.size()-1; i > 0; --i) - M[i] = M[i-1]; - M[0] = M0; - } - } // end namespace AMDiS diff --git a/src/amdis/typetree/RangeType.hpp b/src/amdis/typetree/RangeType.hpp index 38b2ecec78344a40a6df2c2b21638da5a262aa4b..0c3faf78827302801df4773b74d5202fa5e1a1c8 100644 --- a/src/amdis/typetree/RangeType.hpp +++ b/src/amdis/typetree/RangeType.hpp @@ -4,9 +4,21 @@ #include <utility> #include <dune/common/fvector.hh> +#include <dune/common/tuplevector.hh> #include <dune/common/typetraits.hh> -#include <amdis/common/MultiTypeVector.hpp> +#include <amdis/common/Index.hpp> +#include <amdis/common/TypeTraits.hpp> + +namespace Dune +{ + template <class... T> + struct FieldTraits<TupleVector<T...>> + { + using field_type = std::common_type_t<typename FieldTraits<T>::field_type...>; + using real_type = std::common_type_t<typename FieldTraits<T>::real_type...>; + }; +} namespace AMDiS { @@ -25,7 +37,7 @@ namespace AMDiS * Generate the range type by recursively combining leaf range types to a * hybrid node range type. Range types for PowerNodes are thereby constructed * as Dune::FieldVector of child range types. CompositeNodes produce a - * MultiTypeVector of the difference child range types. + * TupleVector of the difference child range types. * * \tparam Node Type of a basis-tree node * \tparam R Coefficient type [double] @@ -75,7 +87,7 @@ namespace AMDiS { template <std::size_t J> using ChildNode = typename Node::template Child<J>::type; - using type = MultiTypeVector<RangeType_t<ChildNode<I>,R>...>; + using type = Dune::TupleVector<RangeType_t<ChildNode<I>,R>...>; }; using type = typename RangeTypeGenerator<std::make_index_sequence<Node::CHILDREN>>::type; diff --git a/test/AccessTest.cpp b/test/AccessTest.cpp deleted file mode 100644 index fe35b438f54a25dd3665cbd228cc7cf6157e32d7..0000000000000000000000000000000000000000 --- a/test/AccessTest.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include <amdis/AMDiS.hpp> -#include <amdis/common/Access.hpp> - -#include "Tests.hpp" - -using namespace AMDiS; - -struct Vec1 -{ - int operator[](std::size_t) const { return value; } - int& operator[](std::size_t) { return value; } - - int value = 0; -}; - -struct Vec2 -{ - int operator()(std::size_t) const { return value; } - int& operator()(std::size_t) { return value; } - - int value = 0; -}; - -struct Vec3 -{ - int operator[](std::size_t) const { return 0; } - int operator()(std::size_t) const { return 0; } -}; - -struct Mat1 -{ - Vec1 const& operator[](std::size_t) const { return row; } - Vec1& operator[](std::size_t) { return row; } - - Vec1 row; -}; - -struct Mat2 -{ - int operator()(std::size_t,std::size_t) const { return value; } - int& operator()(std::size_t,std::size_t) { return value; } - - int value = 0; -}; - -struct Mat3 -{ - Vec1 operator[](std::size_t) const { return {}; } - int operator()(std::size_t,std::size_t) const { return 0; } -}; - -struct NotAccessible {}; - -int main(int argc, char** argv) -{ - Environment env(argc, argv); - - Vec1 vec1; - Vec2 vec2; - Vec3 vec3; - - access(vec1, 1) = 2; - int i1 = access(vec1, 1); - AMDIS_TEST_EQ(i1,2); - - access(vec2, 1) = 2; - int i2 = access(vec2, 1); - AMDIS_TEST_EQ(i2,2); - - int i3 = access(vec3, 1); - AMDIS_TEST_EQ(i3,0); - - static_assert(Concepts::VectorAccessible_t<Vec1,std::size_t>::value, ""); - static_assert(Concepts::VectorAccessible_t<Vec2,std::size_t>::value, ""); - static_assert(Concepts::VectorAccessible_t<Vec3,std::size_t>::value, ""); - - Mat1 mat1; - Mat2 mat2; - Mat3 mat3; - - access(mat1, 1,1) = 2; - int j1 = access(mat1, 1,1); - AMDIS_TEST_EQ(j1,2); - - access(mat2, 1,1) = 2; - int j2 = access(mat2, 1,1); - AMDIS_TEST_EQ(j2,2); - - int j3 = access(mat3, 1,1); - AMDIS_TEST_EQ(j3,0); - - static_assert(Concepts::MatrixAccessible_t<Mat1,std::size_t,std::size_t>::value, ""); - static_assert(Concepts::MatrixAccessible_t<Mat2,std::size_t,std::size_t>::value, ""); - static_assert(Concepts::MatrixAccessible_t<Mat3,std::size_t,std::size_t>::value, ""); - - NotAccessible notAccessible; - auto k1 = access(notAccessible,1); - auto k2 = access(notAccessible,1,1); - static_assert(std::is_same<decltype(k1),NotAccessible>::value, ""); - static_assert(std::is_same<decltype(k2),NotAccessible>::value, ""); - - static_assert(not Concepts::VectorAccessible_t<NotAccessible,std::size_t>::value, ""); - static_assert(not Concepts::MatrixAccessible_t<NotAccessible,std::size_t,std::size_t>::value, ""); - - return 0; -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ddbc3c4c80cae1ff2099720d9745595327f83053..a6b8c864db4d5a131b0ad9e3559edb1b84f28512 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,5 @@ # set(DUNE_MAX_TEST_CORES 4) -dune_add_test(SOURCES AccessTest.cpp - LINK_LIBRARIES amdis) - dune_add_test(SOURCES AdaptInfoTest.cpp LINK_LIBRARIES amdis) @@ -67,9 +64,6 @@ dune_add_test(SOURCES GlobalIdSetTest.cpp dune_add_test(SOURCES GradientTest.cpp LINK_LIBRARIES amdis) -dune_add_test(SOURCES HybridSizeTest.cpp - LINK_LIBRARIES amdis) - if(BACKEND STREQUAL "ISTL") dune_add_test(SOURCES ISTLCommTest.cpp LINK_LIBRARIES amdis @@ -90,12 +84,6 @@ dune_add_test(SOURCES MpiWrapperTest.cpp TIMEOUT 300 CMAKE_GUARD "MPI_FOUND") -dune_add_test(SOURCES MultiTypeVectorTest.cpp - LINK_LIBRARIES amdis) - -dune_add_test(SOURCES MultiTypeMatrixTest.cpp - LINK_LIBRARIES amdis) - dune_add_test(SOURCES NodeIndicesTest.cpp LINK_LIBRARIES amdis) @@ -142,9 +130,6 @@ dune_add_test(SOURCES ProblemStatTest.cpp dune_add_test(SOURCES RangeTypeTest.cpp LINK_LIBRARIES amdis) -dune_add_test(SOURCES ResizeTest.cpp - LINK_LIBRARIES amdis) - dune_add_test(SOURCES StaticSizeTest.cpp LINK_LIBRARIES amdis) diff --git a/test/HybridSizeTest.cpp b/test/HybridSizeTest.cpp deleted file mode 100644 index 7fbc900608f1f2a2e067cad9e59aa44aca239bbd..0000000000000000000000000000000000000000 --- a/test/HybridSizeTest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include <amdis/AMDiS.hpp> -#include <amdis/common/HybridSize.hpp> -#include <amdis/common/TypeTraits.hpp> - -#include "Tests.hpp" - -using namespace AMDiS; - -struct Vec1 -{ - static const std::size_t dimension = 1; - - int operator[](std::size_t) const { return 0; } - std::size_t size() const { return 2; } -}; - -struct Vec2 -{ - static const std::size_t dimension = 1; - - template <std::size_t I> - int operator[](index_t<I>) const { return 0; } - std::size_t size() const { return 2; } -}; - -struct Mat1 -{ - int operator()(std::size_t,std::size_t) const { return 0; } - std::size_t N() const { return 2; } - std::size_t M() const { return 2; } -}; - -struct Mat2 -{ - int operator()(std::size_t,std::size_t) const { return 0; } - std::size_t rows() const { return 2; } - std::size_t cols() const { return 2; } -}; - -struct Mat3 -{ - int operator()(std::size_t,std::size_t) const { return 0; } - std::size_t num_rows() const { return 2; } - std::size_t num_cols() const { return 2; } -}; - -struct Mat4 -{ - static const std::size_t rows = 1; - static const std::size_t cols = 1; - - template <std::size_t I, std::size_t J> - int operator()(index_t<I>, index_t<J>) const { return 0; } -}; - -struct NotAccessible {}; - -int main(int argc, char** argv) -{ - Environment env(argc, argv); - - Vec1 vec1; - Vec2 vec2; - - AMDIS_TEST_EQ(std::size_t(hybrid_size(vec1)),2); - AMDIS_TEST_EQ(std::size_t(hybrid_size(vec2)),1); - - auto s = hybrid_size(vec2); - static_assert(VALUE(s) == 1, ""); - - Mat1 mat1; - Mat2 mat2; - Mat3 mat3; - Mat4 mat4; - - AMDIS_TEST_EQ(std::size_t(hybrid_num_rows(mat1)),2); - AMDIS_TEST_EQ(std::size_t(hybrid_num_cols(mat1)),2); - - AMDIS_TEST_EQ(std::size_t(hybrid_num_rows(mat2)),2); - AMDIS_TEST_EQ(std::size_t(hybrid_num_cols(mat2)),2); - - AMDIS_TEST_EQ(std::size_t(hybrid_num_rows(mat3)),2); - AMDIS_TEST_EQ(std::size_t(hybrid_num_cols(mat3)),2); - - AMDIS_TEST_EQ(std::size_t(hybrid_num_rows(mat4)),1); - AMDIS_TEST_EQ(std::size_t(hybrid_num_cols(mat4)),1); - - auto r = hybrid_num_rows(mat4); - auto c = hybrid_num_cols(mat4); - static_assert(VALUE(r) == 1, ""); - static_assert(VALUE(c) == 1, ""); - - return 0; -} diff --git a/test/MultiTypeMatrixTest.cpp b/test/MultiTypeMatrixTest.cpp deleted file mode 100644 index 0b81d2d58e9a6ab93e5ea2a21126a8cb2a42359f..0000000000000000000000000000000000000000 --- a/test/MultiTypeMatrixTest.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include <amdis/common/FieldMatVec.hpp> -#include <amdis/common/MultiTypeMatrix.hpp> - -using namespace AMDiS; - -int main() -{ - using V0 = MultiTypeVector<FieldMatrix<double,2,2>, FieldMatrix<double,2,3>>; - using V1 = MultiTypeVector<FieldMatrix<double,3,2>, FieldMatrix<double,3,3>>; - using M = MultiTypeMatrix<V0, V1>; - - // constructors - M m0{}; // default constructor - - V0 v0{}; - V1 v1{}; - - M m1{v0,v1}; // constructor with Vi arguments - M m2{m1}; // copy constructor - m0 = m1; // copy assignment - - M m3{0.0}; // construction from constant - m3 = 1.0; // assignment of constant - - { - M m0_tmp; - M m1_tmp{std::move(m0_tmp)}; // move constructor - m1 = std::move(m1_tmp); // move assignment - } - - using namespace Dune::Indices; - - // element access - DUNE_UNUSED auto fm0 = m1(_0,_0); // const block access - DUNE_UNUSED auto fm1 = m1[_1][_1]; // const block access - m2(_0,_0) = fm0; // mutable block access - m2[_1][_1] = fm1; // mutable block access - - DUNE_UNUSED double x = m2(_0,_0)[1][1]; // const access - - // compound assignment operators - m1 += m2; - m1 *= 2.0; - m1 /= 2.0; - -} \ No newline at end of file diff --git a/test/MultiTypeVectorTest.cpp b/test/MultiTypeVectorTest.cpp deleted file mode 100644 index 77ceea5a8c1052f3fce50d7a6542e8e23eeca1ea..0000000000000000000000000000000000000000 --- a/test/MultiTypeVectorTest.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include <amdis/common/FieldMatVec.hpp> -#include <amdis/common/MultiTypeVector.hpp> - -#include "Tests.hpp" - -using namespace AMDiS; -using namespace Dune::Indices; - -int main() -{ - using F2 = FieldVector<double,2>; - using F3 = FieldVector<double,3>; - using V = MultiTypeVector<F2, F3>; - - // constructors - V v0{}; // default constructor - - F2 f2 = {1.0, 2.0}; - F3 f3 = {1.0, 2.0, 3.0}; - -// V tmp = {F2{1.0, 2.0}, F3{1.0, 2.0, 3.0}}; - - V v1{f2,f3}; // constructor with FV arguments - AMDIS_TEST_EQ( v1[_0] , f2 ); - AMDIS_TEST_EQ( v1[_1] , f3 ); - - V v2{v1}; // copy constructor - AMDIS_TEST_EQ( v2[_0] , f2 ); - AMDIS_TEST_EQ( v2[_1] , f3 ); - - v0 = v1; // copy assignment - AMDIS_TEST_EQ( v0[_0] , f2 ); - AMDIS_TEST_EQ( v0[_1] , f3 ); - - V v3{0.0}; // construction from constant - AMDIS_TEST_EQ( v3[_0] , F2({0.0, 0.0}) ); - AMDIS_TEST_EQ( v3[_1] , F3({0.0, 0.0, 0.0}) ); - - v3 = 1.0; // assignment of constant - AMDIS_TEST_EQ( v3[_0] , F2({1.0, 1.0}) ); - AMDIS_TEST_EQ( v3[_1] , F3({1.0, 1.0, 1.0}) ); - - // compound assignment operators - v2 += v1; - AMDIS_TEST_EQ( v2[_0] , F2({2.0, 4.0}) ); - AMDIS_TEST_EQ( v2[_1] , F3({2.0, 4.0, 6.0}) ); - v2 -= v1; - - v2 *= 1.5; - AMDIS_TEST_EQ( v2[_0] , F2({1.5, 3.0}) ); - AMDIS_TEST_EQ( v2[_1] , F3({1.5, 3.0, 4.5}) ); - v2 /= 1.5; - - v1[_1] += f3; - AMDIS_TEST( v1[_1] == F3({2.0, 4.0, 6.0}) ); - - { - V v0_tmp; - V v1_tmp{std::move(v0_tmp)}; // move constructor - v1 = std::move(v1_tmp); // move assignment - } - - - // element access - v1[_0] = f2; // mutable block access - v1[_0][0] = 2.5; // mutable element access - AMDIS_TEST( v1[_0][0] == 2.5 && v1[_0][1] == 2.0); - DUNE_UNUSED auto x = v1[_1][1]; // const access - - // multi-index access - std::array<std::size_t,2> index{1,1}; - v1[index] = 2.0; - AMDIS_TEST( v1[_1][1] == 2.0 ); - - using FV = FieldVector<double,1>; - using W0 = MultiTypeVector<FV,FV>; - using W = MultiTypeVector<W0,W0>; - W w; - w[index] = 3.0; - AMDIS_TEST( w[_1][_1] == 3.0 ); - - // dimension of the tuple - AMDIS_TEST( v1.size() == 2 ); -} \ No newline at end of file diff --git a/test/RangeTypeTest.cpp b/test/RangeTypeTest.cpp index 2ba3071f16da95146eb10b10618c740f372fd835..7ded146a76175c7a51fd1a095f4a4849c4ec1f0f 100644 --- a/test/RangeTypeTest.cpp +++ b/test/RangeTypeTest.cpp @@ -36,7 +36,7 @@ int main() localView.bind(e); auto node = localView.tree(); - using NodeRange = MultiTypeVector<FieldVector<double,2>, FieldVector<double,1>>; + using NodeRange = Dune::TupleVector<FieldVector<double,2>, FieldVector<double,1>>; static_assert( std::is_same<NodeRange, RangeType_t<decltype(node)>>::value, "" ); auto v_node = TypeTree::child(node, _0); diff --git a/test/ResizeTest.cpp b/test/ResizeTest.cpp deleted file mode 100644 index f6f0511d6f471f06decaeae7ac13bbc8be632fb4..0000000000000000000000000000000000000000 --- a/test/ResizeTest.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <amdis/AMDiS.hpp> -#include <amdis/common/Resize.hpp> - -using namespace AMDiS; - -struct Vec1 { void resize(std::size_t) {} }; -struct Vec2 { void change_dim(std::size_t) {} }; -struct Vec3 -{ - void resize(std::size_t) {} - void change_dim(std::size_t) {} -}; - -struct Mat1 { void resize(std::size_t,std::size_t) {} }; -struct Mat2 { void change_dim(std::size_t,std::size_t) {} }; -struct Mat3 { void setSize(std::size_t,std::size_t) {} }; -struct Mat4 -{ - void resize(std::size_t,std::size_t) {} - void change_dim(std::size_t,std::size_t) {} - void setSize(std::size_t,std::size_t) {} -}; - -struct NotResizable {}; - -int main(int argc, char** argv) -{ - Environment env(argc, argv); - - Vec1 vec1; - Vec2 vec2; - Vec3 vec3; - - resize(vec1, 1); - resize(vec2, 1); - resize(vec3, 1); - - static_assert(Concepts::VectorResizable_t<Vec1>::value, ""); - static_assert(Concepts::VectorResizable_t<Vec2>::value, ""); - static_assert(Concepts::VectorResizable_t<Vec3>::value, ""); - - Mat1 mat1; - Mat2 mat2; - Mat3 mat3; - Mat4 mat4; - - resize(mat1,1,1); - resize(mat2,1,1); - resize(mat3,1,1); - resize(mat4,1,1); - - static_assert(Concepts::MatrixResizable_t<Mat1>::value, ""); - static_assert(Concepts::MatrixResizable_t<Mat2>::value, ""); - static_assert(Concepts::MatrixResizable_t<Mat3>::value, ""); - static_assert(Concepts::MatrixResizable_t<Mat4>::value, ""); - - NotResizable notResizable; - resize(notResizable,1); - resize(notResizable,1,1); - - static_assert(not Concepts::VectorResizable_t<NotResizable>::value, ""); - static_assert(not Concepts::MatrixResizable_t<NotResizable>::value, ""); - - return 0; -}