DUNE PDELab (git)

blockdiagonal.hh
1// -*- tab-width: 2; indent-tabs-mode: nil -*-
2#ifndef DUNE_PDELAB_LOCALOPERATOR_BLOCKDIAGONAL_HH
3#define DUNE_PDELAB_LOCALOPERATOR_BLOCKDIAGONAL_HH
4
5#include <memory>
6#include <utility>
7
8#include <dune/typetree/traversal.hh>
9#include <dune/typetree/childextraction.hh>
10
11#include <dune/pdelab/localoperator/flags.hh>
12#include <dune/pdelab/localoperator/pattern.hh>
13
14namespace Dune {
15 namespace PDELab {
16
17#ifndef DOXYGEN
18
19 namespace impl {
20
21 // TypeTree visitor for applying an operation to a pair of ansatz and test local function space
22 template<typename LFSV, typename Operation>
23 struct ApplyBlockOperation
24 : public TypeTree::TreeVisitor
25 , public TypeTree::StaticTraversal
26 {
27
28 template<typename LeafLFSU, typename TreePath>
29 void leaf(LeafLFSU& leaf_lfsu, TreePath tree_path)
30 {
31 auto& leaf_lfsv = child(_lfsv,tree_path);
32 _operation(tree_path,leaf_lfsu,leaf_lfsv);
33 }
34
35 ApplyBlockOperation(const LFSV& lfsv, Operation operation)
36 : _lfsv(lfsv)
37 , _operation(operation)
38 {}
39
40 const LFSV& _lfsv;
41 Operation _operation;
42
43 };
44
45 template<typename LFSV, typename Operation>
46 auto applyBlockOperation(const LFSV& lfsv, Operation operation)
47 {
48 return ApplyBlockOperation<LFSV,Operation>(lfsv,operation);
49 }
50
51 } // namespace impl
52
53#endif // DOXYGEN
54
58
60
74 template<typename ScalarLOP>
76 : public FullVolumePattern
78 {
79
80 public:
81
82 using RealType = typename ScalarLOP::RealType;
83
84 static constexpr bool doPatternVolume = true;
85 static constexpr bool doAlphaVolume = true;
86
88 BlockDiagonalLocalOperatorFullCoupling(const std::shared_ptr<ScalarLOP>& scalar_lop)
89 : _scalar_lop(scalar_lop)
90 {}
91
93 BlockDiagonalLocalOperatorFullCoupling(std::shared_ptr<ScalarLOP>& scalar_lop)
94 : _scalar_lop(scalar_lop)
95 {}
96
98 template<typename... ScalarOperatorArgs>
99 BlockDiagonalLocalOperatorFullCoupling(ScalarOperatorArgs&&... scalarOperatorArgs)
100 : _scalar_lop(std::make_shared<ScalarLOP>(std::forward<ScalarOperatorArgs>(scalarOperatorArgs)...))
101 {}
102
103 template<typename EG, typename LFSU, typename X, typename LFSV, typename R>
104 void alpha_volume(const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv, R& r) const
105 {
106 auto visitor = impl::applyBlockOperation(
107 lfsv,
108 [&](auto tree_path, auto& lfsu, auto& lfsv)
109 {
110 _scalar_lop->alpha_volume(eg,lfsu,x,lfsv,r);
111 });
112 TypeTree::applyToTree(lfsu,visitor);
113 }
114
115 template<typename EG, typename LFSU, typename X, typename LFSV, typename Y>
116 void jacobian_apply_volume(const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv, Y& y) const
117 {
118 auto visitor = impl::applyBlockOperation(
119 lfsv,
120 [&](auto tree_path, auto& lfsu, auto& lfsv)
121 {
122 _scalar_lop->jacobian_apply_volume(eg,lfsu,x,lfsv,y);
123 });
124 TypeTree::applyToTree(lfsu,visitor);
125 }
126
127 template<typename EG, typename LFSU, typename X, typename LFSV, typename M>
128 void jacobian_volume(const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv, M& mat) const
129 {
130 auto visitor = impl::applyBlockOperation(
131 lfsv,
132 [&](auto tree_path, auto& lfsu, auto& lfsv)
133 {
134 _scalar_lop->jacobian_volume(eg,lfsu,x,lfsv,mat);
135 });
136 TypeTree::applyToTree(lfsu,visitor);
137 }
138
139 void setTime(RealType t)
140 {
141 _scalar_lop->setTime(t);
142 }
143
144 RealType getTime() const
145 {
146 return _scalar_lop->getTime();
147 }
148
149 void preStep(RealType time, RealType dt, int stages)
150 {
151 _scalar_lop->preStep(time,dt,stages);
152 }
153
154 void postStep()
155 {
156 _scalar_lop->postStep();
157 }
158
159 void preStage(RealType time, int r)
160 {
161 _scalar_lop->preStage(time,r);
162 }
163
164 int getStage() const
165 {
166 return _scalar_lop->getStage();
167 }
168
169 void postStage()
170 {
171 _scalar_lop->postStage();
172 }
173
174 RealType suggestTimestep(RealType dt) const
175 {
176 return _scalar_lop->suggestTimeStep(dt);
177 }
178
179 private:
180
181 std::shared_ptr<ScalarLOP> _scalar_lop;
182
183 };
184
186
187 } // namespace PDELab
188} // namespace Dune
189
190#endif // DUNE_PDELAB_LOCALOPERATOR_BLOCKDIAGONAL_HH
Block diagonal extension of scalar local operator.
Definition: blockdiagonal.hh:78
BlockDiagonalLocalOperatorFullCoupling(const std::shared_ptr< ScalarLOP > &scalar_lop)
Constructs the adapter by wrapping an existing shared_ptr to the scalar operator.
Definition: blockdiagonal.hh:88
BlockDiagonalLocalOperatorFullCoupling(std::shared_ptr< ScalarLOP > &scalar_lop)
Constructs the adapter by wrapping an existing shared_ptr to the scalar operator.
Definition: blockdiagonal.hh:93
BlockDiagonalLocalOperatorFullCoupling(ScalarOperatorArgs &&... scalarOperatorArgs)
Constructs the adapter and creates a scalar operator with the given arguments.
Definition: blockdiagonal.hh:99
sparsity pattern generator
Definition: pattern.hh:14
Default flags for all local operators.
Definition: flags.hh:19
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:239
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:128
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)