Dune Core Modules (2.9.0)

topology.hh
Go to the documentation of this file.
1#ifndef DUNE_SPGRID_TOPOLOGY_HH
2#define DUNE_SPGRID_TOPOLOGY_HH
3
4#include <cassert>
5#include <iostream>
6#include <limits>
7
13namespace Dune
14{
15
16 // SPTopology
17 // ----------
18
29 template< int dim >
31 {
32 typedef SPTopology< dim > This;
33
34 public:
36 static const int dimension = dim;
37
39 static const int numFaces = 2*dimension;
40
46 explicit SPTopology ( const unsigned int periodic = 0 );
47
48 SPTopology ( const This &other );
49
50 ~SPTopology ();
51
52 const This &operator= ( const This &other );
53
55 unsigned int numNodes () const { return data_[ 0 ]; }
56
64 bool hasNeighbor ( const unsigned int node, const int face ) const;
65
76 unsigned int neighbor ( const unsigned int node, const int face ) const;
77
86 bool periodic ( const int i ) const;
87
94 unsigned int periodic () const;
95
96 private:
97 unsigned int &refCount () const { return data_[ 1 ]; }
98 unsigned int &nb ( const unsigned int node, const int face );
99
100 unsigned int *data_;
101 };
102
103
104
105 // Implementation of SPTopology
106 // ----------------------------
107
108 template< int dim >
109 inline SPTopology< dim >::SPTopology ( const unsigned int periodic )
110 {
111 const unsigned int numNodes = 1;
112 data_ = new unsigned int[ 2 + numFaces*numNodes ];
113 data_[ 0 ] = numNodes;
114 refCount() = 1;
115
116 const unsigned int max = std::numeric_limits< unsigned int >::max();
117 for( int i = 0; i < dimension; ++i )
118 {
119 const unsigned int b = (periodic >> i) & 1;
120 nb( 0, 2*i ) = nb( 0, 2*i+1 ) = (1-b)*max;
121 }
122 }
123
124
125 template< int dim >
126 inline SPTopology< dim >::SPTopology ( const This &other )
127 : data_( other.data_ )
128 {
129 ++refCount();
130 }
131
132
133 template< int dim >
134 inline SPTopology< dim >::~SPTopology ()
135 {
136 if( --refCount() == 0 )
137 delete[] data_;
138 }
139
140
141 template< int dim >
142 inline const typename SPTopology< dim >::This &
143 SPTopology< dim >::operator= ( const This &other )
144 {
145 ++other.refCount();
146 if( --refCount() == 0 )
147 delete[] data_;
148 data_ = other.data_;
149 return *this;
150 }
151
152
153 template< int dim >
154 inline bool SPTopology< dim >::hasNeighbor ( const unsigned int node, const int face ) const
155 {
156 return (neighbor( node, face ) < numNodes());
157 }
158
159
160 template< int dim >
161 inline unsigned int SPTopology< dim >::neighbor ( const unsigned int node, const int face ) const
162 {
163 assert( node < numNodes() );
164 assert( (face >= 0) && (face < numFaces) );
165 return data_[ node * numFaces + face + 2 ];
166 }
167
168
169 template< int dim >
170 inline bool SPTopology< dim >::periodic ( const int i ) const
171 {
172 assert( numNodes() == 1 );
173 assert( (i >= 0) && (i < dimension) );
174 return (neighbor( 0, 2*i ) == 0);
175 }
176
177
178 template< int dim >
179 inline unsigned int SPTopology< dim >::periodic () const
180 {
181 unsigned int p = 0;
182 for( int i = 0; i < dimension; ++i )
183 p |= (1u << i) * (unsigned int)periodic( i );
184 return p;
185 }
186
187
188 template< int dim >
189 inline unsigned int &
190 SPTopology< dim >::nb ( const unsigned int node, const int face )
191 {
192 assert( node < numNodes() );
193 assert( (face >= 0) && (face < numFaces) );
194 return data_[ node * numFaces + face + 2 ];
195 }
196
197
198
199 // Auxilliary Functions for SPTopology
200 // -----------------------------------
201
202 template< class char_type, class traits, int dim >
203 inline std::basic_ostream< char_type, traits > &
204 operator<< ( std::basic_ostream< char_type, traits > &out,
205 const SPTopology< dim > &topology )
206 {
207 typedef SPTopology< dim > Topology;
208
209 const unsigned int numNodes = topology().numNodes();
210 out << numNodes;
211 for( unsigned int node = 0; node < numNodes; ++node )
212 {
213 out << " [";
214 for( int face = 0; face < Topology::numFaces; ++face )
215 {
216 if( topology.hasNeighbor( node, face ) )
217 out << " " << topology.neighbor( node, face );
218 else
219 out << " *";
220 }
221 out << " ]";
222 }
223 return out;
224 }
225
226
227 template< class char_type, class traits, int dim >
228 inline std::basic_ostream< char_type, traits > &
229 operator>> ( std::basic_istream< char_type, traits > &in,
230 SPTopology< dim > &topology )
231 {
232 //unsigned int numNodes = 0;
233 //in >> numNodes;
234 return in;
235 }
236
237} // namespace Dune
238
239#endif // #ifndef DUNE_SPGRID_TOPOLOGY_HH
description of the grid's topology
Definition: topology.hh:31
bool periodic(const int i) const
determine whether a direction is periodic
Definition: topology.hh:170
static const int dimension
dimension of the domain
Definition: topology.hh:36
static const int numFaces
number of faces of a cube
Definition: topology.hh:39
unsigned int numNodes() const
number of cubes forming this topology
Definition: topology.hh:55
unsigned int neighbor(const unsigned int node, const int face) const
obtain neighbor of a node over a face
Definition: topology.hh:161
SPTopology(const unsigned int periodic=0)
constructor
Definition: topology.hh:109
unsigned int periodic() const
obtain the periodicity bit field
Definition: topology.hh:179
bool hasNeighbor(const unsigned int node, const int face) const
check whether a node has a neighbor over a face
Definition: topology.hh:154
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
auto periodic(RawPreBasisIndicator &&rawPreBasisIndicator, PIS &&periodicIndexSet)
Create a pre-basis factory that can create a periodic pre-basis.
Definition: periodicbasis.hh:191
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)