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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2016 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Application
28 removeFaces
29
30Group
31 grpMeshAdvancedUtilities
32
33Description
34 Remove faces specified in faceSet by combining cells on both sides.
35
36 Takes faceSet of candidates for removal and writes faceSet with faces that
37 will actually be removed. (because e.g. would cause two faces between the
38 same cells). See removeFaces in dynamicMesh library for constraints.
39
40\*---------------------------------------------------------------------------*/
41
42#include "argList.H"
43#include "Time.H"
44#include "polyTopoChange.H"
45#include "faceSet.H"
46#include "removeFaces.H"
47#include "ReadFields.H"
48#include "volFields.H"
49#include "surfaceFields.H"
50#include "processorMeshes.H"
51
52using namespace Foam;
53
54// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55
56
57int main(int argc, char *argv[])
58{
59 argList::addNote
60 (
61 "Remove faces specified in faceSet by combining cells on both sides"
62 );
63 #include "addOverwriteOption.H"
64 argList::addArgument("faceSet");
65
66 argList::noFunctionObjects(); // Never use function objects
67
68 #include "setRootCase.H"
69 #include "createTime.H"
70 #include "createNamedMesh.H"
71
72 const word oldInstance = mesh.pointsInstance();
73
74 const word setName = args[1];
75 const bool overwrite = args.found("overwrite");
76
77 // Read faces
78 faceSet candidateSet(mesh, setName);
79
80 Pout<< "Read " << candidateSet.size() << " faces to remove" << nl
81 << endl;
82
83
84 labelList candidates(candidateSet.toc());
85
86 // Face removal engine. No checking for not merging boundary faces.
87 removeFaces faceRemover(mesh, 2);
88
89 // Get compatible set of faces and connected sets of cells.
90 labelList cellRegion;
91 labelList cellRegionMaster;
92 labelList facesToRemove;
93
94 faceRemover.compatibleRemoves
95 (
96 candidates,
97 cellRegion,
98 cellRegionMaster,
99 facesToRemove
100 );
101
102 {
103 faceSet compatibleRemoves(mesh, "compatibleRemoves", facesToRemove);
104
105 Pout<< "Original faces to be removed:" << candidateSet.size() << nl
106 << "New faces to be removed:" << compatibleRemoves.size() << nl
107 << endl;
108
109 Pout<< "Writing new faces to be removed to faceSet "
110 << compatibleRemoves.instance()
111 /compatibleRemoves.local()
112 /compatibleRemoves.name()
113 << endl;
114
115 compatibleRemoves.write();
116 }
117
118
119 // Read objects in time directory
120 IOobjectList objects(mesh, runTime.timeName());
121
122 // Read vol fields.
124 ReadFields(mesh, objects, vsFlds);
125
127 ReadFields(mesh, objects, vvFlds);
128
130 ReadFields(mesh, objects, vstFlds);
131
133 ReadFields(mesh, objects, vsymtFlds);
134
136 ReadFields(mesh, objects, vtFlds);
137
138 // Read surface fields.
140 ReadFields(mesh, objects, ssFlds);
141
143 ReadFields(mesh, objects, svFlds);
144
146 ReadFields(mesh, objects, sstFlds);
147
149 ReadFields(mesh, objects, ssymtFlds);
150
152 ReadFields(mesh, objects, stFlds);
153
154
155 // Topo changes container
156 polyTopoChange meshMod(mesh);
157
158 // Insert mesh refinement into polyTopoChange.
159 faceRemover.setRefinement
160 (
161 facesToRemove,
162 cellRegion,
163 cellRegionMaster,
164 meshMod
165 );
166
167 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
168
169 mesh.updateMesh(map());
170
171 // Move mesh (since morphing does not do this)
172 if (map().hasMotionPoints())
173 {
174 mesh.movePoints(map().preMotionPoints());
175 }
176
177 // Update numbering of cells/vertices.
178 faceRemover.updateMesh(map());
179
180 if (!overwrite)
181 {
182 ++runTime;
183 }
184 else
185 {
186 mesh.setInstance(oldInstance);
187 }
188
189 // Take over refinement levels and write to new time directory.
190 Pout<< "Writing mesh to time " << runTime.timeName() << endl;
191 mesh.write();
192 topoSet::removeFiles(mesh);
193 processorMeshes::removeFiles(mesh);
194
195 Pout<< "End\n" << endl;
196
197 return 0;
198}
199
200
201// ************************************************************************* //
Field reading functions for post-processing utilities.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
virtual const fileName & name() const
Get the name of the stream.
Definition: OSstream.H:107
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of face labels.
Definition: faceSet.H:54
Direct mesh changes based on v1.3 polyTopoChange syntax.
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
Namespace for OpenFOAM.
wordList ReadFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, const bool syncPar=true, const bool readOldTime=false)
Read Geometric fields of templated type.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
Foam::surfaceFields.