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 | Copyright (C) 2011-2012 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "edgeSurface.H"
27 #include "triSurface.H"
28 #include "surfaceIntersection.H"
29 #include "meshTools.H"
30 #include "OFstream.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 defineTypeNameAndDebug(edgeSurface, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 // Write whole pointField and edges to stream
43 void Foam::edgeSurface::writeOBJ
44 (
45  const pointField& points,
46  const edgeList& edges,
47  Ostream& os
48 )
49 {
50  forAll(points, pointI)
51  {
52  const point& pt = points[pointI];
53 
54  os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
55  }
56  forAll(edges, edgeI)
57  {
58  const edge& e = edges[edgeI];
59 
60  os << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
61  }
62 }
63 
64 
65 // Write whole pointField and selected edges to stream
66 void Foam::edgeSurface::writeOBJ
67 (
68  const pointField& points,
69  const edgeList& edges,
70  const labelList& edgeLabels,
71  Ostream& os
72 )
73 {
74  forAll(points, pointI)
75  {
76  const point& pt = points[pointI];
77 
78  os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
79  }
80  forAll(edgeLabels, i)
81  {
82  const edge& e = edges[edgeLabels[i]];
83 
84  os << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
85  }
86 }
87 
88 
89 // Pointedges in edgeSurface indices only.
90 void Foam::edgeSurface::calcPointEdges()
91 {
92  pointEdges_.setSize(points_.size());
93 
94  labelList pointNEdges(points_.size(), 0);
95 
96  forAll(edges_, edgeI)
97  {
98  const edge& e = edges_[edgeI];
99 
100  pointNEdges[e[0]]++;
101  pointNEdges[e[1]]++;
102  }
103 
104  forAll(pointEdges_, pointI)
105  {
106  pointEdges_[pointI].setSize(pointNEdges[pointI]);
107  }
108 
109  pointNEdges = 0;
110 
111  forAll(edges_, edgeI)
112  {
113  const edge& e = edges_[edgeI];
114 
115  labelList& pEdges0 = pointEdges_[e[0]];
116  pEdges0[pointNEdges[e[0]]++] = edgeI;
117 
118  labelList& pEdges1 = pointEdges_[e[1]];
119  pEdges1[pointNEdges[e[1]]++] = edgeI;
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125 
126 // Construct from surface and intersection description
128 (
129  const triSurface& surf,
130  const bool isFirstSurface,
131  const surfaceIntersection& inter
132 )
133 :
134  points_(surf.nPoints() + inter.cutPoints().size()),
135  nSurfacePoints_(surf.nPoints()),
136  edges_(),
137  nSurfaceEdges_(surf.nEdges()),
138  parentEdges_(0),
139  faceEdges_(surf.size()),
140  pointEdges_(points_.size())
141 {
142  // Copy points (surface ones first)
143  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 
145  label pointI = 0;
146 
147  const pointField& surfPoints = surf.localPoints();
148 
149  forAll(surfPoints, i)
150  {
151  points_[pointI++] = surfPoints[i];
152  }
153 
154  const pointField& cutPoints = inter.cutPoints();
155 
156  forAll(cutPoints, i)
157  {
158  points_[pointI++] = cutPoints[i];
159  }
160 
161 
162  // Copy edges (surface ones first)
163  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164 
165  DynamicList<edge> allEdges(surf.nEdges() + inter.cutEdges().size());
166  DynamicList<label> allParentEdges(surf.nEdges());
167  List<DynamicList<label> > allFaceEdges(surf.size());
168 
169 
170  // Copy surface edges (can be split!)
171 
172  const edgeList& surfEdges = surf.edges();
173 
174  forAll(surfEdges, edgeI)
175  {
176  const edge& e = surfEdges[edgeI];
177 
178  // Get additional vertices for this edge.
179  const labelList& extraVerts = inter.edgeCuts(isFirstSurface)[edgeI];
180 
181  // Store current top of allEdges.
182  label freeNewEdgeI = allEdges.size();
183 
184  if (extraVerts.empty())
185  {
186  // No cuts across this edge. Note that vertices do not need to be
187  // renumbered.
188  allEdges.append(e);
189  }
190  else
191  {
192  // Edge is cut. From e.start() to extraVerts[0],
193  // from extraVerts[i] to i+1 and finally to e.end().
194  allEdges.append
195  (
196  edge
197  (
198  e.start(),
199  extraVerts[0] + nSurfacePoints_
200  )
201  );
202 
203  for (label extraI = 1; extraI < extraVerts.size(); extraI++)
204  {
205  allEdges.append
206  (
207  edge
208  (
209  extraVerts[extraI-1] + nSurfacePoints_,
210  extraVerts[extraI] + nSurfacePoints_
211  )
212  );
213  }
214  allEdges.append
215  (
216  edge
217  (
218  extraVerts.last() + nSurfacePoints_,
219  e.end()
220  )
221  );
222  }
223 
224  // Update allFaceEdges, parentEdges_ for the newly added edges.
225 
226  // Add each edge label to all face neighbours of edgeI
227  const labelList& myFaces = surf.edgeFaces()[edgeI];
228 
229  for (label eI = freeNewEdgeI; eI < allEdges.size(); eI++)
230  {
231  allParentEdges.append(edgeI);
232 
233  forAll(myFaces, myFaceI)
234  {
235  allFaceEdges[myFaces[myFaceI]].append(eI);
236  }
237  }
238  }
239 
240  // Done all (possibly split) surface edges by now.
241  nSurfaceEdges_ = allEdges.size();
242 
243 
244  // Copy intersection edges
245  // (note no parentEdges)
246  const edgeList& cutEdges = inter.cutEdges();
247 
248  forAll(cutEdges, i)
249  {
250  const edge& e = cutEdges[i];
251 
252  allEdges.append(edge(e[0] + nSurfacePoints_, e[1] + nSurfacePoints_));
253  }
254 
255 
256 
257 
258  // Add intersection edges to faceEdges
259  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260 
262  {
263  // Edge label in intersection
264  const label edgeI = iter();
265 
266  // Get the face from the correct surface
267  const FixedList<label, 2>& twoFaces = iter.key();
268 
269  label faceI;
270 
271  if (isFirstSurface)
272  {
273  faceI = twoFaces[0];
274  }
275  else
276  {
277  faceI = twoFaces[1];
278  }
279 
280  // Store on face-edge addressing. (note: offset edge)
281  allFaceEdges[faceI].append(edgeI + nSurfaceEdges_);
282  }
283 
284  // Transfer.
285  edges_.transfer(allEdges);
286  parentEdges_.transfer(allParentEdges);
287 
288  forAll(allFaceEdges, faceI)
289  {
290  faceEdges_[faceI].transfer(allFaceEdges[faceI]);
291  }
292 
293 
294  // Additional addressing
295  // ~~~~~~~~~~~~~~~~~~~~~
296 
297  calcPointEdges();
298 
299 
300  if (debug & 4)
301  {
302  Pout<< "edgeSurface : Dumping faceEdges to files" << endl;
303 
304  forAll(faceEdges_, faceI)
305  {
306  const labelList& fEdges = faceEdges_[faceI];
307 
308  if (fEdges.size() != 3)
309  {
310  fileName faceFName("face_" + name(faceI) + ".obj");
311  Pout<< "edgeSurface : Dumping faceEdges for face " << faceI
312  << " to " << faceFName << endl;
313 
314  OFstream fStream(faceFName);
315  writeOBJ(points_, edges_, fEdges, fStream);
316  }
317  }
318 
319  Pout<< "edgeSurface : Dumping edges to edges.obj" << endl;
320  OFstream eStream("edges.obj");
321  writeOBJ(points_, edges_, eStream);
322 
323  Pout<< "edgeSurface : Dumping intersectionEdges to"
324  << " intersectionEdges.obj" << endl;
325  OFstream intEdgesStream("intersectionEdges.obj");
326 
327  labelList edgeLabels(edges_.size() - nSurfaceEdges_);
328 
329  label i = 0;
330  for (label edgeI = nSurfaceEdges_; edgeI < edges_.size(); edgeI++)
331  {
332  edgeLabels[i++] = edgeI;
333  }
334 
335  writeOBJ(points_, edges_, edgeLabels, intEdgesStream);
336  }
337 }
338 
339 
340 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
341 
343 (
344  const label faceI,
345  const edgeList& additionalEdges
346 )
347 {
348  if (debug & 2)
349  {
350  Pout<< "Old face consisted of edges:" << endl;
351 
352  const labelList& fEdges = faceEdges_[faceI];
353  forAll(fEdges, i)
354  {
355  const edge& e = edges_[fEdges[i]];
356 
357  Pout<< " " << fEdges[i] << ' ' << e
358  << points_[e.start()] << ' ' << points_[e.end()] << endl;
359  }
360  }
361 
362  // Make space for additional intersection edges (copies old ones)
363  const label oldNEdges = edges_.size();
364 
365  edges_.setSize(oldNEdges + additionalEdges.size());
366 
367  // Append new intersection edges
368  label newEdgeI = oldNEdges;
369 
370  forAll(additionalEdges, i)
371  {
372  edges_[newEdgeI] = additionalEdges[i]; // Vertices already in eSurf
373  // indices.
374  newEdgeI++;
375  }
376 
377  // Append to faceEdges.
378  labelList& fEdges = faceEdges_[faceI];
379 
380  label nFEdges = fEdges.size();
381 
382  fEdges.setSize(nFEdges + additionalEdges.size());
383 
384  forAll(additionalEdges, i)
385  {
386  fEdges[nFEdges++] = oldNEdges + i;
387  }
388 
389 
390  // Update pointEdge addressing
391  calcPointEdges();
392 
393 
394  if (debug & 2)
395  {
396  const labelList& fEdges = faceEdges_[faceI];
397 
398  Pout<< "New face consists of edges:" << endl;
399  forAll(fEdges, i)
400  {
401  const edge& e = edges_[fEdges[i]];
402 
403  Pout<< " " << fEdges[i] << ' ' << e
404  << points_[e.start()] << ' ' << points_[e.end()] << endl;
405  }
406  }
407 }
408 
409 
410 // ************************************************************************* //
edgeSurface(const triSurface &surf, const bool isFirstSurface, const surfaceIntersection &inter)
Construct from surface and intersection description.
Definition: edgeSurface.C:128
Output to file stream.
Definition: OFstream.H:81
vector point
Point is a vector.
Definition: point.H:41
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Basic surface-surface intersection description. Constructed from two surfaces it creates a descriptio...
const labelListList & edgeFaces() const
Return edge-face addressing.
bool empty() const
Return true if the UList is empty (ie, size() is zero).
Definition: UListI.H:313
T & last()
Return the last element of the list.
Definition: UListI.H:131
Triangulated surface description with patch information.
Definition: triSurface.H:57
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
label nPoints() const
Return number of points supporting patch faces.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Namespace for OpenFOAM.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
const Field< PointType > & localPoints() const
Return pointField of points in patch.
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
const pointField & cutPoints() const
const Cmpt & x() const
Definition: VectorI.H:65
const labelListList & edgeCuts(const bool) const
Access either surf1EdgeCuts (isFirstSurface = true) or.
List< edge > edgeList
Definition: edgeList.H:38
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
label end() const
Return end vertex label.
Definition: edgeI.H:92
List< label > labelList
A List of labels.
Definition: labelList.H:56
A class for handling file names.
Definition: fileName.H:69
const labelPairLookup & facePairToEdge() const
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:97
label start() const
Return start vertex label.
Definition: edgeI.H:81
label nEdges() const
Return number of edges in patch.
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:209
void transfer(const FixedList< T, Size > &)
Copy (not transfer) the argument contents.
Definition: FixedListI.H:185
void addIntersectionEdges(const label faceI, const edgeList &)
Add intersection edges to a face. Used for connecting.
Definition: edgeSurface.C:343
defineTypeNameAndDebug(combustionModel, 0)
const edgeList & cutEdges() const
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53