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 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  List<polyPatch*> patches(poly2DMesh.patchNames().size());
171  label countPatches = 0;
172 
173  forAll(patches, patchi)
174  {
175  if (poly2DMesh.patchSizes()[patchi] != 0)
176  {
177  patches[countPatches] = new polyPatch
178  (
179  poly2DMesh.patchNames()[patchi],
180  poly2DMesh.patchSizes()[patchi],
181  poly2DMesh.patchStarts()[patchi],
182  countPatches,
183  pMesh.boundaryMesh(),
184  word::null
185  );
186 
187  countPatches++;
188  }
189  }
190  patches.setSize(countPatches);
191  pMesh.addPatches(patches);
192 
193  if (extrude)
194  {
195  Info<< "Begin extruding the polyMesh:" << endl;
196 
197  {
198  // Point generator
199  autoPtr<extrudeModel> model(extrudeModel::New(extrusionDict));
200 
201  extrude2DMesh extruder(pMesh, extrusionDict, model());
202 
203  extruder.addFrontBackPatches();
204 
205  polyTopoChange meshMod(pMesh.boundaryMesh().size());
206 
207  extruder.setRefinement(meshMod);
208 
209  autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(pMesh, false);
210 
211  pMesh.updateMesh(morphMap());
212  }
213  }
214 
215  if (!overwrite)
216  {
217  ++runTime;
218  }
219  else
220  {
221  pMesh.setInstance("constant");
222  }
223 
224  pMesh.write();
225 
226  Info<< "Finished extruding in = "
227  << runTime.cpuTimeIncrement() << " s." << endl;
228 
229  Info<< "\nEnd\n" << endl;
230 
231  return 0;
232 }
233 
234 
235 // ************************************************************************* //
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:191
Foam::shortEdgeFilter2D
This class filters short edges generated by the CV2D mesher.
Definition: shortEdgeFilter2D.H:47
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Definition: fvMesh.C:1034
Foam::polyMesh::defaultRegion
static word defaultRegion
Definition: polyMesh.H:314
addOverwriteOption.H
globalIndex.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
shortEdgeFilter2D.H
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
polyMesh.H
Foam::cpuTimePosix::cpuTimeIncrement
double cpuTimeIncrement() const
Definition: cpuTimePosix.C:80
Foam::argList::get
T get(const label index) const
Definition: argListI.H:271
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
extrude2DMesh.H
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Definition: regIOobjectWrite.C:125
edgeCollapser.H
Foam::Info
messageStream Info
Foam::CV2D
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition: CV2D.H:142
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:64
extrudeModel.H
argList.H
controlDict
runTime controlDict().readEntry("adjustTimeStep"
Definition: debug.C:139
Foam::PtrList::setSize
void setSize(const label newLen)
Definition: PtrList.H:147
Foam::extrudeModel::New
static autoPtr< extrudeModel > New(const dictionary &dict)
Definition: extrudeModelNew.C:27
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
Foam::Time::loop
virtual bool loop()
Definition: Time.C:950
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Ostream::write
virtual bool write(const token &tok)=0
Foam
Definition: atmBoundaryLayer.C:26
patchToPoly2DMesh.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
setRootCase.H
Foam::TimePaths::system
const word & system() const
Definition: TimePathsI.H:95
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::argList::executable
const word & executable() const noexcept
Definition: argListI.H:44
Foam::patchToPoly2DMesh
Convert a primitivePatch into a 2D polyMesh.
Definition: patchToPoly2DMesh.H:47
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
MeshedSurfaces.H
Foam::word::null
static const word null
Definition: word.H:78
createTime.H
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:182
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:59
Foam::argList::noParallel
static void noParallel()
Definition: argList.C:503
Foam::extrude2DMesh
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
Definition: extrude2DMesh.H:59
Foam::TimePaths::constant
const word & constant() const
Definition: TimePathsI.H:89
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:184
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Definition: argList.C:328
args
Foam::argList args(argc, argv)
CV2D.H
Foam::argList::found
bool found(const word &optName) const
Definition: argListI.H:171