FreeFOAM The Cross-Platform CFD Toolkit
removeFaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Application
25  removeFaces
26 
27 Description
28  Utility to remove faces (combines cells on both sides).
29 
30  Takes faceSet of candidates for removal and writes faceSet with faces that
31  will actually be removed. (because e.g. would cause two faces between the
32  same cells). See removeFaces in dynamicMesh library for constraints.
33 
34 Usage
35 
36  - removeFaces [OPTIONS] <face set>
37 
38  @param <face set> \n
39  @todo Detailed description of argument.
40 
41  @param -overwrite \n
42  Overwrite existing data.
43 
44  @param -case <dir>\n
45  Case directory.
46 
47  @param -parallel \n
48  Run in parallel.
49 
50  @param -help \n
51  Display help message.
52 
53  @param -doc \n
54  Display Doxygen API documentation page for this application.
55 
56  @param -srcDoc \n
57  Display Doxygen source documentation page for this application.
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #include <OpenFOAM/argList.H>
62 #include <OpenFOAM/Time.H>
64 #include <meshTools/faceSet.H>
66 #include <OpenFOAM/ReadFields.H>
67 #include <finiteVolume/volFields.H>
69 
70 using namespace Foam;
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 // Main program:
75 
76 int main(int argc, char *argv[])
77 {
78  Foam::argList::validOptions.insert("overwrite", "");
80 
81 # include <OpenFOAM/setRootCase.H>
82 # include <OpenFOAM/createTime.H>
83  runTime.functionObjects().off();
84 # include <OpenFOAM/createMesh.H>
85  const word oldInstance = mesh.pointsInstance();
86 
87  bool overwrite = args.optionFound("overwrite");
88 
89  word setName(args.additionalArgs()[0]);
90 
91  // Read faces
92  faceSet candidateSet(mesh, setName);
93 
94  Pout<< "Read " << candidateSet.size() << " faces to remove" << nl
95  << endl;
96 
97 
98  labelList candidates(candidateSet.toc());
99 
100  // Face removal engine. No checking for not merging boundary faces.
101  removeFaces faceRemover(mesh, 2);
102 
103  // Get compatible set of faces and connected sets of cells.
104  labelList cellRegion;
105  labelList cellRegionMaster;
106  labelList facesToRemove;
107 
108  faceRemover.compatibleRemoves
109  (
110  candidates,
111  cellRegion,
112  cellRegionMaster,
113  facesToRemove
114  );
115 
116  {
117  faceSet compatibleRemoves(mesh, "compatibleRemoves", facesToRemove);
118 
119  Pout<< "Original faces to be removed:" << candidateSet.size() << nl
120  << "New faces to be removed:" << compatibleRemoves.size() << nl
121  << endl;
122 
123  Pout<< "Writing new faces to be removed to faceSet "
124  << compatibleRemoves.instance()
125  /compatibleRemoves.local()
126  /compatibleRemoves.name()
127  << endl;
128 
129  compatibleRemoves.write();
130  }
131 
132 
133  // Read objects in time directory
134  IOobjectList objects(mesh, runTime.timeName());
135 
136  // Read vol fields.
138  ReadFields(mesh, objects, vsFlds);
139 
141  ReadFields(mesh, objects, vvFlds);
142 
144  ReadFields(mesh, objects, vstFlds);
145 
146  PtrList<volSymmTensorField> vsymtFlds;
147  ReadFields(mesh, objects, vsymtFlds);
148 
150  ReadFields(mesh, objects, vtFlds);
151 
152  // Read surface fields.
154  ReadFields(mesh, objects, ssFlds);
155 
157  ReadFields(mesh, objects, svFlds);
158 
160  ReadFields(mesh, objects, sstFlds);
161 
163  ReadFields(mesh, objects, ssymtFlds);
164 
166  ReadFields(mesh, objects, stFlds);
167 
168 
169  // Topo changes container
170  polyTopoChange meshMod(mesh);
171 
172  // Insert mesh refinement into polyTopoChange.
173  faceRemover.setRefinement
174  (
175  facesToRemove,
176  cellRegion,
177  cellRegionMaster,
178  meshMod
179  );
180 
181  autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
182 
183  mesh.updateMesh(morphMap);
184 
185  // Move mesh (since morphing does not do this)
186  if (morphMap().hasMotionPoints())
187  {
188  mesh.movePoints(morphMap().preMotionPoints());
189  }
190 
191  // Update numbering of cells/vertices.
192  faceRemover.updateMesh(morphMap);
193 
194  if (!overwrite)
195  {
196  runTime++;
197  }
198  else
199  {
200  mesh.setInstance(oldInstance);
201  }
202 
203  // Take over refinement levels and write to new time directory.
204  Pout<< "Writing mesh to time " << runTime.timeName() << endl;
205  mesh.write();
206 
207  Pout<< "End\n" << endl;
208 
209  return 0;
210 }
211 
212 
213 // ************************ vim: set sw=4 sts=4 et: ************************ //