5#ifndef DUNE_GRID_YASPGRID_YGRID_HH
6#define DUNE_GRID_YASPGRID_YGRID_HH
13#include <dune/common/fvector.hh>
14#include <dune/common/math.hh>
15#include <dune/common/streamoperators.hh>
28 template<
int d,
typename ct>
29 std::array<int,d>
sizeArray(
const std::array<std::vector<ct>,d>& v)
31 std::array<int,d> tmp;
32 for (
int i=0; i<d; ++i)
33 tmp[i] = v[i].size() - 1;
73 template<
class Coordinates>
78 typedef typename Coordinates::ctype
ct;
79 static const int d = Coordinates::dimension;
87 std::fill(_origin.begin(), _origin.end(), 0);
88 std::fill(_offset.begin(), _offset.end(), 0);
89 std::fill(_size.begin(), _size.end(), 0);
111 for (
int i=0; i<
d; i++)
116 for (
int i=0; i<
d; ++i)
118 _superincrement[i] = inc;
119 inc *= _supersize[i];
136 for (
int i=0; i<
d; ++i)
138 _superincrement[i] = inc;
139 inc *= _supersize[i];
162 const std::bitset<d>&
shift ()
const
187 return _supersize[i];
212 for (
int i=0; i<
d; ++i)
226 return _origin[i] +
size(i) - 1;
232 for (
int i=0; i<
d; ++i)
243 for (
int i=0; i<
d; i++)
245 if ((coord[i]<_origin[i]) || (coord[i]>=_origin[i]+_size[i]))
254 int index = (coord[
d-1]-_origin[
d-1]);
256 for (
int i=
d-2; i>=0; i--)
257 index =
index*_size[i] + (coord[i]-_origin[i]);
265 for (
int i=0; i<
d; i++)
273 for (
int i=0; i<
d; i++)
282 for (
int i=0; i<
d; ++i)
320 for (
int i=0; i<
d; ++i)
325 for (
int i=0; i<
d; ++i)
371 for (
int i = 0; i <
d; ++i)
381 for (
int i=0; i<
d; i++)
395 for (
int i=0; i<
d; i++)
405 return _grid->getCoords()->coordinate(i,
_coord[i]);
412 for (
int i=0; i<
d; i++)
423 return _grid->getCoords()->coordinate(i,
coord);
430 for (
int i=0; i<
d; i++)
445 for (
int i=0; i<
d; i++)
452 return _grid->shift(i);
457 return _grid->shift();
462 return _grid->getCoords();
476 for (
int i=0; i<
d; ++i)
477 si += (
offset(i)+coord[i]-
origin(i))*_superincrement[i];
483 return _superincrement[i];
502 for (
int i=0; i<
d; i++)
510 std::bitset<d> _shift;
511 Coordinates* _coords;
521 template <
class Coordinates>
524 s <<
"Printing YGridComponent structure:" << std::endl;
525 s <<
"Origin: " << e.
origin() << std::endl;
526 s <<
"Shift: " << e.
shift() << std::endl;
527 s <<
"Size: " << e.
size() << std::endl;
528 s <<
"Offset: " << e.
offset() << std::endl;
529 s <<
"Supersize: " << e.
supersize() << std::endl;
534 template <
class Coordinates>
537 s <<
"Printing YGridComponent Iterator:" << std::endl <<
"Iterator at " << e.
coord() <<
" (index ";
538 s << e.index() <<
"), position " << e.position();
549 template<
class Coordinates>
553 static const int dim = Coordinates::dimension;
558 typedef typename std::array<int, dim>
iTupel;
569 return _shiftmapping[shift.to_ulong()];
585 bool inside(
const iTupel& coord,
const std::bitset<dim>& shift = std::bitset<dim>())
const
587 return (_begin+_shiftmapping[shift.to_ulong()])->inside(coord);
602 : _which(
which), _yg(&yg)
612 _it = _yg->_itends.back();
613 _which = _yg->_itends.size() - 1;
617 _it = _yg->_itbegins[0];
637 const std::array<int, dim>&
coord ()
const
647 Dune::FieldVector<typename Coordinates::ctype,dim>
lowerleft()
const
657 Dune::FieldVector<typename Coordinates::ctype,dim>
upperright()
const
669 Dune::FieldVector<typename Coordinates::ctype,dim>
meshsize()
const
690 return _yg->_indexOffset[_which] + _it.
superindex();
696 if ((++_it == _yg->_itends[_which]) && (_which < _yg->_itends.size()-1))
697 _it = _yg->_itbegins[++_which];
704 if (_which != i._which)
714 return _which != i._which;
741 unsigned int _which = 0;
755 return Iterator(*
this, coord, which);
776 _indexOffset.push_back(artificialOffset);
778 for (
DAI i=_begin; i != _end; ++i, ++k)
781 _itbegins.push_back(i->begin());
782 _itends.push_back(i->end());
785 _indexOffset.push_back(_indexOffset.back() + i->totalsize());
788 _shiftmapping[i->shift().to_ulong()] = k;
790 _indexOffset.resize(_itends.size());
798 std::array<int,Dune::power(2,dim)> _shiftmapping;
799 std::vector<typename YGridComponent<Coordinates>::Iterator> _itbegins;
800 std::vector<typename YGridComponent<Coordinates>::Iterator> _itends;
801 std::vector<int> _indexOffset;
805 template <class Coordinates>
806 inline std::ostream& operator<< (std::ostream& s, const YGrid<Coordinates>& e)
808 s << "Printing YGrid structure:" << std::endl;
809 for (auto it = e.dataBegin(); it != e.dataEnd(); ++it)
810 s << *it << std::endl;
821 template<class Coordinates>
825 static const int dim = Coordinates::dimension;
831 YGridComponent<Coordinates> grid;
837 YGrid<Coordinates> yg;
841 typedef typename std::array<std::deque<Intersection>, Dune::power(2,dim)>::iterator DAI;
850 Iterator(const YGridList<Coordinates>& ygl, bool end=false) : _end(ygl.dataEnd()), _which(ygl.dataBegin())
852 _it = _which->begin();
856 while ((_which != _end) && (_it == _which->end()))
860 _it = _which->begin();
870 Iterator& operator++ ()
875 while ((_which != _end) && (_it == _which->end()))
879 _it = _which->begin();
885 typename std::deque<Intersection>::iterator operator->() const
891 typename std::deque<Intersection>::iterator operator*() const
897 bool operator== (const Iterator& i) const
899 if (_which != i._which)
907 bool operator!= (const Iterator& i) const
909 if (_which != i._which)
917 typename std::deque<Intersection>::iterator _it;
923 Iterator begin() const
925 return Iterator(*this);
931 return Iterator(*this,true);
935 void setBegin(typename std::array<std::deque<Intersection>, Dune::power(2,dim)>::iterator begin)
941 DAI dataBegin() const
956 for (DAI it = _begin; it != _end; ++it)
962 void finalize(DAI end, const YGrid<Coordinates>& ygrid)
982 while (i != _end && i->begin() == i->end())
985 for (auto yit = ygrid.dataBegin(); yit != ygrid.dataEnd(); ++yit)
989 auto it = i->
begin();
990 if (it->grid.shift() == yit->shift())
993 for (; it != i->end(); ++it)
995 it->yg.setBegin(&(it->grid));
996 it->yg.finalize(&(it->grid)+1, offset);
1001 while (i != _end && i->begin() == i->end())
1007 for (
int j=0; j<
dim; j++)
1008 add *= yit->supersize(j);
std::ostream & operator<<(std::ostream &out, const PartitionType &type)
write a PartitionType to a stream
Definition: gridenums.hh:72
Include standard header files.
Definition: agrid.hh:60
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:337
std::array< int, d > sizeArray(const std::array< std::vector< ct >, d > &v)
Definition: ygrid.hh:29
int index(const iTupel &coord) const
given a tupel compute its index in the lexicographic numbering
Definition: ygrid.hh:252
int offset(int i) const
Return offset to origin of enclosing grid.
Definition: ygrid.hh:173
std::array< int, d > iTupel
Definition: ygrid.hh:81
YGridComponent< Coordinates > move(iTupel v) const
return grid moved by the vector v
Definition: ygrid.hh:263
iTupel size() const
retrun size
Definition: ygrid.hh:203
static const int d
Definition: ygrid.hh:79
YGridComponent< Coordinates > intersection(const YGridComponent< Coordinates > &r) const
Return YGridComponent of supergrid of self which is the intersection of self and another YGridCompone...
Definition: ygrid.hh:271
Coordinates::ctype ct
Definition: ygrid.hh:78
Coordinates * getCoords() const
Definition: ygrid.hh:167
int min(int i) const
Return minimum index in direction i.
Definition: ygrid.hh:218
YGridComponent(iTupel origin, iTupel size)
make ygrid without coordinate information
Definition: ygrid.hh:99
int totalsize() const
Return total size of index set which is the product of all size per direction.
Definition: ygrid.hh:209
YGridComponent(iTupel origin, iTupel size, const YGridComponent< Coordinates > &enclosing)
make a subgrid by taking coordinates from a larger grid
Definition: ygrid.hh:108
const iTupel & supersize() const
return size of enclosing grid
Definition: ygrid.hh:191
YGridComponent(iTupel origin, std::bitset< d > shift, Coordinates *coords, iTupel size, iTupel offset, iTupel supersize)
Make YGridComponent by giving all parameters.
Definition: ygrid.hh:131
int superindex(iTupel coord) const
Definition: ygrid.hh:472
Iterator begin() const
return iterator to first element of index set
Definition: ygrid.hh:487
FieldVector< ct, d > fTupel
Definition: ygrid.hh:82
Iterator begin(const iTupel &co) const
return iterator to given element of index set
Definition: ygrid.hh:493
YGridComponent()
make uninitialized ygrid
Definition: ygrid.hh:85
int origin(int i) const
Return origin in direction i.
Definition: ygrid.hh:144
int supersize(int i) const
return size of enclosing grid
Definition: ygrid.hh:185
int size(int i) const
return size in direction i
Definition: ygrid.hh:197
int max(int i) const
Return maximum index in direction i.
Definition: ygrid.hh:224
const std::bitset< d > & shift() const
Return shift tupel.
Definition: ygrid.hh:162
int superincrement(int i) const
Definition: ygrid.hh:481
bool shift(int i) const
Return shift in direction i.
Definition: ygrid.hh:156
Iterator end() const
return subiterator to last element of index set
Definition: ygrid.hh:499
bool inside(const iTupel &coord) const
given a coordinate, return true if it is in the grid
Definition: ygrid.hh:241
bool empty() const
Return true if YGrid is empty, i.e. has size 0 in all directions.
Definition: ygrid.hh:230
const iTupel & offset() const
Return offset to origin of enclosing grid.
Definition: ygrid.hh:179
const iTupel & origin() const
return reference to origin
Definition: ygrid.hh:150
Iterator & operator++()
Increment iterator to next cell with position.
Definition: ygrid.hh:379
int superindex() const
Return consecutive index in enclosing grid.
Definition: ygrid.hh:344
bool operator!=(const Iterator &i) const
Return true when two iterators over the same grid are not equal (!).
Definition: ygrid.hh:338
ct lowerleft(int i) const
Return ith component of lower left corner of the entity associated with the current coordinates and s...
Definition: ygrid.hh:403
std::bitset< d > shift() const
Definition: ygrid.hh:455
ct meshsize(int i) const
Return meshsize in direction i.
Definition: ygrid.hh:436
bool shift(int i) const
Definition: ygrid.hh:450
const YGridComponent< Coordinates > * _grid
Definition: ygrid.hh:468
void reinit(const YGridComponent< Coordinates > &r, const iTupel &coord)
reinitialize iterator to given position
Definition: ygrid.hh:317
void move(const iTupel &dist)
move this iterator dist cells in direction i
Definition: ygrid.hh:369
fTupel meshsize() const
Return meshsize of current cell as reference.
Definition: ygrid.hh:442
fTupel lowerleft() const
Return lower left corner of the entity associated with the current coordinates and shift.
Definition: ygrid.hh:409
Coordinates * coordCont() const
Definition: ygrid.hh:460
iTupel _coord
current position in index set
Definition: ygrid.hh:466
const iTupel & coord() const
Return coordinate of the cell as reference (do not modify).
Definition: ygrid.hh:356
void move(int i, int dist)
move this iterator dist cells in direction i
Definition: ygrid.hh:362
Iterator(const YGridComponent< Coordinates > &r)
Make iterator pointing to first cell in a grid.
Definition: ygrid.hh:304
ct upperright(int i) const
Return ith component of upper right corder of the entity associated with the current coordinates and ...
Definition: ygrid.hh:418
int coord(int i) const
Return coordinate of the cell in direction i.
Definition: ygrid.hh:350
fTupel upperright() const
Return upper right corder of the entity associated with the current coordinates and shift.
Definition: ygrid.hh:427
bool operator==(const Iterator &i) const
Return true when two iterators over the same grid are equal (!).
Definition: ygrid.hh:332
Iterator(const YGridComponent< Coordinates > &r, const iTupel &coord)
Make iterator pointing to given cell in a grid.
Definition: ygrid.hh:311
int _superindex
consecutive index in enclosing grid
Definition: ygrid.hh:467
implements a collection of YGridComponents which form a codimension Entities of given codimension c n...
Definition: ygrid.hh:551
int shiftmapping(const std::bitset< dim > &shift) const
get which component belongs to a given shift vector
Definition: ygrid.hh:567
DAI dataBegin() const
get start iterator in the data array
Definition: ygrid.hh:573
Iterator begin() const
return begin iterator for the codimension and partition the ygrid represents
Definition: ygrid.hh:747
DAI dataEnd() const
get end iterator in the data array
Definition: ygrid.hh:579
std::array< int, dim > iTupel
Definition: ygrid.hh:558
static const int dim
Definition: ygrid.hh:553
void setBegin(DAI begin)
set start iterator in the data array
Definition: ygrid.hh:561
bool inside(const iTupel &coord, const std::bitset< dim > &shift=std::bitset< dim >()) const
decide whether a coordinate is in the grid (depending on the component)
Definition: ygrid.hh:585
int superindex(const iTupel &coord, int which) const
Definition: ygrid.hh:764
Iterator begin(const std::array< int, dim > &coord, int which=0) const
return iterator pointint to a specified position
Definition: ygrid.hh:753
YGridComponent< Coordinates > * DAI
Definition: ygrid.hh:556
void finalize(const DAI &end, int artificialOffset=0)
Definition: ygrid.hh:771
Iterator end() const
return end iterator for the codimension and partition the ygrid represents
Definition: ygrid.hh:759
Iterator over a collection o YGrids A YGrid::Iterator is the heart of an entity in YaspGrid.
Definition: ygrid.hh:594
Iterator()=default
default constructor
int which() const
return the current component number
Definition: ygrid.hh:718
void move(int i, int dist)
move the grid, this is only done and needed for codim 0
Definition: ygrid.hh:724
bool operator==(const Iterator &i) const
compare two iterators: component has to match
Definition: ygrid.hh:702
Coordinates::ctype lowerleft(int i) const
Definition: ygrid.hh:642
Dune::FieldVector< typename Coordinates::ctype, dim > meshsize() const
return the current meshsize vector
Definition: ygrid.hh:669
Iterator(const YGrid< Coordinates > &yg, const std::array< int, dim > &coords, int which=0)
construct an iterator from coordinates and component
Definition: ygrid.hh:601
Coordinates * coordCont() const
Definition: ygrid.hh:734
Coordinates::ctype upperright(int i) const
Definition: ygrid.hh:652
std::bitset< dim > shift() const
return the shift vector
Definition: ygrid.hh:681
bool shift(int i) const
return the shift in direction i
Definition: ygrid.hh:675
bool operator!=(const Iterator &i) const
compare two iterators: component has to match
Definition: ygrid.hh:710
void move(const iTupel &dist)
Definition: ygrid.hh:729
Dune::FieldVector< typename Coordinates::ctype, dim > upperright() const
Definition: ygrid.hh:657
const std::array< int, dim > & coord() const
return coordinate array at the current position
Definition: ygrid.hh:637
Iterator & operator++()
increment to the next entity jumping to next component if necessary
Definition: ygrid.hh:694
Coordinates::ctype meshsize(int i) const
return the current meshsize in direction i
Definition: ygrid.hh:663
int coord(int i) const
return coordinate at the current position (direction i)
Definition: ygrid.hh:631
Iterator(const YGrid< Coordinates > &yg, bool end=false)
create an iterator to start or end of the codimension
Definition: ygrid.hh:608
Dune::FieldVector< typename Coordinates::ctype, dim > lowerleft() const
Definition: ygrid.hh:647
int superindex() const
return the superindex
Definition: ygrid.hh:687
void reinit(const YGrid< Coordinates > &yg, const std::array< int, dim > &coords, int which=0)
reinitializes an iterator, as if it was just constructed.
Definition: ygrid.hh:623