initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / generation / extrude2DMesh / extrude2DMesh.C
blobbb4196d10f8718839c169886e03cff5ebd8b1a93
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "extrude2DMesh.H"
28 #include "polyMesh.H"
29 #include "polyTopoChange.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
36 defineTypeNameAndDebug(extrude2DMesh, 0);
40 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 // Construct from mesh
46 Foam::extrude2DMesh::extrude2DMesh(const polyMesh& mesh)
48     mesh_(mesh)
52 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
54 void Foam::extrude2DMesh::setRefinement
56     const direction extrudeDir,
57     const scalar thickness,
58     const label frontPatchI,
59     polyTopoChange& meshMod
60 ) const
62     for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
63     {
64         meshMod.addCell
65         (
66             -1,     //masterPointID,
67             -1,     //masterEdgeID,
68             -1,     //masterFaceID,
69             cellI,  //masterCellID,
70             mesh_.cellZones().whichZone(cellI)  //zoneID
71         );
72     }
75     // Generate points
76     // ~~~~~~~~~~~~~~~
78     forAll(mesh_.points(), pointI)
79     {
80         meshMod.addPoint
81         (
82             mesh_.points()[pointI],
83             pointI,
84             -1,             // zoneID
85             true            // inCell
86         );
87     }
89     //Info<< "Adding offsetted points." << nl << endl;
90     forAll(mesh_.points(), pointI)
91     {
92         point newPoint(mesh_.points()[pointI]);
93         newPoint[extrudeDir] = thickness;
95         meshMod.addPoint
96         (
97             newPoint,
98             pointI,
99             -1,             // zoneID
100             true            // inCell
101         );
102     }
105     // Generate faces
106     // ~~~~~~~~~~~~~~
108     const faceList& faces = mesh_.faces();
109     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
111     for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
112     {
113         label zoneID = mesh_.faceZones().whichZone(faceI);
114         bool zoneFlip = false;
115         if (zoneID != -1)
116         {
117             const faceZone& fZone = mesh_.faceZones()[zoneID];
118             zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
119         }
121         face newFace(4);
122         const face& f = faces[faceI];
123         newFace[0] = f[0];
124         newFace[1] = f[1];
125         newFace[2] = f[1]+mesh_.nPoints();
126         newFace[3] = f[0]+mesh_.nPoints();
128         meshMod.addFace
129         (
130             newFace,
131             mesh_.faceOwner()[faceI],       // own
132             mesh_.faceNeighbour()[faceI],   // nei
133             -1,                             // masterPointID
134             -1,                             // masterEdgeID
135             faceI,                          // masterFaceID
136             false,                          // flipFaceFlux
137             -1,                             // patchID
138             zoneID,                         // zoneID
139             zoneFlip                        // zoneFlip
140         );
141     }
143     forAll(patches, patchI)
144     {
145         label startFaceI = patches[patchI].start();
146         label endFaceI = startFaceI + patches[patchI].size();
148         for (label faceI = startFaceI; faceI < endFaceI; faceI++)
149         {
150             label zoneID = mesh_.faceZones().whichZone(faceI);
151             bool zoneFlip = false;
152             if (zoneID != -1)
153             {
154                 const faceZone& fZone = mesh_.faceZones()[zoneID];
155                 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
156             }
158             face newFace(4);
159             const face& f = faces[faceI];
160             newFace[0] = f[0];
161             newFace[1] = f[1];
162             newFace[2] = f[1]+mesh_.nPoints();
163             newFace[3] = f[0]+mesh_.nPoints();
165             meshMod.addFace
166             (
167                 newFace,
168                 mesh_.faceOwner()[faceI],       // own
169                 -1,                             // nei
170                 -1,                             // masterPointID
171                 -1,                             // masterEdgeID
172                 faceI,                          // masterFaceID
173                 false,                          // flipFaceFlux
174                 patchI,                         // patchID
175                 zoneID,                         // zoneID
176                 zoneFlip                        // zoneFlip
177             );
178         }
179     }
182     // Generate front and back faces
183     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185     forAll(mesh_.cells(), cellI)
186     {
187         const cell& cFaces = mesh_.cells()[cellI];
189         // Make a loop out of faces.
190         const face& f = faces[cFaces[0]];
192         face frontFace(cFaces.size());
193         frontFace[0] = f[0];
195         label nextPointI = f[1];
196         label nextFaceI = cFaces[0];
198         for (label i = 1; i < frontFace.size(); i++)
199         {
200             frontFace[i] = nextPointI;
202             // Find face containing pointI
203             forAll(cFaces, cFaceI)
204             {
205                 label faceI = cFaces[cFaceI];
206                 if (faceI != nextFaceI)
207                 {
208                     const face& f = faces[faceI];
210                     if (f[0] == nextPointI)
211                     {
212                         nextPointI = f[1];
213                         nextFaceI = faceI;
214                         break;
215                     }
216                     else if (f[1] == nextPointI)
217                     {
218                         nextPointI = f[0];
219                         nextFaceI = faceI;
220                         break;
221                     }
222                 }
223             }
224         }
227         // Add back face.
228         meshMod.addFace
229         (
230             frontFace.reverseFace(),
231             cellI,                          // own
232             -1,                             // nei
233             -1,                             // masterPointID
234             -1,                             // masterEdgeID
235             cFaces[0],                      // masterFaceID
236             false,                          // flipFaceFlux
237             frontPatchI,                    // patchID
238             -1,                             // zoneID
239             false                           // zoneFlip
240         );
242         // Offset to create front face.
243         forAll(frontFace, fp)
244         {
245             frontFace[fp] += mesh_.nPoints();
246         }
247         meshMod.addFace
248         (
249             frontFace,
250             cellI,                          // own
251             -1,                             // nei
252             -1,                             // masterPointID
253             -1,                             // masterEdgeID
254             cFaces[0],                      // masterFaceID
255             false,                          // flipFaceFlux
256             frontPatchI,                    // patchID
257             -1,                             // zoneID
258             false                           // zoneFlip
259         );
260     }
264 // ************************************************************************* //