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 -------------------------------------------------------------------------------
11 License
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 
27 Application
28  removeFaces
29 
30 Group
31  grpMeshAdvancedUtilities
32 
33 Description
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 
52 using namespace Foam;
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 
57 int main(int argc, char *argv[])
58 {
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 
132  PtrList<volSymmTensorField> vsymtFlds;
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();
194 
195  Pout<< "End\n" << endl;
196 
197  return 0;
198 }
199 
200 
201 // ************************************************************************* //
Foam::surfaceFields.
static void noFunctionObjects(bool addWithOption=false)
Remove &#39;-noFunctionObjects&#39; option and ignore any occurrences.
Definition: argList.C:547
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:60
A list of face labels.
Definition: faceSet.H:47
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.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:929
Required Classes.
Field reading functions for post-processing utilities.
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
Definition: OSstream.H:134
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition: topoSet.C:693
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:853
virtual void updateMesh(const mapPolyMesh &mpm)
Update mesh corresponding to the given map.
Definition: fvMesh.C:1005
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1113
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
void setInstance(const fileName &instance, const IOobjectOption::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:29
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Direct mesh changes based on v1.3 polyTopoChange syntax.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Foam::argList args(argc, argv)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.