3#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS_RAVIARTTHOMASSIMPLEX_RAVIARTTHOMASSIMPLEXINTERPOLATION_HH
4#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS_RAVIARTTHOMASSIMPLEX_RAVIARTTHOMASSIMPLEXINTERPOLATION_HH
11#include <dune/geometry/topologyfactory.hh>
13#include <dune/geometry/referenceelements.hh>
16#include <dune/localfunctions/common/localkey.hh>
17#include <dune/localfunctions/utility/interpolationhelper.hh>
18#include <dune/localfunctions/utility/polynomialbasis.hh>
19#include <dune/localfunctions/orthonormal/orthonormalbasis.hh>
27 template <
unsigned int dim >
28 struct RaviartThomasCoefficientsFactory;
30 template <
unsigned int dim,
class Field >
31 struct RaviartThomasL2InterpolationFactory;
38 class LocalCoefficientsContainer
40 typedef LocalCoefficientsContainer This;
43 template <
class Setter>
44 LocalCoefficientsContainer (
const Setter &setter )
46 setter.setLocalKeys(localKey_);
49 const LocalKey &localKey (
const unsigned int i )
const
52 return localKey_[ i ];
55 unsigned int size ()
const
57 return localKey_.size();
61 std::vector< LocalKey > localKey_;
69 template <
unsigned int dim >
70 struct RaviartThomasCoefficientsFactoryTraits
72 static const unsigned int dimension = dim;
73 typedef const LocalCoefficientsContainer Object;
74 typedef unsigned int Key;
75 typedef RaviartThomasCoefficientsFactory<dim> Factory;
83 template <
unsigned int dim >
84 struct RaviartThomasCoefficientsFactory
85 :
public TopologyFactory< RaviartThomasCoefficientsFactoryTraits< dim > >
87 typedef RaviartThomasCoefficientsFactoryTraits< dim > Traits;
89 template<
class Topology >
90 static typename Traits::Object *createObject(
const typename Traits::Key &key )
92 typedef RaviartThomasL2InterpolationFactory< dim, double > InterpolationFactory;
93 if( !supports< Topology >( key ) )
95 typename InterpolationFactory::Object *interpolation = InterpolationFactory::template create< Topology >( key );
96 typename Traits::Object *localKeys =
new typename Traits::Object( *interpolation );
97 InterpolationFactory::release( interpolation );
101 template<
class Topology >
102 static bool supports (
const typename Traits::Key &key )
104 return Impl::IsSimplex< Topology >::value;
119 template<
unsigned int dim,
class Field >
120 struct RTL2InterpolationBuilder
122 static const unsigned int dimension = dim;
123 typedef OrthonormalBasisFactory< dimension, Field > TestBasisFactory;
124 typedef typename TestBasisFactory::Object TestBasis;
125 typedef OrthonormalBasisFactory< dimension-1, Field > TestFaceBasisFactory;
126 typedef typename TestFaceBasisFactory::Object TestFaceBasis;
129 RTL2InterpolationBuilder () =
default;
131 RTL2InterpolationBuilder (
const RTL2InterpolationBuilder & ) =
delete;
132 RTL2InterpolationBuilder ( RTL2InterpolationBuilder && ) =
delete;
134 ~RTL2InterpolationBuilder ()
136 TestBasisFactory::release( testBasis_ );
137 for( FaceStructure &f : faceStructure_ )
138 TestFaceBasisFactory::release( f.basis_ );
141 unsigned int topologyId ()
const {
return topologyId_; }
145 unsigned int order ()
const {
return order_; }
147 unsigned int faceSize ()
const {
return faceSize_; }
149 TestBasis *testBasis ()
const {
return testBasis_; }
150 TestFaceBasis *testFaceBasis (
unsigned int f )
const { assert( f < faceSize() );
return faceStructure_[ f ].basis_; }
152 const Normal &normal (
unsigned int f )
const { assert( f < faceSize() );
return *(faceStructure_[ f ].normal_); }
154 template<
class Topology >
155 void build (
unsigned int order )
158 topologyId_ = Topology::id;
160 testBasis_ = (order > 0 ? TestBasisFactory::template create< Topology >( order-1 ) : nullptr);
163 faceSize_ = refElement.size( 1 );
164 faceStructure_.reserve( faceSize_ );
165 for(
unsigned int face = 0; face < faceSize_; ++face )
168 faceStructure_.emplace_back( faceBasis, refElement.integrationOuterNormal( face ) );
170 assert( faceStructure_.size() == faceSize_ );
176 FaceStructure( TestFaceBasis *tfb,
const Normal &n )
177 : basis_( tfb ), normal_( &n )
180 TestFaceBasis *basis_;
184 template<
class FaceTopology >
185 struct CreateFaceBasis
187 static TestFaceBasis *
apply (
unsigned int order ) {
return TestFaceBasisFactory::template create< FaceTopology >( order ); }
190 std::vector< FaceStructure > faceStructure_;
191 TestBasis *testBasis_ =
nullptr;
192 unsigned int topologyId_, order_, faceSize_;
205 template<
unsigned int dimension,
class F>
207 :
public InterpolationHelper< F ,dimension >
210 typedef InterpolationHelper<F,dimension> Base;
214 typedef RTL2InterpolationBuilder<dimension,Field> Builder;
220 template<
class Function,
class Fy >
221 void interpolate (
const Function &function, std::vector< Fy > &coefficients )
const
223 coefficients.resize(size());
224 typename Base::template Helper<Function,std::vector<Fy>,
true> func( function,coefficients );
227 template<
class Basis,
class Matrix >
228 void interpolate (
const Basis &basis,
Matrix &matrix )
const
230 matrix.resize( size(), basis.size() );
231 typename Base::template Helper<Basis,Matrix,false> func( basis,matrix );
235 unsigned int order()
const
239 unsigned int size()
const
243 template <
class Topology>
244 void build(
unsigned int order )
248 builder_.template build<Topology>(order_);
249 if (builder_.testBasis())
250 size_ += dimension*builder_.testBasis()->size();
251 for (
unsigned int f=0; f<builder_.faceSize(); ++f )
252 if (builder_.testFaceBasis(f))
253 size_ += builder_.testFaceBasis(f)->size();
256 void setLocalKeys(std::vector< LocalKey > &keys)
const
259 unsigned int row = 0;
260 for (
unsigned int f=0; f<builder_.faceSize(); ++f)
262 if (builder_.faceSize())
263 for (
unsigned int i=0; i<builder_.testFaceBasis(f)->size(); ++i,++row)
266 if (builder_.testBasis())
267 for (
unsigned int i=0; i<builder_.testBasis()->size()*dimension; ++i,++row)
269 assert( row == size() );
273 template<
class Func,
class Container,
bool type >
274 void interpolate (
typename Base::template Helper<Func,Container,type> &func )
const
278 std::vector< Field > testBasisVal;
280 for (
unsigned int i=0; i<size(); ++i)
281 for (
unsigned int j=0; j<func.size(); ++j)
284 unsigned int row = 0;
292 for (
unsigned int f=0; f<builder_.faceSize(); ++f)
294 if (!builder_.testFaceBasis(f))
296 testBasisVal.resize(builder_.testFaceBasis(f)->size());
298 const auto &geometry = refElement.template geometry< 1 >( f );
300 const FaceQuadrature &faceQuad = FaceQuadratureRules::rule( subGeoType, 2*order_+2 );
302 const unsigned int quadratureSize = faceQuad.size();
303 for(
unsigned int qi = 0; qi < quadratureSize; ++qi )
306 builder_.testFaceBasis(f)->template evaluate<0>(faceQuad[qi].position(),testBasisVal);
308 testBasisVal[0] = 1.;
309 fillBnd( row, testBasisVal,
310 func.evaluate( geometry.global( faceQuad[qi].position() ) ),
311 builder_.normal(f), faceQuad[qi].weight(),
315 row += builder_.testFaceBasis(f)->size();
318 if (builder_.testBasis())
320 testBasisVal.resize(builder_.testBasis()->size());
326 const unsigned int quadratureSize = elemQuad.size();
327 for(
unsigned int qi = 0; qi < quadratureSize; ++qi )
329 builder_.testBasis()->template evaluate<0>(elemQuad[qi].position(),testBasisVal);
330 fillInterior( row, testBasisVal,
331 func.evaluate(elemQuad[qi].position()),
332 elemQuad[qi].weight(),
336 row += builder_.testBasis()->size()*dimension;
343 template <
class MVal,
class RTVal,
class Matrix>
344 void fillBnd (
unsigned int startRow,
351 const unsigned int endRow = startRow+mVal.size();
352 typename RTVal::const_iterator rtiter = rtVal.begin();
353 for (
unsigned int col = 0; col < rtVal.size() ; ++rtiter,++col)
355 Field cFactor = (*rtiter)*normal;
356 typename MVal::const_iterator miter = mVal.
begin();
357 for (
unsigned int row = startRow;
358 row!=endRow; ++miter, ++row )
360 matrix.add(row,col, (weight*cFactor)*(*miter) );
362 assert( miter == mVal.end() );
365 template <
class MVal,
class RTVal,
class Matrix>
366 void fillInterior (
unsigned int startRow,
372 const unsigned int endRow = startRow+mVal.size()*dimension;
373 typename RTVal::const_iterator rtiter = rtVal.begin();
374 for (
unsigned int col = 0; col < rtVal.size() ; ++rtiter,++col)
376 typename MVal::const_iterator miter = mVal.begin();
377 for (
unsigned int row = startRow;
378 row!=endRow; ++miter,row+=dimension )
380 for (
unsigned int i=0; i<dimension; ++i)
382 matrix.add(row+i,col, (weight*(*miter))*(*rtiter)[i] );
385 assert( miter == mVal.end() );
394 template <
unsigned int dim,
class F >
395 struct RaviartThomasL2InterpolationFactoryTraits
397 static const unsigned int dimension = dim;
398 typedef unsigned int Key;
400 typedef RaviartThomasL2InterpolationFactory<dim,F> Factory;
402 template <
unsigned int dim,
class Field >
403 struct RaviartThomasL2InterpolationFactory :
404 public TopologyFactory< RaviartThomasL2InterpolationFactoryTraits<dim,Field> >
406 typedef RaviartThomasL2InterpolationFactoryTraits<dim,Field> Traits;
407 typedef RTL2InterpolationBuilder<dim,Field> Builder;
408 typedef typename Traits::Object Object;
409 typedef typename std::remove_const<Object>::type NonConstObject;
410 template <
class Topology>
411 static typename Traits::Object *createObject(
const typename Traits::Key &key )
413 if ( !supports<Topology>(key) )
415 NonConstObject *interpol =
new NonConstObject();
416 interpol->template build<Topology>(key);
419 template<
class Topology >
420 static bool supports (
const typename Traits::Key &key )
422 return Impl::IsSimplex<Topology>::value;
Iterator begin()
begin iterator
Definition: densevector.hh:308
Base class template for function classes.
Definition: function.hh:29
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
Describe position of one degree of freedom.
Definition: localkey.hh:21
A generic dynamic dense matrix.
Definition: matrix.hh:555
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:97
A container for all quadrature rules of dimension dim
Definition: quadraturerules.hh:143
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:225
An L2-based interpolation for Raviart Thomas.
Definition: raviartthomassimplexinterpolation.hh:208
A few common exception classes.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
Dune namespace.
Definition: alignedallocator.hh:10
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:196
A unique label for each type of element that can occur in a grid.