Loading...
Searching...
No Matches
analyticgridviewfunction.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_ANALYTICGRIDVIEWFUNCTION_HH
#define DUNE_FUNCTIONS_GRIDFUNCTIONS_ANALYTICGRIDVIEWFUNCTION_HH
#include <type_traits>
#include <optional>
#include <dune/common/copyableoptional.hh>
#include <dune/common/typeutilities.hh>
#include <dune/functions/common/signature.hh>
#include <dune/functions/common/defaultderivativetraits.hh>
#include <dune/functions/common/differentiablefunction_imp.hh>
#include <dune/functions/common/differentiablefunction.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
#include <dune/functions/gridfunctions/localderivativetraits.hh>
namespace Dune {
namespace Functions {
namespace Imp {
template<class Signature, class GV, class FLocal, template<class> class DerivativeTraits=DefaultDerivativeTraits>
class LocalAnalyticGridViewFunction;
template<class Range, class LocalDomain, class GV, class F, template<class> class DerivativeTraits>
class LocalAnalyticGridViewFunction<Range(LocalDomain), GV, F, DerivativeTraits>
{
public:
using Signature = Range(LocalDomain);
using RawSignature = typename SignatureTraits<Signature>::RawSignature;
using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(LocalDomain);
using GridView = GV;
using EntitySet = GridViewEntitySet<GridView, 0>;
using Element = typename EntitySet::Element;
// using Geometry = typename Element::Geometry;
using Geometry = std::decay_t<typename Element::Geometry>;
// Use the indirection via derivativeIfImplemented to also support
// function types F that do not implement derivative. In this case
// the interface type DifferentiableFunction is using a dummy for
// the derivative type
using DerivativeDummy = DifferentiableFunction<DerivativeSignature>;
using GlobalRawDerivative = decltype(Imp::derivativeIfImplemented<DerivativeDummy, F>(std::declval<F>()));
using LocalDerivative = LocalAnalyticGridViewFunction<DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits>;
template<class FT, disableCopyMove<LocalAnalyticGridViewFunction, FT> = 0>
LocalAnalyticGridViewFunction(FT&& f) :
f_(std::forward<FT>(f))
{}
template<class FT>
LocalAnalyticGridViewFunction(FT&& f, const Element& element, const std::optional<Geometry>& geometry) :
f_(std::forward<FT>(f)),
element_(element),
geometry_(geometry)
{}
void bind(const Element& element)
{
element_ = element;
geometry_.emplace(element_.geometry());
}
void unbind()
{
geometry_.reset();
}
bool bound() const
{
return static_cast<bool>(geometry_);
}
Range operator()(const LocalDomain& x) const
{
assert(!!geometry_);
return (*f_)(geometry_->global(x));
}
const Element& localContext() const
{
assert(!!geometry_);
return element_;
}
friend LocalDerivative derivative(const LocalAnalyticGridViewFunction& t)
{
return LocalDerivative(Imp::derivativeIfImplemented<DerivativeDummy, F>(*t.f_), t.element_, t.geometry_);
}
private:
// Wrap the function into CopyableOptional to make it copy-assignable
CopyableOptional<F> f_;
Element element_;
std::optional<Geometry> geometry_ = std::nullopt;
};
} // end namespace Imp
template<class Signature, class GV, class F, template<class> class DerivativeTraits=DefaultDerivativeTraits>
class AnalyticGridViewFunction;
template<class Range, class Domain, class GV, class F, template<class> class DerivativeTraits>
class AnalyticGridViewFunction<Range(Domain), GV, F, DerivativeTraits>
{
public:
using Signature = Range(Domain);
using RawSignature = typename SignatureTraits<Signature>::RawSignature;
using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
using GridView = GV;
using EntitySet = GridViewEntitySet<GridView, 0>;
using Element = typename EntitySet::Element;
using Geometry = typename Element::Geometry;
// Use the indirection via derivativeIfImplemented to also support
// function types F that do not implement derivative. In this case
// the interface type DifferentiableFunction is used a dummy for
// the derivative type
using DerivativeDummy = DifferentiableFunction<DerivativeSignature>;
using GlobalRawDerivative = decltype(Imp::derivativeIfImplemented<DerivativeDummy, F>(std::declval<F>()));
using Derivative = AnalyticGridViewFunction<DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits>;
using LocalDomain = typename EntitySet::LocalCoordinate;
using LocalFunction = typename Imp::LocalAnalyticGridViewFunction<Range(LocalDomain), GridView, F, LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits>;
template<class FT>
AnalyticGridViewFunction(FT&& f, const GridView& gridView) :
f_(std::forward<FT>(f)),
entitySet_(gridView)
{}
Range operator()(const Domain& x) const
{
return (*f_)(x);
}
friend Derivative derivative(const AnalyticGridViewFunction& t)
{
return Derivative(Imp::derivativeIfImplemented<DerivativeDummy, F>(*t.f_), t.entitySet_.gridView());
}
friend LocalFunction localFunction(const AnalyticGridViewFunction& t)
{
return LocalFunction(*t.f_);
}
const EntitySet& entitySet() const
{
return entitySet_;
}
private:
// Wrap the function into CopyableOptional to make it copy-assignable
CopyableOptional<F> f_;
EntitySet entitySet_;
};
// deduction guides
template<class F, class GridView,
class Domain = typename GridView::template Codim<0>::Geometry::GlobalCoordinate,
class Range = std::invoke_result_t<F,Domain>>
AnalyticGridViewFunction(const F&, const GridView&)
-> AnalyticGridViewFunction<Range(Domain), GridView, F>;
template<class F, class GridView>
auto makeAnalyticGridViewFunction(F&& f, const GridView& gridView)
{
using Domain = typename GridView::template Codim<0>::Geometry::GlobalCoordinate;
using Range = std::invoke_result_t<F, Domain>;
using FRaw = std::decay_t<F>;
return AnalyticGridViewFunction<Range(Domain), GridView, FRaw>(std::forward<F>(f), gridView);
}
}} // namespace Dune::Functions
#endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_ANALYTICGRIDVIEWFUNCTION_HH
localderivativetraits.hh
gridviewentityset.hh
signature.hh
differentiablefunction.hh
defaultderivativetraits.hh
differentiablefunction_imp.hh
Dune::Functions::derivative
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition trigonometricfunction.hh:43
Dune::Functions::AnalyticGridViewFunction::makeAnalyticGridViewFunction
auto makeAnalyticGridViewFunction(F &&f, const GridView &gridView)
Create an AnalyticGridViewFunction from a function and a grid view.
Definition analyticgridviewfunction.hh:238
Dune
Definition monomialset.hh:19
Dune::Functions
Definition monomialset.hh:19
Dune::Functions::AnalyticGridViewFunction
AnalyticGridViewFunction(const F &, const GridView &) -> AnalyticGridViewFunction< Range(Domain), GridView, F >
Dune::Functions::DefaultDerivativeTraits
Default implementation for derivative traits.
Definition defaultderivativetraits.hh:41
Dune::Functions::DifferentiableFunction
Definition differentiablefunction.hh:33
Dune::Functions::SignatureTraits
Helper class to deduce the signature of a callable.
Definition signature.hh:60
Dune::Functions::AnalyticGridViewFunction
Definition analyticgridviewfunction.hh:144
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::operator()
Range operator()(const Domain &x) const
Evaluate the wrapped function f directly in global coordinates x.
Definition analyticgridviewfunction.hh:184
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::LocalDomain
typename EntitySet::LocalCoordinate LocalDomain
Definition analyticgridviewfunction.hh:173
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::derivative
friend Derivative derivative(const AnalyticGridViewFunction &t)
Create a derivative grid-function by wrapping the derivative of f.
Definition analyticgridviewfunction.hh:190
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::Geometry
typename Element::Geometry Geometry
Definition analyticgridviewfunction.hh:163
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::Element
typename EntitySet::Element Element
Definition analyticgridviewfunction.hh:162
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::GridView
GV GridView
Definition analyticgridviewfunction.hh:160
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::GlobalRawDerivative
decltype(Imp::derivativeIfImplemented< DerivativeDummy, F >(std::declval< F >())) GlobalRawDerivative
Definition analyticgridviewfunction.hh:170
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::DerivativeDummy
DifferentiableFunction< DerivativeSignature > DerivativeDummy
Definition analyticgridviewfunction.hh:169
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::Signature
Range(Domain) Signature
Definition analyticgridviewfunction.hh:156
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::AnalyticGridViewFunction
AnalyticGridViewFunction(FT &&f, const GridView &gridView)
Create the grid-function by wrapping a function f and create a GridViewEntitySet.
Definition analyticgridviewfunction.hh:178
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::localFunction
friend LocalFunction localFunction(const AnalyticGridViewFunction &t)
Construct the associated local-function.
Definition analyticgridviewfunction.hh:196
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::LocalFunction
typename Imp::LocalAnalyticGridViewFunction< Range(LocalDomain), GridView, F, LocalDerivativeTraits< EntitySet, DerivativeTraits >::template Traits > LocalFunction
Definition analyticgridviewfunction.hh:174
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::RawSignature
typename SignatureTraits< Signature >::RawSignature RawSignature
Definition analyticgridviewfunction.hh:157
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::EntitySet
GridViewEntitySet< GridView, 0 > EntitySet
Definition analyticgridviewfunction.hh:161
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::entitySet
const EntitySet & entitySet() const
Return the set of entities this local-function can be bound to.
Definition analyticgridviewfunction.hh:202
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::DerivativeSignature
typename DerivativeTraits< RawSignature >::Range(Domain) DerivativeSignature
Definition analyticgridviewfunction.hh:158
Dune::Functions::AnalyticGridViewFunction< Range(Domain), GV, F, DerivativeTraits >::Derivative
AnalyticGridViewFunction< DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits > Derivative
Definition analyticgridviewfunction.hh:171
Dune::Functions::GridViewEntitySet
An entity set for all entities of given codim in a grid view.
Definition gridviewentityset.hh:27
Dune::Functions::GridViewEntitySet< GridView, 0 >::Element
GridView::template Codim< codim >::Entity Element
Definition gridviewentityset.hh:36
Dune::Functions::GridViewEntitySet< GridView, 0 >::LocalCoordinate
Element::Geometry::LocalCoordinate LocalCoordinate
Definition gridviewentityset.hh:39
Dune::Functions::LocalDerivativeTraits
Derivative traits for local functions.
Definition localderivativetraits.hh:32