File heavisidestepfunction.h
File List > algebra > operators > heavisidestepfunction.h
Go to the documentation of this file
#ifndef TEMPLAT_LATTICE_ALGEBRA_OPERATORS_HEAVISIDESTEPFUNCTION_H
#define TEMPLAT_LATTICE_ALGEBRA_OPERATORS_HEAVISIDESTEPFUNCTION_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Wessel Valkenburg, Year: 2019
#include "TempLat/lattice/algebra/conditional/conditionalunarygetter.h"
#include "TempLat/lattice/algebra/helpers/getderiv.h"
#include "TempLat/lattice/algebra/operators/diracdeltafunction.h"
#include "TempLat/lattice/algebra/operators/unaryoperator.h"
#include "TempLat/lattice/algebra/constants/onetype.h"
#include "TempLat/lattice/algebra/constants/zerotype.h"
namespace TempLat
{
template <typename R> class HeavisideStepFunction : public UnaryOperator<R>
{
public:
using UnaryOperator<R>::mR;
HeavisideStepFunction(const R &pR) : UnaryOperator<R>(pR) {}
template <typename... IDX>
requires requires(std::decay_t<R> r, IDX... idx) {
requires IsVariadicIndex<IDX...>;
DoEval::eval(r, idx...);
}
DEVICE_INLINE_FUNCTION auto eval(const IDX &...idx) const
{
return (DoEval::eval(mR, idx...) >= 0 ? 1 : 0);
}
template <typename U> auto d(const U &other) { return GetDeriv::get(mR, other) * DiracDelta(mR); }
virtual std::string operatorString() const override { return "Heaviside"; }
};
template <typename R>
requires ConditionalUnaryGetter<R>
auto heaviside(const R &r)
{
return HeavisideStepFunction<R>(r);
}
constexpr inline OneType heaviside(ZeroType a) { return {}; }
constexpr inline OneType heaviside(OneType a) { return {}; }
} // namespace TempLat
#endif