dune-pdelab  2.4.1
l2volumefunctional.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_PDELAB_LOCALOPERATOR_L2VOLUMEFUNCTIONAL_HH
4 #define DUNE_PDELAB_LOCALOPERATOR_L2VOLUMEFUNCTIONAL_HH
5 
6 #include <vector>
7 
8 #include <dune/common/exceptions.hh>
9 #include <dune/common/fvector.hh>
10 
11 #include <dune/geometry/type.hh>
12 #include <dune/geometry/quadraturerules.hh>
13 
14 #include <dune/localfunctions/common/interfaceswitch.hh>
15 
20 
21 namespace Dune {
22  namespace PDELab {
26 
36  template<typename F>
39  {
40  public:
41  // residual assembly flags
42  enum { doLambdaVolume = true };
43 
49  L2VolumeFunctional (const F& f, unsigned int quadOrder)
50  : f_(f), quadOrder_(quadOrder)
51  {}
52 
53  // volume integral depending only on test functions
54  template<typename EG, typename LFSV, typename R>
55  void lambda_volume (const EG& eg, const LFSV& lfsv, R& r) const
56  {
57  // Define types
58  using FESwitch = FiniteElementInterfaceSwitch<typename LFSV::Traits::FiniteElementType>;
59  using BasisSwitch = BasisInterfaceSwitch<typename FESwitch::Basis>;
60  using RF = typename BasisSwitch::RangeField;
61  using Range = typename BasisSwitch::Range;
62 
63  // Reference to cell
64  const auto& cell = eg.entity();
65 
66  // get geometry
67  auto geo = eg.geometry();
68 
69  // Initialize vectors outside for loop
70  std::vector<Range> phi(lfsv.size());
71  typename F::Traits::RangeType y(0.0);
72 
73  // loop over quadrature points
74  for (const auto& ip : quadratureRule(geo,quadOrder_))
75  {
76  // evaluate shape functions
77  FESwitch::basis(lfsv.finiteElement()).
78  evaluateFunction(ip.position(),phi);
79 
80  // evaluate right hand side parameter function
81  f_.evaluate(cell,ip.position(),y);
82 
83  // integrate f
84  auto factor = r.weight() * ip.weight() * geo.integrationElement(ip.position());
85  for (size_t i=0; i<lfsv.size(); i++)
86  r.rawAccumulate(lfsv,i,y*phi[i]*factor);
87  }
88  }
89 
90  protected:
91  const F& f_;
92 
93  // Quadrature rule order
94  unsigned int quadOrder_;
95  };
96 
98  } // namespace PDELab
99 } // namespace Dune
100 
101 #endif
A local operator that tests a function against a test function space defined on the entire grid...
Definition: l2volumefunctional.hh:37
Definition: l2volumefunctional.hh:42
Definition: adaptivity.hh:27
Default flags for all local operators.
Definition: flags.hh:18
QuadratureRuleWrapper< QuadratureRule< typename Geometry::ctype, Geometry::mydimension > > quadratureRule(const Geometry &geo, std::size_t order, QuadratureType::Enum quadrature_type=QuadratureType::GaussLegendre)
Returns a quadrature rule for the given geometry.
Definition: quadraturerules.hh:117
const F & f_
Definition: l2volumefunctional.hh:91
void lambda_volume(const EG &eg, const LFSV &lfsv, R &r) const
Definition: l2volumefunctional.hh:55
unsigned int quadOrder_
Definition: l2volumefunctional.hh:94
L2VolumeFunctional(const F &f, unsigned int quadOrder)
Constructor.
Definition: l2volumefunctional.hh:49