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 "addPatchCellLayer.H"
51#include "patchToPoly2DMesh.H"
52#include "globalIndex.H"
53#include "topoSet.H"
54#include "processorMeshes.H"
55
56using namespace Foam;
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60enum ExtrudeMode
61{
62 POLYMESH2D,
63 MESHEDSURFACE
64};
65
66static const Enum<ExtrudeMode> ExtrudeModeNames
67{
68 { ExtrudeMode::POLYMESH2D, "polyMesh2D" },
69 { ExtrudeMode::MESHEDSURFACE, "MeshedSurface" },
70};
71
72
73//pointField moveInitialPoints
74//(
75// primitiveFacePatch& fMesh,
76// const extrudeModel& model
77//)
78//{
79// pointField layer0Points(fMesh.nPoints());
80// pointField layer1Points(fMesh.nPoints());
81// pointField displacement(fMesh.nPoints());
82
83// forAll(layer0Points, pointi)
84// {
85// const labelList& meshPoints = fMesh.meshPoints();
86// label meshPointi = meshPoints[pointi];
87
88// layer0Points[meshPointi] = model
89// (
90// fMesh.points()[meshPointi],
91// fMesh.pointNormals()[pointi],
92// 0
93// );
94
95// layer1Points[meshPointi] = model
96// (
97// fMesh.points()[meshPointi],
98// fMesh.pointNormals()[pointi],
99// 1
100// );
101
102// displacement[pointi] =
103// layer1Points[meshPointi]
104// - layer0Points[meshPointi];
105// }
106
107// fMesh.movePoints(layer0Points);
108
109// return displacement;
110//}
111
112
113
114int main(int argc, char *argv[])
115{
116 argList::addNote
117 (
118 "Create a 3D mesh from a 2D mesh by extruding with specified thickness"
119 );
120
121 argList::addArgument("surfaceFormat");
122
123 #include "addOverwriteOption.H"
124
125 argList::noFunctionObjects(); // Never use function objects
126
127 #include "setRootCase.H"
128
129 Info<< "Create time\n" << endl;
130
131 Time runTimeExtruded
132 (
133 Time::controlDictName,
134 args.rootPath(),
135 args.caseName()
136 );
137
138 // For safety
139 runTimeExtruded.functionObjects().off();
140
141 const ExtrudeMode surfaceFormat = ExtrudeModeNames[args[1]];
142 const bool overwrite = args.found("overwrite");
143
144 Info<< "Extruding from " << ExtrudeModeNames[surfaceFormat]
145 << " at time " << runTimeExtruded.timeName() << endl;
146
147 IOdictionary extrude2DMeshDict
148 (
150 (
151 "extrude2DMeshDict",
152 runTimeExtruded.system(),
153 runTimeExtruded,
154 IOobject::MUST_READ,
155 IOobject::NO_WRITE,
156 false
157 )
158 );
159
160 // Point generator
161 autoPtr<extrudeModel> model(extrudeModel::New(extrude2DMeshDict));
162
164
166
168
169 labelListList extrudeEdgePatches;
170
171 if (surfaceFormat == MESHEDSURFACE)
172 {
173 fMesh.reset(new MeshedSurface<face>("MeshedSurface.obj"));
174
175 EdgeMap<label> edgeRegionMap;
176 wordList patchNames(1, "default");
177 labelList patchSizes(1, fMesh().nEdges() - fMesh().nInternalEdges());
178
179 const edgeList& edges = fMesh().edges();
180 forAll(edges, edgeI)
181 {
182 if (!fMesh().isInternalEdge(edgeI))
183 {
184 edgeRegionMap.insert(edges[edgeI], 0);
185 }
186 }
187
188 patchToPoly2DMesh poly2DMesh
189 (
190 fMesh(),
192 patchSizes,
193 edgeRegionMap
194 );
195
196 poly2DMesh.createMesh();
197
199 (
201 (
202 polyMesh::defaultRegion,
203 runTimeExtruded.constant(),
204 runTimeExtruded,
205 IOobject::NO_READ,
206 IOobject::NO_WRITE,
207 false
208 ),
209 std::move(poly2DMesh.points()),
210 std::move(poly2DMesh.faces()),
211 std::move(poly2DMesh.owner()),
212 std::move(poly2DMesh.neighbour())
213 );
214
215 Info<< "Constructing patches." << endl;
216 List<polyPatch*> patches(poly2DMesh.patchNames().size());
217
218 forAll(patches, patchi)
219 {
220 patches[patchi] = new polyPatch
221 (
222 poly2DMesh.patchNames()[patchi],
223 poly2DMesh.patchSizes()[patchi],
224 poly2DMesh.patchStarts()[patchi],
225 patchi,
226 mesh().boundaryMesh(),
227 polyPatch::typeName
228 );
229 }
230
231 mesh().addPatches(patches);
232 }
233 else if (surfaceFormat == POLYMESH2D)
234 {
236 (
238 (
239 polyMesh::defaultRegion,
240 runTimeExtruded.timeName(),
241 runTimeExtruded,
242 IOobject::MUST_READ
243 )
244 );
245 }
246
247 // Engine to extrude mesh
248 extrude2DMesh extruder(mesh(), extrude2DMeshDict, model());
249
250 extruder.addFrontBackPatches();
251
252 meshMod.reset(new polyTopoChange(mesh().boundaryMesh().size()));
253
254 extruder.setRefinement(meshMod());
255
256 // Create a mesh from topo changes.
257 autoPtr<mapPolyMesh> morphMap = meshMod().changeMesh(mesh(), false);
258
259 mesh().updateMesh(morphMap());
260
261 {
262 edgeCollapser collapser(mesh());
263
264 const edgeList& edges = mesh().edges();
265 const pointField& points = mesh().points();
266
267 const boundBox& bb = mesh().bounds();
268 const scalar mergeDim = 1e-4 * bb.minDim();
269
271 Map<point> collapsePointToLocation(mesh().nPoints());
272
273 forAll(edges, edgeI)
274 {
275 const edge& e = edges[edgeI];
276
277 scalar d = e.mag(points);
278
279 if (d < mergeDim)
280 {
281 Info<< "Merging edge " << e << " since length " << d
282 << " << " << mergeDim << nl;
283
284 collapseEdge.set(edgeI);
285 collapsePointToLocation.set(e[1], points[e[0]]);
286 }
287 }
288
289 List<pointEdgeCollapse> allPointInfo;
291 labelList pointPriority(mesh().nPoints(), Zero);
292
293 collapser.consistentCollapse
294 (
296 pointPriority,
297 collapsePointToLocation,
299 allPointInfo
300 );
301
302 polyTopoChange meshModCollapse(mesh());
303
304 collapser.setRefinement(allPointInfo, meshModCollapse);
305
306 // Create a mesh from topo changes.
307 autoPtr<mapPolyMesh> morphMap
308 = meshModCollapse.changeMesh(mesh(), false);
309
310 mesh().updateMesh(morphMap());
311 }
312
313 if (!overwrite)
314 {
315 ++runTimeExtruded;
316 }
317 else
318 {
319 mesh().setInstance("constant");
320 }
321
322 // Take over refinement levels and write to new time directory.
323 Info<< "\nWriting extruded mesh to time = " << runTimeExtruded.timeName()
324 << nl << endl;
325
326 mesh().write();
327 topoSet::removeFiles(mesh());
328 processorMeshes::removeFiles(mesh());
329
330 Info<< "End\n" << endl;
331
332 return 0;
333}
334
335
336// ************************************************************************* //
Map from edge (expressed as its endpoints) to value. For easier forward declaration it is currently i...
Definition: EdgeMap.H:54
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
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 HashTable to objects of type <T> with a label key.
Definition: Map.H:60
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:99
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
const fileName & rootPath() const noexcept
Return root path.
Definition: argListI.H:63
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:117
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
scalar minDim() const
Smallest length/height/width dimension.
Definition: boundBoxI.H:145
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
Definition: edgeCollapser.H:69
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
Given a 2D mesh insert all the topology changes to extrude. Does not work in parallel.
Definition: extrude2DMesh.H:64
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:103
Convert a primitivePatch into a 2D polyMesh.
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.
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
const labelList nEdges(UPstream::listGatherValues< label >(aMesh.nEdges()))
const pointField & points
label nPoints
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
wordList patchNames(nPatches)
Foam::argList args(argc, argv)
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333