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> 13 #include <dune/common/streamoperators.hh> 26 template<
int d,
typename ct>
27 std::array<int,d>
sizeArray(
const std::array<std::vector<ct>,d>& v)
29 std::array<int,d> tmp;
30 for (
int i=0; i<d; ++i)
31 tmp[i] = v[i].size() - 1;
71 template<
class Coordinates>
76 typedef typename Coordinates::ctype
ct;
77 static const int d = Coordinates::dimension;
85 std::fill(_origin.begin(), _origin.end(), 0);
86 std::fill(_offset.begin(), _offset.end(), 0);
87 std::fill(_size.begin(), _size.end(), 0);
98 : _origin(origin), _size(size)
107 : _origin(origin), _shift(enclosing.shift()), _coords(enclosing.getCoords()), _size(size), _supersize(enclosing.supersize())
109 for (
int i=0; i<d; i++)
110 _offset[i] = origin[i] - enclosing.
origin(i) + enclosing.
offset(i);
114 for (
int i=0; i<d; ++i)
116 _superincrement[i] = inc;
117 inc *= _supersize[i];
129 YGridComponent (iTupel origin, std::bitset<d> shift, Coordinates* coords, iTupel size, iTupel offset, iTupel supersize)
130 : _origin(origin), _shift(shift), _coords(coords), _size(size), _offset(offset), _supersize(supersize)
134 for (
int i=0; i<d; ++i)
136 _superincrement[i] = inc;
137 inc *= _supersize[i];
160 const std::bitset<d>&
shift ()
const 185 return _supersize[i];
210 for (
int i=0; i<d; ++i)
224 return _origin[i] + size(i) - 1;
230 for (
int i=0; i<d; ++i)
241 for (
int i=0; i<d; i++)
243 if ((coord[i]<_origin[i]) || (coord[i]>=_origin[i]+_size[i]))
250 int index (
const iTupel& coord)
const 252 int index = (coord[d-1]-_origin[d-1]);
254 for (
int i=d-2; i>=0; i--)
255 index = index*_size[i] + (coord[i]-_origin[i]);
263 for (
int i=0; i<d; i++)
271 for (
int i=0; i<d; i++)
274 if (empty() || r.
empty())
280 for (
int i=0; i<d; ++i)
318 for (
int i=0; i<d; ++i)
319 _coord[i] = coord[i];
323 for (
int i=0; i<d; ++i)
363 _superindex += dist*_grid->superincrement(i);
369 for (
int i = 0; i < d; ++i)
371 _coord[i] += dist[i];
372 _superindex += dist[i]*_grid->superincrement(i);
379 for (
int i=0; i<d; i++)
381 _superindex += _grid->superincrement(i);
382 if (++_coord[i] <= _grid->max(i))
386 _coord[i] = _grid->origin(i);
387 _superindex -= _grid->size(i) * _grid->superincrement(i);
391 if (_coord == _grid->origin())
393 for (
int i=0; i<d; i++)
394 _superindex += (_grid->size(i)-1) * _grid->superincrement(i);
395 _superindex += _grid->superincrement(0);
403 return _grid->getCoords()->coordinate(i,_coord[i]);
410 for (
int i=0; i<d; i++)
411 ll[i] = lowerleft(i);
418 int coord = _coord[i];
421 return _grid->getCoords()->coordinate(i,coord);
428 for (
int i=0; i<d; i++)
429 ur[i] = upperright(i);
436 return _grid->getCoords()->meshsize(i,_coord[i]);
443 for (
int i=0; i<d; i++)
450 return _grid->shift(i);
455 return _grid->shift();
460 return _grid->getCoords();
474 for (
int i=0; i<d; ++i)
475 si += (offset(i)+coord[i]-origin(i))*_superincrement[i];
481 return _superincrement[i];
500 for (
int i=0; i<d; i++)
508 std::bitset<d> _shift;
509 Coordinates* _coords;
513 iTupel _superincrement;
519 template <
class Coordinates>
520 inline std::ostream& operator<< (std::ostream& s, YGridComponent<Coordinates> e)
522 s <<
"Printing YGridComponent structure:" << std::endl;
523 s <<
"Origin: " << e.origin() << std::endl;
524 s <<
"Shift: " << e.shift() << std::endl;
525 s <<
"Size: " << e.size() << std::endl;
526 s <<
"Offset: " << e.offset() << std::endl;
527 s <<
"Supersize: " << e.supersize() << std::endl;
532 template <
class Coordinates>
533 inline std::ostream& operator<< (std::ostream& s, typename YGridComponent<Coordinates>::Iterator& e)
535 s <<
"Printing YGridComponent Iterator:" << std::endl <<
"Iterator at " << e.coord() <<
" (index ";
536 s << e.index() <<
"), position " << e.position();
547 template<
class Coordinates>
551 static const int dim = Coordinates::dimension;
556 typedef typename std::array<int, dim>
iTupel;
567 return _shiftmapping[shift.to_ulong()];
583 bool inside(
const iTupel& coord,
const std::bitset<dim>& shift = std::bitset<dim>())
const 585 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();
739 unsigned int _which = 0;
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);
int totalsize() const
Return total size of index set which is the product of all size per direction.
Definition: ygrid.hh:207
void move(const iTupel &dist)
move this iterator dist cells in direction i
Definition: ygrid.hh:367
int size(int i) const
return size in direction i
Definition: ygrid.hh:195
Coordinates::ctype lowerleft(int i) const
Definition: ygrid.hh:640
Dune::FieldVector< typename Coordinates::ctype, dim > meshsize() const
return the current meshsize vector
Definition: ygrid.hh:667
const std::bitset< d > & shift() const
Return shift tupel.
Definition: ygrid.hh:160
YGridComponent(iTupel origin, iTupel size, const YGridComponent< Coordinates > &enclosing)
make a subgrid by taking coordinates from a larger grid
Definition: ygrid.hh:106
int superindex(iTupel coord) const
Definition: ygrid.hh:470
Coordinates * getCoords() const
Definition: ygrid.hh:165
YGridComponent(iTupel origin, std::bitset< d > shift, Coordinates *coords, iTupel size, iTupel offset, iTupel supersize)
Make YGridComponent by giving all parameters.
Definition: ygrid.hh:129
fTupel upperright() const
Return upper right corder of the entity associated with the current coordinates and shift...
Definition: ygrid.hh:425
Iterator(const YGrid< Coordinates > &yg, bool end=false)
create an iterator to start or end of the codimension
Definition: ygrid.hh:606
int superindex() const
Return consecutive index in enclosing grid.
Definition: ygrid.hh:342
std::array< int, dim > iTupel
Definition: ygrid.hh:556
YGridComponent< Coordinates > * DAI
Definition: ygrid.hh:554
std::array< std::deque< Intersection >, StaticPower< 2, dim >::power >::iterator DAI
Definition: ygrid.hh:839
bool shift(int i) const
return the shift in direction i
Definition: ygrid.hh:673
void setBegin(DAI begin)
set start iterator in the data array
Definition: ygrid.hh:559
DAI dataEnd() const
get end iterator in the data array
Definition: ygrid.hh:577
fTupel lowerleft() const
Return lower left corner of the entity associated with the current coordinates and shift...
Definition: ygrid.hh:407
iTupel _coord
current position in index set
Definition: ygrid.hh:464
YGridComponent< Coordinates > move(iTupel v) const
return grid moved by the vector v
Definition: ygrid.hh:261
int shiftmapping(const std::bitset< dim > &shift) const
get which component belongs to a given shift vector
Definition: ygrid.hh:565
Coordinates::ctype ct
Definition: ygrid.hh:76
Iterator over a collection o YGrids A YGrid::Iterator is the heart of an entity in YaspGrid...
Definition: ygrid.hh:591
bool inside(const iTupel &coord) const
given a coordinate, return true if it is in the grid
Definition: ygrid.hh:239
int min(int i) const
Return minimum index in direction i.
Definition: ygrid.hh:216
void finalize(const DAI &end, int artificialOffset=0)
Definition: ygrid.hh:769
bool shift(int i) const
Definition: ygrid.hh:448
int index(const iTupel &coord) const
given a tupel compute its index in the lexicographic numbering
Definition: ygrid.hh:250
int offset(int i) const
Return offset to origin of enclosing grid.
Definition: ygrid.hh:171
bool empty() const
Return true if YGrid is empty, i.e. has size 0 in all directions.
Definition: ygrid.hh:228
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
void reinit(const YGridComponent< Coordinates > &r, const iTupel &coord)
reinitialize iterator to given position
Definition: ygrid.hh:315
bool operator==(const Iterator &i) const
compare two iterators: component has to match
Definition: ygrid.hh:700
std::array< int, d > iTupel
Definition: ygrid.hh:79
Coordinates::ctype upperright(int i) const
Definition: ygrid.hh:650
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:401
int max(int i) const
Return maximum index in direction i.
Definition: ygrid.hh:222
Iterator end() const
return end iterator for the codimension and partition the ygrid represents
Definition: ygrid.hh:757
const std::array< int, dim > & coord() const
return coordinate array at the current position
Definition: ygrid.hh:635
ct meshsize(int i) const
Return meshsize in direction i.
Definition: ygrid.hh:434
int supersize(int i) const
return size of enclosing grid
Definition: ygrid.hh:183
Iterator end() const
return subiterator to last element of index set
Definition: ygrid.hh:497
implements a collection of YGridComponents which form a codimension Entities of given codimension c n...
Definition: ygrid.hh:548
int coord(int i) const
Return coordinate of the cell in direction i.
Definition: ygrid.hh:348
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:269
int superindex(const iTupel &coord, int which) const
Definition: ygrid.hh:762
bool shift(int i) const
Return shift in direction i.
Definition: ygrid.hh:154
Coordinates * coordCont() const
Definition: ygrid.hh:458
int _superindex
consecutive index in enclosing grid
Definition: ygrid.hh:465
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:335
const iTupel & origin() const
return reference to origin
Definition: ygrid.hh:148
YGridComponent(iTupel origin, iTupel size)
make ygrid without coordinate information
Definition: ygrid.hh:97
void move(int i, int dist)
move the grid, this is only done and needed for codim 0
Definition: ygrid.hh:722
ct upperright(int i) const
Return ith component of upper right corder of the entity associated with the current coordinates and ...
Definition: ygrid.hh:416
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 > upperright() const
Definition: ygrid.hh:655
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
Coordinates::ctype meshsize(int i) const
return the current meshsize in direction i
Definition: ygrid.hh:661
std::bitset< dim > shift() const
return the shift vector
Definition: ygrid.hh:679
int superindex() const
return the superindex
Definition: ygrid.hh:685
fTupel meshsize() const
Return meshsize of current cell as reference.
Definition: ygrid.hh:440
int which() const
return the current component number
Definition: ygrid.hh:716
void move(int i, int dist)
move this iterator dist cells in direction i
Definition: ygrid.hh:360
int coord(int i) const
return coordinate at the current position (direction i)
Definition: ygrid.hh:629
Iterator begin(const iTupel &co) const
return iterator to given element of index set
Definition: ygrid.hh:491
void move(const iTupel &dist)
Definition: ygrid.hh:727
std::bitset< d > shift() const
Definition: ygrid.hh:453
Iterator(const YGridComponent< Coordinates > &r, const iTupel &coord)
Make iterator pointing to given cell in a grid.
Definition: ygrid.hh:309
int origin(int i) const
Return origin in direction i.
Definition: ygrid.hh:142
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:583
DAI dataBegin() const
get start iterator in the data array
Definition: ygrid.hh:571
int superincrement(int i) const
Definition: ygrid.hh:479
Iterator begin(const std::array< int, dim > &coord, int which=0) const
return iterator pointint to a specified position
Definition: ygrid.hh:751
Iterator begin() const
return begin iterator for the codimension and partition the ygrid represents
Definition: ygrid.hh:745
const iTupel & coord() const
Return coordinate of the cell as reference (do not modify).
Definition: ygrid.hh:354
iTupel size() const
retrun size
Definition: ygrid.hh:201
const iTupel & supersize() const
return size of enclosing grid
Definition: ygrid.hh:189
YGridComponent()
make uninitialized ygrid
Definition: ygrid.hh:83
FieldVector< ct, d > fTupel
Definition: ygrid.hh:80
const iTupel & offset() const
Return offset to origin of enclosing grid.
Definition: ygrid.hh:177
Coordinates * coordCont() const
Definition: ygrid.hh:732
Iterator(const YGridComponent< Coordinates > &r)
Make iterator pointing to first cell in a grid.
Definition: ygrid.hh:302
bool operator!=(const Iterator &i) const
compare two iterators: component has to match
Definition: ygrid.hh:708
Dune::FieldVector< typename Coordinates::ctype, dim > lowerleft() const
Definition: ygrid.hh:645
std::array< int, d > sizeArray(const std::array< std::vector< ct >, d > &v)
Definition: ygrid.hh:27
Iterator begin() const
return iterator to first element of index set
Definition: ygrid.hh:485
Include standard header files.
Definition: agrid.hh:58