1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
extrude2DMesh
Description
Takes 2D mesh (all faces 2 points only, no front and back faces) and
creates a 3D mesh by extruding with specified thickness.
Note
Not sure about the walking of the faces to create the front and back faces.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "polyMesh.H"
#include "extrude2DMesh.H"
#include "extrudeModel.H"
#include "polyTopoChange.H"
#include "MeshedSurface.H"
#include "edgeCollapser.H"
#include "addPatchCellLayer.H"
#include "patchToPoly2DMesh.H"
#include "globalIndex.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
enum ExtrudeMode
{
POLYMESH2D,
MESHEDSURFACE
};
namespace Foam
{
template<>
const char* NamedEnum<ExtrudeMode, 2>::names[] =
{
"polyMesh2D",
"MeshedSurface"
};
}
static const NamedEnum<ExtrudeMode, 2> ExtrudeModeNames;
//pointField moveInitialPoints
//(
// primitiveFacePatch& fMesh,
// const extrudeModel& model
//)
//{
// pointField layer0Points(fMesh.nPoints());
// pointField layer1Points(fMesh.nPoints());
// pointField displacement(fMesh.nPoints());
// forAll(layer0Points, pointi)
// {
// const labelList& meshPoints = fMesh.meshPoints();
// label meshPointi = meshPoints[pointi];
// layer0Points[meshPointi] = model
// (
// fMesh.points()[meshPointi],
// fMesh.pointNormals()[pointi],
// 0
// );
// layer1Points[meshPointi] = model
// (
// fMesh.points()[meshPointi],
// fMesh.pointNormals()[pointi],
// 1
// );
// displacement[pointi] =
// layer1Points[meshPointi]
// - layer0Points[meshPointi];
// }
// fMesh.movePoints(layer0Points);
// return displacement;
//}
int main(int argc, char *argv[])
{
argList::validArgs.append("surfaceFormat");
#include "addOverwriteOption.H"
#include "setRootCase.H"
Info<< "Create time\n" << endl;
Time runTimeExtruded
(
Time::controlDictName,
args.rootPath(),
args.caseName()
);
runTimeExtruded.functionObjects().off();
const ExtrudeMode surfaceFormat = ExtrudeModeNames[args[1]];
const bool overwrite = args.optionFound("overwrite");
Info<< "Extruding from " << ExtrudeModeNames[surfaceFormat]
<< " at time " << runTimeExtruded.timeName() << endl;
IOdictionary extrude2DMeshDict
(
IOobject
(
"extrude2DMeshDict",
runTimeExtruded.system(),
runTimeExtruded,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
// Point generator
autoPtr<extrudeModel> model(extrudeModel::New(extrude2DMeshDict));
autoPtr<MeshedSurface<face>> fMesh;
autoPtr<polyMesh> mesh;
autoPtr<polyTopoChange> meshMod;
labelListList extrudeEdgePatches;
if (surfaceFormat == MESHEDSURFACE)
{
fMesh.set(new MeshedSurface<face>("MeshedSurface.obj"));
EdgeMap<label> edgeRegionMap;
wordList patchNames(1, "default");
labelList patchSizes(1, fMesh().nEdges() - fMesh().nInternalEdges());
const edgeList& edges = fMesh().edges();
forAll(edges, edgeI)
{
if (!fMesh().isInternalEdge(edgeI))
{
edgeRegionMap.insert(edges[edgeI], 0);
}
}
patchToPoly2DMesh poly2DMesh
(
fMesh(),
patchNames,
patchSizes,
edgeRegionMap
);
poly2DMesh.createMesh();
mesh.set
(
new polyMesh
(
IOobject
(
polyMesh::defaultRegion,
runTimeExtruded.constant(),
runTimeExtruded,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
xferMove(poly2DMesh.points()),
xferMove(poly2DMesh.faces()),
xferMove(poly2DMesh.owner()),
xferMove(poly2DMesh.neighbour())
)
);
Info<< "Constructing patches." << endl;
List<polyPatch*> patches(poly2DMesh.patchNames().size());
forAll(patches, patchi)
{
patches[patchi] = new polyPatch
(
poly2DMesh.patchNames()[patchi],
poly2DMesh.patchSizes()[patchi],
poly2DMesh.patchStarts()[patchi],
patchi,
mesh().boundaryMesh(),
polyPatch::typeName
);
}
mesh().addPatches(patches);
}
else if (surfaceFormat == POLYMESH2D)
{
mesh.set
(
new polyMesh
(
Foam::IOobject
(
Foam::polyMesh::defaultRegion,
runTimeExtruded.timeName(),
runTimeExtruded,
Foam::IOobject::MUST_READ
)
)
);
}
// Engine to extrude mesh
extrude2DMesh extruder(mesh(), extrude2DMeshDict, model());
extruder.addFrontBackPatches();
meshMod.set(new polyTopoChange(mesh().boundaryMesh().size()));
extruder.setRefinement(meshMod());
// Create a mesh from topo changes.
autoPtr<mapPolyMesh> morphMap = meshMod().changeMesh(mesh(), false);
mesh().updateMesh(morphMap);
{
edgeCollapser collapser(mesh());
const edgeList& edges = mesh().edges();
const pointField& points = mesh().points();
const boundBox& bb = mesh().bounds();
const scalar mergeDim = 1e-4 * bb.minDim();
PackedBoolList collapseEdge(mesh().nEdges());
Map<point> collapsePointToLocation(mesh().nPoints());
forAll(edges, edgeI)
{
const edge& e = edges[edgeI];
scalar d = e.mag(points);
if (d < mergeDim)
{
Info<< "Merging edge " << e << " since length " << d
<< " << " << mergeDim << nl;
collapseEdge[edgeI] = true;
collapsePointToLocation.set(e[1], points[e[0]]);
}
}
List<pointEdgeCollapse> allPointInfo;
const globalIndex globalPoints(mesh().nPoints());
labelList pointPriority(mesh().nPoints(), 0);
collapser.consistentCollapse
(
globalPoints,
pointPriority,
collapsePointToLocation,
collapseEdge,
allPointInfo
);
polyTopoChange meshModCollapse(mesh());
collapser.setRefinement(allPointInfo, meshModCollapse);
// Create a mesh from topo changes.
autoPtr<mapPolyMesh> morphMap
= meshModCollapse.changeMesh(mesh(), false);
mesh().updateMesh(morphMap);
}
if (!overwrite)
{
runTimeExtruded++;
}
else
{
mesh().setInstance("constant");
}
// Take over refinement levels and write to new time directory.
Info<< "\nWriting extruded mesh to time = " << runTimeExtruded.timeName()
<< nl << endl;
mesh().write();
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
|