dune-vtk 2.12
Loading...
Searching...
No Matches
localfunction.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <memory>
6#include <type_traits>
7#include <vector>
8
13
14namespace Dune::Vtk {
15namespace Impl {
16
17template <class ElementType, class ComponentMapperType>
18struct LocalFunctionDefinition
19{
20 using Element = ElementType;
21 using ComponentMapper = ComponentMapperType;
22 using Domain = typename Element::Geometry::LocalCoordinate;
23
24 // Definition of the interface a LocalFunction must fulfill
25 struct Interface
26 {
27 virtual ~Interface() = default;
28 virtual Interface* clone () const = 0;
29 virtual void bind(Element const&) = 0;
30 virtual void unbind() = 0;
31 virtual double evaluate (int, Domain const&) const = 0;
32 };
33
34 // Templatized implementation of the interface
35 template <class Impl>
36 struct Model : public Interface
37 {
38 template <class I, disableCopyMove<Model,I> = 0>
39 Model(I&& impl) : impl_(std::forward<I>(impl)) {}
40 Model* clone() const final { return new Model(*this); }
41 auto& impl() { return resolveRef(impl_); }
42 const auto& impl() const { return resolveRef(impl_); }
43
44 void bind(Element const& e) final { impl().bind(e); }
45 void unbind() final { impl().unbind(); }
46 double evaluate(int i, Domain const& x) const final {
47 return ComponentMapper::map(i, x, impl()); }
48
49 private:
50 Impl impl_;
51 };
52
53 // The Concept definition of a LocalFunction
54 struct Concept
55 {
56 template <class LOp>
57 auto require(LOp&& lop) -> decltype
58 (
59 lop.bind(std::declval<Element>()),
60 lop.unbind()
61 );
62 };
63};
64
65} // end namespace Impl
66
67
68
71
74 template <class Element, class ComponentMapper>
76 {
77 using Definition = Impl::LocalFunctionDefinition<Element,ComponentMapper>;
78 using Interface = typename Definition::Interface;
79 using Domain = typename Definition::Domain;
80
81 template <class LF>
82 using Model = typename Definition::template Model<std::remove_reference_t<LF>>;
83
84 public:
86 template <class LF>
88 : interface_(std::make_unique<Model<LF>>(std::forward<LF>(lf)))
89 , components_(std::move(components))
90 {
92 "Implementation does not model the LocalFunction concept.");
93 }
94
96 LocalFunction () = default;
97
100
103
106 : interface_(other.interface_ ? other.interface_->clone() : nullptr)
107 , components_(other.components_)
108 {}
109
112 {
113 return *this = LocalFunction(other);
114 }
115
117 void bind (Element const& element)
118 {
119 interface_->bind(element);
120 }
121
123 void unbind ()
124 {
125 interface_->unbind();
126 }
127
129 Impl::RangeProxy<LocalFunction,Domain> operator() (Domain const& x) const
130 {
131 return {this, x};
132 }
133
135 double evaluate (int i, Domain const& x) const
136 {
137 return i < int(components_.size()) && components_[i] >= 0
138 ? interface_->evaluate(components_[i], x) : 0.0;
139 }
140
142 int numComponents () const
143 {
144 return components_.size();
145 }
146
149 {
150 return components_;
151 }
152
155 {
156 components_ = std::move(components);
157 }
158
159 private:
161 std::vector<int> components_{};
162 };
163
164} // end namespace Dune::Vtk
STL namespace.
Definition datacollector.hh:19
constexpr T & resolveRef(T &gf) noexcept
virtual void operator()()=0
virtual ~Interface()
Implementation & impl()
ALBERTA EL Element
U_CHAR ElementType
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
A Vtk::LocalFunction is a function-like object that can be bound to a grid element an that provides a...
Definition localfunction.hh:76
LocalFunction(LF &&lf, std::vector< int > components)
Constructor. Pass any type supporting the LocalOperatorInterface.
Definition localfunction.hh:87
void bind(Element const &element)
Binds the local function to an element.
Definition localfunction.hh:117
LocalFunction(const LocalFunction &other)
Copy constructor, clones the underlying implementation.
Definition localfunction.hh:105
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:154
const std::vector< int > & components() const
Return the components vector. An entry -1 represents a zero-padded component.
Definition localfunction.hh:148
void unbind()
Unbinds function from element.
Definition localfunction.hh:123
double evaluate(int i, Domain const &x) const
Evaluate the ith component of the Range value at local coordinate x
Definition localfunction.hh:135
LocalFunction()=default
Default Constructor.
LocalFunction(LocalFunction &&)=default
Move Constructor.
int numComponents() const
Return the number of components as written to the file.
Definition localfunction.hh:142
T bind(T... args)
T forward(T... args)
T size(T... args)