dune-fem 2.12-git
Loading...
Searching...
No Matches
vtxprojection.hh
Go to the documentation of this file.
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
12
18
19namespace Dune
20{
21 namespace Fem
22 {
23
24 template <class GridPartType>
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_;
47 };
48
50 {
51 template< class DiscreteFunction, class Intersection >
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
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
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 )
228 {
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;
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
virtual void operator()()=0
#define DUNE_THROW(E,...)
static void interpolate(const GridFunction &u, DiscreteFunction &v)
perform native interpolation of a discrete function space
Definition common/interpolate.hh:55
static const Point & coordinate(const Point &x)
Definition coordinate.hh:14
static auto bindGuard(Object &object, Args &&... args) -> std::enable_if_t< isBindable< Object, Args... >::value, BindGuard< Object > >
Definition bindguard.hh:67
GridImp::template Codim< 1 >::LocalGeometry LocalGeometry
Abstract class representing a function.
Definition common/function.hh:50
specialize with 'false' if grid part has no underlying dune grid (default=true)
Definition gridpart/common/capabilities.hh:18
abstract operator
Definition operator.hh:34
Definition vtxprojection.hh:25
double operator()(const DomainType &point)
Definition vtxprojection.hh:38
double volume_
Definition vtxprojection.hh:44
EntityType::Geometry::GlobalCoordinate WorldDomainType
Definition vtxprojection.hh:28
GridPartType::template Codim< 0 >::EntityType EntityType
Definition vtxprojection.hh:26
WorldDomainType baryCenter_
Definition vtxprojection.hh:45
void setEntity(const EntityType &en)
Definition vtxprojection.hh:33
EntityType::Geometry::LocalCoordinate DomainType
Definition vtxprojection.hh:29
EntityType en_
Definition vtxprojection.hh:46
Definition vtxprojection.hh:50
static auto project(const Function &f, DiscreteFunction &u) -> std::enable_if_t< std::is_void< decltype(project(f, u, std::declval< WeightDefault< typename DiscreteFunction::GridPartType > & >())) >::value >
Definition vtxprojection.hh:226
static auto project(const Function &f, DiscreteFunction &u, Weight &weight) -> std::enable_if_t< std::is_void< decltype(interpolate(f, u, weight, u)) >::value >
Definition vtxprojection.hh:217
static void makeConforming(DiscreteFunction &u)
Definition vtxprojection.hh:143
void init(const EntityType &outside, const GeometryType &geoIn, const GeometryType &geoOut)
Definition vtxprojection.hh:77
const EntityType & entity() const
Definition vtxprojection.hh:85
static const int dimRange
Definition vtxprojection.hh:71
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition vtxprojection.hh:65
void evaluate(const Point &x, RangeType &value) const
Definition vtxprojection.hh:91
int order() const
Definition vtxprojection.hh:88
void evaluateQuadrature(const Quadrature &quadrature, Values &values) const
Definition vtxprojection.hh:109
FunctionSpaceType::RangeType RangeType
Definition vtxprojection.hh:63
EntityType::Geometry::LocalCoordinate LocalCoordinateType
Definition vtxprojection.hh:68
LocalFunctionType::FunctionSpaceType FunctionSpaceType
Definition vtxprojection.hh:57
LocalFunctionType::EntityType EntityType
Definition vtxprojection.hh:56
DiscreteFunction::LocalFunctionType LocalFunctionType
Definition vtxprojection.hh:54
FunctionSpaceType::DomainFieldType DomainFieldType
Definition vtxprojection.hh:59
Intersection::LocalGeometry GeometryType
Definition vtxprojection.hh:73
static const int dimDomain
Definition vtxprojection.hh:70
void jacobian(const Point &x, JacobianRangeType &jacobian) const
Definition vtxprojection.hh:97
void hessian(const Point &x, HessianRangeType &hessian) const
Definition vtxprojection.hh:103
bool valid() const
Definition vtxprojection.hh:86
FunctionSpaceType::HessianRangeType HessianRangeType
Definition vtxprojection.hh:66
FunctionSpaceType::RangeFieldType RangeFieldType
Definition vtxprojection.hh:60
OutsideLocalFunction(const DiscreteFunction &df)
Definition vtxprojection.hh:75
FunctionSpaceType::DomainType DomainType
Definition vtxprojection.hh:62
The Projection class which average discontinuous function using the interpolation of the space (e....
Definition vtxprojection.hh:244
RType::DiscreteFunctionSpaceType::GridPartType GridPartType
Definition vtxprojection.hh:251
RType RangeType
Definition vtxprojection.hh:247
VtxProjection()
Constructor.
Definition vtxprojection.hh:253
DType DomainType
Definition vtxprojection.hh:246
RType::RangeFieldType RangeFieldType
Definition vtxprojection.hh:249
Dune::FieldTraits< RangeFieldType >::real_type RealType
Definition vtxprojection.hh:250
DomainType::RangeFieldType DomainFieldType
Definition vtxprojection.hh:248
actual interface class for integration point lists
Definition quadrature.hh:158
Definition common/localinterpolation.hh:23
T reserve(T... args)
T resize(T... args)