Dune Core Modules (2.6.0)

entitykey_inline.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ENTITYKEY_INLINE_HH
4#define DUNE_ENTITYKEY_INLINE_HH
5
6#include <algorithm>
7#include <dune/geometry/referenceelements.hh>
8#include <dune/grid/io/file/dgfparser/entitykey.hh>
9
10namespace Dune
11{
12
13 // DGFEntityKey
14 // ------------
15
16 template< class A >
17 inline DGFEntityKey< A > :: DGFEntityKey ( const std :: vector< A > &key, bool setOrigKey )
18 : key_( key.size() ),
19 origKey_( key.size() ),
20 origKeySet_( setOrigKey )
21 {
22 for (size_t i=0; i<key_.size(); i++)
23 {
24 key_[i]=key[i];
25 origKey_[i]=key_[i];
26 }
27 std :: sort( key_.begin(), key_.end() );
28 }
29
30
31 template< class A >
32 inline DGFEntityKey< A > :: DGFEntityKey ( const std :: vector< A > &key,
33 int N, int offset, bool setOrigKey )
34 : key_( N ),
35 origKey_( N ),
36 origKeySet_( setOrigKey )
37 {
38 for (size_t i=0; i<key_.size(); i++)
39 {
40 key_[i]=key[(i+offset)%key.size()];
41 origKey_[i]=key[(i+offset)%key.size()];
42 }
43 std :: sort( key_.begin(), key_.end() );
44 }
45
46
47 template< class A >
48 inline DGFEntityKey< A > :: DGFEntityKey ( const DGFEntityKey< A > &k )
49 : key_( k.key_.size() ),
50 origKey_( k.key_.size() ),
51 origKeySet_( k. origKeySet_ )
52 {
53 for (size_t i=0; i<key_.size(); i++)
54 {
55 key_[i]=k.key_[i];
56 origKey_[i]=k.origKey_[i];
57 }
58 }
59
60
61 template< class A >
62 inline DGFEntityKey< A > &DGFEntityKey< A > :: operator= ( const DGFEntityKey< A > &k )
63 {
64 assert(key_.size()==k.key_.size());
65 for (size_t i=0; i<key_.size(); i++) {
66 key_[i]=k.key_[i];
67 origKey_[i]=k.origKey_[i];
68 }
69 origKeySet_ = k.origKeySet_;
70 return *this;
71 }
72
73
74 template< class A >
75 inline void DGFEntityKey< A >
76 :: orientation ( int base, std::vector< std :: vector< double > > &vtx )
77 {
78 if (key_.size()==3) {
79 assert( (size_t) origKey_[0] < vtx.size() );
80 std::vector<double>& p0 = vtx[origKey_[0]];
81 assert( (size_t) origKey_[1] < vtx.size() );
82 std::vector<double>& p1 = vtx[origKey_[1]];
83 assert( (size_t) origKey_[2] < vtx.size() );
84 std::vector<double>& p2 = vtx[origKey_[2]];
85 assert( (size_t) base < vtx.size() );
86 std::vector<double>& q = vtx[base];
87 double n[3];
88 n[0] = (p1[1]-p0[1])*(p2[2]-p0[2])-(p2[1]-p0[1])*(p1[2]-p0[2]);
89 n[1] = (p1[2]-p0[2])*(p2[0]-p0[0])-(p2[2]-p0[2])*(p1[0]-p0[0]);
90 n[2] = (p1[0]-p0[0])*(p2[1]-p0[1])-(p2[0]-p0[0])*(p1[1]-p0[1]);
91 double test = n[0]*(q[0]-p0[0])+n[1]*(q[1]-p0[1])+n[2]*(q[2]-p0[2]);
92 bool reorient = (test>0);
93 if (reorient) {
94 A key1=origKey_[1];
95 origKey_[1]=origKey_[2];
96 origKey_[2]=key1;
97 }
98 }
99 }
100
101
102 template< class A >
103 inline void DGFEntityKey< A > :: print ( std :: ostream &out ) const
104 {
105 for( size_t i = 0; i < key_.size(); ++i )
106 out << key_[ i ] << " ";
107 out << std :: endl;
108 }
109
110
111 // ElementFaceUtil
112 // ---------------
113
114 template< int dim >
115 inline DGFEntityKey< unsigned int >
116 ElementFaceUtil::generateCubeFace
117 ( const std::vector< unsigned int > &element, int f )
118 {
120 const unsigned int size = refCube.size( f, 1, dim );
121 std::vector< unsigned int > k( size );
122 for( unsigned int i = 0; i < size; ++ i )
123 k[ i ] = element[ refCube.subEntity( f, 1, i, dim ) ];
124 return DGFEntityKey< unsigned int >( k );
125 }
126
127
128 template< int dim >
129 inline DGFEntityKey< unsigned int >
130 ElementFaceUtil :: generateSimplexFace
131 ( const std :: vector< unsigned int > &element, int f )
132 {
134 const unsigned int size = refSimplex.size( f, 1, dim );
135 std :: vector< unsigned int > k( size );
136 for( unsigned int i = 0; i < size; ++i )
137 k[ i ] = element[ refSimplex.subEntity( f, 1, i, dim ) ];
138 return DGFEntityKey< unsigned int >( k );
139 }
140
141
142 inline DGFEntityKey< unsigned int >
143 ElementFaceUtil::generateFace ( int dim, const std::vector< unsigned int > &element, int f )
144 {
145 if( element.size() == size_t(dim+1) )
146 {
147 // Simplex element
148 switch( dim )
149 {
150 case 3 :
151 return generateSimplexFace< 3 >( element, f );
152 case 2 :
153 return generateSimplexFace< 2 >( element, f );
154 case 1 :
155 return generateSimplexFace< 1 >( element, f );
156 default :
157 DUNE_THROW( NotImplemented, "ElementUtil::generateFace not implemented for dim = " << dim << "." );
158 }
159 }
160 else
161 {
162 // Cube element
163 switch( dim )
164 {
165 case 3 :
166 return generateCubeFace< 3 >( element, f );
167 case 2 :
168 return generateCubeFace< 2 >( element, f );
169 case 1 :
170 return generateCubeFace< 1 >( element, f );
171 default :
172 DUNE_THROW( NotImplemented, "ElementUtil::generateFace not implemented for dim = " << dim << "." );
173 }
174 }
175 }
176
177} // end namespace Dune
178
179#endif // DUNE_ENTITYKEY_INLINE_HH
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:705
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:696
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)