Loading...
Searching...
No Matches
extrude2DMeshApp.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016 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 extrude2DMesh
29
30Group
31 grpMeshGenerationUtilities
32
33Description
34 Create a 3D mesh by extruding a 2D mesh with specified thickness.
35 For the 2D mesh, all faces are 2 points only, no front and back faces.
36
37Note
38 Not sure about the walking of the faces to create the front and back faces.
39
40\*---------------------------------------------------------------------------*/
41
42#include "argList.H"
43#include "Time.H"
44#include "polyMesh.H"
45#include "extrude2DMesh.H"
46#include "extrudeModel.H"
47#include "polyTopoChange.H"
48#include "MeshedSurface.H"
49#include "edgeCollapser.H"
50#include "patchToPoly2DMesh.H"
51#include "globalIndex.H"
52#include "topoSet.H"
53#include "processorMeshes.H"
54
55using namespace Foam;
56
57// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58
59enum ExtrudeMode
60{
61 POLYMESH2D,
62 MESHEDSURFACE
63};
64
65static const Enum<ExtrudeMode> ExtrudeModeNames
66{
67 { ExtrudeMode::POLYMESH2D, "polyMesh2D" },
68 { ExtrudeMode::MESHEDSURFACE, "MeshedSurface" },
69};
70
71
72//pointField moveInitialPoints
73//(
74// primitiveFacePatch& fMesh,
75// const extrudeModel& model
76//)
77//{
78// pointField layer0Points(fMesh.nPoints());
79// pointField layer1Points(fMesh.nPoints());
80// pointField displacement(fMesh.nPoints());
81
82// forAll(layer0Points, pointi)
83// {
84// const labelList& meshPoints = fMesh.meshPoints();
85// label meshPointi = meshPoints[pointi];
86
87// layer0Points[meshPointi] = model
88// (
89// fMesh.points()[meshPointi],
90// fMesh.pointNormals()[pointi],
91// 0
92// );
93
94// layer1Points[meshPointi] = model
95// (
96// fMesh.points()[meshPointi],
97// fMesh.pointNormals()[pointi],
98// 1
99// );
100
101// displacement[pointi] =
102// layer1Points[meshPointi]
103// - layer0Points[meshPointi];
104// }
105
106// fMesh.movePoints(layer0Points);
107
108// return displacement;
109//}
110
111
112
113int main(int argc, char *argv[])
114{
116 (
117 "Create a 3D mesh from a 2D mesh by extruding with specified thickness"
118 );
119
120 argList::addArgument("surfaceFormat");
121
122 #include "addOverwriteOption.H"
123
124 argList::noFunctionObjects(); // Never use function objects
125
126 #include "setRootCase.H"
127
128 Info<< "Create time\n" << endl;
129
130 Time runTimeExtruded
131 (
133 args.rootPath(),
134 args.caseName()
135 );
136
137 // For safety
138 runTimeExtruded.functionObjects().off();
139
140 const ExtrudeMode surfaceFormat = ExtrudeModeNames[args[1]];
141 const bool overwrite = args.found("overwrite");
142
143 Info<< "Extruding from " << ExtrudeModeNames[surfaceFormat]
144 << " at time " << runTimeExtruded.timeName() << endl;
145
146 IOdictionary extrude2DMeshDict
147 (
149 (
150 "extrude2DMeshDict",
151 runTimeExtruded.system(),
152 runTimeExtruded,
156 )
157 );
158
159 // Point generator
160 autoPtr<extrudeModel> model(extrudeModel::New(extrude2DMeshDict));
161
163
165
167
168 labelListList extrudeEdgePatches;
169
170 if (surfaceFormat == MESHEDSURFACE)
171 {
172 fMesh.reset(new MeshedSurface<face>("MeshedSurface.obj"));
173
174 EdgeMap<label> edgeRegionMap;
175 wordList patchNames(1, "default");
176 labelList patchSizes(1, fMesh().nEdges() - fMesh().nInternalEdges());
177
178 const edgeList& edges = fMesh().edges();
179 forAll(edges, edgeI)
180 {
181 if (!fMesh().isInternalEdge(edgeI))
182 {
183 edgeRegionMap.insert(edges[edgeI], 0);
184 }
185 }
186
187 patchToPoly2DMesh poly2DMesh
188 (
189 fMesh(),
191 patchSizes,
192 edgeRegionMap
193 );
194
195 poly2DMesh.createMesh();
196
198 (
200 (
202 runTimeExtruded.constant(),
203 runTimeExtruded,
207 ),
208 std::move(poly2DMesh.points()),
209 std::move(poly2DMesh.faces()),
210 std::move(poly2DMesh.owner()),
211 std::move(poly2DMesh.neighbour())
212 );
213
214 Info<< "Constructing patches." << endl;
215 List<polyPatch*> patches(poly2DMesh.patchNames().size());
216
217 forAll(patches, patchi)
218 {
219 patches[patchi] = new polyPatch
220 (
221 poly2DMesh.patchNames()[patchi],
222 poly2DMesh.patchSizes()[patchi],
223 poly2DMesh.patchStarts()[patchi],
224 patchi,
225 mesh().boundaryMesh(),
226 polyPatch::typeName
227 );
228 }
229
230 mesh().addPatches(patches);
231 }
232 else if (surfaceFormat == POLYMESH2D)
233 {
235 (
237 (
239 runTimeExtruded.timeName(),
240 runTimeExtruded,
242 )
243 );
244 }
245
246 // Engine to extrude mesh
247 extrude2DMesh extruder(mesh(), extrude2DMeshDict, model());
248
249 extruder.addFrontBackPatches();
250
251 meshMod.reset(new polyTopoChange(mesh().boundaryMesh().size()));
252
253 extruder.setRefinement(meshMod());
254
255 // Create a mesh from topo changes.
256 autoPtr<mapPolyMesh> morphMap = meshMod().changeMesh(mesh(), false);
257
258 mesh().updateMesh(morphMap());
259
260 {
261 edgeCollapser collapser(mesh());
262
263 const edgeList& edges = mesh().edges();
264 const pointField& points = mesh().points();
265
266 const boundBox& bb = mesh().bounds();
267 const scalar mergeDim = 1e-4 * bb.minDim();
268
269 bitSet collapseEdge(mesh().nEdges());
270 Map<point> collapsePointToLocation(mesh().nPoints());
271
272 forAll(edges, edgeI)
273 {
274 const edge& e = edges[edgeI];
275
276 scalar d = e.mag(points);
277
278 if (d < mergeDim)
279 {
280 Info<< "Merging edge " << e << " since length " << d
281 << " << " << mergeDim << nl;
282
283 collapseEdge.set(edgeI);
284 collapsePointToLocation.set(e[1], points[e[0]]);
285 }
286 }
287
288 List<pointEdgeCollapse> allPointInfo;
290 labelList pointPriority(mesh().nPoints(), Zero);
291
292 collapser.consistentCollapse
293 (
295 pointPriority,
296 collapsePointToLocation,
298 allPointInfo
299 );
300
301 polyTopoChange meshModCollapse(mesh());
302
303 collapser.setRefinement(allPointInfo, meshModCollapse);
304
305 // Create a mesh from topo changes.
306 autoPtr<mapPolyMesh> morphMap
307 = meshModCollapse.changeMesh(mesh(), false);
308
309 mesh().updateMesh(morphMap());
310 }
311
312 if (!overwrite)
313 {
314 ++runTimeExtruded;
315 }
316 else
317 {
318 mesh().setInstance("constant");
319 }
320
321 // Take over refinement levels and write to new time directory.
322 Info<< "\nWriting extruded mesh to time = " << runTimeExtruded.timeName()
323 << nl << endl;
324
325 mesh().write();
328
329 Info<< "End\n" << endl;
330
331 return 0;
332}
333
334
335// ************************************************************************* //
Map from edge (expressed as its endpoints) to value. Hashing (and ==) on an edge is symmetric.
Definition edgeHashes.H:59
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition HashTableI.H:152
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.
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
static word controlDictName
The default control dictionary name (normally "controlDict").
Definition Time.H:267
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
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
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition autoPtrI.H:37
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
scalar minDim() const
Smallest length/height/width dimension.
Definition boundBoxI.H:216
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition edge.H:62
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.
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Definition globalIndex.H:77
Calculates points shared by more than two processor patches or cyclic patches.
Convert a primitivePatch into a 2D polyMesh.
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.
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition topoSet.C:693
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
const pointField & points
label nPoints
Namespace for OpenFOAM.
List< edge > edgeList
List of edge.
Definition edgeList.H:32
List< word > wordList
List of word.
Definition fileName.H:60
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
vectorField pointField
pointField is a vectorField.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
wordList patchNames(nPatches)
Foam::argList args(argc, argv)
volScalarField & e
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299