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

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