Skip to content

File unaryoperator.h

File List > algebra > operators > unaryoperator.h

Go to the documentation of this file

#ifndef TEMPLAT_LATTICE_ALGEBRA_UNARYOPERATOR_H
#define TEMPLAT_LATTICE_ALGEBRA_UNARYOPERATOR_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/doeval.h"
#include "TempLat/lattice/algebra/helpers/getstring.h"
#include "TempLat/util/containsspace.h"
#include "TempLat/lattice/algebra/helpers/getderiv.h"
#include "TempLat/lattice/algebra/helpers/confirmghosts.h"
#include "TempLat/lattice/algebra/helpers/confirmspace.h"

#include "TempLat/lattice/algebra/helpers/preget.h"
#include "TempLat/lattice/algebra/helpers/postget.h"

#include "TempLat/lattice/algebra/helpers/getndim.h"
#include "TempLat/lattice/algebra/helpers/getdx.h"
#include "TempLat/lattice/algebra/helpers/getfloattype.h"
#include "TempLat/lattice/algebra/helpers/getgetreturntype.h"
#include "TempLat/lattice/algebra/helpers/getkir.h"
#include "TempLat/lattice/algebra/helpers/ghostshunter.h"
#include "TempLat/lattice/algebra/spacestateinterface.h"
#include "TempLat/lattice/memory/memorylayouts/layoutstruct.h"

#include "TempLat/parallel/device.h"

// #include "TempLat/lattice/algebra/conditional/conditionalunarygetter.h"

namespace TempLat
{
  template <typename R> class UnaryOperator
  {
  public:
    UnaryOperator(const R &pR) : mR(pR) {}

    static consteval size_t getNDim() { return GetNDim::get<R>(); }

    void doWeNeedGhosts() const { GhostsHunter::apply(mR); }

    void preGet() { PreGet::apply(mR); }

    void postGet() { PostGet::apply(mR); }

    device::Idx confirmGhostsUpToDate() const { return ConfirmGhosts::apply(mR); }

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

    auto getToolBox() const { return GetToolBox::get(mR); }

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

    auto getDx() const { return GetDx::getDx(mR); }
    auto getKIR() const { return GetKIR::getKIR(mR); }

    std::string toString() const
    {
      std::string result = GetString::get(mR);
      if (ContainsSpace::test(result)) result = "(" + result + ")";

      return operatorString() + result;
    }

  protected:
    R mR;
  };
} // namespace TempLat

#endif