#pragma once #include #include #include #include #include #include namespace AMDiS { namespace Operation { /** \addtogroup operations * @{ **/ /// A functor that evaluates to the global coordinates struct CoordsFunction { using Self = CoordsFunction; struct Creator { template static auto create(Self const& f, GridView const& gridView) { return AnalyticGridFunction{f, gridView}; } }; template Dune::FieldVector const& operator()(Dune::FieldVector const& x) const { return x; } friend int order(CoordsFunction /*f*/, int /*d*/) { return 1; } struct Derivative { template Dune::DiagonalMatrix const& operator()(Dune::FieldVector const& x) const { return Dune::DiagonalMatrix{T(1)}; } }; friend Derivative derivative(CoordsFunction const& /*f*/, tag::gradient) { return Derivative{}; } }; /// A functor that evaluates to a component of the global coordinates struct CoordsCompFunction { using Self = CoordsCompFunction; struct Creator { template static auto create(Self const& f, GridView const& gridView) { return AnalyticGridFunction{f, gridView}; } }; public: /// Constructor. Stores the component comp of the coordinates. explicit CoordsCompFunction(int comp) : comp_(comp) {} template T const& operator()(Dune::FieldVector const& x) const { return x[comp_]; } friend int order(CoordsCompFunction /*f*/, int /*d*/) { return 1; } struct Derivative { explicit Derivative(int comp) : comp_(comp) {} template Dune::FieldVector operator()(Dune::FieldVector const& x) const { Dune::FieldVector result(0); result[comp_] = T(1); return result; } private: int comp_; }; friend Derivative derivative(Self const& f, tag::gradient) { return Derivative{f.comp_}; } private: int comp_; }; /** @} **/ } // end namespace Operation /// Generator for \ref CoordsFunction inline auto X() { return Operation::CoordsFunction{}; } /// Generator for \ref CoordsCompFunction inline auto X(int comp) { return Operation::CoordsCompFunction{comp}; } namespace Traits { template <> struct IsPreGridFunction : std::true_type {}; template <> struct IsPreGridFunction : std::true_type {}; } } // end namespace AMDiS