foamyQuadMesh.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) 2013-2016 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  foamyQuadMesh
26 
27 Description
28  Conformal-Voronoi 2D extruding automatic mesher with grid or read
29  initial points and point position relaxation with optional
30  "squarification".
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #include "CV2D.H"
35 #include "argList.H"
36 
37 #include "MeshedSurfaces.H"
38 #include "shortEdgeFilter2D.H"
39 #include "extrude2DMesh.H"
40 #include "polyMesh.H"
41 #include "patchToPoly2DMesh.H"
42 #include "extrudeModel.H"
43 #include "polyTopoChange.H"
44 #include "edgeCollapser.H"
45 #include "globalIndex.H"
46 
47 using namespace Foam;
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 int main(int argc, char *argv[])
52 {
54  argList::validArgs.clear();
56  (
57  "pointsFile",
58  "filename"
59  );
60 
61  #include "addOverwriteOption.H"
62 
63  #include "setRootCase.H"
64  #include "createTime.H"
65 
66  // Read control dictionary
67  // ~~~~~~~~~~~~~~~~~~~~~~~
69  (
70  IOobject
71  (
72  args.executable() + "Dict",
73  runTime.system(),
74  runTime,
77  )
78  );
79 
80  const dictionary& shortEdgeFilterDict
81  (
82  controlDict.subDict("shortEdgeFilter")
83  );
84  const dictionary& extrusionDict(controlDict.subDict("extrusion"));
85 
86  Switch extrude(extrusionDict.lookup("extrude"));
87  const bool overwrite = args.optionFound("overwrite");
88 
89  // Read and triangulation
90  // ~~~~~~~~~~~~~~~~~~~~~~
91  CV2D mesh(runTime, controlDict);
92 
93  if (args.options().found("pointsFile"))
94  {
95  fileName pointFileName(IStringStream(args.options()["pointsFile"])());
96  mesh.insertPoints(pointFileName);
97  }
98  else
99  {
100  mesh.insertGrid();
101  }
102 
103  mesh.insertSurfacePointPairs();
104  mesh.boundaryConform();
105 
106  while (runTime.loop())
107  {
108  Info<< nl << "Time = " << runTime.timeName() << endl;
109 
110  mesh.newPoints();
111  }
112 
113  mesh.write();
114 
115  Info<< "Finished Delaunay in = " << runTime.cpuTimeIncrement() << " s."
116  << endl;
117 
118  Info<< "Begin filtering short edges:" << endl;
119  shortEdgeFilter2D sef(mesh, shortEdgeFilterDict);
120 
121  sef.filter();
122 
123  Info<< "Meshed surface after edge filtering :" << endl;
124  sef.fMesh().writeStats(Info);
125 
126  if (mesh.meshControls().meshedSurfaceOutput())
127  {
128  Info<< "Write .obj file of the 2D mesh: MeshedSurface.obj" << endl;
129  sef.fMesh().write("MeshedSurface.obj");
130  }
131 
132  Info<< "Finished filtering in = " << runTime.cpuTimeIncrement() << " s."
133  << endl;
134 
135  Info<< "Begin constructing a polyMesh:" << endl;
136 
137  patchToPoly2DMesh poly2DMesh
138  (
139  sef.fMesh(),
140  sef.patchNames(),
141  sef.patchSizes(),
142  sef.mapEdgesRegion()
143  );
144 
145  poly2DMesh.createMesh();
146 
147  polyMesh pMesh
148  (
149  IOobject
150  (
152  runTime.constant(),
153  runTime,
156  false
157  ),
158  xferMove(poly2DMesh.points()),
159  xferMove(poly2DMesh.faces()),
160  xferMove(poly2DMesh.owner()),
161  xferMove(poly2DMesh.neighbour())
162  );
163 
164  Info<< "Constructing patches." << endl;
165  List<polyPatch*> patches(poly2DMesh.patchNames().size());
166  label countPatches = 0;
167 
169  {
170  if (poly2DMesh.patchSizes()[patchi] != 0)
171  {
172  patches[countPatches] = new polyPatch
173  (
174  poly2DMesh.patchNames()[patchi],
175  poly2DMesh.patchSizes()[patchi],
176  poly2DMesh.patchStarts()[patchi],
177  countPatches,
178  pMesh.boundaryMesh(),
179  word::null
180  );
181 
182  countPatches++;
183  }
184  }
185  patches.setSize(countPatches);
186  pMesh.addPatches(patches);
187 
188  if (extrude)
189  {
190  Info<< "Begin extruding the polyMesh:" << endl;
191 
192  {
193  // Point generator
194  autoPtr<extrudeModel> model(extrudeModel::New(extrusionDict));
195 
196  extrude2DMesh extruder(pMesh, extrusionDict, model());
197 
198  extruder.addFrontBackPatches();
199 
200  polyTopoChange meshMod(pMesh.boundaryMesh().size());
201 
202  extruder.setRefinement(meshMod);
203 
204  autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(pMesh, false);
205 
206  pMesh.updateMesh(morphMap);
207  }
208  }
209 
210  if (!overwrite)
211  {
212  runTime++;
213  }
214  else
215  {
216  pMesh.setInstance("constant");
217  }
218 
219  pMesh.write();
220 
221  Info<< "Finished extruding in = "
222  << runTime.cpuTimeIncrement() << " s." << endl;
223 
224  Info<< nl << "End\n" << endl;
225 
226  return 0;
227 }
228 
229 
230 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
patches[0]
const Foam::HashTable< string > & options() const
Return options.
Definition: argListI.H:90
const word & executable() const
Name of executable without the path.
Definition: argListI.H:30
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
dynamicFvMesh & mesh
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
static autoPtr< extrudeModel > New(const dictionary &)
Select null constructed.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
static const word null
An empty word.
Definition: word.H:77
static const char nl
Definition: Ostream.H:262
Convert a primitivePatch into a 2D polyMesh.
label patchi
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
Definition: extrude2DMesh.H:61
Input from memory buffer stream.
Definition: IStringStream.H:49
void createMesh()
Create the mesh.
Direct mesh changes based on v1.3 polyTopoChange syntax.
messageStream Info
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition: CV2D.H:146
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
This class filters short edges generated by the CV2D mesher.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
static HashTable< string > validOptions
A list of valid options.
Definition: argList.H:157
virtual bool write() const
Write mesh using IO settings from time.
Definition: fvMesh.C:870
Namespace for OpenFOAM.