1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Takes 2D mesh (all faces 2 points only, no front and back faces) and
29 creates a 3D mesh by extruding with specified thickness.
33 - extrude2DMesh thickness
36 Thickness (in metre) of slab.
39 Not sure about the walking of the faces to create the front and back faces.
40 Tested on one .ccm file.
42 \*---------------------------------------------------------------------------*/
45 #include "objectRegistry.H"
48 #include "directTopoChange.H"
49 #include "extrude2DMesh.H"
50 #include "emptyPolyPatch.H"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 int main(int argc, char *argv[])
60 argList::validArgs.append("thickness");
61 argList::validOptions.insert("overwrite", "");
62 # include "setRootCase.H"
63 # include "createTime.H"
64 runTime.functionObjects().off();
65 # include "createPolyMesh.H"
66 const word oldInstance = mesh.pointsInstance();
68 scalar thickness(readScalar(IStringStream(args.additionalArgs()[0])()));
69 bool overwrite = args.optionFound("overwrite");
72 // Check that mesh is 2D
73 // ~~~~~~~~~~~~~~~~~~~~~
75 const faceList& faces = mesh.faces();
78 if (faces[faceI].size() != 2)
80 FatalErrorIn(args.executable())
81 << "Face " << faceI << " size " << faces[faceI].size()
82 << " is not of size 2 so mesh is not proper two-dimensional."
88 // Find extrude direction
89 // ~~~~~~~~~~~~~~~~~~~~~~
91 scalar minRange = GREAT;
92 direction extrudeDir = 4; //illegal value.
94 for (direction dir = 0; dir < 3; dir++)
96 scalarField cmpts(mesh.points().component(dir));
98 scalar range = max(cmpts)-min(cmpts);
100 Info<< "Direction:" << dir << " range:" << range << endl;
102 if (range < minRange)
109 Info<< "Extruding in direction " << extrudeDir
110 << " with thickness " << thickness << nl
115 const polyBoundaryMesh& patches = mesh.boundaryMesh();
118 // Add front and back patch
119 // ~~~~~~~~~~~~~~~~~~~~~~~~
121 label frontPatchI = patches.findPatchID("frontAndBack");
123 if (frontPatchI == -1)
126 List<polyPatch*> newPatches(patches.size()+1);
128 forAll(patches, patchI)
130 const polyPatch& pp = patches[patchI];
132 newPatches[patchI] = pp.clone
141 frontPatchI = patches.size();
143 newPatches[frontPatchI] = new emptyPolyPatch
152 Info<< "Adding empty patch " << newPatches[frontPatchI]->name()
153 << " at index " << frontPatchI
154 << " for front and back faces." << nl << endl;
156 mesh.removeBoundary();
157 mesh.addPatches(newPatches);
162 // Topo changes container. Initialise with number of patches.
163 directTopoChange meshMod(mesh.boundaryMesh().size());
165 // Engine to extrude mesh
166 extrude2DMesh extruder(mesh);
168 // Insert changes into meshMod
169 extruder.setRefinement
177 // Create a mesh from topo changes.
178 autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
180 mesh.updateMesh(morphMap);
188 mesh.setInstance(oldInstance);
191 // Take over refinement levels and write to new time directory.
192 Pout<< "Writing extruded mesh to time " << runTime.timeName() << nl
197 Pout<< "End\n" << endl;
203 // ************************************************************************* //