diff --git a/etc/caseDicts/surface/surfaceFeatureExtractDict.cfg b/etc/caseDicts/surface/surfaceFeatureExtractDict.cfg index 683d8acd59648b913a43b305f5269d1d60df9384..14af1b9e48472ade3f43611e78cbd320a9489455 100644 --- a/etc/caseDicts/surface/surfaceFeatureExtractDict.cfg +++ b/etc/caseDicts/surface/surfaceFeatureExtractDict.cfg @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: plus | +| \\ / O peration | Version: plus | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ diff --git a/src/functionObjects/utilities/Make/files b/src/functionObjects/utilities/Make/files index ea37b71c95d67d35e516cc7db20ad54444d2c0eb..5cd7055b4693edf0427e31d1e210770218dc3728 100644 --- a/src/functionObjects/utilities/Make/files +++ b/src/functionObjects/utilities/Make/files @@ -2,7 +2,7 @@ abort/abort.C codedFunctionObject/codedFunctionObject.C ensightWrite/ensightWrite.C -writeVTK/writeVTK.C +vtkWrite/vtkWrite.C removeRegisteredObject/removeRegisteredObject.C diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.H b/src/functionObjects/utilities/ensightWrite/ensightWrite.H index 79c4110800b0f102a7157385fa89f2a7cc5c3ec7..ce9592f99c4112e565a4071aee8a212c9d5c738e 100644 --- a/src/functionObjects/utilities/ensightWrite/ensightWrite.H +++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.H @@ -76,7 +76,6 @@ SourceFiles ensightWrite.C ensightWriteTemplates.C - \*---------------------------------------------------------------------------*/ #ifndef functionObjects_ensightWrite_H diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.C b/src/functionObjects/utilities/vtkWrite/vtkWrite.C new file mode 100644 index 0000000000000000000000000000000000000000..af55e3f82ea9a1b704d153a6ad4c56715ea59abf --- /dev/null +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.C @@ -0,0 +1,221 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "vtkWrite.H" +#include "dictionary.H" +#include "Time.H" +#include "foamVtkInternalWriter.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(vtkWrite, 0); + addToRunTimeSelectionTable(functionObject, vtkWrite, dictionary); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::vtkWrite::vtkWrite +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + writeOpts_(vtk::formatType::INLINE_BASE64), + selectFields_(), + dirName_("VTK") +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::vtkWrite::~vtkWrite() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::vtkWrite::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + + // + // writer options - default is xml base64 + // + writeOpts_ = vtk::formatType::INLINE_BASE64; + if (dict.lookupOrDefault<bool>("legacy", false)) + { + writeOpts_.legacy(true); + } + + writeOpts_.ascii + ( + dict.found("format") + && (IOstream::formatEnum(dict.lookup("format")) == IOstream::ASCII) + ); + + // FUTURE? + // writeOpts_.precision + // ( + // dict.lookupOrDefault + // ( + // "writePrecision", + // IOstream::defaultPrecision() + // ) + // ); + + // Info<< type() << " " << name() << " output-format: " + // << writeOpts_.description() << nl; + + // + // other options + // + dict.readIfPresent("directory", dirName_); + + writeIds_ = dict.lookupOrDefault<bool>("writeIds", false); + + + // + // output fields + // + dict.lookup("fields") >> selectFields_; + wordRes::inplaceUniq(selectFields_); + + return true; +} + + +bool Foam::functionObjects::vtkWrite::execute() +{ + return true; +} + + +bool Foam::functionObjects::vtkWrite::write() +{ + // Count number of fields to be written: only needed for legacy vtk format + label nFields = 0; + if (writeOpts_.legacy()) + { + nFields = + ( + (writeIds_ ? 1 : 0) + + countFields<volScalarField>() + + countFields<volVectorField>() + + countFields<volSphericalTensorField>() + + countFields<volSymmTensorField>() + + countFields<volTensorField>() + ); + } + + // const word timeDesc = + // useTimeName ? time_.timeName() : Foam::name(time_.timeIndex()); + + const word timeDesc = time_.timeName(); + + fileName vtkDir = dirName_; + if (!vtkDir.isAbsolute()) + { + vtkDir = time_.path()/vtkDir; + } + mkDir(vtkDir); + + string vtkName = time_.caseName(); + + if (Pstream::parRun()) + { + // Strip off leading casename, leaving just processor_DDD ending. + string::size_type i = vtkName.rfind("processor"); + + if (i != string::npos) + { + vtkName = vtkName.substr(i); + } + } + + // Create file and write header + const fileName outputName + ( + vtkDir/vtkName + + "_" + + timeDesc + ); + + Info<< name() << " output Time: " << time_.timeName() << nl + << " Internal : " << outputName << endl; + + vtk::vtuCells vtuMeshCells + ( + mesh_, + writeOpts_, + true // decompose + ); + + // Write mesh + vtk::internalWriter writer + ( + mesh_, + vtuMeshCells, + outputName, + writeOpts_ + ); + + // CellData + { + writer.beginCellData(nFields); + + // Write cellID field + if (writeIds_) + { + writer.writeCellIDs(); + } + + // Write volFields + writeFields<volScalarField>(writer); + writeFields<volVectorField>(writer); + writeFields<volSphericalTensorField>(writer); + writeFields<volSymmTensorField>(writer); + writeFields<volTensorField>(writer); + + writer.endCellData(); + } + + writer.writeFooter(); + + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/writeVTK/writeVTK.H b/src/functionObjects/utilities/vtkWrite/vtkWrite.H similarity index 62% rename from src/functionObjects/utilities/writeVTK/writeVTK.H rename to src/functionObjects/utilities/vtkWrite/vtkWrite.H index 33c62057f33843f40612537ee6a67993386a5ff3..025e92bdab21e505d14c7abad6924b92d271a468 100644 --- a/src/functionObjects/utilities/writeVTK/writeVTK.H +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Class - Foam::functionObjects::writeVTK + Foam::functionObjects::vtkWrite Group grpUtilitiesFunctionObjects @@ -36,56 +36,47 @@ Description Example of function object specification: \verbatim - writeVTK1 - { - type writeVTK; - libs ("libutilityFunctionObjects.so"); - ... - objectNames (obj1 obj2); - } + vtkWrite1 + { + type vtkWrite; + libs ("libutilityFunctionObjects.so"); + writeControl writeTime; + writeInterval 1; + format binary; + legacy false; + ... + fields (U p); + } \endverbatim Usage \table Property | Description | Required | Default value - type | Type name: writeVTK | yes | - objectNames | objects to write | yes | + type | Type name: vtkWrite | yes | + fields | Fields to output | yes | + writeControl | Output control | recommended | timeStep + directory | The output directory name | no | "VTK" + format | ASCII or binary format | no | binary + legacy | Legacy VTK output | no | false + writeIds | Write cell ids as field | no | true \endtable See also Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::timeControl - Example of function object specification to calculate Lambda2: - \verbatim - Lambda2_1 - { - type Lambda2; - functionObjectLibs ("libutilityFunctionObjects.so"); - ... - } - \endverbatim - - \heading Function object usage - \table - Property | Description | Required | Default value - type | Type name: Lambda2 | yes | - UName | Name of velocity field | no | U - resultName | Name of Lambda2 field | no | <function name> - log | Log to standard output | no | yes - \endtable - SourceFiles - writeVTK.C - IOwriteVTK.H + vtkWrite.C + vtkWriteTemplates.C \*---------------------------------------------------------------------------*/ -#ifndef functionObjects_writeVTK_H -#define functionObjects_writeVTK_H +#ifndef functionObjects_vtkWrite_H +#define functionObjects_vtkWrite_H #include "fvMeshFunctionObject.H" -#include "wordReList.H" +#include "foamVtkInternalWriter.H" +#include "wordRes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -95,46 +86,57 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class writeVTK Declaration + Class vtkWrite Declaration \*---------------------------------------------------------------------------*/ -class writeVTK +class vtkWrite : public fvMeshFunctionObject { // Private data - //- Names of objects - wordReList objectNames_; + //- VTK output options + vtk::outputOptions writeOpts_; + + //- Name of fields to process + wordReList selectFields_; - //- Result name - word resultName_; + //- Output directory name + fileName dirName_; + + //- Write cell ids field + bool writeIds_; - //- Switch to send output to Info as well as to file - Switch log_; // Private Member Functions + //- Count number of selected fields for GeoField type. + // Only needed for legacy vtk format. + template<class GeoField> + label countFields() const; + + //- Write selected fields for GeoField type. template<class GeoField> - UPtrList<const GeoField> lookupFields() const; + label writeFields(vtk::internalWriter& writer, bool verbose=true) const; + //- Disallow default bitwise copy construct - writeVTK(const writeVTK&) = delete; + vtkWrite(const vtkWrite&) = delete; //- Disallow default bitwise assignment - void operator=(const writeVTK&) = delete; + void operator=(const vtkWrite&) = delete; public: //- Runtime type information - TypeName("writeVTK"); + TypeName("vtkWrite"); // Constructors //- Construct from Time and dictionary - writeVTK + vtkWrite ( const word& name, const Time& t, @@ -143,18 +145,18 @@ public: //- Destructor - virtual ~writeVTK(); + virtual ~vtkWrite(); // Member Functions - //- Read the writeVTK data + //- Read the vtkWrite specification virtual bool read(const dictionary& dict); //- Execute, currently does nothing virtual bool execute(); - //- Write the writeVTK + //- Write fields virtual bool write(); }; @@ -167,7 +169,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "writeVTKTemplates.C" + #include "vtkWriteTemplates.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/functionObjects/utilities/writeVTK/writeVTKTemplates.C b/src/functionObjects/utilities/vtkWrite/vtkWriteTemplates.C similarity index 63% rename from src/functionObjects/utilities/writeVTK/writeVTKTemplates.C rename to src/functionObjects/utilities/vtkWrite/vtkWriteTemplates.C index e46f0333d4d02905fa08d4f11f0986c5d80bae78..1cdce49cd15a595d955244999a91238375282338 100644 --- a/src/functionObjects/utilities/writeVTK/writeVTKTemplates.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWriteTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,38 +23,38 @@ License \*---------------------------------------------------------------------------*/ -#include "writeVTK.H" -#include "objectRegistry.H" -#include "DynamicList.H" - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class GeoField> -Foam::UPtrList<const GeoField> -Foam::functionObjects::writeVTK::lookupFields() const +Foam::label +Foam::functionObjects::vtkWrite::countFields() const { - DynamicList<word> allNames(obr_.toc().size()); - forAll(objectNames_, i) - { - wordList names(obr_.names<GeoField>(objectNames_[i])); + return obr_.names<GeoField>(selectFields_).size(); +} - if (names.size()) - { - allNames.append(names); - } - } - UPtrList<const GeoField> fields(allNames.size()); +template<class GeoField> +Foam::label +Foam::functionObjects::vtkWrite::writeFields +( + vtk::internalWriter& writer, + bool verbose +) const +{ + const wordList names = obr_.sortedNames<GeoField>(selectFields_); + + if (verbose && names.size()) + { + Info<< " " << GeoField::typeName + << " " << flatOutput(names) << endl; + } - forAll(allNames, i) + for (const word& fieldName : names) { - const GeoField& field = obr_.lookupObject<GeoField>(allNames[i]); - Info<< " Writing " << GeoField::typeName - << " field " << field.name() << endl; - fields.set(i, &field); + writer.write(obr_.lookupObject<GeoField>(fieldName)); } - return fields; + return names.size(); } diff --git a/src/functionObjects/utilities/writeVTK/writeVTK.C b/src/functionObjects/utilities/writeVTK/writeVTK.C deleted file mode 100644 index ab56d294fda129457bcff05808bc528c488d05ac..0000000000000000000000000000000000000000 --- a/src/functionObjects/utilities/writeVTK/writeVTK.C +++ /dev/null @@ -1,166 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "writeVTK.H" -#include "dictionary.H" -#include "Time.H" -#include "foamVtkInternalWriter.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ -namespace functionObjects -{ - defineTypeNameAndDebug(writeVTK, 0); - addToRunTimeSelectionTable(functionObject, writeVTK, dictionary); -} -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::functionObjects::writeVTK::writeVTK -( - const word& name, - const Time& runTime, - const dictionary& dict -) -: - fvMeshFunctionObject(name, runTime, dict), - objectNames_() -{ - read(dict); -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::functionObjects::writeVTK::~writeVTK() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::functionObjects::writeVTK::read(const dictionary& dict) -{ - dict.lookup("objects") >> objectNames_; - - return true; -} - - -bool Foam::functionObjects::writeVTK::execute() -{ - return true; -} - - -bool Foam::functionObjects::writeVTK::write() -{ - Info<< type() << " " << name() << " output:" << nl; - - Info<< "Time: " << time_.timeName() << endl; - - word timeDesc = time_.timeName(); - - // VTK/ directory in the case - fileName fvPath(time_.path()/"VTK"); - - mkDir(fvPath); - - string vtkName = time_.caseName(); - - if (Pstream::parRun()) - { - // Strip off leading casename, leaving just processor_DDD ending. - string::size_type i = vtkName.rfind("processor"); - - if (i != string::npos) - { - vtkName = vtkName.substr(i); - } - } - - // Create file and write header - const fileName outputName - ( - fvPath/vtkName - + "_" - + timeDesc - ); - - Info<< " Internal : " << outputName << endl; - - vtk::vtuCells meshCells - ( - mesh_, - vtk::vtuCells::contentType::LEGACY, - true // decompose - ); - - // Write mesh - vtk::internalWriter writer - ( - mesh_, - meshCells, - outputName, - vtk::formatType::LEGACY_ASCII - ); - - - UPtrList<const volScalarField> vsf(lookupFields<volScalarField>()); - UPtrList<const volVectorField> vvf(lookupFields<volVectorField>()); - UPtrList<const volSphericalTensorField> vsptf - ( - lookupFields<volSphericalTensorField>() - ); - UPtrList<const volSymmTensorField> vstf(lookupFields<volSymmTensorField>()); - UPtrList<const volTensorField> vtf(lookupFields<volTensorField>()); - - const label nVolFields = - vsf.size() + vvf.size() + vsptf.size() + vstf.size() + vtf.size(); - - // CellData - { - writer.beginCellData(1 + nVolFields); - - // Write cellID field - writer.writeCellIDs(); - - // Write volFields - writer.write(vsf); - writer.write(vvf); - writer.write(vsptf); - writer.write(vstf); - writer.write(vtf); - } - - return true; -} - - -// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite b/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite index 34e7b14d71b4f1e12eea04845ba07454a9f3264b..2630bdc3b63debd09671c9747ef073584682e9b7 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite +++ b/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite @@ -10,8 +10,8 @@ ensightWrite // Fields to output (words or regex) fields (U p "(k|epsilon|omega)"); - writeControl writeTime; - writeIterval 1; + writeControl writeTime; + writeInterval 1; } // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/windAroundBuildings/system/controlDict b/tutorials/incompressible/simpleFoam/windAroundBuildings/system/controlDict index 7ceca861c1be4f50552b4ba7b4588ed3bbced585..2f6bf243811bd5adbf5df6cc4a73fbb69a42eafe 100644 --- a/tutorials/incompressible/simpleFoam/windAroundBuildings/system/controlDict +++ b/tutorials/incompressible/simpleFoam/windAroundBuildings/system/controlDict @@ -50,6 +50,8 @@ runTimeModifiable true; functions { + #include "vtkWrite" } + // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/windAroundBuildings/system/vtkWrite b/tutorials/incompressible/simpleFoam/windAroundBuildings/system/vtkWrite new file mode 100644 index 0000000000000000000000000000000000000000..9f729db0cba4f5feeb3aad2341dd483c75941b0c --- /dev/null +++ b/tutorials/incompressible/simpleFoam/windAroundBuildings/system/vtkWrite @@ -0,0 +1,31 @@ +// -*- C++ -*- +// Minimal example of using the vtkWrite function object. +vtkWrite +{ + type vtkWrite; + libs ("libutilityFunctionObjects.so"); + log true; + + // Fields to output (words or regex) + fields (U p "(k|epsilon|omega)"); + + //- Output format (ascii | binary) - Default=binary + // format binary; + + //- Use legacy output format - Default=false + // legacy false; + + //- Output directory name - Default="VTK" + // directory "VTK"; + + //- Write cell ids as field - Default=true + writeIds false; + + writeControl writeTime; + writeInterval 1; + + writeControl timeStep; + writeInterval 25; +} + +// ************************************************************************* //