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