mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support independent specification of surface read/write format (#1600)
- adjustments to internal handling to improve run-time addition of
other formats (eg, with additional user library)
For example, to write a binary STL with a '.stl' extension:
$ surfaceMeshConvert input.obj -write-format stlb output.stl
Or in a sampler,
to specify the input type without ambiguity:
surf
{
type meshedSurface;
surface sampling.inp;
fileType starcd;
scale 0.001;
...
}
STYLE: regularize naming for input/output scaling
* -read-scale (compat: -scaleIn)
* -write-scale (compat: -scaleOut)
CONFIG: change edge/surface selection name for STARCD format
- now select as "starcd" instead of "inp" to avoid naming ambiguity
with abaqus
This commit is contained in:
@ -148,8 +148,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
FatalError
|
||||
<< "Output file would overwrite input file."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ int main(int argc, char *argv[])
|
||||
fileName exportName;
|
||||
if (args.readIfPresent("name", exportName))
|
||||
{
|
||||
const word ext = exportName.ext();
|
||||
const word ext(exportName.ext());
|
||||
// strip erroneous extension (.ccm, .ccmg, .ccmp)
|
||||
if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
|
||||
{
|
||||
|
||||
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
||||
fileName exportName = ccm::writer::defaultMeshName;
|
||||
if (args.readIfPresent("name", exportName))
|
||||
{
|
||||
const word ext = exportName.ext();
|
||||
const word ext(exportName.ext());
|
||||
// strip erroneous extension (.ccm, .ccmg, .ccmp)
|
||||
if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
|
||||
{
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,6 +40,12 @@ Usage
|
||||
- \par -clean
|
||||
Perform some surface checking/cleanup on the input surface
|
||||
|
||||
- \par -read-format \<type\>
|
||||
Specify input file format
|
||||
|
||||
- \par -write-format \<type\>
|
||||
Specify output file format
|
||||
|
||||
- \par -scale \<scale\>
|
||||
Specify a scaling factor for writing the files
|
||||
|
||||
@ -59,6 +66,36 @@ Note
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
static word getExtension(const fileName& name)
|
||||
{
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
// Non-short-circuiting check to get all warnings
|
||||
static bool hasReadWriteTypes(const word& readType, const word& writeType)
|
||||
{
|
||||
volatile bool good = true;
|
||||
|
||||
if (!triSurface::canReadType(readType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
if (!triSurface::canWriteType(writeType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
return good;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -84,6 +121,18 @@ int main(int argc, char *argv[])
|
||||
"Reorder faces into groups; one per region"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"read-format",
|
||||
"type",
|
||||
"The input format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"write-format",
|
||||
"type",
|
||||
"The output format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scale",
|
||||
"factor",
|
||||
@ -93,7 +142,7 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
"precision",
|
||||
"int",
|
||||
"Write to output with the specified precision"
|
||||
"The output precision"
|
||||
);
|
||||
argList::addOptionCompat("precision", {"writePrecision", 1812});
|
||||
|
||||
@ -110,30 +159,47 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
const fileName importName = args[1];
|
||||
const fileName exportName = args[2];
|
||||
const fileName importName(args[1]);
|
||||
const fileName exportName(args[2]);
|
||||
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
FatalError
|
||||
<< "Output file would overwrite input file." << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if
|
||||
const word readFileType
|
||||
(
|
||||
!triSurface::canRead(importName, true)
|
||||
|| !triSurface::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
args.getOrDefault<word>("read-format", getExtension(importName))
|
||||
);
|
||||
|
||||
const word writeFileType
|
||||
(
|
||||
args.getOrDefault<word>("write-format", getExtension(exportName))
|
||||
);
|
||||
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if (!hasReadWriteTypes(readFileType, writeFileType))
|
||||
{
|
||||
return 1;
|
||||
FatalError
|
||||
<< "Unsupported file format(s)" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
const scalar scaleFactor = args.get<scalar>("scale", -1);
|
||||
|
||||
scalar scaleFactor(0);
|
||||
|
||||
Info<< "Reading : " << importName << endl;
|
||||
triSurface surf(importName, scaleFactor);
|
||||
triSurface surf(importName, readFileType, scaleFactor);
|
||||
|
||||
if (args.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleFactor << nl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
@ -159,10 +225,9 @@ int main(int argc, char *argv[])
|
||||
Info<< "Maintaining face ordering" << endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
Info<< endl;
|
||||
Info<< "writing " << exportName << endl;
|
||||
|
||||
surf.write(exportName, sortByRegion);
|
||||
surf.write(exportName, writeFileType, sortByRegion);
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2015 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -42,8 +42,38 @@ Description
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
static word getExtension(const fileName& name)
|
||||
{
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
// Non-short-circuiting check to get all warnings
|
||||
static bool hasReadWriteTypes(const word& readType, const word& writeType)
|
||||
{
|
||||
volatile bool good = true;
|
||||
|
||||
if (!edgeMesh::canReadType(readType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
if (!edgeMesh::canWriteType(writeType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
return good;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -55,44 +85,64 @@ int main(int argc, char *argv[])
|
||||
argList::addArgument("input", "The input edge file");
|
||||
argList::addArgument("output", "The output edge file");
|
||||
argList::addOption
|
||||
(
|
||||
"read-format",
|
||||
"type",
|
||||
"The input format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"write-format",
|
||||
"type",
|
||||
"The output format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scale",
|
||||
"factor",
|
||||
"Geometry scaling factor - default is 1"
|
||||
"Input geometry scaling factor"
|
||||
);
|
||||
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
|
||||
const fileName importName = args[1];
|
||||
const fileName exportName = args[2];
|
||||
const fileName importName(args[1]);
|
||||
const fileName exportName(args[2]);
|
||||
|
||||
// Disable inplace editing
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
FatalError
|
||||
<< "Output file would overwrite input file."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if
|
||||
const word readFileType
|
||||
(
|
||||
!edgeMesh::canReadType(importName.ext(), true)
|
||||
|| !edgeMesh::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
args.getOrDefault<word>("read-format", getExtension(importName))
|
||||
);
|
||||
|
||||
const word writeFileType
|
||||
(
|
||||
args.getOrDefault<word>("write-format", getExtension(exportName))
|
||||
);
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if (!hasReadWriteTypes(readFileType, writeFileType))
|
||||
{
|
||||
return 1;
|
||||
FatalError
|
||||
<< "Unsupported file format(s)" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
edgeMesh mesh(importName);
|
||||
edgeMesh mesh(importName, readFileType);
|
||||
|
||||
Info<< "\nRead edgeMesh " << importName << nl;
|
||||
mesh.writeStats(Info);
|
||||
Info<< nl
|
||||
<< "\nwriting " << exportName;
|
||||
|
||||
scalar scaleFactor = 0;
|
||||
scalar scaleFactor(0);
|
||||
if (args.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
@ -103,7 +153,7 @@ int main(int argc, char *argv[])
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
|
||||
mesh.write(exportName);
|
||||
mesh.write(exportName, writeFileType);
|
||||
mesh.writeStats(Info);
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
@ -41,26 +41,32 @@ Usage
|
||||
- \par -clean
|
||||
Perform some surface checking/cleanup on the input surface.
|
||||
|
||||
- \par -scaleIn \<scale\>
|
||||
Specify a scaling factor when reading files.
|
||||
- \par -read-format \<type\>
|
||||
The input file format (default: use file extension)
|
||||
|
||||
- \par -scaleOut \<scale\>
|
||||
Specify a scaling factor when writing files.
|
||||
- \par -write-format \<type\>
|
||||
The output file format (default: use file extension)
|
||||
|
||||
- \par -read-scale \<scale\>
|
||||
Input geometry scaling factor.
|
||||
|
||||
- \par -write-scale \<scale\>
|
||||
Output geometry scaling factor.
|
||||
|
||||
- \par -dict \<dictionary\>
|
||||
Specify an alternative dictionary for constant/coordinateSystems.
|
||||
Alternative dictionary for constant/coordinateSystems.
|
||||
|
||||
- \par -from \<coordinateSystem\>
|
||||
Specify a coordinate System when reading files.
|
||||
Apply specified coordinate system after reading file.
|
||||
|
||||
- \par -to \<coordinateSystem\>
|
||||
Specify a coordinate System when writing files.
|
||||
Apply specified coordinate system before writing file.
|
||||
|
||||
- \par -tri
|
||||
Triangulate surface.
|
||||
|
||||
Note
|
||||
The filename extensions are used to determine the file format type.
|
||||
The filename extensions are used to determine the default file formats.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -73,6 +79,36 @@ Note
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
static word getExtension(const fileName& name)
|
||||
{
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
// Non-short-circuiting check to get all warnings
|
||||
static bool hasReadWriteTypes(const word& readType, const word& writeType)
|
||||
{
|
||||
volatile bool good = true;
|
||||
|
||||
if (!meshedSurface::canReadType(readType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
if (!meshedSurface::canWriteType(writeType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
return good;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -93,30 +129,46 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scaleIn",
|
||||
"factor",
|
||||
"Geometry scaling factor on input"
|
||||
"read-format",
|
||||
"type",
|
||||
"Input format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scaleOut",
|
||||
"factor",
|
||||
"Geometry scaling factor on output"
|
||||
"write-format",
|
||||
"type",
|
||||
"Output format (default: use file extension)"
|
||||
);
|
||||
argList::addOption("dict", "file", "Use alternative coordinateSystems");
|
||||
argList::addOption
|
||||
(
|
||||
"read-scale",
|
||||
"factor",
|
||||
"Input geometry scaling factor"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"write-scale",
|
||||
"factor",
|
||||
"Output geometry scaling factor"
|
||||
);
|
||||
|
||||
argList::addOptionCompat("read-scale", {"scaleIn", 1912});
|
||||
argList::addOptionCompat("write-scale", {"scaleOut", 1912});
|
||||
|
||||
argList::addOption("dict", "file", "Alternative coordinateSystems");
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"from",
|
||||
"system",
|
||||
"Specify the source coordinate system, applied after '-scaleIn'",
|
||||
"The source coordinate system, applied after '-read-scale'",
|
||||
true // advanced
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"to",
|
||||
"system",
|
||||
"Specify the target coordinate system, applied before '-scaleOut'",
|
||||
"The target coordinate system, applied before '-write-scale'",
|
||||
true // advanced
|
||||
);
|
||||
argList::addBoolOption
|
||||
@ -129,28 +181,38 @@ int main(int argc, char *argv[])
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
|
||||
const fileName importName = args[1];
|
||||
const fileName exportName = args[2];
|
||||
const fileName importName(args[1]);
|
||||
const fileName exportName(args[2]);
|
||||
|
||||
// disable inplace editing
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
FatalError
|
||||
<< "Output file would overwrite input file."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if
|
||||
const word readFileType
|
||||
(
|
||||
!MeshedSurface<face>::canRead(importName, true)
|
||||
|| !MeshedSurface<face>::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
args.getOrDefault<word>("read-format", getExtension(importName))
|
||||
);
|
||||
|
||||
const word writeFileType
|
||||
(
|
||||
args.getOrDefault<word>("write-format", getExtension(exportName))
|
||||
);
|
||||
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if (!hasReadWriteTypes(readFileType, writeFileType))
|
||||
{
|
||||
return 1;
|
||||
FatalError
|
||||
<< "Unsupported file format(s)" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
scalar scaleFactor(0);
|
||||
|
||||
// The coordinate transformations (must be cartesian)
|
||||
autoPtr<coordSystem::cartesian> fromCsys;
|
||||
autoPtr<coordSystem::cartesian> toCsys;
|
||||
@ -173,7 +235,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot open coordinateSystems file\n "
|
||||
<< ioCsys.objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
@ -188,7 +250,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!csPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot find -from " << csName << nl
|
||||
<< "available coordinateSystems: "
|
||||
<< flatOutput(globalCoords.names()) << nl
|
||||
@ -205,7 +267,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!csPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot find -to " << csName << nl
|
||||
<< "available coordinateSystems: "
|
||||
<< flatOutput(globalCoords.names()) << nl
|
||||
@ -218,7 +280,7 @@ int main(int argc, char *argv[])
|
||||
// Maybe fix this later
|
||||
if (fromCsys && toCsys)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Only allowed '-from' or '-to' option at the moment."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
@ -226,24 +288,23 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
{
|
||||
MeshedSurface<face> surf(importName);
|
||||
meshedSurface surf(importName, readFileType);
|
||||
|
||||
if (args.readIfPresent("read-scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleFactor << nl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
if (args.found("clean"))
|
||||
{
|
||||
surf.cleanup(true);
|
||||
}
|
||||
|
||||
scalar scaleIn = 0;
|
||||
if (args.readIfPresent("scaleIn", scaleIn) && scaleIn > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleIn << endl;
|
||||
surf.scalePoints(scaleIn);
|
||||
}
|
||||
|
||||
if (fromCsys)
|
||||
{
|
||||
Info<< "move points from coordinate system: "
|
||||
<< fromCsys->name() << endl;
|
||||
<< fromCsys->name() << nl;
|
||||
tmp<pointField> tpf = fromCsys->localPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
@ -251,26 +312,25 @@ int main(int argc, char *argv[])
|
||||
if (toCsys)
|
||||
{
|
||||
Info<< "move points to coordinate system: "
|
||||
<< toCsys->name() << endl;
|
||||
<< toCsys->name() << nl;
|
||||
tmp<pointField> tpf = toCsys->globalPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
scalar scaleOut = 0;
|
||||
if (args.readIfPresent("scaleOut", scaleOut) && scaleOut > 0)
|
||||
if (args.readIfPresent("write-scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale output " << scaleOut << endl;
|
||||
surf.scalePoints(scaleOut);
|
||||
Info<< "scale output " << scaleFactor << nl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
if (args.found("tri"))
|
||||
{
|
||||
Info<< "triangulate" << endl;
|
||||
Info<< "triangulate" << nl;
|
||||
surf.triangulate();
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
surf.write(exportName);
|
||||
surf.write(exportName, writeFileType);
|
||||
}
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
@ -45,11 +45,14 @@ Usage
|
||||
- \par -name \<name\>
|
||||
Specify an alternative surface name when writing.
|
||||
|
||||
- \par -scaleIn \<scale\>
|
||||
Specify a scaling factor when reading files.
|
||||
- \par -write-format \<type\>
|
||||
Specify output file format
|
||||
|
||||
- \par -scaleOut \<scale\>
|
||||
Specify a scaling factor when writing files.
|
||||
- \par -read-scale \<scale\>
|
||||
Scale factor when reading files.
|
||||
|
||||
- \par -write-scale \<scale\>
|
||||
Scale factor when writing files.
|
||||
|
||||
- \par -dict \<dictionary\>
|
||||
Specify an alternative dictionary for constant/coordinateSystems.
|
||||
@ -74,6 +77,18 @@ Note
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
static word getExtension(const fileName& name)
|
||||
{
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -100,46 +115,65 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scaleIn",
|
||||
"factor",
|
||||
"Geometry scaling factor on input - default is 1"
|
||||
"write-format",
|
||||
"type",
|
||||
"Output format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scaleOut",
|
||||
"read-scale",
|
||||
"factor",
|
||||
"Geometry scaling factor on output - default is 1"
|
||||
"Input geometry scaling factor"
|
||||
);
|
||||
argList::addOption("dict", "file", "Use alternative coordinateSystems");
|
||||
argList::addOption
|
||||
(
|
||||
"write-scale",
|
||||
"factor",
|
||||
"Output geometry scaling factor"
|
||||
);
|
||||
|
||||
argList::addOptionCompat("read-scale", {"scaleIn", 1912});
|
||||
argList::addOptionCompat("write-scale", {"scaleOut", 1912});
|
||||
|
||||
argList::addOption("dict", "file", "Alternative coordinateSystems");
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"from",
|
||||
"coordinateSystem",
|
||||
"Specify the source coordinate system, applied after '-scaleIn'",
|
||||
"system",
|
||||
"The source coordinate system, applied after '-read-scale'",
|
||||
true // advanced
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"to",
|
||||
"coordinateSystem",
|
||||
"Specify the target coordinate system, applied before '-scaleOut'",
|
||||
"system",
|
||||
"The target coordinate system, applied before '-write-scale'",
|
||||
true // advanced
|
||||
);
|
||||
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
|
||||
const fileName exportName = args[1];
|
||||
const word importName = args.get<word>("name", "default");
|
||||
const fileName exportName(args[1]);
|
||||
const word importName(args.get<word>("name", "default"));
|
||||
|
||||
// check that writing is supported
|
||||
if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
|
||||
const word writeFileType
|
||||
(
|
||||
args.getOrDefault<word>("write-format", getExtension(exportName))
|
||||
);
|
||||
|
||||
// Check read/write support for formats
|
||||
if (!meshedSurface::canWriteType(writeFileType, true))
|
||||
{
|
||||
return 1;
|
||||
FatalError
|
||||
<< "Unsupported file format(s)" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
scalar scaleFactor(0);
|
||||
|
||||
// The coordinate transformations (must be cartesian)
|
||||
autoPtr<coordSystem::cartesian> fromCsys;
|
||||
autoPtr<coordSystem::cartesian> toCsys;
|
||||
@ -162,7 +196,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< ioCsys.objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
@ -176,7 +210,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!csPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot find -from " << csName << nl
|
||||
<< "available coordinateSystems: "
|
||||
<< flatOutput(globalCoords.names()) << nl
|
||||
@ -193,7 +227,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!csPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot find -to " << csName << nl
|
||||
<< "available coordinateSystems: "
|
||||
<< flatOutput(globalCoords.names()) << nl
|
||||
@ -206,7 +240,7 @@ int main(int argc, char *argv[])
|
||||
// Maybe fix this later
|
||||
if (fromCsys && toCsys)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Only allowed '-from' or '-to' option at the moment."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
@ -228,22 +262,21 @@ int main(int argc, char *argv[])
|
||||
Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
|
||||
|
||||
|
||||
// Simply copy for now, but really should have a separate write method
|
||||
// Simply copy for now, but really could have a separate write method
|
||||
|
||||
MeshedSurface<face> surf(smesh);
|
||||
meshedSurface surf(smesh);
|
||||
|
||||
if (args.readIfPresent("read-scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleFactor << nl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
if (args.found("clean"))
|
||||
{
|
||||
surf.cleanup(true);
|
||||
}
|
||||
|
||||
scalar scaleIn = 0;
|
||||
if (args.readIfPresent("scaleIn", scaleIn) && scaleIn > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleIn << endl;
|
||||
surf.scalePoints(scaleIn);
|
||||
}
|
||||
|
||||
if (fromCsys.valid())
|
||||
{
|
||||
Info<< "move points from coordinate system: "
|
||||
@ -260,19 +293,17 @@ int main(int argc, char *argv[])
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
scalar scaleOut = 0;
|
||||
if (args.readIfPresent("scaleOut", scaleOut) && scaleOut > 0)
|
||||
if (args.readIfPresent("write-scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale output " << scaleOut << endl;
|
||||
surf.scalePoints(scaleOut);
|
||||
Info<< "scale output " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
Info<< "writing " << exportName << endl;
|
||||
surf.write(exportName);
|
||||
Info<< "writing " << exportName << nl;
|
||||
surf.write(exportName, writeFileType);
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
|
||||
@ -45,11 +45,14 @@ Usage
|
||||
- \par -name \<name\>
|
||||
Specify an alternative surface name when writing.
|
||||
|
||||
- \par -scaleIn \<scale\>
|
||||
Specify a scaling factor when reading files.
|
||||
- \par -read-format \<type\>
|
||||
Specify input file format
|
||||
|
||||
- \par -scaleOut \<scale\>
|
||||
Specify a scaling factor when writing files.
|
||||
- \par -read-scale \<scale\>
|
||||
Scale factor when reading files.
|
||||
|
||||
- \par -write-scale \<scale\>
|
||||
Scale factor when writing files.
|
||||
|
||||
- \par -dict \<dictionary\>
|
||||
Use alternative dictionary for constant/coordinateSystems.
|
||||
@ -74,6 +77,18 @@ Note
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
static word getExtension(const fileName& name)
|
||||
{
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -95,35 +110,44 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
"name",
|
||||
"name",
|
||||
"Specify an alternative surface name when writing - "
|
||||
"default is 'default'"
|
||||
"The surface name when writing (default is 'default')"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scaleIn",
|
||||
"factor",
|
||||
"Geometry scaling factor on input - default is 1"
|
||||
"read-format",
|
||||
"type",
|
||||
"Input format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"scaleOut",
|
||||
"read-scale",
|
||||
"factor",
|
||||
"Geometry scaling factor on output - default is 1"
|
||||
"Input geometry scaling factor"
|
||||
);
|
||||
argList::addOption("dict", "file", "Use alternative coordinateSystems");
|
||||
argList::addOption
|
||||
(
|
||||
"write-scale",
|
||||
"factor",
|
||||
"Output geometry scaling factor"
|
||||
);
|
||||
|
||||
argList::addOptionCompat("read-scale", {"scaleIn", 1912});
|
||||
argList::addOptionCompat("write-scale", {"scaleOut", 1912});
|
||||
|
||||
argList::addOption("dict", "file", "Alternative coordinateSystems");
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"from",
|
||||
"coordinateSystem",
|
||||
"Specify a local coordinate system when reading files.",
|
||||
"system",
|
||||
"The source coordinate system, applied after '-read-scale'",
|
||||
true // advanced
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"to",
|
||||
"coordinateSystem",
|
||||
"Specify a local coordinate system when writing files.",
|
||||
"system",
|
||||
"The target coordinate system, applied before '-write-scale'",
|
||||
true // advanced
|
||||
);
|
||||
|
||||
@ -143,16 +167,25 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
const fileName importName = args[1];
|
||||
const word exportName = args.get<word>("name", "default");
|
||||
const fileName importName(args[1]);
|
||||
const word exportName(args.get<word>("name", "default"));
|
||||
|
||||
// check that reading is supported
|
||||
if (!MeshedSurface<face>::canRead(importName, true))
|
||||
const word readFileType
|
||||
(
|
||||
args.getOrDefault<word>("read-format", getExtension(importName))
|
||||
);
|
||||
|
||||
// Check that reading is supported
|
||||
if (!meshedSurface::canRead(readFileType, true))
|
||||
{
|
||||
return 1;
|
||||
FatalError
|
||||
<< "Unsupported file format(s)" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
scalar scaleFactor(0);
|
||||
|
||||
// The coordinate transformations (must be cartesian)
|
||||
autoPtr<coordSystem::cartesian> fromCsys;
|
||||
autoPtr<coordSystem::cartesian> toCsys;
|
||||
@ -175,7 +208,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< ioCsys.objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
@ -189,7 +222,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!csPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot find -from " << csName << nl
|
||||
<< "available coordinateSystems: "
|
||||
<< flatOutput(globalCoords.names()) << nl
|
||||
@ -206,7 +239,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!csPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Cannot find -to " << csName << nl
|
||||
<< "available coordinateSystems: "
|
||||
<< flatOutput(globalCoords.names()) << nl
|
||||
@ -219,28 +252,26 @@ int main(int argc, char *argv[])
|
||||
// Maybe fix this later
|
||||
if (fromCsys && toCsys)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
FatalError
|
||||
<< "Only allowed '-from' or '-to' option at the moment."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MeshedSurface<face> surf(importName);
|
||||
meshedSurface surf(importName, readFileType);
|
||||
|
||||
if (args.readIfPresent("read-scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleFactor << nl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
if (args.found("clean"))
|
||||
{
|
||||
surf.cleanup(true);
|
||||
}
|
||||
|
||||
|
||||
scalar scaleIn = 0;
|
||||
if (args.readIfPresent("scaleIn", scaleIn) && scaleIn > 0)
|
||||
{
|
||||
Info<< "scale input " << scaleIn << endl;
|
||||
surf.scalePoints(scaleIn);
|
||||
}
|
||||
|
||||
if (fromCsys)
|
||||
{
|
||||
Info<< "move points from coordinate system: "
|
||||
@ -257,11 +288,10 @@ int main(int argc, char *argv[])
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
scalar scaleOut = 0;
|
||||
if (args.readIfPresent("scaleOut", scaleOut) && scaleOut > 0)
|
||||
if (args.readIfPresent("write-scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
Info<< "scale output " << scaleOut << endl;
|
||||
surf.scalePoints(scaleOut);
|
||||
Info<< "scale output " << scaleFactor << nl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
|
||||
surfMesh smesh
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -62,6 +62,36 @@ Description
|
||||
using namespace Foam;
|
||||
using namespace Foam::coordinateRotations;
|
||||
|
||||
static word getExtension(const fileName& name)
|
||||
{
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
// Non-short-circuiting check to get all warnings
|
||||
static bool hasReadWriteTypes(const word& readType, const word& writeType)
|
||||
{
|
||||
volatile bool good = true;
|
||||
|
||||
if (!meshedSurface::canReadType(readType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
if (!meshedSurface::canWriteType(writeType, true))
|
||||
{
|
||||
good = false;
|
||||
}
|
||||
|
||||
return good;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -119,6 +149,19 @@ int main(int argc, char *argv[])
|
||||
"Scale by the specified amount - Eg, for uniform [mm] to [m] scaling "
|
||||
"use either '(0.001 0.001 0.001)' or simply '0.001'"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"read-format",
|
||||
"type",
|
||||
"Input format (default: use file extension)"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"write-format",
|
||||
"type",
|
||||
"Output format (default: use file extension)"
|
||||
);
|
||||
|
||||
argList args(argc, argv);
|
||||
|
||||
// Verify that an operation has been specified
|
||||
@ -151,13 +194,34 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
const fileName surfFileName = args[1];
|
||||
const fileName outFileName = args[2];
|
||||
const fileName importName(args[1]);
|
||||
const fileName exportName(args[2]);
|
||||
|
||||
Info<< "Reading surf from " << surfFileName << " ..." << nl
|
||||
<< "Writing surf to " << outFileName << " ..." << endl;
|
||||
const word readFileType
|
||||
(
|
||||
args.getOrDefault<word>("read-format", getExtension(importName))
|
||||
);
|
||||
|
||||
meshedSurface surf1(surfFileName);
|
||||
const word writeFileType
|
||||
(
|
||||
args.getOrDefault<word>("write-format", getExtension(exportName))
|
||||
);
|
||||
|
||||
|
||||
// Check that reading/writing is supported
|
||||
if (!hasReadWriteTypes(readFileType, writeFileType))
|
||||
{
|
||||
FatalError
|
||||
<< "Unsupported file format(s)" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
Info<< "Reading surf from " << importName << " ..." << nl
|
||||
<< "Writing surf to " << exportName << " ..." << endl;
|
||||
|
||||
|
||||
meshedSurface surf1(importName, readFileType);
|
||||
|
||||
pointField points(surf1.points());
|
||||
|
||||
@ -169,7 +233,7 @@ int main(int argc, char *argv[])
|
||||
points += v;
|
||||
}
|
||||
|
||||
vector origin;
|
||||
vector origin(Zero);
|
||||
const bool useOrigin = args.readIfPresent("origin", origin);
|
||||
if (useOrigin)
|
||||
{
|
||||
@ -240,7 +304,16 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
// readListIfPresent handles single or multiple values
|
||||
|
||||
if (scaling.size() == 1)
|
||||
if
|
||||
(
|
||||
scaling.size() == 1
|
||||
||
|
||||
(
|
||||
scaling.size() == 3
|
||||
&& equal(scaling[0], scaling[1])
|
||||
&& equal(scaling[0], scaling[2])
|
||||
)
|
||||
)
|
||||
{
|
||||
Info<< "Scaling points uniformly by " << scaling[0] << nl;
|
||||
points *= scaling[0];
|
||||
@ -248,9 +321,9 @@ int main(int argc, char *argv[])
|
||||
else if (scaling.size() == 3)
|
||||
{
|
||||
Info<< "Scaling points by ("
|
||||
<< scaling[0] << " "
|
||||
<< scaling[1] << " "
|
||||
<< scaling[2] << ")" << nl;
|
||||
<< scaling[0] << ' '
|
||||
<< scaling[1] << ' '
|
||||
<< scaling[2] << ')' << nl;
|
||||
|
||||
points.replace(vector::X, scaling[0]*points.component(vector::X));
|
||||
points.replace(vector::Y, scaling[1]*points.component(vector::Y));
|
||||
@ -272,7 +345,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
surf1.movePoints(points);
|
||||
surf1.write(outFileName);
|
||||
surf1.write(exportName, writeFileType);
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
|
||||
|
||||
@ -378,8 +378,10 @@ bool Foam::fileFormats::FIREMeshReader::readGeometry(const scalar scaleFactor)
|
||||
{
|
||||
IOstream::streamFormat fmt = IOstream::ASCII;
|
||||
|
||||
const word ext = geometryFile_.ext();
|
||||
const word ext(geometryFile_.ext());
|
||||
|
||||
bool supported = FIRECore::file3dExtensions.found(ext);
|
||||
|
||||
if (supported)
|
||||
{
|
||||
FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext];
|
||||
|
||||
@ -272,7 +272,7 @@ bool Foam::fileFormats::FIREMeshWriter::write(const fileName& meshName) const
|
||||
}
|
||||
else
|
||||
{
|
||||
const word ext = baseName.ext();
|
||||
const word ext(baseName.ext());
|
||||
|
||||
if (FIRECore::file3dExtensions.found(ext))
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -44,6 +44,8 @@ namespace Foam
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::wordHashSet Foam::edgeMesh::readTypes()
|
||||
{
|
||||
return wordHashSet(*fileExtensionConstructorTablePtr_);
|
||||
@ -56,26 +58,24 @@ Foam::wordHashSet Foam::edgeMesh::writeTypes()
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::edgeMesh::canReadType(const word& ext, bool verbose)
|
||||
bool Foam::edgeMesh::canReadType(const word& fileType, bool verbose)
|
||||
{
|
||||
return checkSupport
|
||||
(
|
||||
readTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::edgeMesh::canWriteType(const word& ext, bool verbose)
|
||||
bool Foam::edgeMesh::canWriteType(const word& fileType, bool verbose)
|
||||
{
|
||||
return checkSupport
|
||||
(
|
||||
writeTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
@ -84,7 +84,7 @@ bool Foam::edgeMesh::canWriteType(const word& ext, bool verbose)
|
||||
|
||||
bool Foam::edgeMesh::canRead(const fileName& name, bool verbose)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
@ -97,14 +97,15 @@ bool Foam::edgeMesh::canRead(const fileName& name, bool verbose)
|
||||
|
||||
void Foam::edgeMesh::calcPointEdges() const
|
||||
{
|
||||
if (pointEdgesPtr_.valid())
|
||||
if (pointEdgesPtr_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "pointEdges already calculated." << abort(FatalError);
|
||||
<< "pointEdges already calculated."
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
pointEdgesPtr_.reset(new labelListList(points_.size()));
|
||||
labelListList& pointEdges = pointEdgesPtr_();
|
||||
auto& pointEdges = *pointEdgesPtr_;
|
||||
|
||||
invertManyToMany(pointEdges.size(), edges_, pointEdges);
|
||||
}
|
||||
@ -116,12 +117,17 @@ void Foam::edgeMesh::clear()
|
||||
{
|
||||
points_.clear();
|
||||
edges_.clear();
|
||||
pointEdgesPtr_.clear();
|
||||
pointEdgesPtr_.reset(nullptr);
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::transfer(edgeMesh& mesh)
|
||||
{
|
||||
if (&mesh == this)
|
||||
{
|
||||
return; // Self-transfer is a no-op
|
||||
}
|
||||
|
||||
points_.transfer(mesh.points_);
|
||||
edges_.transfer(mesh.edges_);
|
||||
pointEdgesPtr_ = std::move(mesh.pointEdgesPtr_);
|
||||
@ -189,6 +195,7 @@ Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
|
||||
|
||||
currentRegion++;
|
||||
}
|
||||
|
||||
return currentRegion;
|
||||
}
|
||||
|
||||
@ -220,7 +227,7 @@ void Foam::edgeMesh::mergePoints(const scalar mergeDist)
|
||||
|
||||
if (hasMerged)
|
||||
{
|
||||
pointEdgesPtr_.clear(); // connectivity change
|
||||
pointEdgesPtr_.reset(nullptr); // connectivity change
|
||||
|
||||
points_.transfer(newPoints);
|
||||
|
||||
@ -281,13 +288,13 @@ void Foam::edgeMesh::mergeEdges()
|
||||
|
||||
if (nUniqEdges < edges_.size())
|
||||
{
|
||||
pointEdgesPtr_.clear(); // connectivity change
|
||||
pointEdgesPtr_.reset(nullptr); // connectivity change
|
||||
edges_.setSize(nUniqEdges); // truncate
|
||||
}
|
||||
|
||||
if (nUniqPoints < points_.size())
|
||||
{
|
||||
pointEdgesPtr_.clear(); // connectivity change
|
||||
pointEdgesPtr_.reset(nullptr); // connectivity change
|
||||
|
||||
// build a oldToNew point-map and rewrite the points.
|
||||
// We can do this simultaneously since the point order is unchanged
|
||||
@ -320,7 +327,6 @@ void Foam::edgeMesh::mergeEdges()
|
||||
e[1] = pointMap[e[1]];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -56,16 +56,12 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
// Forward Declarations
|
||||
class edgeMesh;
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
Istream& operator>>(Istream& is, edgeMesh& em);
|
||||
Ostream& operator<<(Ostream& os, const edgeMesh& em);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class edgeMesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -74,7 +70,7 @@ class edgeMesh
|
||||
:
|
||||
public fileFormats::edgeMeshFormatsCore
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Vertices of the edges
|
||||
pointField points_;
|
||||
@ -83,7 +79,7 @@ class edgeMesh
|
||||
edgeList edges_;
|
||||
|
||||
//- From point to edges
|
||||
mutable autoPtr<labelListList> pointEdgesPtr_;
|
||||
mutable unique_ptr<labelListList> pointEdgesPtr_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
@ -109,24 +105,27 @@ public:
|
||||
TypeName("edgeMesh");
|
||||
|
||||
|
||||
// Static
|
||||
// Static Member Functions
|
||||
|
||||
//- Summary of supported read file types.
|
||||
static wordHashSet readTypes();
|
||||
|
||||
//- Summary of supported write file types.
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we write this file format type?
|
||||
static bool canWriteType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& ext, bool verbose=false);
|
||||
|
||||
//- Can we write this file format type?
|
||||
static bool canWriteType(const word& ext, bool verbose=false);
|
||||
|
||||
static wordHashSet readTypes();
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
inline edgeMesh();
|
||||
|
||||
//- Copy construct
|
||||
@ -144,8 +143,8 @@ public:
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
edgeMesh(const fileName& name);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
edgeMesh(const fileName& name, const word& ext);
|
||||
//- Construct from file name with specified type
|
||||
edgeMesh(const fileName& name, const word& fileType);
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
@ -164,11 +163,11 @@ public:
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
//- Read construct from filename with given format
|
||||
static autoPtr<edgeMesh> New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
);
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
@ -194,8 +193,20 @@ public:
|
||||
(name, mesh)
|
||||
);
|
||||
|
||||
//- Write to file
|
||||
static void write(const fileName& name, const edgeMesh& mesh);
|
||||
//- Write to file (format implicit in the extension)
|
||||
static void write
|
||||
(
|
||||
const fileName& name,
|
||||
const edgeMesh& mesh
|
||||
);
|
||||
|
||||
//- Write to file, with given format
|
||||
static void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& fileType,
|
||||
const edgeMesh& mesh
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -207,7 +218,7 @@ public:
|
||||
// Read
|
||||
|
||||
//- Read from file. Chooses reader based on explicit extension
|
||||
bool read(const fileName& name, const word& ext);
|
||||
bool read(const fileName& name, const word& fileType);
|
||||
|
||||
//- Read from file. Chooses reader based on detected extension
|
||||
virtual bool read(const fileName& name);
|
||||
@ -255,6 +266,12 @@ public:
|
||||
write(name, *this);
|
||||
}
|
||||
|
||||
//- Generic write routine. Chooses writer based on extension.
|
||||
virtual void write(const fileName& name, const word& fileType) const
|
||||
{
|
||||
write(name, fileType, *this);
|
||||
}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
@ -269,7 +286,6 @@ public:
|
||||
|
||||
friend Ostream& operator<<(Ostream& os, const edgeMesh& em);
|
||||
friend Istream& operator>>(Istream& is, edgeMesh& em);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,9 +27,8 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "edgeMeshFormatsCore.H"
|
||||
|
||||
#include "Time.H"
|
||||
#include "Fstream.H"
|
||||
#include "ListOps.H"
|
||||
#include "edgeMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -44,7 +44,7 @@ Foam::string Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment
|
||||
const char comment
|
||||
)
|
||||
{
|
||||
Foam::string line;
|
||||
string line;
|
||||
do
|
||||
{
|
||||
is.getLine(line);
|
||||
@ -158,28 +158,27 @@ Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshFile
|
||||
bool Foam::fileFormats::edgeMeshFormatsCore::checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
const char* functionName
|
||||
)
|
||||
{
|
||||
if (available.found(ext))
|
||||
if (available.found(fileType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (verbose)
|
||||
{
|
||||
wordList known = available.sortedToc();
|
||||
Info<< "Unknown file type";
|
||||
|
||||
Info<<"Unknown file extension for " << functionName
|
||||
<< " : " << ext << nl
|
||||
<<"Valid types: (";
|
||||
// compact output:
|
||||
forAll(known, i)
|
||||
if (functionName)
|
||||
{
|
||||
Info<<" " << known[i];
|
||||
Info<< " for " << functionName;
|
||||
}
|
||||
Info<<" )" << endl;
|
||||
|
||||
Info<< " : " << fileType << nl
|
||||
<< "Valid types: " << flatOutput(available.sortedToc()) << nl
|
||||
<< nl;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -46,8 +47,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
|
||||
// Forward Declarations
|
||||
class ISstream;
|
||||
class Time;
|
||||
|
||||
@ -75,14 +75,16 @@ public:
|
||||
// Normally "eMesh" (edge-mesh)
|
||||
static word nativeExt;
|
||||
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Verbose checking of fileType in the list of available types
|
||||
static bool checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
const word& fileType,
|
||||
const bool verbose = false,
|
||||
const char* functionName = nullptr
|
||||
);
|
||||
|
||||
// //- Return the local file name (within time directory)
|
||||
@ -102,15 +104,13 @@ public:
|
||||
// static fileName findMeshFile(const Time&, const word& edgeName="");
|
||||
|
||||
|
||||
// Constructors
|
||||
// Generated Methods
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
edgeMeshFormatsCore() = default;
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~edgeMeshFormatsCore() = default;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,7 +27,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "NASedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
@ -37,7 +37,16 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read edgeMesh - .bdf (Bulk Data Format)
|
||||
// Read
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
NASedgeFormat,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
|
||||
// Read - .bdf (Bulk Data Format)
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
@ -46,7 +55,7 @@ addNamedToRunTimeSelectionTable
|
||||
bdf
|
||||
);
|
||||
|
||||
// read edgeMesh - .nas (Nastran Data Format)
|
||||
// Read .nas (Nastran Data Format)
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -84,8 +84,8 @@ protected:
|
||||
|
||||
static void writeCase
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const label nEdges
|
||||
);
|
||||
|
||||
@ -95,7 +95,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from file name
|
||||
STARCDedgeFormat(const fileName&);
|
||||
explicit STARCDedgeFormat(const fileName& filename);
|
||||
|
||||
|
||||
// Selectors
|
||||
@ -114,10 +114,10 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Write edge mesh
|
||||
static void write(const fileName&, const edgeMesh&);
|
||||
static void write(const fileName& name, const edgeMesh& mesh);
|
||||
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
virtual bool read(const fileName& name);
|
||||
|
||||
//- Write object
|
||||
virtual void write(const fileName& name) const
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,7 +27,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STARCDedgeFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
@ -37,23 +37,23 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read edgeMesh
|
||||
// Read
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
STARCDedgeFormat,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
|
||||
// write edgeMesh
|
||||
// Write
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
edgeMesh,
|
||||
STARCDedgeFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -110,7 +110,7 @@ inline const Foam::edgeList& Foam::edgeMesh::edges() const
|
||||
|
||||
inline const Foam::labelListList& Foam::edgeMesh::pointEdges() const
|
||||
{
|
||||
if (pointEdgesPtr_.empty())
|
||||
if (!pointEdgesPtr_)
|
||||
{
|
||||
calcPointEdges();
|
||||
}
|
||||
@ -124,7 +124,7 @@ inline void Foam::edgeMesh::operator=(const edgeMesh& rhs)
|
||||
{
|
||||
points_ = rhs.points_;
|
||||
edges_ = rhs.edges_;
|
||||
pointEdgesPtr_.clear();
|
||||
pointEdgesPtr_.reset(nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -35,21 +35,21 @@ License
|
||||
Foam::edgeMesh::edgeMesh
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
:
|
||||
points_(0),
|
||||
edges_(0),
|
||||
points_(),
|
||||
edges_(),
|
||||
pointEdgesPtr_(nullptr)
|
||||
{
|
||||
read(name, ext);
|
||||
read(name, fileType);
|
||||
}
|
||||
|
||||
|
||||
Foam::edgeMesh::edgeMesh(const fileName& name)
|
||||
:
|
||||
points_(0),
|
||||
edges_(0),
|
||||
points_(),
|
||||
edges_(),
|
||||
pointEdgesPtr_(nullptr)
|
||||
{
|
||||
read(name);
|
||||
@ -60,7 +60,7 @@ Foam::edgeMesh::edgeMesh(const fileName& name)
|
||||
|
||||
bool Foam::edgeMesh::read(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
fileName unzipName = name.lessExt();
|
||||
@ -71,42 +71,50 @@ bool Foam::edgeMesh::read(const fileName& name)
|
||||
}
|
||||
|
||||
|
||||
// Read from file in given format
|
||||
bool Foam::edgeMesh::read
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
{
|
||||
// read via selector mechanism
|
||||
transfer(New(name, ext)());
|
||||
// Read via selector mechanism
|
||||
transfer(*New(name, fileType));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& fileType,
|
||||
const edgeMesh& mesh
|
||||
)
|
||||
{
|
||||
DebugInFunction << "Writing to " << name << endl;
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(fileType);
|
||||
|
||||
if (!mfIter.found())
|
||||
{
|
||||
FatalErrorInLookup
|
||||
(
|
||||
"extension",
|
||||
fileType,
|
||||
*writefileExtensionMemberFunctionTablePtr_
|
||||
) << exit(FatalError);
|
||||
}
|
||||
|
||||
mfIter()(name, mesh);
|
||||
}
|
||||
|
||||
|
||||
void Foam::edgeMesh::write
|
||||
(
|
||||
const fileName& name,
|
||||
const edgeMesh& mesh
|
||||
)
|
||||
{
|
||||
DebugInFunction << "Writing to " << name << endl;
|
||||
|
||||
const word ext = name.ext();
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext);
|
||||
|
||||
if (!mfIter.found())
|
||||
{
|
||||
FatalErrorInLookup
|
||||
(
|
||||
"extension",
|
||||
ext,
|
||||
*writefileExtensionMemberFunctionTablePtr_
|
||||
) << exit(FatalError);
|
||||
}
|
||||
|
||||
mfIter()(name, mesh);
|
||||
write(name, name.ext(), mesh);
|
||||
}
|
||||
|
||||
|
||||
@ -133,7 +141,7 @@ Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
|
||||
{
|
||||
fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
|
||||
|
||||
em.pointEdgesPtr_.clear();
|
||||
em.pointEdgesPtr_.reset(nullptr);
|
||||
|
||||
is.check(FUNCTION_NAME);
|
||||
return is;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,18 +33,18 @@ License
|
||||
Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
{
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(ext);
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(fileType);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext
|
||||
<< "Unknown edge format " << fileType
|
||||
<< " for file " << name << nl << nl
|
||||
<< "Valid extensions :" << nl
|
||||
<< fileExtensionConstructorTablePtr_->sortedToc()
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput(fileExtensionConstructorTablePtr_->sortedToc())
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New
|
||||
|
||||
Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
|
||||
@ -95,10 +95,8 @@ Foam::label Foam::extendedEdgeMesh::convexStart_ = 0;
|
||||
|
||||
Foam::label Foam::extendedEdgeMesh::externalStart_ = 0;
|
||||
|
||||
Foam::label Foam::extendedEdgeMesh::nPointTypes = 4;
|
||||
|
||||
Foam::label Foam::extendedEdgeMesh::nEdgeTypes = 5;
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::wordHashSet Foam::extendedEdgeMesh::readTypes()
|
||||
{
|
||||
@ -112,26 +110,24 @@ Foam::wordHashSet Foam::extendedEdgeMesh::writeTypes()
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::extendedEdgeMesh::canReadType(const word& ext, bool verbose)
|
||||
bool Foam::extendedEdgeMesh::canReadType(const word& fileType, bool verbose)
|
||||
{
|
||||
return edgeMeshFormatsCore::checkSupport
|
||||
(
|
||||
readTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::extendedEdgeMesh::canWriteType(const word& ext, bool verbose)
|
||||
bool Foam::extendedEdgeMesh::canWriteType(const word& fileType, bool verbose)
|
||||
{
|
||||
return edgeMeshFormatsCore::checkSupport
|
||||
(
|
||||
writeTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
@ -140,7 +136,7 @@ bool Foam::extendedEdgeMesh::canWriteType(const word& ext, bool verbose)
|
||||
|
||||
bool Foam::extendedEdgeMesh::canRead(const fileName& name, bool verbose)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
@ -380,7 +376,7 @@ void Foam::extendedEdgeMesh::select
|
||||
|
||||
Foam::extendedEdgeMesh::extendedEdgeMesh()
|
||||
:
|
||||
edgeMesh(pointField(), edgeList()),
|
||||
edgeMesh(),
|
||||
concaveStart_(0),
|
||||
mixedStart_(0),
|
||||
nonFeatureStart_(0),
|
||||
@ -396,15 +392,15 @@ Foam::extendedEdgeMesh::extendedEdgeMesh()
|
||||
featurePointNormals_(0),
|
||||
featurePointEdges_(0),
|
||||
regionEdges_(0),
|
||||
pointTree_(),
|
||||
edgeTree_(),
|
||||
pointTree_(nullptr),
|
||||
edgeTree_(nullptr),
|
||||
edgeTreesByType_()
|
||||
{}
|
||||
|
||||
|
||||
Foam::extendedEdgeMesh::extendedEdgeMesh(class one::minus)
|
||||
:
|
||||
edgeMesh(pointField(), edgeList()),
|
||||
edgeMesh(),
|
||||
concaveStart_(-1),
|
||||
mixedStart_(-1),
|
||||
nonFeatureStart_(-1),
|
||||
@ -420,8 +416,8 @@ Foam::extendedEdgeMesh::extendedEdgeMesh(class one::minus)
|
||||
featurePointNormals_(0),
|
||||
featurePointEdges_(0),
|
||||
regionEdges_(0),
|
||||
pointTree_(),
|
||||
edgeTree_(),
|
||||
pointTree_(nullptr),
|
||||
edgeTree_(nullptr),
|
||||
edgeTreesByType_()
|
||||
{}
|
||||
|
||||
@ -444,8 +440,8 @@ Foam::extendedEdgeMesh::extendedEdgeMesh(const extendedEdgeMesh& fem)
|
||||
featurePointNormals_(fem.featurePointNormals()),
|
||||
featurePointEdges_(fem.featurePointEdges()),
|
||||
regionEdges_(fem.regionEdges()),
|
||||
pointTree_(),
|
||||
edgeTree_(),
|
||||
pointTree_(nullptr),
|
||||
edgeTree_(nullptr),
|
||||
edgeTreesByType_()
|
||||
{}
|
||||
|
||||
@ -600,8 +596,8 @@ Foam::extendedEdgeMesh::extendedEdgeMesh
|
||||
featurePointNormals_(featurePointNormals),
|
||||
featurePointEdges_(featurePointEdges),
|
||||
regionEdges_(regionEdges),
|
||||
pointTree_(),
|
||||
edgeTree_(),
|
||||
pointTree_(nullptr),
|
||||
edgeTree_(nullptr),
|
||||
edgeTreesByType_()
|
||||
{}
|
||||
|
||||
@ -609,12 +605,12 @@ Foam::extendedEdgeMesh::extendedEdgeMesh
|
||||
Foam::extendedEdgeMesh::extendedEdgeMesh
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
:
|
||||
extendedEdgeMesh()
|
||||
{
|
||||
read(name, ext);
|
||||
read(name, fileType);
|
||||
}
|
||||
|
||||
|
||||
@ -626,17 +622,11 @@ Foam::extendedEdgeMesh::extendedEdgeMesh(const fileName& name)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::extendedEdgeMesh::~extendedEdgeMesh()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::extendedEdgeMesh::read(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
fileName unzipName = name.lessExt();
|
||||
@ -647,15 +637,14 @@ bool Foam::extendedEdgeMesh::read(const fileName& name)
|
||||
}
|
||||
|
||||
|
||||
// Read from file in given format
|
||||
bool Foam::extendedEdgeMesh::read
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
{
|
||||
// read via selector mechanism
|
||||
transfer(New(name, ext)());
|
||||
// Read via selector mechanism
|
||||
transfer(*New(name, fileType));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -837,7 +826,7 @@ void Foam::extendedEdgeMesh::allNearestFeatureEdges
|
||||
const Foam::indexedOctree<Foam::treeDataPoint>&
|
||||
Foam::extendedEdgeMesh::pointTree() const
|
||||
{
|
||||
if (pointTree_.empty())
|
||||
if (!pointTree_)
|
||||
{
|
||||
Random rndGen(17301893);
|
||||
|
||||
@ -877,7 +866,7 @@ Foam::extendedEdgeMesh::pointTree() const
|
||||
const Foam::indexedOctree<Foam::treeDataEdge>&
|
||||
Foam::extendedEdgeMesh::edgeTree() const
|
||||
{
|
||||
if (edgeTree_.empty())
|
||||
if (!edgeTree_)
|
||||
{
|
||||
Random rndGen(17301893);
|
||||
|
||||
@ -919,10 +908,8 @@ Foam::extendedEdgeMesh::edgeTree() const
|
||||
const Foam::PtrList<Foam::indexedOctree<Foam::treeDataEdge>>&
|
||||
Foam::extendedEdgeMesh::edgeTreesByType() const
|
||||
{
|
||||
if (edgeTreesByType_.size() == 0)
|
||||
if (edgeTreesByType_.empty())
|
||||
{
|
||||
edgeTreesByType_.setSize(nEdgeTypes);
|
||||
|
||||
Random rndGen(872141);
|
||||
|
||||
// Slightly extended bb. Slightly off-centred just so on symmetric
|
||||
@ -954,6 +941,9 @@ Foam::extendedEdgeMesh::edgeTreesByType() const
|
||||
sliceEdges[4] =
|
||||
identity((edges().size() - multipleStart_), multipleStart_);
|
||||
|
||||
|
||||
edgeTreesByType_.resize(nEdgeTypes);
|
||||
|
||||
forAll(edgeTreesByType_, i)
|
||||
{
|
||||
edgeTreesByType_.set
|
||||
@ -983,6 +973,11 @@ Foam::extendedEdgeMesh::edgeTreesByType() const
|
||||
|
||||
void Foam::extendedEdgeMesh::transfer(extendedEdgeMesh& mesh)
|
||||
{
|
||||
if (&mesh == this)
|
||||
{
|
||||
return; // Self-transfer is a no-op
|
||||
}
|
||||
|
||||
edgeMesh::transfer(mesh);
|
||||
|
||||
concaveStart_ = mesh.concaveStart_;
|
||||
@ -1026,8 +1021,8 @@ void Foam::extendedEdgeMesh::clear()
|
||||
featurePointNormals_.clear();
|
||||
featurePointEdges_.clear();
|
||||
regionEdges_.clear();
|
||||
pointTree_.clear();
|
||||
edgeTree_.clear();
|
||||
pointTree_.reset(nullptr);
|
||||
edgeTree_.reset(nullptr);
|
||||
edgeTreesByType_.clear();
|
||||
}
|
||||
|
||||
@ -1296,8 +1291,8 @@ void Foam::extendedEdgeMesh::add(const extendedEdgeMesh& fem)
|
||||
|
||||
regionEdges_.transfer(newRegionEdges);
|
||||
|
||||
pointTree_.clear();
|
||||
edgeTree_.clear();
|
||||
pointTree_.reset(nullptr);
|
||||
edgeTree_.reset(nullptr);
|
||||
edgeTreesByType_.clear();
|
||||
}
|
||||
|
||||
@ -1407,8 +1402,8 @@ void Foam::extendedEdgeMesh::flipNormals()
|
||||
featurePointNormals_.transfer(newFeaturePointNormals);
|
||||
regionEdges_.transfer(newRegionEdges);
|
||||
|
||||
pointTree_.clear();
|
||||
edgeTree_.clear();
|
||||
pointTree_.reset(nullptr);
|
||||
edgeTree_.reset(nullptr);
|
||||
edgeTreesByType_.clear();
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -70,8 +70,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
// Forward Declarations
|
||||
class surfaceFeatures;
|
||||
class searchableSurface;
|
||||
class extendedEdgeMesh;
|
||||
@ -132,7 +131,7 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
// Static data
|
||||
// Static Data
|
||||
|
||||
//- Index of the start of the convex feature points - static as 0
|
||||
static label convexStart_;
|
||||
@ -141,7 +140,7 @@ protected:
|
||||
static label externalStart_;
|
||||
|
||||
|
||||
// Protected data
|
||||
// Protected Data
|
||||
|
||||
//- Index of the start of the concave feature points
|
||||
label concaveStart_;
|
||||
@ -194,10 +193,10 @@ protected:
|
||||
labelList regionEdges_;
|
||||
|
||||
//- Search tree for all feature points
|
||||
mutable autoPtr<indexedOctree<treeDataPoint>> pointTree_;
|
||||
mutable unique_ptr<indexedOctree<treeDataPoint>> pointTree_;
|
||||
|
||||
//- Search tree for all edges
|
||||
mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
|
||||
mutable unique_ptr<indexedOctree<treeDataEdge>> edgeTree_;
|
||||
|
||||
//- Individual search trees for each type of edge
|
||||
mutable PtrList<indexedOctree<treeDataEdge>> edgeTreesByType_;
|
||||
@ -247,43 +246,49 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
// Static data
|
||||
// Static Data
|
||||
|
||||
//- Number of possible point types (i.e. number of slices)
|
||||
static label nPointTypes;
|
||||
static constexpr label nPointTypes = 4;
|
||||
|
||||
//- Number of possible feature edge types (i.e. number of slices)
|
||||
static label nEdgeTypes;
|
||||
static constexpr label nEdgeTypes = 5;
|
||||
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Summary of supported read file types.
|
||||
static wordHashSet readTypes();
|
||||
|
||||
//- Summary of supported write file types.
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we write this file format type?
|
||||
static bool canWriteType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& ext, bool verbose=false);
|
||||
|
||||
//- Can we write this file format type?
|
||||
static bool canWriteType(const word& ext, bool verbose=false);
|
||||
|
||||
static wordHashSet readTypes();
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
extendedEdgeMesh();
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct
|
||||
explicit extendedEdgeMesh(const extendedEdgeMesh& fem);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
extendedEdgeMesh(const fileName&);
|
||||
explicit extendedEdgeMesh(const fileName& name);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
extendedEdgeMesh(const fileName&, const word& ext);
|
||||
//- Construct from file name with given format type
|
||||
extendedEdgeMesh(const fileName& name, const word& fileType);
|
||||
|
||||
//- Construct from Istream
|
||||
extendedEdgeMesh(Istream& is);
|
||||
explicit extendedEdgeMesh(Istream& is);
|
||||
|
||||
//- Copy construct from components
|
||||
extendedEdgeMesh(const pointField& points, const edgeList& edges);
|
||||
@ -348,11 +353,11 @@ public:
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
//- Select constructed from filename with given file format
|
||||
static autoPtr<extendedEdgeMesh> New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
);
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
@ -360,7 +365,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
~extendedEdgeMesh();
|
||||
~extendedEdgeMesh() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2013-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,7 +28,6 @@ License
|
||||
|
||||
#include "extendedEdgeMesh.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -41,18 +41,18 @@ namespace Foam
|
||||
Foam::autoPtr<Foam::extendedEdgeMesh> Foam::extendedEdgeMesh::New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
{
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(ext);
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(fileType);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext
|
||||
<< " for file " << name << nl << nl
|
||||
<< "Valid extensions :" << nl
|
||||
<< fileExtensionConstructorTablePtr_->sortedToc()
|
||||
<< "Unknown edge format " << fileType
|
||||
<< " for file " << name << nl
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput(fileExtensionConstructorTablePtr_->sortedToc())
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ Foam::autoPtr<Foam::extendedEdgeMesh> Foam::extendedEdgeMesh::New
|
||||
const fileName& name
|
||||
)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
|
||||
@ -179,12 +179,6 @@ Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::extendedFeatureEdgeMesh::~extendedFeatureEdgeMesh()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::extendedFeatureEdgeMesh::readData(Istream& is)
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -46,6 +47,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
class objectRegistry;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
@ -67,12 +69,12 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct (read) given an IOobject
|
||||
extendedFeatureEdgeMesh(const IOobject&);
|
||||
explicit extendedFeatureEdgeMesh(const IOobject& io);
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct with IOobject
|
||||
extendedFeatureEdgeMesh
|
||||
(
|
||||
const IOobject&,
|
||||
const IOobject& io,
|
||||
const extendedEdgeMesh&
|
||||
);
|
||||
|
||||
@ -91,7 +93,7 @@ public:
|
||||
//- Construct from PrimitivePatch
|
||||
extendedFeatureEdgeMesh
|
||||
(
|
||||
const IOobject&,
|
||||
const IOobject& io,
|
||||
const PrimitivePatch<face, List, pointField, point>& surf,
|
||||
const labelUList& featureEdges,
|
||||
const labelUList& regionFeatureEdges,
|
||||
@ -123,7 +125,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~extendedFeatureEdgeMesh();
|
||||
virtual ~extendedFeatureEdgeMesh() = default;
|
||||
|
||||
|
||||
// IO
|
||||
@ -144,7 +146,7 @@ public:
|
||||
}
|
||||
|
||||
//- Return complete path + object name if the file exists
|
||||
// either in the case/processor or case otherwise null
|
||||
//- either in the case/processor or case otherwise null
|
||||
virtual fileName filePath() const
|
||||
{
|
||||
return globalFilePath(type());
|
||||
|
||||
@ -256,7 +256,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
surfaceClosed_(-1),
|
||||
outsideVolType_(volumeType::UNKNOWN)
|
||||
{
|
||||
// Adjust to use supplied file name instead of objectPath/filePath
|
||||
// Read with supplied file name instead of objectPath/filePath
|
||||
if (dict.readIfPresent("file", fName_, keyType::LITERAL))
|
||||
{
|
||||
fName_ = triSurface::relativeFilePath
|
||||
@ -414,6 +414,9 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
{
|
||||
if (io.readOpt() != IOobject::NO_READ)
|
||||
{
|
||||
// Surface type (optional)
|
||||
const word surfType(dict.getOrDefault<word>("fileType", word::null));
|
||||
|
||||
// Scale factor (optional)
|
||||
const scalar scaleFactor(dict.getOrDefault<scalar>("scale", 0));
|
||||
|
||||
@ -446,6 +449,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
<< " from:" << actualFile << endl;
|
||||
}
|
||||
|
||||
|
||||
if (searchGlobal && Pstream::parRun())
|
||||
{
|
||||
// Check where surface was found
|
||||
@ -457,7 +461,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
// surface. Load on master only
|
||||
if (Pstream::master())
|
||||
{
|
||||
triSurface s2(actualFile, scaleFactor);
|
||||
triSurface s2(actualFile, surfType, scaleFactor);
|
||||
triSurface::transfer(s2);
|
||||
}
|
||||
Pstream::scatter(triSurface::patches());
|
||||
@ -470,7 +474,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
else
|
||||
{
|
||||
// Read on all processors
|
||||
triSurface s2(actualFile, scaleFactor);
|
||||
triSurface s2(actualFile, surfType, scaleFactor);
|
||||
triSurface::transfer(s2);
|
||||
if (debug)
|
||||
{
|
||||
@ -482,7 +486,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
else
|
||||
{
|
||||
// Read on all processors
|
||||
triSurface s2(actualFile, scaleFactor);
|
||||
triSurface s2(actualFile, surfType, scaleFactor);
|
||||
triSurface::transfer(s2);
|
||||
if (debug)
|
||||
{
|
||||
|
||||
@ -41,6 +41,7 @@ Description
|
||||
Property | Description | Required | Default
|
||||
type | triSurfaceMesh | selector |
|
||||
file | File name to locate the surface | no |
|
||||
fileType | The surface format (Eg, nastran) | no |
|
||||
scale | Scaling factor | no | 0
|
||||
minQuality | Quality criterion | no | -1
|
||||
\endtable
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -450,6 +450,7 @@ Foam::surfaceToCell::surfaceToCell
|
||||
new triSurface
|
||||
(
|
||||
surfName_,
|
||||
dict.getOrDefault<word>("fileType", word::null),
|
||||
dict.lookupOrDefault<scalar>("scale", -1)
|
||||
)
|
||||
),
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,7 +43,8 @@ Description
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
file | The surface "filename" | yes |
|
||||
scale | surface scaling factor | no | -1
|
||||
fileType | The surface format | no |
|
||||
scale | Surface scaling factor | no | -1
|
||||
nearDistance | Near distance to the surface | yes |
|
||||
curvature | surface curvature selection | yes |
|
||||
outsidePoints| Points outside of surface | yes |
|
||||
@ -68,8 +69,10 @@ SourceFiles
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
class triSurfaceSearch;
|
||||
|
||||
// Forward Declarations
|
||||
class triSurface;
|
||||
class triSurfaceSearch;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surfaceToCell Declaration
|
||||
@ -79,8 +82,7 @@ class surfaceToCell
|
||||
:
|
||||
public topoSetCellSource
|
||||
{
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Add usage string
|
||||
static addToUsageTable usage_;
|
||||
@ -217,7 +219,6 @@ public:
|
||||
const topoSetSource::setAction action,
|
||||
topoSet&
|
||||
) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -64,7 +64,7 @@ void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
|
||||
{
|
||||
cpuTime timer;
|
||||
|
||||
triSurface surf(surfName_, scale_);
|
||||
triSurface surf(surfName_, surfType_, scale_);
|
||||
|
||||
if (verbose_)
|
||||
{
|
||||
@ -137,7 +137,8 @@ Foam::surfaceToPoint::surfaceToPoint
|
||||
:
|
||||
topoSetPointSource(mesh),
|
||||
surfName_(surfName),
|
||||
scale_(1.0),
|
||||
surfType_(),
|
||||
scale_(-1),
|
||||
nearDist_(nearDist),
|
||||
includeInside_(includeInside),
|
||||
includeOutside_(includeOutside)
|
||||
@ -154,6 +155,7 @@ Foam::surfaceToPoint::surfaceToPoint
|
||||
:
|
||||
topoSetPointSource(mesh),
|
||||
surfName_(dict.get<fileName>("file").expand()),
|
||||
surfType_(dict.getOrDefault<word>("fileType", word::null)),
|
||||
scale_(dict.lookupOrDefault<scalar>("scale", -1)),
|
||||
nearDist_(dict.get<scalar>("nearDistance")),
|
||||
includeInside_(dict.get<bool>("includeInside")),
|
||||
@ -171,7 +173,8 @@ Foam::surfaceToPoint::surfaceToPoint
|
||||
:
|
||||
topoSetPointSource(mesh),
|
||||
surfName_(checkIs(is)),
|
||||
scale_(1.0),
|
||||
surfType_(),
|
||||
scale_(-1),
|
||||
nearDist_(readScalar(checkIs(is))),
|
||||
includeInside_(readBool(checkIs(is))),
|
||||
includeOutside_(readBool(checkIs(is)))
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -40,7 +40,8 @@ Description
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
file | The surface "filename" | yes |
|
||||
scale | surface scaling factor | no | -1
|
||||
fileType | The surface format | no |
|
||||
scale | Surface scaling factor | no | -1
|
||||
nearDistance | Near distance to the surface | yes |
|
||||
includeInside | Include inside cells (bool) | yes |
|
||||
includeOutside | Include outside cells (bool) | yes |
|
||||
@ -61,9 +62,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class triSurfaceSearch;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surfaceToPoint Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -72,8 +70,7 @@ class surfaceToPoint
|
||||
:
|
||||
public topoSetPointSource
|
||||
{
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Add usage string
|
||||
static addToUsageTable usage_;
|
||||
@ -81,7 +78,10 @@ class surfaceToPoint
|
||||
//- Name of surface file
|
||||
const fileName surfName_;
|
||||
|
||||
//- Optional scaling for surface
|
||||
//- Surface file type (optional)
|
||||
const word surfType_;
|
||||
|
||||
//- Surface scaling factor (optional)
|
||||
const scalar scale_;
|
||||
|
||||
//- If > 0 : include points with distance to surface less than nearDist.
|
||||
|
||||
@ -87,6 +87,9 @@ Usage
|
||||
patches | Limit to named surface regions (wordRes) | no |
|
||||
source | cells/insideCells/boundaryFaces | yes |
|
||||
keepIds | pass through id numbering | no | false
|
||||
file | Alternative file name | no |
|
||||
fileType | The surface format | no | (extension)
|
||||
scale | Surface scaling factor | no | 0
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
|
||||
@ -39,7 +39,7 @@ License
|
||||
#include "faceTraits.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes()
|
||||
@ -47,6 +47,7 @@ Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes()
|
||||
return wordHashSet(*fileExtensionConstructorTablePtr_);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::wordHashSet Foam::MeshedSurface<Face>::writeTypes()
|
||||
{
|
||||
@ -54,19 +55,17 @@ Foam::wordHashSet Foam::MeshedSurface<Face>::writeTypes()
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::MeshedSurface<Face>::canReadType
|
||||
(
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
readTypes() | FriendType::readTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
@ -76,14 +75,14 @@ bool Foam::MeshedSurface<Face>::canReadType
|
||||
template<class Face>
|
||||
bool Foam::MeshedSurface<Face>::canWriteType
|
||||
(
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
writeTypes() | ProxyType::writeTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
@ -97,7 +96,7 @@ bool Foam::MeshedSurface<Face>::canRead
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
@ -123,36 +122,53 @@ template<class Face>
|
||||
void Foam::MeshedSurface<Face>::write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const MeshedSurface<Face>& surf,
|
||||
IOstreamOption streamOpt,
|
||||
const dictionary& options
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
if (fileType.empty())
|
||||
{
|
||||
InfoInFunction << "Writing to " << name << endl;
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext);
|
||||
write(name, ext, surf, streamOpt, options);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DebugInFunction << "Writing to " << name << nl;
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(fileType);
|
||||
|
||||
if (!mfIter.found())
|
||||
{
|
||||
// No direct writer, delegate to proxy if possible
|
||||
const wordHashSet& delegate = ProxyType::writeTypes();
|
||||
// Delegate to proxy if possible
|
||||
const wordHashSet delegate(ProxyType::writeTypes());
|
||||
|
||||
if (delegate.found(ext))
|
||||
{
|
||||
MeshedSurfaceProxy<Face>(surf).write(name, ext, streamOpt, options);
|
||||
}
|
||||
else
|
||||
if (!delegate.found(fileType))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext << nl << nl
|
||||
<< "Unknown write format " << fileType << nl << nl
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput((delegate | writeTypes()).sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
MeshedSurfaceProxy<Face>(surf).write
|
||||
(
|
||||
name, fileType, streamOpt, options
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -396,12 +412,12 @@ template<class Face>
|
||||
Foam::MeshedSurface<Face>::MeshedSurface
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
:
|
||||
MeshedSurface<Face>()
|
||||
{
|
||||
read(name, ext);
|
||||
read(name, fileType);
|
||||
}
|
||||
|
||||
|
||||
@ -481,11 +497,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
|
||||
fileFormats::surfaceFormatsCore::checkFile(io, dict, isGlobal)
|
||||
);
|
||||
|
||||
// TBD:
|
||||
// word fExt(dict.getOrDefault<word>("surfaceType", fName.ext()));
|
||||
// read(fName, fExt);
|
||||
|
||||
this->read(fName, fName.ext());
|
||||
this->read(fName, dict.getOrDefault<word>("fileType", word::null));
|
||||
|
||||
this->scalePoints(dict.getOrDefault<scalar>("scale", 0));
|
||||
}
|
||||
@ -1331,18 +1343,34 @@ bool Foam::MeshedSurface<Face>::read(const fileName& name)
|
||||
}
|
||||
|
||||
|
||||
// Read from file in given format
|
||||
template<class Face>
|
||||
bool Foam::MeshedSurface<Face>::read
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
{
|
||||
if (fileType.empty())
|
||||
{
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return read(name, ext);
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
// read via selector mechanism
|
||||
transfer(New(name, ext)());
|
||||
// Read via selector mechanism
|
||||
transfer(*(New(name, fileType)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -199,21 +199,21 @@ public:
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& ext, bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWriteType(const word& ext, bool verbose=false);
|
||||
|
||||
//- Known readable file-types
|
||||
//- Known readable file-types, without friends or proxies
|
||||
static wordHashSet readTypes();
|
||||
|
||||
//- Known writable file-types
|
||||
//- Known writable file-types, without friends or proxies
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
//- Can we read this file format? Also checks friend types.
|
||||
static bool canReadType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we write this file format? Also checks proxy types.
|
||||
static bool canWriteType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, bool verbose=false);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -282,8 +282,9 @@ public:
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
explicit MeshedSurface(const fileName& name);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
explicit MeshedSurface(const fileName& name, const word& ext);
|
||||
//- Construct from file name and given file type
|
||||
// If the format type is "", uses the file extension.
|
||||
explicit MeshedSurface(const fileName& name, const word& fileType);
|
||||
|
||||
//- Construct from Istream
|
||||
explicit MeshedSurface(Istream& is);
|
||||
@ -295,8 +296,11 @@ public:
|
||||
MeshedSurface(const Time& runTime, const word& surfName);
|
||||
|
||||
//- Read construct using IO to find the file location.
|
||||
// Dictionary may contain optional 'file' entry, and an
|
||||
// optional 'scale' entry (eg, 0.001: mm -> m)
|
||||
// Dictionary may contain the following entries:
|
||||
// - \c file = alternative file name (default is dictionary name)
|
||||
// - \c fileType = file format (default is from file extension)
|
||||
// - \c scale (eg, 0.001: mm to m)
|
||||
// .
|
||||
MeshedSurface
|
||||
(
|
||||
const IOobject& io,
|
||||
@ -321,14 +325,15 @@ public:
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
//- Read construct from filename with given file type
|
||||
static autoPtr<MeshedSurface> New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType,
|
||||
bool mandatory = true
|
||||
);
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
//- Read construct from filename (file type implicit from extension)
|
||||
static autoPtr<MeshedSurface> New(const fileName& name);
|
||||
|
||||
|
||||
@ -366,7 +371,7 @@ public:
|
||||
static void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const MeshedSurface<Face>& surf,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const dictionary& options = dictionary::null
|
||||
@ -574,7 +579,7 @@ public:
|
||||
// Read
|
||||
|
||||
//- Read from file. Chooses reader based on explicit extension
|
||||
bool read(const fileName& name, const word& ext);
|
||||
bool read(const fileName& name, const word& fileType);
|
||||
|
||||
//- Read from file. Chooses reader based on detected extension
|
||||
virtual bool read(const fileName& name);
|
||||
@ -595,10 +600,24 @@ public:
|
||||
write(name, *this, streamOpt, options);
|
||||
}
|
||||
|
||||
//- Generic write routine for given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
virtual void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& fileType,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const dictionary& options = dictionary::null
|
||||
) const
|
||||
{
|
||||
write(name, fileType, *this, streamOpt, options);
|
||||
}
|
||||
|
||||
|
||||
//- Write to database
|
||||
void write
|
||||
(
|
||||
const Time& t,
|
||||
const Time& runTime,
|
||||
const word& surfName = word::null
|
||||
) const;
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -34,39 +34,46 @@ License
|
||||
|
||||
template<class Face>
|
||||
Foam::autoPtr<Foam::MeshedSurface<Face>>
|
||||
Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext)
|
||||
Foam::MeshedSurface<Face>::New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& fileType,
|
||||
bool mandatory
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
DebugInFunction
|
||||
<< "Construct MeshedSurface (" << fileType << ")\n";
|
||||
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(fileType);
|
||||
|
||||
if (cstrIter.found())
|
||||
{
|
||||
InfoInFunction << "Constructing MeshedSurface" << endl;
|
||||
return autoPtr<MeshedSurface<Face>>(cstrIter()(name));
|
||||
}
|
||||
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(ext);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
// No direct reader, delegate to friend if possible
|
||||
const wordHashSet& delegate = FriendType::readTypes();
|
||||
// Delegate to friend if possible
|
||||
const wordHashSet delegate(FriendType::readTypes());
|
||||
|
||||
if (delegate.found(ext))
|
||||
if (delegate.found(fileType))
|
||||
{
|
||||
// Create indirectly
|
||||
// OK, can create indirectly
|
||||
auto surf = autoPtr<MeshedSurface<Face>>::New();
|
||||
surf().transfer(*(FriendType::New(name, ext)));
|
||||
surf->transfer(*FriendType::New(name, fileType));
|
||||
|
||||
return surf;
|
||||
}
|
||||
else
|
||||
else if (mandatory)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext << nl << nl
|
||||
<< "Unknown surface format " << fileType << nl << nl
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput((delegate | readTypes()).sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
return autoPtr<MeshedSurface<Face>>(cstrIter()(name));
|
||||
// Failed, but was optional
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +81,7 @@ template<class Face>
|
||||
Foam::autoPtr<Foam::MeshedSurface<Face>>
|
||||
Foam::MeshedSurface<Face>::New(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
|
||||
@ -27,7 +27,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "MeshedSurfaceProxy.H"
|
||||
|
||||
#include "Time.H"
|
||||
#include "ListOps.H"
|
||||
#include "surfMesh.H"
|
||||
@ -46,13 +45,16 @@ Foam::wordHashSet Foam::MeshedSurfaceProxy<Face>::writeTypes()
|
||||
template<class Face>
|
||||
bool Foam::MeshedSurfaceProxy<Face>::canWriteType
|
||||
(
|
||||
const word& ext,
|
||||
const bool verbose
|
||||
const word& fileType,
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
writeTypes(), ext, verbose, "writing"
|
||||
writeTypes(),
|
||||
fileType,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
}
|
||||
|
||||
@ -74,23 +76,39 @@ template<class Face>
|
||||
void Foam::MeshedSurfaceProxy<Face>::write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const MeshedSurfaceProxy& surf,
|
||||
IOstreamOption streamOpt,
|
||||
const dictionary& options
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
if (fileType.empty())
|
||||
{
|
||||
InfoInFunction << "Writing to " << name << endl;
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext);
|
||||
write(name, ext, surf, streamOpt, options);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DebugInFunction << "Writing to " << name << nl;
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(fileType);
|
||||
|
||||
if (!mfIter.found())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext << nl << nl
|
||||
<< "Unknown file type " << fileType << nl << nl
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput(writeTypes().sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
@ -110,10 +128,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
|
||||
// the surface name to be used
|
||||
const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
InfoInFunction << "Writing to " << name << endl;
|
||||
}
|
||||
DebugInFunction << "Writing to " << name << endl;
|
||||
|
||||
|
||||
// The local location
|
||||
|
||||
@ -94,7 +94,7 @@ public:
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
//- Can this file format type be written via MeshedSurfaceProxy?
|
||||
static bool canWriteType(const word& ext, const bool verbose=false);
|
||||
static bool canWriteType(const word& fileType, bool verbose=false);
|
||||
|
||||
|
||||
// Constructors
|
||||
@ -139,11 +139,12 @@ public:
|
||||
const dictionary& options = dictionary::null
|
||||
);
|
||||
|
||||
//- Write to file, selected based on given extension
|
||||
//- Write to file with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
static void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const MeshedSurfaceProxy& surf,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const dictionary& options = dictionary::null
|
||||
@ -198,7 +199,7 @@ public:
|
||||
|
||||
// Write
|
||||
|
||||
//- Generic write routine. Chooses writer based on its extension.
|
||||
//- Write to file, choosing writer based on the file extension.
|
||||
virtual void write
|
||||
(
|
||||
const fileName& name,
|
||||
@ -209,16 +210,17 @@ public:
|
||||
write(name, *this, streamOpt, options);
|
||||
}
|
||||
|
||||
//- Generic write routine. Chooses writer based on extension.
|
||||
//- Write to file with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
virtual void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const dictionary& options = dictionary::null
|
||||
) const
|
||||
{
|
||||
write(name, ext, *this, streamOpt, options);
|
||||
write(name, fileType, *this, streamOpt, options);
|
||||
}
|
||||
|
||||
//- Write to database
|
||||
|
||||
@ -54,14 +54,14 @@ Foam::wordHashSet Foam::UnsortedMeshedSurface<Face>::writeTypes()
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::canReadType
|
||||
(
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
readTypes() | MeshReference::readTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
@ -71,14 +71,14 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::canWriteType
|
||||
(
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
writeTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
@ -92,7 +92,7 @@ bool Foam::UnsortedMeshedSurface<Face>::canRead
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
@ -118,36 +118,53 @@ template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const UnsortedMeshedSurface<Face>& surf,
|
||||
IOstreamOption streamOpt,
|
||||
const dictionary& options
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
if (fileType.empty())
|
||||
{
|
||||
InfoInFunction << "Writing to " << name << endl;
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext);
|
||||
write(name, ext, surf, streamOpt, options);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DebugInFunction << "Writing to " << name << nl;
|
||||
|
||||
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(fileType);
|
||||
|
||||
if (!mfIter.found())
|
||||
{
|
||||
// No direct writer, delegate to proxy if possible
|
||||
const wordHashSet& delegate = ProxyType::writeTypes();
|
||||
// Delegate to proxy if possible
|
||||
const wordHashSet delegate(ProxyType::writeTypes());
|
||||
|
||||
if (delegate.found(ext))
|
||||
{
|
||||
MeshedSurfaceProxy<Face>(surf).write(name, ext, streamOpt, options);
|
||||
}
|
||||
else
|
||||
if (!delegate.found(fileType))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext << nl << nl
|
||||
<< "Unknown write format " << fileType << nl << nl
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput((delegate | writeTypes()).sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
MeshedSurfaceProxy<Face>(surf).write
|
||||
(
|
||||
name, fileType, streamOpt, options
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -309,11 +326,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
fileFormats::surfaceFormatsCore::checkFile(io, dict, isGlobal)
|
||||
);
|
||||
|
||||
// TBD:
|
||||
// word fExt(dict.getOrDefault<word>("surfaceType", fName.ext()));
|
||||
// read(fName, fExt);
|
||||
|
||||
this->read(fName, fName.ext());
|
||||
this->read(fName, dict.getOrDefault<word>("fileType", word::null));
|
||||
|
||||
this->scalePoints(dict.getOrDefault<scalar>("scale", 0));
|
||||
}
|
||||
@ -452,26 +465,25 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::Istream& Foam::UnsortedMeshedSurface<Face>::read(Istream& is)
|
||||
bool Foam::UnsortedMeshedSurface<Face>::readIstream(Istream& is)
|
||||
{
|
||||
is >> this->storedZoneIds()
|
||||
>> this->storedPoints()
|
||||
>> this->storedFaces();
|
||||
|
||||
is.check(FUNCTION_NAME);
|
||||
return is;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::Ostream& Foam::UnsortedMeshedSurface<Face>::write(Ostream& os) const
|
||||
void Foam::UnsortedMeshedSurface<Face>::writeOstream(Ostream& os) const
|
||||
{
|
||||
os << this->zoneIds()
|
||||
<< this->points()
|
||||
<< this->surfFaces();
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@ -734,7 +746,6 @@ Foam::UnsortedMeshedSurface<Face>::releaseZoneIds()
|
||||
}
|
||||
|
||||
|
||||
// Read from file, determine format from extension
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::read(const fileName& name)
|
||||
{
|
||||
@ -749,18 +760,34 @@ bool Foam::UnsortedMeshedSurface<Face>::read(const fileName& name)
|
||||
}
|
||||
|
||||
|
||||
// Read from file in given format
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::read
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType
|
||||
)
|
||||
{
|
||||
if (fileType.empty())
|
||||
{
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return read(name, ext);
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
// read via use selector mechanism
|
||||
transfer(New(name, ext)());
|
||||
// Read via selector mechanism
|
||||
transfer(*New(name, fileType));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -784,6 +811,11 @@ void Foam::UnsortedMeshedSurface<Face>::operator=
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
if (&surf == this)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
this->storedPoints() = surf.points();
|
||||
@ -829,7 +861,8 @@ Foam::Istream& Foam::operator>>
|
||||
UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
return surf.read(is);
|
||||
surf.readIstream(is);
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@ -840,7 +873,8 @@ Foam::Ostream& Foam::operator<<
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
return surf.write(os);
|
||||
surf.writeOstream(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -120,10 +120,10 @@ private:
|
||||
void setSize(const label, const Face&) = delete;
|
||||
|
||||
//- Read/construct from Istream
|
||||
Istream& read(Istream&);
|
||||
bool readIstream(Istream& is);
|
||||
|
||||
//- Write to Ostream
|
||||
Ostream& write(Ostream&) const;
|
||||
void writeOstream(Ostream& os) const;
|
||||
|
||||
|
||||
//- Return a new surface using specified pointMap and faceMap
|
||||
@ -174,21 +174,21 @@ public:
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Can we read this file format type?
|
||||
static bool canReadType(const word& ext, bool verbose=false);
|
||||
//- Known readable file-types, without friends or proxies
|
||||
static wordHashSet readTypes();
|
||||
|
||||
//- Known writable file-types, without friends or proxies
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
//- Can we read this file format? Also checks friend types.
|
||||
static bool canReadType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we write this file format? Also checks friend types.
|
||||
static bool canWriteType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, bool verbose=false);
|
||||
|
||||
//- Can we write this file format type?
|
||||
static bool canWriteType(const word& ext, bool verbose=false);
|
||||
|
||||
//- Known readable file-types
|
||||
static wordHashSet readTypes();
|
||||
|
||||
//- Known writable file-types
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -220,8 +220,9 @@ public:
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
explicit UnsortedMeshedSurface(const fileName& name);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
UnsortedMeshedSurface(const fileName& name, const word& ext);
|
||||
//- Construct from file name with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
UnsortedMeshedSurface(const fileName& name, const word& fileType);
|
||||
|
||||
//- Construct from Istream
|
||||
explicit UnsortedMeshedSurface(Istream& is);
|
||||
@ -233,8 +234,11 @@ public:
|
||||
UnsortedMeshedSurface(const Time& runTime, const word& surfName);
|
||||
|
||||
//- Read construct using IO to find the file location.
|
||||
// Dictionary may contain optional 'file' entry, and an
|
||||
// optional 'scale' entry (eg, 0.001: mm -> m)
|
||||
// Dictionary may contain the following entries:
|
||||
// - \c file = alternative file name (default is dictionary name)
|
||||
// - \c fileType = file format (default is from file extension)
|
||||
// - \c scale (eg, 0.001: mm to m)
|
||||
// .
|
||||
UnsortedMeshedSurface
|
||||
(
|
||||
const IOobject& io,
|
||||
@ -259,14 +263,15 @@ public:
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
//- Read construct from filename with given file type
|
||||
static autoPtr<UnsortedMeshedSurface> New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType,
|
||||
bool mandatory = true
|
||||
);
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
//- Read construct from filename (implicit extension)
|
||||
static autoPtr<UnsortedMeshedSurface> New(const fileName& name);
|
||||
|
||||
|
||||
@ -300,11 +305,12 @@ public:
|
||||
const dictionary& options = dictionary::null
|
||||
);
|
||||
|
||||
//- Write to file, selected based on given extension
|
||||
//- Write to file with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
static void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const UnsortedMeshedSurface<Face>& surf,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const dictionary& options = dictionary::null
|
||||
@ -428,8 +434,9 @@ public:
|
||||
|
||||
// Read
|
||||
|
||||
//- Read from file. Chooses reader based on explicit extension
|
||||
bool read(const fileName& name, const word& ext);
|
||||
//- Read from file with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
bool read(const fileName& name, const word& fileType);
|
||||
|
||||
//- Read from file. Chooses reader based on detected extension
|
||||
virtual bool read(const fileName& name);
|
||||
@ -437,7 +444,7 @@ public:
|
||||
|
||||
// Write
|
||||
|
||||
//- Generic write routine. Chooses writer based on its extension.
|
||||
//- Write to file, choosing writer based on the file extension.
|
||||
virtual void write
|
||||
(
|
||||
const fileName& name,
|
||||
@ -448,6 +455,19 @@ public:
|
||||
write(name, *this, streamOpt, options);
|
||||
}
|
||||
|
||||
//- Write to file with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
virtual void write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& fileType,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const dictionary& options = dictionary::null
|
||||
) const
|
||||
{
|
||||
write(name, fileType, *this, streamOpt, options);
|
||||
}
|
||||
|
||||
//- Write to database
|
||||
void write
|
||||
(
|
||||
|
||||
@ -36,40 +36,43 @@ Foam::autoPtr<Foam::UnsortedMeshedSurface<Face>>
|
||||
Foam::UnsortedMeshedSurface<Face>::New
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext
|
||||
const word& fileType,
|
||||
bool mandatory
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
DebugInFunction
|
||||
<< "Construct UnsortedMeshedSurface (" << fileType << ")\n";
|
||||
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(fileType);
|
||||
|
||||
if (cstrIter.found())
|
||||
{
|
||||
InfoInFunction << "Constructing UnsortedMeshedSurface" << endl;
|
||||
return autoPtr<UnsortedMeshedSurface<Face>>(cstrIter()(name));
|
||||
}
|
||||
|
||||
auto cstrIter = fileExtensionConstructorTablePtr_->cfind(ext);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
// No direct reader, delegate to parent if possible
|
||||
const wordHashSet& delegate = MeshReference::readTypes();
|
||||
// Delegate to friend if possible
|
||||
const wordHashSet delegate(MeshReference::readTypes());
|
||||
|
||||
if (delegate.found(ext))
|
||||
if (delegate.found(fileType))
|
||||
{
|
||||
// Create indirectly
|
||||
// OK, can create indirectly
|
||||
auto surf = autoPtr<UnsortedMeshedSurface<Face>>::New();
|
||||
surf().transfer(*(MeshReference::New(name, ext)));
|
||||
surf->transfer(*(MeshReference::New(name, fileType)));
|
||||
|
||||
return surf;
|
||||
}
|
||||
else
|
||||
else if (mandatory)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown file extension " << ext << nl << nl
|
||||
<< "Unknown surface format " << fileType << nl << nl
|
||||
<< "Valid types:" << nl
|
||||
<< flatOutput((delegate | readTypes()).sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
return autoPtr<UnsortedMeshedSurface<Face>>(cstrIter()(name));
|
||||
// Failed, but was optional
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +80,7 @@ template<class Face>
|
||||
Foam::autoPtr<Foam::UnsortedMeshedSurface<Face>>
|
||||
Foam::UnsortedMeshedSurface<Face>::New(const fileName& name)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
|
||||
@ -28,7 +28,7 @@ Class
|
||||
Foam::fileFormats::NASsurfaceFormat
|
||||
|
||||
Description
|
||||
Nastran surface reader.
|
||||
Nastran surface reader/writer.
|
||||
|
||||
- Uses the Ansa "$ANSA_NAME" or the Hypermesh "$HMNAME COMP" extensions
|
||||
to obtain zone names.
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,7 +27,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "NASsurfaceFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
@ -38,7 +37,15 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read MeshedSurface - .bdf (Bulk Data Format) and nas (Nastran)
|
||||
// Read MeshedSurface - .bdf (Bulk Data Format) and nas (Nastran)
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
@ -56,6 +63,14 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
nas
|
||||
);
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
@ -73,6 +88,14 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
nas
|
||||
);
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
labelledTri,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
@ -91,7 +114,16 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
|
||||
|
||||
// write MeshedSurfaceProxy
|
||||
// Write MeshedSurfaceProxy
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
NASsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
@ -102,6 +134,15 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
nas
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
NASsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
NASsurfaceFormat,
|
||||
@ -111,6 +152,15 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
nas
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
NASsurfaceFormat,
|
||||
labelledTri,
|
||||
write,
|
||||
fileExtension,
|
||||
nastran
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
NASsurfaceFormat,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2016 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,7 +27,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STARCDsurfaceFormat.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
@ -38,14 +37,14 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// read MeshedSurface
|
||||
// Read MeshedSurface
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
@ -53,7 +52,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
STARCDsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
@ -61,10 +60,10 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
STARCDsurfaceFormat,
|
||||
labelledTri,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
|
||||
// write MeshedSurfaceProxy
|
||||
// Write MeshedSurfaceProxy
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurfaceProxy,
|
||||
@ -72,7 +71,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
@ -81,7 +80,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
@ -90,7 +89,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
labelledTri,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
starcd
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@ -29,7 +29,6 @@ License
|
||||
#include "surfaceFormatsCore.H"
|
||||
#include "Time.H"
|
||||
#include "ListOps.H"
|
||||
#include "Fstream.H"
|
||||
#include "surfMesh.H"
|
||||
#include "stringListOps.H"
|
||||
|
||||
@ -326,21 +325,27 @@ Foam::fileName Foam::fileFormats::surfaceFormatsCore::checkFile
|
||||
bool Foam::fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
const char* functionName
|
||||
)
|
||||
{
|
||||
if (available.found(ext))
|
||||
if (available.found(fileType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (verbose)
|
||||
{
|
||||
Info<<"Unknown file extension for " << functionName
|
||||
<< " : " << ext << nl
|
||||
Info<< "Unknown file type";
|
||||
|
||||
if (functionName)
|
||||
{
|
||||
Info<< " for " << functionName;
|
||||
}
|
||||
|
||||
Info<< " : " << fileType << nl
|
||||
<< "Valid types: " << flatOutput(available.sortedToc()) << nl
|
||||
<< endl;
|
||||
<< nl;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@ -143,13 +143,13 @@ public:
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Helper function when checking if a file extension is supported.
|
||||
//- Verbose checking of fileType in the list of available types
|
||||
static bool checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
const word& fileType,
|
||||
const bool verbose = false,
|
||||
const char* functionName = nullptr
|
||||
);
|
||||
|
||||
//- Use IOobject information to resolve file to load from,
|
||||
|
||||
@ -499,13 +499,13 @@ Foam::triSurface::triSurface
|
||||
Foam::triSurface::triSurface
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const scalar scaleFactor
|
||||
)
|
||||
:
|
||||
triSurface()
|
||||
{
|
||||
read(name, ext);
|
||||
read(name, fileType);
|
||||
scalePoints(scaleFactor);
|
||||
setDefaultPatches();
|
||||
}
|
||||
|
||||
@ -91,12 +91,8 @@ class triSurface
|
||||
// (face ordering nFaces/startFace only used during reading, writing)
|
||||
geometricSurfacePatchList patches_;
|
||||
|
||||
static wordHashSet readTypes_;
|
||||
|
||||
static wordHashSet writeTypes_;
|
||||
|
||||
|
||||
// Demand driven
|
||||
// Demand Driven
|
||||
|
||||
//- Edge-face addressing (sorted)
|
||||
mutable unique_ptr<labelListList> sortedEdgeFacesPtr_;
|
||||
@ -136,11 +132,12 @@ class triSurface
|
||||
//- Read in STL format
|
||||
bool readSTL(const fileName& filename, bool forceBinary=false);
|
||||
|
||||
//- Generic read routine. Chooses reader based on extension.
|
||||
//- Generic read routine for given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
bool read
|
||||
(
|
||||
const fileName& filename,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const bool check = true
|
||||
);
|
||||
|
||||
@ -154,17 +151,8 @@ class triSurface
|
||||
//- Write GTS (Gnu Tri Surface library) format.
|
||||
void writeGTS(const fileName& filename, const bool sort) const;
|
||||
|
||||
//- Generic write routine. Chooses writer based on extension.
|
||||
// The sort option may not have an effect.
|
||||
void write
|
||||
(
|
||||
const fileName& filename,
|
||||
const word& ext,
|
||||
const bool sort
|
||||
) const;
|
||||
|
||||
|
||||
// Static private functions
|
||||
// Static Private Functions
|
||||
|
||||
//- Convert faces to labelledTri. All get same region.
|
||||
static List<labelledTri> convertToTri
|
||||
@ -240,20 +228,20 @@ public:
|
||||
//- Name of triSurface directory to use.
|
||||
static fileName triSurfInstance(const Time&);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, const bool verbose=false);
|
||||
//- Known readable file-types, including via friends or proxies
|
||||
static wordHashSet readTypes();
|
||||
|
||||
//- Known writable file-types, including via friends or proxies
|
||||
static wordHashSet writeTypes();
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& ext, const bool verbose=false);
|
||||
static bool canReadType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWriteType(const word& ext, const bool verbose=false);
|
||||
static bool canWriteType(const word& fileType, bool verbose=false);
|
||||
|
||||
//- Known readable file-types
|
||||
static const wordHashSet& readTypes();
|
||||
|
||||
//- Known writable file-types
|
||||
static const wordHashSet& writeTypes();
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, bool verbose=false);
|
||||
|
||||
|
||||
// IO helpers
|
||||
@ -356,11 +344,12 @@ public:
|
||||
const scalar scaleFactor = -1
|
||||
);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
//- Construct from file name with given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
triSurface
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const scalar scaleFactor = -1
|
||||
);
|
||||
|
||||
@ -371,8 +360,11 @@ public:
|
||||
explicit triSurface(const Time& d);
|
||||
|
||||
//- Read construct using IO to find the file location.
|
||||
// Dictionary may contain optional 'file' entry, and an
|
||||
// optional 'scale' entry (eg, 0.001: mm -> m)
|
||||
// Dictionary may contain the following entries:
|
||||
// - \c file = alternative file name (default is dictionary name)
|
||||
// - \c fileType = file format (default is from file extension)
|
||||
// - \c scale (eg, 0.001: mm to m)
|
||||
// .
|
||||
triSurface
|
||||
(
|
||||
const IOobject& io,
|
||||
@ -574,9 +566,20 @@ public:
|
||||
//- Write to Ostream in simple FOAM format
|
||||
void write(Ostream& os) const;
|
||||
|
||||
//- Generic write routine. Chooses writer based on extension.
|
||||
//- Generic write routine (uses extension to determine type).
|
||||
// The sort option may not have an effect.
|
||||
void write(const fileName&, const bool sortByRegion = false) const;
|
||||
|
||||
//- Generic write routine for given format type.
|
||||
// If the format type is "", uses the file extension.
|
||||
// The sort option may not have an effect.
|
||||
void write
|
||||
(
|
||||
const fileName& filename,
|
||||
const word& fileType,
|
||||
const bool sortByRegion = false
|
||||
) const;
|
||||
|
||||
//- Write to database
|
||||
void write(const Time& d) const;
|
||||
|
||||
@ -584,7 +587,7 @@ public:
|
||||
void writeStats(Ostream& os) const;
|
||||
|
||||
|
||||
// Member operators
|
||||
// Member Operators
|
||||
|
||||
//- Copy assignment
|
||||
void operator=(const triSurface& surf);
|
||||
|
||||
@ -35,68 +35,70 @@ License
|
||||
#include "MeshedSurfaceProxy.H"
|
||||
#include "MeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::wordHashSet Foam::triSurface::readTypes_;
|
||||
Foam::wordHashSet Foam::triSurface::writeTypes_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
const Foam::wordHashSet& Foam::triSurface::readTypes()
|
||||
Foam::wordHashSet Foam::triSurface::readTypes()
|
||||
{
|
||||
// Stop-gap measure until reading is handled more generally
|
||||
if (readTypes_.empty())
|
||||
{
|
||||
readTypes_ = { "ftr", "stl", "stlb" };
|
||||
readTypes_ += UnsortedMeshedSurface<labelledTri>::readTypes();
|
||||
readTypes_ += MeshedSurface<labelledTri>::readTypes();
|
||||
}
|
||||
wordHashSet known
|
||||
(
|
||||
UnsortedMeshedSurface<labelledTri>::readTypes()
|
||||
| MeshedSurface<labelledTri>::readTypes()
|
||||
);
|
||||
|
||||
return readTypes_;
|
||||
// Additional hard-coded entry points, but do not need
|
||||
// {"stl", "stlb"}
|
||||
// since they are shadowed by *MeshedSurface
|
||||
|
||||
known.insert("ftr");
|
||||
|
||||
return known;
|
||||
}
|
||||
|
||||
|
||||
const Foam::wordHashSet& Foam::triSurface::writeTypes()
|
||||
Foam::wordHashSet Foam::triSurface::writeTypes()
|
||||
{
|
||||
// Stop-gap measure until writing is handled more generally
|
||||
if (writeTypes_.empty())
|
||||
{
|
||||
writeTypes_ = { "ftr", "stl", "stlb", "gts" };
|
||||
writeTypes_ += MeshedSurfaceProxy<labelledTri>::writeTypes();
|
||||
}
|
||||
wordHashSet known
|
||||
(
|
||||
MeshedSurfaceProxy<labelledTri>::writeTypes()
|
||||
);
|
||||
|
||||
return writeTypes_;
|
||||
// Additional hard-coded entry points, but do not need
|
||||
// {"gts", "stl", "stlb"}
|
||||
// since they are shadowed by MeshedSurfaceProxy
|
||||
|
||||
known.insert("ftr");
|
||||
|
||||
return known;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::triSurface::canReadType(const word& ext, const bool verbose)
|
||||
bool Foam::triSurface::canReadType(const word& fileType, bool verbose)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
readTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::triSurface::canWriteType(const word& ext, const bool verbose)
|
||||
bool Foam::triSurface::canWriteType(const word& fileType, bool verbose)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
writeTypes(),
|
||||
ext,
|
||||
fileType,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::triSurface::canRead(const fileName& name, const bool verbose)
|
||||
bool Foam::triSurface::canRead(const fileName& name, bool verbose)
|
||||
{
|
||||
word ext = name.ext();
|
||||
word ext(name.ext());
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
@ -105,8 +107,6 @@ bool Foam::triSurface::canRead(const fileName& name, const bool verbose)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Foam::fileName Foam::triSurface::relativeFilePath
|
||||
(
|
||||
const IOobject& io,
|
||||
@ -192,7 +192,7 @@ bool Foam::triSurface::read(Istream& is)
|
||||
bool Foam::triSurface::read
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const word& fileType,
|
||||
const bool check
|
||||
)
|
||||
{
|
||||
@ -203,7 +203,25 @@ bool Foam::triSurface::read
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (ext == "gz")
|
||||
if (fileType.empty())
|
||||
{
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return read(name, ext, false);
|
||||
}
|
||||
|
||||
|
||||
if (fileType == "gz")
|
||||
{
|
||||
fileName unzipName = name.lessExt();
|
||||
|
||||
@ -212,15 +230,15 @@ bool Foam::triSurface::read
|
||||
}
|
||||
|
||||
// Hard-coded readers
|
||||
if (ext == "ftr")
|
||||
if (fileType == "ftr")
|
||||
{
|
||||
return read(IFstream(name)());
|
||||
}
|
||||
else if (ext == "stl")
|
||||
else if (fileType == "stl")
|
||||
{
|
||||
return readSTL(name); // ASCII
|
||||
}
|
||||
else if (ext == "stlb")
|
||||
else if (fileType == "stlb")
|
||||
{
|
||||
return readSTL(name, true); // Force BINARY
|
||||
}
|
||||
@ -228,9 +246,9 @@ bool Foam::triSurface::read
|
||||
// UnsortedMeshedSurface
|
||||
{
|
||||
using proxyType = UnsortedMeshedSurface<labelledTri>;
|
||||
if (proxyType::readTypes().found(ext))
|
||||
if (proxyType::readTypes().found(fileType))
|
||||
{
|
||||
transfer(*(proxyType::New(name, ext)));
|
||||
transfer(*(proxyType::New(name, fileType)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -238,19 +256,19 @@ bool Foam::triSurface::read
|
||||
// MeshedSurface
|
||||
{
|
||||
using proxyType = MeshedSurface<labelledTri>;
|
||||
if (proxyType::readTypes().found(ext))
|
||||
if (proxyType::readTypes().found(fileType))
|
||||
{
|
||||
transfer(*(proxyType::New(name, ext)));
|
||||
transfer(*(proxyType::New(name, fileType)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FatalErrorInFunction
|
||||
<< "unknown file extension " << ext
|
||||
<< " for reading file " << name
|
||||
<< ". Supported extensions:" << nl
|
||||
<< " " << flatOutput(readTypes_.sortedToc()) << nl
|
||||
<< "Unknown surface format " << fileType
|
||||
<< " for reading file " << name << nl
|
||||
<< "Valid types:" << nl
|
||||
<< " " << flatOutput(readTypes().sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
|
||||
return false;
|
||||
@ -260,30 +278,49 @@ bool Foam::triSurface::read
|
||||
void Foam::triSurface::write
|
||||
(
|
||||
const fileName& name,
|
||||
const word& ext,
|
||||
const bool sort
|
||||
const word& fileType,
|
||||
const bool sortByRegion
|
||||
) const
|
||||
{
|
||||
if (fileType.empty())
|
||||
{
|
||||
// Handle empty/missing type
|
||||
|
||||
const word ext(name.ext());
|
||||
|
||||
if (ext.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot determine format from filename" << nl
|
||||
<< " " << name << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
write(name, ext, sortByRegion);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Hard-coded readers
|
||||
|
||||
if (ext == "ftr")
|
||||
if (fileType == "ftr")
|
||||
{
|
||||
OFstream os(name);
|
||||
write(os);
|
||||
}
|
||||
else if (ext == "stl")
|
||||
else if (fileType == "stl")
|
||||
{
|
||||
writeSTLASCII(name, sort);
|
||||
writeSTLASCII(name, sortByRegion);
|
||||
}
|
||||
else if (ext == "stlb")
|
||||
else if (fileType == "stlb")
|
||||
{
|
||||
writeSTLBINARY(name);
|
||||
}
|
||||
else if (ext == "gts")
|
||||
else if (fileType == "gts")
|
||||
{
|
||||
writeGTS(name, sort);
|
||||
writeGTS(name, sortByRegion);
|
||||
}
|
||||
else if (MeshedSurfaceProxy<labelledTri>::canWriteType(ext))
|
||||
else if (MeshedSurfaceProxy<labelledTri>::canWriteType(fileType))
|
||||
{
|
||||
labelList faceMap;
|
||||
List<surfZone> zoneLst = this->sortedZones(faceMap);
|
||||
@ -296,15 +333,15 @@ void Foam::triSurface::write
|
||||
faceMap
|
||||
);
|
||||
|
||||
proxy.write(name, ext);
|
||||
proxy.write(name, fileType);
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "unknown file extension " << ext
|
||||
<< " for writing file " << name
|
||||
<< ". Supported extensions:" << nl
|
||||
<< " " << flatOutput(writeTypes_.sortedToc()) << nl
|
||||
<< "Unknown surface format " << fileType
|
||||
<< " for writing file " << name << nl
|
||||
<< "Valid types:" << nl
|
||||
<< " " << flatOutput(writeTypes().sortedToc()) << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
@ -326,13 +363,12 @@ Foam::triSurface::triSurface(const Time& d)
|
||||
:
|
||||
triSurface()
|
||||
{
|
||||
fileName foamFile(d.caseName() + ".ftr");
|
||||
IFstream is
|
||||
(
|
||||
d.path()/triSurfInstance(d)/typeName/(d.caseName() + ".ftr")
|
||||
);
|
||||
|
||||
fileName foamPath(d.path()/triSurfInstance(d)/typeName/foamFile);
|
||||
|
||||
IFstream foamStream(foamPath);
|
||||
|
||||
read(foamStream);
|
||||
read(is);
|
||||
|
||||
setDefaultPatches();
|
||||
}
|
||||
@ -349,11 +385,7 @@ Foam::triSurface::triSurface
|
||||
{
|
||||
fileName fName(checkFile(io, dict, isGlobal));
|
||||
|
||||
// TBD:
|
||||
// word fileExt = dict.getOrDefault<word>("surfaceType", fName.ext());
|
||||
// read(fName, ext);
|
||||
|
||||
read(fName, fName.ext());
|
||||
read(fName, dict.getOrDefault<word>("fileType", word::null));
|
||||
|
||||
scalePoints(dict.getOrDefault<scalar>("scale", 0));
|
||||
|
||||
@ -381,20 +413,18 @@ void Foam::triSurface::write(Ostream& os) const
|
||||
os << points() << nl
|
||||
<< static_cast<const List<labelledTri>&>(*this) << nl;
|
||||
|
||||
// Check state of Ostream
|
||||
os.check(FUNCTION_NAME);
|
||||
}
|
||||
|
||||
|
||||
void Foam::triSurface::write(const Time& d) const
|
||||
{
|
||||
fileName foamFile(d.caseName() + ".ftr");
|
||||
OFstream os
|
||||
(
|
||||
d.path()/triSurfInstance(d)/typeName/(d.caseName() + ".ftr")
|
||||
);
|
||||
|
||||
fileName foamPath(d.path()/triSurfInstance(d)/typeName/foamFile);
|
||||
|
||||
OFstream foamStream(foamPath);
|
||||
|
||||
write(foamStream);
|
||||
write(os);
|
||||
}
|
||||
|
||||
|
||||
@ -402,9 +432,9 @@ void Foam::triSurface::writeStats(Ostream& os) const
|
||||
{
|
||||
// Unfortunately nPoints constructs meshPoints() so do compact version
|
||||
// ourselves.
|
||||
|
||||
bitSet pointIsUsed(points().size());
|
||||
|
||||
label nPoints = 0;
|
||||
boundBox bb(boundBox::invertedBox);
|
||||
labelHashSet regionsUsed;
|
||||
|
||||
@ -412,20 +442,18 @@ void Foam::triSurface::writeStats(Ostream& os) const
|
||||
{
|
||||
regionsUsed.insert(f.region());
|
||||
|
||||
forAll(f, fp)
|
||||
for (const label pointi : f)
|
||||
{
|
||||
const label pointi = f[fp];
|
||||
if (pointIsUsed.set(pointi))
|
||||
{
|
||||
bb.add(points()[pointi]);
|
||||
++nPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
os << "Triangles : " << size()
|
||||
<< " in " << regionsUsed.size() << " region(s)" << nl
|
||||
<< "Vertices : " << nPoints << nl
|
||||
<< "Vertices : " << pointIsUsed.count() << nl
|
||||
<< "Bounding Box : " << bb << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::write()
|
||||
MeshedSurfaceProxy<face>(surf.points(), surf.faces()).write
|
||||
(
|
||||
outputFile,
|
||||
"inp",
|
||||
"starcd", // Canonical selection name
|
||||
streamOpt_
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user