functionObjects: writeVTK: Fixes
The lookup been fixed to prevent failures when a field is looked up with the wrong type, and it now also provides warnings when a field cannot be found for any type.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -128,32 +128,60 @@ bool Foam::functionObjects::writeVTK::write()
|
||||
// Write mesh
|
||||
internalWriter writer(vMesh, false, vtkFileName);
|
||||
|
||||
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>());
|
||||
// Declare UPtrLists to the volFields that are to be written
|
||||
#define DeclareTypeFields(Type, nullArg) \
|
||||
UPtrList<const VolField<Type>> Type##Fields;
|
||||
FOR_ALL_FIELD_TYPES(DeclareTypeFields);
|
||||
#undef DeclareTypeFields
|
||||
|
||||
// Look up the volFields and store the pointers
|
||||
label nFields = 0;
|
||||
forAll(objectNames_, i)
|
||||
{
|
||||
bool objectFound = false;
|
||||
|
||||
#define SetTypeFields(Type, nullarg) \
|
||||
{ \
|
||||
if (obr_.foundObject<VolField<Type>>(objectNames_[i])) \
|
||||
{ \
|
||||
const VolField<Type>& field = \
|
||||
obr_.lookupObject<VolField<Type>>(objectNames_[i]); \
|
||||
\
|
||||
Type##Fields.resize(Type##Fields.size() + 1); \
|
||||
Type##Fields.set(Type##Fields.size() - 1, &field); \
|
||||
\
|
||||
Info<< " Writing " << VolField<Type>::typeName \
|
||||
<< " field " << field.name() << endl; \
|
||||
\
|
||||
nFields ++; \
|
||||
objectFound = true; \
|
||||
} \
|
||||
}
|
||||
FOR_ALL_FIELD_TYPES(SetTypeFields);
|
||||
#undef SetTypeFields
|
||||
|
||||
if (!objectFound)
|
||||
{
|
||||
cannotFindObject(objectNames_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Write header for cellID and volFields
|
||||
vtkWriteOps::writeCellDataHeader
|
||||
(
|
||||
writer.os(),
|
||||
vMesh.nFieldCells(),
|
||||
1 + vsf.size() + vvf.size() + vsptf.size() + vstf.size() + vtf.size()
|
||||
1 + nFields
|
||||
);
|
||||
|
||||
// Write cellID field
|
||||
writer.writeCellIDs();
|
||||
|
||||
// Write volFields
|
||||
writer.write(vsf);
|
||||
writer.write(vvf);
|
||||
writer.write(vsptf);
|
||||
writer.write(vstf);
|
||||
writer.write(vtf);
|
||||
#define WriteTypeFields(Type, nullArg) \
|
||||
writer.write(Type##Fields);
|
||||
FOR_ALL_FIELD_TYPES(WriteTypeFields);
|
||||
#undef WriteTypeFields
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -145,12 +145,6 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "writeVTKTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2016-2021 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
|
||||
{
|
||||
UPtrList<const GeoField> fields(objectNames_.size());
|
||||
|
||||
forAll(objectNames_, i)
|
||||
{
|
||||
const GeoField& field = obr_.lookupObject<GeoField>(objectNames_[i]);
|
||||
Info<< " Writing " << GeoField::typeName
|
||||
<< " field " << field.name() << endl;
|
||||
fields.set(i, &field);
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user