dune-fem  2.4.1-rc
vtxprojection.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_VTXPROJECTION_HH
2 #define DUNE_FEM_VTXPROJECTION_HH
3 
4 // #include <dune/grid/utility/twistutility.hh>
5 
10 
11 namespace Dune
12 {
13  namespace Fem
14  {
15 
16  template <class GridPartType>
17  struct WeightDefault {
18  typedef FieldVector<double,GridPartType::dimension> DomainType;
19  template <class EntityType>
20  void setEntity(const EntityType& en) {
21  volume_ = en.geometry().volume();
22  }
23  double operator()(const DomainType& point) {
24  return volume_;
25  }
26  double volume_;
27  };
28 
30  {
31  template< class Function, class DiscreteFunction, class Weight >
32  static void project ( const Function &f, DiscreteFunction &u, Weight &weight )
33  {
34  typedef typename Function::FunctionSpaceType FunctionSpaceType;
35  typedef typename Function::LocalFunctionType LocalFunctionType;
36 
37  typedef typename DiscreteFunction::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
38  typedef typename DiscreteFunction::LocalFunctionType LocalDiscreteFunctionType;
39 
40  typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
41  typedef typename DiscreteFunctionSpaceType::LagrangePointSetType LagrangePointSetType;
42 
43  typedef typename GridPartType::IntersectionIteratorType IntersectionIteratorType;
44  typedef typename GridPartType::IntersectionType IntersectionType;
45  typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
46  typedef typename GridPartType::template Codim< 0 >::GeometryType GeometryType;;
47 
48  typedef typename LagrangePointSetType::template Codim< 1 >::SubEntityIteratorType FaceDofIteratorType;
49 
50  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
51  typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
52  typedef typename FunctionSpaceType::RangeType RangeType;
53  typedef typename GeometryType::LocalCoordinate LocalCoordinateType;
54 
55  const unsigned int dimRange = FunctionSpaceType::dimRange;
56  const DiscreteFunctionSpaceType &space = u.space();
57 
58  u.clear();
59  DiscreteFunction w ( "weight", space );
60  w.clear();
61 
62  for ( const auto& entity : space )
63  {
64  weight.setEntity( entity );
65 
66  LocalDiscreteFunctionType lw = w.localFunction( entity );
67  LocalDiscreteFunctionType lu = u.localFunction( entity );
68 
69  const LocalFunctionType lf = f.localFunction( entity );
70  const LagrangePointSetType &lagrangePointSet = space.lagrangePointSet( entity );
71 
72  const unsigned int numPoints = lagrangePointSet.nop();
73  for( unsigned int pt = 0; pt < numPoints; ++pt )
74  {
75  RangeType val;
76  lf.evaluate( lagrangePointSet[ pt ], val );
77 
78  RealType wght = weight( lagrangePointSet.point( pt ) );
79 
80  for( unsigned int coordinate = 0; coordinate < dimRange; ++coordinate )
81  {
82  lu[ dimRange*pt + coordinate ] += wght*val[ coordinate ];
83  lw[ dimRange*pt + coordinate ] += wght;
84  }
85  }
86  }
87 
88  u.communicate();
89  w.communicate();
90 
91  typedef typename DiscreteFunction::DofIteratorType DofIteratorType;
92 
93  const DofIteratorType udend = u.dend();
94  DofIteratorType udit = u.dbegin();
95  DofIteratorType wdit = w.dbegin();
96  for( ; udit != udend; ++udit, ++wdit )
97  {
98  // assert( (*wdit > 0.) || (*udit == 0.) );
99  RealType weight = std::abs( *wdit );
100  if ( weight > 1e-12 )
101  *udit /= weight;
102  }
103 
104  // make function continuous over hanging nodes
105 
106  if( !GridPartType::Traits::conforming && Fem::GridPartCapabilities::hasGrid< GridPartType >::v)
107  {
108  const GridPartType &gridPart = space.gridPart();
109  for( const auto& entity : space )
110  {
111  const LagrangePointSetType &lagrangePointSet = space.lagrangePointSet( entity );
112 
113  const IntersectionIteratorType iend = gridPart.iend( entity );
114  for( IntersectionIteratorType iit = gridPart.ibegin( entity ); iit != iend; ++iit )
115  {
116  const IntersectionType &intersection = *iit;
117 
118  if( intersection.neighbor() )
119  {
120  // get neighbor
121  EntityType neighbor = make_entity( intersection.outside() );
122 
123  // if non-conforming situation
124  if( entity.level() > neighbor.level() )
125  {
126  const int indexInInside = intersection.indexInInside();
127 
128  typedef typename IntersectionType::LocalGeometry LocalGeometryType;
129  const LocalGeometryType &geoIn = intersection.geometryInInside();
130  const LocalGeometryType &geoOut = intersection.geometryInOutside();
131 
132  LocalDiscreteFunctionType uIn = u.localFunction( entity );
133  LocalDiscreteFunctionType uOut = u.localFunction( neighbor );
134 
135  const FaceDofIteratorType fdend = lagrangePointSet.template endSubEntity< 1 >( indexInInside );
136  FaceDofIteratorType fdit = lagrangePointSet.template beginSubEntity< 1 >( indexInInside );
137  for( ; fdit != fdend; ++fdit )
138  {
139  const LocalCoordinateType &xIn = lagrangePointSet.point( *fdit );
140  const LocalCoordinateType xOut = geoOut.global( geoIn.local( xIn ) );
141 
142  RangeType val;
143  uOut.evaluate( xOut, val );
144 
145  for( unsigned int coordinate = 0; coordinate < dimRange; ++coordinate )
146  uIn[ dimRange*(*fdit) + coordinate ] = val[ coordinate ];
147  }
148  }
149  }
150  }
151  }
152  }
153  }
154  };
155 
156  /*======================================================================*/
162  /*======================================================================*/
163  template < typename DType, typename RType >
164  class VtxProjection : public Operator< DType, RType >
165  {
166  public:
167  typedef DType DomainType;
168  typedef RType RangeType;
169  typedef typename DomainType :: RangeFieldType DomainFieldType;
170  typedef typename RType :: RangeFieldType RangeFieldType;
171  typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
172  typedef typename RType :: DiscreteFunctionSpaceType :: GridPartType GridPartType;
175 
177  template <class WeightType>
178  void operator() (const DomainType& f, RangeType& discFunc,
179  WeightType& weight) const
180  {
181  VtxProjectionImpl::project(f,discFunc,weight);
182  }
184  void operator() (const DomainType& f, RangeType& discFunc) const
185  {
187  VtxProjectionImpl::project(f,discFunc, weight);
188  }
189 
190  private:
191  };
192 
193  } // namespace Fem
194 
195 } // name space Dune
196 
197 #endif // #ifndef DUNE_FEM_VTXPROJECTION_HH
static void project(const Function &f, DiscreteFunction &u, Weight &weight)
Definition: vtxprojection.hh:32
DType DomainType
Definition: vtxprojection.hh:167
FunctionSpaceImp FunctionSpaceType
type of function space this function belongs to
Definition: function.hh:56
double operator()(const DomainType &point)
Definition: vtxprojection.hh:23
specialize with &#39;false&#39; if grid part has no underlying dune grid (default=true)
Definition: gridpart/common/capabilities.hh:17
VtxProjection()
Constructor.
Definition: vtxprojection.hh:174
void setEntity(const EntityType &en)
Definition: vtxprojection.hh:20
Definition: vtxprojection.hh:17
Dune::FieldTraits< RangeFieldType >::real_type RealType
Definition: vtxprojection.hh:171
Double abs(const Double &a)
Definition: double.hh:860
abstract operator
Definition: operator.hh:25
Dune::EntityPointer< Grid, Implementation >::Entity make_entity(const Dune::EntityPointer< Grid, Implementation > &entityPointer)
Definition: compatibility.hh:23
Definition: coordinate.hh:4
FieldVector< double, GridPartType::dimension > DomainType
Definition: vtxprojection.hh:18
RType::RangeFieldType RangeFieldType
Definition: vtxprojection.hh:170
RType RangeType
Definition: vtxprojection.hh:168
RType::DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: vtxprojection.hh:172
Definition: vtxprojection.hh:29
Abstract class representing a function.
Definition: function.hh:43
double volume_
Definition: vtxprojection.hh:26
DomainType::RangeFieldType DomainFieldType
Definition: vtxprojection.hh:169
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:11
The Projection class which average discontinuous function in the Lagrangepoints.
Definition: vtxprojection.hh:164
void evaluate(const DomainType &x, RangeType &value) const
evaluate the function
Definition: function.hh:111