ENH: add -tri (triangulate) option to foamToSurface, surfaceMeshConvert

STYLE: drop surface extraction from foamToStarMesh

- retain surfZone names when writing surfaces
- remove surface extraction/writing from meshWriter since it now
  duplicates what the meshedSurface class can do.
This commit is contained in:
Mark Olesen
2010-02-10 11:49:53 +01:00
parent 0bae7febff
commit 3613752115
15 changed files with 108 additions and 318 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -39,16 +39,6 @@ Usage
Specify an alternative geometry scaling factor. Specify an alternative geometry scaling factor.
The default is @b 1000 (scale @em [m] to @em [mm]). The default is @b 1000 (scale @em [m] to @em [mm]).
@param -surface \n
Extract the surface of the volume mesh only.
This can be useful, for example, for surface morphing in an external
package.
@param -tri \n
Extract a triangulated surface.
The @b -surface options is implicitly selected.
Note Note
The cellTable information available in the files The cellTable information available in the files
@c constant/cellTable and @c constant/polyMesh/cellTableId @c constant/cellTable and @c constant/polyMesh/cellTableId
@ -87,34 +77,13 @@ int main(int argc, char *argv[])
"noBnd", "noBnd",
"suppress writing the .bnd file" "suppress writing the .bnd file"
); );
argList::addBoolOption
(
"tri",
"Extract a triangulated surface. Implies -surface"
);
argList::addBoolOption
(
"surface",
"extract the surface of the volume mesh only"
);
# include "setRootCase.H" # include "setRootCase.H"
# include "createTime.H" # include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args); instantList timeDirs = timeSelector::select0(runTime, args);
bool surfaceOnly = false;
if (args.optionFound("surface") || args.optionFound("tri"))
{
surfaceOnly = true;
}
fileName exportName = meshWriter::defaultMeshName; fileName exportName = meshWriter::defaultMeshName;
if (surfaceOnly)
{
exportName = meshWriter::defaultSurfaceName;
}
if (args.optionFound("case")) if (args.optionFound("case"))
{ {
exportName += '-' + args.globalCaseName(); exportName += '-' + args.globalCaseName();
@ -132,7 +101,6 @@ int main(int argc, char *argv[])
# include "createPolyMesh.H" # include "createPolyMesh.H"
forAll(timeDirs, timeI) forAll(timeDirs, timeI)
{ {
runTime.setTime(timeDirs[timeI], timeI); runTime.setTime(timeDirs[timeI], timeI);
@ -156,21 +124,7 @@ int main(int argc, char *argv[])
meshName += '_' + runTime.timeName(); meshName += '_' + runTime.timeName();
} }
if (surfaceOnly) writer.write(meshName);
{
if (args.optionFound("tri"))
{
writer.writeSurface(meshName, true);
}
else
{
writer.writeSurface(meshName);
}
}
else
{
writer.write(meshName);
}
} }
Info<< nl << endl; Info<< nl << endl;

View File

@ -36,6 +36,9 @@ Usage
Specify an alternative geometry scaling factor. Specify an alternative geometry scaling factor.
Eg, use @b 1000 to scale @em [m] to @em [mm]. Eg, use @b 1000 to scale @em [m] to @em [mm].
@param -tri \n
Triangulate surface.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "argList.H" #include "argList.H"
@ -62,6 +65,11 @@ int main(int argc, char *argv[])
"scale", "scale",
"specify geometry scaling factor" "specify geometry scaling factor"
); );
argList::addBoolOption
(
"tri",
"triangulate surface"
);
# include "setRootCase.H" # include "setRootCase.H"
@ -69,6 +77,7 @@ int main(int argc, char *argv[])
scalar scaleFactor = 0; scalar scaleFactor = 0;
args.optionReadIfPresent<scalar>("scale", scaleFactor); args.optionReadIfPresent<scalar>("scale", scaleFactor);
const bool doTriangulate = args.optionFound("tri");
fileName exportName(params[0]); fileName exportName(params[0]);
@ -107,6 +116,12 @@ int main(int argc, char *argv[])
surf.scalePoints(scaleFactor); surf.scalePoints(scaleFactor);
Info<< "writing " << exportName; Info<< "writing " << exportName;
if (doTriangulate)
{
Info<< " triangulated";
surf.triangulate();
}
if (scaleFactor <= 0) if (scaleFactor <= 0)
{ {
Info<< " without scaling" << endl; Info<< " without scaling" << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -50,6 +50,9 @@ Usage
@param -to \<coordinateSystem\> \n @param -to \<coordinateSystem\> \n
Specify a coordinate System when writing files. Specify a coordinate System when writing files.
@param -tri \n
Triangulate surface.
Note Note
The filename extensions are used to determine the file format type. The filename extensions are used to determine the file format type.
@ -73,13 +76,47 @@ int main(int argc, char *argv[])
argList::validArgs.append("inputFile"); argList::validArgs.append("inputFile");
argList::validArgs.append("outputFile"); argList::validArgs.append("outputFile");
argList::addBoolOption("clean"); argList::addBoolOption
(
"clean",
"perform some surface checking/cleanup on the input surface"
);
argList::addOption
(
"scaleIn",
"scale",
"specify input geometry scaling factor"
);
argList::addOption
(
"scaleOut",
"scale",
"specify output geometry scaling factor"
);
argList::addOption
(
"dict",
"file",
"specify alternative dictionary for the coordinateSystems descriptions"
);
argList::addOption
(
"from",
"system",
"specify the source coordinate system, applied after '-scaleIn'"
);
argList::addOption
(
"to",
"system",
"specify the target coordinate system, applied before '-scaleOut'"
);
argList::addBoolOption
(
"tri",
"triangulate surface"
);
argList::addOption("scaleIn", "scale");
argList::addOption("scaleOut", "scale");
argList::addOption("dict", "coordinateSystemsDict");
argList::addOption("from", "sourceCoordinateSystem");
argList::addOption("to", "targetCoordinateSystem");
argList args(argc, argv); argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName()); Time runTime(args.rootPath(), args.caseName());
@ -242,6 +279,12 @@ int main(int argc, char *argv[])
surf.scalePoints(scaleOut); surf.scalePoints(scaleOut);
} }
if (args.optionFound("tri"))
{
Info<< "triangulate" << endl;
surf.triangulate();
}
Info<< "writing " << exportName; Info<< "writing " << exportName;
surf.write(exportName); surf.write(exportName);
} }

View File

@ -29,6 +29,9 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::string Foam::meshWriter::defaultMeshName = "meshExport";
const Foam::cellModel* Foam::meshWriter::unknownModel = Foam::cellModeller:: const Foam::cellModel* Foam::meshWriter::unknownModel = Foam::cellModeller::
lookup lookup
( (
@ -64,10 +67,6 @@ lookup
); );
Foam::string Foam::meshWriter::defaultMeshName = "meshExport";
Foam::string Foam::meshWriter::defaultSurfaceName = "surfExport";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshWriter::meshWriter(const polyMesh& mesh, const scalar scaleFactor) Foam::meshWriter::meshWriter(const polyMesh& mesh, const scalar scaleFactor)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -85,7 +85,7 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class meshWriter Declaration Class meshWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class meshWriter class meshWriter
@ -133,13 +133,12 @@ public:
// Static data members // Static data members
//- Specify a default mesh name
static string defaultMeshName; static string defaultMeshName;
static string defaultSurfaceName;
// Constructors // Constructors
//- Ccreate a writer obejct //- Create a writer obejct
meshWriter meshWriter
( (
const polyMesh&, const polyMesh&,
@ -167,26 +166,14 @@ public:
writeBoundary_ = false; writeBoundary_ = false;
} }
// Write // Write
//- Write volume mesh //- Write volume mesh. Subclass must supply this method
// subclass must to supply this method
virtual bool write virtual bool write
( (
const fileName& timeName = fileName::null const fileName& timeName = fileName::null
) const = 0; ) const = 0;
//- Write surface mesh with optional triangulation
// subclass could supply this information
virtual bool writeSurface
(
const fileName& timeName = fileName::null,
const bool triangulate = false
) const
{
return false;
}
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -527,201 +527,4 @@ bool Foam::meshWriters::STARCD::write(const fileName& meshName) const
} }
bool Foam::meshWriters::STARCD::writeSurface
(
const fileName& meshName,
const bool triangulate
) const
{
fileName baseName(meshName);
if (baseName.empty())
{
baseName = meshWriter::defaultSurfaceName;
if
(
mesh_.time().timeName() != "0"
&& mesh_.time().timeName() != "constant"
)
{
baseName += "_" + mesh_.time().timeName();
}
}
rmFiles(baseName);
OFstream celFile(baseName + ".cel");
writeHeader(celFile, "CELL");
Info<< "Writing " << celFile.name() << endl;
// mesh and patch info
const pointField& points = mesh_.points();
const labelList& owner = mesh_.faceOwner();
const faceList& meshFaces = mesh_.faces();
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
label shapeId = 3; // shell/baffle element
label typeId = 4; // 4(shell)
// remember which points need to be written
labelHashSet pointHash;
// write boundary faces as normal STAR-CD mesh
if (triangulate)
{
// cell Id has no particular meaning - just increment
// use the cellTable id from the patch Number
label cellId = 0;
forAll(patches, patchI)
{
label patchStart = patches[patchI].start();
label patchSize = patches[patchI].size();
label ctableId = patchI + 1;
for
(
label faceI = patchStart;
faceI < (patchStart + patchSize);
++faceI
)
{
const face& f = meshFaces[faceI];
label nTri = f.nTriangles(points);
faceList triFaces;
// triangulate polygons, but not quads
if (nTri <= 2)
{
triFaces.setSize(1);
triFaces[0] = f;
}
else
{
triFaces.setSize(nTri);
nTri = 0;
f.triangles(points, nTri, triFaces);
}
forAll(triFaces, faceI)
{
const labelList& vrtList = triFaces[faceI];
celFile
<< cellId + 1 << " "
<< shapeId << " "
<< vrtList.size() << " "
<< ctableId << " "
<< typeId;
// must be 3 (triangle) but could be quad
label count = 0;
forAll(vrtList, i)
{
if ((count % 8) == 0)
{
celFile
<< nl
<< " " << cellId + 1;
}
// remember which points we'll need to write
pointHash.insert(vrtList[i]);
celFile << " " << vrtList[i] + 1;
count++;
}
celFile << endl;
cellId++;
}
}
}
}
else
{
// cell Id is the OpenFOAM face Id
// use the cellTable id from the face owner
// - allows separation of parts
forAll(patches, patchI)
{
label patchStart = patches[patchI].start();
label patchSize = patches[patchI].size();
for
(
label faceI = patchStart;
faceI < (patchStart + patchSize);
++faceI
)
{
const labelList& vrtList = meshFaces[faceI];
label cellId = faceI;
celFile
<< cellId + 1 << " "
<< shapeId << " "
<< vrtList.size() << " "
<< cellTableId_[owner[faceI]] << " "
<< typeId;
// likely <= 8 vertices, but prevent overrun anyhow
label count = 0;
forAll(vrtList, i)
{
if ((count % 8) == 0)
{
celFile
<< nl
<< " " << cellId + 1;
}
// remember which points we'll need to write
pointHash.insert(vrtList[i]);
celFile << " " << vrtList[i] + 1;
count++;
}
celFile << endl;
}
}
}
OFstream vrtFile(baseName + ".vrt");
writeHeader(vrtFile, "VERTEX");
vrtFile.precision(10);
vrtFile.setf(std::ios::showpoint); // force decimal point for Fortran
Info<< "Writing " << vrtFile.name() << endl;
// build sorted table of contents
SortableList<label> toc(pointHash.size());
{
label i = 0;
forAllConstIter(labelHashSet, pointHash, iter)
{
toc[i++] = iter.key();
}
}
toc.sort();
toc.shrink();
pointHash.clear();
// write points in sorted order
forAll(toc, i)
{
label vrtId = toc[i];
vrtFile
<< vrtId + 1
<< " " << scaleFactor_ * points[vrtId].x()
<< " " << scaleFactor_ * points[vrtId].y()
<< " " << scaleFactor_ * points[vrtId].z()
<< endl;
}
return true;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -28,11 +28,6 @@ Class
Description Description
Writes polyMesh in pro-STAR (v4) bnd/cel/vrt format Writes polyMesh in pro-STAR (v4) bnd/cel/vrt format
Alternatively, extracts the surface of the FOAM mesh into
pro-STAR (v4) .cel/.vrt/ format.
This can be useful, for example, for surface morphing in an external
package.
The cellTableId and cellTable information are used (if available). The cellTableId and cellTable information are used (if available).
Otherwise the cellZones are used (if available). Otherwise the cellZones are used (if available).
@ -131,12 +126,6 @@ public:
const fileName& meshName = fileName::null const fileName& meshName = fileName::null
) const; ) const;
//- Write surface mesh with optional triangulation
virtual bool writeSurface
(
const fileName& meshName = fileName::null,
const bool triangulate = false
) const;
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -225,9 +225,9 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
// for no zones, suppress the group name // for no zones, suppress the group name
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst, "")
: oneZone(faceLst, "") : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -52,9 +52,9 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst)
: oneZone(faceLst) : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -256,9 +256,9 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst)
: oneZone(faceLst) : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -213,9 +213,9 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst)
: oneZone(faceLst) : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -139,9 +139,9 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst)
: oneZone(faceLst) : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -70,9 +70,9 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst)
: oneZone(faceLst) : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -53,9 +53,9 @@ void Foam::fileFormats::WRLsurfaceFormat<Face>::write
// for no zones, suppress the group name // for no zones, suppress the group name
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst, "")
: oneZone(faceLst, "") : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -55,9 +55,9 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
// for no zones, suppress the group name // for no zones, suppress the group name
const List<surfZone>& zones = const List<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().empty()
? surf.surfZones() ? oneZone(faceLst, "")
: oneZone(faceLst, "") : surf.surfZones()
); );
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);