Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / applications / utilities / mesh / advanced / removeFaces / removeFaces.C
blobce8848101278316bb82c0f60336b1cffc15c6a50
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Description
25     Utility to remove faces (combines cells on both sides).
27     Takes faceSet of candidates for removal and writes faceSet with faces that
28     will actually be removed. (because e.g. would cause two faces between the
29     same cells). See removeFaces in dynamicMesh library for constraints.
31 \*---------------------------------------------------------------------------*/
33 #include "argList.H"
34 #include "Time.H"
35 #include "polyTopoChange.H"
36 #include "faceSet.H"
37 #include "removeFaces.H"
38 #include "ReadFields.H"
39 #include "volFields.H"
40 #include "surfaceFields.H"
42 using namespace Foam;
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // Main program:
48 int main(int argc, char *argv[])
50 #   include "addOverwriteOption.H"
51     argList::validArgs.append("faceSet");
53 #   include "setRootCase.H"
54 #   include "createTime.H"
55     runTime.functionObjects().off();
56 #   include "createMesh.H"
57     const word oldInstance = mesh.pointsInstance();
59     const word setName = args[1];
60     const bool overwrite = args.optionFound("overwrite");
62     // Read faces
63     faceSet candidateSet(mesh, setName);
65     Pout<< "Read " << candidateSet.size() << " faces to remove" << nl
66         << endl;
69     labelList candidates(candidateSet.toc());
71     // Face removal engine. No checking for not merging boundary faces.
72     removeFaces faceRemover(mesh, 2);
74     // Get compatible set of faces and connected sets of cells.
75     labelList cellRegion;
76     labelList cellRegionMaster;
77     labelList facesToRemove;
79     faceRemover.compatibleRemoves
80     (
81         candidates,
82         cellRegion,
83         cellRegionMaster,
84         facesToRemove
85     );
87     {
88         faceSet compatibleRemoves(mesh, "compatibleRemoves", facesToRemove);
90         Pout<< "Original faces to be removed:" << candidateSet.size() << nl
91             << "New faces to be removed:" << compatibleRemoves.size() << nl
92             << endl;
94         Pout<< "Writing new faces to be removed to faceSet "
95             << compatibleRemoves.instance()
96               /compatibleRemoves.local()
97               /compatibleRemoves.name()
98             << endl;
100         compatibleRemoves.write();
101     }
104     // Read objects in time directory
105     IOobjectList objects(mesh, runTime.timeName());
107     // Read vol fields.
108     PtrList<volScalarField> vsFlds;
109     ReadFields(mesh, objects, vsFlds);
111     PtrList<volVectorField> vvFlds;
112     ReadFields(mesh, objects, vvFlds);
114     PtrList<volSphericalTensorField> vstFlds;
115     ReadFields(mesh, objects, vstFlds);
117     PtrList<volSymmTensorField> vsymtFlds;
118     ReadFields(mesh, objects, vsymtFlds);
120     PtrList<volTensorField> vtFlds;
121     ReadFields(mesh, objects, vtFlds);
123     // Read surface fields.
124     PtrList<surfaceScalarField> ssFlds;
125     ReadFields(mesh, objects, ssFlds);
127     PtrList<surfaceVectorField> svFlds;
128     ReadFields(mesh, objects, svFlds);
130     PtrList<surfaceSphericalTensorField> sstFlds;
131     ReadFields(mesh, objects, sstFlds);
133     PtrList<surfaceSymmTensorField> ssymtFlds;
134     ReadFields(mesh, objects, ssymtFlds);
136     PtrList<surfaceTensorField> stFlds;
137     ReadFields(mesh, objects, stFlds);
140     // Topo changes container
141     polyTopoChange meshMod(mesh);
143     // Insert mesh refinement into polyTopoChange.
144     faceRemover.setRefinement
145     (
146         facesToRemove,
147         cellRegion,
148         cellRegionMaster,
149         meshMod
150     );
152     autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
154     mesh.updateMesh(morphMap);
156     // Move mesh (since morphing does not do this)
157     if (morphMap().hasMotionPoints())
158     {
159         mesh.movePoints(morphMap().preMotionPoints());
160     }
162     // Update numbering of cells/vertices.
163     faceRemover.updateMesh(morphMap);
165     if (!overwrite)
166     {
167         runTime++;
168     }
169     else
170     {
171         mesh.setInstance(oldInstance);
172     }
174     // Take over refinement levels and write to new time directory.
175     Pout<< "Writing mesh to time " << runTime.timeName() << endl;
176     mesh.write();
178     Pout<< "End\n" << endl;
180     return 0;
184 // ************************************************************************* //