dune-pdelab  2.7-git
fastdg.hh
Go to the documentation of this file.
1 // -*- tab-width: 2; indent-tabs-mode: nil -*-
2 // vi: set et ts=2 sw=2 sts=2:
3 #ifndef DUNE_PDELAB_GRIDOPERATOR_FASTDG_HH
4 #define DUNE_PDELAB_GRIDOPERATOR_FASTDG_HH
5 
6 #include <dune/common/tupleutility.hh>
7 
13 
14 namespace Dune {
15  namespace PDELab {
16 
29  template<typename GFSU, typename GFSV, typename LOP,
30  typename MB, typename DF, typename RF, typename JF,
34  {
35  public:
36 
39 
46 
48  typedef typename MB::template Pattern<Jacobian,GFSV,GFSU> Pattern;
49 
51  typedef FastDGLocalAssembler<
53  LOP,
54  GFSU::Traits::EntitySet::Partitions::partitionIterator() == InteriorBorder_Partition
56 
57  // Fix this as soon as the default Partitions are constexpr
58  typedef typename std::conditional<
59  GFSU::Traits::EntitySet::Partitions::partitionIterator() == InteriorBorder_Partition,
63 
66  <GFSU,GFSV,MB,DF,RF,JF,CU,CV,Assembler,LocalAssembler> Traits;
67 
68  template <typename MFT>
70  typedef typename Traits::Jacobian Type;
71  };
72 
74  FastDGGridOperator(const GFSU & gfsu_, const CU & cu_, const GFSV & gfsv_, const CV & cv_, LOP & lop_, const MB& mb_ = MB())
75  : global_assembler(gfsu_,gfsv_,cu_,cv_)
76  , dof_exchanger(std::make_shared<BorderDOFExchanger>(*this))
77  , local_assembler(lop_, cu_, cv_,dof_exchanger)
78  , backend(mb_)
79  , lop(lop_)
80  , cu(cu_)
81  , cv(cv_)
82  {}
83 
85  FastDGGridOperator(const GFSU & gfsu_, const GFSV & gfsv_, LOP & lop_, const MB& mb_ = MB())
86  : global_assembler(gfsu_,gfsv_)
87  , dof_exchanger(std::make_shared<BorderDOFExchanger>(*this))
88  , local_assembler(lop_,dof_exchanger)
89  , backend(mb_)
90  , lop(lop_)
91  , cu(*std::make_shared<Dune::PDELab::EmptyTransformation>())
92  , cv(*std::make_shared<Dune::PDELab::EmptyTransformation>())
93  {}
94 
96  const GFSU& trialGridFunctionSpace() const
97  {
98  return global_assembler.trialGridFunctionSpace();
99  }
100 
102  const GFSV& testGridFunctionSpace() const
103  {
104  return global_assembler.testGridFunctionSpace();
105  }
106 
108  {
109  return cu;
110  }
112  {
113  return cu;
114  }
115 
117  {
118  return cv;
119  }
121  {
122  return cv;
123  }
124 
126  {
127  return lop;
128  }
129 
130  const LOP & localOperator() const
131  {
132  return lop;
133  }
134 
136  typename GFSU::Traits::SizeType globalSizeU () const
137  {
138  return trialGridFunctionSpace().globalSize();
139  }
140 
142  typename GFSV::Traits::SizeType globalSizeV () const
143  {
144  return testGridFunctionSpace().globalSize();
145  }
146 
147  Assembler & assembler() { return global_assembler; }
148 
149  const Assembler & assembler() const { return global_assembler; }
150 
151  LocalAssembler & localAssembler() const { return local_assembler; }
152 
153 
156  template <typename GridOperatorTuple>
158  {
160  : index(0), size(std::tuple_size<GridOperatorTuple>::value) {}
161 
162  template <typename T>
163  void visit(T& elem) {
164  elem.localAssembler().preProcessing(index == 0);
165  elem.localAssembler().postProcessing(index == size-1);
166  ++index;
167  }
168 
169  int index;
170  const int size;
171  };
172 
176  template<typename GridOperatorTuple>
177  static void setupGridOperators(GridOperatorTuple tuple)
178  {
180  Hybrid::forEach(tuple,
181  [&](auto &el) { setup_visitor.visit(el); });
182  }
183 
185  template<typename F, typename X>
186  void interpolate (const X& xold, F& f, X& x) const
187  {
188  // Interpolate f into grid function space and set corresponding coefficients
189  Dune::PDELab::interpolate(f,global_assembler.trialGridFunctionSpace(),x);
190 
191  // Copy non-constrained dofs from old time step
193  }
194 
196  void fill_pattern(Pattern & p) const
197  {
198  typedef typename LocalAssembler::LocalPatternAssemblerEngine PatternEngine;
199  PatternEngine & pattern_engine = local_assembler.localPatternAssemblerEngine(p);
200  global_assembler.assemble(pattern_engine);
201  }
202 
204  void residual(const Domain & x, Range & r) const
205  {
206  typedef typename LocalAssembler::LocalResidualAssemblerEngine ResidualEngine;
207  ResidualEngine & residual_engine = local_assembler.localResidualAssemblerEngine(r,x);
208  global_assembler.assemble(residual_engine);
209  }
210 
212  void jacobian(const Domain & x, Jacobian & a) const
213  {
214  typedef typename LocalAssembler::LocalJacobianAssemblerEngine JacobianEngine;
215  JacobianEngine & jacobian_engine = local_assembler.localJacobianAssemblerEngine(a,x);
216  global_assembler.assemble(jacobian_engine);
217  }
218 
220  void jacobian_apply(const Domain & update, Range & result) const
221  {
222  if (not local_assembler.localOperator().isLinear)
223  DUNE_THROW(Dune::Exception, "Your trying to use a linear jacobian apply for a non linear problem.");
224  global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(update, result));
225  }
226 
228  void jacobian_apply(const Domain & solution, const Domain & update, Range & result) const
229  {
230  if (local_assembler.localOperator().isLinear)
231  DUNE_THROW(Dune::Exception, "Your trying to use a non linear jacobian apply for a linear problem.");
232  global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(solution, update, result));
233  }
234 
236  void DUNE_DEPRECATED_MSG("nonlinear_jacobian_apply(x,z,r) is deprecated. Please use jacobian_apply(solution, update, result) instead!")
237  nonlinear_jacobian_apply(const Domain & solution, const Domain & update, Range & result) const
238  {
239  if (local_assembler.localOperator().isLinear)
240  DUNE_THROW(Dune::Exception, "Your trying to use a non linear jacobian apply for a linear problem.");
241  global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(solution, update, result));
242  }
243 
244  void make_consistent(Jacobian& a) const
245  {
246  dof_exchanger->accumulateBorderEntries(*this,a);
247  }
248 
249  void update()
250  {
251  // the DOF exchanger has matrix information, so we need to update it
252  dof_exchanger->update(*this);
253  }
254 
256  const typename Traits::MatrixBackend& matrixBackend() const
257  {
258  return backend;
259  }
260 
261  private:
262  Assembler global_assembler;
263  std::shared_ptr<BorderDOFExchanger> dof_exchanger;
264 
265  mutable LocalAssembler local_assembler;
266  MB backend;
267 
268  const LOP& lop;
269  const CU& cu;
270  const CV& cv;
271 
272  }; // end class FastDGGridOperator
273  } // end namespace PDELab
274 } // end namespace Dune
275 #endif
Dune::PDELab::FastDGLocalAssembler::localJacobianApplyAssemblerEngine
LocalJacobianApplyAssemblerEngine & localJacobianApplyAssemblerEngine(const typename Traits::Domain &update, typename Traits::Range &result)
Definition: fastdg/localassembler.hh:190
Dune::PDELab::FastDGGridOperator::jacobian_apply
void jacobian_apply(const Domain &update, Range &result) const
Apply jacobian matrix to the vector update without explicitly assembling it.
Definition: fastdg.hh:220
Dune::PDELab::FastDGGridOperator::jacobian
void jacobian(const Domain &x, Jacobian &a) const
Assembler jacobian.
Definition: fastdg.hh:212
Dune::PDELab::FastDGGridOperator::assembler
const Assembler & assembler() const
Definition: fastdg.hh:149
Dune::PDELab::Backend::Vector
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:106
gridoperatorutilities.hh
p
const P & p
Definition: constraints.hh:148
Dune::PDELab::FastDGGridOperator::residual
void residual(const Domain &x, Range &r) const
Assemble residual.
Definition: fastdg.hh:204
Dune::PDELab::FastDGGridOperator::setupGridOperators
static void setupGridOperators(GridOperatorTuple tuple)
Definition: fastdg.hh:177
Dune::PDELab::FastDGGridOperator::MatrixContainer
Definition: fastdg.hh:69
Dune::PDELab::FastDGLocalPatternAssemblerEngine< FastDGLocalAssembler >
Dune::PDELab::copy_nonconstrained_dofs
void copy_nonconstrained_dofs(const CG &cg, const XG &xgin, XG &xgout)
Definition: constraints.hh:987
Dune::PDELab::FastDGGridOperator::result
void const Domain Range &const result
Definition: fastdg.hh:238
borderdofexchanger.hh
Dune::PDELab::FastDGGridOperator::Domain
Dune::PDELab::Backend::Vector< GFSU, DF > Domain
The type of the domain (solution).
Definition: fastdg.hh:41
Dune::PDELab::FastDGGridOperator::Jacobian
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: fastdg.hh:45
Dune::PDELab::GridOperatorTraits::MatrixBackend
MB MatrixBackend
The matrix backend of the grid operator.
Definition: gridoperatorutilities.hh:51
Dune::PDELab::FastDGLocalJacobianAssemblerEngine< FastDGLocalAssembler >
Dune::PDELab::FastDGGridOperator::make_consistent
void make_consistent(Jacobian &a) const
Definition: fastdg.hh:244
Dune::PDELab::FastDGGridOperator::trialGridFunctionSpaceConstraints
CU & trialGridFunctionSpaceConstraints()
Definition: fastdg.hh:107
Dune::PDELab::FastDGGridOperator::testGridFunctionSpaceConstraints
const CV & testGridFunctionSpaceConstraints() const
Definition: fastdg.hh:120
Dune::PDELab::FastDGGridOperator::DUNE_DEPRECATED_MSG
void DUNE_DEPRECATED_MSG("nonlinear_jacobian_apply(x,z,r) is deprecated. Please use jacobian_apply(solution, update, result) instead!") nonlinear_jacobian_apply(const Domain &solution
Apply jacobian matrix to the vector update without explicitly assembling it.
Dune::PDELab::FastDGGridOperator::testGridFunctionSpaceConstraints
CV & testGridFunctionSpaceConstraints()
Definition: fastdg.hh:116
localassembler.hh
Dune::PDELab::FastDGGridOperator
Definition: fastdg.hh:33
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::FastDGGridOperator::matrixBackend
const Traits::MatrixBackend & matrixBackend() const
Get the matrix backend for this grid operator.
Definition: fastdg.hh:256
Dune::PDELab::GridOperatorTraits
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:33
Dune::PDELab::FastDGLocalAssembler::localJacobianAssemblerEngine
LocalJacobianAssemblerEngine & localJacobianAssemblerEngine(typename Traits::Jacobian &a, const typename Traits::Solution &x)
Definition: fastdg/localassembler.hh:180
Dune::PDELab::FastDGGridOperator::trialGridFunctionSpace
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: fastdg.hh:96
Dune::PDELab::FastDGLocalAssembler::localResidualAssemblerEngine
LocalResidualAssemblerEngine & localResidualAssemblerEngine(typename Traits::Residual &r, const typename Traits::Solution &x)
Definition: fastdg/localassembler.hh:170
Dune::PDELab::FastDGAssembler::trialGridFunctionSpace
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: fastdg/assembler.hh:70
Dune::PDELab::FastDGGridOperator::localAssembler
LocalAssembler & localAssembler() const
Definition: fastdg.hh:151
value
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Dune::PDELab::FastDGGridOperator::SetupGridOperator::size
const int size
Definition: fastdg.hh:170
Dune::PDELab::FastDGLocalAssembler::localOperator
LOP & localOperator()
get a reference to the local operator
Definition: fastdg/localassembler.hh:111
Dune::PDELab::GridOperatorTraits::Jacobian
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
Dune::PDELab::FastDGGridOperator::update
void update()
Definition: fastdg.hh:249
Dune::PDELab::LocalAssemblerBase::trialConstraints
const CU & trialConstraints() const
get the constraints on the trial grid function space
Definition: assemblerutilities.hh:205
Dune::PDELab::FastDGGridOperator::testGridFunctionSpace
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: fastdg.hh:102
Dune::PDELab::FastDGGridOperator::BorderDOFExchanger
std::conditional< GFSU::Traits::EntitySet::Partitions::partitionIterator()==InteriorBorder_Partition, NonOverlappingBorderDOFExchanger< FastDGGridOperator >, OverlappingBorderDOFExchanger< FastDGGridOperator > >::type BorderDOFExchanger
Definition: fastdg.hh:62
Dune::PDELab::FastDGGridOperator::update
void const Domain & update
Definition: fastdg.hh:237
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::FastDGGridOperator::globalSizeU
GFSU::Traits::SizeType globalSizeU() const
Get dimension of space u.
Definition: fastdg.hh:136
Dune::PDELab::FastDGGridOperator::Assembler
FastDGAssembler< GFSU, GFSV, CU, CV > Assembler
The global assembler type.
Definition: fastdg.hh:38
Dune::PDELab::Backend::Matrix
typename impl::BackendMatrixSelector< Backend, VU, VV, E >::Type Matrix
alias of the return type of BackendMatrixSelector
Definition: backend/interface.hh:127
Dune::PDELab::FastDGGridOperator::jacobian_apply
void jacobian_apply(const Domain &solution, const Domain &update, Range &result) const
Apply jacobian matrix to the vector update without explicitly assembling it.
Definition: fastdg.hh:228
Dune::PDELab::FastDGGridOperator::FastDGGridOperator
FastDGGridOperator(const GFSU &gfsu_, const GFSV &gfsv_, LOP &lop_, const MB &mb_=MB())
Constructor for empty constraints.
Definition: fastdg.hh:85
Dune::PDELab::FastDGAssembler::testGridFunctionSpace
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: fastdg/assembler.hh:76
Dune::PDELab::FastDGGridOperator::interpolate
void interpolate(const X &xold, F &f, X &x) const
Interpolate the constrained dofs from given function.
Definition: fastdg.hh:186
Dune::PDELab::FastDGGridOperator::localOperator
LOP & localOperator()
Definition: fastdg.hh:125
Dune::PDELab::FastDGGridOperator::SetupGridOperator
Definition: fastdg.hh:157
interpolate.hh
Dune::PDELab::FastDGGridOperator::localOperator
const LOP & localOperator() const
Definition: fastdg.hh:130
Dune::PDELab::FastDGGridOperator::trialGridFunctionSpaceConstraints
const CU & trialGridFunctionSpaceConstraints() const
Definition: fastdg.hh:111
Dune::PDELab::EmptyTransformation
Definition: constraintstransformation.hh:111
Dune::PDELab::FastDGAssembler::assemble
void assemble(LocalAssemblerEngine &assembler_engine) const
Definition: fastdg/assembler.hh:88
Dune::PDELab::FastDGLocalAssembler
The local assembler for DUNE grids.
Definition: fastdg/localassembler.hh:37
Dune::PDELab::OverlappingBorderDOFExchanger
Definition: borderdofexchanger.hh:577
Dune::PDELab::FastDGGridOperator::SetupGridOperator::SetupGridOperator
SetupGridOperator()
Definition: fastdg.hh:159
Dune::PDELab::FastDGGridOperator::SetupGridOperator::visit
void visit(T &elem)
Definition: fastdg.hh:163
Dune::PDELab::FastDGGridOperator::Range
Dune::PDELab::Backend::Vector< GFSV, RF > Range
The type of the range (residual).
Definition: fastdg.hh:43
Dune::PDELab::NonOverlappingBorderDOFExchanger
Helper class for adding up matrix entries on border.
Definition: borderdofexchanger.hh:67
Dune::PDELab::FastDGLocalResidualAssemblerEngine< FastDGLocalAssembler >
Dune::PDELab::FastDGGridOperator::globalSizeV
GFSV::Traits::SizeType globalSizeV() const
Get dimension of space v.
Definition: fastdg.hh:142
Dune::PDELab::FastDGGridOperator::Pattern
MB::template Pattern< Jacobian, GFSV, GFSU > Pattern
The sparsity pattern container for the jacobian matrix.
Definition: fastdg.hh:48
Dune::PDELab::FastDGGridOperator::LocalAssembler
FastDGLocalAssembler< FastDGGridOperator, LOP, GFSU::Traits::EntitySet::Partitions::partitionIterator()==InteriorBorder_Partition > LocalAssembler
The local assembler type.
Definition: fastdg.hh:55
Dune::PDELab::FastDGGridOperator::assembler
Assembler & assembler()
Definition: fastdg.hh:147
Dune::PDELab::FastDGGridOperator::FastDGGridOperator
FastDGGridOperator(const GFSU &gfsu_, const CU &cu_, const GFSV &gfsv_, const CV &cv_, LOP &lop_, const MB &mb_=MB())
Constructor for non trivial constraints.
Definition: fastdg.hh:74
Dune::PDELab::FastDGAssembler
The fast DG assembler for standard DUNE grid.
Definition: fastdg/assembler.hh:25
assembler.hh
Dune::PDELab::FastDGGridOperator::SetupGridOperator::index
int index
Definition: fastdg.hh:169
Dune::PDELab::FastDGGridOperator::fill_pattern
void fill_pattern(Pattern &p) const
Fill pattern of jacobian matrix.
Definition: fastdg.hh:196
Dune::PDELab::FastDGGridOperator::Traits
Dune::PDELab::GridOperatorTraits< GFSU, GFSV, MB, DF, RF, JF, CU, CV, Assembler, LocalAssembler > Traits
The grid operator traits.
Definition: fastdg.hh:66
Dune::PDELab::FastDGLocalAssembler::localPatternAssemblerEngine
LocalPatternAssemblerEngine & localPatternAssemblerEngine(typename Traits::MatrixPattern &p)
Definition: fastdg/localassembler.hh:161
Dune::PDELab::FastDGGridOperator::MatrixContainer::Type
Traits::Jacobian Type
Definition: fastdg.hh:70