40#ifndef DUNE_FEM_SCHEMES_ELLIPTIC_HH
41#define DUNE_FEM_SCHEMES_ELLIPTIC_HH
48#include <dune/fem/quadrature/cachingquadrature.hh>
49#include <dune/fem/operator/common/operator.hh>
50#include <dune/fem/operator/common/stencil.hh>
52#include <dune/fem/common/bindguard.hh>
53#include <dune/fem/function/common/localcontribution.hh>
54#include <dune/fem/function/localfunction/const.hh>
56#include <dune/fem/operator/common/differentiableoperator.hh>
57#include <dune/fem/operator/common/temporarylocalmatrix.hh>
61#include <dune/fem/io/parameter.hh>
62#include <dune/fem/io/file/dataoutput.hh>
65#include <dune/fempy/quadrature/fempyquadratures.hh>
71template<
class DomainDiscreteFunction,
class RangeDiscreteFunction,
class Model>
76 typedef DomainDiscreteFunction DomainFunctionType;
77 typedef RangeDiscreteFunction RangeFunctionType;
78 typedef Model ModelType;
79 typedef Model DirichletModelType;
81 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainDiscreteFunctionSpaceType;
82 typedef typename DomainFunctionType::LocalFunctionType DomainLocalFunctionType;
83 typedef typename DomainLocalFunctionType::RangeType DomainRangeType;
84 typedef typename DomainLocalFunctionType::JacobianRangeType DomainJacobianRangeType;
85 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeDiscreteFunctionSpaceType;
86 typedef typename RangeFunctionType::LocalFunctionType RangeLocalFunctionType;
87 typedef typename RangeLocalFunctionType::RangeType RangeRangeType;
88 typedef typename RangeLocalFunctionType::JacobianRangeType RangeJacobianRangeType;
91 typedef typename RangeDiscreteFunctionSpaceType::IteratorType IteratorType;
92 typedef typename IteratorType::Entity EntityType;
93 typedef typename EntityType::Geometry GeometryType;
94 typedef typename RangeDiscreteFunctionSpaceType::DomainType DomainType;
95 typedef typename RangeDiscreteFunctionSpaceType::GridPartType GridPartType;
97 typedef typename IntersectionIteratorType::Intersection IntersectionType;
104 const Dune::Fem::ParameterReader ¶meter = Dune::Fem::Parameter::container() )
106 dSpace_(rangeSpace), rSpace_(rangeSpace)
109 const RangeDiscreteFunctionSpaceType &rSpace,
111 const Dune::Fem::ParameterReader ¶meter = Dune::Fem::Parameter::container() )
113 dSpace_(dSpace), rSpace_(rSpace),
114 interiorOrder_(-1), surfaceOrder_(-1)
118 virtual void operator() (
const DomainFunctionType &u, RangeFunctionType &w )
const
121 void operator()(
const GF &u, RangeFunctionType &w )
const
126 const DomainDiscreteFunctionSpaceType& domainSpace()
const
130 const RangeDiscreteFunctionSpaceType& rangeSpace()
const
134 const ModelType &model ()
const {
return model_; }
135 ModelType &model () {
return model_; }
137 void setQuadratureOrders(
unsigned int interior,
unsigned int surface)
140 surfaceOrder_ = surface;
144 int interiorOrder_, surfaceOrder_;
147 const DomainDiscreteFunctionSpaceType &dSpace_;
148 const RangeDiscreteFunctionSpaceType &rSpace_;
157template<
class JacobianOperator,
class Model >
159:
public EllipticOperator< typename JacobianOperator::DomainFunctionType, typename JacobianOperator::RangeFunctionType, Model >,
169 typedef typename BaseType::ModelType ModelType;
171 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainDiscreteFunctionSpaceType;
172 typedef typename DomainFunctionType::LocalFunctionType DomainLocalFunctionType;
173 typedef typename DomainLocalFunctionType::RangeType DomainRangeType;
174 typedef typename DomainLocalFunctionType::JacobianRangeType DomainJacobianRangeType;
175 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeDiscreteFunctionSpaceType;
176 typedef typename RangeFunctionType::LocalFunctionType RangeLocalFunctionType;
177 typedef typename RangeLocalFunctionType::RangeType RangeRangeType;
178 typedef typename RangeLocalFunctionType::JacobianRangeType RangeJacobianRangeType;
181 typedef typename RangeDiscreteFunctionSpaceType::IteratorType IteratorType;
182 typedef typename IteratorType::Entity EntityType;
183 typedef typename EntityType::Geometry GeometryType;
184 typedef typename RangeDiscreteFunctionSpaceType::DomainType DomainType;
185 typedef typename RangeDiscreteFunctionSpaceType::GridPartType GridPartType;
187 typedef typename IntersectionIteratorType::Intersection IntersectionType;
189 typedef typename BaseType::QuadratureType QuadratureType;
191 typedef typename BaseType::FaceQuadratureType FaceQuadratureType;
196 const Dune::Fem::ParameterReader ¶meter = Dune::Fem::Parameter::container() )
197 :
BaseType( space, space, model, parameter )
201 const RangeDiscreteFunctionSpaceType &rSpace,
203 const Dune::Fem::ParameterReader ¶meter = Dune::Fem::Parameter::container() )
204 :
BaseType( dSpace, rSpace, model, parameter )
210 template <
class Gr
idFunctionType>
211 void jacobian (
const GridFunctionType &u, JacobianOperatorType &jOp )
const
213 template <
class Gr
idFunctionType>
214 void assemble (
const GridFunctionType &u, JacobianOperatorType &jOp )
const;
215 using BaseType::operator();
217 using BaseType::model;
218 using BaseType::interiorOrder_;
219 using BaseType::surfaceOrder_;
227template<
class DomainDiscreteFunction,
class RangeDiscreteFunction,
class Model >
230 ::apply(
const GF &u, RangeFunctionType &w )
const
234 const RangeDiscreteFunctionSpaceType &dfSpace = w.space();
237 Dune::Fem::ConstLocalFunction< GF > uLocal( u );
238 Dune::Fem::AddLocalContribution< RangeFunctionType > wLocal( w );
241 for(
const EntityType &entity : dfSpace )
243 if( !model().init( entity ) )
247 const GeometryType &geometry = entity.geometry();
249 auto uGuard = Dune::Fem::bindGuard( uLocal, entity );
250 auto wGuard = Dune::Fem::bindGuard( wLocal, entity );
253 const int quadOrder = interiorOrder_==-1?
254 uLocal.order() + wLocal.order() : interiorOrder_;
258 const size_t numQuadraturePoints = quadrature.nop();
259 for(
size_t pt = 0; pt < numQuadraturePoints; ++pt )
262 const typename QuadratureType::CoordinateType &x = quadrature.point( pt );
263 const double weight = quadrature.weight( pt ) * geometry.integrationElement( x );
266 uLocal.evaluate( quadrature[ pt ], vu );
267 DomainJacobianRangeType du;
268 uLocal.jacobian( quadrature[ pt ], du );
271 RangeRangeType avu( 0 );
272 model().source( quadrature[ pt ], vu, du, avu );
276 RangeJacobianRangeType adu( 0 );
278 model().flux( quadrature[ pt ], vu, du, adu );
282 wLocal.axpy( quadrature[ pt ], avu, adu );
287 if( model().hasNeumanBoundary() && entity.hasBoundaryIntersections() )
289 const IntersectionIteratorType iitend = dfSpace.gridPart().iend( entity );
290 for( IntersectionIteratorType iit = dfSpace.gridPart().ibegin( entity ); iit != iitend; ++iit )
292 const IntersectionType &intersection = *iit;
293 if( !intersection.boundary() )
296 std::array<int,RangeRangeType::dimension> components(0);
298 const bool hasDirichletComponent = model().isDirichletIntersection( intersection, components );
300 const auto &intersectionGeometry = intersection.geometry();
301 const int quadOrder = surfaceOrder_==-1?
302 uLocal.order() + wLocal.order() : surfaceOrder_;
303 FaceQuadratureType quadInside( dfSpace.gridPart(), intersection, quadOrder, FaceQuadratureType::INSIDE );
304 const std::size_t numQuadraturePoints = quadInside.nop();
305 for( std::size_t pt = 0; pt < numQuadraturePoints; ++pt )
307 const auto &x = quadInside.localPoint( pt );
308 double weight = quadInside.weight( pt ) * intersectionGeometry.integrationElement( x );
310 uLocal.evaluate( quadInside[ pt ], vu );
311 RangeRangeType alpha( 0 );
312 model().alpha( quadInside[ pt ], vu, alpha );
314 for(
int k = 0; k < RangeRangeType::dimension; ++k )
315 if( hasDirichletComponent && components[ k ] )
317 wLocal.axpy( quadInside[ pt ], alpha );
331template<
class JacobianOperator,
class Model >
338 typedef typename DomainDiscreteFunctionSpaceType::BasisFunctionSetType DomainBasisFunctionSetType;
339 typedef typename RangeDiscreteFunctionSpaceType::BasisFunctionSetType RangeBasisFunctionSetType;
342 const DomainDiscreteFunctionSpaceType &domainSpace = jOp.
domainSpace();
343 const RangeDiscreteFunctionSpaceType &rangeSpace = jOp.rangeSpace();
346 jOp.reserve(stencil);
348 TmpLocalMatrixType jLocal( domainSpace, rangeSpace );
350 const int domainBlockSize = domainSpace.localBlockSize;
351 std::vector< typename DomainLocalFunctionType::RangeType > phi( domainSpace.blockMapper().maxNumDofs()*domainBlockSize );
352 std::vector< typename DomainLocalFunctionType::JacobianRangeType > dphi( domainSpace.blockMapper().maxNumDofs()*domainBlockSize );
353 const int rangeBlockSize = rangeSpace.localBlockSize;
354 std::vector< typename RangeLocalFunctionType::RangeType > rphi( rangeSpace.blockMapper().maxNumDofs()*rangeBlockSize );
355 std::vector< typename RangeLocalFunctionType::JacobianRangeType > rdphi( rangeSpace.blockMapper().maxNumDofs()*rangeBlockSize );
357 Dune::Fem::ConstLocalFunction< GF > uLocal( u );
359 for(
const EntityType &entity : rangeSpace )
361 if( !model().init( entity ) )
364 const GeometryType &geometry = entity.geometry();
366 auto uGuard = Dune::Fem::bindGuard( uLocal, entity );
367 jLocal.bind( entity, entity );
370 const DomainBasisFunctionSetType &domainBaseSet = jLocal.domainBasisFunctionSet();
371 const RangeBasisFunctionSetType &rangeBaseSet = jLocal.rangeBasisFunctionSet();
372 const std::size_t domainNumBasisFunctions = domainBaseSet.size();
374 const int quadOrder = interiorOrder_==-1?
375 domainSpace.order() + rangeSpace.order() : interiorOrder_;
376 QuadratureType quadrature( entity, quadOrder );
377 const size_t numQuadraturePoints = quadrature.nop();
378 for(
size_t pt = 0; pt < numQuadraturePoints; ++pt )
381 const typename QuadratureType::CoordinateType &x = quadrature.point( pt );
382 const double weight = quadrature.weight( pt ) * geometry.integrationElement( x );
385 domainBaseSet.evaluateAll( quadrature[ pt ], phi );
386 rangeBaseSet.evaluateAll( quadrature[ pt ], rphi );
389 domainBaseSet.jacobianAll( quadrature[ pt ], dphi );
390 rangeBaseSet.jacobianAll( quadrature[ pt ], rdphi );
394 DomainJacobianRangeType jacU0;
395 uLocal.evaluate( quadrature[ pt ], u0 );
396 uLocal.jacobian( quadrature[ pt ], jacU0 );
398 RangeRangeType aphi( 0 );
399 RangeJacobianRangeType adphi( 0 );
400 for( std::size_t localCol = 0; localCol < domainNumBasisFunctions; ++localCol )
403 model().linSource( u0, jacU0, quadrature[ pt ], phi[ localCol ], dphi[localCol], aphi );
406 model().linFlux( u0, jacU0, quadrature[ pt ], phi[ localCol ], dphi[ localCol ], adphi );
409 jLocal.column( localCol ).axpy( rphi, rdphi, aphi, adphi, weight );
414 if( model().hasNeumanBoundary() && entity.hasBoundaryIntersections() )
416 const IntersectionIteratorType iitend = rangeSpace.gridPart().iend( entity );
417 for( IntersectionIteratorType iit = rangeSpace.gridPart().ibegin( entity ); iit != iitend; ++iit )
419 const IntersectionType &intersection = *iit;
420 if( !intersection.boundary() )
423 std::array<int,RangeRangeType::dimension> components(0);
424 bool hasDirichletComponent = model().isDirichletIntersection( intersection, components );
426 const auto &intersectionGeometry = intersection.geometry();
427 const int quadOrder = surfaceOrder_==-1?
428 domainSpace.order() + rangeSpace.order() : surfaceOrder_;
429 FaceQuadratureType quadInside( rangeSpace.gridPart(), intersection, quadOrder, FaceQuadratureType::INSIDE );
430 const std::size_t numQuadraturePoints = quadInside.nop();
431 for( std::size_t pt = 0; pt < numQuadraturePoints; ++pt )
433 const auto &x = quadInside.localPoint( pt );
434 const double weight = quadInside.weight( pt ) * intersectionGeometry.integrationElement( x );
436 uLocal.evaluate( quadInside[ pt ], u0 );
437 domainBaseSet.evaluateAll( quadInside[ pt ], phi );
438 for( std::size_t localCol = 0; localCol < domainNumBasisFunctions; ++localCol )
440 RangeRangeType alpha( 0 );
441 model().linAlpha( u0,quadInside[ pt ], phi[ localCol ], alpha );
442 for(
int k = 0; k < RangeRangeType::dimension; ++k )
443 if( hasDirichletComponent && components[ k ] )
445 jLocal.column( localCol ).axpy( phi, alpha, weight );
450 jOp.addLocalMatrix( entity, entity, jLocal );
Traits::IntersectionIteratorType IntersectionIteratorType
type of intersection iterator
Definition: adaptiveleafgridpart.hh:92
quadrature class supporting base function caching
Definition: cachingquadrature.hh:101
abstract differentiable operator
Definition: differentiableoperator.hh:29
BaseType::RangeFunctionType RangeFunctionType
type of discrete function in the operator's range
Definition: differentiableoperator.hh:40
JacobianOperator JacobianOperatorType
type of linear operator modelling the operator's Jacobian
Definition: differentiableoperator.hh:35
BaseType::DomainFunctionType DomainFunctionType
type of discrete function in the operator's domain
Definition: differentiableoperator.hh:38
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:382
A local matrix with a small array as storage.
Definition: temporarylocalmatrix.hh:100
Implements a matrix constructed from a given type representing a field and compile-time given number ...
constexpr Interior interior
PartitionSet for the interior partition.
Definition: partitionset.hh:271
[Class for linearizable elliptic operator]
Definition: elliptic.hh:162
DifferentiableEllipticOperator(const DomainDiscreteFunctionSpaceType &dSpace, const RangeDiscreteFunctionSpaceType &rSpace, ModelType &model, const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
contructor
Definition: elliptic.hh:200
DifferentiableEllipticOperator(const RangeDiscreteFunctionSpaceType &space, ModelType &model, const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
contructor
Definition: elliptic.hh:194
void jacobian(const DomainFunctionType &u, JacobianOperatorType &jOp) const
method to setup the jacobian of the operator for storage in a matrix
Definition: elliptic.hh:208
Stencil contaning the entries (en,en) for all entities in the space. Defailt for an operator over a L...
Definition: stencil.hh:349
abstract operator
Definition: operator.hh:34
JacobianOperator::RangeFunctionType RangeFunctionType
type of discrete function in the operator's range
Definition: operator.hh:38
[Class for elliptic operator]
Definition: elliptic.hh:75
void apply(const GF &u, RangeFunctionType &w) const
Definition: elliptic.hh:230
virtual void operator()(const DomainFunctionType &u, RangeFunctionType &w) const
application operator
Definition: elliptic.hh:118