Skip to content

File getvectorcomponent.h

File List > algebra > helpers > getvectorcomponent.h

Go to the documentation of this file

#ifndef TEMPLAT_LATTICE_ALGEBRA_HELPERS_GETVECTORCOMPONENT_H
#define TEMPLAT_LATTICE_ALGEBRA_HELPERS_GETVECTORCOMPONENT_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/helpers/ghostshunter.h"
#include "TempLat/lattice/algebra/helpers/confirmghosts.h"
#include "TempLat/lattice/algebra/helpers/confirmspace.h"
#include "TempLat/lattice/algebra/helpers/gettoolbox.h"

namespace TempLat
{
  template <int N, typename R> class GetVectorComponentHelper
  {
    static_assert(N >= 0, "GetVectorComponentHelper: N must be non-negative");

  public:
    // Put public methods here. These should change very little over time.
    GetVectorComponentHelper(const R &pR) : mR(pR) {}

    template <typename... JDX>
      requires requires(std::decay_t<R> mR, JDX... idx) {
        requires IsVariadicIndex<JDX...>;
        DoEval::eval(mR, idx...);
      }
    DEVICE_INLINE_FUNCTION auto eval(const JDX &...jdx) const
    {
      return DoEval::eval(mR, jdx...)[N];
    }

    void doWeNeedGhosts() const { GhostsHunter::apply(mR, Tag<N>{}); }

    template <size_t NDim> void confirmSpace(const LayoutStruct<NDim> &newLayout, const SpaceStateType &spaceType) const
    {
      ConfirmSpace::apply(mR, Tag<N>{}, newLayout, spaceType);
    }

    device::Idx confirmGhostsUpToDate() const { return ConfirmGhosts::apply(mR, Tag<N>{}); }

    inline auto getToolBox() const
    { // just take toolbox from first component
      return GetToolBox::get(mR);
    }

    std::string toString() const { return mR.toString(N); }

  private:
    /* Put all member variables and private methods here. These may change arbitrarily. */
    R mR;
  };

  template <int N, typename R> GetVectorComponentHelper<N, R> getVectorComponent(const R &pR, Tag<N>)
  {
    return GetVectorComponentHelper<N, R>(pR);
  }
} // namespace TempLat

#endif