dune-fem  2.4.1-rc
dgmasspass.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DGMASSPASS_HH
2 #define DUNE_FEM_DGMASSPASS_HH
3 
4 #include <dune/geometry/referenceelements.hh>
5 
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
27  template< class DiscreteModelImp, class PreviousPassImp >
29  : public LocalDGPass< DiscreteModelImp, PreviousPassImp >
30  {
33 
34  public:
37 
39 
44 
46  typedef typename BaseType::GridType GridType;
48  typedef typename BaseType::Entity EntityType;
49  typedef typename BaseType::Geometry GeometryType;
51 
52 
53  typedef typename BaseType::RangeType RangeType;
54  typedef typename RangeType::value_type RangeFieldType;
55 
57 
59 
60  typedef typename DiscreteModelType::MassFactorType MassFactorType;
61 
63 
64  public:
65  //- Public methods
73  LocalDGMassPass(DiscreteModelType& problem,
74  PreviousPassType& pass,
75  const DiscreteFunctionSpaceType& spc,
76  double factor = -1.0,
77  int volumeQuadOrd = -1, int faceQuadOrd=-1) :
78  BaseType(problem, pass, spc,volumeQuadOrd,faceQuadOrd),
79  problem_(problem),
80  spc_(spc),
81  communicationManager_(spc_),
82  tau_(0.0),
83  tauTmp_(0.0),
84  massVal_(0.0),
85  factor_(factor)
86  {
87  }
88 
90  virtual ~LocalDGMassPass() {
91  }
92 
93  private:
95  virtual void finalize(const ArgumentType& arg, DestinationType& dest) const
96  {
97  if(problem_.hasMass())
98  {
99  IteratorType endit = spc_.end();
100  for (IteratorType it = spc_.begin(); it != endit; ++it)
101  {
102  applyLocalMass(*it);
103  }
104  }
105 
106  // call finalize of dg pass (i.e. data communication)
107  BaseType :: finalize(arg,dest);
108  }
109 
110  private:
111  // apply mass matrix multiplication
112  // here matrix free implementation due to memory savings
113  void applyLocalMass(EntityType& en) const
114  {
115  //- typedefs
116  typedef typename DiscreteFunctionSpaceType::IndexSetType IndexSetType;
117 
118  //- statements
119  this->caller_.setEntity(en);
120  LocalFunctionType updEn = this->dest_->localFunction(en);
121  const int updEn_numDofs = updEn.numDofs();
122  const BasisFunctionSetType& bsetEn = updEn.basisFunctionSet();
123 
124  // only call geometry once, who know what is done in this function
125  const GeometryType & geo = en.geometry();
126 
127  const double massVolElinv = massVolInv(geo);
128 
129  if((int)massMatrix_.size() != updEn_numDofs)
130  {
131  massMatrix_.resize(updEn_numDofs);
132  }
133 
134  // clear mass entries
135  for (int i = 0; i < updEn_numDofs; ++i)
136  {
137  massMatrix_[i] = 0.0;
138  }
139 
141  // Volumetric integral part
143  VolumeQuadratureType volQuad(en, this->volumeQuadOrd_);
144  const int volQuad_nop = volQuad.nop();
145  for (int l = 0; l < volQuad_nop; ++l)
146  {
147  const double intel = geo.integrationElement(volQuad.point(l))
148  * massVolElinv * volQuad.weight(l);
149 
150  // evaluate mass factor
151  this->caller_.mass(en, volQuad, l, massVal_ );
152 
153  for (int i = 0; i < updEn_numDofs; ++i)
154  {
155  // eval tau_k
156  bsetEn.evaluate(i, volQuad[l], tau_ );
157 
158  // apply mass factor
159  massVal_.mv(tau_,tauTmp_);
160 
161  massMatrix_[i] += bsetEn.evaluateSingle(i, volQuad[l], tauTmp_ ) * intel;
162  }
163  }
164 
165  // multiply with mass matrix
166  for(int i=0; i<updEn_numDofs; ++i)
167  {
168  updEn[i] *= factor_ * massMatrix_[i];
169  }
170  }
171 
172  private:
173  LocalDGMassPass();
175  LocalDGMassPass& operator=(const LocalDGMassPass&);
176 
177  private:
178  double massVolInv(const GeometryType& geo) const
179  {
180  double volume = geo.volume();
181 
182  typedef typename GeometryType :: ctype coordType;
183  enum { dim = GridType :: dimension };
184  const Dune::ReferenceElement< coordType, dim > & refElem =
185  Dune::ReferenceElements< coordType, dim >::general(geo.type());
186 
187  double volRef = refElem.volume();
188  return volRef/volume;
189  }
190 
191  private:
192  DiscreteModelType& problem_;
193 
194  const DiscreteFunctionSpaceType& spc_;
195  mutable CommunicationManagerType communicationManager_;
196 
197  mutable RangeType tau_;
198  mutable RangeType tauTmp_;
199  mutable MassFactorType massVal_;
200  const double factor_;
201 
202  mutable std::vector<RangeFieldType> massMatrix_;
203  };
204 
206  } // namespace Fem
207 
208 } // namespace Dune
209 
210 #endif // #ifndef DUNE_FEM_DGMASSPASS_HH
GridType::template Codim< 0 >::Geometry Geometry
Definition: localdg/pass.hh:82
BaseType::LocalFunctionType LocalFunctionType
Definition: dgmasspass.hh:43
DiscreteFunctionSpaceType::IteratorType IteratorType
Iterator over the space.
Definition: localdg/pass.hh:69
BaseType::GridType GridType
Definition: dgmasspass.hh:46
DiscreteModelImp DiscreteModelType
Repetition of template arguments.
Definition: localdg/pass.hh:55
DiscreteModelType::MassFactorType MassFactorType
Definition: dgmasspass.hh:60
GridPartType::IntersectionIteratorType IntersectionIteratorType
Definition: localdg/pass.hh:80
BaseType::DiscreteModelType DiscreteModelType
Definition: dgmasspass.hh:35
virtual ~LocalDGMassPass()
Destructor.
Definition: dgmasspass.hh:90
Implementation of operator to calculate gradient of a given discrete function using the pass concept...
Definition: dgmasspass.hh:28
GridPartType::IndexSetType IndexSetType
Definition: localdg/pass.hh:94
CommunicationManager< DiscreteFunctionSpaceType > CommunicationManagerType
Definition: dgmasspass.hh:58
BaseType::BasisFunctionSetType BasisFunctionSetType
Definition: dgmasspass.hh:42
BaseType::PreviousPassType PreviousPassType
Definition: dgmasspass.hh:36
DiscreteModelCallerType * caller_
Definition: localdg/pass.hh:580
BaseType::DestinationType DestinationType
Definition: dgmasspass.hh:40
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: dgmasspass.hh:41
BaseType::ArgumentType ArgumentType
Definition: dgmasspass.hh:38
BaseType::ArgumentType ArgumentType
Definition: localdg/pass.hh:61
BaseType::IntersectionIteratorType IntersectionIteratorType
Definition: dgmasspass.hh:50
void pass(const GlobalArgumentType &arg) const
Definition: common/pass.hh:267
Definition: coordinate.hh:4
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: localdg/pass.hh:73
DiscreteModelType::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: localdg/pass.hh:67
BaseType::Entity EntityType
Definition: dgmasspass.hh:48
RangeType::value_type RangeFieldType
Definition: dgmasspass.hh:54
BaseType::Geometry GeometryType
Definition: dgmasspass.hh:49
const int volumeQuadOrd_
Definition: localdg/pass.hh:604
BaseType::RangeType RangeType
Definition: dgmasspass.hh:53
BaseType::GridPartType GridPartType
Definition: dgmasspass.hh:45
DiscreteModelType::Traits::DestinationType DestinationType
Definition: localdg/pass.hh:64
DiscreteModelType::Traits::VolumeQuadratureType VolumeQuadratureType
Definition: localdg/pass.hh:65
BaseType::IteratorType IteratorType
Definition: dgmasspass.hh:47
virtual void finalize(const ArgumentType &arg, DestinationType &dest) const
Some timestep size management.
Definition: localdg/pass.hh:194
DestinationType * dest_
Definition: localdg/pass.hh:584
DiscreteFunctionSpaceType::BasisFunctionSetType BasisFunctionSetType
Definition: localdg/pass.hh:77
Definition: dgmasspass.hh:62
DiscreteFunctionSpaceType::RangeType RangeType
Definition: localdg/pass.hh:75
PreviousPassImp PreviousPassType
Repetition of template arguments.
Definition: localdg/pass.hh:57
void mass(const EntityType &entity, const VolumeQuadratureType &quadrature, const int qp, MassFactorType &massFactor)
Definition: modelcaller.hh:199
BaseType::VolumeQuadratureType VolumeQuadratureType
Definition: dgmasspass.hh:56
DestinationType::LocalFunctionType LocalFunctionType
Definition: localdg/pass.hh:86
LocalDGMassPass(DiscreteModelType &problem, PreviousPassType &pass, const DiscreteFunctionSpaceType &spc, double factor=-1.0, int volumeQuadOrd=-1, int faceQuadOrd=-1)
Definition: dgmasspass.hh:73
void setEntity(const EntityType &entity)
Definition: modelcaller.hh:97
DiscreteFunctionSpaceType::GridType GridType
Definition: localdg/pass.hh:72
Definition: localdg/pass.hh:41