Commit e905780f authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'issue/remove_unnecessary_headers' into 'master'

removed some headers from amdis and moved them to independent repository dune-blocked

See merge request !158
parents 5c9749d2 985c10d3
#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
......@@ -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
......
#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
#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
#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)
{