Skip to content

File su2dotter.h

File List > algebra > su2algebra > su2dotter.h

Go to the documentation of this file

#ifndef TEMPLAT_LATTICE_ALGEBRA_SU2ALGEBRA_SU2DOTTER_H
#define TEMPLAT_LATTICE_ALGEBRA_SU2ALGEBRA_SU2DOTTER_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): Franz R. Sattler, Year: 2026

#include "TempLat/lattice/algebra/operators/binaryoperator.h"
#include "TempLat/lattice/algebra/helpers/doeval.h"
#include "TempLat/lattice/algebra/helpers/isvariadicindex.h"
#include "TempLat/lattice/algebra/su2algebra/helpers/hassu2get.h"
#include "TempLat/parallel/device.h"

namespace TempLat
{
  template <typename R, typename T> class SU2Dotter : public BinaryOperator<R, T>
  {
  public:
    using BinaryOperator<R, T>::mR;
    using BinaryOperator<R, T>::mT;

    SU2Dotter(const R &pR, const T &pT) : BinaryOperator<R, T>(pR, pT) {}

    template <typename... IDX>
      requires requires(std::decay_t<R> r, std::decay_t<T> t, IDX... idx) {
        requires IsVariadicIndex<IDX...>;
        DoEval::eval(r, idx...);
        DoEval::eval(t, idx...);
      }
    DEVICE_INLINE_FUNCTION auto eval(const IDX &...idx) const
    {
      const auto rr = DoEval::eval(mR, idx...);
      const auto tt = DoEval::eval(mT, idx...);
      return rr[1] * tt[1] + rr[2] * tt[2] + rr[3] * tt[3];
    }

    virtual std::string operatorString() const override { return "ยท"; }
  };

  template <class R, class T>
    requires(HasSU2Get<R> && HasSU2Get<T>)
  auto su2dotter(const R &r, const T &t)
  {
    return SU2Dotter<R, T>(r, t);
  }
} // namespace TempLat

#endif