Dune-Fufem 2.12-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 <optional>
11#include <utility>
12
14
15
16
17namespace Dune::Fufem::Forms {
18
19
41 template<class LocalOperator>
43 {
44 public:
45
46 using Element = typename LocalOperator::Element;
47 using Range = typename LocalOperator::Range;
48
49 private:
50
51 static constexpr int dimension = Element::dimension;
52 using CacheManager = typename Dune::Fufem::Forms::CacheManager<double, dimension>;
53 using QuadratureRule = typename CacheManager::QuadratureRule;
54 using QuadraturePoint = typename QuadratureRule::value_type;
55 using Domain = typename Element::Geometry::LocalCoordinate;
56
57 public:
58
59 LocalFunctionAdaptor(LocalOperator&& localOperator) :
60 localOperator_(std::move(localOperator)),
61 internalRule_(),
62 internalCacheManager_(),
63 element_()
64 {
65 localOperator_.registerCaches(internalCacheManager_);
66 internalRule_.emplace_back(typename QuadraturePoint::Vector(),0.0);
67 }
68
69 LocalFunctionAdaptor(const LocalOperator& localOperator) :
70 localOperator_(localOperator),
71 internalRule_(),
72 internalCacheManager_(),
73 element_()
74 {
75 localOperator_.registerCaches(internalCacheManager_);
76 internalRule_.emplace_back(typename QuadraturePoint::Vector(),0.0);
77 }
78
80 LocalFunctionAdaptor(other.localOperator_)
81 {
82 if (other.bound())
83 bind(other.localContext());
84 }
85
87 LocalFunctionAdaptor(std::move(other.localOperator_))
88 {
89 // If moving from a bound LocalFunctionAdaptor we also
90 // bind the present one. For the moved-from object we
91 // deliberately do not call unbind(), because we do
92 // not know if this call is safe once we moved out data.
93 if (other.bound())
94 bind(other.localContext());
95 }
96
98 void bind(const Element& element)
99 {
100 element_ = element;
101 localOperator_.bind(*element_);
102 }
103
105 void unbind()
106 {
107 localOperator_.unbind();
108 element_.reset();
109 }
110
112 bool bound() const
113 {
114 return static_cast<bool>(element_);
115 }
116
118 auto operator()(const Domain& x) const
119 {
120 // The cache must always be fully invalidated,
121 // because the quadrature rule was modified.
122 // This is achieved by calling the setRule()
123 // method.
124 internalRule_[0] = QuadraturePoint{x, 0};
125 internalCacheManager_.setRule(internalRule_);
126 localOperator_.bindToCaches(internalCacheManager_);
127 return localOperator_(0)();
128 }
129
131 const Element& localContext() const
132 {
133 return *element_;
134 }
135
136 private:
137 mutable LocalOperator localOperator_;
138 mutable QuadratureRule internalRule_;
139 mutable CacheManager internalCacheManager_;
140 std::optional<Element> element_;
141 };
142
143
144} // namespace Dune::Fufem::Forms
145
146
147#endif // DUNE_FUFEM_FORMS_LOCALFUNCTIONADAPTOR_HH
A class for managing caches of different types.
Definition shapefunctioncache.hh:644
Dune::QuadratureRule< CT, dimension > QuadratureRule
Definition shapefunctioncache.hh:646
Adaptor for turning a Fufem::Forms LocalOperator into a LocalFunction.
Definition localfunctionadaptor.hh:43
typename LocalOperator::Range Range
Definition localfunctionadaptor.hh:47
LocalFunctionAdaptor(LocalOperator &&localOperator)
Definition localfunctionadaptor.hh:59
const Element & localContext() const
Return the element the local-function is bound to.
Definition localfunctionadaptor.hh:131
void unbind()
Unbind the LocalFunction.
Definition localfunctionadaptor.hh:105
void bind(const Element &element)
Bind the LocalFunction to an element.
Definition localfunctionadaptor.hh:98
bool bound() const
Check if LocalFunction is already bound to an element.
Definition localfunctionadaptor.hh:112
typename LocalOperator::Element Element
Definition localfunctionadaptor.hh:46
LocalFunctionAdaptor(const LocalOperator &localOperator)
Definition localfunctionadaptor.hh:69
auto operator()(const Domain &x) const
Evaluate the local function.
Definition localfunctionadaptor.hh:118
LocalFunctionAdaptor(LocalFunctionAdaptor &&other)
Definition localfunctionadaptor.hh:86
LocalFunctionAdaptor(const LocalFunctionAdaptor &other)
Definition localfunctionadaptor.hh:79
Definition baseclass.hh:22
STL namespace.
T reset(T... args)