3#ifndef DUNE_FOAMGRID_HH
4#define DUNE_FOAMGRID_HH
20#define DUNE_FUNCTION_HH_SILENCE_DEPRECATION
21#include <dune/common/function.hh>
23#include <dune/common/version.hh>
24#if DUNE_VERSION_LT(DUNE_COMMON,2,7)
25#include <dune/common/parallel/collectivecommunication.hh>
27#include <dune/common/parallel/communication.hh>
30#include <dune/common/stdstreams.hh>
31#include <dune/grid/common/capabilities.hh>
32#include <dune/grid/common/grid.hh>
52template <
int dimgr
id,
int dimworld,
class ctype =
double>
57template<
int dimgr
id,
int dimworld,
class ctype>
79 CollectiveCommunication<Dune::FoamGrid<dimgrid, dimworld, ctype> > ,
80 DefaultLevelGridViewTraits,
81 DefaultLeafGridViewTraits,
93template <
int dimgr
id,
int dimworld,
class ct>
95 public GridDefaultImplementation <dimgrid, dimworld, ct, FoamGridFamily<dimgrid, dimworld, ct> >
106 template<
int codim, PartitionIteratorType pitype,
class Gr
idImp_>
109 template<
int codim, PartitionIteratorType pitype,
class Gr
idImp_>
112 template <
class Gr
idType_>
115 template <
int dimgr
id_,
int dimworld_,
class ct_>
118 template<
int codim_,
int dim_,
class Gr
idImp_>
124 static_assert(dimgrid==1 || dimgrid==2,
"Use FoamGrid only for 1d and 2d grids!");
142 : entityImps_(makeEntityImps_())
144 , leafIndexSet_(*this)
147 , numBoundarySegments_(0)
155 for (
size_t i=0; i<levelIndexSets_.size(); i++)
156 if (levelIndexSets_[i])
157 delete (levelIndexSets_[i]);
164 return entityImps_.size()-1;
170 typename Traits::template Codim<codim>::LevelIterator
lbegin (
int level)
const {
172 DUNE_THROW(Dune::GridError,
"LevelIterator in nonexisting level " << level <<
" requested!");
180 typename Traits::template Codim<codim>::LevelIterator
lend (
int level)
const {
182 DUNE_THROW(GridError,
"LevelIterator in nonexisting level " << level <<
" requested!");
189 template<
int codim, PartitionIteratorType PiType>
190 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator
lbegin (
int level)
const {
192 DUNE_THROW(Dune::GridError,
"LevelIterator in nonexisting level " << level <<
" requested!");
199 template<
int codim, PartitionIteratorType PiType>
200 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator
lend (
int level)
const {
202 DUNE_THROW(GridError,
"LevelIterator in nonexisting level " << level <<
" requested!");
210 typename Traits::template Codim<codim>::LeafIterator
leafbegin()
const {
217 typename Traits::template Codim<codim>::LeafIterator
leafend()
const {
223 template<
int codim, PartitionIteratorType PiType>
224 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator
leafbegin()
const {
230 template<
int codim, PartitionIteratorType PiType>
231 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator
leafend()
const {
238 int size (
int level,
int codim)
const {
241 if ((codim==2 && dimgrid==2) || (codim==1 && dimgrid==1))
242 return std::get<0>(entityImps_[level]).size();
243 if ((codim==1 && dimgrid==2))
244 return std::get<1>(entityImps_[level]).size();
246 return std::get<dimgrid>(entityImps_[level]).size();
259 int size (
int level, GeometryType type)
const {
265 int size (GeometryType type)
const
273 return numBoundarySegments_;
292 DUNE_THROW(GridError,
"LevelIndexSet for nonexisting level " << level <<
" requested!");
294 if (! levelIndexSets_[level])
297 levelIndexSets_[level]->update();
299 return *levelIndexSets_[level];
306 return leafIndexSet_;
310 template <
class EntitySeed>
311 typename Traits::template Codim<EntitySeed::codimension>::Entity
314 const int codim = EntitySeed::codimension;
338 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity & e)
358 int getMark(
const typename Traits::template Codim<0>::Entity & e)
const
360 switch(e.impl().target_->markState_)
392 void setPosition(
const typename Traits::template Codim<dimgrid>::Entity & e,
393 const FieldVector<ctype, dimworld>& pos);
404 if(!growing_) initializeGrowth_();
409 newVertex.isNew_ =
true;
412 newVertex.growthInsertionIndex_ = this->leafGridView().size(dimgrid) - 1 + verticesToInsert_.size();
413 return newVertex.growthInsertionIndex_;
423 const std::vector<unsigned int>& vertices)
426 assert(type.isTriangle() || type.isLine());
427 assert(vertices.size() == dimgrid + 1);
432 assert(vertices.size() == newElement.vertex_.size());
434 for(std::size_t i = 0; i < vertices.size(); i++)
436 if(
int(vertices[i]) >= this->leafGridView().
size(dimgrid))
439 auto vIt = verticesToInsert_.begin();
440 std::advance(vIt, vertices[i] - this->leafGridView().
size(dimgrid));
441 newElement.vertex_[i] = &*vIt;
446 if(!growing_) initializeGrowth_();
448 assert(indexToVertexMap_[vertices[i]]->isLeaf());
449 newElement.vertex_[i] = indexToVertexMap_[vertices[i]];
452 newElement.isNew_ =
true;
453 newElement.growthInsertionIndex_ = elementsToInsert_.size()-1;
454 return newElement.growthInsertionIndex_;
457DUNE_NO_DEPRECATED_BEGIN
465 [[deprecated(
"Signature with VirtualFunction is deprecated and will be removed after Dune 2.8. Use signature with std::function.")]]
467 const std::vector<unsigned int>& vertices,
468 const std::shared_ptr<VirtualFunction<FieldVector<ctype,dimgrid>,FieldVector<ctype,dimworld> > >& elementParametrization)
472 elementsToInsert_.back().elementParametrization_ =
473 [elementParametrization](
const FieldVector<ctype,dimgrid>& x){
474 FieldVector<ctype,dimworld> y;
475 elementParametrization->evaluate(x, y);
480DUNE_NO_DEPRECATED_END
490 const std::vector<unsigned int>& vertices,
491 std::function<FieldVector<ctype,dimworld>(FieldVector<ctype,dimgrid>)> elementParametrization)
495 elementsToInsert_.back().elementParametrization_ = elementParametrization;
527 int idx = e.impl().target_->growthInsertionIndex_;
529 return static_cast<unsigned int>(idx);
542 int idx = e.impl().target_->growthInsertionIndex_;
544 return static_cast<unsigned int>(idx);
577 template<
class DataHandle>
586 DUNE_THROW(Dune::NotImplemented,
"Load balancing not implemented. Foamgrid does not run in parallel yet!");
601 template<
class T,
template<
class>
class P,
int codim>
602 void communicate (T& t, InterfaceType iftype, CommunicationDirection dir,
int level)
const
608 template<
class DataHandle>
609 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir,
int level)
const
612 template<
class DataHandle>
613 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir)
const
617 const typename Traits::CollectiveCommunication&
comm ()
const
631 void initializeGrowth_()
634 indexToVertexMap_.resize(this->leafGridView().
size(dimgrid));
635 for (
const auto& vertex : vertices(this->leafGridView()))
646 void erasePointersToEntities(std::list<FoamGridEntityImp<dimgrid, dimgrid ,dimworld, ctype> >& elements);
653 void eraseVanishedEntities(std::list<FoamGridEntityImp<i, dimgrid, dimworld, ctype> >& levelEntities);
657 void coarsenSimplexElement(FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>& element);
662 void refineSimplexElement(FoamGridEntityImp<2, 2, dimworld, ctype>& element,
int refCount);
664 void refineSimplexElement(FoamGridEntityImp<1, 1, dimworld, ctype>& element,
int refCount);
667 bool removeSimplexElement(FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>& element);
678 void overwriteFineLevelNeighbours(FoamGridEntityImp<dimgrid-1, dimgrid, dimworld, ctype>& edge,
679 const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* son,
680 const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* father);
688 void addElementForFacet(
const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* element,
689 FoamGridEntityImp<dimgrid-1, dimgrid, dimworld, ctype>* facet);
692 void addNewFacet(FoamGridEntityImp<dimgrid-1, dimgrid, dimworld, ctype>* &facet,
693 std::array<FoamGridEntityImp<0, dimgrid, dimworld, ctype>*,dimgrid> vertexArray,
702 unsigned int getNextFreeId()
704 return freeIdCounter_++;
708 void computeTwoZeroConnectivity()
711 for(
int level = 0; level <=
maxLevel(); ++level)
714 for(
auto&& vertex : std::get<0>(entityImps_[level]))
715 vertex.elements_.clear();
717 for(
auto eIt = std::get<dimgrid>(entityImps_[level]).begin(); eIt != std::get<dimgrid>(entityImps_[level]).end(); ++eIt)
718 for(
auto&& vertex : eIt->vertex_)
719 vertex->elements_.push_back(&*eIt);
724 typename Traits::CollectiveCommunication ccobj_;
726 template<std::size_t... dimEntity>
727 static auto makeEntityImpsImpl_(std::index_sequence<dimEntity...>, std::size_t numLevels)
728 {
return std::vector<std::tuple<std::list<FoamGridEntityImp<dimEntity, dimgrid, dimworld, ctype>>...>>(numLevels); }
731 static auto makeEntityImps_(std::size_t numLevels = 1)
732 {
return makeEntityImpsImpl_(std::make_index_sequence<dimgrid+1>{}, numLevels); }
735 using EntityImps = std::decay_t<
decltype(makeEntityImps_())>;
738 using EntityTuple =
typename EntityImps::value_type;
741 EntityImps entityImps_;
744 mutable std::vector<FoamGridLevelIndexSet<const FoamGrid>*> levelIndexSets_;
753 unsigned int freeIdCounter_;
759 std::size_t numBoundarySegments_;
765 std::vector<FoamGridEntityImp<0, dimgrid, dimworld, ctype>* > indexToVertexMap_;
768 std::vector<FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* > elementsToRemove_;
771 std::list<FoamGridEntityImp<0, dimgrid, dimworld, ctype> > verticesToInsert_;
774 std::list<FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype> > elementsToInsert_;
783namespace Capabilities
789 template<
int dimgr
id,
int dimworld,
class ctype,
int codim>
790 struct hasEntity<
FoamGrid<dimgrid, dimworld, ctype>, codim>
792 static const bool v =
true;
796 template <
int dimgr
id,
int dimworld,
class ctype>
797 struct isLevelwiseConforming<
FoamGrid<dimgrid, dimworld, ctype> >
799 static const bool v =
false;
803 template <
int dimgr
id,
int dimworld,
class ctype>
804 struct isLeafwiseConforming<
FoamGrid<dimgrid, dimworld, ctype> >
806 static const bool v =
false;
The FoamGridEntity class.
Implementation of EntitySeed for the FoamGrid grid manager.
The specialization of the generic GridFactory for FoamGrid.
The FoamGridGeometry class.
The FoamGridHierarchicIterator class.
The index and id sets for the FoamGrid class.
The FoamGridLeafIntersectionIterator and FoamGridLevelIntersectionIterator classes.
The FoamGridLeafIterator class.
The FoamGridLevelIterator class.
An implementation of the Dune grid interface: a 1- or 2-dimensional simplicial grid in an n-dimension...
Definition: foamgrid.hh:96
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: foamgrid.hh:200
void removeElement(const typename Traits::template Codim< 0 >::Entity &e)
Mark an element for removal from the grid.
Definition: foamgrid.hh:502
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: foamgrid.hh:565
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: foamgrid.hh:259
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: foamgrid.hh:283
size_t numBoundarySegments() const
The number of boundary edges on the coarsest level.
Definition: foamgrid.hh:271
void setPosition(const typename Traits::template Codim< dimgrid >::Entity &e, const FieldVector< ctype, dimworld > &pos)
Sets a (leaf) vertex to a new position.
Definition: foamgrid.cc:1422
void communicate(T &t, InterfaceType iftype, CommunicationDirection dir, int level) const
The communication interface.
Definition: foamgrid.hh:602
FoamGrid()
Constructor, constructs an empty grid.
Definition: foamgrid.hh:141
friend class FoamGridLeafIndexSet< const FoamGrid >
Definition: foamgrid.hh:99
friend class GridFactory
Definition: foamgrid.hh:113
bool preGrow()
Book-keeping routine to be called before growth.
Definition: foamgrid.cc:1001
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark entity for refinement.
Definition: foamgrid.hh:338
FoamGridFamily< dimgrid, dimworld, ct > GridFamily
FoamGrid is only implemented for 1 and 2 dimension.
Definition: foamgrid.hh:131
unsigned int insertVertex(const FieldVector< ctype, dimworld > &pos)
Add new vertex to be added the grid.
Definition: foamgrid.hh:402
~FoamGrid()
Destructor.
Definition: foamgrid.hh:152
unsigned int growthInsertionIndex(const typename Traits::template Codim< 0 >::Entity &e) const
The index of insertion if the element was created in the current growth step. If this is the first el...
Definition: foamgrid.hh:525
void postGrow()
Clean up isNew markers.
Definition: foamgrid.cc:1325
friend class FoamGridLevelIndexSet< const FoamGrid >
Definition: foamgrid.hh:98
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: foamgrid.hh:358
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: foamgrid.hh:231
unsigned int insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Add a new element to be added to the grid.
Definition: foamgrid.hh:422
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir, int level) const
Definition: foamgrid.hh:609
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: foamgrid.hh:289
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: foamgrid.hh:277
DUNE_NO_DEPRECATED_BEGIN unsigned int insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices, const std::shared_ptr< VirtualFunction< FieldVector< ctype, dimgrid >, FieldVector< ctype, dimworld > > > &elementParametrization)
Add a new element to be added to the grid.
Definition: foamgrid.hh:466
friend class FoamGridIdSet< const FoamGrid >
Definition: foamgrid.hh:100
bool loadBalance(DataHandle &data)
Distributes this grid over the available nodes in a distributed machine.
Definition: foamgrid.hh:578
bool preAdapt()
Book-keeping routine to be called before adaptation.
Definition: foamgrid.cc:152
FoamGridFamily< dimgrid, dimworld, ct >::Traits Traits
Exports various types belonging to this grid class.
Definition: foamgrid.hh:134
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: foamgrid.hh:170
void postAdapt()
Clean up refinement markers.
Definition: foamgrid.cc:317
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir) const
Definition: foamgrid.hh:613
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: foamgrid.hh:265
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: foamgrid.hh:210
void globalRefine(int refCount=1)
Refine the grid uniformly.
Definition: foamgrid.cc:3
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: foamgrid.hh:217
ct ctype
The type used to store coordinates.
Definition: foamgrid.hh:137
bool loadBalance()
Definition: foamgrid.hh:583
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: foamgrid.hh:553
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: foamgrid.hh:190
const Traits::CollectiveCommunication & comm() const
Definition: foamgrid.hh:617
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: foamgrid.hh:224
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: foamgrid.hh:571
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create an Entity from an EntitySeed.
Definition: foamgrid.hh:312
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: foamgrid.hh:559
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: foamgrid.hh:180
DUNE_NO_DEPRECATED_END unsigned int insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices, std::function< FieldVector< ctype, dimworld >(FieldVector< ctype, dimgrid >)> elementParametrization)
Add a new element to be added to the grid.
Definition: foamgrid.hh:489
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: foamgrid.hh:304
int maxLevel() const
Definition: foamgrid.hh:163
bool grow()
Triggers the grid growth process.
Definition: foamgrid.cc:1008
unsigned int growthInsertionIndex(const typename Traits::template Codim< dimgrid >::Entity &e) const
The index of insertion if the vertex was created in the current growth step. If this is the first ver...
Definition: foamgrid.hh:540
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: foamgrid.hh:238
bool adapt()
Triggers the grid refinement process.
Definition: foamgrid.cc:206
int size(int codim) const
number of leaf entities per codim in this process
Definition: foamgrid.hh:253
Encapsulates loads of types exported by FoamGrid.
Definition: foamgrid.hh:59
GridTraits< dimgrid, dimworld, Dune::FoamGrid< dimgrid, dimworld, ctype >, FoamGridGeometry, FoamGridEntity, FoamGridLevelIterator, FoamGridLeafIntersection, FoamGridLevelIntersection, FoamGridLeafIntersectionIterator, FoamGridLevelIntersectionIterator, FoamGridHierarchicIterator, FoamGridLeafIterator, FoamGridLevelIndexSet< const FoamGrid< dimgrid, dimworld, ctype > >, FoamGridLeafIndexSet< const FoamGrid< dimgrid, dimworld, ctype > >, FoamGridIdSet< const FoamGrid< dimgrid, dimworld, ctype > >, unsigned int, FoamGridIdSet< const FoamGrid< dimgrid, dimworld, ctype > >, unsigned int, CollectiveCommunication< Dune::FoamGrid< dimgrid, dimworld, ctype > >, DefaultLevelGridViewTraits, DefaultLeafGridViewTraits, FoamGridEntitySeed > Traits
Definition: foamgrid.hh:83
The implementation of entities in a FoamGrid.
Definition: foamgridentity.hh:54
Iterator over all entities of a given codimension and level of a grid.
Definition: foamgridleveliterator.hh:18
Definition: foamgridintersectioniterators.hh:239
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: foamgridintersectioniterators.hh:28
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: foamgridhierarchiciterator.hh:24
The EntitySeed class provides the minmal information needed to restore an Entity using the grid.
Definition: foamgridentityseed.hh:21
Specialization of the generic GridFactory for FoamGrid<dimgrid, dimworld>
Definition: foamgridfactory.hh:38
Definition: foamgridgeometry.hh:21
Definition: foamgridindexsets.hh:26
Definition: foamgridindexsets.hh:200
Definition: foamgridindexsets.hh:417
Definition: foamgridintersections.hh:252
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: foamgridintersections.hh:386
Iterator over all entities of a given codimension and level of a grid.
Definition: foamgridleafiterator.hh:15
The actual entity implementation.
Definition: foamgridvertex.hh:47