Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / mesh / generation / extrude2DMesh / extrude2DMesh.C
blob6b49054a70964481288747fb44411310763711c1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "extrude2DMesh.H"
27 #include "polyMesh.H"
28 #include "directTopoChange.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
35 defineTypeNameAndDebug(extrude2DMesh, 0);
39 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 // Construct from mesh
45 Foam::extrude2DMesh::extrude2DMesh(const polyMesh& mesh)
47     mesh_(mesh)
51 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
53 void Foam::extrude2DMesh::setRefinement
55     const direction extrudeDir,
56     const scalar thickness,
57     const label frontPatchI,
58     directTopoChange& meshMod
59 ) const
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     }
74     // Generate points
75     // ~~~~~~~~~~~~~~~
77     forAll(mesh_.points(), pointI)
78     {
79         meshMod.addPoint
80         (
81             mesh_.points()[pointI],
82             pointI,
83             -1,             // zoneID
84             true            // inCell
85         );
86     }
88     //Info<< "Adding offsetted points." << nl << endl;
89     forAll(mesh_.points(), pointI)
90     {
91         point newPoint(mesh_.points()[pointI]);
92         newPoint[extrudeDir] = thickness;
94         meshMod.addPoint
95         (
96             newPoint,
97             pointI,
98             -1,             // zoneID
99             true            // inCell
100         );
101     }
104     // Generate faces
105     // ~~~~~~~~~~~~~~
107     const faceList& faces = mesh_.faces();
108     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
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         }
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();
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     }
142     forAll(patches, patchI)
143     {
144         label startFaceI = patches[patchI].start();
145         label endFaceI = startFaceI + patches[patchI].size();
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             }
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();
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     }
181     // Generate front and back faces
182     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184     forAll(mesh_.cells(), cellI)
185     {
186         const cell& cFaces = mesh_.cells()[cellI];
188         // Make a loop out of faces.
189         const face& f = faces[cFaces[0]];
191         face frontFace(cFaces.size());
192         frontFace[0] = f[0];
194         label nextPointI = f[1];
195         label nextFaceI = cFaces[0];
197         for (label i = 1; i < frontFace.size(); i++)
198         {
199             frontFace[i] = nextPointI;
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];
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         }
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         );
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     }
263 // ************************************************************************* //