mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: replace foamToVTK routines with library-level equivalents
This commit is contained in:
@ -2,6 +2,7 @@ abort/abort.C
|
||||
|
||||
codedFunctionObject/codedFunctionObject.C
|
||||
ensightWrite/ensightWrite.C
|
||||
writeVTK/writeVTK.C
|
||||
|
||||
removeRegisteredObject/removeRegisteredObject.C
|
||||
|
||||
|
||||
167
src/functionObjects/utilities/writeVTK/writeVTK.C
Normal file
167
src/functionObjects/utilities/writeVTK/writeVTK.C
Normal file
@ -0,0 +1,167 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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
|
||||
fileName outputName
|
||||
(
|
||||
fvPath/vtkName
|
||||
+ "_"
|
||||
+ timeDesc
|
||||
+ ".vtk"
|
||||
);
|
||||
|
||||
Info<< " Internal : " << outputName << endl;
|
||||
|
||||
foamVtkCells foamVtkMeshCells
|
||||
(
|
||||
mesh_,
|
||||
foamVtkCells::contentType::LEGACY,
|
||||
true // decompose
|
||||
);
|
||||
|
||||
// Write mesh
|
||||
foamVtkOutput::internalWriter writer
|
||||
(
|
||||
mesh_,
|
||||
foamVtkOutput::LEGACY_ASCII,
|
||||
foamVtkMeshCells,
|
||||
outputName
|
||||
);
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
177
src/functionObjects/utilities/writeVTK/writeVTK.H
Normal file
177
src/functionObjects/utilities/writeVTK/writeVTK.H
Normal file
@ -0,0 +1,177 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::writeVTK
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
This functionObject writes objects registered to the database in VTK format.
|
||||
|
||||
Currently only supports writing of the cell-values of volFields but
|
||||
support for other field types, patch fields, Lagrangian data etc. will be
|
||||
added.
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
writeVTK1
|
||||
{
|
||||
type writeVTK;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
...
|
||||
objectNames (obj1 obj2);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | Type name: writeVTK | yes |
|
||||
objectNames | objects to write | yes |
|
||||
\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
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_writeVTK_H
|
||||
#define functionObjects_writeVTK_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "wordReList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class writeVTK Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class writeVTK
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Names of objects
|
||||
wordReList objectNames_;
|
||||
|
||||
//- Result name
|
||||
word resultName_;
|
||||
|
||||
//- Switch to send output to Info as well as to file
|
||||
Switch log_;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
template<class GeoField>
|
||||
UPtrList<const GeoField> lookupFields() const;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
writeVTK(const writeVTK&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const writeVTK&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("writeVTK");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
writeVTK
|
||||
(
|
||||
const word& name,
|
||||
const Time& t,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~writeVTK();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the writeVTK data
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the writeVTK
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "writeVTKTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
61
src/functionObjects/utilities/writeVTK/writeVTKTemplates.C
Normal file
61
src/functionObjects/utilities/writeVTK/writeVTKTemplates.C
Normal file
@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "objectRegistry.H"
|
||||
#include "DynamicList.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class GeoField>
|
||||
Foam::UPtrList<const GeoField>
|
||||
Foam::functionObjects::writeVTK::lookupFields() const
|
||||
{
|
||||
DynamicList<word> allNames(obr_.toc().size());
|
||||
forAll(objectNames_, i)
|
||||
{
|
||||
wordList names(obr_.names<GeoField>(objectNames_[i]));
|
||||
|
||||
if (names.size())
|
||||
{
|
||||
allNames.append(names);
|
||||
}
|
||||
}
|
||||
|
||||
UPtrList<const GeoField> fields(allNames.size());
|
||||
|
||||
forAll(allNames, i)
|
||||
{
|
||||
const GeoField& field = obr_.lookupObject<GeoField>(allNames[i]);
|
||||
Info<< " Writing " << GeoField::typeName
|
||||
<< " field " << field.name() << endl;
|
||||
fields.set(i, &field);
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user