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-------------------------------------------------------------------------------
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{
59 argList::addNote
60 (
61 "Conformal Voronoi 2D automatic mesh generator"
62 );
63
64 argList::noParallel();
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,
81 IOobject::MUST_READ_IF_MODIFIED,
82 IOobject::NO_WRITE
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 (
156 polyMesh::defaultRegion,
157 runTime.constant(),
158 runTime,
159 IOobject::NO_READ,
160 IOobject::NO_WRITE,
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(),
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// ************************************************************************* //
Conformal-Voronoi 2D automatic mesher with grid or read initial points and point position relaxation ...
Definition: CV2D.H:149
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:51
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
Definition: extrude2DMesh.H:64
A class for handling file names.
Definition: fileName.H:76
Convert a primitivePatch into a 2D polyMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
Direct mesh changes based on v1.3 polyTopoChange syntax.
This class filters short edges generated by the CV2D mesher.
runTime controlDict().readEntry("adjustTimeStep"
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
engineTime & runTime
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333