mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: upgrade writeVTK function object -> vtkWrite function object
- user-selectable format (vtk or vtu, ascii or binary) - dictionary syntax closer to ensightWrite - tutorial example in windAroundBuildings
This commit is contained in:
@ -2,7 +2,7 @@ abort/abort.C
|
|||||||
|
|
||||||
codedFunctionObject/codedFunctionObject.C
|
codedFunctionObject/codedFunctionObject.C
|
||||||
ensightWrite/ensightWrite.C
|
ensightWrite/ensightWrite.C
|
||||||
writeVTK/writeVTK.C
|
vtkWrite/vtkWrite.C
|
||||||
|
|
||||||
removeRegisteredObject/removeRegisteredObject.C
|
removeRegisteredObject/removeRegisteredObject.C
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,6 @@ SourceFiles
|
|||||||
ensightWrite.C
|
ensightWrite.C
|
||||||
ensightWriteTemplates.C
|
ensightWriteTemplates.C
|
||||||
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef functionObjects_ensightWrite_H
|
#ifndef functionObjects_ensightWrite_H
|
||||||
|
|||||||
221
src/functionObjects/utilities/vtkWrite/vtkWrite.C
Normal file
221
src/functionObjects/utilities/vtkWrite/vtkWrite.C
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,7 +22,7 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Class
|
Class
|
||||||
Foam::functionObjects::writeVTK
|
Foam::functionObjects::vtkWrite
|
||||||
|
|
||||||
Group
|
Group
|
||||||
grpUtilitiesFunctionObjects
|
grpUtilitiesFunctionObjects
|
||||||
@ -36,56 +36,47 @@ Description
|
|||||||
|
|
||||||
Example of function object specification:
|
Example of function object specification:
|
||||||
\verbatim
|
\verbatim
|
||||||
writeVTK1
|
vtkWrite1
|
||||||
{
|
{
|
||||||
type writeVTK;
|
type vtkWrite;
|
||||||
libs ("libutilityFunctionObjects.so");
|
libs ("libutilityFunctionObjects.so");
|
||||||
|
writeControl writeTime;
|
||||||
|
writeInterval 1;
|
||||||
|
format binary;
|
||||||
|
legacy false;
|
||||||
...
|
...
|
||||||
objectNames (obj1 obj2);
|
fields (U p);
|
||||||
}
|
}
|
||||||
\endverbatim
|
\endverbatim
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
\table
|
\table
|
||||||
Property | Description | Required | Default value
|
Property | Description | Required | Default value
|
||||||
type | Type name: writeVTK | yes |
|
type | Type name: vtkWrite | yes |
|
||||||
objectNames | objects to write | 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
|
\endtable
|
||||||
|
|
||||||
See also
|
See also
|
||||||
Foam::functionObjects::fvMeshFunctionObject
|
Foam::functionObjects::fvMeshFunctionObject
|
||||||
Foam::functionObjects::timeControl
|
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
|
SourceFiles
|
||||||
writeVTK.C
|
vtkWrite.C
|
||||||
IOwriteVTK.H
|
vtkWriteTemplates.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef functionObjects_writeVTK_H
|
#ifndef functionObjects_vtkWrite_H
|
||||||
#define functionObjects_writeVTK_H
|
#define functionObjects_vtkWrite_H
|
||||||
|
|
||||||
#include "fvMeshFunctionObject.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
|
public fvMeshFunctionObject
|
||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Names of objects
|
//- VTK output options
|
||||||
wordReList objectNames_;
|
vtk::outputOptions writeOpts_;
|
||||||
|
|
||||||
//- Result name
|
//- Name of fields to process
|
||||||
word resultName_;
|
wordReList selectFields_;
|
||||||
|
|
||||||
|
//- 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
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Count number of selected fields for GeoField type.
|
||||||
|
// Only needed for legacy vtk format.
|
||||||
template<class GeoField>
|
template<class GeoField>
|
||||||
UPtrList<const GeoField> lookupFields() const;
|
label countFields() const;
|
||||||
|
|
||||||
|
//- Write selected fields for GeoField type.
|
||||||
|
template<class GeoField>
|
||||||
|
label writeFields(vtk::internalWriter& writer, bool verbose=true) const;
|
||||||
|
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
writeVTK(const writeVTK&) = delete;
|
vtkWrite(const vtkWrite&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const writeVTK&) = delete;
|
void operator=(const vtkWrite&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Runtime type information
|
//- Runtime type information
|
||||||
TypeName("writeVTK");
|
TypeName("vtkWrite");
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from Time and dictionary
|
//- Construct from Time and dictionary
|
||||||
writeVTK
|
vtkWrite
|
||||||
(
|
(
|
||||||
const word& name,
|
const word& name,
|
||||||
const Time& t,
|
const Time& t,
|
||||||
@ -143,18 +145,18 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~writeVTK();
|
virtual ~vtkWrite();
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Read the writeVTK data
|
//- Read the vtkWrite specification
|
||||||
virtual bool read(const dictionary& dict);
|
virtual bool read(const dictionary& dict);
|
||||||
|
|
||||||
//- Execute, currently does nothing
|
//- Execute, currently does nothing
|
||||||
virtual bool execute();
|
virtual bool execute();
|
||||||
|
|
||||||
//- Write the writeVTK
|
//- Write fields
|
||||||
virtual bool write();
|
virtual bool write();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -167,7 +169,7 @@ public:
|
|||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
#ifdef NoRepository
|
||||||
#include "writeVTKTemplates.C"
|
#include "vtkWriteTemplates.C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -23,38 +23,38 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "writeVTK.H"
|
|
||||||
#include "objectRegistry.H"
|
|
||||||
#include "DynamicList.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class GeoField>
|
template<class GeoField>
|
||||||
Foam::UPtrList<const GeoField>
|
Foam::label
|
||||||
Foam::functionObjects::writeVTK::lookupFields() const
|
Foam::functionObjects::vtkWrite::countFields() const
|
||||||
{
|
{
|
||||||
DynamicList<word> allNames(obr_.toc().size());
|
return obr_.names<GeoField>(selectFields_).size();
|
||||||
forAll(objectNames_, i)
|
}
|
||||||
{
|
|
||||||
wordList names(obr_.names<GeoField>(objectNames_[i]));
|
|
||||||
|
|
||||||
if (names.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())
|
||||||
{
|
{
|
||||||
allNames.append(names);
|
Info<< " " << GeoField::typeName
|
||||||
}
|
<< " " << flatOutput(names) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
UPtrList<const GeoField> fields(allNames.size());
|
for (const word& fieldName : names)
|
||||||
|
|
||||||
forAll(allNames, i)
|
|
||||||
{
|
{
|
||||||
const GeoField& field = obr_.lookupObject<GeoField>(allNames[i]);
|
writer.write(obr_.lookupObject<GeoField>(fieldName));
|
||||||
Info<< " Writing " << GeoField::typeName
|
|
||||||
<< " field " << field.name() << endl;
|
|
||||||
fields.set(i, &field);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
return names.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -11,7 +11,7 @@ ensightWrite
|
|||||||
fields (U p "(k|epsilon|omega)");
|
fields (U p "(k|epsilon|omega)");
|
||||||
|
|
||||||
writeControl writeTime;
|
writeControl writeTime;
|
||||||
writeIterval 1;
|
writeInterval 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -50,6 +50,8 @@ runTimeModifiable true;
|
|||||||
|
|
||||||
functions
|
functions
|
||||||
{
|
{
|
||||||
|
#include "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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user