From dcbeb47a3b589d8bf2b66ac0cf20b2b58916044e Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon.praetorius@tu-dresden.de> Date: Thu, 15 Nov 2018 22:03:26 -0500 Subject: [PATCH] determine order of divides grid-function of second argument is constant --- .../gridfunctions/ConstantGridFunction.hpp | 2 +- .../gridfunctions/CoordsGridFunction.hpp | 4 ++-- .../gridfunctions/OperationsGridFunction.hpp | 21 +++++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/amdis/gridfunctions/ConstantGridFunction.hpp b/src/amdis/gridfunctions/ConstantGridFunction.hpp index 8d76d2fa..cbecac12 100644 --- a/src/amdis/gridfunctions/ConstantGridFunction.hpp +++ b/src/amdis/gridfunctions/ConstantGridFunction.hpp @@ -82,7 +82,7 @@ namespace AMDiS template <class R, class D, class LocalContext, class T> int order(ConstantLocalFunction<R(D), LocalContext, T> const& lf) { - return lf.order(); + return 0; } diff --git a/src/amdis/gridfunctions/CoordsGridFunction.hpp b/src/amdis/gridfunctions/CoordsGridFunction.hpp index 2c0e7a08..28965dff 100644 --- a/src/amdis/gridfunctions/CoordsGridFunction.hpp +++ b/src/amdis/gridfunctions/CoordsGridFunction.hpp @@ -35,7 +35,7 @@ namespace AMDiS return x; } - friend int order(Self const& /*f*/, int /*d*/) + friend int order(CoordsFunction /*f*/, int /*d*/) { return 1; } @@ -81,7 +81,7 @@ namespace AMDiS return x[comp_]; } - friend int order(Self const& /*f*/, int /*d*/) + friend int order(CoordsCompFunction /*f*/, int /*d*/) { return 1; } diff --git a/src/amdis/gridfunctions/OperationsGridFunction.hpp b/src/amdis/gridfunctions/OperationsGridFunction.hpp index 15efa20d..425d5d68 100644 --- a/src/amdis/gridfunctions/OperationsGridFunction.hpp +++ b/src/amdis/gridfunctions/OperationsGridFunction.hpp @@ -16,7 +16,7 @@ namespace AMDiS // @{ /// \brief Applies \ref Operation::Negate to GridFunctions. \relates FunctorGridFunction - template <class Lhs, class Rhs, + template <class Lhs, REQUIRES(Concepts::AnyGridFunction<Lhs>)> auto operator-(Lhs&& lhs) { @@ -47,12 +47,29 @@ namespace AMDiS return invokeAtQP(Operation::Multiplies{}, std::forward<Lhs>(lhs), std::forward<Rhs>(rhs)); } + namespace Impl + { + template <class Lhs, class Value, + REQUIRES(Concepts::ConstantToGridFunction<Value>)> + auto divideAtQP(Lhs&& lhs, Value value) + { + return invokeAtQP(Operation::Multiplies{}, std::forward<Lhs>(lhs), 1.0/value); + } + + template <class Lhs, class Rhs, + REQUIRES(not Concepts::ConstantToGridFunction<std::decay_t<Rhs>>)> + auto divideAtQP(Lhs&& lhs, Rhs&& rhs) + { + return invokeAtQP(Operation::Divides{}, std::forward<Lhs>(lhs), std::forward<Rhs>(rhs)); + } + } + /// \brief Applies \ref Operation::Divides to GridFunctions. \relates FunctorGridFunction template <class Lhs, class Rhs, REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)> auto operator/(Lhs&& lhs, Rhs&& rhs) { - return invokeAtQP(Operation::Divides{}, std::forward<Lhs>(lhs), std::forward<Rhs>(rhs)); + return Impl::divideAtQP(std::forward<Lhs>(lhs), std::forward<Rhs>(rhs)); } -- GitLab