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

removeFaces.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 Description
00026     Utility to remove faces (combines cells on both sides).
00027 
00028     Takes faceSet of candidates for removal and writes faceSet with faces that
00029     will actually be removed. (because e.g. would cause two faces between the
00030     same cells). See removeFaces in dynamicMesh library for constraints.
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #include "argList.H"
00035 #include "Time.H"
00036 #include "polyTopoChange.H"
00037 #include "faceSet.H"
00038 #include "removeFaces.H"
00039 #include "ReadFields.H"
00040 #include "volFields.H"
00041 #include "surfaceFields.H"
00042 
00043 using namespace Foam;
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 // Main program:
00048 
00049 int main(int argc, char *argv[])
00050 {
00051     Foam::argList::validOptions.insert("overwrite", "");
00052     Foam::argList::validArgs.append("faceSet");
00053 
00054 #   include "setRootCase.H"
00055 #   include "createTime.H"
00056     runTime.functionObjects().off();
00057 #   include "createMesh.H"
00058     const word oldInstance = mesh.pointsInstance();
00059 
00060     bool overwrite = args.optionFound("overwrite");
00061 
00062     word setName(args.additionalArgs()[0]);
00063 
00064     // Read faces
00065     faceSet candidateSet(mesh, setName);
00066 
00067     Pout<< "Read " << candidateSet.size() << " faces to remove" << nl
00068         << endl;
00069 
00070 
00071     labelList candidates(candidateSet.toc());
00072 
00073     // Face removal engine. No checking for not merging boundary faces.
00074     removeFaces faceRemover(mesh, 2);
00075 
00076     // Get compatible set of faces and connected sets of cells.
00077     labelList cellRegion;
00078     labelList cellRegionMaster;
00079     labelList facesToRemove;
00080 
00081     faceRemover.compatibleRemoves
00082     (
00083         candidates,
00084         cellRegion,
00085         cellRegionMaster,
00086         facesToRemove
00087     );
00088 
00089     {
00090         faceSet compatibleRemoves(mesh, "compatibleRemoves", facesToRemove);
00091 
00092         Pout<< "Original faces to be removed:" << candidateSet.size() << nl
00093             << "New faces to be removed:" << compatibleRemoves.size() << nl
00094             << endl;
00095 
00096         Pout<< "Writing new faces to be removed to faceSet "
00097             << compatibleRemoves.instance()
00098               /compatibleRemoves.local()
00099               /compatibleRemoves.name()
00100             << endl;
00101 
00102         compatibleRemoves.write();
00103     }
00104 
00105 
00106     // Read objects in time directory
00107     IOobjectList objects(mesh, runTime.timeName());
00108 
00109     // Read vol fields.
00110     PtrList<volScalarField> vsFlds;
00111     ReadFields(mesh, objects, vsFlds);
00112 
00113     PtrList<volVectorField> vvFlds;
00114     ReadFields(mesh, objects, vvFlds);
00115 
00116     PtrList<volSphericalTensorField> vstFlds;
00117     ReadFields(mesh, objects, vstFlds);
00118 
00119     PtrList<volSymmTensorField> vsymtFlds;
00120     ReadFields(mesh, objects, vsymtFlds);
00121 
00122     PtrList<volTensorField> vtFlds;
00123     ReadFields(mesh, objects, vtFlds);
00124 
00125     // Read surface fields.
00126     PtrList<surfaceScalarField> ssFlds;
00127     ReadFields(mesh, objects, ssFlds);
00128 
00129     PtrList<surfaceVectorField> svFlds;
00130     ReadFields(mesh, objects, svFlds);
00131 
00132     PtrList<surfaceSphericalTensorField> sstFlds;
00133     ReadFields(mesh, objects, sstFlds);
00134 
00135     PtrList<surfaceSymmTensorField> ssymtFlds;
00136     ReadFields(mesh, objects, ssymtFlds);
00137 
00138     PtrList<surfaceTensorField> stFlds;
00139     ReadFields(mesh, objects, stFlds);
00140 
00141 
00142     // Topo changes container
00143     polyTopoChange meshMod(mesh);
00144 
00145     // Insert mesh refinement into polyTopoChange.
00146     faceRemover.setRefinement
00147     (
00148         facesToRemove,
00149         cellRegion,
00150         cellRegionMaster,
00151         meshMod
00152     );
00153 
00154     autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
00155 
00156     mesh.updateMesh(morphMap);
00157 
00158     // Move mesh (since morphing does not do this)
00159     if (morphMap().hasMotionPoints())
00160     {
00161         mesh.movePoints(morphMap().preMotionPoints());
00162     }
00163 
00164     // Update numbering of cells/vertices.
00165     faceRemover.updateMesh(morphMap);
00166 
00167     if (!overwrite)
00168     {
00169         runTime++;
00170     }
00171     else
00172     {
00173         mesh.setInstance(oldInstance);
00174     }
00175 
00176     // Take over refinement levels and write to new time directory.
00177     Pout<< "Writing mesh to time " << runTime.timeName() << endl;
00178     mesh.write();
00179 
00180     Pout<< "End\n" << endl;
00181 
00182     return 0;
00183 }
00184 
00185 
00186 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd