EntityRep.hpp
Go to the documentation of this file.
1//===========================================================================
2//
3// File: EntityRep.hpp
4//
5// Created: Tue Jun 9 11:11:24 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_ENTITYREP_HEADER
37#define OPM_ENTITYREP_HEADER
38
39
40// -------------------------------------------------------------------
41// -> Layering violation. --------------------------------------------
42//
43// We need a unary operator-() for class Dune::FieldVector<K,n>
44// within method Dune::SignedEntityVariable<T,codim>::operator[](),
45// but Dune::FieldVector<K,n> does not provide such an operator.
46//
47
48// Warning suppression for Dune includes.
50#include <dune/common/fvector.hh>
52
53namespace Dune
54{
55 template<typename K, int n>
56 FieldVector<K,n>
57 operator- (const FieldVector<K,n>& v)
58 {
59 // Assume 'K' supports a single parameter constructor. The
60 // assumption holds for all standard C++ built-in arithmetic
61 // types such as 'int', 'float', and 'complex<double>'.
62 //
63 return FieldVector<K,n>(K(0)) - v;
64 }
65}
66//
67// <- Layering violation. --------------------------------------------
68// -------------------------------------------------------------------
69
70
71//#include <opm/core/utility/SparseTable.hpp>
72#include <opm/common/ErrorMacros.hpp>
73#include <climits>
74#include <vector>
75
77namespace Dune
78{
79
80 namespace cpgrid
81 {
82
96
97 template <int codim>
99 {
100 public:
101 enum{ codimension=codim};
102
105 : entityrep_(0)
106 {
107 }
111 EntityRep(int index_arg, bool orientation_arg)
112 : entityrep_(orientation_arg ? index_arg : ~index_arg)
113 {
114 assert(index_arg >= 0);
115 }
119 void setValue(int index_arg, bool orientation_arg)
120 {
121 assert(index_arg >= 0);
122 entityrep_ = orientation_arg ? index_arg : ~index_arg;
123 }
126 int index() const
127 {
128 return entityrep_ < 0 ? ~entityrep_ : entityrep_;
129 }
130
132 int signedIndex() const
133 {
134 return entityrep_;
135 }
140 bool orientation() const
141 {
142 return entityrep_ >= 0;
143 }
144
148 {
149 return EntityRep(~entityrep_);
150 }
151
154 {
155 if (entityrep_ < 0) {
156 --entityrep_;
157 } else {
158 ++entityrep_;
159 }
160 }
161
167 bool operator<(const EntityRep& other) const
168 {
169 int i1 = index();
170 int i2 = other.index();
171 if (i1 < i2) return true;
172 if (orientation() && !other.orientation()) return true;
173 return false;
174 }
175
179 bool operator==(const EntityRep& other) const
180 {
181 return entityrep_ == other.entityrep_;
182 }
183
187 bool operator!=(const EntityRep& other) const
188 {
189 return !operator==(other);
190 }
191
192 enum { InvalidIndex = INT_MAX };
193
194 private:
202 explicit EntityRep(int erep)
203 : entityrep_(erep)
204 {
205 }
206
207 // Interior representation is documented in class main comment.
208 int entityrep_;
209 };
210
211
212
217 template <typename T>
218 class EntityVariableBase : private std::vector<T>
219 {
220 friend class CpGridData;
221 public:
222 typedef std::vector<T> V;
223 typedef typename std::vector<T>::iterator iterator;
224 typedef typename std::vector<T>::const_iterator const_iterator;
225
226 using V::empty;
227 using V::size;
228 using V::assign;
229 using V::begin;
230 using V::end;
231 using typename V::value_type;
232 using V::reserve;
233 using V::push_back;
234 using V::data;
235 using V::operator[];
236 using V::resize;
237
240 {
241 }
242
243 const T& get(int i) const
244 {
245 return V::operator[](i);
246 }
247
248 T& get(int i)
249 {
250 return V::operator[](i);
251 }
252
253 };
254
255
256
257
265 template <typename T, int codim>
267 {
268 public:
271 {
272 }
276 const T& operator[](const EntityRep<codim>& e) const
277 {
279 }
284 {
286 }
287 };
288
289
290
291
292
300 template <typename T, int codim>
302 {
303 public:
306 {
307 }
311 const T operator[](const EntityRep<codim>& e) const
312 {
313 return e.orientation() ?
316 }
317 };
318
319
320 } // namespace cpgrid
321} // namespace Dune
322
323
324
325
326#endif // OPM_ENTITYREP_HEADER
DataHandle & data
Definition: CpGridData.hpp:1085
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:131
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:99
bool operator<(const EntityRep &other) const
Ordering relation used for maps etc.
Definition: EntityRep.hpp:167
@ codimension
Definition: EntityRep.hpp:101
EntityRep(int index_arg, bool orientation_arg)
Constructor taking an entity index and an orientation.
Definition: EntityRep.hpp:111
bool operator!=(const EntityRep &other) const
Inequality operator.
Definition: EntityRep.hpp:187
bool orientation() const
Returns true if the entity has positive orientation. Not a Dune interface method.
Definition: EntityRep.hpp:140
void setValue(int index_arg, bool orientation_arg)
Set entity value.
Definition: EntityRep.hpp:119
EntityRep opposite() const
Returns an EntityRep with opposite orientation.
Definition: EntityRep.hpp:147
bool operator==(const EntityRep &other) const
Equality operator.
Definition: EntityRep.hpp:179
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:126
EntityRep()
Default constructor.
Definition: EntityRep.hpp:104
@ InvalidIndex
Definition: EntityRep.hpp:192
int signedIndex() const
The signed index that also tells us the orientation.
Definition: EntityRep.hpp:132
void increment()
Increments the entityrep's index() by one.
Definition: EntityRep.hpp:153
Base class for EntityVariable and SignedEntityVariable. Forwards a restricted subset of the std::vect...
Definition: EntityRep.hpp:219
T & get(int i)
Definition: EntityRep.hpp:248
std::vector< T >::iterator iterator
Definition: EntityRep.hpp:223
std::vector< T > V
Definition: EntityRep.hpp:222
const T & get(int i) const
Definition: EntityRep.hpp:243
std::vector< T >::const_iterator const_iterator
Definition: EntityRep.hpp:224
EntityVariableBase()
Default constructor.
Definition: EntityRep.hpp:239
A class design to hold a variable with a value for each entity of the given codimension,...
Definition: EntityRep.hpp:267
const T & operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:276
T & operator[](const EntityRep< codim > &e)
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:283
EntityVariable()
Default constructor.
Definition: EntityRep.hpp:270
A class design to hold a variable with a value for each entity of the given codimension,...
Definition: EntityRep.hpp:302
const T operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep. Note that this operator always returns a copy,...
Definition: EntityRep.hpp:311
SignedEntityVariable()
Default constructor.
Definition: EntityRep.hpp:305
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
FieldVector< K, n > operator-(const FieldVector< K, n > &v)
Definition: EntityRep.hpp:57