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 // ************************************************************************* //
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Definition: fvMesh.C:1034
Foam::ReadFields
wordList ReadFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh >> &fields, const bool syncPar=true, const bool readOldTime=false)
addOverwriteOption.H
polyTopoChange.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:773
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:95
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::faceSet
A list of face labels.
Definition: faceSet.H:47
Foam::fvMesh::movePoints
virtual tmp< scalarField > movePoints(const pointField &)
Definition: fvMesh.C:858
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
surfaceFields.H
Foam::surfaceFields.
Foam::Pout
prefixOSstream Pout
processorMeshes.H
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Definition: argList.C:294
Foam::polyMesh::pointsInstance
const fileName & pointsInstance() const
Definition: polyMesh.C:839
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Definition: argList.C:466
Foam::removeFaces
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:60
Foam::OSstream::name
virtual const fileName & name() const
Definition: OSstream.H:103
argList.H
faceSet.H
Foam::fvMesh::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Definition: fvMesh.C:946
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:55
removeFaces.H
createNamedMesh.H
Required Variables.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Ostream::write
virtual bool write(const token &tok)=0
Foam
Definition: atmBoundaryLayer.C:26
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:51
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
setRootCase.H
ReadFields.H
Field reading functions for post-processing utilities.
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::processorMeshes::removeFiles
static void removeFiles(const polyMesh &mesh)
Definition: processorMeshes.C:267
createTime.H
args
Foam::argList args(argc, argv)
Foam::topoSet::removeFiles
static void removeFiles(const polyMesh &)
Definition: topoSet.C:628
Foam::polyMesh::setInstance
void setInstance(const fileName &instance, const IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Definition: polyMeshIO.C:29
Foam::argList::found
bool found(const word &optName) const
Definition: argListI.H:171