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

doExtrude2DMesh.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 Application
00025     extrude2DMesh
00026 
00027 Description
00028     Takes 2D mesh (all faces 2 points only, no front and back faces) and
00029     creates a 3D mesh by extruding with specified thickness.
00030 
00031 Usage
00032 
00033     - extrude2DMesh <thickness>
00034 
00035     @param <thickness> \n
00036     Thickness (in metre) of slab.
00037 
00038     @param -case <dir> \n
00039     Case directory.
00040 
00041     @param -parallel \n
00042     Run in parallel.
00043 
00044     @param -help \n
00045     Display help message.
00046 
00047     @param -doc \n
00048     Display Doxygen API documentation page for this application.
00049 
00050     @param -srcDoc \n
00051     Display Doxygen source documentation page for this application.
00052 
00053 Note
00054     Not sure about the walking of the faces to create the front and back faces.
00055     Tested on one .ccm file.
00056 
00057 \*---------------------------------------------------------------------------*/
00058 
00059 #include <OpenFOAM/argList.H>
00060 #include <OpenFOAM/Time.H>
00061 #include <OpenFOAM/polyMesh.H>
00062 #include <dynamicMesh/polyTopoChange.H>
00063 #include "extrude2DMesh.H"
00064 #include <OpenFOAM/emptyPolyPatch.H>
00065 
00066 using namespace Foam;
00067 
00068 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00069 
00070 // Main program:
00071 
00072 int main(int argc, char *argv[])
00073 {
00074     argList::validArgs.append("thickness");
00075     argList::validOptions.insert("overwrite", "");
00076 #   include <OpenFOAM/setRootCase.H>
00077 #   include <OpenFOAM/createTime.H>
00078     runTime.functionObjects().off();
00079 #   include <OpenFOAM/createPolyMesh.H>
00080     const word oldInstance = mesh.pointsInstance();
00081 
00082     scalar thickness(readScalar(IStringStream(args.additionalArgs()[0])()));
00083     bool overwrite = args.optionFound("overwrite");
00084 
00085 
00086     // Check that mesh is 2D
00087     // ~~~~~~~~~~~~~~~~~~~~~
00088 
00089     const faceList& faces = mesh.faces();
00090     forAll(faces, faceI)
00091     {
00092         if (faces[faceI].size() != 2)
00093         {
00094             FatalErrorIn(args.executable())
00095                 << "Face " << faceI << " size " << faces[faceI].size()
00096                 << " is not of size 2 so mesh is not proper two-dimensional."
00097                 << exit(FatalError);
00098         }
00099     }
00100 
00101 
00102     // Find extrude direction
00103     // ~~~~~~~~~~~~~~~~~~~~~~
00104 
00105     scalar minRange = GREAT;
00106     direction extrudeDir = 4;   //illegal value.
00107 
00108     for (direction dir = 0; dir < 3; dir++)
00109     {
00110         scalarField cmpts(mesh.points().component(dir));
00111 
00112         scalar range = max(cmpts)-min(cmpts);
00113 
00114         Info<< "Direction:" << dir << " range:" << range << endl;
00115 
00116         if (range < minRange)
00117         {
00118             minRange = range;
00119             extrudeDir = dir;
00120         }
00121     }
00122 
00123     Info<< "Extruding in direction " << extrudeDir
00124         << " with thickness " << thickness << nl
00125         << endl;
00126 
00127 
00128 
00129     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00130 
00131 
00132     // Add front and back patch
00133     // ~~~~~~~~~~~~~~~~~~~~~~~~
00134 
00135     label frontPatchI = patches.findPatchID("frontAndBack");
00136 
00137     if (frontPatchI == -1)
00138     {
00139         // Add patch.
00140         List<polyPatch*> newPatches(patches.size()+1);
00141 
00142         forAll(patches, patchI)
00143         {
00144             const polyPatch& pp = patches[patchI];
00145 
00146             newPatches[patchI] = pp.clone
00147             (
00148                 patches,
00149                 newPatches.size(),
00150                 pp.size(),
00151                 pp.start()
00152             ).ptr();
00153         }
00154 
00155         frontPatchI = patches.size();
00156 
00157         newPatches[frontPatchI] = new emptyPolyPatch
00158         (
00159             "frontAndBack",
00160             0,
00161             mesh.nFaces(),
00162             frontPatchI,
00163             patches
00164         );
00165 
00166         Info<< "Adding empty patch " << newPatches[frontPatchI]->name()
00167             << " at index " << frontPatchI
00168             << " for front and back faces." << nl << endl;
00169 
00170         mesh.removeBoundary();
00171         mesh.addPatches(newPatches);
00172     }
00173 
00174 
00175 
00176     // Topo changes container. Initialise with number of patches.
00177     polyTopoChange meshMod(mesh.boundaryMesh().size());
00178 
00179     // Engine to extrude mesh
00180     extrude2DMesh extruder(mesh);
00181 
00182     // Insert changes into meshMod
00183     extruder.setRefinement
00184     (
00185         extrudeDir,
00186         thickness,
00187         frontPatchI,
00188         meshMod
00189     );
00190 
00191     // Create a mesh from topo changes.
00192     autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
00193 
00194     mesh.updateMesh(morphMap);
00195 
00196     if (!overwrite)
00197     {
00198         runTime++;
00199     }
00200     else
00201     {
00202         mesh.setInstance(oldInstance);
00203     }
00204 
00205     // Take over refinement levels and write to new time directory.
00206     Pout<< "Writing extruded mesh to time " << runTime.timeName() << nl
00207         << endl;
00208 
00209     mesh.write();
00210 
00211     Pout<< "End\n" << endl;
00212 
00213     return 0;
00214 }
00215 
00216 
00217 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines