DUNE PDELab (git)

entitykey_inline.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ENTITYKEY_INLINE_HH
6#define DUNE_ENTITYKEY_INLINE_HH
7
8#include <algorithm>
9#include <dune/geometry/referenceelements.hh>
10#include <dune/grid/io/file/dgfparser/entitykey.hh>
11
12namespace Dune
13{
14
15 // DGFEntityKey
16 // ------------
17
18 template< class A >
19 inline DGFEntityKey< A > :: DGFEntityKey ( const std :: vector< A > &key, bool setOrigKey )
20 : key_( key.size() ),
21 origKey_( key.size() ),
22 origKeySet_( setOrigKey )
23 {
24 for (size_t i=0; i<key_.size(); i++)
25 {
26 key_[i]=key[i];
27 origKey_[i]=key_[i];
28 }
29 std :: sort( key_.begin(), key_.end() );
30 }
31
32
33 template< class A >
34 inline DGFEntityKey< A > :: DGFEntityKey ( const std :: vector< A > &key,
35 int N, int offset, bool setOrigKey )
36 : key_( N ),
37 origKey_( N ),
38 origKeySet_( setOrigKey )
39 {
40 for (size_t i=0; i<key_.size(); i++)
41 {
42 key_[i]=key[(i+offset)%key.size()];
43 origKey_[i]=key[(i+offset)%key.size()];
44 }
45 std :: sort( key_.begin(), key_.end() );
46 }
47
48
49 template< class A >
50 inline DGFEntityKey< A > :: DGFEntityKey ( const DGFEntityKey< A > &k )
51 : key_( k.key_.size() ),
52 origKey_( k.key_.size() ),
53 origKeySet_( k. origKeySet_ )
54 {
55 for (size_t i=0; i<key_.size(); i++)
56 {
57 key_[i]=k.key_[i];
58 origKey_[i]=k.origKey_[i];
59 }
60 }
61
62
63 template< class A >
64 inline DGFEntityKey< A > &DGFEntityKey< A > :: operator= ( const DGFEntityKey< A > &k )
65 {
66 assert(key_.size()==k.key_.size());
67 for (size_t i=0; i<key_.size(); i++) {
68 key_[i]=k.key_[i];
69 origKey_[i]=k.origKey_[i];
70 }
71 origKeySet_ = k.origKeySet_;
72 return *this;
73 }
74
75
76 template< class A >
77 inline void DGFEntityKey< A >
78 :: orientation ( int base, std::vector< std :: vector< double > > &vtx )
79 {
80 if (key_.size()==3) {
81 assert( (size_t) origKey_[0] < vtx.size() );
82 std::vector<double>& p0 = vtx[origKey_[0]];
83 assert( (size_t) origKey_[1] < vtx.size() );
84 std::vector<double>& p1 = vtx[origKey_[1]];
85 assert( (size_t) origKey_[2] < vtx.size() );
86 std::vector<double>& p2 = vtx[origKey_[2]];
87 assert( (size_t) base < vtx.size() );
88 std::vector<double>& q = vtx[base];
89 double n[3];
90 n[0] = (p1[1]-p0[1])*(p2[2]-p0[2])-(p2[1]-p0[1])*(p1[2]-p0[2]);
91 n[1] = (p1[2]-p0[2])*(p2[0]-p0[0])-(p2[2]-p0[2])*(p1[0]-p0[0]);
92 n[2] = (p1[0]-p0[0])*(p2[1]-p0[1])-(p2[0]-p0[0])*(p1[1]-p0[1]);
93 double test = n[0]*(q[0]-p0[0])+n[1]*(q[1]-p0[1])+n[2]*(q[2]-p0[2]);
94 bool reorient = (test>0);
95 if (reorient) {
96 A key1=origKey_[1];
97 origKey_[1]=origKey_[2];
98 origKey_[2]=key1;
99 }
100 }
101 }
102
103
104 template< class A >
105 inline void DGFEntityKey< A > :: print ( std :: ostream &out ) const
106 {
107 for( size_t i = 0; i < key_.size(); ++i )
108 out << key_[ i ] << " ";
109 out << std :: endl;
110 }
111
112
113 // ElementFaceUtil
114 // ---------------
115
116 template< int dim >
117 inline DGFEntityKey< unsigned int >
118 ElementFaceUtil::generateCubeFace
119 ( const std::vector< unsigned int > &element, int f )
120 {
122 const unsigned int size = refCube.size( f, 1, dim );
123 std::vector< unsigned int > k( size );
124 for( unsigned int i = 0; i < size; ++ i )
125 k[ i ] = element[ refCube.subEntity( f, 1, i, dim ) ];
126 return DGFEntityKey< unsigned int >( k );
127 }
128
129
130 template< int dim >
131 inline DGFEntityKey< unsigned int >
132 ElementFaceUtil :: generateSimplexFace
133 ( const std :: vector< unsigned int > &element, int f )
134 {
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:218
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:462
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:453
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)