From 7e6f5c05e8c5d71b58e1f1920f46a5a24a100533 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Fri, 17 Jan 2020 14:42:52 +0100 Subject: [PATCH 1/4] removed some headers from amdis and moved them to independent repository dune-blocked --- src/amdis/common/Access.hpp | 125 --------------------- src/amdis/common/CMakeLists.txt | 3 - src/amdis/common/HybridSize.hpp | 188 -------------------------------- test/AccessTest.cpp | 106 ------------------ test/CMakeLists.txt | 6 - test/HybridSizeTest.cpp | 94 ---------------- test/ResizeTest.cpp | 65 ----------- 7 files changed, 587 deletions(-) delete mode 100644 src/amdis/common/Access.hpp delete mode 100644 src/amdis/common/HybridSize.hpp delete mode 100644 test/AccessTest.cpp delete mode 100644 test/HybridSizeTest.cpp delete mode 100644 test/ResizeTest.cpp diff --git a/src/amdis/common/Access.hpp b/src/amdis/common/Access.hpp deleted file mode 100644 index a99de107..00000000 --- a/src/amdis/common/Access.hpp +++ /dev/null @@ -1,125 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -namespace AMDiS -{ - namespace Concepts - { - namespace Definition - { - struct HasVectorAccess - { - template - auto require(V&& v, I&& i, Dune::PriorityTag<2>) -> decltype( v[i] ); - - template - auto require(V&& v, I&& i, Dune::PriorityTag<1>) -> decltype( v(i) ); - }; - - struct HasMatrixAccess - { - template - auto require(M&& m, I&& i, J&& j, Dune::PriorityTag<2>) -> decltype( m[i][j] ); - - template - 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 - using VectorAccessible_t = models_t)>; - - /// Matrix component can be accessed either with [.][.] or (.,.) - template - using MatrixAccessible_t = models_t)>; - - } // end namespace Concepts - - -#ifdef DOXYGEN - /// \brief Uniform vector access using [.] or (.) - template - decltype(auto) access(Vector&& vec, I const& i); - - /// \brief Uniform matrix access using either [.][.] or (.,.) - template - decltype(auto) access(Matrix&& mat, I const& i, J const& j); -#else - - namespace Impl - { - // access i'th component of a vector using [.] - template ()[std::declval()])> > - decltype(auto) access_impl(Vector&& vec, I const& i, Dune::PriorityTag<2>) - { - return vec[i]; - } - - // access i'th component of a vector using (.) - template ()(std::declval()))> > - decltype(auto) access_impl(Vector&& vec, I const& i, Dune::PriorityTag<1>) - { - return vec(i); - } - - // fall-back implementation for scalars - template - decltype(auto) access_impl(Vector&& vec, I const& /*i*/, Dune::PriorityTag<0>) - { - return FWD(vec); - } - } - - // access i'th component of a vector - template - 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 ()[std::declval(),std::declval()])> > - 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 ()(std::declval(),std::declval()))> > - 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 - 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 - 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 8f345538..f34d89aa 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,7 +18,6 @@ install(FILES FlatMatrix.hpp FlatVector.hpp ForEach.hpp - HybridSize.hpp Index.hpp Literals.hpp Logical.hpp @@ -27,7 +25,6 @@ install(FILES 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 b93c622a..00000000 --- a/src/amdis/common/HybridSize.hpp +++ /dev/null @@ -1,188 +0,0 @@ -#pragma once - -#include - -#include -#include - -#include -#include -#include - -namespace AMDiS -{ - namespace Concepts - { - /// Vector can be accessed with dynamic indices. See \ref VectorAccessible_t - template - using DynamicVectorAccessible_t = VectorAccessible_t; - - /// Matrix can be accessed with dynamic indices. See \ref MatrixAccessible_t - template - using DynamicMatrixAccessible_t = MatrixAccessible_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 - 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 - 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 - 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 - 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 - 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 - implementation-defined hybridCols(Matrix const& mat); -#else - - namespace Impl - { - template ::value)> - auto hybrid_size(Vector const& vec, Dune::PriorityTag<2>) - -> decltype(vec.size()) { return vec.size(); } - - template ::value)> - auto hybrid_size(Vector const& vec, Dune::PriorityTag<1>) - -> decltype(size(vec)) { return size(vec); } - - template - auto hybrid_size(Vector const& vec, Dune::PriorityTag<0>) - { - return AMDiS::static_size(vec); - } - - } // end namespace Impl - - template - auto hybrid_size(Vector const& vec) - { - return Impl::hybrid_size(vec, Dune::PriorityTag<42>{}); - } - - template - auto hybridElements(Vector const& vec) - { - return Dune::range(hybrid_size(vec)); - } - - - namespace Impl - { - template ::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<5>) - -> decltype(mat.num_rows()) { return mat.num_rows(); } - - template ::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<4>) - -> decltype(mat.N()) { return mat.N(); } - - template ::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<3>) - -> decltype(mat.rows()) { return mat.rows(); } - - template ::value)> - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<2>) - -> decltype(num_rows(mat)) { return num_rows(mat); } - - template - auto hybrid_num_rows(Matrix const& mat, Dune::PriorityTag<0>) - { - return AMDiS::static_num_rows(mat); - } - - } // end namespace Impl - - template - auto hybrid_num_rows(Matrix const& mat) - { - return Impl::hybrid_num_rows(mat, Dune::PriorityTag<42>{}); - } - - template - auto hybridRows(Matrix const& mat) - { - return Dune::range(hybrid_num_rows(mat)); - } - - - namespace Impl - { - template ::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<5>) - -> decltype(mat.num_rows()) { return mat.num_cols(); } - - template ::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<4>) - -> decltype(mat.M()) { return mat.M(); } - - template ::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<3>) - -> decltype(mat.cols()) { return mat.cols(); } - - template ::value)> - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<2>) - -> decltype(num_cols(mat)) { return num_cols(mat); } - - template - auto hybrid_num_cols(Matrix const& mat, Dune::PriorityTag<0>) - { - return AMDiS::static_num_cols(mat); - } - - } // end namespace Impl - - template - auto hybrid_num_cols(Matrix const& mat) - { - return Impl::hybrid_num_cols(mat, Dune::PriorityTag<42>{}); - } - - template - auto hybridCols(Matrix const& mat) - { - return Dune::range(hybrid_num_cols(mat)); - } - -#endif // DOXYGEN - -} // end namespace AMDiS diff --git a/test/AccessTest.cpp b/test/AccessTest.cpp deleted file mode 100644 index fe35b438..00000000 --- a/test/AccessTest.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include - -#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::value, ""); - static_assert(Concepts::VectorAccessible_t::value, ""); - static_assert(Concepts::VectorAccessible_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::value, ""); - static_assert(Concepts::MatrixAccessible_t::value, ""); - static_assert(Concepts::MatrixAccessible_t::value, ""); - - NotAccessible notAccessible; - auto k1 = access(notAccessible,1); - auto k2 = access(notAccessible,1,1); - static_assert(std::is_same::value, ""); - static_assert(std::is_same::value, ""); - - static_assert(not Concepts::VectorAccessible_t::value, ""); - static_assert(not Concepts::MatrixAccessible_t::value, ""); - - return 0; -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ddbc3c4c..e6f6ec32 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 diff --git a/test/HybridSizeTest.cpp b/test/HybridSizeTest.cpp deleted file mode 100644 index 7fbc9006..00000000 --- a/test/HybridSizeTest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include - -#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 - int operator[](index_t) 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 - int operator()(index_t, index_t) 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/ResizeTest.cpp b/test/ResizeTest.cpp deleted file mode 100644 index f6f0511d..00000000 --- a/test/ResizeTest.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include - -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::value, ""); - static_assert(Concepts::VectorResizable_t::value, ""); - static_assert(Concepts::VectorResizable_t::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::value, ""); - static_assert(Concepts::MatrixResizable_t::value, ""); - static_assert(Concepts::MatrixResizable_t::value, ""); - static_assert(Concepts::MatrixResizable_t::value, ""); - - NotResizable notResizable; - resize(notResizable,1); - resize(notResizable,1,1); - - static_assert(not Concepts::VectorResizable_t::value, ""); - static_assert(not Concepts::MatrixResizable_t::value, ""); - - return 0; -} -- GitLab From 9e24fd1796c8b73affd7c36eb8d1fdf38ca1b043 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Sat, 8 Feb 2020 22:47:09 +0100 Subject: [PATCH 2/4] removed Resize and MultiTypeContainers --- src/amdis/common/CMakeLists.txt | 2 - src/amdis/common/MultiTypeMatrix.hpp | 158 --------------------------- src/amdis/common/MultiTypeVector.hpp | 141 ------------------------ src/amdis/common/Resize.hpp | 124 --------------------- src/amdis/typetree/RangeType.hpp | 18 ++- test/CMakeLists.txt | 9 -- test/MultiTypeMatrixTest.cpp | 46 -------- test/MultiTypeVectorTest.cpp | 84 -------------- test/RangeTypeTest.cpp | 2 +- 9 files changed, 16 insertions(+), 568 deletions(-) delete mode 100644 src/amdis/common/MultiTypeMatrix.hpp delete mode 100644 src/amdis/common/MultiTypeVector.hpp delete mode 100644 src/amdis/common/Resize.hpp delete mode 100644 test/MultiTypeMatrixTest.cpp delete mode 100644 test/MultiTypeVectorTest.cpp diff --git a/src/amdis/common/CMakeLists.txt b/src/amdis/common/CMakeLists.txt index f34d89aa..fc7b8788 100644 --- a/src/amdis/common/CMakeLists.txt +++ b/src/amdis/common/CMakeLists.txt @@ -22,8 +22,6 @@ install(FILES Literals.hpp Logical.hpp Math.hpp - MultiTypeMatrix.hpp - MultiTypeVector.hpp Range.hpp QuadMath.hpp SharedPtr.hpp diff --git a/src/amdis/common/MultiTypeMatrix.hpp b/src/amdis/common/MultiTypeMatrix.hpp deleted file mode 100644 index a3a56828..00000000 --- a/src/amdis/common/MultiTypeMatrix.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AMDiS -{ - // forward declaration - template - class MultiTypeMatrix; -} - -namespace Dune -{ - template - struct FieldTraits> - { - using field_type = std::common_type_t::field_type...>; - using real_type = std::common_type_t::real_type...>; - }; -} - - -namespace AMDiS -{ - // Rows should be of type MultiTypeVector - template - class MultiTypeMatrix - : public std::tuple - { - using Self = MultiTypeMatrix; - using Super = std::tuple; - - static_assert(IsEqual::value, - "All columns must have the same length."); - - public: - using field_type = typename Dune::FieldTraits::field_type; - using real_type = typename Dune::FieldTraits::real_type; - using size_type = std::size_t; - - static constexpr int rows = std::tuple_size::value; - static constexpr int cols = Math::max(Rows::dimension...); - - template , Types> )> - 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 - decltype(auto) operator()(index_t const i, index_t const j) const - { - return (*this)[i][j]; - } - - /// Mutable access to the tuple elements - template - decltype(auto) operator()(index_t const i, index_t const j) - { - return (*this)[i][j]; - } - - - /// Const access to the rows - template - decltype(auto) operator[](index_t const) const - { - return std::get(as_tuple()); - } - - /// Mutable access to the rows - template - decltype(auto) operator[](index_t const) - { - return std::get(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& as_tuple() { return *this; } - std::tuple 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 72345347..00000000 --- a/src/amdis/common/MultiTypeVector.hpp +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace AMDiS -{ - // forward declaration - template - class MultiTypeVector; -} - -namespace Dune -{ - template - struct FieldTraits> - { - using field_type = std::common_type_t::field_type...>; - using real_type = std::common_type_t::real_type...>; - }; -} - - -namespace AMDiS -{ - template - class MultiTypeVector - : public std::tuple - { - using Self = MultiTypeVector; - using Super = std::tuple; - - public: - using field_type = typename Dune::FieldTraits::field_type; - using real_type = typename Dune::FieldTraits::real_type; - using size_type = std::size_t; - - static constexpr int dimension = std::tuple_size::value; - - template , Types> )> - 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 - decltype(auto) operator[](index_t const) const - { - return std::get(as_tuple()); - } - - /// Mutable access to the tuple elements - template - decltype(auto) operator[](index_t const) - { - return std::get(as_tuple()); - } - - /// Const access to the vector using multi-indices - template )> - decltype(auto) operator[](Index const& index) const - { - return Dune::Functions::hybridMultiIndexAccess(*this, index); - } - - /// Mutable access to the vector using multi-indices - template )> - decltype(auto) operator[](Index const& index) - { - return Dune::Functions::hybridMultiIndexAccess(*this, index); - } - - /// Return number of elements of the tuple - static constexpr std::size_t size() - { - return dimension; - } - - private: - std::tuple& as_tuple() { return *this; } - std::tuple 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 a894792c..00000000 --- a/src/amdis/common/Resize.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#pragma once - -#include - -#include -#include - -namespace AMDiS -{ - namespace Concepts - { - namespace Definition - { - struct VectorResizable - { - template - auto require(V const& vec, Dune::PriorityTag<2>) -> decltype( const_cast(vec).resize(0u), 0); - - template - auto require(V const& vec, Dune::PriorityTag<1>) -> decltype( const_cast(vec).change_dim(0u), 0); - }; - - struct MatrixResizable - { - template - auto require(M const& mat, Dune::PriorityTag<3>) -> decltype( const_cast(mat).resize(0u,0u), 0); - - template - auto require(M const& mat, Dune::PriorityTag<2>) -> decltype( const_cast(mat).change_dim(0u,0u), 0); - - template - auto require(M const& mat, Dune::PriorityTag<1>) -> decltype( const_cast(mat).setSize(0u,0u), 0); - }; - } - - /// Checks whether a vector can be resized by various resize methods - template - using VectorResizable_t = models_t)>; - - /// Checks whether a matrix can be resized by various resize methods - template - using MatrixResizable_t = models_t)>; - - } // end namespace Concepts - -#ifdef DOXYGEN - /// \brief Uniform vector resize, using either vector.resize() or vector.change_dim() - template - void resize(Vector& vec, std::size_t size); - - /// \brief Uniform matrix resize, using either matrix.resize(), matrix.setSize() or matrix.change_dim() - template - void resize(Matrix& mat, std::size_t r, std::size_t c); -#else - - namespace Impl - { - template ().resize(0u))> > - void resize_impl(Vector& vec, std::size_t size, Dune::PriorityTag<2>) - { - vec.resize(size); - } - - template ().change_dim(0u))> > - void resize_impl(Vector& vec, std::size_t size, Dune::PriorityTag<1>) - { - vec.change_dim(size); - } - - template - void resize_impl(Vector& /*vec*/, std::size_t /*size*/, Dune::PriorityTag<0>) - { - /* do nothing */ - } - } - - template - void resize(Vector& vec, std::size_t size) - { - Impl::resize_impl(vec, size, Dune::PriorityTag<42>{}); - } - - - namespace Impl - { - template ().resize(0u,0u))> > - void resize_impl(Matrix& mat, std::size_t rows, std::size_t cols, Dune::PriorityTag<3>) - { - mat.resize(rows, cols); - } - - template ().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 ().setSize(0u,0u))> > - void resize_impl(Matrix& mat, std::size_t rows, std::size_t cols, Dune::PriorityTag<1>) - { - mat.setSize(rows, cols); - } - - template - void resize_impl(Matrix& /*mat*/, std::size_t /*rows*/, std::size_t /*cols*/, Dune::PriorityTag<0>) - { - /* do nothing */ - } - } - - template - 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/typetree/RangeType.hpp b/src/amdis/typetree/RangeType.hpp index 38b2ecec..0c3faf78 100644 --- a/src/amdis/typetree/RangeType.hpp +++ b/src/amdis/typetree/RangeType.hpp @@ -4,9 +4,21 @@ #include #include +#include #include -#include +#include +#include + +namespace Dune +{ + template + struct FieldTraits> + { + using field_type = std::common_type_t::field_type...>; + using real_type = std::common_type_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 using ChildNode = typename Node::template Child::type; - using type = MultiTypeVector,R>...>; + using type = Dune::TupleVector,R>...>; }; using type = typename RangeTypeGenerator>::type; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e6f6ec32..a6b8c864 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -84,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) @@ -136,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/MultiTypeMatrixTest.cpp b/test/MultiTypeMatrixTest.cpp deleted file mode 100644 index 0b81d2d5..00000000 --- a/test/MultiTypeMatrixTest.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -using namespace AMDiS; - -int main() -{ - using V0 = MultiTypeVector, FieldMatrix>; - using V1 = MultiTypeVector, FieldMatrix>; - using M = MultiTypeMatrix; - - // 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 77ceea5a..00000000 --- a/test/MultiTypeVectorTest.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include - -#include "Tests.hpp" - -using namespace AMDiS; -using namespace Dune::Indices; - -int main() -{ - using F2 = FieldVector; - using F3 = FieldVector; - using V = MultiTypeVector; - - // 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 index{1,1}; - v1[index] = 2.0; - AMDIS_TEST( v1[_1][1] == 2.0 ); - - using FV = FieldVector; - using W0 = MultiTypeVector; - using W = MultiTypeVector; - 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 2ba3071f..7ded146a 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>; + using NodeRange = Dune::TupleVector, FieldVector>; static_assert( std::is_same>::value, "" ); auto v_node = TypeTree::child(node, _0); -- GitLab From fe42c84f8bcda6060f08e910485ec77f2ca62193 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Sat, 8 Feb 2020 23:11:06 +0100 Subject: [PATCH 3/4] removed multiIndexPushFront function --- src/amdis/typetree/MultiIndex.hpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/amdis/typetree/MultiIndex.hpp b/src/amdis/typetree/MultiIndex.hpp index 3ef8048f..b148d9ab 100644 --- a/src/amdis/typetree/MultiIndex.hpp +++ b/src/amdis/typetree/MultiIndex.hpp @@ -35,13 +35,4 @@ namespace AMDiS return idx[0]; } - template - 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 -- GitLab From f2abb0142c88709159d3526af3d131d5fec724dd Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Sat, 8 Feb 2020 23:12:14 +0100 Subject: [PATCH 4/4] remove type-erased SizeInfo --- src/amdis/functions/CMakeLists.txt | 1 - src/amdis/functions/SizeInfo.hpp | 89 ------------------------------ 2 files changed, 90 deletions(-) delete mode 100644 src/amdis/functions/SizeInfo.hpp diff --git a/src/amdis/functions/CMakeLists.txt b/src/amdis/functions/CMakeLists.txt index c8ef3913..73697b63 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 5f1d2777..00000000 --- a/src/amdis/functions/SizeInfo.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include - -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 - { - using Super = std::vector; - - public: - SizePrefix() = default; - - // Constructor copies the content of the passed container to the internal storage - template = 0, - Dune::disableCopyMove = 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(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 ()(std::declval()))> > - 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_; - std::function dimension_; - }; -} \ No newline at end of file -- GitLab