8#include <dune/common/referencehelper.hh>
10#include <dune/vtk/gridfunctions/rangeproxy.hh>
15template <
class ElementType,
class ComponentMapperType>
16struct LocalFunctionDefinition
18 using Element = ElementType;
19 using ComponentMapper = ComponentMapperType;
20 using Domain =
typename Element::Geometry::LocalCoordinate;
25 virtual ~Interface() =
default;
26 virtual Interface* clone ()
const = 0;
27 virtual void bind(Element
const&) = 0;
28 virtual void unbind() = 0;
29 virtual double evaluate (
int, Domain
const&)
const = 0;
34 struct Model :
public Interface
36 template <
class I, disableCopyMove<Model,I> = 0>
37 Model(I&& impl) : impl_(
std::forward<I>(impl)) {}
38 Model* clone() const final {
return new Model(*
this); }
40 const auto& impl()
const {
return resolveRef(impl_); }
42 void bind(Element
const& e)
final { impl().bind(e); }
43 void unbind() final { impl().unbind(); }
44 double evaluate(
int i, Domain
const& x)
const final {
45 return ComponentMapper::map(i, x, impl()); }
55 auto require(LOp&& lop) ->
decltype
57 lop.bind(std::declval<Element>()),
72 template <
class Element,
class ComponentMapper>
75 using Definition = Impl::LocalFunctionDefinition<Element,ComponentMapper>;
76 using Interface =
typename Definition::Interface;
77 using Domain =
typename Definition::Domain;
80 using Model =
typename Definition::template Model<std::remove_reference_t<LF>>;
86 : interface_(
std::make_unique<Model<LF>>(
std::forward<LF>(lf)))
89 static_assert(models<typename Definition::Concept,ResolveRef_t<LF>>(),
90 "Implementation does not model the LocalFunction concept.");
104 : interface_(other.interface_ ? other.interface_->clone() : nullptr)
105 , components_(other.components_)
115 void bind (Element
const& element)
117 interface_->bind(element);
123 interface_->unbind();
127 Impl::RangeProxy<LocalFunction,Domain>
operator() (Domain
const& x)
const
135 return i < int(components_.size()) ? interface_->evaluate(components_[i], x) : 0.0;
151 std::unique_ptr<Interface> interface_;
152 std::vector<int> components_{};
A Vtk::LocalFunction is a function-like object that can be bound to a grid element an that provides a...
Definition: localfunction.hh:74
LocalFunction(LF &&lf, std::vector< int > components)
Constructor. Pass any type supporting the LocalOperatorInterface.
Definition: localfunction.hh:85
void bind(Element const &element)
Binds the local function to an element.
Definition: localfunction.hh:115
LocalFunction(const LocalFunction &other)
Copy constructor, clones the underlying implementation.
Definition: localfunction.hh:103
Impl::RangeProxy< LocalFunction, Domain > operator()(Domain const &x) const
Return a proxy object to access the components of the range vector.
Definition: localfunction.hh:127
LocalFunction & operator=(LocalFunction &&)=default
Move assignment-operator.
void setComponents(std::vector< int > components)
Use the passed components for evaluation of the range.
Definition: localfunction.hh:145
const std::vector< int > & components() const
Return the components vector.
Definition: localfunction.hh:139
void unbind()
Unbinds function from element.
Definition: localfunction.hh:121
double evaluate(int i, Domain const &x) const
Evaluate the ith component of the Range value at local coordinate x
Definition: localfunction.hh:133
LocalFunction()=default
Default Constructor.
LocalFunction(LocalFunction &&)=default
Move Constructor.
Infrastructure for concepts.
Traits for type conversions and type information.
constexpr T & resolveRef(T &gf) noexcept
Helper function to resolve std::reference_wrapper.
Definition: referencehelper.hh:47