Commit 99a99ff0 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

moved field-mat-vec operations to namespace Dune

parent 9383e422
Pipeline #1238 failed with stage
in 2 minutes and 35 seconds
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <amdis/AMDiS.hpp> #include <amdis/AMDiS.hpp>
#include <amdis/ProblemStat.hpp> #include <amdis/ProblemStat.hpp>
#include <amdis/Operators.hpp> #include <amdis/Operators.hpp>
#include <amdis/common/FieldMatVec.hpp>
#include <amdis/common/Literals.hpp> #include <amdis/common/Literals.hpp>
#include <amdis/gridfunctions/Integrate.hpp> #include <amdis/gridfunctions/Integrate.hpp>
......
#pragma once #pragma once
#include <type_traits>
#include <dune/common/diagonalmatrix.hh> #include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh> #include <dune/common/fvector.hh>
#include <amdis/common/ConceptsBase.hpp> namespace Dune
#include <amdis/common/ScalarTypes.hpp>
namespace AMDiS
{ {
using Dune::FieldVector;
using Dune::FieldMatrix;
// some arithmetic operations with FieldVector // some arithmetic operations with FieldVector
template <class T, int N, class S, template <class T, int N, class S,
REQUIRES(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
FieldVector<T,N> operator*(FieldVector<T,N> v, S factor); FieldVector<T,N> operator*(FieldVector<T,N> v, S factor);
template <class S, class T, int N, template <class S, class T, int N,
REQUIRES(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
FieldVector<T,N> operator*(S factor, FieldVector<T,N> v); FieldVector<T,N> operator*(S factor, FieldVector<T,N> v);
template <class T, int N, class S, template <class T, int N, class S,
REQUIRES(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
FieldVector<T,N> operator/(FieldVector<T,N> v, S factor); FieldVector<T,N> operator/(FieldVector<T,N> v, S factor);
template <class T> template <class T>
...@@ -50,7 +46,7 @@ namespace AMDiS ...@@ -50,7 +46,7 @@ namespace AMDiS
auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2); auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2);
template <class T, int N, int M, template <class T, int N, int M,
REQUIRES( N!=1 && M!=1 )> std::enable_if_t<( N!=1 && M!=1 ),int> = 0>
auto operator*(FieldVector<T,N> const& v, FieldVector<T,M> const& w); auto operator*(FieldVector<T,N> const& v, FieldVector<T,M> const& w);
template <class T, class S, int N> template <class T, class S, int N>
...@@ -198,15 +194,15 @@ namespace AMDiS ...@@ -198,15 +194,15 @@ namespace AMDiS
template <class T, int M, int N, class S, template <class T, int M, int N, class S,
REQUIRES(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
FieldMatrix<T,M,N> operator*(S scalar, FieldMatrix<T, M, N> A); FieldMatrix<T,M,N> operator*(S scalar, FieldMatrix<T, M, N> A);
template <class T, int M, int N, class S, template <class T, int M, int N, class S,
REQUIRES(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
FieldMatrix<T,M,N> operator*(FieldMatrix<T, M, N> A, S scalar); FieldMatrix<T,M,N> operator*(FieldMatrix<T, M, N> A, S scalar);
template <class T, int M, int N, class S, template <class T, int M, int N, class S,
REQUIRES(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
FieldMatrix<T,M,N> operator/(FieldMatrix<T, M, N> A, S scalar); FieldMatrix<T,M,N> operator/(FieldMatrix<T, M, N> A, S scalar);
...@@ -243,8 +239,14 @@ namespace AMDiS ...@@ -243,8 +239,14 @@ namespace AMDiS
FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, L> const& A, FieldMatrix<T, N, L> const& B, FieldMatrix<T,M,N>& C); FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, L> const& A, FieldMatrix<T, N, L> const& B, FieldMatrix<T,M,N>& C);
template <class T, int M, int N> template <class T, int M, int N>
FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, N> const& A, Dune::DiagonalMatrix<T, N> const& B, FieldMatrix<T,M,N>& C); FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, N> const& A, DiagonalMatrix<T, N> const& B, FieldMatrix<T,M,N>& C);
} // end namespace AMDiS } // end namespace Dune
namespace AMDiS
{
using Dune::FieldMatrix;
using Dune::FieldVector;
}
#include "FieldMatVec.inc.hpp" #include "FieldMatVec.inc.hpp"
...@@ -9,26 +9,26 @@ ...@@ -9,26 +9,26 @@
#ifndef DOXYGEN #ifndef DOXYGEN
namespace AMDiS { namespace Dune {
// some arithmetic operations with FieldVector // some arithmetic operations with FieldVector
template <class T, int N, class S, template <class T, int N, class S,
REQUIRES_(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> >
FieldVector<T,N> operator*(FieldVector<T,N> v, S factor) FieldVector<T,N> operator*(FieldVector<T,N> v, S factor)
{ {
return v *= factor; return v *= factor;
} }
template <class S, class T, int N, template <class S, class T, int N,
REQUIRES_(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> >
FieldVector<T,N> operator*(S factor, FieldVector<T,N> v) FieldVector<T,N> operator*(S factor, FieldVector<T,N> v)
{ {
return v *= factor; return v *= factor;
} }
template <class T, int N, class S, template <class T, int N, class S,
REQUIRES_(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> >
FieldVector<T,N> operator/(FieldVector<T,N> v, S factor) FieldVector<T,N> operator/(FieldVector<T,N> v, S factor)
{ {
return v /= factor; return v /= factor;
...@@ -78,7 +78,7 @@ auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2) ...@@ -78,7 +78,7 @@ auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2)
} }
template <class T, int N, int M, template <class T, int N, int M,
REQUIRES_( N!=1 && M!=1 )> std::enable_if_t<( N!=1 && M!=1 ),int> >
auto operator*(FieldVector<T,N> const& v, FieldVector<T,M> const& w) auto operator*(FieldVector<T,N> const& v, FieldVector<T,M> const& w)
{ {
static_assert(M == N, "Requires vectors of the same type!"); static_assert(M == N, "Requires vectors of the same type!");
...@@ -117,13 +117,13 @@ namespace Impl ...@@ -117,13 +117,13 @@ namespace Impl
template <class T, int N> template <class T, int N>
T sum(FieldVector<T, N> const& x) T sum(FieldVector<T, N> const& x)
{ {
return Impl::accumulate(x, T(0), Operation::Plus{}); return Impl::accumulate(x, T(0), AMDiS::Operation::Plus{});
} }
template <class T, int N> template <class T, int N>
T sum(FieldMatrix<T, 1, N> const& x) T sum(FieldMatrix<T, 1, N> const& x)
{ {
return Impl::accumulate(x, T(0), Operation::Plus{}); return Impl::accumulate(x, T(0), AMDiS::Operation::Plus{});
} }
...@@ -131,14 +131,14 @@ T sum(FieldMatrix<T, 1, N> const& x) ...@@ -131,14 +131,14 @@ T sum(FieldMatrix<T, 1, N> const& x)
template <class T, int N> template <class T, int N>
auto unary_dot(FieldVector<T, N> const& x) auto unary_dot(FieldVector<T, N> const& x)
{ {
auto op = [](auto const& a, auto const& b) { return a + Math::sqr(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + AMDiS::Math::sqr(std::abs(b)); };
return Impl::accumulate(x, T(0), op); return Impl::accumulate(x, T(0), op);
} }
template <class T, int N> template <class T, int N>
auto unary_dot(FieldMatrix<T, 1, N> const& x) auto unary_dot(FieldMatrix<T, 1, N> const& x)
{ {
auto op = [](auto const& a, auto const& b) { return a + Math::sqr(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + AMDiS::Math::sqr(std::abs(b)); };
return Impl::accumulate(x, T(0), op); return Impl::accumulate(x, T(0), op);
} }
...@@ -146,52 +146,52 @@ auto unary_dot(FieldMatrix<T, 1, N> const& x) ...@@ -146,52 +146,52 @@ auto unary_dot(FieldMatrix<T, 1, N> const& x)
template <class T, int N> template <class T, int N>
auto max(FieldVector<T, N> const& x) auto max(FieldVector<T, N> const& x)
{ {
return Impl::accumulate(x, std::numeric_limits<T>::lowest(), Operation::Max{}); return Impl::accumulate(x, std::numeric_limits<T>::lowest(), AMDiS::Operation::Max{});
} }
template <class T, int N> template <class T, int N>
auto max(FieldMatrix<T, 1, N> const& x) auto max(FieldMatrix<T, 1, N> const& x)
{ {
return Impl::accumulate(x, std::numeric_limits<T>::lowest(), Operation::Max{}); return Impl::accumulate(x, std::numeric_limits<T>::lowest(), AMDiS::Operation::Max{});
} }
/// Minimum over all vector entries /// Minimum over all vector entries
template <class T, int N> template <class T, int N>
auto min(FieldVector<T, N> const& x) auto min(FieldVector<T, N> const& x)
{ {
return Impl::accumulate(x, std::numeric_limits<T>::max(), Operation::Min{}); return Impl::accumulate(x, std::numeric_limits<T>::max(), AMDiS::Operation::Min{});
} }
template <class T, int N> template <class T, int N>
auto min(FieldMatrix<T, 1, N> const& x) auto min(FieldMatrix<T, 1, N> const& x)
{ {
return Impl::accumulate(x, std::numeric_limits<T>::max(), Operation::Min{}); return Impl::accumulate(x, std::numeric_limits<T>::max(), AMDiS::Operation::Min{});
} }
/// Maximum of the absolute values of vector entries /// Maximum of the absolute values of vector entries
template <class T, int N> template <class T, int N>
auto abs_max(FieldVector<T, N> const& x) auto abs_max(FieldVector<T, N> const& x)
{ {
return Impl::accumulate(x, T(0), Operation::AbsMax{}); return Impl::accumulate(x, T(0), AMDiS::Operation::AbsMax{});
} }
template <class T, int N> template <class T, int N>
auto abs_max(FieldMatrix<T, 1, N> const& x) auto abs_max(FieldMatrix<T, 1, N> const& x)
{ {
return Impl::accumulate(x, T(0), Operation::AbsMax{}); return Impl::accumulate(x, T(0), AMDiS::Operation::AbsMax{});
} }
/// Minimum of the absolute values of vector entries /// Minimum of the absolute values of vector entries
template <class T, int N> template <class T, int N>
auto abs_min(FieldVector<T, N> const& x) auto abs_min(FieldVector<T, N> const& x)
{ {
return Impl::accumulate(x, std::numeric_limits<T>::max(), Operation::AbsMin{}); return Impl::accumulate(x, std::numeric_limits<T>::max(), AMDiS::Operation::AbsMin{});
} }
template <class T, int N> template <class T, int N>
auto abs_min(FieldMatrix<T, 1, N> const& x) auto abs_min(FieldMatrix<T, 1, N> const& x)
{ {
return Impl::accumulate(x, std::numeric_limits<T>::max(), Operation::AbsMin{}); return Impl::accumulate(x, std::numeric_limits<T>::max(), AMDiS::Operation::AbsMin{});
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -234,14 +234,14 @@ auto two_norm(FieldMatrix<T, 1, N> const& x) ...@@ -234,14 +234,14 @@ auto two_norm(FieldMatrix<T, 1, N> const& x)
template <int p, class T, int N> template <int p, class T, int N>
auto p_norm(FieldVector<T, N> const& x) auto p_norm(FieldVector<T, N> const& x)
{ {
auto op = [](auto const& a, auto const& b) { return a + Math::pow<p>(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + AMDiS::Math::pow<p>(std::abs(b)); };
return std::pow( Impl::accumulate(x, T(0), op), 1.0/p ); return std::pow( Impl::accumulate(x, T(0), op), 1.0/p );
} }
template <int p, class T, int N> template <int p, class T, int N>
auto p_norm(FieldMatrix<T, 1, N> const& x) auto p_norm(FieldMatrix<T, 1, N> const& x)
{ {
auto op = [](auto const& a, auto const& b) { return a + Math::pow<p>(std::abs(b)); }; auto op = [](auto const& a, auto const& b) { return a + AMDiS::Math::pow<p>(std::abs(b)); };
return std::pow( Impl::accumulate(x, T(0), op), 1.0/p ); return std::pow( Impl::accumulate(x, T(0), op), 1.0/p );
} }
...@@ -268,7 +268,7 @@ T distance(FieldVector<T, N> const& lhs, FieldVector<T, N> const& rhs) ...@@ -268,7 +268,7 @@ T distance(FieldVector<T, N> const& lhs, FieldVector<T, N> const& rhs)
{ {
T result = 0; T result = 0;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
result += Math::sqr(lhs[i] - rhs[i]); result += AMDiS::Math::sqr(lhs[i] - rhs[i]);
return std::sqrt(result); return std::sqrt(result);
} }
...@@ -371,21 +371,21 @@ FieldMatrix<T,N,M> trans(FieldMatrix<T, M, N> const& A) ...@@ -371,21 +371,21 @@ FieldMatrix<T,N,M> trans(FieldMatrix<T, M, N> const& A)
template <class T, int M, int N, class S, template <class T, int M, int N, class S,
REQUIRES_(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> >
FieldMatrix<T,M,N> operator*(S scalar, FieldMatrix<T, M, N> A) FieldMatrix<T,M,N> operator*(S scalar, FieldMatrix<T, M, N> A)
{ {
return A *= scalar; return A *= scalar;
} }
template <class T, int M, int N, class S, template <class T, int M, int N, class S,
REQUIRES_(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> >
FieldMatrix<T,M,N> operator*(FieldMatrix<T, M, N> A, S scalar) FieldMatrix<T,M,N> operator*(FieldMatrix<T, M, N> A, S scalar)
{ {
return A *= scalar; return A *= scalar;
} }
template <class T, int M, int N, class S, template <class T, int M, int N, class S,
REQUIRES_(Concepts::Arithmetic<S>) > std::enable_if_t<std::is_arithmetic<S>::value,int> >
FieldMatrix<T,M,N> operator/(FieldMatrix<T, M, N> A, S scalar) FieldMatrix<T,M,N> operator/(FieldMatrix<T, M, N> A, S scalar)
{ {
return A /= scalar; return A /= scalar;
...@@ -476,7 +476,7 @@ FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, L> const& A, FieldMatrix<T ...@@ -476,7 +476,7 @@ FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, L> const& A, FieldMatrix<T
} }
template <class T, int M, int N> template <class T, int M, int N>
FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, N> const& A, Dune::DiagonalMatrix<T, N> const& B, FieldMatrix<T,M,N>& C) FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, N> const& A, DiagonalMatrix<T, N> const& B, FieldMatrix<T,M,N>& C)
{ {
for (int m = 0; m < M; ++m) { for (int m = 0; m < M; ++m) {
for (int n = 0; n < N; ++n) { for (int n = 0; n < N; ++n) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment