ENH: vtk: fix reading of inverted prisms. Fixes #850.

This commit is contained in:
mattijs
2018-05-31 12:42:43 +01:00
parent cd8b67844f
commit b393c60d86

View File

@ -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) 2012-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,6 +29,7 @@ License
#include "stringIOList.H" #include "stringIOList.H"
#include "cellModel.H" #include "cellModel.H"
#include "vectorIOField.H" #include "vectorIOField.H"
#include "triPointRef.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
@ -300,6 +301,7 @@ void Foam::vtkUnstructuredReader::extractCells
) << "Expected size 6 for VTK_WEDGE but found " ) << "Expected size 6 for VTK_WEDGE but found "
<< nRead << exit(FatalIOError); << nRead << exit(FatalIOError);
} }
//- From mesh description in vtk documentation
prismPoints[0] = cellVertData[dataIndex++]; prismPoints[0] = cellVertData[dataIndex++];
prismPoints[2] = cellVertData[dataIndex++]; prismPoints[2] = cellVertData[dataIndex++];
prismPoints[1] = cellVertData[dataIndex++]; prismPoints[1] = cellVertData[dataIndex++];
@ -364,6 +366,8 @@ void Foam::vtkUnstructuredReader::readField
const label size const label size
) const ) const
{ {
if (vtkDataTypeNames.found(dataType))
{
switch (vtkDataTypeNames[dataType]) switch (vtkDataTypeNames[dataType])
{ {
case VTK_INT: case VTK_INT:
@ -445,7 +449,7 @@ void Foam::vtkUnstructuredReader::readField
default: default:
{ {
IOWarningInFunction(inFile) IOWarningInFunction(inFile)
<< "Unhandled type " << vtkDataTypeNames[dataType] << endl << "Unhandled type " << dataType << endl
<< "Skipping " << size << "Skipping " << size
<< " words." << endl; << " words." << endl;
scalarField fieldVals; scalarField fieldVals;
@ -453,6 +457,16 @@ void Foam::vtkUnstructuredReader::readField
} }
break; break;
} }
}
else
{
IOWarningInFunction(inFile)
<< "Unhandled type " << dataType << endl
<< "Skipping " << size
<< " words." << endl;
scalarField fieldVals;
readBlock(inFile, size, fieldVals);
}
} }
@ -907,6 +921,29 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
} }
} }
} }
else if (tag == "METADATA")
{
word infoTag(inFile);
if (infoTag != "INFORMATION")
{
FatalIOErrorInFunction(inFile)
<< "Unsupported tag "
<< infoTag << exit(FatalIOError);
}
label nInfo(readLabel(inFile));
if (debug)
{
Info<< "Consuming " << nInfo << " metadata information."
<< endl;
}
string line;
// Consume rest of line
inFile.getLine(line);
for (label i = 0; i < 2*nInfo; i++)
{
inFile.getLine(line);
}
}
else else
{ {
FatalIOErrorInFunction(inFile) FatalIOErrorInFunction(inFile)
@ -915,6 +952,53 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
} }
} }
// There is some problem with orientation of prisms - the point
// ordering seems to be different for some exports (e.g. of cgns)
{
const cellModel& prism = cellModel::ref(cellModel::PRISM);
label nSwapped = 0;
forAll(cells_, celli)
{
cellShape& shape = cells_[celli];
if (shape.model() == prism)
{
const triPointRef bottom
(
points_[shape[0]],
points_[shape[1]],
points_[shape[2]]
);
const triPointRef top
(
points_[shape[3]],
points_[shape[4]],
points_[shape[5]]
);
const point bottomCc(bottom.centre());
const vector bottomNormal(bottom.normal());
const point topCc(top.centre());
if (((topCc-bottomCc)&bottomNormal) < 0)
{
// Flip top and bottom
Swap(shape[0], shape[3]);
Swap(shape[1], shape[4]);
Swap(shape[2], shape[5]);
nSwapped++;
}
}
}
if (nSwapped > 0)
{
WarningInFunction << "Swapped " << nSwapped << " prismatic cells"
<< endl;
}
}
if (debug) if (debug)
{ {
Info<< "Read points:" << points_.size() Info<< "Read points:" << points_.size()