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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2021-2022 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  foamyQuadMesh
29 
30 Group
31  grpMeshGenerationUtilities
32 
33 Description
34  Conformal-Voronoi 2D extruding automatic mesher with grid or read
35  initial points and point position relaxation with optional
36  "squarification".
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #include "CV2D.H"
41 #include "argList.H"
42 
43 #include "MeshedSurfaces.H"
44 #include "shortEdgeFilter2D.H"
45 #include "extrude2DMesh.H"
46 #include "polyMesh.H"
47 #include "patchToPoly2DMesh.H"
48 #include "extrudeModel.H"
49 #include "polyTopoChange.H"
50 #include "edgeCollapser.H"
51 #include "globalIndex.H"
52 
53 using namespace Foam;
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 int main(int argc, char *argv[])
58 {
60  (
61  "Conformal Voronoi 2D automatic mesh generator"
62  );
63 
65  argList::addOption("pointsFile", "filename");
66 
67  #include "addOverwriteOption.H"
68 
69  #include "setRootCase.H"
70  #include "createTime.H"
71 
72  // Read control dictionary
73  // ~~~~~~~~~~~~~~~~~~~~~~~
75  (
76  IOobject
77  (
78  args.executable() + "Dict",
79  runTime.system(),
80  runTime,
83  )
84  );
85 
86  const dictionary& shortEdgeFilterDict
87  (
88  controlDict.subDict("shortEdgeFilter")
89  );
90  const dictionary& extrusionDict(controlDict.subDict("extrusion"));
91 
92  const bool extrude = extrusionDict.get<bool>("extrude");
93  const bool overwrite = args.found("overwrite");
94 
95  // Read and triangulation
96  // ~~~~~~~~~~~~~~~~~~~~~~
98 
99  if (args.found("pointsFile"))
100  {
101  mesh.insertPoints(args.get<fileName>("pointsFile"));
102  }
103  else
104  {
105  mesh.insertGrid();
106  }
107 
108  mesh.insertSurfacePointPairs();
109  mesh.boundaryConform();
110 
111  while (runTime.loop())
112  {
113  Info<< nl << "Time = " << runTime.timeName() << endl;
114 
115  mesh.newPoints();
116  }
117 
118  mesh.write();
119 
120  Info<< "Finished Delaunay in = " << runTime.cpuTimeIncrement() << " s."
121  << endl;
122 
123  Info<< "Begin filtering short edges:" << endl;
124  shortEdgeFilter2D sef(mesh, shortEdgeFilterDict);
125 
126  sef.filter();
127 
128  Info<< "Meshed surface after edge filtering :" << endl;
129  sef.fMesh().writeStats(Info);
130 
131  if (mesh.meshControls().meshedSurfaceOutput())
132  {
133  Info<< "Write .obj file of the 2D mesh: MeshedSurface.obj" << endl;
134  sef.fMesh().write("MeshedSurface.obj");
135  }
136 
137  Info<< "Finished filtering in = " << runTime.cpuTimeIncrement() << " s."
138  << endl;
139 
140  Info<< "Begin constructing a polyMesh:" << endl;
141 
142  patchToPoly2DMesh poly2DMesh
143  (
144  sef.fMesh(),
145  sef.patchNames(),
146  sef.patchSizes(),
147  sef.mapEdgesRegion()
148  );
149 
150  poly2DMesh.createMesh();
151 
152  polyMesh pMesh
153  (
154  IOobject
155  (
157  runTime.constant(),
158  runTime,
161  false
162  ),
163  std::move(poly2DMesh.points()),
164  std::move(poly2DMesh.faces()),
165  std::move(poly2DMesh.owner()),
166  std::move(poly2DMesh.neighbour())
167  );
168 
169  Info<< "Constructing patches." << endl;
170  polyPatchList newPatches(poly2DMesh.patchNames().size());
171  label nPatches = 0;
172 
173  forAll(newPatches, patchi)
174  {
175  if (poly2DMesh.patchSizes()[patchi] != 0)
176  {
177  newPatches.set
178  (
179  nPatches,
180  new polyPatch
181  (
182  poly2DMesh.patchNames()[patchi],
183  poly2DMesh.patchSizes()[patchi],
184  poly2DMesh.patchStarts()[patchi],
185  nPatches,
186  pMesh.boundaryMesh(),
187  word::null
188  )
189  );
190 
191  ++nPatches;
192  }
193  }
194  newPatches.resize(nPatches);
195  pMesh.addPatches(newPatches);
196 
197  if (extrude)
198  {
199  Info<< "Begin extruding the polyMesh:" << endl;
200 
201  {
202  // Point generator
203  autoPtr<extrudeModel> model(extrudeModel::New(extrusionDict));
204 
205  extrude2DMesh extruder(pMesh, extrusionDict, model());
206 
207  extruder.addFrontBackPatches();
208 
209  polyTopoChange meshMod(pMesh.boundaryMesh().size());
210 
211  extruder.setRefinement(meshMod);
212 
213  autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(pMesh, false);
214 
215  pMesh.updateMesh(morphMap());
216  }
217  }
218 
219  if (!overwrite)
220  {
221  ++runTime;
222  }
223  else
224  {
225  pMesh.setInstance("constant");
226  }
227 
228  pMesh.write();
229 
230  Info<< "Finished extruding in = "
231  << runTime.cpuTimeIncrement() << " s." << endl;
232 
233  Info<< "\nEnd\n" << endl;
234 
235  return 0;
236 }
237 
238 
239 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:396
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:453
A class for handling file names.
Definition: fileName.H:71
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1072
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:931
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static void noParallel()
Remove the parallel options.
Definition: argList.C:551
Ignore writing from objectRegistry::writeObject()
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
dynamicFvMesh & mesh
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:44
Reading required, file watched for runTime modification.
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:397
const word & system() const noexcept
Return system name.
Definition: TimePathsI.H:95
static const word null
An empty word.
Definition: word.H:84
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:376
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
runTime controlDict().readEntry("adjustTimeStep"
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
Definition: debug.C:142
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
Definition: Time.C:760
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:89
Convert a primitivePatch into a 2D polyMesh.
static autoPtr< extrudeModel > New(const dictionary &dict)
Select null constructed.
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTimePosix.C:80
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
Definition: extrude2DMesh.H:59
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
void createMesh()
Create the mesh.
Direct mesh changes based on v1.3 polyTopoChange syntax.
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition: CV2D.H:142
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
This class filters short edges generated by the CV2D mesher.
virtual bool write(const bool valid=true) const
Write using setting from DB.
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.