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
Definition: IOobject.H:195
Foam::shortEdgeFilter2D
This class filters short edges generated by the CV2D mesher.
Definition: shortEdgeFilter2D.H:51
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::patchToPoly2DMesh::createMesh
void createMesh()
Create the mesh.
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1041
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:318
addOverwriteOption.H
globalIndex.H
polyTopoChange.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
shortEdgeFilter2D.H
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
polyMesh.H
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
extrude2DMesh.H
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:132
edgeCollapser.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::CV2D
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition: CV2D.H:146
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
extrudeModel.H
argList.H
controlDict
runTime controlDict().readEntry("adjustTimeStep"
Definition: debug.C:143
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:151
Foam::extrudeModel::New
static autoPtr< extrudeModel > New(const dictionary &dict)
Select null constructed.
Definition: extrudeModelNew.C:34
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::Time::loop
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:957
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
patchToPoly2DMesh.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
setRootCase.H
Foam::TimePaths::system
const word & system() const
Return system name.
Definition: TimePathsI.H:102
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::argList::executable
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:51
Foam::patchToPoly2DMesh
Convert a primitivePatch into a 2D polyMesh.
Definition: patchToPoly2DMesh.H:51
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:63
MeshedSurfaces.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
createTime.H
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::cpuTimeCxx::cpuTimeIncrement
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTimeCxx.C:75
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:510
Foam::extrude2DMesh
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
Definition: extrude2DMesh.H:63
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::argList::addOption
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:335
args
Foam::argList args(argc, argv)
CV2D.H
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178