Loading...
Searching...
No Matches
coarsefunctiononfinegridview.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_COARSEFUNCTIONONFINEGRIDVIEW_HH
#define DUNE_FUNCTIONS_GRIDFUNCTIONS_COARSEFUNCTIONONFINEGRIDVIEW_HH
#include <optional>
#include <type_traits>
#include <utility>
#include <dune/common/referencehelper.hh>
#include <dune/functions/common/defaultderivativetraits.hh>
#include <dune/functions/common/geometryinancestor.hh>
#include <dune/functions/gridfunctions/gridfunction.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
namespace Dune::Functions {
template<class GridFunction, class GV, template<class> class DerivativeTraits=Dune::Functions::DefaultDerivativeTraits>
class CoarseFunctionOnFineGridView
{
using RawGridFunction = Dune::ResolveRef_t<GridFunction>;
auto&& rawFunction() const
{
return Dune::resolveRef(function_);
}
public:
using GridView = GV;
using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
using Element = typename EntitySet::Element;
using Domain = typename EntitySet::GlobalCoordinate;
using LocalDomain = typename EntitySet::LocalCoordinate;
using Range = std::decay_t<decltype(std::declval<RawGridFunction>()(std::declval<Domain>()))>;
private:
using CoarseEntitySet = std::decay_t<decltype(std::declval<RawGridFunction>().entitySet())>;
using GeometryInAncestor = Dune::Functions::GeometryInAncestor<Element>;
using Traits = Dune::Functions::Imp::GridFunctionTraits<Range(Domain), EntitySet, DerivativeTraits, 56>;
class CoarseLocalFunctionOnFineGridView
{
using Traits = typename CoarseFunctionOnFineGridView::Traits::LocalFunctionTraits;
public:
using Derivative = decltype(localFunction(derivative(std::declval<CoarseFunctionOnFineGridView>())));
using RawLocalFunction = std::decay_t<decltype(localFunction(std::declval<const RawGridFunction&>()))>;
CoarseLocalFunctionOnFineGridView(RawLocalFunction&& localFunction, const CoarseEntitySet& coarseEntitySet)
: element_()
, localFunction_(localFunction)
, coarseEntitySet_(coarseEntitySet)
, geometryInAncestor_()
{}
CoarseLocalFunctionOnFineGridView(
RawLocalFunction&& localFunction,
const CoarseEntitySet& coarseEntitySet,
const GeometryInAncestor& geometryInAncestor,
const std::optional<Element>& element
)
: element_(element)
, localFunction_(localFunction)
, coarseEntitySet_(coarseEntitySet)
, geometryInAncestor_(geometryInAncestor, *element_)
{}
void bind(const Element& element)
{
element_ = element;
geometryInAncestor_.bind(*element_, [&](const auto& e) { return not coarseEntitySet_.contains(e); });
localFunction_.bind(geometryInAncestor_.coarseElement());
}
void unbind()
{
element_.reset();
}
bool bound() const
{
return static_cast<bool>(element_);
}
const Element& localContext() const
{
return *element_;
}
friend auto derivative(const CoarseLocalFunctionOnFineGridView& f)
{
if constexpr(requires{ derivative(f.localFunction_); })
return Derivative(derivative(f.localFunction_), f.coarseEntitySet_, f.geometryInAncestor_, f.element_);
else
return typename Traits::DerivativeInterface{};
}
Range operator()(LocalDomain x) const
{
return localFunction_(geometryInAncestor_.global(x));
}
private:
std::optional<Element> element_;
RawLocalFunction localFunction_;
const CoarseEntitySet& coarseEntitySet_;
GeometryInAncestor geometryInAncestor_;
};
public:
using LocalFunction = CoarseLocalFunctionOnFineGridView;
CoarseFunctionOnFineGridView(const GridFunction& function, const GridView& gridView)
: function_(function)
, entitySet_(gridView)
{}
CoarseFunctionOnFineGridView(GridFunction&& function, const GridView& gridView)
: function_(std::move(function))
, entitySet_(gridView)
{}
Range operator()(const Domain& x) const
{
return function_(x);
}
friend auto derivative(const CoarseFunctionOnFineGridView& f)
{
if constexpr(requires{ derivative(f.rawFunction()); })
{
using RawDerivative = std::decay_t<decltype(derivative(f.rawFunction()))>;
return CoarseFunctionOnFineGridView<RawDerivative, GridView, DerivativeTraits>(derivative(f.rawFunction()), f.entitySet_.gridView());
}
else
return typename Traits::DerivativeInterface{};
}
friend LocalFunction localFunction(const CoarseFunctionOnFineGridView& f)
{
return LocalFunction(localFunction(f.rawFunction()), f.rawFunction().entitySet());
}
const EntitySet& entitySet() const
{
return entitySet_;
}
protected:
GridFunction function_;
EntitySet entitySet_;
};
} // namespace Dune::Functions
#endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_COARSEFUNCTIONONFINEGRIDVIEW_HH
gridfunction.hh
gridviewentityset.hh
geometryinancestor.hh
defaultderivativetraits.hh
Dune::Functions
Definition monomialset.hh:19
Dune::Functions::GeometryInAncestor
A geometry embedding a descendent element into an ancestor.
Definition geometryinancestor.hh:39
Dune::Functions::GeometryInAncestor::global
GlobalCoordinate global(LocalCoordinate x) const
Map local coordinate in fine element into coarse element.
Definition geometryinancestor.hh:169
Dune::Functions::GeometryInAncestor::bind
const Element & bind(const Element &fineElement, F &&includeFather)
Bind this GeometryInAncestor to a fine element and search coarse element.
Definition geometryinancestor.hh:119
Dune::Functions::GeometryInAncestor::coarseElement
const Element & coarseElement() const
Return the coarse element.
Definition geometryinancestor.hh:163
Dune::Functions::CoarseFunctionOnFineGridView::derivative
friend auto derivative(const CoarseFunctionOnFineGridView &f)
Obtain global derivative of this function.
Definition coarsefunctiononfinegridview.hh:183
Dune::Functions::CoarseFunctionOnFineGridView::EntitySet
Dune::Functions::GridViewEntitySet< GridView, 0 > EntitySet
Definition coarsefunctiononfinegridview.hh:52
Dune::Functions::CoarseFunctionOnFineGridView::operator()
Range operator()(const Domain &x) const
Evaluate function in global coordinates.
Definition coarsefunctiononfinegridview.hh:177
Dune::Functions::CoarseFunctionOnFineGridView::Domain
typename EntitySet::GlobalCoordinate Domain
Definition coarsefunctiononfinegridview.hh:54
Dune::Functions::CoarseFunctionOnFineGridView::CoarseFunctionOnFineGridView
CoarseFunctionOnFineGridView(GridFunction &&function, const GridView &gridView)
Create CoarseFunctionOnFineGridView from GridFunction and GridView.
Definition coarsefunctiononfinegridview.hh:171
Dune::Functions::CoarseFunctionOnFineGridView::entitySet
const EntitySet & entitySet() const
Return the EntitySet associated to this GridViewFunction.
Definition coarsefunctiononfinegridview.hh:201
Dune::Functions::CoarseFunctionOnFineGridView::LocalFunction
CoarseLocalFunctionOnFineGridView LocalFunction
Definition coarsefunctiononfinegridview.hh:152
Dune::Functions::CoarseFunctionOnFineGridView::Element
typename EntitySet::Element Element
Definition coarsefunctiononfinegridview.hh:53
Dune::Functions::CoarseFunctionOnFineGridView::function_
GridFunction function_
Definition coarsefunctiononfinegridview.hh:208
Dune::Functions::CoarseFunctionOnFineGridView::CoarseFunctionOnFineGridView
CoarseFunctionOnFineGridView(const GridFunction &function, const GridView &gridView)
Create CoarseFunctionOnFineGridView from GridFunction and GridView.
Definition coarsefunctiononfinegridview.hh:160
Dune::Functions::CoarseFunctionOnFineGridView::entitySet_
EntitySet entitySet_
Definition coarsefunctiononfinegridview.hh:209
Dune::Functions::CoarseFunctionOnFineGridView::LocalDomain
typename EntitySet::LocalCoordinate LocalDomain
Definition coarsefunctiononfinegridview.hh:55
Dune::Functions::CoarseFunctionOnFineGridView::localFunction
friend LocalFunction localFunction(const CoarseFunctionOnFineGridView &f)
Create a LocalFunction for evaluation in local coordinates.
Definition coarsefunctiononfinegridview.hh:195
Dune::Functions::CoarseFunctionOnFineGridView::Range
std::decay_t< decltype(std::declval< RawGridFunction >()(std::declval< Domain >()))> Range
Definition coarsefunctiononfinegridview.hh:56
Dune::Functions::CoarseFunctionOnFineGridView::GridView
GV GridView
Definition coarsefunctiononfinegridview.hh:51
Dune::Functions::GridFunction
Definition gridfunction.hh:36
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
const GridView & gridView() const
Return the associated GridView.
Definition gridviewentityset.hh:80
Dune::Functions::GridViewEntitySet< GridView, 0 >::LocalCoordinate
Element::Geometry::LocalCoordinate LocalCoordinate
Definition gridviewentityset.hh:39
Dune::Functions::GridViewEntitySet< GridView, 0 >::GlobalCoordinate
Element::Geometry::GlobalCoordinate GlobalCoordinate
Definition gridviewentityset.hh:40