DUNE PDELab (git)

gridoperator.hh
1#ifndef DUNE_PDELAB_GRIDOPERATOR_GRIDOPERATOR_HH
2#define DUNE_PDELAB_GRIDOPERATOR_GRIDOPERATOR_HH
3
4#include <tuple>
5
6#include <dune/common/hybridutilities.hh>
7
8#include <dune/pdelab/gridfunctionspace/interpolate.hh>
9#include <dune/pdelab/gridoperator/common/borderdofexchanger.hh>
10#include <dune/pdelab/gridoperator/common/gridoperatorutilities.hh>
11#include <dune/pdelab/gridoperator/default/assembler.hh>
12#include <dune/pdelab/gridoperator/default/localassembler.hh>
13
14namespace Dune{
15 namespace PDELab{
16
30 template<typename GFSU, typename GFSV, typename LOP,
31 typename MB, typename DF, typename RF, typename JF,
32 typename CU=Dune::PDELab::EmptyTransformation,
33 typename CV=Dune::PDELab::EmptyTransformation
34 >
36 {
37 public:
38
41
43 using Domain = Dune::PDELab::Backend::Vector<GFSU,DF>;
45 using Range = Dune::PDELab::Backend::Vector<GFSV,RF>;
47 using Jacobian = Dune::PDELab::Backend::Matrix<MB,Domain,Range,JF>;
48
50 typedef typename MB::template Pattern<Jacobian,GFSV,GFSU> Pattern;
51
55 LOP,
56 GFSU::Traits::EntitySet::Partitions::partitionIterator() == InteriorBorder_Partition
58
59 // Fix this as soon as the default Partitions are constexpr
60 typedef typename std::conditional<
61 GFSU::Traits::EntitySet::Partitions::partitionIterator() == InteriorBorder_Partition,
63 OverlappingBorderDOFExchanger<GridOperator>
64 >::type BorderDOFExchanger;
65
68 <GFSU,GFSV,MB,DF,RF,JF,CU,CV,Assembler,LocalAssembler> Traits;
69
70 template <typename MFT>
71 struct MatrixContainer{
72 typedef typename Traits::Jacobian Type;
73 };
74
76 GridOperator(const GFSU & gfsu_, const CU & cu_, const GFSV & gfsv_, const CV & cv_, LOP & lop_, const MB& mb_ = MB())
77 : global_assembler(gfsu_,gfsv_,cu_,cv_)
78 , dof_exchanger(std::make_shared<BorderDOFExchanger>(*this))
79 , local_assembler(lop_, cu_, cv_,dof_exchanger)
80 , backend(mb_)
81 {}
82
84 GridOperator(const GFSU & gfsu_, const GFSV & gfsv_, LOP & lop_, const MB& mb_ = MB())
85 : global_assembler(gfsu_,gfsv_)
86 , dof_exchanger(std::make_shared<BorderDOFExchanger>(*this))
87 , local_assembler(lop_,dof_exchanger)
88 , backend(mb_)
89 {}
90
92 const GFSU& trialGridFunctionSpace() const
93 {
94 return global_assembler.trialGridFunctionSpace();
95 }
96
98 const GFSV& testGridFunctionSpace() const
99 {
100 return global_assembler.testGridFunctionSpace();
101 }
102
104 typename GFSU::Traits::SizeType globalSizeU () const
105 {
106 return trialGridFunctionSpace().globalSize();
107 }
108
110 typename GFSV::Traits::SizeType globalSizeV () const
111 {
112 return testGridFunctionSpace().globalSize();
113 }
114
115 Assembler & assembler() { return global_assembler; }
116
117 const Assembler & assembler() const { return global_assembler; }
118
119 LocalAssembler & localAssembler() const { return local_assembler; }
120
121
124 template <typename GridOperatorTuple>
126 {
128 : index(0), size(std::tuple_size<GridOperatorTuple>::value) {}
129
130 template <typename T>
131 void visit(T& elem) {
132 elem.localAssembler().preProcessing(index == 0);
133 elem.localAssembler().postProcessing(index == size-1);
134 ++index;
135 }
136
137 int index;
138 const int size;
139 };
140
144 template<typename GridOperatorTuple>
145 static void setupGridOperators(GridOperatorTuple tuple)
146 {
148 Hybrid::forEach(tuple,
149 [&](auto &el) { setup_visitor.visit(el); });
150 }
151
153 template<typename F, typename X>
154 void interpolate (const X& xold, F& f, X& x) const
155 {
156 // If xold is alias of x it is rewritten by interpolate. Initial guess is then stored in tmp
157 std::optional<X> tmp;
158 const X& source = (&xold == &x) ? tmp.emplace(xold) : xold;
159
160 // Interpolate f into grid function space and set corresponding coefficients
162
163 // Copy non-constrained dofs from old time step
165 }
166
168 void fill_pattern(Pattern & p) const
169 {
170 typedef typename LocalAssembler::LocalPatternAssemblerEngine PatternEngine;
171 PatternEngine & pattern_engine = local_assembler.localPatternAssemblerEngine(p);
172 global_assembler.assemble(pattern_engine);
173 }
174
176 void residual(const Domain & x, Range & r) const
177 {
178 typedef typename LocalAssembler::LocalResidualAssemblerEngine ResidualEngine;
179 ResidualEngine & residual_engine = local_assembler.localResidualAssemblerEngine(r,x);
180 global_assembler.assemble(residual_engine);
181 }
182
184 void jacobian(const Domain & x, Jacobian & a) const
185 {
186 typedef typename LocalAssembler::LocalJacobianAssemblerEngine JacobianEngine;
187 JacobianEngine & jacobian_engine = local_assembler.localJacobianAssemblerEngine(a,x);
188 global_assembler.assemble(jacobian_engine);
189 }
190
192 void jacobian_apply(const Domain & update, Range & result) const
193 {
194 if (not local_assembler.localOperator().isLinear)
195 DUNE_THROW(Dune::Exception, "Your trying to use a non linear jacobian apply for a linear problem.");
196 global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(update, result));
197 }
198
200 void jacobian_apply(const Domain & solution, const Domain & update, Range & result) const
201 {
202 if (local_assembler.localOperator().isLinear)
203 DUNE_THROW(Dune::Exception, "Your trying to use a non linear jacobian apply for a linear problem.");
204 global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(solution, update, result));
205 }
206
208 [[deprecated("nonlinear_jacobian_apply(x,z,r) is deprecated. Please use jacobian_apply(solution, update, result) instead!")]]
209 void nonlinear_jacobian_apply(const Domain & solution, const Domain & update, Range & result) const
210 {
211 if (local_assembler.localOperator().isLinear)
212 DUNE_THROW(Dune::Exception, "Your trying to use a non linear jacobian apply for a linear problem.");
213 global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(solution, update, result));
214 }
215
216 void make_consistent(Jacobian& a) const
217 {
218 dof_exchanger->accumulateBorderEntries(*this,a);
219 }
220
221 void update()
222 {
223 // the DOF exchanger has matrix information, so we need to update it
224 dof_exchanger->update(*this);
225 }
226
228 const typename Traits::MatrixBackend& matrixBackend() const
229 {
230 return backend;
231 }
232
233 private:
234 Assembler global_assembler;
235 std::shared_ptr<BorderDOFExchanger> dof_exchanger;
236
237 mutable LocalAssembler local_assembler;
238 MB backend;
239
240 };
241
242 }
243}
244#endif // DUNE_PDELAB_GRIDOPERATOR_GRIDOPERATOR_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
The assembler for standard DUNE grid.
Definition: assembler.hh:22
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: assembler.hh:67
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: assembler.hh:73
The local assembler for DUNE grids.
Definition: localassembler.hh:35
LocalPatternAssemblerEngine & localPatternAssemblerEngine(typename Traits::MatrixPattern &p)
Definition: localassembler.hh:186
LocalJacobianApplyAssemblerEngine & localJacobianApplyAssemblerEngine(const typename Traits::Domain &update, typename Traits::Range &result)
Definition: localassembler.hh:215
LocalResidualAssemblerEngine & localResidualAssemblerEngine(typename Traits::Residual &r, const typename Traits::Solution &x)
Definition: localassembler.hh:195
LOP & localOperator()
get a reference to the local operator
Definition: localassembler.hh:100
LocalJacobianAssemblerEngine & localJacobianAssemblerEngine(typename Traits::Jacobian &a, const typename Traits::Solution &x)
Definition: localassembler.hh:205
Standard grid operator implementation.
Definition: gridoperator.hh:36
static void setupGridOperators(GridOperatorTuple tuple)
Definition: gridoperator.hh:145
GridOperator(const GFSU &gfsu_, const CU &cu_, const GFSV &gfsv_, const CV &cv_, LOP &lop_, const MB &mb_=MB())
Constructor for non trivial constraints.
Definition: gridoperator.hh:76
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: gridoperator.hh:92
GFSV::Traits::SizeType globalSizeV() const
Get dimension of space v.
Definition: gridoperator.hh:110
void nonlinear_jacobian_apply(const Domain &solution, const Domain &update, Range &result) const
Apply jacobian matrix to the vector update without explicitly assembling it.
Definition: gridoperator.hh:209
DefaultAssembler< GFSU, GFSV, CU, CV > Assembler
The global assembler type.
Definition: gridoperator.hh:40
const Traits::MatrixBackend & matrixBackend() const
Get the matrix backend for this grid operator.
Definition: gridoperator.hh:228
Dune::PDELab::Backend::Vector< GFSU, DF > Domain
The type of the domain (solution).
Definition: gridoperator.hh:43
Dune::PDELab::GridOperatorTraits< GFSU, GFSV, MB, DF, RF, JF, CU, CV, Assembler, LocalAssembler > Traits
The grid operator traits.
Definition: gridoperator.hh:68
void jacobian(const Domain &x, Jacobian &a) const
Assembler jacobian.
Definition: gridoperator.hh:184
void interpolate(const X &xold, F &f, X &x) const
Interpolate the constrained dofs from given function.
Definition: gridoperator.hh:154
MB::template Pattern< Jacobian, GFSV, GFSU > Pattern
The sparsity pattern container for the jacobian matrix.
Definition: gridoperator.hh:50
void jacobian_apply(const Domain &solution, const Domain &update, Range &result) const
Apply jacobian matrix to the vector update without explicitly assembling it.
Definition: gridoperator.hh:200
Dune::PDELab::Backend::Vector< GFSV, RF > Range
The type of the range (residual).
Definition: gridoperator.hh:45
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperator.hh:47
void fill_pattern(Pattern &p) const
Fill pattern of jacobian matrix.
Definition: gridoperator.hh:168
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: gridoperator.hh:98
void jacobian_apply(const Domain &update, Range &result) const
Apply jacobian matrix to the vector update without explicitly assembling it.
Definition: gridoperator.hh:192
GridOperator(const GFSU &gfsu_, const GFSV &gfsv_, LOP &lop_, const MB &mb_=MB())
Constructor for empty constraints.
Definition: gridoperator.hh:84
void residual(const Domain &x, Range &r) const
Assemble residual.
Definition: gridoperator.hh:176
GFSU::Traits::SizeType globalSizeU() const
Get dimension of space u.
Definition: gridoperator.hh:104
DefaultLocalAssembler< GridOperator, LOP, GFSU::Traits::EntitySet::Partitions::partitionIterator()==InteriorBorder_Partition > LocalAssembler
The local assembler type.
Definition: gridoperator.hh:57
const CU & trialConstraints() const
get the constraints on the trial grid function space
Definition: assemblerutilities.hh:233
Helper class for adding up matrix entries on border.
Definition: borderdofexchanger.hh:68
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
@ InteriorBorder_Partition
interior and border entities
Definition: gridenums.hh:138
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
void copy_nonconstrained_dofs(const CG &cg, const XG &xgin, XG &xgout)
Definition: constraints.hh:987
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:34
MB MatrixBackend
The matrix backend of the grid operator.
Definition: gridoperatorutilities.hh:51
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
Definition: gridoperator.hh:126
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)