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
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -128,32 +128,60 @@ bool Foam::functionObjects::writeVTK::write()
|
|||||||
// Write mesh
|
// Write mesh
|
||||||
internalWriter writer(vMesh, false, vtkFileName);
|
internalWriter writer(vMesh, false, vtkFileName);
|
||||||
|
|
||||||
UPtrList<const volScalarField> vsf(lookupFields<volScalarField>());
|
// Declare UPtrLists to the volFields that are to be written
|
||||||
UPtrList<const volVectorField> vvf(lookupFields<volVectorField>());
|
#define DeclareTypeFields(Type, nullArg) \
|
||||||
UPtrList<const volSphericalTensorField> vsptf
|
UPtrList<const VolField<Type>> Type##Fields;
|
||||||
(
|
FOR_ALL_FIELD_TYPES(DeclareTypeFields);
|
||||||
lookupFields<volSphericalTensorField>()
|
#undef DeclareTypeFields
|
||||||
);
|
|
||||||
UPtrList<const volSymmTensorField> vstf(lookupFields<volSymmTensorField>());
|
// Look up the volFields and store the pointers
|
||||||
UPtrList<const volTensorField> vtf(lookupFields<volTensorField>());
|
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
|
// Write header for cellID and volFields
|
||||||
vtkWriteOps::writeCellDataHeader
|
vtkWriteOps::writeCellDataHeader
|
||||||
(
|
(
|
||||||
writer.os(),
|
writer.os(),
|
||||||
vMesh.nFieldCells(),
|
vMesh.nFieldCells(),
|
||||||
1 + vsf.size() + vvf.size() + vsptf.size() + vstf.size() + vtf.size()
|
1 + nFields
|
||||||
);
|
);
|
||||||
|
|
||||||
// Write cellID field
|
// Write cellID field
|
||||||
writer.writeCellIDs();
|
writer.writeCellIDs();
|
||||||
|
|
||||||
// Write volFields
|
// Write volFields
|
||||||
writer.write(vsf);
|
#define WriteTypeFields(Type, nullArg) \
|
||||||
writer.write(vvf);
|
writer.write(Type##Fields);
|
||||||
writer.write(vsptf);
|
FOR_ALL_FIELD_TYPES(WriteTypeFields);
|
||||||
writer.write(vstf);
|
#undef WriteTypeFields
|
||||||
writer.write(vtf);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -145,12 +145,6 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
|
||||||
#include "writeVTKTemplates.C"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#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