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 @@
#include <amdis/AMDiS.hpp>
#include <amdis/ProblemStat.hpp>
#include <amdis/Operators.hpp>
#include <amdis/common/FieldMatVec.hpp>
#include <amdis/common/Literals.hpp>
#include <amdis/gridfunctions/Integrate.hpp>
......
#pragma once
#include <type_traits>
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <amdis/common/ConceptsBase.hpp>
#include <amdis/common/ScalarTypes.hpp>
namespace AMDiS
namespace Dune
{
using Dune::FieldVector;
using Dune::FieldMatrix;
// some arithmetic operations with FieldVector
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);
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);
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);
template <class T>
......@@ -50,7 +46,7 @@ namespace AMDiS
auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2);
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);
template <class T, class S, int N>
......@@ -198,15 +194,15 @@ namespace AMDiS
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);
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);
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);
......@@ -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);
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"
......@@ -9,26 +9,26 @@
#ifndef DOXYGEN
namespace AMDiS {
namespace Dune {
// some arithmetic operations with FieldVector
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)
{
return v *= factor;
}
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)
{
return v *= factor;
}
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)
{
return v /= factor;
......@@ -78,7 +78,7 @@ auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2)
}
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)
{
static_assert(M == N, "Requires vectors of the same type!");
......@@ -117,13 +117,13 @@ namespace Impl
template <class T, int N>
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>
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)
template <class T, int N>
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);
}
template <class T, int N>
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);
}
......@@ -146,52 +146,52 @@ auto unary_dot(FieldMatrix<T, 1, N> const& x)
template <class T, int N>
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>
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
template <class T, int N>
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>
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
template <class T, int N>
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>
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
template <class T, int N>
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>
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)
template <int p, class T, int N>
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 );
}
template <int p, class T, int N>
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 );
}
......@@ -268,7 +268,7 @@ T distance(FieldVector<T, N> const& lhs, FieldVector<T, N> const& rhs)
{
T result = 0;
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);
}
......@@ -371,21 +371,21 @@ FieldMatrix<T,N,M> trans(FieldMatrix<T, M, N> const& A)
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)
{
return A *= scalar;
}
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)
{
return A *= scalar;
}
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)
{
return A /= scalar;
......@@ -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>
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 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