1#ifndef DUNE_FEM_VTXPROJECTION_HH
2#define DUNE_FEM_VTXPROJECTION_HH
11#include <dune/grid/common/rangegenerators.hh>
13#include <dune/fem/common/coordinate.hh>
14#include <dune/fem/operator/common/operator.hh>
15#include <dune/fem/space/common/communicationmanager.hh>
16#include <dune/fem/space/common/interpolate.hh>
17#include <dune/fem/space/lagrange.hh>
24 template <
class Gr
idPartType>
25 struct WeightDefault {
26 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
28 typedef typename EntityType::Geometry::GlobalCoordinate WorldDomainType;
29 typedef typename EntityType::Geometry::LocalCoordinate DomainType;
33 void setEntity(
const EntityType& en) {
35 volume_ = en.geometry().volume();
36 baryCenter_ = en.geometry().center();
38 double operator()(
const DomainType& point) {
40 auto tau = en_.geometry().global(point);
42 return tau.two_norm() / volume_;
45 WorldDomainType baryCenter_;
49 struct VtxProjectionImpl
51 template<
class DiscreteFunction,
class Intersection >
52 struct OutsideLocalFunction
54 typedef typename DiscreteFunction::LocalFunctionType LocalFunctionType;
56 typedef typename LocalFunctionType::EntityType EntityType;
68 typedef typename EntityType::Geometry::LocalCoordinate LocalCoordinateType;
75 explicit OutsideLocalFunction (
const DiscreteFunction &df ) : order_(df.order()), localFunction_( df ) {}
77 void init (
const EntityType &outside,
const GeometryType &geoIn,
const GeometryType &geoOut )
79 localFunction_.init( outside );
85 const EntityType &entity()
const {
return entity_; }
87 int order()
const {
return order_; }
89 template<
class Po
int >
90 void evaluate (
const Point &x, RangeType &value )
const
92 localFunction_.evaluate( geoOut_->global( geoIn_->local( coordinate( x ) ) ), value );
95 template<
class Po
int >
96 void jacobian (
const Point &x, JacobianRangeType &jacobian )
const
98 DUNE_THROW( NotImplemented,
"Vertex projection weights do not provide Jacobians." );
101 template<
class Po
int >
102 void hessian (
const Point &x, HessianRangeType &hessian )
const
104 DUNE_THROW( NotImplemented,
"Vertex projection weights do not provide Hessians." );
107 template<
class Quadrature,
class Values >
108 void evaluateQuadrature (
const Quadrature &quadrature, Values &values )
const
110 for(
const auto &qp : quadrature )
111 doEvaluate( qp, values[ qp.index() ] );
115 template<
class Po
int >
116 void doEvaluate (
const Point &x, RangeType &value )
const
118 evaluate( x, value );
121 template<
class Po
int >
122 void doEvaluate (
const Point &x, JacobianRangeType &value )
const
124 jacobian( x, value );
127 template<
class Po
int >
128 void doEvaluate (
const Point &x, HessianRangeType &value )
const
134 LocalFunctionType localFunction_;
141 template<
class DiscreteFunction >
142 static void makeConforming ( DiscreteFunction &u )
144 typedef typename DiscreteFunction::GridPartType GridPartType;
147 typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
148 typedef typename DiscreteFunction::DiscreteFunctionSpaceType
149 DiscreteFunctionSpaceType;
151 if( u.space().gridPart().isConforming() || !Fem::GridPartCapabilities::hasGrid< GridPartType >::v )
154 const auto &blockMapper = u.space().blockMapper();
156 std::vector< typename DiscreteFunction::DofType > ldu, ldw;
157 const std::size_t localBlockSize = DiscreteFunctionSpaceType::localBlockSize;
158 const std::size_t maxNumBlocks = blockMapper.maxNumDofs();
159 ldu.reserve( maxNumBlocks * localBlockSize );
160 ldw.reserve( maxNumBlocks * localBlockSize );
162 std::vector< char > onSubEntity;
163 onSubEntity.reserve( maxNumBlocks );
165 OutsideLocalFunction< DiscreteFunction, IntersectionType > uOutside( u );
167 LocalInterpolation< DiscreteFunctionSpaceType > interpolation( u.space() );
169 for(
const EntityType &inside : u.space() )
171 for(
const IntersectionType &intersection : intersections( u.gridPart(), inside ) )
173 if( intersection.conforming() || !intersection.neighbor() )
177 const EntityType outside = intersection.outside();
178 if( inside.level() <= outside.level() )
183 const auto geoIn = intersection.geometryInInside();
184 const auto geoOut = intersection.geometryInOutside();
185 uOutside.init( outside, geoIn, geoOut );
188 const std::size_t numBlocks = blockMapper.numDofs( inside );
189 ldu.resize( numBlocks * localBlockSize );
190 ldw.resize( numBlocks * localBlockSize );
193 auto guard = bindGuard( interpolation, inside );
194 interpolation( uOutside, ldw );
197 u.getLocalDofs( inside, ldu );
200 blockMapper.onSubEntity( inside, intersection.indexInInside(), 1, onSubEntity );
201 for( std::size_t i = 0; i < numBlocks; ++i )
203 if( !onSubEntity[ i ] )
205 for( std::size_t j = 0; j < localBlockSize; ++j )
206 ldu[ i*localBlockSize + j ] = ldw[ i*localBlockSize + j ];
210 u.setLocalDofs( inside, ldu );
215 template<
class Function,
class DiscreteFunction,
class Weight >
216 static auto project (
const Function &f, DiscreteFunction &u, Weight &weight )
217 -> std::enable_if_t<std::is_void<
decltype(
interpolate(f,u,weight,u )) >::value>
220 DiscreteFunction w (
"weight", u.space() );
224 template<
class Function,
class DiscreteFunction >
225 static auto project (
const Function &f, DiscreteFunction &u )
226 -> std::enable_if_t< std::is_void<
decltype( project( f,u,std::declval<WeightDefault<typename DiscreteFunction::GridPartType>&>() ) ) >::value>
228 WeightDefault<typename DiscreteFunction::GridPartType> weight;
229 project(f, u, weight);
241 template <
typename DType,
typename RType >
245 typedef DType DomainType;
246 typedef RType RangeType;
247 typedef typename DomainType :: RangeFieldType DomainFieldType;
248 typedef typename RType :: RangeFieldType RangeFieldType;
249 typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
250 typedef typename RType :: DiscreteFunctionSpaceType :: GridPartType GridPartType;
255 template <
class WeightType>
257 WeightType& weight)
const
259 VtxProjectionImpl::project(f,discFunc,weight);
262 void operator() (
const DomainType& f, RangeType& discFunc)
const
264 VtxProjectionImpl::project(f,discFunc);
IntersectionIteratorType::Intersection IntersectionType
type of intersection
Definition: adaptiveleafgridpart.hh:95
Definition: explicitfieldvector.hh:75
FunctionSpaceTraits::DomainFieldType DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspaceinterface.hh:60
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
@ dimDomain
dimension of domain vector space
Definition: functionspaceinterface.hh:46
@ dimRange
dimension of range vector space
Definition: functionspaceinterface.hh:48
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:75
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:67
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
A vector valued function space.
Definition: functionspace.hh:60
The Projection class which average discontinuous function using the interpolation of the space (e....
Definition: vtxprojection.hh:243
VtxProjection()
Constructor.
Definition: vtxprojection.hh:252
void operator()(const DomainType &f, RangeType &discFunc, WeightType &weight) const
apply projection
Definition: vtxprojection.hh:256
GridImp::template Codim< 1 >::LocalGeometry LocalGeometry
Codim 1 geometry returned by geometryInInside() and geometryInOutside()
Definition: intersection.hh:204
actual interface class for quadratures
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
static void interpolate(const GridFunction &u, DiscreteFunction &v)
perform native interpolation of a discrete function space
Definition: interpolate.hh:54
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
abstract operator
Definition: operator.hh:34