My Project
EntityRep.hpp
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.
49#include <opm/grid/utility/platform_dependent/disable_warnings.h>
50#include <dune/common/fvector.hh>
51#include <opm/grid/utility/platform_dependent/reenable_warnings.h>
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/grid/utility/ErrorMacros.hpp>
73#include <climits>
74#include <vector>
75
77namespace Dune
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
131 int signedIndex() const
132 {
133 return entityrep_;
134 }
139 bool orientation() const
140 {
141 return entityrep_ >= 0;
142 }
143
147 {
148 return EntityRep(~entityrep_);
149 }
150
153 {
154 if (entityrep_ < 0) {
155 --entityrep_;
156 } else {
157 ++entityrep_;
158 }
159 }
160
166 bool operator<(const EntityRep& other) const
167 {
168 int i1 = index();
169 int i2 = other.index();
170 if (i1 < i2) return true;
171 if (orientation() && !other.orientation()) return true;
172 return false;
173 }
174
178 bool operator==(const EntityRep& other) const
179 {
180 return entityrep_ == other.entityrep_;
181 }
182
186 bool operator!=(const EntityRep& other) const
187 {
188 return !operator==(other);
189 }
190
191 enum { InvalidIndex = INT_MAX };
192
193 private:
201 explicit EntityRep(int erep)
202 : entityrep_(erep)
203 {
204 }
205
206 // Interior representation is documented in class main comment.
207 int entityrep_;
208 };
209
210
211
216 template <typename T>
217 class EntityVariableBase : private std::vector<T>
218 {
219 friend class CpGridData;
220 public:
221 typedef std::vector<T> V;
222 typedef typename std::vector<T>::iterator iterator;
223 typedef typename std::vector<T>::const_iterator const_iterator;
224
225 using V::empty;
226 using V::size;
227 using V::assign;
228 using V::begin;
229 using V::end;
230 using typename V::value_type;
231 using V::reserve;
232 using V::push_back;
233 using V::data;
234
237 {
238 }
239
240 const T& get(int i) const
241 {
242 return V::operator[](i);
243 }
244
245 T& get(int i)
246 {
247 return V::operator[](i);
248 }
249
250 };
251
252
253
254
262 template <typename T, int codim>
264 {
265 public:
268 {
269 }
273 const T& operator[](const EntityRep<codim>& e) const
274 {
276 }
281 {
283 }
284 };
285
286
287
288
289
297 template <typename T, int codim>
299 {
300 public:
303 {
304 }
308 const T operator[](const EntityRep<codim>& e) const
309 {
310 return e.orientation() ?
313 }
314 };
315
316
317 } // namespace cpgrid
318} // namespace Dune
319
320
321
322
323#endif // OPM_ENTITYREP_HEADER
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:123
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:166
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:186
bool orientation() const
Returns true if the entity has positive orientation.
Definition: EntityRep.hpp:139
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:146
bool operator==(const EntityRep &other) const
Equality operator.
Definition: EntityRep.hpp:178
int index() const
The (positive) index of an entity.
Definition: EntityRep.hpp:125
EntityRep()
Default constructor.
Definition: EntityRep.hpp:103
int signedIndex() const
The signed index that also tells us the orientation.
Definition: EntityRep.hpp:131
void increment()
Increments the entityrep's index() by one.
Definition: EntityRep.hpp:152
Base class for EntityVariable and SignedEntityVariable.
Definition: EntityRep.hpp:218
EntityVariableBase()
Default constructor.
Definition: EntityRep.hpp:236
A class design to hold a variable with a value for each entity of the given codimension,...
Definition: EntityRep.hpp:264
const T & operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:273
T & operator[](const EntityRep< codim > &e)
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:280
EntityVariable()
Default constructor.
Definition: EntityRep.hpp:267
A class design to hold a variable with a value for each entity of the given codimension,...
Definition: EntityRep.hpp:299
const T operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep.
Definition: EntityRep.hpp:308
SignedEntityVariable()
Default constructor.
Definition: EntityRep.hpp:302
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10