Iterators.hpp
1 //===========================================================================
2 //
3 // File: Iterators.hpp
4 //
5 // Created: Fri May 29 23:29:09 2009
6 //
7 // Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8 // Bård Skaflestad <bard.skaflestad@sintef.no>
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17 Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
18 Copyright 2009, 2010 Statoil ASA.
19 
20 This file is part of The Open Porous Media project (OPM).
21 
22 OPM is free software: you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation, either version 3 of the License, or
25 (at your option) any later version.
26 
27 OPM is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License
33 along with OPM. If not, see <http://www.gnu.org/licenses/>.
34 */
35 
36 #ifndef OPM_ITERATORS_HEADER
37 #define OPM_ITERATORS_HEADER
38 
39 #include <dune/grid/common/gridenums.hh>
40 #include "PartitionIteratorRule.hpp"
41 #include <opm/grid/utility/ErrorMacros.hpp>
42 
43 namespace Dune
44 {
45  namespace cpgrid
46  {
47  class CpGridData;
48 
49 
54  template<int cd, PartitionIteratorType pitype>
55  class Iterator : public EntityPointer<cd>
56  {
57  public:
61  Iterator(const CpGridData& grid, int index, bool orientation);
62 
70  {
72  if(rule_.fullSet || rule_.emptySet)
73  return *this;
74  while(this->index()<noEntities_ && rule_.isInvalid(*this))
76  return *this;
77  }
78  private:
80  int noEntities_;
82  };
83 
84 
85 
86 
89  {
90  public:
95  : EntityPointer<0>(grid, EntityRep<0>::InvalidIndex, true )
96  {
97  }
98 
103  {
104  OPM_THROW(std::runtime_error, "Calling operator++() on HierarchicIterator for CpGrid, which has no refinement.");
105  return *this;
106  }
107  };
108 
109 
110 
111 
112 
113  } // namespace cpgrid
114 } // namespace Dune
115 
116 namespace std
117 {
118  template< int codim, Dune::PartitionIteratorType pitype >
119  struct iterator_traits< Dune::cpgrid::Iterator< codim, pitype > >
120  {
122  typedef ptrdiff_t difference_type;
123  typedef typename Iterator::Entity value_type;
124  typedef value_type* pointer;
125  typedef value_type& reference;
126  typedef forward_iterator_tag iterator_category;
127  };
128 
129  template <>
130  struct iterator_traits< Dune::cpgrid::HierarchicIterator >
131  {
132  typedef ptrdiff_t difference_type;
134  typedef value_type* pointer;
135  typedef value_type& reference;
136  typedef forward_iterator_tag iterator_category;
137  };
138 
139 } // namespace std
140 
141 
142 #include <dune/grid/cpgrid/CpGridData.hpp>
143 #include "Entity.hpp"
144 
145 namespace Dune {
146 namespace cpgrid {
147 
148 template<int cd, PartitionIteratorType pitype>
149 Iterator<cd, pitype>::Iterator(const CpGridData& grid, int index, bool orientation)
150  : EntityPointer<cd>(grid,
151  // If the partition is empty, goto to end iterator!
152  EntityRep<cd>(PartitionIteratorRule<pitype>::emptySet?grid.size(cd):index,
153  orientation)),
154  noEntities_(grid.size(cd))
155 {
156  if(rule_.fullSet || rule_.emptySet)
157  return;
158 
159  while(this->index()<noEntities_ && rule_.isInvalid(*this))
161 }
162 }}
163 
164 
165 #endif // OPM_ITERATORS_HEADER
Definition: CpGridData.hpp:93
int index() const
The (positive) index of an entity.
Definition: EntityRep.hpp:126
bool orientation() const
Returns true if the entity has positive orientation.
Definition: EntityRep.hpp:135
HierarchicIterator(const CpGridData &grid)
Definition: Iterators.hpp:94
Holds the implementation of the CpGrid as a pimple.
Definition: OpmParserIncludes.hpp:42
Definition: Iterators.hpp:116
HierarchicIterator & operator++()
Definition: Iterators.hpp:102
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:105
Iterator intended to be used as LeafIterator and LevelIterator (no difference due to no adaptivity) f...
Definition: Entity.hpp:52
Iterator & operator++()
Increment operator.
Definition: Iterators.hpp:69
Class representing a pointer to an entity.
Definition: Entity.hpp:50
Only needs to provide interface for doing nothing.
Definition: Iterators.hpp:88
Iterator(const CpGridData &grid, int index, bool orientation)
Definition: Iterators.hpp:149
A rule at what entities to stop.
Definition: PartitionIteratorRule.hpp:41
Represents an entity of a given codim, with positive or negative orientation.
Definition: CpGridData.hpp:94
void increment()
Increments the entityrep&#39;s index() by one.
Definition: EntityRep.hpp:148