Skip to content

File scalarsu2multiplication.h

File List > algebra > su2algebra > scalarsu2multiplication.h

Go to the documentation of this file

#ifndef COSMOINTERFACE_SU2ALGEBRA_COMPLEXFIELDSU2MULTIPLY_H
#define COSMOINTERFACE_SU2ALGEBRA_COMPLEXFIELDSU2MULTIPLY_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): Adrien Florio, Franz R. Sattler, Year: 2025

#include "TempLat/lattice/algebra/complexalgebra/complexwrapper.h"
#include "TempLat/lattice/algebra/complexalgebra/complexfieldmultiply.h"
#include "TempLat/lattice/algebra/helpers/getstring.h"
#include "TempLat/lattice/algebra/su2algebra/helpers/hassu2get.h"
#include "TempLat/util/rangeiteration/tagliteral.h"
#include "TempLat/lattice/algebra/su2algebra/su2binaryoperator.h"
#include "TempLat/parallel/device.h"
#include "TempLat/lattice/algebra/helpers/haseval.h"
#include <type_traits>

namespace TempLat
{
  template <typename R, typename T> class ScalarSU2Multiplication : public SU2BinaryOperator<R, T>
  {
  public:
    // Put public methods here. These should change very little over time.
    using SU2BinaryOperator<R, T>::mR;
    using SU2BinaryOperator<R, T>::mT;

    ScalarSU2Multiplication(const R &pR, const T &pT) : SU2BinaryOperator<R, T>(pR, pT) {}

    using SV = typename SU2GetGetReturnType<T>::type;

    template <int N> auto SU2Get(Tag<N> t) const
    {
      static_assert(N >= 0 && N <= 3, "SU2Get: N must be between 0 and 3 for ScalarSU2Multiplication");
      return mR * mT.SU2Get(t);
    }

    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
    {
      auto su2 = DoEval::eval(mT, idx...);
      const auto scalar = DoEval::eval(mR, idx...);
      su2[0] *= scalar;
      su2[1] *= scalar;
      su2[2] *= scalar;
      su2[3] *= scalar;
      return su2;
    }

    template <int N> auto operator()(Tag<N> t) const { return SU2Get(t); }

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

  template <typename R, typename T>
    requires(HasEvalMethod<R> && HasSU2Get<T> && !HasSU2Get<R>)
  auto operator*(const R &r, const T &t)
  {
    return ScalarSU2Multiplication{r, t};
  }

  template <typename R, typename T>
    requires(HasSU2Get<T> && std::is_arithmetic_v<R>)
  auto operator*(R r, const T &t)
  {
    return ScalarSU2Multiplication{r, t};
  }
} // namespace TempLat

#endif