FreeFOAM The Cross-Platform CFD Toolkit
extrude2DMesh.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) 1991-2010 OpenCFD Ltd.
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 "extrude2DMesh.H"
27 #include <OpenFOAM/polyMesh.H>
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 defineTypeNameAndDebug(extrude2DMesh, 0);
36 
37 }
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 // Construct from mesh
46 :
47  mesh_(mesh)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
54 (
55  const direction extrudeDir,
56  const scalar thickness,
57  const label frontPatchI,
58  polyTopoChange& meshMod
59 ) const
60 {
61  for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
62  {
63  meshMod.addCell
64  (
65  -1, //masterPointID,
66  -1, //masterEdgeID,
67  -1, //masterFaceID,
68  cellI, //masterCellID,
69  mesh_.cellZones().whichZone(cellI) //zoneID
70  );
71  }
72 
73 
74  // Generate points
75  // ~~~~~~~~~~~~~~~
76 
77  forAll(mesh_.points(), pointI)
78  {
79  meshMod.addPoint
80  (
81  mesh_.points()[pointI],
82  pointI,
83  -1, // zoneID
84  true // inCell
85  );
86  }
87 
88  //Info<< "Adding offsetted points." << nl << endl;
89  forAll(mesh_.points(), pointI)
90  {
91  point newPoint(mesh_.points()[pointI]);
92  newPoint[extrudeDir] = thickness;
93 
94  meshMod.addPoint
95  (
96  newPoint,
97  pointI,
98  -1, // zoneID
99  true // inCell
100  );
101  }
102 
103 
104  // Generate faces
105  // ~~~~~~~~~~~~~~
106 
107  const faceList& faces = mesh_.faces();
108  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
109 
110  for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
111  {
112  label zoneID = mesh_.faceZones().whichZone(faceI);
113  bool zoneFlip = false;
114  if (zoneID != -1)
115  {
116  const faceZone& fZone = mesh_.faceZones()[zoneID];
117  zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
118  }
119 
120  face newFace(4);
121  const face& f = faces[faceI];
122  newFace[0] = f[0];
123  newFace[1] = f[1];
124  newFace[2] = f[1]+mesh_.nPoints();
125  newFace[3] = f[0]+mesh_.nPoints();
126 
127  meshMod.addFace
128  (
129  newFace,
130  mesh_.faceOwner()[faceI], // own
131  mesh_.faceNeighbour()[faceI], // nei
132  -1, // masterPointID
133  -1, // masterEdgeID
134  faceI, // masterFaceID
135  false, // flipFaceFlux
136  -1, // patchID
137  zoneID, // zoneID
138  zoneFlip // zoneFlip
139  );
140  }
141 
142  forAll(patches, patchI)
143  {
144  label startFaceI = patches[patchI].start();
145  label endFaceI = startFaceI + patches[patchI].size();
146 
147  for (label faceI = startFaceI; faceI < endFaceI; faceI++)
148  {
149  label zoneID = mesh_.faceZones().whichZone(faceI);
150  bool zoneFlip = false;
151  if (zoneID != -1)
152  {
153  const faceZone& fZone = mesh_.faceZones()[zoneID];
154  zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
155  }
156 
157  face newFace(4);
158  const face& f = faces[faceI];
159  newFace[0] = f[0];
160  newFace[1] = f[1];
161  newFace[2] = f[1]+mesh_.nPoints();
162  newFace[3] = f[0]+mesh_.nPoints();
163 
164  meshMod.addFace
165  (
166  newFace,
167  mesh_.faceOwner()[faceI], // own
168  -1, // nei
169  -1, // masterPointID
170  -1, // masterEdgeID
171  faceI, // masterFaceID
172  false, // flipFaceFlux
173  patchI, // patchID
174  zoneID, // zoneID
175  zoneFlip // zoneFlip
176  );
177  }
178  }
179 
180 
181  // Generate front and back faces
182  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183 
184  forAll(mesh_.cells(), cellI)
185  {
186  const cell& cFaces = mesh_.cells()[cellI];
187 
188  // Make a loop out of faces.
189  const face& f = faces[cFaces[0]];
190 
191  face frontFace(cFaces.size());
192  frontFace[0] = f[0];
193 
194  label nextPointI = f[1];
195  label nextFaceI = cFaces[0];
196 
197  for (label i = 1; i < frontFace.size(); i++)
198  {
199  frontFace[i] = nextPointI;
200 
201  // Find face containing pointI
202  forAll(cFaces, cFaceI)
203  {
204  label faceI = cFaces[cFaceI];
205  if (faceI != nextFaceI)
206  {
207  const face& f = faces[faceI];
208 
209  if (f[0] == nextPointI)
210  {
211  nextPointI = f[1];
212  nextFaceI = faceI;
213  break;
214  }
215  else if (f[1] == nextPointI)
216  {
217  nextPointI = f[0];
218  nextFaceI = faceI;
219  break;
220  }
221  }
222  }
223  }
224 
225 
226  // Add back face.
227  meshMod.addFace
228  (
229  frontFace.reverseFace(),
230  cellI, // own
231  -1, // nei
232  -1, // masterPointID
233  -1, // masterEdgeID
234  cFaces[0], // masterFaceID
235  false, // flipFaceFlux
236  frontPatchI, // patchID
237  -1, // zoneID
238  false // zoneFlip
239  );
240 
241  // Offset to create front face.
242  forAll(frontFace, fp)
243  {
244  frontFace[fp] += mesh_.nPoints();
245  }
246  meshMod.addFace
247  (
248  frontFace,
249  cellI, // own
250  -1, // nei
251  -1, // masterPointID
252  -1, // masterEdgeID
253  cFaces[0], // masterFaceID
254  false, // flipFaceFlux
255  frontPatchI, // patchID
256  -1, // zoneID
257  false // zoneFlip
258  );
259  }
260 }
261 
262 
263 // ************************ vim: set sw=4 sts=4 et: ************************ //