2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Description
|
2010-08-25 21:42:57 +00:00
|
|
|
Extrude mesh from existing patch (by default outwards facing normals;
|
|
|
|
optional flips faces) or from patch read from file.
|
|
|
|
|
2019-06-13 13:14:49 +00:00
|
|
|
Note: Merges close points so be careful. This can be controlled with the
|
|
|
|
optional mergeTolerance parameter (1e-4) by default.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Type of extrusion prescribed by run-time selectable model.
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "argList.H"
|
2013-11-03 20:28:05 +00:00
|
|
|
#include "objectRegistry.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#include "dimensionedTypes.H"
|
|
|
|
#include "IFstream.H"
|
|
|
|
#include "faceMesh.H"
|
|
|
|
#include "mapPolyMesh.H"
|
|
|
|
#include "directTopoChange.H"
|
|
|
|
#include "polyTopoChange.H"
|
|
|
|
#include "polyTopoChanger.H"
|
|
|
|
#include "edgeCollapser.H"
|
|
|
|
#include "mathematicalConstants.H"
|
|
|
|
#include "globalMeshData.H"
|
|
|
|
#include "perfectInterface.H"
|
|
|
|
|
|
|
|
#include "extrudedMesh.H"
|
|
|
|
#include "extrudeModel.H"
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
# include "setRootCase.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
# include "createTimeExtruded.H"
|
|
|
|
|
2019-01-25 16:22:44 +00:00
|
|
|
autoPtr<extrudedMesh> meshPtr(nullptr);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
IOdictionary dict
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
2010-08-25 21:42:57 +00:00
|
|
|
IOobject
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
2010-08-25 21:42:57 +00:00
|
|
|
"extrudeProperties",
|
|
|
|
runTimeExtruded.constant(),
|
|
|
|
runTimeExtruded,
|
|
|
|
IOobject::MUST_READ
|
2010-05-12 13:27:55 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
autoPtr<extrudeModel> model(extrudeModel::New(dict));
|
|
|
|
|
|
|
|
const word sourceType(dict.lookup("constructFrom"));
|
|
|
|
|
|
|
|
autoPtr<faceMesh> fMesh;
|
|
|
|
|
|
|
|
if (sourceType == "patch")
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
fileName sourceCasePath(dict.lookup("sourceCase"));
|
|
|
|
sourceCasePath.expand();
|
|
|
|
fileName sourceRootDir = sourceCasePath.path();
|
|
|
|
fileName sourceCaseDir = sourceCasePath.name();
|
|
|
|
word patchName(dict.lookup("sourcePatch"));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Extruding patch " << patchName
|
2010-08-25 21:42:57 +00:00
|
|
|
<< " on mesh " << sourceCasePath << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< endl;
|
|
|
|
|
|
|
|
Time runTime
|
|
|
|
(
|
|
|
|
Time::controlDictName,
|
2010-08-25 21:42:57 +00:00
|
|
|
sourceRootDir,
|
|
|
|
sourceCaseDir
|
2010-05-12 13:27:55 +00:00
|
|
|
);
|
2010-08-25 21:42:57 +00:00
|
|
|
#include "createPolyMesh.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
label patchID = mesh.boundaryMesh().findPatchID(patchName);
|
|
|
|
|
|
|
|
if (patchID == -1)
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Cannot find patch " << patchName
|
|
|
|
<< " in the source mesh.\n"
|
|
|
|
<< "Valid patch names are " << mesh.boundaryMesh().names()
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
const polyPatch& pp = mesh.boundaryMesh()[patchID];
|
2010-08-25 21:42:57 +00:00
|
|
|
fMesh.reset(new faceMesh(pp.localFaces(), pp.localPoints()));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
fileName surfName(runTime.path()/patchName + ".sMesh");
|
|
|
|
Info<< "Writing patch as surfaceMesh to "
|
|
|
|
<< surfName << nl << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
OFstream os(surfName);
|
2010-08-25 21:42:57 +00:00
|
|
|
os << fMesh() << nl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-25 21:42:57 +00:00
|
|
|
else if (sourceType == "surface")
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Read from surface
|
2010-08-25 21:42:57 +00:00
|
|
|
fileName surfName(dict.lookup("surface"));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Extruding surfaceMesh read from file " << surfName << nl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
IFstream is(surfName);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
fMesh.reset(new faceMesh(is));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Read patch from file " << surfName << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< endl;
|
2010-08-25 21:42:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Illegal 'constructFrom' specification. Should either be "
|
|
|
|
<< "patch or surface." << exit(FatalError);
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Switch flipNormals(dict.lookup("flipNormals"));
|
|
|
|
|
|
|
|
if (flipNormals)
|
|
|
|
{
|
|
|
|
Info<< "Flipping faces." << nl << endl;
|
|
|
|
|
|
|
|
faceList faces(fMesh().size());
|
|
|
|
forAll(faces, i)
|
|
|
|
{
|
|
|
|
faces[i] = fMesh()[i].reverseFace();
|
|
|
|
}
|
|
|
|
fMesh.reset(new faceMesh(faces, fMesh().localPoints()));
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2010-08-25 21:42:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
Info<< "Extruding patch with :" << nl
|
|
|
|
<< " points : " << fMesh().points().size() << nl
|
|
|
|
<< " faces : " << fMesh().size() << nl
|
|
|
|
<< " normals[0] : " << fMesh().faceNormals()[0]
|
|
|
|
<< nl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
extrudedMesh mesh
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
extrudedMesh::defaultRegion,
|
|
|
|
runTimeExtruded.constant(),
|
|
|
|
runTimeExtruded
|
|
|
|
),
|
|
|
|
fMesh(),
|
|
|
|
model()
|
|
|
|
);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
const boundBox& bb = mesh.globalData().bb();
|
2010-08-25 21:42:57 +00:00
|
|
|
const vector span = bb.span();
|
2019-06-02 16:49:26 +00:00
|
|
|
|
|
|
|
// Read merge tolerance
|
2019-06-13 13:14:49 +00:00
|
|
|
const scalar mergeTolerance =
|
|
|
|
dict.lookupOrDefault<scalar>("mergeTolerance", 1e-4);
|
2019-06-02 16:49:26 +00:00
|
|
|
const scalar mergeDim = mergeTolerance*bb.minDim();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Mesh bounding box : " << bb << nl
|
|
|
|
<< " with span : " << span << nl
|
|
|
|
<< "Merge distance : " << mergeDim << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< endl;
|
|
|
|
|
|
|
|
const polyBoundaryMesh& patches = mesh.boundaryMesh();
|
|
|
|
|
|
|
|
const label origPatchID = patches.findPatchID("originalPatch");
|
|
|
|
const label otherPatchID = patches.findPatchID("otherSide");
|
|
|
|
|
|
|
|
if (origPatchID == -1 || otherPatchID == -1)
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Cannot find patch originalPatch or otherSide." << nl
|
|
|
|
<< "Valid patches are " << patches.names() << exit(FatalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collapse edges
|
|
|
|
// ~~~~~~~~~~~~~~
|
2019-06-02 16:49:26 +00:00
|
|
|
if (mergeTolerance > SMALL)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Collapsing edges < " << mergeDim << " ..." << nl << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Edge collapsing engine
|
|
|
|
edgeCollapser collapser(mesh);
|
|
|
|
|
|
|
|
const edgeList& edges = mesh.edges();
|
|
|
|
const pointField& points = mesh.points();
|
|
|
|
|
|
|
|
forAll(edges, edgeI)
|
|
|
|
{
|
|
|
|
const edge& e = edges[edgeI];
|
|
|
|
|
|
|
|
scalar d = e.mag(points);
|
|
|
|
|
|
|
|
if (d < mergeDim)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Merging edge " << e << " since length " << d
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " << " << mergeDim << nl;
|
|
|
|
|
|
|
|
// Collapse edge to e[0]
|
|
|
|
collapser.collapseEdge(edgeI, e[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Topo change container
|
|
|
|
directTopoChange meshMod(mesh);
|
|
|
|
// Put all modifications into meshMod
|
|
|
|
bool anyChange = collapser.setRefinement(meshMod);
|
|
|
|
|
|
|
|
if (anyChange)
|
|
|
|
{
|
|
|
|
// Construct new mesh from directTopoChange.
|
|
|
|
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
|
|
|
|
|
|
|
|
// Update fields
|
|
|
|
mesh.updateMesh(map);
|
|
|
|
|
|
|
|
// Move mesh (if inflation used)
|
|
|
|
if (map().hasMotionPoints())
|
|
|
|
{
|
|
|
|
mesh.movePoints(map().preMotionPoints());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Merging front and back patch faces
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Switch mergeFaces(dict.lookup("mergeFaces"));
|
|
|
|
if (mergeFaces)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Assuming full 360 degree axisymmetric case;"
|
|
|
|
<< " stitching faces on patches "
|
2010-05-12 13:27:55 +00:00
|
|
|
<< patches[origPatchID].name() << " and "
|
|
|
|
<< patches[otherPatchID].name() << " together ..." << nl << endl;
|
|
|
|
|
|
|
|
polyTopoChanger stitcher(mesh);
|
|
|
|
stitcher.setSize(1);
|
|
|
|
|
|
|
|
// Make list of masterPatch faces
|
|
|
|
labelList isf(patches[origPatchID].size());
|
|
|
|
|
|
|
|
forAll (isf, i)
|
|
|
|
{
|
|
|
|
isf[i] = patches[origPatchID].start() + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
const word cutZoneName("originalCutFaceZone");
|
|
|
|
|
|
|
|
List<faceZone*> fz
|
|
|
|
(
|
|
|
|
1,
|
|
|
|
new faceZone
|
|
|
|
(
|
|
|
|
cutZoneName,
|
|
|
|
isf,
|
|
|
|
boolList(isf.size(), false),
|
|
|
|
0,
|
|
|
|
mesh.faceZones()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
mesh.addZones(List<pointZone*>(0), fz, List<cellZone*>(0));
|
|
|
|
|
|
|
|
// Add the perfect interface mesh modifier
|
|
|
|
stitcher.set
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
new perfectInterface
|
|
|
|
(
|
|
|
|
"couple",
|
|
|
|
0,
|
|
|
|
stitcher,
|
|
|
|
cutZoneName,
|
|
|
|
patches[origPatchID].name(),
|
|
|
|
patches[otherPatchID].name()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Execute all polyMeshModifiers
|
2010-09-22 18:13:13 +00:00
|
|
|
autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
mesh.movePoints(morphMap->preMotionPoints());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mesh.write())
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable()) << "Failed writing mesh"
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
Info << "End\n" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|