Skip to content

File diracdeltafunction.h

File List > algebra > operators > diracdeltafunction.h

Go to the documentation of this file

#ifndef TEMPLAT_LATTICE_ALGEBRA_OPERATORS_DIRACDELTAFUNCTION_H
#define TEMPLAT_LATTICE_ALGEBRA_OPERATORS_DIRACDELTAFUNCTION_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/helpers/getgetreturntype.h"
// #include "TempLat/lattice/algebra/constants/positiveinfinitytype.h"
#include "TempLat/lattice/algebra/operators/unaryoperator.h"

namespace TempLat
{
  namespace Operators
  {
    template <typename R> class DiracDeltaFunction : public UnaryOperator<R>
    {
    public:
      using UnaryOperator<R>::mR;

      DiracDeltaFunction(const R &a) : UnaryOperator<R>(a) {}

      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
      {
        using mType = typename GetGetReturnType<R>::type;
        const mType objValue = DoEval::eval(mR, idx...);
        const bool isZero = objValue == mType{};
        return isZero ? std::numeric_limits<mType>::max() : mType{};
      }

      template <typename U> void d(const U &other) = delete;
      //            {
      //                return GetDeriv::get(mInstanceT, other) * DiracDelta(mInstanceT);
      //            }

      virtual std::string operatorString() const override { return "DiracDelta"; }
    };
  } // namespace Operators

  template <typename T> Operators::DiracDeltaFunction<T> DiracDelta(const T &a)
  {
    return Operators::DiracDeltaFunction<T>(a);
  }
} // namespace TempLat
#endif