From 773ec00d4b021f011e048285f500eeb865a27ce7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 11 Mar 2019 15:09:03 +0100 Subject: [PATCH] ENH: improved consistency of surface writers (#1232) - remove writeGeometry() in favour of write() and make it pure virtual so that all writers must explicitly deal with it. - establish proxy extension at construction time and treated as an invariant thereafter. This avoids potentially surprising changes in behaviour when writing. --- applications/test/surfaceWriter/Make/files | 3 + applications/test/surfaceWriter/Make/options | 5 + .../test/surfaceWriter/Test-surfaceWriter.C | 115 ++++++++++++++++++ .../mesh/manipulation/checkMesh/checkTools.C | 4 +- .../sampledSurfaces/sampledSurfaces.C | 2 +- .../boundaryData/boundaryDataSurfaceWriter.H | 13 +- .../writers/ensight/ensightSurfaceWriter.H | 2 +- .../writers/nastran/nastranSurfaceWriter.H | 2 - src/surfMesh/writers/null/nullSurfaceWriter.C | 6 + src/surfMesh/writers/null/nullSurfaceWriter.H | 4 +- .../writers/proxy/proxySurfaceWriter.C | 10 -- .../writers/proxy/proxySurfaceWriter.H | 11 -- .../writers/starcd/starcdSurfaceWriter.H | 2 +- src/surfMesh/writers/surfaceWriter.H | 7 +- 14 files changed, 145 insertions(+), 41 deletions(-) create mode 100644 applications/test/surfaceWriter/Make/files create mode 100644 applications/test/surfaceWriter/Make/options create mode 100644 applications/test/surfaceWriter/Test-surfaceWriter.C diff --git a/applications/test/surfaceWriter/Make/files b/applications/test/surfaceWriter/Make/files new file mode 100644 index 0000000000..d52a295402 --- /dev/null +++ b/applications/test/surfaceWriter/Make/files @@ -0,0 +1,3 @@ +Test-surfaceWriter.C + +EXE = $(FOAM_USER_APPBIN)/Test-surfaceWriter diff --git a/applications/test/surfaceWriter/Make/options b/applications/test/surfaceWriter/Make/options new file mode 100644 index 0000000000..a504dd8617 --- /dev/null +++ b/applications/test/surfaceWriter/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/surfMesh/lnInclude + +EXE_LIBS = \ + -lsurfMesh diff --git a/applications/test/surfaceWriter/Test-surfaceWriter.C b/applications/test/surfaceWriter/Test-surfaceWriter.C new file mode 100644 index 0000000000..0d8e0c1e4e --- /dev/null +++ b/applications/test/surfaceWriter/Test-surfaceWriter.C @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Application + Test-surfaceWriter + +Group + grpSurfaceUtilities + +Description + Test surface writers. + +Usage + \b Test-surfaceWriter inputFile outputFile + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "surfaceWriter.H" +#include "MeshedSurfaces.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + argList::addNote + ( + "convert between surface formats, " + "but primarily for testing functionality\n" + "Normally use surfaceMeshConvert instead." + ); + + argList::noParallel(); + argList::noFunctionObjects(); + + argList::addOption + ( + "type", + "writerType" + ); + + argList::addArgument("inputFile"); + argList::addArgument("outputFile"); + + #include "setRootCase.H" + + const fileName importName = args[1]; + const fileName exportName = args[2]; + + if (importName == exportName) + { + FatalErrorInFunction + << "Output file " << exportName << " would overwrite input file." + << exit(FatalError); + } + + + if (!MeshedSurface::canRead(importName, true)) + { + return 1; + } + + const word writerType = + args.lookupOrDefault("type", exportName.ext()); + + auto surfWriter = surfaceWriter::New(writerType); + + { + MeshedSurface surf(importName); + + Info<< "Read surface:" << endl; + surf.writeStats(Info); + + Info<< "Open " << exportName + << " for writing with " << surfWriter->type() << nl; + + surfWriter->open + ( + surf.points(), + surf.surfFaces(), + exportName.lessExt(), + false // serial + ); + + surfWriter->write(); + } + + Info<< "\nEnd\n" << endl; + + return 0; +} + +// ************************************************************************* // diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C index 4b530ee9ef..8aa7783038 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C @@ -250,7 +250,7 @@ void Foam::mergeAndWrite false // serial - already merged ); - writer.writeGeometry(); + writer.write(); writer.clear(); } } @@ -264,7 +264,7 @@ void Foam::mergeAndWrite false // serial - already merged ); - writer.writeGeometry(); + writer.write(); writer.clear(); } } diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index efe043f428..fcfb3478e6 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -560,7 +560,7 @@ bool Foam::sampledSurfaces::performAction(unsigned request) // Write geometry if no fields would otherwise be written if (!outWriter.nFields() || outWriter.separateGeometry()) { - outWriter.writeGeometry(); + outWriter.write(); continue; } diff --git a/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H b/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H index 569c07fb5a..93535078c2 100644 --- a/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H +++ b/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H @@ -165,13 +165,12 @@ public: //- Write surface geometry to file. virtual fileName write(); // override - - declareSurfaceWriterWriteMethod(label); - declareSurfaceWriterWriteMethod(scalar); - declareSurfaceWriterWriteMethod(vector); - declareSurfaceWriterWriteMethod(sphericalTensor); - declareSurfaceWriterWriteMethod(symmTensor); - declareSurfaceWriterWriteMethod(tensor); + declareSurfaceWriterWriteMethod(label); + declareSurfaceWriterWriteMethod(scalar); + declareSurfaceWriterWriteMethod(vector); + declareSurfaceWriterWriteMethod(sphericalTensor); + declareSurfaceWriterWriteMethod(symmTensor); + declareSurfaceWriterWriteMethod(tensor); }; diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriter.H b/src/surfMesh/writers/ensight/ensightSurfaceWriter.H index 39a958a20b..a5e2de9536 100644 --- a/src/surfMesh/writers/ensight/ensightSurfaceWriter.H +++ b/src/surfMesh/writers/ensight/ensightSurfaceWriter.H @@ -174,7 +174,7 @@ public: // False if geometry and field must be in a single file virtual bool separateGeometry() const; - //- Write single surface geometry to file. + //- Write surface geometry to file. virtual fileName write(); // override declareSurfaceWriterWriteMethod(label); diff --git a/src/surfMesh/writers/nastran/nastranSurfaceWriter.H b/src/surfMesh/writers/nastran/nastranSurfaceWriter.H index 3993148cad..1e1e05feb2 100644 --- a/src/surfMesh/writers/nastran/nastranSurfaceWriter.H +++ b/src/surfMesh/writers/nastran/nastranSurfaceWriter.H @@ -236,8 +236,6 @@ public: // Member Functions - // Write - //- Write surface geometry to file. virtual fileName write(); // override diff --git a/src/surfMesh/writers/null/nullSurfaceWriter.C b/src/surfMesh/writers/null/nullSurfaceWriter.C index b9bcbcc1c6..9e245f91ec 100644 --- a/src/surfMesh/writers/null/nullSurfaceWriter.C +++ b/src/surfMesh/writers/null/nullSurfaceWriter.C @@ -114,6 +114,12 @@ void Foam::surfaceWriters::nullWriter::open(const fileName& outputPath) {} +Foam::fileName Foam::surfaceWriters::nullWriter::write() +{ + return fileName::null; +} + + // Field writing methods defineSurfaceWriterWriteFields(Foam::surfaceWriters::nullWriter); diff --git a/src/surfMesh/writers/null/nullSurfaceWriter.H b/src/surfMesh/writers/null/nullSurfaceWriter.H index e8817c4e02..5ccf8a5f09 100644 --- a/src/surfMesh/writers/null/nullSurfaceWriter.H +++ b/src/surfMesh/writers/null/nullSurfaceWriter.H @@ -102,7 +102,7 @@ public: virtual bool enabled() const; - // Surface association + // Surface Association //- Change association with a surface (no-op). virtual void setSurface @@ -128,6 +128,8 @@ public: // Write + virtual fileName write(); // override; + declareSurfaceWriterWriteMethod(label); declareSurfaceWriterWriteMethod(scalar); declareSurfaceWriterWriteMethod(vector); diff --git a/src/surfMesh/writers/proxy/proxySurfaceWriter.C b/src/surfMesh/writers/proxy/proxySurfaceWriter.C index 1e8d20856b..77518db6bd 100644 --- a/src/surfMesh/writers/proxy/proxySurfaceWriter.C +++ b/src/surfMesh/writers/proxy/proxySurfaceWriter.C @@ -93,16 +93,6 @@ Foam::surfaceWriters::proxyWriter::proxyWriter // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::surfaceWriters::proxyWriter::open -( - const fileName& outputPath -) -{ - fileExtension_ = outputPath.ext(); - surfaceWriter::open(outputPath); -} - - Foam::fileName Foam::surfaceWriters::proxyWriter::write() { checkOpen(); diff --git a/src/surfMesh/writers/proxy/proxySurfaceWriter.H b/src/surfMesh/writers/proxy/proxySurfaceWriter.H index 383d4b3fc5..d11f92f539 100644 --- a/src/surfMesh/writers/proxy/proxySurfaceWriter.H +++ b/src/surfMesh/writers/proxy/proxySurfaceWriter.H @@ -119,23 +119,12 @@ public: // Member Functions - // Capability - //- A separate file is required for geometry. virtual bool separateGeometry() const { return true; } - - // Output - - //- Open for output on specified path, using existing surface - virtual void open(const fileName& outputPath); // override - - - // Write - //- Write surface geometry to file. virtual fileName write(); // override diff --git a/src/surfMesh/writers/starcd/starcdSurfaceWriter.H b/src/surfMesh/writers/starcd/starcdSurfaceWriter.H index 034725d126..82239526a1 100644 --- a/src/surfMesh/writers/starcd/starcdSurfaceWriter.H +++ b/src/surfMesh/writers/starcd/starcdSurfaceWriter.H @@ -146,7 +146,7 @@ public: return true; } - //- Write single surface geometry to file. + //- Write surface geometry to file. virtual fileName write(); // override declareSurfaceWriterWriteMethod(label); diff --git a/src/surfMesh/writers/surfaceWriter.H b/src/surfMesh/writers/surfaceWriter.H index a2a7451e87..15eb84b8cb 100644 --- a/src/surfMesh/writers/surfaceWriter.H +++ b/src/surfMesh/writers/surfaceWriter.H @@ -462,11 +462,8 @@ public: // Write - //- Write single surface geometry to file. - virtual fileName writeGeometry() const - { - return fileName::null; - } + //- Write separate surface geometry to file. + virtual fileName write() = 0; #undef declareSurfaceWriterWriteMethod