dune-pdelab  2.7-git
blockdiagonal.hh
Go to the documentation of this file.
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 
13 
14 namespace 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 
140  {
141  _scalar_lop->setTime(t);
142  }
143 
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 
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
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::doPatternVolume
static constexpr bool doPatternVolume
Definition: blockdiagonal.hh:84
Dune::PDELab::LocalOperatorDefaultFlags
Default flags for all local operators.
Definition: flags.hh:18
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::jacobian_apply_volume
void jacobian_apply_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, Y &y) const
Definition: blockdiagonal.hh:116
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::doAlphaVolume
static constexpr bool doAlphaVolume
Definition: blockdiagonal.hh:85
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::getStage
int getStage() const
Definition: blockdiagonal.hh:164
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::alpha_volume
void alpha_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, R &r) const
Definition: blockdiagonal.hh:104
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::postStage
void postStage()
Definition: blockdiagonal.hh:169
pattern.hh
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling
Block diagonal extension of scalar local operator.
Definition: blockdiagonal.hh:75
Dune::PDELab::FullVolumePattern
sparsity pattern generator
Definition: pattern.hh:13
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::preStage
void preStage(RealType time, int r)
Definition: blockdiagonal.hh:159
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::BlockDiagonalLocalOperatorFullCoupling
BlockDiagonalLocalOperatorFullCoupling(std::shared_ptr< ScalarLOP > &scalar_lop)
Constructs the adapter by wrapping an existing shared_ptr to the scalar operator.
Definition: blockdiagonal.hh:93
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::setTime
void setTime(RealType t)
Definition: blockdiagonal.hh:139
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::BlockDiagonalLocalOperatorFullCoupling
BlockDiagonalLocalOperatorFullCoupling(ScalarOperatorArgs &&... scalarOperatorArgs)
Constructs the adapter and creates a scalar operator with the given arguments.
Definition: blockdiagonal.hh:99
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::jacobian_volume
void jacobian_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, M &mat) const
Definition: blockdiagonal.hh:128
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling< impl::ScalarL2 >::RealType
typename impl::ScalarL2 ::RealType RealType
Definition: blockdiagonal.hh:82
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::preStep
void preStep(RealType time, RealType dt, int stages)
Definition: blockdiagonal.hh:149
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::BlockDiagonalLocalOperatorFullCoupling
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
flags.hh
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::postStep
void postStep()
Definition: blockdiagonal.hh:154
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::suggestTimestep
RealType suggestTimestep(RealType dt) const
Definition: blockdiagonal.hh:174
Dune::PDELab::BlockDiagonalLocalOperatorFullCoupling::getTime
RealType getTime() const
Definition: blockdiagonal.hh:144