Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
quadraturerulecache.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM 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
4#ifndef QUADRATURERULECACHE_HH
5#define QUADRATURERULECACHE_HH
6
7#include <mutex>
8#include <map>
9#include <algorithm>
10
11#include <dune/geometry/type.hh>
12
14
18
20
21
22
39{
40 public:
41
45 gt_(Dune::GeometryTypes::none(0)),
46 order_(0),
47 refinement_(0),
48 lumping_(false)
49 {}
50
53 template<class LocalFiniteElement>
54 QuadratureRuleKey(const LocalFiniteElement& fe)
55 {
56 gt_ = fe.type();
57 order_ = fe.localBasis().order();
59 lumping_ = false;
60 }
61
68 QuadratureRuleKey(const Dune::GeometryType& gt, const int order, const int refinement=0, bool lumping=false) :
69 gt_(gt),
73 {}
74
81 QuadratureRuleKey(const int dim, const int order, const int refinement=0, bool lumping=false) :
82 gt_(Dune::GeometryTypes::none(dim)),
86 {}
87
93 bool operator<(const QuadratureRuleKey& other) const
94 {
95 if (gt_ < other.gt_)
96 return true;
97 if (gt_ == other.gt_)
98 {
99 if (order_ < other.order_)
100 return true;
101 if (order_ == other.order_)
102 {
103 if (refinement_ < other.refinement_)
104 return true;
105 if (refinement_ == other.refinement_)
106 return lumping_ < other.lumping_;
107 }
108 }
109 return false;
110 }
111
113 {
114 return gt_;
115 }
116
118 {
119 gt_ = gt;
120 }
121
122 int order() const
123 {
124 return order_;
125 }
126
127 void setOrder(int order)
128 {
129 order_ = order;
130 }
131
132 int refinement() const
133 {
134 return refinement_;
135 }
136
138 {
140 }
141
142 bool lumping() const
143 {
144 return lumping_;
145 }
146
148 {
150 }
151
152
153
155 {
156 int derivativeOrder = gt_.isSimplex() ? std::max(0,order_-1) : order_;
157 return QuadratureRuleKey(gt_, derivativeOrder, refinement_, lumping_);
158 }
159
161 {
162 Dune::GeometryType resultGT = gt_.isNone() ? other.gt_ : gt_;
163 return QuadratureRuleKey(resultGT, std::max(order_, other.order_), std::max(refinement_, other.refinement_), (lumping_ or other.lumping_));
164 }
165
167 {
168 Dune::GeometryType resultGT = gt_.isNone() ? other.gt_ : gt_;
169 return QuadratureRuleKey(resultGT, order_ + other.order_, std::max(refinement_, other.refinement_), (lumping_ or other.lumping_));
170 }
171
176
177 protected:
178
183};
184
185
186
187
188template <class coord_type, int dim>
190{
192 static ContainerType quadRules;
193 static std::mutex mut;
194
195 public:
196 static const Dune::QuadratureRule<coord_type,dim>& rule(const Dune::GeometryType& gt, const int order, int refinement)
197 {
198 return rule(QuadratureRuleKey(gt, order, refinement));
199 }
200
202 {
203 const Dune::GeometryType& gt = index.geometryType();
204 const int order = index.order();
205 const int refinement = index.refinement();
206 const bool lumping = index.lumping();
207
208 typename ContainerType::iterator qrule_it = quadRules.find(index);
209
210 if (qrule_it != quadRules.end())
211 return qrule_it->second;
212
213 // if quadrature rule is not already cached, create it and insert it in the cache
214 if (lumping)
215 {
216 auto lock = std::unique_lock(mut);
217 qrule_it = (quadRules.insert(std::make_pair(QuadratureRuleKey(gt,order,refinement,true), LumpingQuadratureRule<coord_type,dim>(gt)))).first;
218 return qrule_it->second;
219 }
220 if (refinement==0)
221 {
222 return Dune::template QuadratureRules<coord_type, dim>::rule(gt, order);
223 }
224 if ((refinement==1) and (gt.isSimplex()))
225 {
226 auto lock = std::unique_lock(mut);
228 qrule_it = (quadRules.insert(std::make_pair(index, qrule))).first;
229 return qrule_it->second;
230 }
231 if ((refinement>1) and (gt.isSimplex()))
232 {
233 auto lock = std::unique_lock(mut);
235 qrule_it = (quadRules.insert(std::make_pair(index, qrule))).first;
236 return qrule_it->second;
237 }
238 DUNE_THROW(Dune::NotImplemented, "Quadrature rule for given QuadratureRuleKey(" << gt << "," << order << "," << refinement << " is not implemented!");
239 }
240};
241// define static template members
243template <class coord_type, int dim> std::mutex QuadratureRuleCache<coord_type,dim>::mut;
244
245
246#endif
247
Construct composite quadrature rules from other quadrature rules.
size_type dim() const
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
constexpr bool isNone() const
constexpr bool isSimplex() const
Construct composite quadrature rules for simplex elements.
Definition compositequadraturerule.hh:20
A lumping quadrature rule.
Definition lumpingquadraturerule.hh:26
A token that specifies a quadrature rule.
Definition quadraturerulecache.hh:39
int order() const
Definition quadraturerulecache.hh:122
const Dune::GeometryType & geometryType() const
Definition quadraturerulecache.hh:112
QuadratureRuleKey(const int dim, const int order, const int refinement=0, bool lumping=false)
Constructor for rules to integrate analytical functions (i.e., not related to a grid)
Definition quadraturerulecache.hh:81
QuadratureRuleKey square() const
Definition quadraturerulecache.hh:172
QuadratureRuleKey(const Dune::GeometryType &gt, const int order, const int refinement=0, bool lumping=false)
Constructor with given element type, order and refinement level.
Definition quadraturerulecache.hh:68
void setRefinement(int refinement)
Definition quadraturerulecache.hh:137
bool lumping() const
Definition quadraturerulecache.hh:142
QuadratureRuleKey derivative() const
Definition quadraturerulecache.hh:154
bool operator<(const QuadratureRuleKey &other) const
defines order relation on QuadratureRuleKeys
Definition quadraturerulecache.hh:93
QuadratureRuleKey product(const QuadratureRuleKey &other) const
Definition quadraturerulecache.hh:166
int refinement_
Definition quadraturerulecache.hh:181
bool lumping_
Definition quadraturerulecache.hh:182
QuadratureRuleKey(const LocalFiniteElement &fe)
Create a key for a quadrature rule that can integrate a given local basis exactly.
Definition quadraturerulecache.hh:54
int order_
Definition quadraturerulecache.hh:180
Dune::GeometryType gt_
Definition quadraturerulecache.hh:179
void setLumping(bool lumping)
Definition quadraturerulecache.hh:147
QuadratureRuleKey sum(const QuadratureRuleKey &other) const
Definition quadraturerulecache.hh:160
QuadratureRuleKey()
Default constructor, same as QuadratureRuleKey(0,0)
Definition quadraturerulecache.hh:44
int refinement() const
Definition quadraturerulecache.hh:132
void setGeometryType(const Dune::GeometryType &gt)
Definition quadraturerulecache.hh:117
void setOrder(int order)
Definition quadraturerulecache.hh:127
Definition quadraturerulecache.hh:190
static const Dune::QuadratureRule< coord_type, dim > & rule(const QuadratureRuleKey &index)
Definition quadraturerulecache.hh:201
static const Dune::QuadratureRule< coord_type, dim > & rule(const Dune::GeometryType &gt, const int order, int refinement)
Definition quadraturerulecache.hh:196
Definition refinedquadraturerule.hh:21
static bool value(const LocalFiniteElementType &)
Definition refinedfehelper.hh:20
T end(T... args)
T find(T... args)
T insert(T... args)
T make_pair(T... args)
T max(T... args)