3#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS_RAVIARTTHOMASSIMPLEX_RAVIARTTHOMASSIMPLEXINTERPOLATION_HH
4#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS_RAVIARTTHOMASSIMPLEX_RAVIARTTHOMASSIMPLEXINTERPOLATION_HH
12#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,
class Field >
28 struct RaviartThomasL2InterpolationFactory;
35 class LocalCoefficientsContainer
37 typedef LocalCoefficientsContainer This;
40 template <
class Setter>
41 LocalCoefficientsContainer (
const Setter &setter )
43 setter.setLocalKeys(localKey_);
46 const LocalKey &localKey (
const unsigned int i )
const
49 return localKey_[ i ];
52 std::size_t size ()
const
54 return localKey_.size();
58 std::vector< LocalKey > localKey_;
66 template <
unsigned int dim >
67 struct RaviartThomasCoefficientsFactory
69 typedef std::size_t Key;
70 typedef const LocalCoefficientsContainer Object;
72 template< GeometryType::Id geometryId >
73 static Object *create(
const Key &key )
75 typedef RaviartThomasL2InterpolationFactory< dim, double > InterpolationFactory;
76 if( !supports< geometryId >( key ) )
78 typename InterpolationFactory::Object *interpolation = InterpolationFactory::template create< geometryId >( key );
79 Object *localKeys =
new Object( *interpolation );
80 InterpolationFactory::release( interpolation );
84 template< GeometryType::Id geometryId >
85 static bool supports (
const Key &key )
89 static void release( Object *
object ) {
delete object; }
103 template<
unsigned int dim,
class Field >
104 struct RTL2InterpolationBuilder
106 static const unsigned int dimension = dim;
109 typedef OrthonormalBasisFactory< dimension, Field > TestBasisFactory;
110 typedef typename TestBasisFactory::Object TestBasis;
113 typedef OrthonormalBasisFactory< dimension-1, Field > TestFaceBasisFactory;
114 typedef typename TestFaceBasisFactory::Object TestFaceBasis;
119 RTL2InterpolationBuilder () =
default;
121 RTL2InterpolationBuilder (
const RTL2InterpolationBuilder & ) =
delete;
122 RTL2InterpolationBuilder ( RTL2InterpolationBuilder && ) =
delete;
124 ~RTL2InterpolationBuilder ()
126 TestBasisFactory::release( testBasis_ );
127 for( FaceStructure &f : faceStructure_ )
128 TestFaceBasisFactory::release( f.basis_ );
131 [[deprecated(
"Use type().id() instead.")]]
132 unsigned int topologyId ()
const {
return type().id(); }
136 std::size_t order ()
const {
return order_; }
139 unsigned int faceSize ()
const {
return faceSize_; }
142 TestBasis *testBasis ()
const {
return testBasis_; }
145 TestFaceBasis *testFaceBasis (
unsigned int f )
const { assert( f < faceSize() );
return faceStructure_[ f ].basis_; }
148 const Normal &normal (
unsigned int f )
const { assert( f < faceSize() );
return *(faceStructure_[ f ].normal_); }
150 template< GeometryType::Id geometryId >
151 void build ( std::size_t order )
154 geometry_ = geometry;
157 testBasis_ = (order > 0 ? TestBasisFactory::template create< geometry >( order-1 ) : nullptr);
160 faceSize_ = refElement.size( 1 );
161 faceStructure_.reserve( faceSize_ );
162 for(
unsigned int face = 0; face < faceSize_; ++face )
175 TestFaceBasis *faceBasis = Impl::toGeometryTypeIdConstant<dimension-1>(refElement.type( face, 1 ), [&](
auto faceGeometryTypeId) {
176 return TestFaceBasisFactory::template create< decltype(faceGeometryTypeId)::value >( order );
178 faceStructure_.emplace_back( faceBasis, refElement.integrationOuterNormal( face ) );
180 assert( faceStructure_.size() == faceSize_ );
186 FaceStructure( TestFaceBasis *tfb,
const Normal &n )
187 : basis_( tfb ), normal_( &n )
190 TestFaceBasis *basis_;
194 std::vector< FaceStructure > faceStructure_;
195 TestBasis *testBasis_ =
nullptr;
197 unsigned int faceSize_;
211 template<
unsigned int dimension,
class F>
213 :
public InterpolationHelper< F ,dimension >
216 typedef InterpolationHelper<F,dimension> Base;
220 typedef RTL2InterpolationBuilder<dimension,Field> Builder;
226 template<
class Function,
class Vector >
227 auto interpolate (
const Function &function, Vector &coefficients )
const
228 -> std::enable_if_t< std::is_same< decltype(std::declval<Vector>().resize(1) ),
void >::value,
void>
230 coefficients.resize(size());
231 typename Base::template Helper<Function,Vector,true> func( function,coefficients );
235 template<
class Basis,
class Matrix >
236 auto interpolate (
const Basis &basis,
Matrix &matrix )
const
237 -> std::enable_if_t< std::is_same<
238 decltype(std::declval<Matrix>().rowPtr(0)),
typename Matrix::Field* >::value,
void>
240 matrix.resize( size(), basis.size() );
241 typename Base::template Helper<Basis,Matrix,false> func( basis,matrix );
245 std::size_t order()
const
249 std::size_t size()
const
253 template <GeometryType::Id geometryId>
254 void build( std::size_t order )
258 builder_.template build<geometryId>(order_);
259 if (builder_.testBasis())
260 size_ += dimension*builder_.testBasis()->size();
261 for (
unsigned int f=0; f<builder_.faceSize(); ++f )
262 if (builder_.testFaceBasis(f))
263 size_ += builder_.testFaceBasis(f)->size();
266 void setLocalKeys(std::vector< LocalKey > &keys)
const
269 unsigned int row = 0;
270 for (
unsigned int f=0; f<builder_.faceSize(); ++f)
272 if (builder_.faceSize())
273 for (
unsigned int i=0; i<builder_.testFaceBasis(f)->size(); ++i,++row)
276 if (builder_.testBasis())
277 for (
unsigned int i=0; i<builder_.testBasis()->size()*dimension; ++i,++row)
279 assert( row == size() );
283 template<
class Func,
class Container,
bool type >
284 void interpolate (
typename Base::template Helper<Func,Container,type> &func )
const
288 std::vector< Field > testBasisVal;
290 for (
unsigned int i=0; i<size(); ++i)
291 for (
unsigned int j=0; j<func.size(); ++j)
294 unsigned int row = 0;
302 for (
unsigned int f=0; f<builder_.faceSize(); ++f)
304 if (!builder_.testFaceBasis(f))
306 testBasisVal.resize(builder_.testFaceBasis(f)->size());
308 const auto &geometry = refElement.template geometry< 1 >( f );
310 const FaceQuadrature &faceQuad = FaceQuadratureRules::rule( subGeoType, 2*order_+2 );
312 const unsigned int quadratureSize = faceQuad.size();
313 for(
unsigned int qi = 0; qi < quadratureSize; ++qi )
316 builder_.testFaceBasis(f)->template evaluate<0>(faceQuad[qi].position(),testBasisVal);
318 testBasisVal[0] = 1.;
319 fillBnd( row, testBasisVal,
320 func.evaluate( geometry.global( faceQuad[qi].position() ) ),
321 builder_.normal(f), faceQuad[qi].weight(),
325 row += builder_.testFaceBasis(f)->size();
328 if (builder_.testBasis())
330 testBasisVal.resize(builder_.testBasis()->size());
336 const unsigned int quadratureSize = elemQuad.size();
337 for(
unsigned int qi = 0; qi < quadratureSize; ++qi )
339 builder_.testBasis()->template evaluate<0>(elemQuad[qi].position(),testBasisVal);
340 fillInterior( row, testBasisVal,
341 func.evaluate(elemQuad[qi].position()),
342 elemQuad[qi].weight(),
346 row += builder_.testBasis()->size()*dimension;
361 template <
class MVal,
class RTVal,
class Matrix>
362 void fillBnd (
unsigned int startRow,
369 const unsigned int endRow = startRow+mVal.size();
370 typename RTVal::const_iterator rtiter = rtVal.begin();
371 for (
unsigned int col = 0; col < rtVal.size() ; ++rtiter,++col)
373 Field cFactor = (*rtiter)*normal;
374 typename MVal::const_iterator miter = mVal.
begin();
375 for (
unsigned int row = startRow;
376 row!=endRow; ++miter, ++row )
378 matrix.add(row,col, (weight*cFactor)*(*miter) );
380 assert( miter == mVal.end() );
391 template <
class MVal,
class RTVal,
class Matrix>
392 void fillInterior (
unsigned int startRow,
398 const unsigned int endRow = startRow+mVal.size()*dimension;
399 typename RTVal::const_iterator rtiter = rtVal.begin();
400 for (
unsigned int col = 0; col < rtVal.size() ; ++rtiter,++col)
402 typename MVal::const_iterator miter = mVal.begin();
403 for (
unsigned int row = startRow;
404 row!=endRow; ++miter,row+=dimension )
406 for (
unsigned int i=0; i<dimension; ++i)
408 matrix.add(row+i,col, (weight*(*miter))*(*rtiter)[i] );
411 assert( miter == mVal.end() );
420 template <
unsigned int dim,
class Field >
421 struct RaviartThomasL2InterpolationFactory
423 typedef RTL2InterpolationBuilder<dim,Field> Builder;
425 typedef std::size_t Key;
426 typedef typename std::remove_const<Object>::type NonConstObject;
428 template <GeometryType::Id geometryId>
429 static Object *create(
const Key &key )
431 if ( !supports<geometryId>(key) )
433 NonConstObject *interpol =
new NonConstObject();
434 interpol->template build<geometryId>(key);
437 template< GeometryType::Id geometryId >
438 static bool supports (
const Key &key )
440 return GeometryType(geometryId).isSimplex();
442 static void release( Object *
object ) {
delete object; }
Iterator begin()
begin iterator
Definition: densevector.hh:348
Base class template for function classes.
Definition: function.hh:39
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
Describe position of one degree of freedom.
Definition: localkey.hh:21
A generic dynamic dense matrix.
Definition: matrix.hh:559
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:152
A container for all quadrature rules of dimension dim
Definition: quadraturerules.hh:198
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:280
An L2-based interpolation for Raviart Thomas.
Definition: raviartthomassimplexinterpolation.hh:214
A few common exception classes.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
Dune namespace.
Definition: alignedallocator.hh:11
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.
Helper classes to provide indices for geometrytypes for use in a vector.