OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

extrude2DMesh.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "extrude2DMesh.H"
00028 #include "polyMesh.H"
00029 #include "polyTopoChange.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 defineTypeNameAndDebug(extrude2DMesh, 0);
00037 
00038 }
00039 
00040 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 // Construct from mesh
00046 Foam::extrude2DMesh::extrude2DMesh(const polyMesh& mesh)
00047 :
00048     mesh_(mesh)
00049 {}
00050 
00051 
00052 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00053 
00054 void Foam::extrude2DMesh::setRefinement
00055 (
00056     const direction extrudeDir,
00057     const scalar thickness,
00058     const label frontPatchI,
00059     polyTopoChange& meshMod
00060 ) const
00061 {
00062     for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
00063     {
00064         meshMod.addCell
00065         (
00066             -1,     //masterPointID,
00067             -1,     //masterEdgeID,
00068             -1,     //masterFaceID,
00069             cellI,  //masterCellID,
00070             mesh_.cellZones().whichZone(cellI)  //zoneID
00071         );
00072     }
00073 
00074 
00075     // Generate points
00076     // ~~~~~~~~~~~~~~~
00077 
00078     forAll(mesh_.points(), pointI)
00079     {
00080         meshMod.addPoint
00081         (
00082             mesh_.points()[pointI],
00083             pointI,
00084             -1,             // zoneID
00085             true            // inCell
00086         );
00087     }
00088 
00089     //Info<< "Adding offsetted points." << nl << endl;
00090     forAll(mesh_.points(), pointI)
00091     {
00092         point newPoint(mesh_.points()[pointI]);
00093         newPoint[extrudeDir] = thickness;
00094 
00095         meshMod.addPoint
00096         (
00097             newPoint,
00098             pointI,
00099             -1,             // zoneID
00100             true            // inCell
00101         );
00102     }
00103 
00104 
00105     // Generate faces
00106     // ~~~~~~~~~~~~~~
00107 
00108     const faceList& faces = mesh_.faces();
00109     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00110 
00111     for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00112     {
00113         label zoneID = mesh_.faceZones().whichZone(faceI);
00114         bool zoneFlip = false;
00115         if (zoneID != -1)
00116         {
00117             const faceZone& fZone = mesh_.faceZones()[zoneID];
00118             zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00119         }
00120 
00121         face newFace(4);
00122         const face& f = faces[faceI];
00123         newFace[0] = f[0];
00124         newFace[1] = f[1];
00125         newFace[2] = f[1]+mesh_.nPoints();
00126         newFace[3] = f[0]+mesh_.nPoints();
00127 
00128         meshMod.addFace
00129         (
00130             newFace,
00131             mesh_.faceOwner()[faceI],       // own
00132             mesh_.faceNeighbour()[faceI],   // nei
00133             -1,                             // masterPointID
00134             -1,                             // masterEdgeID
00135             faceI,                          // masterFaceID
00136             false,                          // flipFaceFlux
00137             -1,                             // patchID
00138             zoneID,                         // zoneID
00139             zoneFlip                        // zoneFlip
00140         );
00141     }
00142 
00143     forAll(patches, patchI)
00144     {
00145         label startFaceI = patches[patchI].start();
00146         label endFaceI = startFaceI + patches[patchI].size();
00147 
00148         for (label faceI = startFaceI; faceI < endFaceI; faceI++)
00149         {
00150             label zoneID = mesh_.faceZones().whichZone(faceI);
00151             bool zoneFlip = false;
00152             if (zoneID != -1)
00153             {
00154                 const faceZone& fZone = mesh_.faceZones()[zoneID];
00155                 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00156             }
00157 
00158             face newFace(4);
00159             const face& f = faces[faceI];
00160             newFace[0] = f[0];
00161             newFace[1] = f[1];
00162             newFace[2] = f[1]+mesh_.nPoints();
00163             newFace[3] = f[0]+mesh_.nPoints();
00164 
00165             meshMod.addFace
00166             (
00167                 newFace,
00168                 mesh_.faceOwner()[faceI],       // own
00169                 -1,                             // nei
00170                 -1,                             // masterPointID
00171                 -1,                             // masterEdgeID
00172                 faceI,                          // masterFaceID
00173                 false,                          // flipFaceFlux
00174                 patchI,                         // patchID
00175                 zoneID,                         // zoneID
00176                 zoneFlip                        // zoneFlip
00177             );
00178         }
00179     }
00180 
00181 
00182     // Generate front and back faces
00183     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00184 
00185     forAll(mesh_.cells(), cellI)
00186     {
00187         const cell& cFaces = mesh_.cells()[cellI];
00188 
00189         // Make a loop out of faces.
00190         const face& f = faces[cFaces[0]];
00191 
00192         face frontFace(cFaces.size());
00193         frontFace[0] = f[0];
00194 
00195         label nextPointI = f[1];
00196         label nextFaceI = cFaces[0];
00197 
00198         for (label i = 1; i < frontFace.size(); i++)
00199         {
00200             frontFace[i] = nextPointI;
00201 
00202             // Find face containing pointI
00203             forAll(cFaces, cFaceI)
00204             {
00205                 label faceI = cFaces[cFaceI];
00206                 if (faceI != nextFaceI)
00207                 {
00208                     const face& f = faces[faceI];
00209 
00210                     if (f[0] == nextPointI)
00211                     {
00212                         nextPointI = f[1];
00213                         nextFaceI = faceI;
00214                         break;
00215                     }
00216                     else if (f[1] == nextPointI)
00217                     {
00218                         nextPointI = f[0];
00219                         nextFaceI = faceI;
00220                         break;
00221                     }
00222                 }
00223             }
00224         }
00225 
00226 
00227         // Add back face.
00228         meshMod.addFace
00229         (
00230             frontFace.reverseFace(),
00231             cellI,                          // own
00232             -1,                             // nei
00233             -1,                             // masterPointID
00234             -1,                             // masterEdgeID
00235             cFaces[0],                      // masterFaceID
00236             false,                          // flipFaceFlux
00237             frontPatchI,                    // patchID
00238             -1,                             // zoneID
00239             false                           // zoneFlip
00240         );
00241 
00242         // Offset to create front face.
00243         forAll(frontFace, fp)
00244         {
00245             frontFace[fp] += mesh_.nPoints();
00246         }
00247         meshMod.addFace
00248         (
00249             frontFace,
00250             cellI,                          // own
00251             -1,                             // nei
00252             -1,                             // masterPointID
00253             -1,                             // masterEdgeID
00254             cFaces[0],                      // masterFaceID
00255             false,                          // flipFaceFlux
00256             frontPatchI,                    // patchID
00257             -1,                             // zoneID
00258             false                           // zoneFlip
00259         );
00260     }
00261 }
00262 
00263 
00264 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd