Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Application
28 foamyQuadMesh
29
30Group
31 grpMeshGenerationUtilities
32
33Description
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
53using namespace Foam;
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57int 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 (
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 (
155 (
157 runTime.constant(),
158 runTime,
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(),
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// ************************************************************************* //
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition CV2D.H:145
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static void noParallel()
Remove the parallel options.
Definition argList.C:599
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:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
static autoPtr< extrudeModel > New(const dictionary &dict)
Select null constructed.
A class for handling file names.
Definition fileName.H:75
Convert a primitivePatch into a 2D polyMesh.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
Direct mesh changes based on v1.3 polyTopoChange syntax.
This class filters short edges generated by the CV2D mesher.
static const word null
An empty word.
Definition word.H:84
runTime controlDict().readEntry("adjustTimeStep"
dynamicFvMesh & mesh
engineTime & runTime
Namespace for OpenFOAM.
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition polyPatch.H:61
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
label nPatches
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299