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

Merge branch 'issue/clamp_operations' into 'develop'

Issue/clamp operations

See merge request !50
parents 71cbbe25 4ac29286
Pipeline #1382 passed with stage
in 26 minutes and 9 seconds
......@@ -88,6 +88,14 @@ namespace AMDiS
return invokeAtQP(Operation::AbsMin{}, std::forward<Lhs>(lhs), std::forward<Rhs>(rhs));
}
/// \brief Applies \ref Operation::Clamp to GridFunction. \relates FunctorGridFunction
template <class V, class T,
REQUIRES(Concepts::AnyGridFunction<V>)>
auto clamp(V&& v, T const& lo, T const& hi)
{
return invokeAtQP(Operation::Clamp<T>{lo,hi}, std::forward<V>(v));
}
/// \brief Applies \ref Operation::Sqr to GridFunction. \relates FunctorGridFunction
template <class T,
REQUIRES(Concepts::AnyGridFunction<T>)>
......
......@@ -169,9 +169,27 @@ namespace AMDiS
// -------------------------------------------------------------------------
// forward declaration
template <int p>
struct PowImpl;
template <int p>
struct PowType
{
using type = PowImpl<p>;
};
template <> struct PowType<1> { using type = Id; };
template <> struct PowType<0> { using type = One; };
template <int p>
using Pow = typename PowType<p>::type;
using Sqr = Pow<2>;
/// Functor that represents x^p
template <int p>
struct Pow
struct PowImpl
{
static_assert(p > 1, "Exponent in power must be non-negative!");
......@@ -181,29 +199,17 @@ namespace AMDiS
return Math::pow<p>(x);
}
friend int order(Pow, int d)
friend int order(PowImpl, int d)
{
return p*d;
}
friend auto partial(Pow, index_t<0>)
friend auto partial(PowImpl, index_t<0>)
{
return compose(Multiplies{}, StaticConstant<int,p>{}, Pow<p-1>{});
}
};
using Sqr = Pow<2>;
/// \see Pow
template <>
struct Pow<1>
: public Id {};
/// \see Pow
template <>
struct Pow<0>
: public Zero {};
/// Functor that represents x^p, \see \ref Pow
struct Pow_
{
......
......@@ -117,6 +117,40 @@ namespace AMDiS
}
};
template <class T>
struct Clamp
{
Clamp(T const& lo, T const& hi)
: lo_(lo)
, hi_(hi)
{
assert(lo < hi);
}
constexpr auto operator() (T const& v) const
{
return v < lo_ ? lo_ : hi_ < v ? hi_ : v;
}
struct DClamp
{
constexpr auto operator() (T const& v) const
{
return v < lo_ ? T(0) : hi_ < v ? T(0) : T(1);
}
T lo_, hi_;
};
constexpr friend auto partial(Clamp c, index_t<0>)
{
return DClamp{c.lo_,c.hi_};
}
T lo_, hi_;
};
/** @} **/
} // end namespace Operation
......
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