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

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