Dune Core Modules (2.11.0)

localfunction.hh
1#pragma once
2
3#include <memory>
4#include <type_traits>
5#include <vector>
6
8#include <dune/common/referencehelper.hh>
10#include <dune/vtk/gridfunctions/rangeproxy.hh>
11
12namespace Dune::Vtk {
13namespace Impl {
14
15template <class ElementType, class ComponentMapperType>
16struct LocalFunctionDefinition
17{
18 using Element = ElementType;
19 using ComponentMapper = ComponentMapperType;
20 using Domain = typename Element::Geometry::LocalCoordinate;
21
22 // Definition of the interface a LocalFunction must fulfill
23 struct Interface
24 {
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;
30 };
31
32 // Templatized implementation of the interface
33 template <class Impl>
34 struct Model : public Interface
35 {
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); }
39 auto& impl() { return resolveRef(impl_); }
40 const auto& impl() const { return resolveRef(impl_); }
41
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()); }
46
47 private:
48 Impl impl_;
49 };
50
51 // The Concept definition of a LocalFunction
52 struct Concept
53 {
54 template <class LOp>
55 auto require(LOp&& lop) -> decltype
56 (
57 lop.bind(std::declval<Element>()),
58 lop.unbind()
59 );
60 };
61};
62
63} // end namespace Impl
64
65
66
69
72 template <class Element, class ComponentMapper>
74 {
75 using Definition = Impl::LocalFunctionDefinition<Element,ComponentMapper>;
76 using Interface = typename Definition::Interface;
77 using Domain = typename Definition::Domain;
78
79 template <class LF>
80 using Model = typename Definition::template Model<std::remove_reference_t<LF>>;
81
82 public:
84 template <class LF>
85 LocalFunction (LF&& lf, std::vector<int> components)
86 : interface_(std::make_unique<Model<LF>>(std::forward<LF>(lf)))
87 , components_(std::move(components))
88 {
89 static_assert(models<typename Definition::Concept,ResolveRef_t<LF>>(),
90 "Implementation does not model the LocalFunction concept.");
91 }
92
94 LocalFunction () = default;
95
98
101
104 : interface_(other.interface_ ? other.interface_->clone() : nullptr)
105 , components_(other.components_)
106 {}
107
110 {
111 return *this = LocalFunction(other);
112 }
113
115 void bind (Element const& element)
116 {
117 interface_->bind(element);
118 }
119
121 void unbind ()
122 {
123 interface_->unbind();
124 }
125
127 Impl::RangeProxy<LocalFunction,Domain> operator() (Domain const& x) const
128 {
129 return {this, x};
130 }
131
133 double evaluate (int i, Domain const& x) const
134 {
135 return i < int(components_.size()) ? interface_->evaluate(components_[i], x) : 0.0;
136 }
137
139 const std::vector<int>& components () const
140 {
141 return components_;
142 }
143
145 void setComponents (std::vector<int> components)
146 {
147 components_ = std::move(components);
148 }
149
150 private:
151 std::unique_ptr<Interface> interface_;
152 std::vector<int> components_{};
153 };
154
155} // end namespace Dune::Vtk
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
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 14, 23:39, 2026)