Directory: | ./ |
---|---|
File: | Geometry/listFaces.cpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 123 | 161 | 76.4% |
Branches: | 90 | 155 | 58.1% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // ______ ______ _ _ _____ ______ | ||
2 | // | ____| ____| | (_)/ ____| | ____| | ||
3 | // | |__ | |__ | | _| (___ ___| |__ | ||
4 | // | __| | __| | | | |\___ \ / __| __| | ||
5 | // | | | |____| |____| |____) | (__| |____ | ||
6 | // |_| |______|______|_|_____/ \___|______| | ||
7 | // Finite Elements for Life Sciences and Engineering | ||
8 | // | ||
9 | // License: LGL2.1 License | ||
10 | // FELiScE default license: LICENSE in root folder | ||
11 | // | ||
12 | // Main authors: J.Castelneau & J.Foulon | ||
13 | // | ||
14 | |||
15 | // System includes | ||
16 | |||
17 | // External includes | ||
18 | |||
19 | // Project includes | ||
20 | #include "Geometry/listFaces.hpp" | ||
21 | #include "Geometry/geometricFaces.hpp" | ||
22 | #include "Geometry/neighVolumesOfFaces.hpp" | ||
23 | |||
24 | namespace felisce | ||
25 | { | ||
26 | |||
27 | const felInt ListFaces::m_null_int = -1; | ||
28 | |||
29 | ////////////////////// | ||
30 | // LIST FACES CLASS // | ||
31 | ////////////////////// | ||
32 | |||
33 | //---------------- | ||
34 | 1277 | ListFaces::~ListFaces() { | |
35 |
2/2✓ Branch 1 taken 1539584 times.
✓ Branch 2 taken 1277 times.
|
1540861 | for (std::size_t iface = 0; iface < m_list.size(); ++iface) { |
36 |
1/2✓ Branch 1 taken 1539584 times.
✗ Branch 2 not taken.
|
1539584 | delete m_list[iface]; |
37 | } | ||
38 | |||
39 | 1277 | m_list.clear(); | |
40 | 1277 | m_listBegin.clear(); | |
41 | 1277 | } | |
42 | |||
43 | |||
44 | 133 | void ListFaces::clearAndInit(felInt numPts) { | |
45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 133 times.
|
133 | for (std::size_t iface = 0; iface < m_list.size(); ++iface) |
46 | ✗ | delete m_list[iface]; | |
47 | |||
48 | 133 | m_list.clear(); | |
49 | 133 | m_listBegin.clear(); | |
50 | |||
51 | 133 | m_numFaces = 0; | |
52 | 133 | m_numGivenFaces = 0; | |
53 | |||
54 |
1/2✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
|
133 | m_listBegin.resize(numPts, nullptr); |
55 | 133 | } | |
56 | |||
57 | //---------------- | ||
58 | 3025590 | void ListFaces::searchAddFace(std::vector<felInt> facePts, NeighVolumesOfFaces* the_vol_neighbour, | |
59 | bool check_surface_mesh_flag) { | ||
60 | IGNORE_UNUSED_ARGUMENT(check_surface_mesh_flag); | ||
61 | //------- | ||
62 | //!STEP 1: prepare the face: | ||
63 | |||
64 | //! reorder the face: convention: smallest point first | ||
65 |
1/2✓ Branch 1 taken 3025590 times.
✗ Branch 2 not taken.
|
3025590 | std::vector<felInt> orderedFacePts(facePts); |
66 |
1/2✓ Branch 1 taken 3025590 times.
✗ Branch 2 not taken.
|
3025590 | permutFacePointsSmallIDFirst(facePts, orderedFacePts); |
67 | |||
68 | //! create opposite face, and reorder it following the convention | ||
69 |
1/2✓ Branch 3 taken 3025590 times.
✗ Branch 4 not taken.
|
3025590 | std::vector<felInt> orderedOppFacePts(facePts.size(), 0); |
70 |
1/2✓ Branch 1 taken 3025590 times.
✗ Branch 2 not taken.
|
3025590 | giveOppositeFace(facePts, orderedOppFacePts); |
71 |
1/2✓ Branch 1 taken 3025590 times.
✗ Branch 2 not taken.
|
3025590 | permutFacePointsSmallIDFirst(orderedOppFacePts); |
72 | |||
73 | //------- | ||
74 | //!STEP 2: search the face in the existing list of faces | ||
75 | 3025590 | Face* begin_face = m_listBegin[ orderedFacePts[0] ]; | |
76 | |||
77 |
2/2✓ Branch 0 taken 148307 times.
✓ Branch 1 taken 2877283 times.
|
3025590 | if ( begin_face == nullptr ) { |
78 | //! this vertex has never been the beginning of a face: add the face | ||
79 |
2/4✓ Branch 1 taken 148307 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 148307 times.
✗ Branch 5 not taken.
|
148307 | Face* the_face = new Face(orderedFacePts, m_numFaces); |
80 |
2/2✓ Branch 0 taken 93220 times.
✓ Branch 1 taken 55087 times.
|
148307 | if (the_vol_neighbour != nullptr) |
81 |
1/2✓ Branch 2 taken 93220 times.
✗ Branch 3 not taken.
|
93220 | the_face->listNeighVolumes().push_back(the_vol_neighbour); |
82 | |||
83 |
1/2✓ Branch 1 taken 148307 times.
✗ Branch 2 not taken.
|
148307 | m_list.push_back( the_face ); |
84 | 148307 | m_listBegin[ orderedFacePts[0] ] = the_face; | |
85 | 148307 | m_numFaces++; | |
86 | 148307 | return; | |
87 | } | ||
88 | |||
89 | //! otherwise: there already exists (at least) one face starting with this vertex: | ||
90 | 2877283 | Face* current_face = begin_face; | |
91 | Face* previous_face; | ||
92 | do { //! search FacePts or OppFacePts among all faces starting with this vertex | ||
93 | 28226326 | previous_face = current_face; | |
94 |
5/6✓ Branch 2 taken 28226326 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28089807 times.
✓ Branch 5 taken 136519 times.
✓ Branch 6 taken 1486006 times.
✓ Branch 7 taken 26740320 times.
|
56316133 | if ( compareFaces( current_face->vecFace(), orderedFacePts ) or |
95 |
3/4✓ Branch 2 taken 28089807 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1349487 times.
✓ Branch 5 taken 26740320 times.
|
28089807 | compareFaces( current_face->vecFace(), orderedOppFacePts ) ) { |
96 | //! this face exists already | ||
97 |
1/2✓ Branch 0 taken 1486006 times.
✗ Branch 1 not taken.
|
1486006 | if (the_vol_neighbour != nullptr) |
98 |
1/2✓ Branch 2 taken 1486006 times.
✗ Branch 3 not taken.
|
1486006 | current_face->listNeighVolumes().push_back(the_vol_neighbour); |
99 | 1486006 | return; //! we do not insert this existing face. | |
100 | } | ||
101 | 26740320 | current_face = previous_face->ptrNext(); | |
102 |
2/2✓ Branch 0 taken 25349043 times.
✓ Branch 1 taken 1391277 times.
|
26740320 | } while ( current_face != nullptr ); |
103 | |||
104 | //! If we did not exit so far, this is a new face: we add it | ||
105 |
2/4✓ Branch 1 taken 1391277 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1391277 times.
✗ Branch 5 not taken.
|
1391277 | Face* the_face = new Face(orderedFacePts, m_numFaces); |
106 |
2/2✓ Branch 0 taken 1279718 times.
✓ Branch 1 taken 111559 times.
|
1391277 | if (the_vol_neighbour != nullptr) |
107 |
1/2✓ Branch 2 taken 1279718 times.
✗ Branch 3 not taken.
|
1279718 | the_face->listNeighVolumes().push_back(the_vol_neighbour); |
108 | |||
109 |
1/2✓ Branch 1 taken 1391277 times.
✗ Branch 2 not taken.
|
1391277 | m_list.push_back( the_face ); |
110 | //! link between previous face and current: | ||
111 | 1391277 | previous_face->ptrNext() = m_list[m_numFaces]; | |
112 | 1391277 | m_numFaces ++; | |
113 |
4/4✓ Branch 1 taken 1391277 times.
✓ Branch 2 taken 1634313 times.
✓ Branch 4 taken 1391277 times.
✓ Branch 5 taken 1634313 times.
|
4659903 | } |
114 | |||
115 | //---------------- | ||
116 | 193885 | felInt ListFaces::findFace(const std::vector <felInt> & facePts) const { | |
117 | 193885 | const felInt resultFaceNotFound = -1; | |
118 | |||
119 | //! reorder the face: convention: smallest point first | ||
120 |
1/2✓ Branch 1 taken 193885 times.
✗ Branch 2 not taken.
|
193885 | std::vector<felInt> orderedFacePts(facePts); |
121 |
1/2✓ Branch 1 taken 193885 times.
✗ Branch 2 not taken.
|
193885 | permutFacePointsSmallIDFirst(facePts, orderedFacePts); |
122 | |||
123 | //! create opposite face, and reorder it following the convention | ||
124 |
1/2✓ Branch 3 taken 193885 times.
✗ Branch 4 not taken.
|
193885 | std::vector<felInt> orderedOppFacePts(facePts.size(), 0); |
125 |
1/2✓ Branch 1 taken 193885 times.
✗ Branch 2 not taken.
|
193885 | giveOppositeFace(facePts, orderedOppFacePts); |
126 |
1/2✓ Branch 1 taken 193885 times.
✗ Branch 2 not taken.
|
193885 | permutFacePointsSmallIDFirst(orderedOppFacePts); |
127 | |||
128 | 193885 | Face* current_face = m_listBegin[ orderedFacePts[0] ]; | |
129 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 193885 times.
|
193885 | if ( current_face == nullptr ) { |
130 | ✗ | FEL_WARNING("You are searching a face with an unknow first point!!!!\n"); | |
131 | ✗ | return resultFaceNotFound; | |
132 | } | ||
133 | |||
134 | do { | ||
135 |
5/6✓ Branch 2 taken 510119 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 316296 times.
✓ Branch 5 taken 193823 times.
✓ Branch 6 taken 193885 times.
✓ Branch 7 taken 316234 times.
|
826415 | if ( compareFaces( current_face->vecFace(), orderedFacePts ) or |
136 |
3/4✓ Branch 2 taken 316296 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 316234 times.
|
316296 | compareFaces( current_face->vecFace(), orderedOppFacePts ) ) { |
137 | 193885 | return current_face->id(); | |
138 | } | ||
139 | 316234 | current_face = current_face->ptrNext(); | |
140 |
1/2✓ Branch 0 taken 316234 times.
✗ Branch 1 not taken.
|
316234 | } while ( current_face != nullptr ); |
141 | |||
142 | ✗ | FEL_WARNING("The sought face was not found."); | |
143 | ✗ | return resultFaceNotFound; | |
144 | 193885 | } | |
145 | |||
146 | //---------------- | ||
147 | //! if not used: remove it! 2012/08 vm | ||
148 | ✗ | felInt ListFaces::findFace(const Face& the_face) const { | |
149 | ✗ | return findFace( the_face.vecFace() ); | |
150 | } | ||
151 | |||
152 | //---------------- | ||
153 | //! Like findFace, but instead of returning the face ID, return a copy of the face. (Really useful:??? VM 2012/09) | ||
154 | 193437 | void ListFaces::searchFace(const std::vector <felInt> & facePts, Face& resultFace) const { | |
155 | 193437 | felInt faceID = findFace(facePts); | |
156 | 193437 | resultFace.copyFace( *( list(faceID) ) ); | |
157 | 193437 | } | |
158 | |||
159 | |||
160 | //---------------- | ||
161 | //! return true if the faces are equal | ||
162 | //! we assume that the starting point are equal | ||
163 | 57142548 | bool ListFaces::compareFaces(const std::vector<felInt>& face0, const std::vector<felInt>& face1) const { | |
164 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 57142548 times.
|
57142548 | FEL_ASSERT( face0[0] == face1[0] ); |
165 | //! we assume that a quadrangle and a triangle cannot be equal: | ||
166 |
2/2✓ Branch 2 taken 25444 times.
✓ Branch 3 taken 57117104 times.
|
57142548 | if ( face0.size() != face1.size() ) return false; |
167 | |||
168 |
3/4✓ Branch 1 taken 57098020 times.
✓ Branch 2 taken 12856 times.
✓ Branch 3 taken 6228 times.
✗ Branch 4 not taken.
|
57117104 | switch (face0.size()) { |
169 | 57098020 | case 3: | |
170 |
2/2✓ Branch 2 taken 51078428 times.
✓ Branch 3 taken 6019592 times.
|
57098020 | if (face0[1] != face1[1]) return false; |
171 |
2/2✓ Branch 2 taken 4341379 times.
✓ Branch 3 taken 1678213 times.
|
6019592 | if (face0[2] != face1[2]) return false; |
172 | 1678213 | return true; | |
173 | 12856 | case 4: | |
174 |
2/2✓ Branch 2 taken 8664 times.
✓ Branch 3 taken 4192 times.
|
12856 | if (face0[1] != face1[1]) return false; |
175 |
2/2✓ Branch 2 taken 2682 times.
✓ Branch 3 taken 1510 times.
|
4192 | if (face0[2] != face1[2]) return false; |
176 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1510 times.
|
1510 | if (face0[3] != face1[3]) return false; |
177 | 1510 | return true; | |
178 | 6228 | case 6: | |
179 |
2/2✓ Branch 2 taken 4168 times.
✓ Branch 3 taken 2060 times.
|
6228 | if (face0[1] != face1[1]) return false; |
180 |
2/2✓ Branch 2 taken 1592 times.
✓ Branch 3 taken 468 times.
|
2060 | if (face0[2] != face1[2]) return false; |
181 |
2/2✓ Branch 2 taken 300 times.
✓ Branch 3 taken 168 times.
|
468 | if (face0[3] != face1[3]) return false; |
182 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 168 times.
|
168 | if (face0[4] != face1[4]) return false; |
183 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 168 times.
|
168 | if (face0[5] != face1[5]) return false; |
184 | 168 | return true; | |
185 | ✗ | default: | |
186 | ✗ | FEL_ERROR("Number of points in the face incorrect!!!"); | |
187 | ✗ | return false; //to avoid a warning | |
188 | } | ||
189 | } | ||
190 | |||
191 | |||
192 | //---------------- | ||
193 | //! Permute id point of face description: | ||
194 | //! convention smallest point id first. | ||
195 | 6438950 | void ListFaces::permutFacePointsSmallIDFirst(const std::vector <felInt>& theFacePts, | |
196 | std::vector <felInt>& theOrderedFactePts) const { | ||
197 | 6438950 | felInt minPt = theOrderedFactePts[0]; | |
198 | 6438950 | int posMin = 0; | |
199 | 6438950 | int dim = static_cast<int>( theOrderedFactePts.size() ); | |
200 |
2/2✓ Branch 1 taken 12891592 times.
✓ Branch 2 taken 6438950 times.
|
19330542 | for (unsigned int ipt = 1; ipt < theOrderedFactePts.size(); ipt++) { |
201 |
2/2✓ Branch 1 taken 4931330 times.
✓ Branch 2 taken 7960262 times.
|
12891592 | if ( theOrderedFactePts[ipt] < minPt ) { |
202 | 4931330 | minPt = theOrderedFactePts[ipt]; | |
203 | 4931330 | posMin = ipt; | |
204 | } | ||
205 | } | ||
206 | |||
207 |
2/2✓ Branch 1 taken 19330542 times.
✓ Branch 2 taken 6438950 times.
|
25769492 | for (unsigned int ipt = 0; ipt < theOrderedFactePts.size(); ipt++) { |
208 | 19330542 | int newPos = ( (ipt - posMin)+dim*100 ) % dim; //newPos >=0 because a%b is >=0 if a and b are >=0 | |
209 | 19330542 | theOrderedFactePts[newPos] = theFacePts[ipt]; | |
210 | } | ||
211 | 6438950 | } | |
212 | 3219475 | void ListFaces::permutFacePointsSmallIDFirst(std::vector <felInt>& facePts) const { | |
213 |
1/2✓ Branch 1 taken 3219475 times.
✗ Branch 2 not taken.
|
3219475 | std::vector<felInt> tmpFacePts(facePts); |
214 |
1/2✓ Branch 1 taken 3219475 times.
✗ Branch 2 not taken.
|
3219475 | permutFacePointsSmallIDFirst(tmpFacePts, facePts); |
215 | 3219475 | } | |
216 | |||
217 | //---------------- | ||
218 | 3219475 | void ListFaces::giveOppositeFace(const std::vector <felInt>& theFacePts, | |
219 | std::vector <felInt>& theOppositeFacePts) const { | ||
220 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 3219475 times.
|
3219475 | FEL_ASSERT( theFacePts.size() == theOppositeFacePts.size() ); |
221 |
3/4✓ Branch 1 taken 3214861 times.
✓ Branch 2 taken 3498 times.
✓ Branch 3 taken 1116 times.
✗ Branch 4 not taken.
|
3219475 | switch ( theFacePts.size() ) { |
222 | 3214861 | case 3: | |
223 | 3214861 | theOppositeFacePts[0] = theFacePts[1]; | |
224 | 3214861 | theOppositeFacePts[1] = theFacePts[0]; | |
225 | 3214861 | theOppositeFacePts[2] = theFacePts[2]; | |
226 | 3214861 | break; | |
227 | |||
228 | 3498 | case 4: | |
229 | 3498 | theOppositeFacePts[0] = theFacePts[1]; | |
230 | 3498 | theOppositeFacePts[1] = theFacePts[0]; | |
231 | 3498 | theOppositeFacePts[2] = theFacePts[3]; | |
232 | 3498 | theOppositeFacePts[3] = theFacePts[2]; | |
233 | 3498 | break; | |
234 | |||
235 | 1116 | case 6: | |
236 | 1116 | theOppositeFacePts[0] = theFacePts[1]; | |
237 | 1116 | theOppositeFacePts[1] = theFacePts[0]; | |
238 | 1116 | theOppositeFacePts[2] = theFacePts[3]; | |
239 | 1116 | theOppositeFacePts[3] = theFacePts[2]; | |
240 | 1116 | theOppositeFacePts[4] = theFacePts[5]; | |
241 | 1116 | theOppositeFacePts[5] = theFacePts[4]; | |
242 | 1116 | break; | |
243 | ✗ | default: | |
244 | ✗ | FEL_ERROR("Number of points in the face incorrect!!!"); | |
245 | } | ||
246 | 3219475 | } | |
247 | |||
248 | //---------------- | ||
249 | ✗ | void ListFaces::print( std::ostream& outstr, int verbose, int orderFormat) const { | |
250 | ✗ | switch ( orderFormat ) { | |
251 | ✗ | case 0: { // print by increasing edge ID | |
252 | ✗ | outstr << "Print the list of faces: " << m_numFaces | |
253 | ✗ | << " faces (ordered by face ID) (" << m_numGivenFaces | |
254 | ✗ | << " first faces were provided.)\n"; | |
255 | ✗ | bool print_next_face = false; | |
256 | ✗ | for(auto it_edg = m_list.begin(); | |
257 | ✗ | it_edg != m_list.end(); it_edg++) { | |
258 | ✗ | (*it_edg)->print( outstr, verbose, print_next_face ); | |
259 | } | ||
260 | } | ||
261 | ✗ | break; | |
262 | ✗ | case 1: { // print by increasing BeginPoint | |
263 | ✗ | felInt begPt = 0; | |
264 | ✗ | outstr << "Print the list of faces: " << m_numFaces | |
265 | ✗ | << " faces (ordered by increasing BeginPoint (" << m_numGivenFaces | |
266 | ✗ | << " faces were provided.))\n"; | |
267 | ✗ | bool print_next_face = true; | |
268 | ✗ | for(auto it_beg = m_listBegin.begin(); | |
269 | ✗ | it_beg != m_listBegin.end(); it_beg++) { | |
270 | ✗ | if ( (*it_beg) == NULL ) { | |
271 | ✗ | if ( verbose > 30 ) outstr << begPt << " ------> NULL "<< std::endl; | |
272 | } else { | ||
273 | ✗ | (*it_beg)->print( outstr, verbose, print_next_face ); | |
274 | } | ||
275 | ✗ | begPt++; | |
276 | } | ||
277 | } | ||
278 | ✗ | break; | |
279 | ✗ | default: | |
280 | ✗ | FEL_ERROR("Problem: choose the order for face printing"); | |
281 | } | ||
282 | } | ||
283 | } | ||
284 |