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