Dune Core Modules (2.5.2)

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 {
119 const ReferenceElement< double, dim > &refCube
120 = ReferenceElements< double, dim >::cube();
121 const unsigned int size = refCube.size( f, 1, dim );
122 std::vector< unsigned int > k( size );
123 for( unsigned int i = 0; i < size; ++ i )
124 k[ i ] = element[ refCube.subEntity( f, 1, i, dim ) ];
125 return DGFEntityKey< unsigned int >( k );
126 }
127
128
129 template< int dim >
130 inline DGFEntityKey< unsigned int >
131 ElementFaceUtil :: generateSimplexFace
132 ( const std :: vector< unsigned int > &element, int f )
133 {
134 const ReferenceElement< double, dim > &refSimplex
135 = ReferenceElements< double, dim >::simplex();
136 const unsigned int size = refSimplex.size( f, 1, dim );
137 std :: vector< unsigned int > k( size );
138 for( unsigned int i = 0; i < size; ++i )
139 k[ i ] = element[ refSimplex.subEntity( f, 1, i, dim ) ];
140 return DGFEntityKey< unsigned int >( k );
141 }
142
143
144 inline DGFEntityKey< unsigned int >
145 ElementFaceUtil::generateFace ( int dim, const std::vector< unsigned int > &element, int f )
146 {
147 if( element.size() == size_t(dim+1) )
148 {
149 // Simplex element
150 switch( dim )
151 {
152 case 3 :
153 return generateSimplexFace< 3 >( element, f );
154 case 2 :
155 return generateSimplexFace< 2 >( element, f );
156 case 1 :
157 return generateSimplexFace< 1 >( element, f );
158 default :
159 DUNE_THROW( NotImplemented, "ElementUtil::generateFace not implemented for dim = " << dim << "." );
160 }
161 }
162 else
163 {
164 // Cube element
165 switch( dim )
166 {
167 case 3 :
168 return generateCubeFace< 3 >( element, f );
169 case 2 :
170 return generateCubeFace< 2 >( element, f );
171 case 1 :
172 return generateCubeFace< 1 >( element, f );
173 default :
174 DUNE_THROW( NotImplemented, "ElementUtil::generateFace not implemented for dim = " << dim << "." );
175 }
176 }
177 }
178
179} // end namespace Dune
180
181#endif // DUNE_ENTITYKEY_INLINE_HH
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignment.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)