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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  foamyQuadMesh
28 
29 Group
30  grpMeshGenerationUtilities
31 
32 Description
33  Conformal-Voronoi 2D extruding automatic mesher with grid or read
34  initial points and point position relaxation with optional
35  "squarification".
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "CV2D.H"
40 #include "argList.H"
41 
42 #include "MeshedSurfaces.H"
43 #include "shortEdgeFilter2D.H"
44 #include "extrude2DMesh.H"
45 #include "polyMesh.H"
46 #include "patchToPoly2DMesh.H"
47 #include "extrudeModel.H"
48 #include "polyTopoChange.H"
49 #include "edgeCollapser.H"
50 #include "globalIndex.H"
51 
52 using namespace Foam;
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 int main(int argc, char *argv[])
57 {
59  (
60  "Conformal Voronoi 2D automatic mesh generator"
61  );
62 
64  argList::addOption("pointsFile", "filename");
65 
66  #include "addOverwriteOption.H"
67 
68  #include "setRootCase.H"
69  #include "createTime.H"
70 
71  // Read control dictionary
72  // ~~~~~~~~~~~~~~~~~~~~~~~
74  (
75  IOobject
76  (
77  args.executable() + "Dict",
78  runTime.system(),
79  runTime,
82  )
83  );
84 
85  const dictionary& shortEdgeFilterDict
86  (
87  controlDict.subDict("shortEdgeFilter")
88  );
89  const dictionary& extrusionDict(controlDict.subDict("extrusion"));
90 
91  const bool extrude = extrusionDict.get<bool>("extrude");
92  const bool overwrite = args.found("overwrite");
93 
94  // Read and triangulation
95  // ~~~~~~~~~~~~~~~~~~~~~~
97 
98  if (args.found("pointsFile"))
99  {
100  mesh.insertPoints(args["pointsFile"]);
101  }
102  else
103  {
104  mesh.insertGrid();
105  }
106 
107  mesh.insertSurfacePointPairs();
108  mesh.boundaryConform();
109 
110  while (runTime.loop())
111  {
112  Info<< nl << "Time = " << runTime.timeName() << endl;
113 
114  mesh.newPoints();
115  }
116 
117  mesh.write();
118 
119  Info<< "Finished Delaunay in = " << runTime.cpuTimeIncrement() << " s."
120  << endl;
121 
122  Info<< "Begin filtering short edges:" << endl;
123  shortEdgeFilter2D sef(mesh, shortEdgeFilterDict);
124 
125  sef.filter();
126 
127  Info<< "Meshed surface after edge filtering :" << endl;
128  sef.fMesh().writeStats(Info);
129 
130  if (mesh.meshControls().meshedSurfaceOutput())
131  {
132  Info<< "Write .obj file of the 2D mesh: MeshedSurface.obj" << endl;
133  sef.fMesh().write("MeshedSurface.obj");
134  }
135 
136  Info<< "Finished filtering in = " << runTime.cpuTimeIncrement() << " s."
137  << endl;
138 
139  Info<< "Begin constructing a polyMesh:" << endl;
140 
141  patchToPoly2DMesh poly2DMesh
142  (
143  sef.fMesh(),
144  sef.patchNames(),
145  sef.patchSizes(),
146  sef.mapEdgesRegion()
147  );
148 
149  poly2DMesh.createMesh();
150 
151  polyMesh pMesh
152  (
153  IOobject
154  (
156  runTime.constant(),
157  runTime,
160  false
161  ),
162  std::move(poly2DMesh.points()),
163  std::move(poly2DMesh.faces()),
164  std::move(poly2DMesh.owner()),
165  std::move(poly2DMesh.neighbour())
166  );
167 
168  Info<< "Constructing patches." << endl;
169  List<polyPatch*> patches(poly2DMesh.patchNames().size());
170  label countPatches = 0;
171 
172  forAll(patches, patchi)
173  {
174  if (poly2DMesh.patchSizes()[patchi] != 0)
175  {
176  patches[countPatches] = new polyPatch
177  (
178  poly2DMesh.patchNames()[patchi],
179  poly2DMesh.patchSizes()[patchi],
180  poly2DMesh.patchStarts()[patchi],
181  countPatches,
182  pMesh.boundaryMesh(),
183  word::null
184  );
185 
186  countPatches++;
187  }
188  }
189  patches.setSize(countPatches);
190  pMesh.addPatches(patches);
191 
192  if (extrude)
193  {
194  Info<< "Begin extruding the polyMesh:" << endl;
195 
196  {
197  // Point generator
198  autoPtr<extrudeModel> model(extrudeModel::New(extrusionDict));
199 
200  extrude2DMesh extruder(pMesh, extrusionDict, model());
201 
202  extruder.addFrontBackPatches();
203 
204  polyTopoChange meshMod(pMesh.boundaryMesh().size());
205 
206  extruder.setRefinement(meshMod);
207 
208  autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(pMesh, false);
209 
210  pMesh.updateMesh(morphMap());
211  }
212  }
213 
214  if (!overwrite)
215  {
216  ++runTime;
217  }
218  else
219  {
220  pMesh.setInstance("constant");
221  }
222 
223  pMesh.write();
224 
225  Info<< "Finished extruding in = "
226  << runTime.cpuTimeIncrement() << " s." << endl;
227 
228  Info<< "\nEnd\n" << endl;
229 
230  return 0;
231 }
232 
233 
234 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
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:104
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:895
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:312
addOverwriteOption.H
globalIndex.H
polyTopoChange.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:785
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:413
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
polyMesh.H
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::argList::executable
const word & executable() const
Name of executable without the path.
Definition: argListI.H:51
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:165
edgeCollapser.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:67
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: PtrListI.H:108
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:121
Foam::Time::loop
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:960
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:94
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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: HashTable.H:102
MeshedSurfaces.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
createTime.H
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
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:491
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:88
Foam::IOobject::NO_READ
Definition: IOobject.H:123
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:336
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:157