1#ifndef DUNE_FEM_STENCIL_HH
2#define DUNE_FEM_STENCIL_HH
9#include <unordered_map>
11#include <dune/grid/common/gridenums.hh>
12#include <dune/grid/common/rangegenerators.hh>
33 template <
class DomainSpace,
class RangeSpace>
37 typedef typename DomainSpace::IteratorType DomainIteratorType;
38 typedef typename DomainSpace::BlockMapperType DomainBlockMapper;
41 typedef typename RangeSpace::IteratorType RangeIteratorType;
42 typedef typename RangeSpace::BlockMapperType RangeBlockMapper;
54 typedef typename std::vector< std::size_t > :: size_type
IndexType;
56 static const bool indexIsSimple = std::is_convertible< RangeGlobalKeyType, IndexType >::value;
59 std::unordered_map< RangeGlobalKeyType, LocalStencilType >,
69 Stencil(
const DomainSpace &dSpace,
const RangeSpace &rSpace)
93 bool fillGhost=
true )
const
95 if( (dEntity.partitionType() == GhostEntity) && !fillGhost )
98 rangeBlockMapper_.mapEach( rEntity, [
this, &dEntity ] (
int localRow,
auto globalRow ) {
127 maxNZ =
std::max( maxNZ,
static_cast<int>( entry.second.size() ) );
143 [[deprecated(
"Use Stencil::update instead()")]]
153 struct RowFillFunctor
161 localStencil_.insert( domainGlobal );
184 template <
class DomainSpace,
class RangeSpace>
209 DUNE_THROW( Dune::NotImplemented,
"SimpleStencil: exact stencil information is unavailable." );
214 DUNE_THROW( Dune::NotImplemented,
"SimpleStencil: global stencil is unavailable." );
231 template <
class DomainSpace,
class RangeSpace,
class LocalStencil>
249 typedef std::pair< DomainGlobalKeyType, const LocalStencilType& >
ItemType;
310 bool fillGhost=
true )
328 maxNZ =
std::max( maxNZ,
int(row.size()) );
346 template <
class DomainSpace,
class RangeSpace,
class Partition = Dune::Partitions::InteriorBorder>
369 for (
const auto& entity : elements( dSpace.gridPart(),
PartitionType{} ) )
383 template <
class DomainSpace,
class RangeSpace,
class Partition = Dune::Partitions::InteriorBorder>
397 bool onlyNonContinuousNeighbors =
false)
409 for (
const auto & entity: elements( dSpace.gridPart(),
PartitionType{} ) )
412 for (
const auto & intersection: intersections(dSpace.gridPart(), entity) )
415 && rSpace.continuous(intersection) && dSpace.continuous(intersection) )
417 if( intersection.neighbor() )
419 auto neighbor = intersection.outside();
double max(const Dune::Fem::Double &v, const double p)
Definition: double.hh:965
Definition: bindguard.hh:11
Definition: utility.hh:162
default implementation for a general operator stencil
Definition: stencil.hh:35
const DomainSpace & domainSpace_
Definition: stencil.hh:169
static const bool indexIsSimple
Definition: stencil.hh:56
const RangeBlockMapper & rangeBlockMapper_
Definition: stencil.hh:172
GlobalStencilType globalStencil_
Definition: stencil.hh:174
int rows() const
Definition: stencil.hh:132
RangeIteratorType::Entity RangeEntityType
Definition: stencil.hh:46
void update()
clear previously computed entries such that a re-compute happens when used again
Definition: stencil.hh:136
DomainBlockMapper::GlobalKeyType DomainGlobalKeyType
Definition: stencil.hh:47
const RangeSpace & rangeSpace_
Definition: stencil.hh:170
void setup()
Definition: stencil.hh:144
const RangeSpace & rangeSpace() const
Definition: stencil.hh:80
virtual void setupStencil() const =0
method to setup stencil depending on entity set defined in derived class
RangeBlockMapper::GlobalKeyType RangeGlobalKeyType
Definition: stencil.hh:48
const DomainSpace & domainSpace() const
Definition: stencil.hh:76
const GlobalStencilType & globalStencil() const
Return the full stencil.
Definition: stencil.hh:115
DomainIteratorType::Entity DomainEntityType
Definition: stencil.hh:45
std::set< DomainGlobalKeyType > LocalStencilType
type for storing the stencil of one row
Definition: stencil.hh:51
void fill(const DomainEntityType &dEntity, const RangeEntityType &rEntity, bool fillGhost=true) const
Create stencil entries for (dEntity,rEntity) pair.
Definition: stencil.hh:92
std::vector< std::size_t >::size_type IndexType
type of std::vector for indexing
Definition: stencil.hh:54
std::conditional< indexIsSimple, std::unordered_map< RangeGlobalKeyType, LocalStencilType >, std::map< RangeGlobalKeyType, LocalStencilType > >::type GlobalStencilType
Definition: stencil.hh:60
int maxNonZerosEstimate() const
Return an upper bound for the maximum number of non-zero entries in all rows.
Definition: stencil.hh:122
Stencil(const DomainSpace &dSpace, const RangeSpace &rSpace)
Constructor.
Definition: stencil.hh:69
const LocalStencilType & localStencil(const RangeGlobalKeyType &key) const
Return stencil for a given row of the matrix.
Definition: stencil.hh:108
const DomainBlockMapper & domainBlockMapper_
Definition: stencil.hh:171
int cols() const
Definition: stencil.hh:133
a watered down stencil providing only the upper bound for the non-zero entries per row.
Definition: stencil.hh:186
StencilType::RangeGlobalKeyType RangeGlobalKeyType
Definition: stencil.hh:192
int maxNZ_
Definition: stencil.hh:218
StencilType::RangeEntityType RangeEntityType
Definition: stencil.hh:190
LocalStencilType localStencil_
Definition: stencil.hh:220
const LocalStencilType & localStencil(const DomainGlobalKeyType &key) const
Definition: stencil.hh:207
GlobalStencilType stencil_
Definition: stencil.hh:219
SimpleStencil()
Definition: stencil.hh:199
int maxNonZerosEstimate() const
Definition: stencil.hh:203
SimpleStencil(int maxNZ)
Definition: stencil.hh:196
const GlobalStencilType & globalStencil() const
Definition: stencil.hh:212
StencilType::DomainEntityType DomainEntityType
Definition: stencil.hh:189
StencilType::GlobalStencilType GlobalStencilType
Definition: stencil.hh:194
StencilType::LocalStencilType LocalStencilType
Definition: stencil.hh:193
StencilType::DomainGlobalKeyType DomainGlobalKeyType
Definition: stencil.hh:191
a simple wrapper class for sparsity patterns provide as vector< set< size_t > >
Definition: stencil.hh:233
int computeMaxNZ() const
Definition: stencil.hh:323
void fill(const DomainEntityType &dEntity, const RangeEntityType &rEntity, bool fillGhost=true)
Create stencil entries for (dEntity,rEntity) pair.
Definition: stencil.hh:309
int maxNZ_
Definition: stencil.hh:334
StencilType::DomainEntityType DomainEntityType
Definition: stencil.hh:237
std::vector< LocalStencilType > GlobalStencilType
Definition: stencil.hh:245
const LocalStencilType & localStencil(const DomainGlobalKeyType &key) const
Definition: stencil.hh:292
const ThisType & globalStencil() const
Definition: stencil.hh:297
StencilType::RangeGlobalKeyType RangeGlobalKeyType
Definition: stencil.hh:240
StencilType::DomainGlobalKeyType DomainGlobalKeyType
Definition: stencil.hh:239
LocalStencil LocalStencilType
Definition: stencil.hh:244
Iterator find(const DomainGlobalKeyType &key) const
Definition: stencil.hh:316
StencilWrapper(const GlobalStencilType &stencil)
Definition: stencil.hh:281
StencilType::RangeEntityType RangeEntityType
Definition: stencil.hh:238
Iterator begin() const
Definition: stencil.hh:314
int maxNonZerosEstimate() const
Definition: stencil.hh:287
const GlobalStencilType & stencil_
Definition: stencil.hh:333
Iterator end() const
Definition: stencil.hh:315
Definition: stencil.hh:248
bool operator==(const Iterator &other) const
Definition: stencil.hh:270
const GlobalStencilType & stencil_
Definition: stencil.hh:252
bool operator!=(const Iterator &other) const
Definition: stencil.hh:275
Iterator(const DomainGlobalKeyType &init, const GlobalStencilType &stencil)
Definition: stencil.hh:255
ItemType operator*() const
Definition: stencil.hh:264
std::pair< DomainGlobalKeyType, const LocalStencilType & > ItemType
Definition: stencil.hh:249
DomainGlobalKeyType index_
Definition: stencil.hh:251
Iterator & operator++()
Definition: stencil.hh:258
Stencil contaning the entries (en,en) for all entities in the space. Defailt for an operator over a L...
Definition: stencil.hh:348
BaseType::DomainGlobalKeyType DomainGlobalKeyType
Definition: stencil.hh:354
BaseType::GlobalStencilType GlobalStencilType
Definition: stencil.hh:357
BaseType::RangeEntityType RangeEntityType
Definition: stencil.hh:353
BaseType::DomainEntityType DomainEntityType
Definition: stencil.hh:352
DiagonalStencil(const DomainSpace &dSpace, const RangeSpace &rSpace)
Definition: stencil.hh:359
virtual void setupStencil() const override
method to setup stencil depending on entity set defined in derived class
Definition: stencil.hh:366
Partition PartitionType
Definition: stencil.hh:351
BaseType::LocalStencilType LocalStencilType
Definition: stencil.hh:356
BaseType::RangeGlobalKeyType RangeGlobalKeyType
Definition: stencil.hh:355
Stencil< DomainSpace, RangeSpace > BaseType
Definition: stencil.hh:349
Stencil contaning the entries (en,en) and (en,nb) for all entities en in the space and neighbors nb o...
Definition: stencil.hh:385
virtual void setupStencil() const override
method to setup stencil depending on entity set defined in derived class
Definition: stencil.hh:405
bool onlyNonContinuousNeighbors_
Definition: stencil.hh:426
BaseType::RangeEntityType RangeEntityType
Definition: stencil.hh:390
BaseType::DomainGlobalKeyType DomainGlobalKeyType
Definition: stencil.hh:391
DiagonalAndNeighborStencil(const DomainSpace &dSpace, const RangeSpace &rSpace, bool onlyNonContinuousNeighbors=false)
Definition: stencil.hh:396
Stencil< DomainSpace, RangeSpace > BaseType
Definition: stencil.hh:386
BaseType::LocalStencilType LocalStencilType
Definition: stencil.hh:393
BaseType::GlobalStencilType GlobalStencilType
Definition: stencil.hh:394
Partition PartitionType
Definition: stencil.hh:388
BaseType::DomainEntityType DomainEntityType
Definition: stencil.hh:389
BaseType::RangeGlobalKeyType RangeGlobalKeyType
Definition: stencil.hh:392