dune-pdelab  2.5-dev
cg_to_dg_prolongation.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil -*-
2 #ifndef DUNE_PDELAB_BACKEND_ISTL_CG_TO_DG_PROLONGATION_HH
3 #define DUNE_PDELAB_BACKEND_ISTL_CG_TO_DG_PROLONGATION_HH
4 
5 // this is here for backwards compatibility and deprecation warnings, remove after 2.5.0
6 #include "ensureistlinclude.hh"
7 
8 #include <dune/common/exceptions.hh>
9 #include <dune/common/fvector.hh>
10 
11 #include <dune/geometry/quadraturerules.hh>
12 
13 #include <dune/localfunctions/common/interfaceswitch.hh>
14 
15 #include <dune/typetree/pairtraversal.hh>
16 #include <dune/typetree/transformation.hh>
17 #include <dune/typetree/visitor.hh>
18 
24 
25 namespace Dune {
26  namespace PDELab {
27 
31 
32  namespace CG2DGHelper { // hide some TMP code
33 
34  template <typename Imp>
36  typedef typename Imp::Traits::FiniteElementType::
37  Traits::LocalBasisType::Traits::RangeType RangeType;
38  typedef typename Imp::Traits::FiniteElementType::
39  Traits::LocalBasisType::Traits::DomainType DomainType;
40  };
41 
42  // evaluate a localfunction as a function on a different element
43  template<typename Imp>
45  {
46  const Imp & _imp;
47  const int _comp;
48 
49  typedef typename Imp::Traits::FiniteElementType FEM;
50  typedef FiniteElementInterfaceSwitch<FEM> FESwitch;
51  typedef BasisInterfaceSwitch<typename FESwitch::Basis > BasisSwitch;
52  typedef typename BasisSwitch::DomainField DF;
53  typedef typename BasisSwitch::Range RT;
54  enum { dim = BasisSwitch::dimDomainLocal };
55  public:
57  WrappedLocalShapeFunction (const Imp& imp, int comp) :
58  _imp(imp), _comp(comp) {}
59 
60  void evaluate(const Dune::FieldVector<DF,dim> & x,
61  Dune::FieldVector<DF,1> & y) const
62  {
63  std::vector<RT> v;
64  _imp.finiteElement().localBasis().evaluateFunction(x,v);
65  y = v[_comp];
66  }
67  };
68 
69  template <typename R>
71  public TypeTree::DefaultPairVisitor,
72  public TypeTree::DynamicTraversal,
73  public TypeTree::VisitTree
74  {
75  LocalMatrix<R>& _mat;
76 
77  public:
79  _mat(mat)
80  {}
81 
82  template<typename LFSU, typename LFSV, typename TreePath>
83  void leaf(const LFSU& lfsu, const LFSV& lfsv, TreePath treePath) const
84  {
85  // map from CG (lfsu) 2 DG (lfsv)
86  typedef typename LFSV::Traits::FiniteElementType DG_FEM;
87  typedef FiniteElementInterfaceSwitch<DG_FEM> FESwitch;
88  typedef BasisInterfaceSwitch<typename FESwitch::Basis > BasisSwitch;
89  typedef typename BasisSwitch::DomainField DF;
90  std::vector<DF> v;
91  for (unsigned int i=0; i<lfsu.size(); i++)
92  {
93  // create function f, which wraps a CG shape function
95  // interpolate f into DG space
96  FESwitch::interpolation(lfsv.finiteElement()).
97  interpolate(f, v);
98  // store coefficients
99  for (unsigned int j=0; j<lfsv.size(); j++)
100  {
101  _mat(lfsv,j,lfsu,i) = v[j];
102  }
103  }
104  }
105  };
106 
107  } // end namespace CG2DGHelper
108 
109  // a local operator to compute DG shift matrix needed for some AMG variants
111  public FullVolumePattern,
114  {
115  template<typename LFSU, typename LFSV, typename R>
116  void computeCG2DG(const LFSU & lfsu, const LFSV & lfsv,
117  LocalMatrix<R>& mat) const
118  {
119  // lfsu: CG
120  // lfsv: DG
122  TypeTree::applyToTreePair(lfsu, lfsv, cg2dg);
123  }
124  public:
125  // pattern assembly flags
126  enum { doPatternVolume = true };
127 
128  // residual assembly flags
129  enum { doAlphaVolume = true };
130 
132 
133  // alpha_volume:
134  // not implemented, as it should never be used. We just miss-use the assembler to
135  // assemble the shift-matrix
136 
137  // jacobian of skeleton term
138  template<typename EG, typename LFSU, typename X, typename LFSV, typename M>
139  void jacobian_volume (const EG&, const LFSU& lfsu, const X&, const LFSV& lfsv,
140  M & mat) const
141  {
142  computeCG2DG(lfsu, lfsv, mat.container());
143  }
144  };
145 
147  } // namespace PDELab
148 } // namespace Dune
149 
150 #endif // DUNE_PDELAB_BACKEND_ISTL_CG_TO_DG_PROLONGATION_HH
static const int dim
Definition: adaptivity.hh:83
Imp::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeType RangeType
Definition: cg_to_dg_prolongation.hh:37
void leaf(const LFSU &lfsu, const LFSV &lfsv, TreePath treePath) const
Definition: cg_to_dg_prolongation.hh:83
void jacobian_volume(const EG &, const LFSU &lfsu, const X &, const LFSV &lfsv, M &mat) const
Definition: cg_to_dg_prolongation.hh:139
Definition: cg_to_dg_prolongation.hh:35
Default class for additional methods in instationary local operators.
Definition: idefault.hh:89
Definition: cg_to_dg_prolongation.hh:70
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
WrappedLocalShapeFunction< Imp > Traits
Definition: cg_to_dg_prolongation.hh:56
Imp::Traits::FiniteElementType::Traits::LocalBasisType::Traits::DomainType DomainType
Definition: cg_to_dg_prolongation.hh:39
sparsity pattern generator
Definition: pattern.hh:13
Definition: cg_to_dg_prolongation.hh:44
WrappedLocalShapeFunction(const Imp &imp, int comp)
Definition: cg_to_dg_prolongation.hh:57
CG2DGProlongation()
Definition: cg_to_dg_prolongation.hh:131
void evaluate(const Dune::FieldVector< DF, dim > &x, Dune::FieldVector< DF, 1 > &y) const
Definition: cg_to_dg_prolongation.hh:60
Default flags for all local operators.
Definition: flags.hh:18
Definition: cg_to_dg_prolongation.hh:110
ComputeCG2DGVisitor(LocalMatrix< R > &mat)
Definition: cg_to_dg_prolongation.hh:78
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:191