dune-fem  2.6-git
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 
14 
15 namespace Dune
16 {
17 
18  namespace Fem
19  {
20 
21  // DGInverseMassPassDiscreteModel
22  // ------------------------------
23 
24  template< int functionalId, class PreviousPass >
26  {
27  private:
28  typedef typename PreviousPass::PassIds PassIds;
29  typedef typename PreviousPass::NextArgumentType LocalArgumentType;
30  typedef typename PreviousPass::GlobalArgumentType GlobalArgumentType;
31  typedef typename PushFrontTuple< LocalArgumentType, GlobalArgumentType * >::type TotalArgumentType;
32 
33  public:
34  static const std::size_t functionalPosition
35  = Dune::FirstTypeIndex< PassIds, std::integral_constant< int, functionalId > >::type::value;
36  typedef typename std::tuple_element< functionalPosition, TotalArgumentType >::type DestinationPtrType;
37 
38  struct Traits
39  {
40  typedef typename std::remove_pointer< DestinationPtrType >::type DestinationType;
41  typedef typename DestinationType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
44  };
45  };
46 
47 
48 
49  // DGInverseMassPass
50  // -----------------
51 
58  template< int functionalId, class PreviousPass, int id >
60  : public Dune::Fem::LocalPass< DGInverseMassPassDiscreteModel< functionalId, PreviousPass >, PreviousPass, id >
61  {
64 
65  public:
68 
70  typedef typename BaseType::PassIds PassIds;
71 
76 
79 
80  private:
81  static const std::size_t functionalPosition = DiscreteModelType::functionalPosition;
82 
83  typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
84  typedef typename DiscreteModelType::Traits::VolumeQuadratureType VolumeQuadratureType;
86 
87  typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
88  public:
90  using BaseType::space;
91 
92  explicit DGInverseMassPass ( PreviousPass &previousPass,
94  : BaseType( previousPass, space, "DGInverseMassPass" ),
95  localMassMatrix_( space, 2*space.order() ),
96  arg_( 0 ),
97  dest_( 0 )
98  {}
99 
101  explicit DGInverseMassPass ( const DiscreteModelType& discreteModel,
102  PreviousPass &previousPass,
104  const int volQuadOrd = -1,
105  const int faceQuadOrd = -1)
106  : BaseType( previousPass, space, "DGInverseMassPass" ),
107  localMassMatrix_( space, ( volQuadOrd == -1 ) ? (2*space.order()) : volQuadOrd ),
108  arg_( 0 ),
109  dest_( 0 )
110  {}
111 
112  void printTexInfo ( std::ostream &out ) const
113  {
114  BaseType::printTexInfo( out );
115  out << "DGInverseMassPass: " << "\\\\" << std::endl;
116  }
117 
119  bool requireCommunication () const { return false ; }
120 
122  void prepare( const TotalArgumentType &argument, DestinationType &destination ) const
123  {
124  arg_ = &argument;
125  dest_ = &destination;
126  }
127 
129  void prepare( const TotalArgumentType &argument, DestinationType &destination, const bool ) const
130  {
131  prepare( argument, destination );
132  }
133 
135  void finalize( const TotalArgumentType &argument, DestinationType &destination, const bool ) const
136  {
137  finalize( argument, destination );
138  }
139 
141  void finalize( const TotalArgumentType &argument, DestinationType &destination ) const
142  {
143  arg_ = 0 ;
144  dest_ = 0 ;
145  }
146 
148  void applyLocal( const EntityType& entity ) const
149  {
150  assert( arg_ );
151  assert( dest_ );
152  typename DestinationType::LocalFunctionType localDestination = dest_->localFunction( entity );
153  localDestination.assign( std::get< functionalPosition >( *arg_ )->localFunction( entity ) );
154  localMassMatrix_.applyInverse( entity, localDestination );
155  }
156 
158  template <class NBChecker>
159  void applyLocal( const EntityType& entity, const NBChecker& ) const
160  {
161  applyLocal( entity );
162  }
163 
167  template <class NBChecker>
168  void applyLocalInterior( const EntityType& entity, const NBChecker& ) const
169  {
170  applyLocal( entity );
171  }
172 
176  template <class NBChecker>
177  void applyLocalProcessBoundary( const EntityType& entity, const NBChecker& ) const
178  {
179  DUNE_THROW(InvalidStateException,"DGInverseMassPass does not need a second phase for ThreadPass");
180  }
181 
182  protected:
183  void compute ( const TotalArgumentType &argument, DestinationType &destination ) const
184  {
185  // set pointer
186  prepare( argument, destination );
187 
188  typedef typename GridPartType::template Codim< 0 >::template Partition< All_Partition >::IteratorType IteratorType;
189  const GridPartType &gridPart = space().gridPart();
190  const IteratorType end = gridPart.template end< 0, All_Partition >();
191  for( IteratorType it = gridPart.template begin< 0, All_Partition >(); it != end; ++it )
192  {
193  applyLocal( *it );
194  }
195 
196  // remove pointer
197  finalize( argument, destination );
198  }
199 
200  protected:
203 
204  private:
205  LocalMassMatrixType localMassMatrix_;
206 
207  mutable const TotalArgumentType* arg_;
208  mutable DestinationType* dest_;
209  };
210 
211  } // namespace Fem
212 
213 } // namespace Dune
214 
215 #endif // #ifndef DUNE_FEM_PASS_APPLYLOCALOPERATOR_HH
Definition: bindguard.hh:11
void applyInverse(MassCaller &caller, const EntityType &entity, LocalFunction &lf) const
Definition: localmassmatrix.hh:239
DeleteHandlerType * deleteHandler_
object to delete destination_
Definition: common/pass.hh:376
DestinationType * destination_
destination (might be set from outside)
Definition: common/pass.hh:373
void printTexInfo(std::ostream &out) const
printTex info of operator
Definition: common/pass.hh:206
PushFrontTuple< LocalArgumentType, const GlobalArgumentType * >::type TotalArgumentType
Definition: common/pass.hh:173
const DestinationType & destination() const
return reference to internal discrete function
Definition: common/pass.hh:253
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:153
Specialisation of Pass which provides a grid walk-through, but leaves open what needs to be done on e...
Definition: local.hh:36
const DiscreteFunctionSpaceType & space() const
return reference to space
Definition: local.hh:92
DiscreteFunctionSpaceType::IteratorType IteratorType
iterator over the space
Definition: local.hh:54
DiscreteModelImp::Traits::DestinationType DestinationType
the discrete function representing the return value of this pass
Definition: local.hh:50
Definition: dginversemass.hh:26
std::tuple_element< functionalPosition, TotalArgumentType >::type DestinationPtrType
Definition: dginversemass.hh:36
static const std::size_t functionalPosition
Definition: dginversemass.hh:35
CachingQuadrature< typename DiscreteFunctionSpaceType::GridPartType, 1 > FaceQuadratureType
Definition: dginversemass.hh:43
DestinationType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: dginversemass.hh:41
std::remove_pointer< DestinationPtrType >::type DestinationType
Definition: dginversemass.hh:40
CachingQuadrature< typename DiscreteFunctionSpaceType::GridPartType, 0 > VolumeQuadratureType
Definition: dginversemass.hh:42
Pass applying the local inverse mass matrix on each element.
Definition: dginversemass.hh:61
BaseType::TotalArgumentType TotalArgumentType
argument type
Definition: dginversemass.hh:73
void compute(const TotalArgumentType &argument, DestinationType &destination) const
Definition: dginversemass.hh:183
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:168
void finalize(const TotalArgumentType &argument, DestinationType &destination, const bool) const
finalize for ThreadPass
Definition: dginversemass.hh:135
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:177
void finalize(const TotalArgumentType &argument, DestinationType &destination) const
interface method
Definition: dginversemass.hh:141
bool requireCommunication() const
this pass needs no communication
Definition: dginversemass.hh:119
void printTexInfo(std::ostream &out) const
Definition: dginversemass.hh:112
void prepare(const TotalArgumentType &argument, DestinationType &destination, const bool) const
prepare for ThreadPass
Definition: dginversemass.hh:129
DGInverseMassPassDiscreteModel< functionalId, PreviousPass > DiscreteModelType
type of the discrete model used
Definition: dginversemass.hh:67
void applyLocal(const EntityType &entity, const NBChecker &) const
apply local with neighbor checker (not needed here)
Definition: dginversemass.hh:159
BaseType::DestinationType DestinationType
destination type
Definition: dginversemass.hh:75
BaseType::PassIds PassIds
pass ids up to here (tuple of integral constants)
Definition: dginversemass.hh:70
DiscreteModelType::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
discrete function space type
Definition: dginversemass.hh:78
void applyLocal(const EntityType &entity) const
apply inverse mass matrix locally
Definition: dginversemass.hh:148
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:101
DGInverseMassPass(PreviousPass &previousPass, const DiscreteFunctionSpaceType &space)
Definition: dginversemass.hh:92
void prepare(const TotalArgumentType &argument, DestinationType &destination) const
interface method
Definition: dginversemass.hh:122
Definition: discretemodel.hh:423
quadrature class supporting base function caching
Definition: cachingquadrature.hh:38