FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "extrude2DMesh.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <dynamicMesh/polyTopoChange.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 defineTypeNameAndDebug(extrude2DMesh, 0);
00036 
00037 }
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 
00042 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00043 
00044 // Construct from mesh
00045 Foam::extrude2DMesh::extrude2DMesh(const polyMesh& mesh)
00046 :
00047     mesh_(mesh)
00048 {}
00049 
00050 
00051 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00052 
00053 void Foam::extrude2DMesh::setRefinement
00054 (
00055     const direction extrudeDir,
00056     const scalar thickness,
00057     const label frontPatchI,
00058     polyTopoChange& meshMod
00059 ) const
00060 {
00061     for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
00062     {
00063         meshMod.addCell
00064         (
00065             -1,     //masterPointID,
00066             -1,     //masterEdgeID,
00067             -1,     //masterFaceID,
00068             cellI,  //masterCellID,
00069             mesh_.cellZones().whichZone(cellI)  //zoneID
00070         );
00071     }
00072 
00073 
00074     // Generate points
00075     // ~~~~~~~~~~~~~~~
00076 
00077     forAll(mesh_.points(), pointI)
00078     {
00079         meshMod.addPoint
00080         (
00081             mesh_.points()[pointI],
00082             pointI,
00083             -1,             // zoneID
00084             true            // inCell
00085         );
00086     }
00087 
00088     //Info<< "Adding offsetted points." << nl << endl;
00089     forAll(mesh_.points(), pointI)
00090     {
00091         point newPoint(mesh_.points()[pointI]);
00092         newPoint[extrudeDir] = thickness;
00093 
00094         meshMod.addPoint
00095         (
00096             newPoint,
00097             pointI,
00098             -1,             // zoneID
00099             true            // inCell
00100         );
00101     }
00102 
00103 
00104     // Generate faces
00105     // ~~~~~~~~~~~~~~
00106 
00107     const faceList& faces = mesh_.faces();
00108     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00109 
00110     for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00111     {
00112         label zoneID = mesh_.faceZones().whichZone(faceI);
00113         bool zoneFlip = false;
00114         if (zoneID != -1)
00115         {
00116             const faceZone& fZone = mesh_.faceZones()[zoneID];
00117             zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00118         }
00119 
00120         face newFace(4);
00121         const face& f = faces[faceI];
00122         newFace[0] = f[0];
00123         newFace[1] = f[1];
00124         newFace[2] = f[1]+mesh_.nPoints();
00125         newFace[3] = f[0]+mesh_.nPoints();
00126 
00127         meshMod.addFace
00128         (
00129             newFace,
00130             mesh_.faceOwner()[faceI],       // own
00131             mesh_.faceNeighbour()[faceI],   // nei
00132             -1,                             // masterPointID
00133             -1,                             // masterEdgeID
00134             faceI,                          // masterFaceID
00135             false,                          // flipFaceFlux
00136             -1,                             // patchID
00137             zoneID,                         // zoneID
00138             zoneFlip                        // zoneFlip
00139         );
00140     }
00141 
00142     forAll(patches, patchI)
00143     {
00144         label startFaceI = patches[patchI].start();
00145         label endFaceI = startFaceI + patches[patchI].size();
00146 
00147         for (label faceI = startFaceI; faceI < endFaceI; faceI++)
00148         {
00149             label zoneID = mesh_.faceZones().whichZone(faceI);
00150             bool zoneFlip = false;
00151             if (zoneID != -1)
00152             {
00153                 const faceZone& fZone = mesh_.faceZones()[zoneID];
00154                 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00155             }
00156 
00157             face newFace(4);
00158             const face& f = faces[faceI];
00159             newFace[0] = f[0];
00160             newFace[1] = f[1];
00161             newFace[2] = f[1]+mesh_.nPoints();
00162             newFace[3] = f[0]+mesh_.nPoints();
00163 
00164             meshMod.addFace
00165             (
00166                 newFace,
00167                 mesh_.faceOwner()[faceI],       // own
00168                 -1,                             // nei
00169                 -1,                             // masterPointID
00170                 -1,                             // masterEdgeID
00171                 faceI,                          // masterFaceID
00172                 false,                          // flipFaceFlux
00173                 patchI,                         // patchID
00174                 zoneID,                         // zoneID
00175                 zoneFlip                        // zoneFlip
00176             );
00177         }
00178     }
00179 
00180 
00181     // Generate front and back faces
00182     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00183 
00184     forAll(mesh_.cells(), cellI)
00185     {
00186         const cell& cFaces = mesh_.cells()[cellI];
00187 
00188         // Make a loop out of faces.
00189         const face& f = faces[cFaces[0]];
00190 
00191         face frontFace(cFaces.size());
00192         frontFace[0] = f[0];
00193 
00194         label nextPointI = f[1];
00195         label nextFaceI = cFaces[0];
00196 
00197         for (label i = 1; i < frontFace.size(); i++)
00198         {
00199             frontFace[i] = nextPointI;
00200 
00201             // Find face containing pointI
00202             forAll(cFaces, cFaceI)
00203             {
00204                 label faceI = cFaces[cFaceI];
00205                 if (faceI != nextFaceI)
00206                 {
00207                     const face& f = faces[faceI];
00208 
00209                     if (f[0] == nextPointI)
00210                     {
00211                         nextPointI = f[1];
00212                         nextFaceI = faceI;
00213                         break;
00214                     }
00215                     else if (f[1] == nextPointI)
00216                     {
00217                         nextPointI = f[0];
00218                         nextFaceI = faceI;
00219                         break;
00220                     }
00221                 }
00222             }
00223         }
00224 
00225 
00226         // Add back face.
00227         meshMod.addFace
00228         (
00229             frontFace.reverseFace(),
00230             cellI,                          // own
00231             -1,                             // nei
00232             -1,                             // masterPointID
00233             -1,                             // masterEdgeID
00234             cFaces[0],                      // masterFaceID
00235             false,                          // flipFaceFlux
00236             frontPatchI,                    // patchID
00237             -1,                             // zoneID
00238             false                           // zoneFlip
00239         );
00240 
00241         // Offset to create front face.
00242         forAll(frontFace, fp)
00243         {
00244             frontFace[fp] += mesh_.nPoints();
00245         }
00246         meshMod.addFace
00247         (
00248             frontFace,
00249             cellI,                          // own
00250             -1,                             // nei
00251             -1,                             // masterPointID
00252             -1,                             // masterEdgeID
00253             cFaces[0],                      // masterFaceID
00254             false,                          // flipFaceFlux
00255             frontPatchI,                    // patchID
00256             -1,                             // zoneID
00257             false                           // zoneFlip
00258         );
00259     }
00260 }
00261 
00262 
00263 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines