initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / advanced / removeFaces / removeFaces.C
blobc3fcc727d2087f05a8cc8e0beff782a063a0e30b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Utility to remove faces (combines cells on both sides).
28     Takes faceSet of candidates for removal and writes faceSet with faces that
29     will actually be removed. (because e.g. would cause two faces between the
30     same cells). See removeFaces in dynamicMesh library for constraints.
32 \*---------------------------------------------------------------------------*/
34 #include "argList.H"
35 #include "Time.H"
36 #include "polyTopoChange.H"
37 #include "faceSet.H"
38 #include "removeFaces.H"
39 #include "ReadFields.H"
40 #include "volFields.H"
41 #include "surfaceFields.H"
43 using namespace Foam;
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // Main program:
49 int main(int argc, char *argv[])
51     Foam::argList::validOptions.insert("overwrite", "");
52     Foam::argList::validArgs.append("faceSet");
54 #   include "setRootCase.H"
55 #   include "createTime.H"
56     runTime.functionObjects().off();
57 #   include "createMesh.H"
58     const word oldInstance = mesh.pointsInstance();
60     bool overwrite = args.optionFound("overwrite");
62     word setName(args.additionalArgs()[0]);
64     // Read faces
65     faceSet candidateSet(mesh, setName);
67     Pout<< "Read " << candidateSet.size() << " faces to remove" << nl
68         << endl;
71     labelList candidates(candidateSet.toc());
73     // Face removal engine. No checking for not merging boundary faces.
74     removeFaces faceRemover(mesh, 2);
76     // Get compatible set of faces and connected sets of cells.
77     labelList cellRegion;
78     labelList cellRegionMaster;
79     labelList facesToRemove;
81     faceRemover.compatibleRemoves
82     (
83         candidates,
84         cellRegion,
85         cellRegionMaster,
86         facesToRemove
87     );
89     {
90         faceSet compatibleRemoves(mesh, "compatibleRemoves", facesToRemove);
92         Pout<< "Original faces to be removed:" << candidateSet.size() << nl
93             << "New faces to be removed:" << compatibleRemoves.size() << nl
94             << endl;
96         Pout<< "Writing new faces to be removed to faceSet "
97             << compatibleRemoves.instance()
98               /compatibleRemoves.local()
99               /compatibleRemoves.name()
100             << endl;
102         compatibleRemoves.write();
103     }
106     // Read objects in time directory
107     IOobjectList objects(mesh, runTime.timeName());
109     // Read vol fields.
110     PtrList<volScalarField> vsFlds;
111     ReadFields(mesh, objects, vsFlds);
113     PtrList<volVectorField> vvFlds;
114     ReadFields(mesh, objects, vvFlds);
116     PtrList<volSphericalTensorField> vstFlds;
117     ReadFields(mesh, objects, vstFlds);
119     PtrList<volSymmTensorField> vsymtFlds;
120     ReadFields(mesh, objects, vsymtFlds);
122     PtrList<volTensorField> vtFlds;
123     ReadFields(mesh, objects, vtFlds);
125     // Read surface fields.
126     PtrList<surfaceScalarField> ssFlds;
127     ReadFields(mesh, objects, ssFlds);
129     PtrList<surfaceVectorField> svFlds;
130     ReadFields(mesh, objects, svFlds);
132     PtrList<surfaceSphericalTensorField> sstFlds;
133     ReadFields(mesh, objects, sstFlds);
135     PtrList<surfaceSymmTensorField> ssymtFlds;
136     ReadFields(mesh, objects, ssymtFlds);
138     PtrList<surfaceTensorField> stFlds;
139     ReadFields(mesh, objects, stFlds);
142     // Topo changes container
143     polyTopoChange meshMod(mesh);
145     // Insert mesh refinement into polyTopoChange.
146     faceRemover.setRefinement
147     (
148         facesToRemove,
149         cellRegion,
150         cellRegionMaster,
151         meshMod
152     );
154     autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
156     mesh.updateMesh(morphMap);
158     // Move mesh (since morphing does not do this)
159     if (morphMap().hasMotionPoints())
160     {
161         mesh.movePoints(morphMap().preMotionPoints());
162     }
164     // Update numbering of cells/vertices.
165     faceRemover.updateMesh(morphMap);
167     if (!overwrite)
168     {
169         runTime++;
170     }
171     else
172     {
173         mesh.setInstance(oldInstance);
174     }
176     // Take over refinement levels and write to new time directory.
177     Pout<< "Writing mesh to time " << runTime.timeName() << endl;
178     mesh.write();
180     Pout<< "End\n" << endl;
182     return 0;
186 // ************************************************************************* //