4 #ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_ASSEMBLERUTILITIES_HH 5 #define DUNE_PDELAB_GRIDOPERATOR_COMMON_ASSEMBLERUTILITIES_HH 61 typedef typename GO::Traits::Jacobian
Jacobian;
64 typedef typename MatrixBackend::template Pattern<
67 TrialGridFunctionSpace
100 :
std::tuple<int,int>(i,j)
104 inline int i ()
const 106 return std::get<0>(*this);
110 inline int j ()
const 112 return std::get<1>(*this);
116 void set (
int i,
int j)
118 std::get<0>(*this) = i;
119 std::get<1>(*this) = j;
130 :
public std::vector<SparsityLink>
134 using std::vector<SparsityLink>::push_back;
148 template<
typename LFSV,
typename LFSU>
149 void addLink(
const LFSV& lfsv, std::size_t i,
const LFSU& lfsu, std::size_t j)
151 std::vector<SparsityLink>::push_back(
190 : pconstraintsu(&emptyconstraintsu), pconstraintsv(&emptyconstraintsv)
195 :pconstraintsu(&cu), pconstraintsv(&cv)
201 return *pconstraintsu;
207 return *pconstraintsv;
217 typename std::enable_if<
225 typedef typename CV::const_iterator global_col_iterator;
226 for (global_col_iterator cit=pconstraintsv->begin(); cit!=pconstraintsv->end(); ++cit){
227 typedef typename global_col_iterator::value_type::first_type GlobalIndex;
228 const GlobalIndex & contributor = cit->first;
230 typedef typename global_col_iterator::value_type::second_type ContributedMap;
231 typedef typename ContributedMap::const_iterator global_row_iterator;
232 const ContributedMap & contributed = cit->second;
233 global_row_iterator it = contributed.begin();
234 global_row_iterator eit = contributed.end();
241 x[it->first] += it->second * x[contributor];
246 for (global_col_iterator cit=pconstraintsv->begin(); cit!=pconstraintsv->end(); ++cit)
253 typename std::enable_if<
268 typename std::enable_if<
276 typedef typename CV::const_iterator global_col_iterator;
277 for (global_col_iterator cit=pconstraintsv->begin(); cit!=pconstraintsv->end(); ++cit){
278 typedef typename global_col_iterator::value_type::first_type GlobalIndex;
279 const GlobalIndex & contributor = cit->first;
281 typedef typename global_col_iterator::value_type::second_type ContributedMap;
282 typedef typename ContributedMap::const_iterator global_row_iterator;
283 const ContributedMap & contributed = cit->second;
284 global_row_iterator it = contributed.begin();
285 global_row_iterator eit = contributed.end();
295 x[contributor] += it->second * x[it->first];
302 typename std::enable_if<
315 template<
typename GCView,
typename T>
318 for (
int i = 0; i < localcontainer.N(); ++i)
319 for (
int j = 0; j < localcontainer.M(); ++j)
320 localcontainer(i,j) = globalcontainer_view(i,j);
324 template<
typename T,
typename GCView>
327 for (
int i = 0; i < localcontainer.N(); ++i)
328 for (
int j = 0; j < localcontainer.M(); ++j)
329 globalcontainer_view(i,j) = localcontainer(i,j);
333 template<
typename T,
typename GCView>
336 for (
int i = 0; i < localcontainer.N(); ++i)
337 for (
int j = 0; j < localcontainer.M(); ++j)
338 globalcontainer_view.add(i,j,localcontainer(i,j));
342 template<
typename M,
typename GCView>
343 typename std::enable_if<
349 scatter_jacobian(M& local_container, GCView& global_container_view,
bool symmetric_mode)
const 351 typedef typename GCView::RowIndexCache LFSVIndexCache;
352 typedef typename GCView::ColIndexCache LFSUIndexCache;
354 const LFSVIndexCache& lfsv_indices = global_container_view.rowIndexCache();
355 const LFSUIndexCache& lfsu_indices = global_container_view.colIndexCache();
357 if (lfsv_indices.constraintsCachingEnabled() && lfsu_indices.constraintsCachingEnabled())
359 etadd_symmetric(local_container,global_container_view);
361 etadd(local_container,global_container_view);
365 typedef typename LFSVIndexCache::LocalFunctionSpace LFSV;
366 const LFSV& lfsv = lfsv_indices.localFunctionSpace();
368 typedef typename LFSUIndexCache::LocalFunctionSpace LFSU;
369 const LFSU& lfsu = lfsu_indices.localFunctionSpace();
374 typedef typename LFSUIndexCache::ContainerIndex CI;
376 for (
size_t j = 0; j < lfsu_indices.size(); ++j)
378 const CI& container_index = lfsu_indices.containerIndex(j);
379 const typename CU::const_iterator cit = pconstraintsu->find(container_index);
380 if (cit != pconstraintsu->end())
383 assert(cit->second.empty());
385 for (
size_t i = 0; i < lfsv_indices.size(); ++i)
389 local_container(lfsv,i,lfsu,j) = 0.0;
397 for (
auto it = local_container.begin(); it != local_container.end(); ++it)
402 global_container_view.add(it.row(),it.col(),*it);
408 template<
typename M,
typename GCView>
409 typename std::enable_if<
415 scatter_jacobian(M& local_container, GCView& global_container_view,
bool symmetric_mode)
const 419 for (
auto it = local_container.begin(); it != local_container.end(); ++it)
424 global_container_view.add(it.row(),it.col(),*it);
431 template<
typename M,
typename GCView>
435 typedef typename GCView::RowIndexCache LFSVIndexCache;
436 typedef typename GCView::ColIndexCache LFSUIndexCache;
438 const LFSVIndexCache& lfsv_indices = globalcontainer_view.rowIndexCache();
439 const LFSUIndexCache& lfsu_indices = globalcontainer_view.colIndexCache();
441 typedef typename LFSVIndexCache::LocalFunctionSpace LFSV;
442 const LFSV& lfsv = lfsv_indices.localFunctionSpace();
444 typedef typename LFSUIndexCache::LocalFunctionSpace LFSU;
445 const LFSU& lfsu = lfsu_indices.localFunctionSpace();
447 for (
size_t j = 0; j < lfsu_indices.size(); ++j)
449 if (lfsu_indices.isConstrained(j) && lfsu_indices.isDirichletConstraint(j))
452 for (
size_t i = 0; i < lfsv_indices.size(); ++i)
456 localcontainer(lfsv,i,lfsu,j) = 0.0;
462 etadd(localcontainer,globalcontainer_view);
466 template<
typename M,
typename GCView>
467 void etadd (
const M& localcontainer, GCView& globalcontainer_view)
const 470 typedef typename M::value_type T;
472 typedef typename GCView::RowIndexCache LFSVIndexCache;
473 typedef typename GCView::ColIndexCache LFSUIndexCache;
475 const LFSVIndexCache& lfsv_indices = globalcontainer_view.rowIndexCache();
476 const LFSUIndexCache& lfsu_indices = globalcontainer_view.colIndexCache();
478 typedef typename LFSVIndexCache::LocalFunctionSpace LFSV;
479 const LFSV& lfsv = lfsv_indices.localFunctionSpace();
481 typedef typename LFSUIndexCache::LocalFunctionSpace LFSU;
482 const LFSU& lfsu = lfsu_indices.localFunctionSpace();
484 for (
size_t i = 0; i<lfsv_indices.size(); ++i)
485 for (
size_t j = 0; j<lfsu_indices.size(); ++j)
488 if (localcontainer(lfsv,i,lfsu,j) == 0.0)
491 const bool constrained_v = lfsv_indices.isConstrained(i);
492 const bool constrained_u = lfsu_indices.isConstrained(j);
494 typedef typename LFSVIndexCache::ConstraintsIterator VConstraintsIterator;
495 typedef typename LFSUIndexCache::ConstraintsIterator UConstraintsIterator;
499 if (lfsv_indices.isDirichletConstraint(i))
502 for (VConstraintsIterator vcit = lfsv_indices.constraintsBegin(i); vcit != lfsv_indices.constraintsEnd(i); ++vcit)
505 if (lfsu_indices.isDirichletConstraint(j))
507 T
value = localcontainer(lfsv,i,lfsu,j) * vcit->weight();
509 globalcontainer_view.add(vcit->containerIndex(),j,
value);
513 for (UConstraintsIterator ucit = lfsu_indices.constraintsBegin(j); ucit != lfsu_indices.constraintsEnd(j); ++ucit)
515 T
value = localcontainer(lfsv,i,lfsu,j) * vcit->weight() * ucit->weight();
517 globalcontainer_view.add(vcit->containerIndex(),ucit->containerIndex(),
value);
523 T
value = localcontainer(lfsv,i,lfsu,j) * vcit->weight();
525 globalcontainer_view.add(vcit->containerIndex(),j,
value);
532 if (lfsu_indices.isDirichletConstraint(j))
534 T
value = localcontainer(lfsv,i,lfsu,j);
536 globalcontainer_view.add(i,j,value);
540 for (UConstraintsIterator ucit = lfsu_indices.constraintsBegin(j); ucit != lfsu_indices.constraintsEnd(j); ++ucit)
542 T
value = localcontainer(lfsv,i,lfsu,j) * ucit->weight();
544 globalcontainer_view.add(i,ucit->containerIndex(),
value);
549 globalcontainer_view.add(i,j,localcontainer(lfsv,i,lfsu,j));
555 template<
typename Pattern,
typename RI,
typename CI>
556 typename std::enable_if<
562 pattern.add_link(ri,ci);
565 template<
typename Pattern,
typename RI,
typename CI>
566 typename std::enable_if<
576 template<
typename P,
typename LFSVIndices,
typename LFSUIndices,
typename Index>
578 const LFSVIndices& lfsv_indices, Index i,
579 const LFSUIndices& lfsu_indices, Index j)
const 581 typedef typename LFSVIndices::ConstraintsIterator VConstraintsIterator;
582 typedef typename LFSUIndices::ConstraintsIterator UConstraintsIterator;
584 const bool constrained_v = lfsv_indices.isConstrained(i);
585 const bool constrained_u = lfsu_indices.isConstrained(j);
587 add_diagonal_entry(globalpattern,
588 lfsv_indices.containerIndex(i),
589 lfsu_indices.containerIndex(j)
594 if (!constrained_u || lfsu_indices.isDirichletConstraint(j))
596 globalpattern.add_link(lfsv_indices.containerIndex(i),lfsu_indices.containerIndex(j));
600 for (UConstraintsIterator gurit = lfsu_indices.constraintsBegin(j); gurit != lfsu_indices.constraintsEnd(j); ++gurit)
601 globalpattern.add_link(lfsv_indices.containerIndex(i),gurit->containerIndex());
606 if (lfsv_indices.isDirichletConstraint(i))
608 globalpattern.add_link(lfsv_indices.containerIndex(i),lfsu_indices.containerIndex(j));
612 for(VConstraintsIterator gvrit = lfsv_indices.constraintsBegin(i); gvrit != lfsv_indices.constraintsEnd(i); ++gvrit)
614 if (!constrained_u || lfsu_indices.isDirichletConstraint(j))
616 globalpattern.add_link(gvrit->containerIndex(),lfsu_indices.containerIndex(j));
620 for (UConstraintsIterator gurit = lfsu_indices.constraintsBegin(j); gurit != lfsu_indices.constraintsEnd(j); ++gurit)
621 globalpattern.add_link(gvrit->containerIndex(),gurit->containerIndex());
631 template<
typename GFSV,
typename GC,
typename C>
634 typedef typename C::const_iterator global_row_iterator;
635 for (global_row_iterator cit = c.begin(); cit != c.end(); ++cit)
636 globalcontainer.clear_row(cit->first,1);
639 template<
typename GFSV,
typename GC>
644 template<
typename GFSV,
typename GC>
647 globalcontainer.flush();
648 set_trivial_rows(gfsv,globalcontainer,*pconstraintsv);
649 globalcontainer.finalize();
659 template<
typename B,
typename CU,
typename CV>
661 template<
typename B,
typename CU,
typename CV>
667 #endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_ASSEMBLERUTILITIES_HH B::size_type SizeType
Definition: assemblerutilities.hh:186
std::enable_if< AlwaysTrue< M >::value &&std::is_same< CV, EmptyTransformation >::value >::type scatter_jacobian(M &local_container, GCView &global_container_view, bool symmetric_mode) const
Definition: assemblerutilities.hh:415
void set_trivial_rows(const GFSV &gfsv, GC &globalcontainer, const EmptyTransformation &c) const
Definition: assemblerutilities.hh:640
Entry in sparsity pattern.
Definition: assemblerutilities.hh:91
void etadd(const M &localcontainer, GCView &globalcontainer_view) const
Definition: assemblerutilities.hh:467
std::enable_if< !std::is_same< RI, CI >::value >::type add_diagonal_entry(Pattern &pattern, const RI &ri, const CI &ci) const
Definition: assemblerutilities.hh:569
const CU * pconstraintsu
Definition: assemblerutilities.hh:653
SparsityLink()
Standard constructor for uninitialized local index.
Definition: assemblerutilities.hh:95
GO::Traits::Range Residual
The type of the range (residual).
Definition: assemblerutilities.hh:54
GO::Traits::TrialGridFunctionSpaceConstraints TrialGridFunctionSpaceConstraints
The type of the trial grid function space constraints.
Definition: assemblerutilities.hh:33
Definition: constraintstransformation.hh:111
Base class for local assembler.
Definition: assemblerutilities.hh:182
Definition: assemblerutilities.hh:22
GO::Traits::Jacobian Jacobian
The type of the jacobian.
Definition: assemblerutilities.hh:61
GO::Traits::RangeField RangeField
The field type of the range (residual).
Definition: assemblerutilities.hh:51
const CV * pconstraintsv
Definition: assemblerutilities.hh:654
void ewrite(const LocalMatrix< T > &localcontainer, GCView &globalcontainer_view) const
write local stiffness matrix for entity
Definition: assemblerutilities.hh:325
GO::Traits::TrialGridFunctionSpace TrialGridFunctionSpace
The trial grid function space.
Definition: assemblerutilities.hh:26
LocalAssemblerBase(const CU &cu, const CV &cv)
construct AssemblerSpace, with constraints
Definition: assemblerutilities.hh:194
MatrixBackend::template Pattern< Jacobian, TestGridFunctionSpace, TrialGridFunctionSpace > MatrixPattern
The matrix pattern.
Definition: assemblerutilities.hh:68
std::enable_if< AlwaysTrue< X >::value &&!std::is_same< CV, EmptyTransformation >::value >::type forwardtransform(X &x, const bool postrestrict=false) const
Transforms a vector from to . If postrestrict == true then is applied instead of the full transfor...
Definition: assemblerutilities.hh:223
std::enable_if< AlwaysTrue< X >::value &&std::is_same< CV, EmptyTransformation >::value >::type forwardtransform(X &x, const bool postrestrict=false) const
Definition: assemblerutilities.hh:259
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
const CV & testConstraints() const
get the constraints on the test grid function space
Definition: assemblerutilities.hh:205
GO::Traits::TestGridFunctionSpace TestGridFunctionSpace
The test grid function space.
Definition: assemblerutilities.hh:29
LocalAssemblerBase()
construct AssemblerSpace
Definition: assemblerutilities.hh:189
GO::Traits::DomainField DomainField
The field type of the domain (solution).
Definition: assemblerutilities.hh:44
void etadd_symmetric(M &localcontainer, GCView &globalcontainer_view) const
Add local matrix to global matrix, and apply Dirichlet constraints in a symmetric fashion...
Definition: assemblerutilities.hh:432
GO::Traits::TestGridFunctionSpaceConstraints TestGridFunctionSpaceConstraints
The type of the test grid function space constraints.
Definition: assemblerutilities.hh:36
void handle_dirichlet_constraints(const GFSV &gfsv, GC &globalcontainer) const
Definition: assemblerutilities.hh:645
const CU & trialConstraints() const
get the constraints on the trial grid function space
Definition: assemblerutilities.hh:199
GO::Traits::MatrixBackend MatrixBackend
The matrix backend of the grid operator.
Definition: assemblerutilities.hh:40
void set_trivial_rows(const GFSV &gfsv, GC &globalcontainer, const C &c) const
insert dirichlet constraints for row and assemble T^T_U in constrained rows
Definition: assemblerutilities.hh:632
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
SparsityLink(int i, int j)
Initialize all components.
Definition: assemblerutilities.hh:99
int j() const
Return second component.
Definition: assemblerutilities.hh:110
int i() const
Return first component.
Definition: assemblerutilities.hh:104
void addLink(const LFSV &lfsv, std::size_t i, const LFSU &lfsu, std::size_t j)
Adds a link between DOF i of lfsv and DOF j of lfsu.
Definition: assemblerutilities.hh:149
GO::BorderDOFExchanger BorderDOFExchanger
The helper class to exchange data on the processor boundary.
Definition: assemblerutilities.hh:71
GO::Traits::JacobianField JacobianField
The field type of the jacobian.
Definition: assemblerutilities.hh:58
GO::Traits::Domain Solution
The type of the domain (solution).
Definition: assemblerutilities.hh:47
std::enable_if< AlwaysTrue< X >::value &&!std::is_same< CV, EmptyTransformation >::value >::type backtransform(X &x, const bool prerestrict=false) const
Transforms a vector from to . If prerestrict == true then is applied instead of the full transform...
Definition: assemblerutilities.hh:274
void eadd(const LocalMatrix< T > &localcontainer, GCView &globalcontainer_view) const
write local stiffness matrix for entity
Definition: assemblerutilities.hh:334
std::enable_if< std::is_same< RI, CI >::value >::type add_diagonal_entry(Pattern &pattern, const RI &ri, const CI &ci) const
Definition: assemblerutilities.hh:559
std::enable_if< AlwaysTrue< M >::value &&!std::is_same< CV, EmptyTransformation >::value >::type scatter_jacobian(M &local_container, GCView &global_container_view, bool symmetric_mode) const
Scatter local jacobian to global container.
Definition: assemblerutilities.hh:349
void add_entry(P &globalpattern, const LFSVIndices &lfsv_indices, Index i, const LFSUIndices &lfsu_indices, Index j) const
Adding matrix entry to pattern with respect to the constraints contributions. This assembles the entr...
Definition: assemblerutilities.hh:577
Layout description for a sparse linear operator.
Definition: assemblerutilities.hh:129
std::enable_if< AlwaysTrue< X >::value &&std::is_same< CV, EmptyTransformation >::value >::type backtransform(X &x, const bool prerestrict=false) const
Definition: assemblerutilities.hh:308
A dense matrix for storing data associated with the degrees of freedom of a pair of LocalFunctionSpac...
Definition: localmatrix.hh:184
static CU emptyconstraintsu
Definition: assemblerutilities.hh:655
void eread(const GCView &globalcontainer_view, LocalMatrix< T > &localcontainer) const
read local stiffness matrix for entity
Definition: assemblerutilities.hh:316
static CV emptyconstraintsv
Definition: assemblerutilities.hh:656