dune-pdelab  2.7-git
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 #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  Dune::FieldVector<DF,1> operator()(const Dune::FieldVector<DF,dim> & x) const
58  {
59  std::vector<RT> v;
60  _imp.finiteElement().localBasis().evaluateFunction(x,v);
61  return v[_comp];
62  }
63  };
64 
65  template <typename R>
67  public TypeTree::DefaultPairVisitor,
68  public TypeTree::DynamicTraversal,
69  public TypeTree::VisitTree
70  {
71  LocalMatrix<R>& _mat;
72 
73  public:
75  _mat(mat)
76  {}
77 
78  template<typename LFSU, typename LFSV, typename TreePath>
79  void leaf(const LFSU& lfsu, const LFSV& lfsv, TreePath treePath) const
80  {
81  // map from CG (lfsu) 2 DG (lfsv)
82  typedef typename LFSV::Traits::FiniteElementType DG_FEM;
83  typedef FiniteElementInterfaceSwitch<DG_FEM> FESwitch;
84  typedef BasisInterfaceSwitch<typename FESwitch::Basis > BasisSwitch;
85  typedef typename BasisSwitch::DomainField DF;
86  std::vector<DF> v;
87  for (unsigned int i=0; i<lfsu.size(); i++)
88  {
89  // create function f, which wraps a CG shape function
91  // interpolate f into DG space
92  FESwitch::interpolation(lfsv.finiteElement()).
93  interpolate(f, v);
94  // store coefficients
95  for (unsigned int j=0; j<lfsv.size(); j++)
96  {
97  _mat(lfsv,j,lfsu,i) = v[j];
98  }
99  }
100  }
101  };
102 
103  } // end namespace CG2DGHelper
104 
105  // a local operator to compute DG shift matrix needed for some AMG variants
107  public FullVolumePattern,
110  {
111  template<typename LFSU, typename LFSV, typename R>
112  void computeCG2DG(const LFSU & lfsu, const LFSV & lfsv,
113  LocalMatrix<R>& mat) const
114  {
115  // lfsu: CG
116  // lfsv: DG
118  TypeTree::applyToTreePair(lfsu, lfsv, cg2dg);
119  }
120  public:
121  // pattern assembly flags
122  enum { doPatternVolume = true };
123 
124  // residual assembly flags
125  enum { doAlphaVolume = true };
126 
128 
129  // alpha_volume:
130  // not implemented, as it should never be used. We just miss-use the assembler to
131  // assemble the shift-matrix
132 
133  // jacobian of skeleton term
134  template<typename EG, typename LFSU, typename X, typename LFSV, typename M>
135  void jacobian_volume (const EG&, const LFSU& lfsu, const X&, const LFSV& lfsv,
136  M & mat) const
137  {
138  computeCG2DG(lfsu, lfsv, mat.container());
139  }
140  };
141 
143  } // namespace PDELab
144 } // namespace Dune
145 
146 #endif // DUNE_PDELAB_BACKEND_ISTL_CG_TO_DG_PROLONGATION_HH
Dune::PDELab::CG2DGHelper::ComputeCG2DGVisitor::ComputeCG2DGVisitor
ComputeCG2DGVisitor(LocalMatrix< R > &mat)
Definition: cg_to_dg_prolongation.hh:74
Dune::PDELab::CG2DGProlongation::CG2DGProlongation
CG2DGProlongation()
Definition: cg_to_dg_prolongation.hh:127
Dune::PDELab::LocalOperatorDefaultFlags
Default flags for all local operators.
Definition: flags.hh:18
Dune::PDELab::CG2DGProlongation
Definition: cg_to_dg_prolongation.hh:106
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunctionTraits
Definition: cg_to_dg_prolongation.hh:32
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunction::operator()
Dune::FieldVector< DF, 1 > operator()(const Dune::FieldVector< DF, dim > &x) const
Definition: cg_to_dg_prolongation.hh:57
Dune::PDELab::CG2DGHelper::ComputeCG2DGVisitor::leaf
void leaf(const LFSU &lfsu, const LFSV &lfsv, TreePath treePath) const
Definition: cg_to_dg_prolongation.hh:79
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunction::Traits
WrappedLocalShapeFunctionTraits< Imp > Traits
Definition: cg_to_dg_prolongation.hh:53
Dune::PDELab::InstationaryLocalOperatorDefaultMethods
Default class for additional methods in instationary local operators.
Definition: idefault.hh:89
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::CG2DGHelper::ComputeCG2DGVisitor
Definition: cg_to_dg_prolongation.hh:66
idefault.hh
pattern.hh
Dune::PDELab::FullVolumePattern
sparsity pattern generator
Definition: pattern.hh:13
Dune::PDELab::interpolate
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunctionTraits::RangeType
Imp::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeType RangeType
Definition: cg_to_dg_prolongation.hh:34
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunction::WrappedLocalShapeFunction
WrappedLocalShapeFunction(const Imp &imp, int comp)
Definition: cg_to_dg_prolongation.hh:54
Dune::PDELab::CG2DGProlongation::doPatternVolume
@ doPatternVolume
Definition: cg_to_dg_prolongation.hh:122
geometrywrapper.hh
Dune::PDELab::CG2DGProlongation::doAlphaVolume
@ doAlphaVolume
Definition: cg_to_dg_prolongation.hh:125
Dune::PDELab::LocalMatrix< R >
flags.hh
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunction
Definition: cg_to_dg_prolongation.hh:41
Dune::PDELab::CG2DGHelper::WrappedLocalShapeFunctionTraits::DomainType
Imp::Traits::FiniteElementType::Traits::LocalBasisType::Traits::DomainType DomainType
Definition: cg_to_dg_prolongation.hh:36
localmatrix.hh
Dune::PDELab::CG2DGProlongation::jacobian_volume
void jacobian_volume(const EG &, const LFSU &lfsu, const X &, const LFSV &lfsv, M &mat) const
Definition: cg_to_dg_prolongation.hh:135