DUNE PDELab (git)

cg_to_dg_prolongation.hh
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
7
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
16#include <dune/pdelab/common/geometrywrapper.hh>
17#include <dune/pdelab/gridoperator/common/localmatrix.hh>
18#include <dune/pdelab/localoperator/pattern.hh>
19#include <dune/pdelab/localoperator/flags.hh>
20#include <dune/pdelab/localoperator/idefault.hh>
21
22namespace Dune {
23 namespace PDELab {
24
28
29 namespace CG2DGHelper { // hide some TMP code
30
31 template <typename Imp>
32 struct WrappedLocalShapeFunctionTraits {
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>
41 class WrappedLocalShapeFunction
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:
53 typedef WrappedLocalShapeFunctionTraits<Imp> Traits;
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>
66 class ComputeCG2DGVisitor :
67 public TypeTree::DefaultPairVisitor,
68 public TypeTree::DynamicTraversal,
69 public TypeTree::VisitTree
70 {
71 LocalMatrix<R>& _mat;
72
73 public:
74 ComputeCG2DGVisitor(LocalMatrix<R>& mat) :
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
90 WrappedLocalShapeFunction<LFSU> f(lfsu, i);
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
106 class CG2DGProlongation :
107 public FullVolumePattern,
108 public LocalOperatorDefaultFlags,
109 public InstationaryLocalOperatorDefaultMethods<double>
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
117 CG2DGHelper::ComputeCG2DGVisitor<R> cg2dg(mat);
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
127 CG2DGProlongation () {}
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
vector space out of a tensor product of fields.
Definition: fvector.hh:95
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:326
void applyToTreePair(Tree1 &&tree1, Tree2 &&tree2, Visitor &&visitor)
Apply visitor to a pair of TypeTrees.
Definition: pairtraversal.hh:128
Dune namespace.
Definition: alignedallocator.hh:13
static const std::size_t dimDomainLocal
export dimension of local coordinates
Definition: interfaceswitch.hh:158
Basis::Traits::Range Range
export vector type of the values
Definition: interfaceswitch.hh:167
Basis::Traits::DomainField DomainField
export field types of the coordinates
Definition: interfaceswitch.hh:156
void leaf(T1 &&, T2 &&, TreePath) const
Method for leaf traversal.
Definition: visitor.hh:216
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)