File wavenumber.h
File List > algebra > coordinates > wavenumber.h
Go to the documentation of this file
#ifndef TEMPLAT_LATTICE_ALGEBRA_COORDINATES_WAVENUMBER_H
#define TEMPLAT_LATTICE_ALGEBRA_COORDINATES_WAVENUMBER_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, Franz R. Sattler, Year: 2025
#include "TempLat/lattice/algebra/helpers/isvariadicindex.h"
#include "TempLat/util/exception.h"
#include "TempLat/lattice/memory/memorytoolbox.h"
#include "TempLat/lattice/algebra/operators/operators.h"
#include "TempLat/lattice/algebra/listoperators/vectordotter.h"
#include "TempLat/lattice/algebra/helpers/getvectorcomponent.h"
#include "TempLat/util/rangeiteration/tag.h"
namespace TempLat
{
MakeException(WaveNumberWrongSpaceConfirmation);
template <size_t NDim> class WaveNumber /*: public Vector*/
{
public:
// Put public methods here. These should change very little over time.
WaveNumber(device::memory::host_ptr<MemoryToolBox<NDim>> toolBox)
: mLayout(toolBox->mLayouts.getFourierSpaceLayout())
{
}
constexpr static size_t getVectorSize() { return NDim; }
template <typename... IDX>
requires IsVariadicNDIndex<NDim, IDX...>
DEVICE_INLINE_FUNCTION auto eval(const IDX &...idx) const
{
device::IdxArray<NDim> result;
mLayout.putSpatialLocationFromMemoryIndexInto(result, idx...);
return result;
}
template <int N> auto vectorGet(Tag<N> t) const
{
static_assert(N > 0 && N <= NDim, "VectorGet: N must be between 1 and NDim for WaveNumber");
return getVectorComponent(*this, Tag<N - 1>());
}
template <int N> auto operator()(Tag<N> t) const
{
static_assert(N > 0 && N <= NDim, "Operator(): N must be between 1 and NDim for WaveNumber");
return vectorGet(t);
}
auto norm2() const { return dot(*this, *this); }
auto norm() const { return sqrt(dot(*this, *this)); }
static std::string toString(device::Idx j) { return "k_" + std::to_string(j); }
static std::string toString() { return "k"; }
void confirmSpace(device::Idx i, const LayoutStruct<NDim> &newLayout, const SpaceStateType &spaceType) const
{
switch (spaceType) {
case SpaceStateType::Configuration:
throw WaveNumberWrongSpaceConfirmation("WaveNumber explicitly only can be used in fourier space. Abort.");
break;
case SpaceStateType::Fourier:
default:
break;
}
}
private:
/* Put all member variables and private methods here. These may change arbitrarily. */
LayoutStruct<NDim> mLayout;
};
template <size_t NDim> using FourierSite = WaveNumber<NDim>;
} // namespace TempLat
#endif