5#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS_RAVIARTTHOMASSIMPLEX_RAVIARTTHOMASSIMPLEXINTERPOLATION_HH
6#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS_RAVIARTTHOMASSIMPLEX_RAVIARTTHOMASSIMPLEXINTERPOLATION_HH
11#include <dune/common/exceptions.hh>
13#include <dune/geometry/quadraturerules.hh>
14#include <dune/geometry/referenceelements.hh>
15#include <dune/geometry/type.hh>
16#include <dune/geometry/typeindex.hh>
29 template <
unsigned int dim,
class Field >
30 struct RaviartThomasL2InterpolationFactory;
37 class LocalCoefficientsContainer
42 template <
class Setter>
45 setter.setLocalKeys(localKey_);
51 return localKey_[ i ];
56 return localKey_.size();
60 std::vector< LocalKey > localKey_;
68 template <
unsigned int dim >
71 typedef std::size_t
Key;
74 template< GeometryType::Id geometryId >
78 if( !supports< geometryId >( key ) )
80 typename InterpolationFactory::Object *interpolation = InterpolationFactory::template create< geometryId >( key );
82 InterpolationFactory::release( interpolation );
86 template< GeometryType::Id geometryId >
89 return GeometryType(geometryId).isSimplex();
105 template<
unsigned int dim,
class Field >
119 typedef FieldVector< Field, dimension >
Normal;
129 for( FaceStructure &f : faceStructure_ )
133 GeometryType
type ()
const {
return geometry_; }
135 std::size_t
order ()
const {
return order_; }
138 unsigned int faceSize ()
const {
return faceSize_; }
147 const Normal &
normal (
unsigned int f )
const { assert( f <
faceSize() );
return *(faceStructure_[ f ].normal_); }
149 template< GeometryType::Id geometryId >
152 constexpr GeometryType geometry = geometryId;
153 geometry_ = geometry;
156 testBasis_ = (
order > 0 ? TestBasisFactory::template create< geometry >(
order-1 ) :
nullptr);
158 const auto &refElement = ReferenceElements< Field, dimension >::general(
type() );
159 faceSize_ = refElement.size( 1 );
160 faceStructure_.reserve( faceSize_ );
161 for(
unsigned int face = 0; face < faceSize_; ++face )
174 TestFaceBasis *faceBasis = Impl::toGeometryTypeIdConstant<
dimension-1>(refElement.type( face, 1 ), [&](
auto faceGeometryTypeId) {
175 return TestFaceBasisFactory::template create< decltype(faceGeometryTypeId)::value >(
order );
177 faceStructure_.emplace_back( faceBasis, refElement.integrationOuterNormal( face ) );
179 assert( faceStructure_.size() == faceSize_ );
186 : basis_( tfb ), normal_( &n )
190 const Dune::FieldVector< Field, dimension > *normal_;
193 std::vector< FaceStructure > faceStructure_;
195 GeometryType geometry_;
196 unsigned int faceSize_;
210 template<
unsigned int dimension,
class F>
225 template<
class Function,
class Vector >
226 auto interpolate (
const Function &function, Vector &coefficients )
const
227 -> std::enable_if_t< std::is_same< decltype(std::declval<Vector>().resize(1) ),
void >
::value,
void>
229 coefficients.resize(
size());
234 template<
class Basis,
class Matrix >
236 -> std::enable_if_t< std::is_same<
237 decltype(std::declval<Matrix>().rowPtr(0)),
typename Matrix::Field* >
::value,
void>
239 matrix.resize(
size(), basis.size() );
252 template <GeometryType::Id geometryId>
257 builder_.template build<geometryId>(order_);
260 for (
unsigned int f=0; f<builder_.
faceSize(); ++f )
268 unsigned int row = 0;
269 for (
unsigned int f=0; f<builder_.
faceSize(); ++f)
276 for (
unsigned int i=0; i<builder_.
testBasis()->
size()*dimension; ++i,++row)
278 assert( row ==
size() );
282 template<
class Func,
class Container,
bool type >
285 const Dune::GeometryType geoType = builder_.
type();
287 std::vector< Field > testBasisVal;
289 for (
unsigned int i=0; i<
size(); ++i)
290 for (
unsigned int j=0; j<func.size(); ++j)
293 unsigned int row = 0;
296 typedef Dune::QuadratureRule<
Field, dimension-1> FaceQuadrature;
297 typedef Dune::QuadratureRules<
Field, dimension-1> FaceQuadratureRules;
299 const auto &refElement = Dune::ReferenceElements< Field, dimension >::general( geoType );
301 for (
unsigned int f=0; f<builder_.
faceSize(); ++f)
307 const auto &geometry = refElement.template geometry< 1 >( f );
308 const Dune::GeometryType subGeoType( geometry.type().id(), dimension-1 );
309 const FaceQuadrature &faceQuad = FaceQuadratureRules::rule( subGeoType, 2*order_+2 );
311 const unsigned int quadratureSize = faceQuad.size();
312 for(
unsigned int qi = 0; qi < quadratureSize; ++qi )
315 builder_.
testFaceBasis(f)->template evaluate<0>(faceQuad[qi].position(),testBasisVal);
317 testBasisVal[0] = 1.;
318 fillBnd( row, testBasisVal,
319 func.evaluate( geometry.global( faceQuad[qi].position() ) ),
320 builder_.
normal(f), faceQuad[qi].weight(),
331 typedef Dune::QuadratureRule<Field, dimension> Quadrature;
332 typedef Dune::QuadratureRules<Field, dimension> QuadratureRules;
333 const Quadrature &elemQuad = QuadratureRules::rule( geoType, 2*order_+1 );
335 const unsigned int quadratureSize = elemQuad.size();
336 for(
unsigned int qi = 0; qi < quadratureSize; ++qi )
338 builder_.
testBasis()->template evaluate<0>(elemQuad[qi].position(),testBasisVal);
339 fillInterior( row, testBasisVal,
340 func.evaluate(elemQuad[qi].position()),
341 elemQuad[qi].weight(),
360 template <
class MVal,
class RTVal,
class Matrix>
361 void fillBnd (
unsigned int startRow,
364 const FieldVector<Field,dimension> &normal,
366 Matrix &matrix)
const
368 const unsigned int endRow = startRow+mVal.size();
369 typename RTVal::const_iterator rtiter = rtVal.begin();
370 for (
unsigned int col = 0; col < rtVal.size() ; ++rtiter,++col)
372 Field cFactor = (*rtiter)*normal;
373 typename MVal::const_iterator miter = mVal.begin();
374 for (
unsigned int row = startRow;
375 row!=endRow; ++miter, ++row )
377 matrix.add(row,col, (weight*cFactor)*(*miter) );
379 assert( miter == mVal.end() );
390 template <
class MVal,
class RTVal,
class Matrix>
391 void fillInterior (
unsigned int startRow,
395 Matrix &matrix)
const
397 const unsigned int endRow = startRow+mVal.size()*dimension;
398 typename RTVal::const_iterator rtiter = rtVal.begin();
399 for (
unsigned int col = 0; col < rtVal.size() ; ++rtiter,++col)
401 typename MVal::const_iterator miter = mVal.begin();
402 for (
unsigned int row = startRow;
403 row!=endRow; ++miter,row+=dimension )
405 for (
unsigned int i=0; i<dimension; ++i)
407 matrix.add(row+i,col, (weight*(*miter))*(*rtiter)[i] );
410 assert( miter == mVal.end() );
419 template <
unsigned int dim,
class Field >
427 template <GeometryType::Id geometryId>
430 if ( !supports<geometryId>(key) )
433 interpol->template build<geometryId>(key);
436 template< GeometryType::Id geometryId >
439 return GeometryType(geometryId).isSimplex();
Definition: bdfmcube.hh:18
@ value
Definition: tensor.hh:168
Describe position of one degree of freedom.
Definition: localkey.hh:23
Definition: nedelecsimplexinterpolation.hh:38
LocalCoefficientsContainer(const Setter &setter)
Definition: nedelecsimplexinterpolation.hh:43
const LocalKey & localKey(const unsigned int i) const
Definition: raviartthomassimplexinterpolation.hh:48
std::size_t size() const
Definition: nedelecsimplexinterpolation.hh:54
Definition: orthonormalbasis.hh:20
static void release(Object *object)
Definition: orthonormalbasis.hh:57
Definition: raviartthomassimplexinterpolation.hh:421
std::remove_const< Object >::type NonConstObject
Definition: raviartthomassimplexinterpolation.hh:425
static void release(Object *object)
Definition: raviartthomassimplexinterpolation.hh:441
static bool supports(const Key &key)
Definition: raviartthomassimplexinterpolation.hh:437
static Object * create(const Key &key)
Definition: raviartthomassimplexinterpolation.hh:428
RTL2InterpolationBuilder< dim, Field > Builder
Definition: raviartthomassimplexinterpolation.hh:422
const RaviartThomasL2Interpolation< dim, Field > Object
Definition: raviartthomassimplexinterpolation.hh:423
std::size_t Key
Definition: raviartthomassimplexinterpolation.hh:424
Definition: raviartthomassimplexinterpolation.hh:70
std::size_t Key
Definition: raviartthomassimplexinterpolation.hh:71
static void release(Object *object)
Definition: raviartthomassimplexinterpolation.hh:91
static bool supports(const Key &key)
Definition: raviartthomassimplexinterpolation.hh:87
const LocalCoefficientsContainer Object
Definition: raviartthomassimplexinterpolation.hh:72
static Object * create(const Key &key)
Definition: raviartthomassimplexinterpolation.hh:75
Definition: raviartthomassimplexinterpolation.hh:107
TestBasis * testBasis() const
Definition: raviartthomassimplexinterpolation.hh:141
FieldVector< Field, dimension > Normal
Definition: raviartthomassimplexinterpolation.hh:119
TestBasisFactory::Object TestBasis
Definition: raviartthomassimplexinterpolation.hh:112
TestFaceBasisFactory::Object TestFaceBasis
Definition: raviartthomassimplexinterpolation.hh:116
unsigned int faceSize() const
Definition: raviartthomassimplexinterpolation.hh:138
void build(std::size_t order)
Definition: raviartthomassimplexinterpolation.hh:150
RTL2InterpolationBuilder()=default
TestFaceBasis * testFaceBasis(unsigned int f) const
Definition: raviartthomassimplexinterpolation.hh:144
GeometryType type() const
Definition: raviartthomassimplexinterpolation.hh:133
const Normal & normal(unsigned int f) const
Definition: raviartthomassimplexinterpolation.hh:147
RTL2InterpolationBuilder(const RTL2InterpolationBuilder &)=delete
OrthonormalBasisFactory< dimension-1, Field > TestFaceBasisFactory
Definition: raviartthomassimplexinterpolation.hh:115
RTL2InterpolationBuilder(RTL2InterpolationBuilder &&)=delete
OrthonormalBasisFactory< dimension, Field > TestBasisFactory
Definition: raviartthomassimplexinterpolation.hh:111
std::size_t order() const
Definition: raviartthomassimplexinterpolation.hh:135
static const unsigned int dimension
Definition: raviartthomassimplexinterpolation.hh:108
~RTL2InterpolationBuilder()
Definition: raviartthomassimplexinterpolation.hh:126
An L2-based interpolation for Raviart Thomas.
Definition: raviartthomassimplexinterpolation.hh:213
std::size_t order() const
Definition: raviartthomassimplexinterpolation.hh:244
RaviartThomasL2Interpolation()
Definition: raviartthomassimplexinterpolation.hh:220
void interpolate(typename Base::template Helper< Func, Container, type > &func) const
Definition: raviartthomassimplexinterpolation.hh:283
auto interpolate(const Basis &basis, Matrix &matrix) const -> std::enable_if_t< std::is_same< decltype(std::declval< Matrix >().rowPtr(0)), typename Matrix::Field * >::value, void >
Definition: raviartthomassimplexinterpolation.hh:235
RTL2InterpolationBuilder< dimension, Field > Builder
Definition: raviartthomassimplexinterpolation.hh:219
F Field
Definition: raviartthomassimplexinterpolation.hh:218
void build(std::size_t order)
Definition: raviartthomassimplexinterpolation.hh:253
auto interpolate(const Function &function, Vector &coefficients) const -> std::enable_if_t< std::is_same< decltype(std::declval< Vector >().resize(1)), void >::value, void >
Definition: raviartthomassimplexinterpolation.hh:226
std::size_t size() const
Definition: raviartthomassimplexinterpolation.hh:248
void setLocalKeys(std::vector< LocalKey > &keys) const
Definition: raviartthomassimplexinterpolation.hh:265
Definition: interpolationhelper.hh:22
Definition: interpolationhelper.hh:24
Definition: interpolationhelper.hh:87
Definition: polynomialbasis.hh:65
unsigned int size() const
Definition: polynomialbasis.hh:113