dune-fem  2.4.1-rc
dginversemass.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_PASS_DGINVERSEMASS_HH
2 #define DUNE_FEM_PASS_DGINVERSEMASS_HH
3 
4 #include <cassert>
5 #include <iosfwd>
6 #include <sstream>
7 #include <type_traits>
8 
9 #include <dune/common/typetraits.hh>
10 
16 
17 namespace Dune
18 {
19 
20  namespace Fem
21  {
22 
23  // DGInverseMassPassDiscreteModel
24  // ------------------------------
25 
26  template< int functionalId, class PreviousPass >
28  {
29  private:
30  typedef typename PreviousPass::PassIds PassIds;
31  typedef typename PreviousPass::NextArgumentType LocalArgumentType;
32  typedef typename PreviousPass::GlobalArgumentType GlobalArgumentType;
33  typedef typename PushFrontTuple< LocalArgumentType, GlobalArgumentType * >::type TotalArgumentType;
34 
35  public:
36  static const std::size_t functionalPosition
37  = Dune::FirstTypeIndex< PassIds, std::integral_constant< int, functionalId > >::type::value;
38  typedef typename std::tuple_element< functionalPosition, TotalArgumentType >::type DestinationPtrType;
39 
40  struct Traits
41  {
42  typedef typename Dune::TypeTraits< DestinationPtrType >::PointeeType DestinationType;
43  typedef typename DestinationType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
46  };
47  };
48 
49 
50 
51  // DGInverseMassPass
52  // -----------------
53 
60  template< int functionalId, class PreviousPass, int id >
62  : public Dune::Fem::LocalPass< DGInverseMassPassDiscreteModel< functionalId, PreviousPass >, PreviousPass, id >
63  {
66 
67  public:
70 
72  typedef typename BaseType::PassIds PassIds;
73 
78 
80  typedef typename DiscreteModelType::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
81 
82  private:
83  static const std::size_t functionalPosition = DiscreteModelType::functionalPosition;
84 
85  typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
86  typedef typename DiscreteModelType::Traits::VolumeQuadratureType VolumeQuadratureType;
88 
89  typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
90  public:
91  using BaseType::passNumber;
92  using BaseType::space;
93 
94  explicit DGInverseMassPass ( PreviousPass &previousPass,
95  const DiscreteFunctionSpaceType &space )
96  : BaseType( previousPass, space, "DGInverseMassPass" ),
97  localMassMatrix_( space, 2*space.order() ),
98  arg_( 0 ),
99  dest_( 0 )
100  {}
101 
103  explicit DGInverseMassPass ( const DiscreteModelType& discreteModel,
104  PreviousPass &previousPass,
105  const DiscreteFunctionSpaceType &space,
106  const int volQuadOrd = -1,
107  const int faceQuadOrd = -1)
108  : BaseType( previousPass, space, "DGInverseMassPass" ),
109  localMassMatrix_( space, ( volQuadOrd == -1 ) ? (2*space.order()) : volQuadOrd ),
110  arg_( 0 ),
111  dest_( 0 )
112  {}
113 
114  void printTexInfo ( std::ostream &out ) const
115  {
116  BaseType::printTexInfo( out );
117  out << "DGInverseMassPass: " << "\\\\" << std::endl;
118  }
119 
121  bool requireCommunication () const { return false ; }
122 
124  void prepare( const TotalArgumentType &argument, DestinationType &destination ) const
125  {
126  arg_ = &argument;
127  dest_ = &destination;
128  }
129 
131  void prepare( const TotalArgumentType &argument, DestinationType &destination, const bool ) const
132  {
133  prepare( argument, destination );
134  }
135 
137  void finalize( const TotalArgumentType &argument, DestinationType &destination, const bool ) const
138  {
139  finalize( argument, destination );
140  }
141 
143  void finalize( const TotalArgumentType &argument, DestinationType &destination ) const
144  {
145  arg_ = 0 ;
146  dest_ = 0 ;
147  }
148 
150  void applyLocal( const EntityType& entity ) const
151  {
152  assert( arg_ );
153  assert( dest_ );
154  typename DestinationType::LocalFunctionType localDestination = dest_->localFunction( entity );
155  localDestination.assign( std::get< functionalPosition >( *arg_ )->localFunction( entity ) );
156  localMassMatrix_.applyInverse( entity, localDestination );
157  }
158 
160  template <class NBChecker>
161  void applyLocal( const EntityType& entity, const NBChecker& ) const
162  {
163  applyLocal( entity );
164  }
165 
169  template <class NBChecker>
170  void applyLocalInterior( const EntityType& entity, const NBChecker& ) const
171  {
172  applyLocal( entity );
173  }
174 
178  template <class NBChecker>
179  void applyLocalProcessBoundary( const EntityType& entity, const NBChecker& ) const
180  {
181  DUNE_THROW(InvalidStateException,"DGInverseMassPass does not need a second phase for ThreadPass");
182  }
183 
184  protected:
185  void compute ( const TotalArgumentType &argument, DestinationType &destination ) const
186  {
187  // set pointer
188  prepare( argument, destination );
189 
190  typedef typename GridPartType::template Codim< 0 >::template Partition< All_Partition >::IteratorType IteratorType;
191  const GridPartType &gridPart = space().gridPart();
192  const IteratorType end = gridPart.template end< 0, All_Partition >();
193  for( IteratorType it = gridPart.template begin< 0, All_Partition >(); it != end; ++it )
194  {
195  applyLocal( *it );
196  }
197 
198  // remove pointer
199  finalize( argument, destination );
200  }
201 
202  protected:
203  using BaseType::destination_;
204  using BaseType::deleteHandler_;
205 
206  private:
207  LocalMassMatrixType localMassMatrix_;
208 
209  mutable const TotalArgumentType* arg_;
210  mutable DestinationType* dest_;
211  };
212 
213  } // namespace Fem
214 
215 } // namespace Dune
216 
217 #endif // #ifndef DUNE_FEM_PASS_APPLYLOCALOPERATOR_HH
DiscreteFunctionSpaceType::IteratorType IteratorType
iterator over the space
Definition: local.hh:52
void applyLocalInterior(const EntityType &entity, const NBChecker &) const
apply local for all elements that do not need information from other processes (here all elements) ...
Definition: dginversemass.hh:170
CachingQuadrature< typename DiscreteFunctionSpaceType::GridPartType, 1 > FaceQuadratureType
Definition: dginversemass.hh:45
DiscreteModelType::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
discrete function space type
Definition: dginversemass.hh:80
static const std::size_t functionalPosition
Definition: dginversemass.hh:37
Dune::TypeTraits< DestinationPtrType >::PointeeType DestinationType
Definition: dginversemass.hh:42
Pass applying the local inverse mass matrix on each element.
Definition: dginversemass.hh:61
DiscreteModelImp::Traits::DestinationType DestinationType
the discrete function representing the return value of this pass
Definition: local.hh:48
void compute(const TotalArgumentType &argument, DestinationType &destination) const
Definition: dginversemass.hh:185
BaseType::PassIds PassIds
pass ids up to here (tuple of integral constants)
Definition: dginversemass.hh:72
void printTexInfo(std::ostream &out) const
Definition: dginversemass.hh:114
quadrature class supporting base function caching
Definition: cachingquadrature.hh:41
DGInverseMassPass(PreviousPass &previousPass, const DiscreteFunctionSpaceType &space)
Definition: dginversemass.hh:94
DGInverseMassPassDiscreteModel< functionalId, PreviousPass > DiscreteModelType
type of the discrete model used
Definition: dginversemass.hh:69
void prepare(const TotalArgumentType &argument, DestinationType &destination, const bool) const
prepare for ThreadPass
Definition: dginversemass.hh:131
Definition: coordinate.hh:4
bool requireCommunication() const
this pass needs no communication
Definition: dginversemass.hh:121
BaseType::TotalArgumentType TotalArgumentType
argument type
Definition: dginversemass.hh:75
DGInverseMassPass(const DiscreteModelType &discreteModel, PreviousPass &previousPass, const DiscreteFunctionSpaceType &space, const int volQuadOrd=-1, const int faceQuadOrd=-1)
constructor for use with thread pass
Definition: dginversemass.hh:103
void finalize(const TotalArgumentType &argument, DestinationType &destination) const
interface method
Definition: dginversemass.hh:143
void applyLocal(const EntityType &entity, const NBChecker &) const
apply local with neighbor checker (not needed here)
Definition: dginversemass.hh:161
void applyLocal(const EntityType &entity) const
apply inverse mass matrix locally
Definition: dginversemass.hh:150
BaseType::DestinationType DestinationType
destination type
Definition: dginversemass.hh:77
void prepare(const TotalArgumentType &argument, DestinationType &destination) const
interface method
Definition: dginversemass.hh:124
void applyLocalProcessBoundary(const EntityType &entity, const NBChecker &) const
apply local for all elements that need information from other processes (here no elements) ...
Definition: dginversemass.hh:179
void finalize(const TotalArgumentType &argument, DestinationType &destination, const bool) const
finalize for ThreadPass
Definition: dginversemass.hh:137
DestinationType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: dginversemass.hh:43
PushFrontTuple< LocalArgumentType, const GlobalArgumentType * >::type TotalArgumentType
Definition: common/pass.hh:177
CachingQuadrature< typename DiscreteFunctionSpaceType::GridPartType, 0 > VolumeQuadratureType
Definition: dginversemass.hh:44
Specialisation of Pass which provides a grid walk-through, but leaves open what needs to be done on e...
Definition: local.hh:32
std::tuple_element< functionalPosition, TotalArgumentType >::type DestinationPtrType
Definition: dginversemass.hh:38
Definition: dginversemass.hh:27
Dune::PushBackTuple< typename PreviousPassType::PassIds, std::integral_constant< int, passIdImp > >::type PassIds
pass ids up to here (tuple of integral constants)
Definition: common/pass.hh:157
Definition: discretemodel.hh:431