Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
localfunctionadaptor.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUFEM_FORMS_LOCALFUNCTIONADAPTOR_HH
8#define DUNE_FUFEM_FORMS_LOCALFUNCTIONADAPTOR_HH
9
10#include <utility>
11
13
14
15
16namespace Dune::Fufem::Forms {
17
18
40 template<class LocalOperator>
42 {
43 public:
44
45 using Element = typename LocalOperator::Element;
46 using Range = typename LocalOperator::Range;
47
48 private:
49
50 static constexpr int dimension = Element::dimension;
51 using CacheManager = typename Dune::Fufem::Forms::CacheManager<double, dimension>;
52 using QuadratureRule = typename CacheManager::QuadratureRule;
53 using QuadraturePoint = typename QuadratureRule::value_type;
54 using Domain = typename Element::Geometry::LocalCoordinate;
55
56 public:
57
58 LocalFunctionAdaptor(LocalOperator&& localOperator) :
59 localOperator_(std::move(localOperator)),
60 internalRule_(),
61 internalCacheManager_()
62 {
63 localOperator_.registerCaches(internalCacheManager_);
64 internalRule_.emplace_back(typename QuadraturePoint::Vector(),0.0);
65 }
66
67 LocalFunctionAdaptor(const LocalOperator& localOperator) :
68 localOperator_(localOperator),
69 internalRule_(),
70 internalCacheManager_()
71 {
72 localOperator_.registerCaches(internalCacheManager_);
73 internalRule_.emplace_back(typename QuadraturePoint::Vector(),0.0);
74 }
75
77 LocalFunctionAdaptor(other.localOperator_)
78 {}
79
81 LocalFunctionAdaptor(std::move(other.localOperator_))
82 {}
83
85 void bind(const Element& element)
86 {
87 localOperator_.bind(element);
88 }
89
91 void unbind()
92 {
93 localOperator_.unbind();
94 }
95
97 bool bound() const
98 {
99 return localOperator_.bound();
100 }
101
103 auto operator()(const Domain& x) const
104 {
105 // The cache must always be fully invalidated,
106 // because the quadrature rule was modified.
107 // Since the internal cache was marked as non affine,
108 // calling invalidate() will indeed remove all cached
109 // entries.
110 internalRule_[0] = QuadraturePoint{x, 0};
111 internalCacheManager_.setRule(internalRule_);
112 localOperator_.bindToCaches(internalCacheManager_);
113 return localOperator_(0)();
114 }
115
117 const Element& localContext() const
118 {
119 return localOperator_.localContext();
120 }
121
122 private:
123 mutable LocalOperator localOperator_;
124 mutable QuadratureRule internalRule_;
125 mutable CacheManager internalCacheManager_;
126 };
127
128
129} // namespace Dune::Fufem::Forms
130
131
132#endif // DUNE_FUFEM_FORMS_LOCALFUNCTIONADAPTOR_HH
STL namespace.
Definition baseclass.hh:22
Adaptor for turning a Fufem::Forms LocalOperator into a LocalFunction.
Definition localfunctionadaptor.hh:42
typename LocalOperator::Range Range
Definition localfunctionadaptor.hh:46
LocalFunctionAdaptor(LocalOperator &&localOperator)
Definition localfunctionadaptor.hh:58
const Element & localContext() const
Return the element the local-function is bound to.
Definition localfunctionadaptor.hh:117
void unbind()
Unbind the LocalFunction.
Definition localfunctionadaptor.hh:91
void bind(const Element &element)
Bind the LocalFunction to an element.
Definition localfunctionadaptor.hh:85
bool bound() const
Check if LocalFunction is already bound to an element.
Definition localfunctionadaptor.hh:97
typename LocalOperator::Element Element
Definition localfunctionadaptor.hh:45
LocalFunctionAdaptor(const LocalOperator &localOperator)
Definition localfunctionadaptor.hh:67
auto operator()(const Domain &x) const
Evaluate the local function.
Definition localfunctionadaptor.hh:103
LocalFunctionAdaptor(LocalFunctionAdaptor &&other)
Definition localfunctionadaptor.hh:80
LocalFunctionAdaptor(const LocalFunctionAdaptor &other)
Definition localfunctionadaptor.hh:76
A class for managing caches of different types.
Definition shapefunctioncache.hh:615
Dune::QuadratureRule< CT, dimension > QuadratureRule
Definition shapefunctioncache.hh:617