dune-pdelab  2.0.0
laplace.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 
4 #ifndef DUNE_PDELAB_LOCALOPERATOR_LAPLACE_HH
5 #define DUNE_PDELAB_LOCALOPERATOR_LAPLACE_HH
6 
7 #include <vector>
8 
9 #include <dune/common/fvector.hh>
10 #include <dune/common/static_assert.hh>
11 
12 #include <dune/geometry/type.hh>
13 #include <dune/geometry/quadraturerules.hh>
14 
15 #include <dune/localfunctions/common/interfaceswitch.hh>
16 
19 
20 namespace Dune {
21  namespace PDELab {
25 
37  class Laplace
38  : public FullVolumePattern,
40  {
41  public:
42  // pattern assembly flags
43  enum { doPatternVolume = true };
44 
45  // residual assembly flags
46  enum { doAlphaVolume = true };
47 
52  Laplace (unsigned int quadOrder)
53  : quadOrder_(quadOrder)
54  {}
55 
66  template<typename EG, typename LFSU, typename X, typename LFSV, typename R>
67  void alpha_volume (const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv, R& r) const
68  {
69  // domain and range field type
70  typedef FiniteElementInterfaceSwitch<
71  typename LFSU::Traits::FiniteElementType
72  > FESwitch;
73  typedef BasisInterfaceSwitch<
74  typename FESwitch::Basis
75  > BasisSwitch;
76  typedef typename BasisSwitch::DomainField DF;
77  typedef typename BasisSwitch::RangeField RF;
78 
79  // dimensions
80  static const int dimLocal = EG::Geometry::mydimension;
81  static const int dimGlobal = EG::Geometry::coorddimension;
82 
83  // select quadrature rule
84  Dune::GeometryType gt = eg.geometry().type();
85  const Dune::QuadratureRule<DF,dimLocal>& rule =
86  Dune::QuadratureRules<DF,dimLocal>::rule(gt,quadOrder_);
87 
88  // loop over quadrature points
89  for(typename Dune::QuadratureRule<DF,dimLocal>::const_iterator it =
90  rule.begin(); it!=rule.end(); ++it)
91  {
92  // evaluate gradient of shape functions
93  // (we assume Galerkin method lfsu=lfsv)
94  std::vector<Dune::FieldMatrix<RF,1,dimGlobal> >
95  gradphiu(lfsu.size());
96  BasisSwitch::gradient(FESwitch::basis(lfsu.finiteElement()),
97  eg.geometry(), it->position(), gradphiu);
98  std::vector<Dune::FieldMatrix<RF,1,dimGlobal> >
99  gradphiv(lfsv.size());
100  BasisSwitch::gradient(FESwitch::basis(lfsv.finiteElement()),
101  eg.geometry(), it->position(), gradphiv);
102 
103  // compute gradient of u
104  Dune::FieldVector<RF,dimGlobal> gradu(0.0);
105  for (size_t i=0; i<lfsu.size(); i++)
106  gradu.axpy(x(lfsu,i),gradphiu[i][0]);
107 
108  // integrate grad u * grad phi_i
109  RF factor = r.weight() * it->weight() * eg.geometry().integrationElement(it->position());
110  for (size_t i=0; i<lfsv.size(); i++)
111  r.rawAccumulate(lfsv,i,(gradu*gradphiv[i][0])*factor);
112  }
113  }
114 
125  template<typename EG, typename LFSU, typename X, typename LFSV, typename M>
126  void jacobian_volume (const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv, M & matrix) const
127  {
128  // Switches between local and global interface
129  typedef FiniteElementInterfaceSwitch<
130  typename LFSU::Traits::FiniteElementType
131  > FESwitch;
132  typedef BasisInterfaceSwitch<
133  typename FESwitch::Basis
134  > BasisSwitch;
135 
136  // domain and range field type
137  typedef typename BasisSwitch::DomainField DF;
138  typedef typename BasisSwitch::RangeField RF;
139  typedef typename LFSU::Traits::SizeType size_type;
140 
141  // dimensions
142  const int dim = EG::Geometry::dimension;
143 
144  // select quadrature rule
145  Dune::GeometryType gt = eg.geometry().type();
146  const Dune::QuadratureRule<DF,dim>& rule = Dune::QuadratureRules<DF,dim>::rule(gt,quadOrder_);
147 
148  // loop over quadrature points
149  for (typename QuadratureRule<DF,dim>::const_iterator it=rule.begin(); it!=rule.end(); ++it)
150  {
151  std::vector<Dune::FieldMatrix<RF,1,dim> > gradphi(lfsu.size());
152  BasisSwitch::gradient(FESwitch::basis(lfsu.finiteElement()),
153  eg.geometry(), it->position(), gradphi);
154 
155  // geometric weight
156  RF factor = it->weight() * eg.geometry().integrationElement(it->position());
157 
158  for (size_type i=0; i<lfsu.size(); i++)
159  {
160  for (size_type j=0; j<lfsv.size(); j++)
161  {
162  // integrate grad u * grad phi
163  matrix.accumulate(lfsv,j,lfsu,i, gradphi[i][0] * gradphi[j][0] * factor);
164  }
165  }
166  }
167  }
168 
169  protected:
170  // Quadrature rule order
171  unsigned int quadOrder_;
172  };
173 
175  } // namespace PDELab
176 } // namespace Dune
177 
178 #endif
void jacobian_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, M &matrix) const
Compute the Laplace stiffness matrix for the element given in 'eg'.
Definition: laplace.hh:126
unsigned int quadOrder_
Definition: laplace.hh:171
Default flags for all local operators.
Definition: flags.hh:18
static const int dim
Definition: adaptivity.hh:82
void alpha_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, R &r) const
Compute Laplace matrix times a given vector for one element.
Definition: laplace.hh:67
Laplace(unsigned int quadOrder)
Constructor.
Definition: laplace.hh:52
sparsity pattern generator
Definition: pattern.hh:14
const EG & eg
Definition: common/constraints.hh:277
Definition: laplace.hh:46
Definition: laplace.hh:37