1#ifndef DUNE_LOBATTOBASIS_HH
2#define DUNE_LOBATTOBASIS_HH
7#include <dune/geometry/topologyfactory.hh>
9#include <dune/geometry/referenceelements.hh>
11#include <dune/fem/common/forloop.hh>
13#if HAVE_DUNE_LOCALFUNCTIONS
14#include <dune/localfunctions/utility/field.hh>
15#include <dune/localfunctions/lagrange/lagrangecoefficients.hh>
16#include <dune/localfunctions/lagrange/emptypoints.hh>
17#include <dune/localfunctions/lagrange/equidistantpoints.hh>
24 template <
class Field>
27 template <
class Po
ints1DType>
28 static int size(
const GeometryType
gt,
const Points1DType &points1D)
30 if (
gt.dim()==0)
return 1;
31 else if (
gt.isPrismatic())
32 return Builder<Field>::size(Impl::getBase(
gt),points1D)*points1D.size();
35 std::cout <<
"Not implemented for pyramid geometries still missing!\n";
39 template <
unsigned int dim,
class Po
ints1DType>
40 static void setup(
const GeometryType
gt,
const Points1DType &points1D,
41 LagrangePoint< Field, dim > *points )
50 points->point_[0] = Zero<Field>();
53 else if (
gt.isPrismatic())
56 assert(dim>=
gt.dim());
57 Builder<Field>::template setup<dim>(baseGt,points1D,points);
58 const unsigned int baseSize = Builder::size(baseGt,points1D);
59 for (
unsigned int i=0;i<baseSize;++i)
61 Field weight = points[i].weight_;
62 for (
unsigned int q=0;q<points1D.size();q++)
64 const unsigned int pos = q*baseSize+i;
65 for (
unsigned int d=0;d<
gt.dim()-1;++d)
66 points[pos].point_[d] = points[i].point_[d];
67 points[pos].point_[
gt.dim()-1]=points1D[q].first;
68 points[pos].weight_ = weight*points1D[q].second;
74 std::cout <<
"Not implemented for pyramid geometries still missing!\n";
81 template<
class F,
unsigned int dim >
82 struct PointSetFromQuadrature :
public EmptyPointSet<F,dim>
84 static const unsigned int dimension = dim;
86 typedef EmptyPointSet<F,dim> Base;
87 typedef typename Base::LagrangePoint Point;
88 typedef std::vector<std::pair<Field,Field>> Points1DType;
89 PointSetFromQuadrature(
unsigned int order)
90 : Base(order), quadOrder_(-1)
93 template <GeometryType::Id geometryId,
class Quad>
94 bool build (
const Quad& quadFactory)
97 unsigned int order = Base::order();
98 const auto &quad = quadFactory(order);
99 quadOrder_ = quad.order();
100 assert( quad.size() == order+1 );
101 bool withEndPoints =
false;
102 Points1DType points1D;
103 Field vertexWeight = 1;
104 for (
unsigned int i=0;i<=order;++i)
108 Field p = field_cast<Field>(quad[i].position());
110 if (std::abs(p)<1e-12 || std::abs(q)<1e-12)
112 withEndPoints =
true;
113 vertexWeight = quad[i].weight();
116 points1D.push_back(std::make_pair(p,quad[i].weight()));
119 Dune::Fem::ForLoop<Setup::template InitCodim,0,dimension>::
120 apply(
gt,order,points1D,vertexWeight,points_);
122 Setup::template InitCodim<dimension>::
123 apply(
gt,order,points1D,vertexWeight,points_);
126 static bool supports ( GeometryType
gt,
int order )
130 template< GeometryType::Id geometryId>
131 static bool supports ( std::size_t order ) {
134 unsigned int quadOrder()
const
140 unsigned int quadOrder_;
147 static const unsigned int codim = dimension-pdim;
148 static void apply(GeometryType
gt,
const unsigned int order,
149 const Points1DType &points1D,
150 const Field &vertexWeight,
151 std::vector<Point> &points)
153 const unsigned int subEntities = Dune::Geo::Impl::size(
gt.id(),
gt.dim(),codim);
154 for (
unsigned int subEntity=0;subEntity<subEntities;++subEntity)
157 unsigned int oldSize = points.size();
158 unsigned int size = Impl::Builder<Field>::size(subGt,points1D);
159 if (
size==0)
continue;
160 points.resize(oldSize+
size);
161 std::vector< LagrangePoint<Field,dimension-codim> > subPoints(
size);
162 Impl::Builder<Field>::template setup<dimension-codim>( subGt, points1D, &(subPoints[0]) );
164 const auto &refElement = referenceElement<Field,dimension>(
gt);
165 const auto &mapping = refElement.template geometry< codim >( subEntity );
167 LagrangePoint<Field,dimension> *p = &(points[oldSize]);
168 for (
unsigned int nr = 0; nr<
size; ++nr, ++p)
170 p->point_ = mapping.global( subPoints[nr].point_ );
171 p->weight_ = subPoints[nr].weight_ * std::pow(vertexWeight,codim)*refElement.volume();
172 p->localKey_ = LocalKey( subEntity, codim, nr );
183 template<
class F,
unsigned int dim >
184 struct EquidistantPointSetDerived :
public Dune::EquidistantPointSet< F, dim >
186 typedef Dune::EquidistantPointSet< F, dim > Base;
188 EquidistantPointSetDerived(
unsigned int order)
193 static const int pointSetId = Dune::QuadratureType::size;
195 static unsigned int quad2PolOrder(
int order) {
return order; }
196 unsigned int quadOrder()
const {
return Base::order(); }
198 static auto buildCubeQuadrature(
unsigned int quadOrder)
200 using namespace Impl;
201 EquidistantPointSetDerived ps(quad2PolOrder(quadOrder));
202 ps.template build<GeometryTypes::cube(dim)>();
211 template<
class F,
unsigned int dim >
212 struct GaussLobattoPointSet :
public PointSetFromQuadrature<F,dim>
214 static const unsigned int dimension = dim;
216 typedef PointSetFromQuadrature<F,dim> Base;
217 typedef typename Base::LagrangePoint Point;
222 GaussLobattoPointSet(
unsigned int order)
225 template< GeometryType::Id geometryId >
229 auto quadFactory = [](
int order)
234 return Base::template build<geometryId>(quadFactory);
236 static unsigned int pol2QuadOrder(
int order)
238 return (order>0)? 2*order-1 : 0;
240 static unsigned int quad2PolOrder(
int order)
245 static auto buildCubeQuadrature(
unsigned int quadOrder)
247 using namespace Impl;
248 GaussLobattoPointSet ps(quad2PolOrder(quadOrder));
249 ps.template build<GeometryTypes::cube(dim)>();
255 template<
class F,
unsigned int dim >
256 struct GaussLegendrePointSet :
public PointSetFromQuadrature<F,dim>
258 static const unsigned int dimension = dim;
260 typedef PointSetFromQuadrature<F,dim> Base;
261 typedef typename Base::LagrangePoint Point;
266 GaussLegendrePointSet(
unsigned int order)
269 template< GeometryType::Id geometryId >
273 auto quadFactory = [](
int order)
277 return Base::template build<GeometryType(geometryId)>(quadFactory);
280 static unsigned int pol2QuadOrder(
int order)
284 static unsigned int quad2PolOrder(
int order)
289 static auto buildCubeQuadrature(
unsigned int quadOrder)
291 using namespace Impl;
292 GaussLegendrePointSet ps(quad2PolOrder(quadOrder));
293 ps.template build<GeometryTypes::cube(dim)>();
302 template<
class F,
unsigned int dim >
303 struct CellCentersPointSet :
public PointSetFromQuadrature<F,dim>
305 typedef PointSetFromQuadrature<F,dim> Base;
306 static const unsigned int dimension = dim;
310 static const int pointSetId = Dune::QuadratureType::size+1;
312 CellCentersPointSet(
unsigned int order)
319 template<
typename ct>
324 enum { highest_order=7 };
326 friend class QuadratureRuleFactory<ct,1>;
329 this->delivered_order = p;
332 const Field h = 1./Field(n);
334 for(
int i=0; i<n; ++i )
336 const Field x = 0.5*h + h*i;
337 assert( x > 0.0 && x < 1.0 );
338 this->
push_back(QuadraturePoint<ct,1>(x, h));
343 static unsigned int quad2PolOrder(
int order) {
return order; }
345 unsigned int quadOrder()
const {
return Base::order(); }
347 template< GeometryType::Id geometryId >
351 auto quadFactory = [](
int order)
353 return CellCenters<Field>(order);
355 return Base::template build<geometryId>(quadFactory);
357 static auto buildCubeQuadrature(
unsigned int quadOrder)
359 using namespace Impl;
360 CellCentersPointSet ps(quad2PolOrder(quadOrder));
361 ps.template build<GeometryTypes::cube(dim)>();
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:214
static const QuadratureRule & rule(const GeometryType &t, int p, QuadratureType::Enum qt=QuadratureType::GaussLegendre)
select the appropriate QuadratureRule for GeometryType t and order p
Definition: quadraturerules.hh:326
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
constexpr GeometryType line
GeometryType representing a line.
Definition: type.hh:498
@ GaussLobatto
Gauss-Lobatto rules.
Definition: quadraturerules.hh:176
@ GaussLegendre
Gauss-Legendre rules (default)
Definition: quadraturerules.hh:141
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integer_sequence< T, II..., T(IN)> push_back(std::integer_sequence< T, II... >, std::integral_constant< T, IN >={})
Append an index IN to the back of the sequence.
Definition: integersequence.hh:69
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
A unique label for each type of element that can occur in a grid.