Loading [MathJax]/extensions/tex2jax.js

DUNE-FEM (unstable)

vtxprojection.hh
1#ifndef DUNE_FEM_VTXPROJECTION_HH
2#define DUNE_FEM_VTXPROJECTION_HH
3
4#include <cstddef>
5#include <cmath>
6
7#include <algorithm>
8#include <functional>
9#include <vector>
10
11#include <dune/grid/common/rangegenerators.hh>
12
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>
18
19namespace Dune
20{
21 namespace Fem
22 {
23
24 template <class GridPartType>
25 struct WeightDefault {
26 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
27
28 typedef typename EntityType::Geometry::GlobalCoordinate WorldDomainType;
29 typedef typename EntityType::Geometry::LocalCoordinate DomainType;
30
31 //typedef FieldVector<double,GridPartType::dimensionworld> WorldDomainType;
32 //typedef FieldVector<double,GridPartType::dimension> DomainType;
33 void setEntity(const EntityType& en) {
34 en_ = en;
35 volume_ = en.geometry().volume();
36 baryCenter_ = en.geometry().center();
37 }
38 double operator()(const DomainType& point) {
39 // return volume_;
40 auto tau = en_.geometry().global(point);
41 tau -= baryCenter_;
42 return tau.two_norm() / volume_;
43 }
44 double volume_;
45 WorldDomainType baryCenter_;
46 EntityType en_;
47 };
48
49 struct VtxProjectionImpl
50 {
51 template< class DiscreteFunction, class Intersection >
52 struct OutsideLocalFunction
53 {
54 typedef typename DiscreteFunction::LocalFunctionType LocalFunctionType;
55
56 typedef typename LocalFunctionType::EntityType EntityType;
57 typedef typename LocalFunctionType::FunctionSpaceType FunctionSpaceType;
58
59 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
60 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
61
62 typedef typename FunctionSpaceType::DomainType DomainType;
63 typedef typename FunctionSpaceType::RangeType RangeType;
64
65 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
66 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
67
68 typedef typename EntityType::Geometry::LocalCoordinate LocalCoordinateType;
69
70 static const int dimDomain = FunctionSpaceType::dimDomain;
71 static const int dimRange = FunctionSpaceType::dimRange;
72
74
75 explicit OutsideLocalFunction ( const DiscreteFunction &df ) : order_(df.order()), localFunction_( df ) {}
76
77 void init ( const EntityType &outside, const GeometryType &geoIn, const GeometryType &geoOut )
78 {
79 localFunction_.init( outside );
80 geoIn_ = &geoIn;
81 geoOut_ = &geoOut;
82 entity_ = outside;
83 }
84
85 const EntityType &entity() const { return entity_; }
86 bool valid () const { return geoIn_ != nullptr; }
87
88 int order() const { return order_; }
89
90 template< class Point >
91 void evaluate ( const Point &x, RangeType &value ) const
92 {
93 localFunction_.evaluate( geoOut_->global( geoIn_->local( coordinate( x ) ) ), value );
94 };
95
96 template< class Point >
97 void jacobian ( const Point &x, JacobianRangeType &jacobian ) const
98 {
99 DUNE_THROW( NotImplemented, "Vertex projection weights do not provide Jacobians." );
100 }
101
102 template< class Point >
103 void hessian ( const Point &x, HessianRangeType &hessian ) const
104 {
105 DUNE_THROW( NotImplemented, "Vertex projection weights do not provide Hessians." );
106 }
107
108 template< class Quadrature, class Values >
109 void evaluateQuadrature ( const Quadrature &quadrature, Values &values ) const
110 {
111 for( const auto &qp : quadrature )
112 doEvaluate( qp, values[ qp.index() ] );
113 }
114
115 private:
116 template< class Point >
117 void doEvaluate ( const Point &x, RangeType &value ) const
118 {
119 evaluate( x, value );
120 };
121
122 template< class Point >
123 void doEvaluate ( const Point &x, JacobianRangeType &value ) const
124 {
125 jacobian( x, value );
126 };
127
128 template< class Point >
129 void doEvaluate ( const Point &x, HessianRangeType &value ) const
130 {
131 hessian( x, value );
132 };
133
134 int order_;
135 LocalFunctionType localFunction_;
136 const GeometryType *geoIn_ = nullptr;
137 const GeometryType *geoOut_ = nullptr;
138 EntityType entity_;
139 };
140
141
142 template< class DiscreteFunction >
143 static void makeConforming ( DiscreteFunction &u )
144 {
145 typedef typename DiscreteFunction::GridPartType GridPartType;
146
147 typedef typename GridPartType::IntersectionType IntersectionType;
148 typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
149 typedef typename DiscreteFunction::DiscreteFunctionSpaceType
150 DiscreteFunctionSpaceType;
151
152 if( u.space().gridPart().isConforming() || !Fem::GridPartCapabilities::hasGrid< GridPartType >::v )
153 return;
154
155 const auto &blockMapper = u.space().blockMapper();
156
157 std::vector< typename DiscreteFunction::DofType > ldu, ldw;
158 const std::size_t localBlockSize = DiscreteFunctionSpaceType::localBlockSize;
159 const std::size_t maxNumBlocks = blockMapper.maxNumDofs();
160 ldu.reserve( maxNumBlocks * localBlockSize );
161 ldw.reserve( maxNumBlocks * localBlockSize );
162
163 std::vector< char > onSubEntity;
164 onSubEntity.reserve( maxNumBlocks );
165
166 OutsideLocalFunction< DiscreteFunction, IntersectionType > uOutside( u );
167
168 LocalInterpolation< DiscreteFunctionSpaceType > interpolation( u.space() );
169
170 for( const EntityType &inside : u.space() )
171 {
172 for( const IntersectionType &intersection : intersections( u.gridPart(), inside ) )
173 {
174 if( intersection.conforming() || !intersection.neighbor() )
175 continue;
176
177 // skip this intersection, if inside is finer than outside
178 const EntityType outside = intersection.outside();
179 if( inside.level() <= outside.level() )
180 continue;
181
182 // initialize "outside local function"
183 // note: intersection geometries must live until end of intersection loop!
184 const auto geoIn = intersection.geometryInInside();
185 const auto geoOut = intersection.geometryInOutside();
186 uOutside.init( outside, geoIn, geoOut );
187
188 // resize local DoF vectors
189 const std::size_t numBlocks = blockMapper.numDofs( inside );
190 ldu.resize( numBlocks * localBlockSize );
191 ldw.resize( numBlocks * localBlockSize );
192
193 // interpolate "outside" values
194 auto guard = bindGuard( interpolation, inside );
195 interpolation( uOutside, ldw );
196
197 // fetch inside local DoFs
198 u.getLocalDofs( inside, ldu );
199
200 // patch DoFs assigned to the face
201 blockMapper.onSubEntity( inside, intersection.indexInInside(), 1, onSubEntity );
202 for( std::size_t i = 0; i < numBlocks; ++i )
203 {
204 if( !onSubEntity[ i ] )
205 continue;
206 for( std::size_t j = 0; j < localBlockSize; ++j )
207 ldu[ i*localBlockSize + j ] = ldw[ i*localBlockSize + j ];
208 }
209
210 // write back inside local DoFs
211 u.setLocalDofs( inside, ldu );
212 }
213 }
214 }
215
216 template< class Function, class DiscreteFunction, class Weight >
217 static auto project ( const Function &f, DiscreteFunction &u, Weight &weight )
218 -> std::enable_if_t<std::is_void< decltype( interpolate(f,u,weight,u )) >::value>
219 // -> std::enable_if_t<std::is_void< decltype( interpolate(f,u,weight,std::declval<std::remove_cv<std::remove_reference<DiscreteFunction>>&>()) ) >::value>
220 {
221 DiscreteFunction w ( "weight", u.space() );
222 interpolate( f, u, weight, w );
223 makeConforming( u );
224 }
225 template< class Function, class DiscreteFunction >
226 static auto project ( const Function &f, DiscreteFunction &u )
227 -> std::enable_if_t< std::is_void< decltype( project( f,u,std::declval<WeightDefault<typename DiscreteFunction::GridPartType>&>() ) ) >::value>
228 {
229 WeightDefault<typename DiscreteFunction::GridPartType> weight;
230 project(f, u, weight);
231 }
232 };
233
234 /*======================================================================*/
241 /*======================================================================*/
242 template < typename DType, typename RType >
243 class VtxProjection : public Operator< DType, RType >
244 {
245 public:
246 typedef DType DomainType;
247 typedef RType RangeType;
248 typedef typename DomainType :: RangeFieldType DomainFieldType;
249 typedef typename RType :: RangeFieldType RangeFieldType;
250 typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
251 typedef typename RType :: DiscreteFunctionSpaceType :: GridPartType GridPartType;
254
256 template <class WeightType>
257 void operator() (const DomainType& f, RangeType& discFunc,
258 WeightType& weight) const
259 {
260 VtxProjectionImpl::project(f,discFunc,weight);
261 }
263 void operator() (const DomainType& f, RangeType& discFunc) const
264 {
265 VtxProjectionImpl::project(f,discFunc);
266 }
267
268 private:
269 };
270
271 } // namespace Fem
272
273} // name space Dune
274
275#endif // #ifndef DUNE_FEM_VTXPROJECTION_HH
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:244
VtxProjection()
Constructor.
Definition: vtxprojection.hh:253
void operator()(const DomainType &f, RangeType &discFunc, WeightType &weight) const
apply projection
Definition: vtxprojection.hh:257
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:55
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
Dune namespace.
Definition: alignedallocator.hh:13
abstract operator
Definition: operator.hh:34
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 22, 22:34, 2025)