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 <climits>
73#include <vector>
74
76namespace Dune
77{
78
79 namespace cpgrid
80 {
81
95
96 template <int codim>
98 {
99 public:
100 enum{ codimension=codim};
101
104 : entityrep_(0)
105 {
106 }
110 EntityRep(int index_arg, bool orientation_arg)
111 : entityrep_(orientation_arg ? index_arg : ~index_arg)
112 {
113 assert(index_arg >= 0);
114 }
118 void setValue(int index_arg, bool orientation_arg)
119 {
120 assert(index_arg >= 0);
121 entityrep_ = orientation_arg ? index_arg : ~index_arg;
122 }
125 int index() const
126 {
127 return entityrep_ < 0 ? ~entityrep_ : entityrep_;
128 }
129
134 bool isValid() const
135 {
136 return index() != InvalidIndex;
137 }
138
140 int signedIndex() const
141 {
142 return entityrep_;
143 }
148 bool orientation() const
149 {
150 return entityrep_ >= 0;
151 }
152
156 {
157 return EntityRep(~entityrep_);
158 }
159
162 {
163 if (entityrep_ < 0) {
164 --entityrep_;
165 } else {
166 ++entityrep_;
167 }
168 }
169
175 bool operator<(const EntityRep& other) const
176 {
177 int i1 = index();
178 int i2 = other.index();
179 if (i1 < i2) return true;
180 if (orientation() && !other.orientation()) return true;
181 return false;
182 }
183
187 bool operator==(const EntityRep& other) const
188 {
189 return entityrep_ == other.entityrep_;
190 }
191
195 bool operator!=(const EntityRep& other) const
196 {
197 return !operator==(other);
198 }
199
201 enum { InvalidIndex = INT_MAX };
202
203 private:
211 explicit EntityRep(int erep)
212 : entityrep_(erep)
213 {
214 }
215
216 // Interior representation is documented in class main comment.
217 int entityrep_;
218 };
219
220
221
226 template <typename T>
227 class EntityVariableBase : private std::vector<T>
228 {
229 friend class CpGridData;
230 public:
231 typedef std::vector<T> V;
232 typedef typename std::vector<T>::iterator iterator;
233 typedef typename std::vector<T>::const_iterator const_iterator;
234
235 using V::empty;
236 using V::size;
237 using V::assign;
238 using V::begin;
239 using V::end;
240 using typename V::value_type;
241 using V::reserve;
242 using V::push_back;
243 using V::data;
244 using V::operator[];
245 using V::resize;
246
249 {
250 }
251
252 const T& get(int i) const
253 {
254 return V::operator[](i);
255 }
256
257 T& get(int i)
258 {
259 return V::operator[](i);
260 }
261
263 {
264 V::swap(static_cast<V&>(other));
265 }
266
267 };
268
269
270
271
279 template <typename T, int codim>
281 {
282 public:
285 {
286 }
290 const T& operator[](const EntityRep<codim>& e) const
291 {
293 }
298 {
300 }
301 };
302
303
304
305
306
314 template <typename T, int codim>
316 {
317 public:
320 {
321 }
325 const T operator[](const EntityRep<codim>& e) const
326 {
327 return e.orientation() ?
330 }
331 };
332
333
334 } // namespace cpgrid
335} // namespace Dune
336
337
338
339
340#endif // OPM_ENTITYREP_HEADER
DataHandle & data
Definition: CpGridData.hpp:1136
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:117
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:98
bool operator<(const EntityRep &other) const
Ordering relation used for maps etc.
Definition: EntityRep.hpp:175
EntityRep(int index_arg, bool orientation_arg)
Constructor taking an entity index and an orientation.
Definition: EntityRep.hpp:110
bool operator!=(const EntityRep &other) const
Inequality operator.
Definition: EntityRep.hpp:195
bool orientation() const
Returns true if the entity has positive orientation. Not a Dune interface method.
Definition: EntityRep.hpp:148
@ InvalidIndex
Definition: EntityRep.hpp:201
void setValue(int index_arg, bool orientation_arg)
Set entity value.
Definition: EntityRep.hpp:118
EntityRep opposite() const
Returns an EntityRep with opposite orientation.
Definition: EntityRep.hpp:155
@ codimension
Definition: EntityRep.hpp:100
bool operator==(const EntityRep &other) const
Equality operator.
Definition: EntityRep.hpp:187
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:125
EntityRep()
Default constructor.
Definition: EntityRep.hpp:103
bool isValid() const
Whether this representation has a local entity index. InvalidIndex marks absent entities,...
Definition: EntityRep.hpp:134
int signedIndex() const
The signed index that also tells us the orientation.
Definition: EntityRep.hpp:140
void increment()
Increments the entityrep's index() by one.
Definition: EntityRep.hpp:161
Base class for EntityVariable and SignedEntityVariable. Forwards a restricted subset of the std::vect...
Definition: EntityRep.hpp:228
T & get(int i)
Definition: EntityRep.hpp:257
std::vector< T >::iterator iterator
Definition: EntityRep.hpp:232
std::vector< T > V
Definition: EntityRep.hpp:231
const T & get(int i) const
Definition: EntityRep.hpp:252
std::vector< T >::const_iterator const_iterator
Definition: EntityRep.hpp:233
EntityVariableBase()
Default constructor.
Definition: EntityRep.hpp:248
void swap(EntityVariableBase &other)
Definition: EntityRep.hpp:262
A class design to hold a variable with a value for each entity of the given codimension,...
Definition: EntityRep.hpp:281
const T & operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:290
T & operator[](const EntityRep< codim > &e)
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:297
EntityVariable()
Default constructor.
Definition: EntityRep.hpp:284
A class design to hold a variable with a value for each entity of the given codimension,...
Definition: EntityRep.hpp:316
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:325
SignedEntityVariable()
Default constructor.
Definition: EntityRep.hpp:319
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