3 #ifndef DUNE_GRID_YASPGRID_YGRID_HH 4 #define DUNE_GRID_YASPGRID_YGRID_HH 11 #include <dune/common/fvector.hh> 12 #include <dune/common/power.hh> 25 template<
int d,
typename ct>
26 std::array<int,d>
sizeArray(
const std::array<std::vector<ct>,d>& v)
28 std::array<int,d> tmp;
29 for (
int i=0; i<d; ++i)
30 tmp[i] = v[i].size() - 1;
70 template<
class Coordinates>
75 typedef typename Coordinates::ctype
ct;
76 static const int d = Coordinates::dimension;
84 std::fill(_origin.begin(), _origin.end(), 0);
85 std::fill(_offset.begin(), _offset.end(), 0);
86 std::fill(_size.begin(), _size.end(), 0);
97 : _origin(origin), _size(size)
106 : _origin(origin), _shift(enclosing.shift()), _coords(enclosing.getCoords()), _size(size), _supersize(enclosing.supersize())
108 for (
int i=0; i<d; i++)
109 _offset[i] = origin[i] - enclosing.
origin(i) + enclosing.
offset(i);
113 for (
int i=0; i<d; ++i)
115 _superincrement[i] = inc;
116 inc *= _supersize[i];
128 YGridComponent (iTupel origin, std::bitset<d> shift, Coordinates* coords, iTupel size, iTupel offset, iTupel supersize)
129 : _origin(origin), _shift(shift), _coords(coords), _size(size), _offset(offset), _supersize(supersize)
133 for (
int i=0; i<d; ++i)
135 _superincrement[i] = inc;
136 inc *= _supersize[i];
159 const std::bitset<d>&
shift ()
const 184 return _supersize[i];
209 for (
int i=0; i<d; ++i)
223 return _origin[i] + size(i) - 1;
229 for (
int i=0; i<d; ++i)
240 for (
int i=0; i<d; i++)
242 if ((coord[i]<_origin[i]) || (coord[i]>=_origin[i]+_size[i]))
249 int index (
const iTupel& coord)
const 251 int index = (coord[d-1]-_origin[d-1]);
253 for (
int i=d-2; i>=0; i--)
254 index = index*_size[i] + (coord[i]-_origin[i]);
262 for (
int i=0; i<d; i++)
270 for (
int i=0; i<d; i++)
273 if (empty() || r.
empty())
279 for (
int i=0; i<d; ++i)
317 for (
int i=0; i<d; ++i)
318 _coord[i] = coord[i];
322 for (
int i=0; i<d; ++i)
362 _superindex += dist*_grid->superincrement(i);
368 for (
int i = 0; i < d; ++i)
370 _coord[i] += dist[i];
371 _superindex += dist[i]*_grid->superincrement(i);
378 for (
int i=0; i<d; i++)
380 _superindex += _grid->superincrement(i);
381 if (++_coord[i] <= _grid->max(i))
385 _coord[i] = _grid->origin(i);
386 _superindex -= _grid->size(i) * _grid->superincrement(i);
390 if (_coord == _grid->origin())
392 for (
int i=0; i<d; i++)
393 _superindex += (_grid->size(i)-1) * _grid->superincrement(i);
394 _superindex += _grid->superincrement(0);
402 return _grid->getCoords()->coordinate(i,_coord[i]);
409 for (
int i=0; i<d; i++)
410 ll[i] = lowerleft(i);
417 int coord = _coord[i];
420 return _grid->getCoords()->coordinate(i,coord);
427 for (
int i=0; i<d; i++)
428 ur[i] = upperright(i);
435 return _grid->getCoords()->meshsize(i,_coord[i]);
442 for (
int i=0; i<d; i++)
449 return _grid->shift(i);
454 return _grid->shift();
459 return _grid->getCoords();
473 for (
int i=0; i<d; ++i)
474 si += (offset(i)+coord[i]-origin(i))*_superincrement[i];
480 return _superincrement[i];
499 for (
int i=0; i<d; i++)
507 std::bitset<d> _shift;
508 Coordinates* _coords;
512 iTupel _superincrement;
518 template <
class Coordinates>
519 inline std::ostream& operator<< (std::ostream& s, YGridComponent<Coordinates> e)
521 s <<
"Printing YGridComponent structure:" << std::endl;
522 s <<
"Origin: " << e.origin() << std::endl;
523 s <<
"Shift: " << e.shift() << std::endl;
524 s <<
"Size: " << e.size() << std::endl;
525 s <<
"Offset: " << e.offset() << std::endl;
526 s <<
"Supersize: " << e.supersize() << std::endl;
531 template <
class Coordinates>
532 inline std::ostream& operator<< (std::ostream& s, typename YGridComponent<Coordinates>::Iterator& e)
534 s <<
"Printing YGridComponent Iterator:" << std::endl <<
"Iterator at " << e.coord() <<
" (index ";
535 s << e.index() <<
"), position " << e.position();
546 template<
class Coordinates>
550 static const int dim = Coordinates::dimension;
555 typedef typename std::array<int, dim>
iTupel;
566 return _shiftmapping[shift.to_ulong()];
582 bool inside(
const iTupel& coord,
const std::bitset<dim>& shift = std::bitset<dim>())
const 584 return (_begin+_shiftmapping[shift.to_ulong()])->inside(coord);
600 : _which(which), _yg(&yg)
610 _it = _yg->_itends.back();
611 _which = _yg->_itends.size() - 1;
615 _it = _yg->_itbegins[0];
635 const std::array<int, dim>&
coord ()
const 642 return _it.lowerleft(i);
645 Dune::FieldVector<typename Coordinates::ctype,dim>
lowerleft()
const 647 return _it.lowerleft();
652 return _it.upperright(i);
655 Dune::FieldVector<typename Coordinates::ctype,dim>
upperright()
const 657 return _it.upperright();
663 return _it.meshsize(i);
667 Dune::FieldVector<typename Coordinates::ctype,dim>
meshsize()
const 669 return _it.meshsize();
688 return _yg->_indexOffset[_which] + _it.superindex();
694 if ((++_it == _yg->_itends[_which]) && (_which < _yg->_itends.size()-1))
695 _it = _yg->_itbegins[++_which];
702 if (_which != i._which)
712 return _which != i._which;
734 return _it.coordCont();
753 return Iterator(*
this, coord, which);
764 return _indexOffset[which] + (dataBegin()+which)->superindex(coord);
769 void finalize(
const DAI& end,
int artificialOffset = 0)
774 _indexOffset.push_back(artificialOffset);
776 for (DAI i=_begin; i != _end; ++i, ++k)
779 _itbegins.push_back(i->begin());
780 _itends.push_back(i->end());
783 _indexOffset.push_back(_indexOffset.back() + i->totalsize());
786 _shiftmapping[i->shift().to_ulong()] = k;
788 _indexOffset.resize(_itends.size());
796 std::array<int,StaticPower<2,dim>::power> _shiftmapping;
797 std::vector<typename YGridComponent<Coordinates>::Iterator> _itbegins;
798 std::vector<typename YGridComponent<Coordinates>::Iterator> _itends;
799 std::vector<int> _indexOffset;
803 template <class Coordinates>
804 inline std::ostream& operator<< (std::ostream& s, const YGrid<Coordinates>& e)
806 s << "Printing YGrid structure:" << std::endl;
807 for (auto it = e.dataBegin(); it != e.dataEnd(); ++it)
808 s << *it << std::endl;
819 template<class Coordinates>
823 static const int dim = Coordinates::dimension;
829 YGridComponent<Coordinates> grid;
835 YGrid<Coordinates> yg;
839 typedef typename std::array<std::deque<Intersection>, StaticPower<2,dim>::power>::iterator DAI;
848 Iterator(const YGridList<Coordinates>& ygl, bool end=false) : _end(ygl.dataEnd()), _which(ygl.dataBegin())
850 _it = _which->begin();
854 while ((_which != _end) && (_it == _which->end()))
858 _it = _which->begin();
868 Iterator& operator++ ()
873 while ((_which != _end) && (_it == _which->end()))
877 _it = _which->begin();
883 typename std::deque<Intersection>::iterator operator->() const
889 typename std::deque<Intersection>::iterator operator*() const
895 bool operator== (const Iterator& i) const
897 if (_which != i._which)
905 bool operator!= (const Iterator& i) const
907 if (_which != i._which)
915 typename std::deque<Intersection>::iterator _it;
921 Iterator begin() const
923 return Iterator(*this);
929 return Iterator(*this,true);
933 void setBegin(typename std::array<std::deque<Intersection>, StaticPower<2,dim>::power>::iterator begin)
939 DAI dataBegin() const
954 for (DAI it = _begin; it != _end; ++it)
960 void finalize(DAI end, const YGrid<Coordinates>& ygrid)
980 while (i != _end && i->begin() == i->end())
983 for (auto yit = ygrid.dataBegin(); yit != ygrid.dataEnd(); ++yit)
987 auto it = i->begin();
988 if (it->grid.shift() == yit->shift())
991 for (; it != i->end(); ++it)
993 it->yg.setBegin(&(it->grid));
994 it->yg.finalize(&(it->grid)+1, offset);
999 while (i != _end && i->begin() == i->end())
1005 for (
int j=0; j<dim; j++)
1006 add *= yit->supersize(j);
YGridComponent(iTupel origin, iTupel size, const YGridComponent< Coordinates > &enclosing)
make a subgrid by taking coordinates from a larger grid
Definition: ygrid.hh:105
Iterator()
Definition: ygrid.hh:298
int superincrement(int i) const
Definition: ygrid.hh:478
fTupel upperright() const
Return upper right corder of the entity associated with the current coordinates and shift...
Definition: ygrid.hh:424
std::array< std::deque< Intersection >, StaticPower< 2, dim >::power >::iterator DAI
Definition: ygrid.hh:839
Coordinates * getCoords() const
Definition: ygrid.hh:164
Coordinates::ctype lowerleft(int i) const
Definition: ygrid.hh:640
Iterator begin(const std::array< int, dim > &coord, int which=0) const
return iterator pointint to a specified position
Definition: ygrid.hh:751
const iTupel & supersize() const
return size of enclosing grid
Definition: ygrid.hh:188
bool shift(int i) const
return the shift in direction i
Definition: ygrid.hh:673
void move(int i, int dist)
move the grid, this is only done and needed for codim 0
Definition: ygrid.hh:722
FieldVector< ct, d > fTupel
Definition: ygrid.hh:79
fTupel meshsize() const
Return meshsize of current cell as reference.
Definition: ygrid.hh:439
int index(const iTupel &coord) const
given a tupel compute its index in the lexicographic numbering
Definition: ygrid.hh:249
iTupel _coord
current position in index set
Definition: ygrid.hh:463
void move(const iTupel &dist)
move this iterator dist cells in direction i
Definition: ygrid.hh:366
std::array< int, d > iTupel
Definition: ygrid.hh:78
fTupel lowerleft() const
Return lower left corner of the entity associated with the current coordinates and shift...
Definition: ygrid.hh:406
int superindex() const
return the superindex
Definition: ygrid.hh:685
int size(int i) const
return size in direction i
Definition: ygrid.hh:194
Iterator end() const
return subiterator to last element of index set
Definition: ygrid.hh:496
int offset(int i) const
Return offset to origin of enclosing grid.
Definition: ygrid.hh:170
bool operator!=(const Iterator &i) const
compare two iterators: component has to match
Definition: ygrid.hh:708
int shiftmapping(const std::bitset< dim > &shift) const
get which component belongs to a given shift vector
Definition: ygrid.hh:564
Coordinates::ctype meshsize(int i) const
return the current meshsize in direction i
Definition: ygrid.hh:661
const std::array< int, dim > & coord() const
return coordinate array at the current position
Definition: ygrid.hh:635
void setBegin(DAI begin)
set start iterator in the data array
Definition: ygrid.hh:558
Coordinates * coordCont() const
Definition: ygrid.hh:732
ct meshsize(int i) const
Return meshsize in direction i.
Definition: ygrid.hh:433
std::bitset< dim > shift() const
return the shift vector
Definition: ygrid.hh:679
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:268
YGridComponent(iTupel origin, std::bitset< d > shift, Coordinates *coords, iTupel size, iTupel offset, iTupel supersize)
Make YGridComponent by giving all parameters.
Definition: ygrid.hh:128
implements a collection of YGridComponents which form a codimension Entities of given codimension c n...
Definition: ygrid.hh:547
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
Dune::FieldVector< typename Coordinates::ctype, dim > meshsize() const
return the current meshsize vector
Definition: ygrid.hh:667
bool empty() const
Return true if YGrid is empty, i.e. has size 0 in all directions.
Definition: ygrid.hh:227
YGridComponent< Coordinates > * DAI
Definition: ygrid.hh:553
YGridComponent< Coordinates > move(iTupel v) const
return grid moved by the vector v
Definition: ygrid.hh:260
void reinit(const YGridComponent< Coordinates > &r, const iTupel &coord)
reinitialize iterator to given position
Definition: ygrid.hh:314
Coordinates * coordCont() const
Definition: ygrid.hh:457
const YGridComponent< Coordinates > * _grid
Definition: ygrid.hh:465
Iterator begin() const
return begin iterator for the codimension and partition the ygrid represents
Definition: ygrid.hh:745
Coordinates::ctype ct
Definition: ygrid.hh:75
int coord(int i) const
Return coordinate of the cell in direction i.
Definition: ygrid.hh:347
bool inside(const iTupel &coord) const
given a coordinate, return true if it is in the grid
Definition: ygrid.hh:238
int max(int i) const
Return maximum index in direction i.
Definition: ygrid.hh:221
int min(int i) const
Return minimum index in direction i.
Definition: ygrid.hh:215
int supersize(int i) const
return size of enclosing grid
Definition: ygrid.hh:182
void move(int i, int dist)
move this iterator dist cells in direction i
Definition: ygrid.hh:359
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:621
Dune::FieldVector< typename Coordinates::ctype, dim > lowerleft() const
Definition: ygrid.hh:645
Dune::FieldVector< typename Coordinates::ctype, dim > upperright() const
Definition: ygrid.hh:655
YGridComponent(iTupel origin, iTupel size)
make ygrid without coordinate information
Definition: ygrid.hh:96
ct upperright(int i) const
Return ith component of upper right corder of the entity associated with the current coordinates and ...
Definition: ygrid.hh:415
bool shift(int i) const
Definition: ygrid.hh:447
std::array< int, dim > iTupel
Definition: ygrid.hh:555
int which() const
return the current component number
Definition: ygrid.hh:716
bool shift(int i) const
Return shift in direction i.
Definition: ygrid.hh:153
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:400
Iterator(const YGrid< Coordinates > &yg, bool end=false)
create an iterator to start or end of the codimension
Definition: ygrid.hh:606
void move(const iTupel &dist)
Definition: ygrid.hh:727
Iterator(const YGridComponent< Coordinates > &r)
Make iterator pointing to first cell in a grid.
Definition: ygrid.hh:301
int superindex() const
Return consecutive index in enclosing grid.
Definition: ygrid.hh:341
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:582
Coordinates::ctype upperright(int i) const
Definition: ygrid.hh:650
const iTupel & origin() const
return reference to origin
Definition: ygrid.hh:147
DAI dataEnd() const
get end iterator in the data array
Definition: ygrid.hh:576
Include standard header files.
Definition: agrid.hh:59
Iterator(const YGridComponent< Coordinates > &r, const iTupel &coord)
Make iterator pointing to given cell in a grid.
Definition: ygrid.hh:308
bool operator==(const Iterator &i) const
compare two iterators: component has to match
Definition: ygrid.hh:700
DAI dataBegin() const
get start iterator in the data array
Definition: ygrid.hh:570
Iterator over a collection o YGrids A YGrid::Iterator is the heart of an entity in YaspGrid...
Definition: ygrid.hh:590
int _superindex
consecutive index in enclosing grid
Definition: ygrid.hh:464
std::array< int, d > sizeArray(const std::array< std::vector< ct >, d > &v)
Definition: ygrid.hh:26
void finalize(const DAI &end, int artificialOffset=0)
Definition: ygrid.hh:769
Iterator(const YGrid< Coordinates > &yg, const std::array< int, dim > &coords, int which=0)
construct an iterator from coordinates and component
Definition: ygrid.hh:599
Iterator()
default constructor
Definition: ygrid.hh:595
const iTupel & offset() const
Return offset to origin of enclosing grid.
Definition: ygrid.hh:176
int totalsize() const
Return total size of index set which is the product of all size per direction.
Definition: ygrid.hh:206
int superindex(const iTupel &coord, int which) const
Definition: ygrid.hh:762
std::bitset< d > shift() const
Definition: ygrid.hh:452
const iTupel & coord() const
Return coordinate of the cell as reference (do not modify).
Definition: ygrid.hh:353
Iterator begin() const
return iterator to first element of index set
Definition: ygrid.hh:484
int coord(int i) const
return coordinate at the current position (direction i)
Definition: ygrid.hh:629
Iterator end() const
return end iterator for the codimension and partition the ygrid represents
Definition: ygrid.hh:757
int superindex(iTupel coord) const
Definition: ygrid.hh:469
iTupel size() const
retrun size
Definition: ygrid.hh:200
Iterator begin(const iTupel &co) const
return iterator to given element of index set
Definition: ygrid.hh:490
const std::bitset< d > & shift() const
Return shift tupel.
Definition: ygrid.hh:159
YGridComponent()
make uninitialized ygrid
Definition: ygrid.hh:82
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:335
int origin(int i) const
Return origin in direction i.
Definition: ygrid.hh:141