edgeSurface.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "edgeSurface.H"
29#include "triSurface.H"
30#include "surfaceIntersection.H"
31#include "meshTools.H"
32#include "OBJstream.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
39
40// file-scope
41// Write points in obj format
42static void writeObjPoints(const UList<point>& pts, Ostream& os)
43{
44 forAll(pts, i)
45 {
46 const point& pt = pts[i];
47 os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
48 }
49}
50
51
52// Write whole pointField and selected edges to stream
54(
55 const UList<point>& points,
56 const edgeList& edges,
57 const labelList& edgeLabels,
58 Ostream& os
59)
60{
62
63 forAll(edgeLabels, i)
64 {
65 const edge& e = edges[edgeLabels[i]];
66
67 os << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
68 }
69}
70
71} // End namespace Foam
72
73
74// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
75
76// Pointedges in edgeSurface indices only.
77void Foam::edgeSurface::calcPointEdges()
78{
79 pointEdges_.setSize(points_.size());
80
81 labelList pointNEdges(points_.size(), Zero);
82
83 forAll(edges_, edgeI)
84 {
85 const edge& e = edges_[edgeI];
86
87 pointNEdges[e[0]]++;
88 pointNEdges[e[1]]++;
89 }
90
91 forAll(pointEdges_, pointi)
92 {
93 pointEdges_[pointi].setSize(pointNEdges[pointi]);
94 }
95
96 pointNEdges = 0;
97
98 forAll(edges_, edgeI)
99 {
100 const edge& e = edges_[edgeI];
101
102 labelList& pEdges0 = pointEdges_[e[0]];
103 pEdges0[pointNEdges[e[0]]++] = edgeI;
104
105 labelList& pEdges1 = pointEdges_[e[1]];
106 pEdges1[pointNEdges[e[1]]++] = edgeI;
107 }
108}
109
110
111// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112
113// Construct from surface and intersection description
115(
116 const triSurface& surf,
117 const bool isFirstSurface,
118 const surfaceIntersection& inter
119)
120:
121 points_(surf.nPoints() + inter.cutPoints().size()),
122 nSurfacePoints_(surf.nPoints()),
123 edges_(),
124 nSurfaceEdges_(surf.nEdges()),
125 parentEdges_(0),
126 faceEdges_(surf.size()),
127 pointEdges_(points_.size())
128{
129 // Copy points (surface ones first)
130 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131
132 label pointi = 0;
133
134 const pointField& surfPoints = surf.localPoints();
135
136 forAll(surfPoints, i)
137 {
138 points_[pointi++] = surfPoints[i];
139 }
140
141 const pointField& cutPoints = inter.cutPoints();
142
143 forAll(cutPoints, i)
144 {
145 points_[pointi++] = cutPoints[i];
146 }
147
148
149 // Copy edges (surface ones first)
150 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151
152 DynamicList<edge> allEdges(surf.nEdges() + inter.cutEdges().size());
153 DynamicList<label> allParentEdges(surf.nEdges());
154 List<DynamicList<label>> allFaceEdges(surf.size());
155
156
157 // Copy surface edges (can be split!)
158
159 const edgeList& surfEdges = surf.edges();
160
161 forAll(surfEdges, edgeI)
162 {
163 const edge& e = surfEdges[edgeI];
164
165 // Get additional vertices for this edge.
166 const labelList& extraVerts = inter.edgeCuts(isFirstSurface)[edgeI];
167
168 // Store current top of allEdges.
169 label freeNewEdgeI = allEdges.size();
170
171 if (extraVerts.empty())
172 {
173 // No cuts across this edge. Note that vertices do not need to be
174 // renumbered.
175 allEdges.append(e);
176 }
177 else
178 {
179 // Edge is cut. From e.start() to extraVerts[0],
180 // from extraVerts[i] to i+1 and finally to e.end().
181 allEdges.append
182 (
183 edge
184 (
185 e.start(),
186 extraVerts[0] + nSurfacePoints_
187 )
188 );
189
190 for (label extraI = 1; extraI < extraVerts.size(); extraI++)
191 {
192 allEdges.append
193 (
194 edge
195 (
196 extraVerts[extraI-1] + nSurfacePoints_,
197 extraVerts[extraI] + nSurfacePoints_
198 )
199 );
200 }
201 allEdges.append
202 (
203 edge
204 (
205 extraVerts.last() + nSurfacePoints_,
206 e.end()
207 )
208 );
209 }
210
211 // Update allFaceEdges, parentEdges_ for the newly added edges.
212
213 // Add each edge label to all face neighbours of edgeI
214 const labelList& myFaces = surf.edgeFaces()[edgeI];
215
216 for (label eI = freeNewEdgeI; eI < allEdges.size(); eI++)
217 {
218 allParentEdges.append(edgeI);
219
220 forAll(myFaces, myFacei)
221 {
222 allFaceEdges[myFaces[myFacei]].append(eI);
223 }
224 }
225 }
226
227 // Done all (possibly split) surface edges by now.
228 nSurfaceEdges_ = allEdges.size();
229
230
231 // Copy intersection edges
232 // (note no parentEdges)
233 const edgeList& cutEdges = inter.cutEdges();
234
235 forAll(cutEdges, i)
236 {
237 const edge& e = cutEdges[i];
238
239 allEdges.append(edge(e[0] + nSurfacePoints_, e[1] + nSurfacePoints_));
240 }
241
242
243 // Add intersection edges to faceEdges
244 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245
247 {
248 // The faceId from the correct surface
249 const label facei = iter.key()[isFirstSurface ? 0 : 1];
250
251 // Edge label in intersection
252 const label edgeI = iter.val();
253
254 // Store on face-edge addressing. (note: offset edge)
255 allFaceEdges[facei].append(edgeI + nSurfaceEdges_);
256 }
257
258 // Transfer.
259 edges_.transfer(allEdges);
260 parentEdges_.transfer(allParentEdges);
261
262 forAll(allFaceEdges, facei)
263 {
264 faceEdges_[facei].transfer(allFaceEdges[facei]);
265 }
266
267
268 // Additional addressing
269 // ~~~~~~~~~~~~~~~~~~~~~
270
271 calcPointEdges();
272
273
274 if (debug & 4)
275 {
276 Pout<< "edgeSurface : Dumping faceEdges to files" << endl;
277
278 forAll(faceEdges_, facei)
279 {
280 const labelList& fEdges = faceEdges_[facei];
281
282 if (fEdges.size() != 3)
283 {
284 fileName faceFName("face_" + name(facei) + ".obj");
285 Pout<< "edgeSurface : Dumping faceEdges for face " << facei
286 << " to " << faceFName << endl;
287
288 OFstream fStream(faceFName);
289 writeObjEdges(points_, edges_, fEdges, fStream);
290 }
291 }
292
293 Pout<< "edgeSurface : Dumping edges to edges.obj" << endl;
294 OBJstream("edges.obj").write(edges_, points_);
295
296 Pout<< "edgeSurface : Dumping intersectionEdges to"
297 << " intersectionEdges.obj" << endl;
298
299 OFstream intEdgesStream("intersectionEdges.obj");
300 labelList edgeLabels(edges_.size() - nSurfaceEdges_);
301
302 label i = 0;
303 for (label edgeI = nSurfaceEdges_; edgeI < edges_.size(); edgeI++)
304 {
305 edgeLabels[i++] = edgeI;
306 }
307
308 writeObjEdges(points_, edges_, edgeLabels, intEdgesStream);
309 }
310}
311
312
313// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
314
316(
317 const label facei,
318 const edgeList& additionalEdges
319)
320{
321 if (debug & 2)
322 {
323 Pout<< "Old face consisted of edges:" << endl;
324
325 const labelList& fEdges = faceEdges_[facei];
326 forAll(fEdges, i)
327 {
328 const edge& e = edges_[fEdges[i]];
329
330 Pout<< " " << fEdges[i] << ' ' << e
331 << points_[e.start()] << ' ' << points_[e.end()] << endl;
332 }
333 }
334
335 // Make space for additional intersection edges (copies old ones)
336 const label oldNEdges = edges_.size();
337
338 edges_.setSize(oldNEdges + additionalEdges.size());
339
340 // Append new intersection edges
341 label newEdgeI = oldNEdges;
342
343 forAll(additionalEdges, i)
344 {
345 edges_[newEdgeI] = additionalEdges[i]; // Vertices already in eSurf
346 // indices.
347 newEdgeI++;
348 }
349
350 // Append to faceEdges.
351 labelList& fEdges = faceEdges_[facei];
352
353 label nFEdges = fEdges.size();
354
355 fEdges.setSize(nFEdges + additionalEdges.size());
356
357 forAll(additionalEdges, i)
358 {
359 fEdges[nFEdges++] = oldNEdges + i;
360 }
361
362
363 // Update pointEdge addressing
364 calcPointEdges();
365
366
367 if (debug & 2)
368 {
369 const labelList& fEdges = faceEdges_[facei];
370
371 Pout<< "New face consists of edges:" << endl;
372 forAll(fEdges, i)
373 {
374 const edge& e = edges_[fEdges[i]];
375
376 Pout<< " " << fEdges[i] << ' ' << e
377 << points_[e.start()] << ' ' << points_[e.end()] << endl;
378 }
379 }
380}
381
382
383// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
void transfer(List< T > &list)
Definition: List.C:447
void setSize(const label n)
Alias for resize()
Definition: List.H:218
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
OFstream that keeps track of vertices.
Definition: OBJstream.H:61
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
Output to file stream, using an OSstream.
Definition: OFstream.H:57
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
label nEdges() const
Number of edges in patch.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
const Field< point_type > & localPoints() const
Return pointField of points in patch.
const labelListList & edgeFaces() const
Return edge-face addressing.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:350
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
T & last()
Return the last element of the list.
Definition: UListI.H:216
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Description of surface in form of 'cloud of edges'.
Definition: edgeSurface.H:76
void addIntersectionEdges(const label facei, const edgeList &)
Add intersection edges to a face. Used for connecting.
Definition: edgeSurface.C:316
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A class for handling file names.
Definition: fileName.H:76
Basic surface-surface intersection description. Constructed from two surfaces it creates a descriptio...
const edgeList & cutEdges() const
The list of created edges.
const labelListList & edgeCuts(const bool isFirstSurf) const
Access either surf1EdgeCuts (isFirstSurface = true) or.
const labelPairLookup & facePairToEdgeId() const
Lookup of pairs of faces to created edges.
const pointField & cutPoints() const
The list of cut points.
Triangulated surface description with patch information.
Definition: triSurface.H:79
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
OBJstream os(runTime.globalPath()/outputName)
const labelList nEdges(UPstream::listGatherValues< label >(aMesh.nEdges()))
const pointField & points
label nPoints
Namespace for OpenFOAM.
void writeObjEdges(const UList< point > &points, const edgeList &edges, const labelList &edgeLabels, Ostream &os)
Definition: edgeSurface.C:54
List< label > labelList
A List of labels.
Definition: List.H:66
static void writeObjPoints(const UList< point > &pts, Ostream &os)
Definition: edgeSurface.C:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278