dune-fem  2.6-git
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 
9 
10 namespace Dune
11 {
12 
13  namespace Fem
14  {
15 
28  template< class DiscreteModelImp, class PreviousPassImp >
30  : public LocalDGPass< DiscreteModelImp, PreviousPassImp >
31  {
34 
35  public:
38 
40 
45 
47  typedef typename BaseType::GridType GridType;
49  typedef typename BaseType::Entity EntityType;
50  typedef typename BaseType::Geometry GeometryType;
52 
53 
54  typedef typename BaseType::RangeType RangeType;
55  typedef typename RangeType::value_type RangeFieldType;
56 
58 
60 
61  typedef typename DiscreteModelType::MassFactorType MassFactorType;
62 
64 
65  public:
66  //- Public methods
76  const DiscreteFunctionSpaceType& spc,
77  double factor = -1.0,
78  int volumeQuadOrd = -1, int faceQuadOrd=-1) :
79  BaseType(problem, pass, spc,volumeQuadOrd,faceQuadOrd),
80  problem_(problem),
81  spc_( referenceToSharedPtr( spc ) ),
82  communicationManager_( space() ),
83  tau_(0.0),
84  tauTmp_(0.0),
85  massVal_(0.0),
86  factor_(factor)
87  {
88  }
89 
91  virtual ~LocalDGMassPass() {
92  }
93 
94  private:
96  virtual void finalize(const ArgumentType& arg, DestinationType& dest) const
97  {
98  if(problem_.hasMass())
99  {
100  IteratorType endit = space().end();
101  for (IteratorType it = space().begin(); it != endit; ++it)
102  {
103  applyLocalMass(*it);
104  }
105  }
106 
107  // call finalize of dg pass (i.e. data communication)
108  BaseType :: finalize(arg,dest);
109  }
110 
111  private:
112  // apply mass matrix multiplication
113  // here matrix free implementation due to memory savings
114  void applyLocalMass(EntityType& en) const
115  {
116  //- statements
117  this->caller_.setEntity(en);
118  LocalFunctionType updEn = this->dest_->localFunction(en);
119  const int updEn_numDofs = updEn.numDofs();
120  const BasisFunctionSetType& bsetEn = updEn.basisFunctionSet();
121 
122  // only call geometry once, who know what is done in this function
123  const GeometryType & geo = en.geometry();
124 
125  const double massVolElinv = massVolInv(geo);
126 
127  if((int)massMatrix_.size() != updEn_numDofs)
128  {
129  massMatrix_.resize(updEn_numDofs);
130  }
131 
132  // clear mass entries
133  for (int i = 0; i < updEn_numDofs; ++i)
134  {
135  massMatrix_[i] = 0.0;
136  }
137 
139  // Volumetric integral part
141  VolumeQuadratureType volQuad(en, this->volumeQuadOrd_);
142  const int volQuad_nop = volQuad.nop();
143  for (int l = 0; l < volQuad_nop; ++l)
144  {
145  const double intel = geo.integrationElement(volQuad.point(l))
146  * massVolElinv * volQuad.weight(l);
147 
148  // evaluate mass factor
149  this->caller_.mass(en, volQuad, l, massVal_ );
150 
151  for (int i = 0; i < updEn_numDofs; ++i)
152  {
153  // eval tau_k
154  bsetEn.evaluate(i, volQuad[l], tau_ );
155 
156  // apply mass factor
157  massVal_.mv(tau_,tauTmp_);
158 
159  massMatrix_[i] += bsetEn.evaluateSingle(i, volQuad[l], tauTmp_ ) * intel;
160  }
161  }
162 
163  // multiply with mass matrix
164  for(int i=0; i<updEn_numDofs; ++i)
165  {
166  updEn[i] *= factor_ * massMatrix_[i];
167  }
168  }
169 
170  const DiscreteFunctionSpaceType &space () const { return *spc_; }
171 
172  private:
173  LocalDGMassPass();
174  LocalDGMassPass(const 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  std::shared_ptr< 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
Definition: bindguard.hh:11
static std::shared_ptr< T > referenceToSharedPtr(T &t)
Definition: memory.hh:19
Implementation of operator to calculate gradient of a given discrete function using the pass concept.
Definition: dgmasspass.hh:31
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: dgmasspass.hh:42
BaseType::RangeType RangeType
Definition: dgmasspass.hh:54
BaseType::IntersectionIteratorType IntersectionIteratorType
Definition: dgmasspass.hh:51
BaseType::LocalFunctionType LocalFunctionType
Definition: dgmasspass.hh:44
BaseType::GridPartType GridPartType
Definition: dgmasspass.hh:46
BaseType::DiscreteModelType DiscreteModelType
Definition: dgmasspass.hh:36
RangeType::value_type RangeFieldType
Definition: dgmasspass.hh:55
BaseType::Geometry GeometryType
Definition: dgmasspass.hh:50
DiscreteModelType::MassFactorType MassFactorType
Definition: dgmasspass.hh:61
BaseType::Entity EntityType
Definition: dgmasspass.hh:49
LocalDGMassPass(DiscreteModelType &problem, PreviousPassType &pass, const DiscreteFunctionSpaceType &spc, double factor=-1.0, int volumeQuadOrd=-1, int faceQuadOrd=-1)
Definition: dgmasspass.hh:74
@ dimRange
Definition: dgmasspass.hh:63
BaseType::BasisFunctionSetType BasisFunctionSetType
Definition: dgmasspass.hh:43
BaseType::VolumeQuadratureType VolumeQuadratureType
Definition: dgmasspass.hh:57
BaseType::IteratorType IteratorType
Definition: dgmasspass.hh:48
BaseType::ArgumentType ArgumentType
Definition: dgmasspass.hh:39
BaseType::PreviousPassType PreviousPassType
Definition: dgmasspass.hh:37
virtual ~LocalDGMassPass()
Destructor.
Definition: dgmasspass.hh:91
BaseType::DestinationType DestinationType
Definition: dgmasspass.hh:41
CommunicationManager< DiscreteFunctionSpaceType > CommunicationManagerType
Definition: dgmasspass.hh:59
BaseType::GridType GridType
Definition: dgmasspass.hh:47
void pass(const GlobalArgumentType &arg) const
Definition: common/pass.hh:263
void setEntity(const EntityType &entity)
Definition: modelcaller.hh:97
void mass(const EntityType &entity, const VolumeQuadratureType &quadrature, const int qp, MassFactorType &massFactor)
Definition: modelcaller.hh:199
Definition: localdg/pass.hh:42
virtual void finalize(const ArgumentType &arg, DestinationType &dest) const
Some timestep size management.
Definition: localdg/pass.hh:193
DiscreteModelType::Traits::DestinationType DestinationType
Definition: localdg/pass.hh:63
BaseType::ArgumentType ArgumentType
Definition: localdg/pass.hh:60
DiscreteModelType::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: localdg/pass.hh:66
GridPartType::IntersectionIteratorType IntersectionIteratorType
Definition: localdg/pass.hh:79
DestinationType * dest_
Definition: localdg/pass.hh:581
PreviousPassImp PreviousPassType
Repetition of template arguments.
Definition: localdg/pass.hh:56
const int volumeQuadOrd_
Definition: localdg/pass.hh:600
DiscreteModelImp DiscreteModelType
Repetition of template arguments.
Definition: localdg/pass.hh:54
DiscreteFunctionSpaceType::IteratorType IteratorType
Iterator over the space.
Definition: localdg/pass.hh:68
DestinationType::LocalFunctionType LocalFunctionType
Definition: localdg/pass.hh:85
DiscreteFunctionSpaceType::GridType GridType
Definition: localdg/pass.hh:71
@ dimRange
Definition: localdg/pass.hh:90
DiscreteModelCallerType * caller_
Definition: localdg/pass.hh:577
GridType::template Codim< 0 >::Geometry Geometry
Definition: localdg/pass.hh:81
DiscreteModelType::Traits::VolumeQuadratureType VolumeQuadratureType
Definition: localdg/pass.hh:64
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: localdg/pass.hh:72
DiscreteFunctionSpaceType::BasisFunctionSetType BasisFunctionSetType
Definition: localdg/pass.hh:76
DiscreteFunctionSpaceType::RangeType RangeType
Definition: localdg/pass.hh:74