removeFaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
35 
36 #include "argList.H"
37 #include "Time.H"
38 #include "polyTopoChange.H"
39 #include "faceSet.H"
40 #include "removeFaces.H"
41 #include "ReadFields.H"
42 #include "volFields.H"
43 #include "surfaceFields.H"
44 #include "pointFields.H"
45 
46 using namespace Foam;
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 int main(int argc, char *argv[])
51 {
52  #include "addOverwriteOption.H"
53  argList::validArgs.append("faceSet");
55  (
56  "noFields",
57  "do not update fields"
58  );
59 
60 
61  #include "setRootCase.H"
63 
64  const bool overwrite = args.optionFound("overwrite");
65  const bool fields = !args.optionFound("noFields");
66 
67  #include "createMeshNoChangers.H"
68  const word oldInstance = mesh.pointsInstance();
69 
70  const word setName = args[1];
71 
72  // Read faces
73  faceSet candidateSet(mesh, setName);
74 
75  Pout<< "Read " << candidateSet.size() << " faces to remove" << nl
76  << endl;
77 
78 
79  labelList candidates(candidateSet.toc());
80 
81  // Face removal engine. No checking for not merging boundary faces.
82  removeFaces faceRemover(mesh, 2);
83 
84  // Get compatible set of faces and connected sets of cells.
85  labelList cellRegion;
86  labelList cellRegionMaster;
87  labelList facesToRemove;
88 
89  faceRemover.compatibleRemoves
90  (
91  candidates,
92  cellRegion,
93  cellRegionMaster,
94  facesToRemove
95  );
96 
97  {
98  faceSet compatibleRemoves(mesh, "compatibleRemoves", facesToRemove);
99 
100  Pout<< "Original faces to be removed:" << candidateSet.size() << nl
101  << "New faces to be removed:" << compatibleRemoves.size() << nl
102  << endl;
103 
104  Pout<< "Writing new faces to be removed to faceSet "
105  << compatibleRemoves.instance()
106  /compatibleRemoves.local()
107  /compatibleRemoves.name()
108  << endl;
109 
110  compatibleRemoves.write();
111  }
112 
113 
114  // Read objects in time directory
115  IOobjectList objects(mesh, runTime.name());
116 
117  if (fields) Info<< "Reading geometric fields" << nl << endl;
118 
119  #include "readVolFields.H"
120  #include "readSurfaceFields.H"
121  #include "readPointFields.H"
122 
123  Info<< endl;
124 
125 
126  // Topo changes container
127  polyTopoChange meshMod(mesh);
128 
129  // Insert mesh refinement into polyTopoChange.
130  faceRemover.setRefinement
131  (
132  facesToRemove,
133  cellRegion,
134  cellRegionMaster,
135  meshMod
136  );
137 
138  autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh, false);
139 
140  mesh.topoChange(map);
141 
142  // Move mesh (since morphing does not do this)
143  if (map().hasMotionPoints())
144  {
145  mesh.setPoints(map().preMotionPoints());
146  }
147 
148  // Update numbering of cells/vertices.
149  faceRemover.topoChange(map);
150 
151  if (!overwrite)
152  {
153  runTime++;
154  }
155  else
156  {
157  mesh.setInstance(oldInstance);
158  }
159 
160  // Take over refinement levels and write to new time directory.
161  Pout<< "Writing mesh to time " << runTime.name() << endl;
162  mesh.write();
163 
164  Pout<< "End\n" << endl;
165 
166  return 0;
167 }
168 
169 
170 // ************************************************************************* //
Field reading functions for post-processing utilities.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:53
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
virtual Ostream & write(const char)=0
Write character.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of face labels.
Definition: faceSet.H:51
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:63
A class for handling words, derived from string.
Definition: word.H:62
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:230
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
static const char nl
Definition: Ostream.H:260
objects
Foam::argList args(argc, argv)
Foam::surfaceFields.