Commit 8a2596a0 authored by Mark Olesen's avatar Mark Olesen
Browse files

PV3FoamReader repaired several misfeatures

  - On the first call, select 'internalMesh' and the 'p', 'U' fields.
    This corresponds to a fairly common default case without loading all
    possible fields etc.
  - Include zones should now work without issuing a FatalError when the
    corresponding files are missing. I must have tried too many things
    at once and didn't notice this before.
  - Use ZoneMesh for zone names if the fvMesh is already cached
    (skips re-reading the same files).
  - Change reader description to "OpenFOAM Reader" to distinguish it a bit
    from the vtkOpenFOAMReader built into paraview/vtk
  - Misc. file and method names reorganized

  - Remaining problem:
    mixing internalMesh and cellZones is clunky since there aren't yet
    interpolated point values for cellSets/cellZones. Paraview complains
    about the mismatch, but extracting a block is still okay.

  TODO:
  - multi-port output for Lagrangian
  - hold all the vtk mesh parts (including multiblock) and just pass the
    reference. With this, the pipeline might notice that the geometry is
    actually identical and skip the PVGeometryFilter that takes so long.
parent af5674ac
<ParaViewReaders>
<Reader name="PV3FoamReader"
extensions="OpenFOAM"
file_description="OpenFOAM">
file_description="OpenFOAM Reader">
</Reader>
</ParaViewReaders>
......@@ -2,10 +2,8 @@ vtkPV3Foam.C
vtkPV3FoamAddVolumeMesh.C
vtkPV3FoamAddLagrangianMesh.C
vtkPV3FoamAddPatchMesh.C
vtkPV3FoamAddFaceZoneMesh.C
vtkPV3FoamAddPointZoneMesh.C
vtkPV3FoamAddFaceSetMesh.C
vtkPV3FoamAddPointSetMesh.C
vtkPV3FoamAddZoneMesh.C
vtkPV3FoamAddSetMesh.C
vtkPV3FoamUpdate.C
vtkPV3FoamUpdateInformation.C
vtkPV3FoamConvertMesh.C
......
......@@ -52,7 +52,7 @@ defineTypeNameAndDebug(Foam::vtkPV3Foam, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
#include "vtkPV3FoamAddFields.H"
#include "vtkPV3FoamAddToSelection.H"
#include "vtkPV3FoamUpdateInformationFields.H"
......@@ -233,13 +233,13 @@ void Foam::vtkPV3Foam::updateSelectedRegions()
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
const label nRegions = arraySelection->GetNumberOfArrays();
const label nSelect = arraySelection->GetNumberOfArrays();
selectedRegions_.setSize(nRegions);
selectedRegionDatasetIds_.setSize(nRegions);
selectedRegions_.setSize(nSelect);
selectedRegionDatasetIds_.setSize(nSelect);
// Read the selected patches and add to the region list
for (int regionId=0; regionId < nRegions; ++regionId)
forAll (selectedRegions_, regionId)
{
selectedRegions_[regionId] = arraySelection->GetArraySetting(regionId);
selectedRegionDatasetIds_[regionId] = -1;
......@@ -269,7 +269,13 @@ Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
if (debug)
{
Info<< "selections(";
Info<< "available(";
forAll (selections, elemI)
{
Info<< " \"" << arraySelection->GetArrayName(elemI) << "\"";
}
Info<< " )\n"
<< "selected(";
}
forAll (selections, elemI)
......@@ -319,28 +325,40 @@ Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
if (debug)
{
Info<< "selections(";
Info<< "available(";
for
(
int elemI = selector.start();
elemI < selector.end();
++elemI
)
{
Info<< " \"" << arraySelection->GetArrayName(elemI) << "\"";
}
Info<< " )\n"
<< "selected(";
}
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
int elemI = selector.start();
elemI < selector.end();
++elemI
)
{
if (arraySelection->GetArraySetting(regionId))
if (arraySelection->GetArraySetting(elemI))
{
if (firstWord)
{
selections[nElem] = getFirstWord
(
arraySelection->GetArrayName(regionId)
arraySelection->GetArrayName(elemI)
);
}
else
{
selections[nElem] = arraySelection->GetArrayName(regionId);
selections[nElem] = arraySelection->GetArrayName(elemI);
}
if (debug)
......@@ -400,10 +418,7 @@ void Foam::vtkPV3Foam::setSelectedArrayEntries
<< endl;
}
arraySelection->EnableArray
(
arrayName.c_str()
);
arraySelection->EnableArray(arrayName.c_str());
break;
}
}
......@@ -523,25 +538,37 @@ void Foam::vtkPV3Foam::UpdateInformation()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::UpdateInformation - "
<< "TimeStep = " << reader_->GetTimeStep() << endl;
Info<< "<beg> Foam::vtkPV3Foam::UpdateInformation"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "] TimeStep="
<< reader_->GetTimeStep() << endl;
}
resetCounters();
// preserve the currently selected values
const stringList selectedEntries = getSelectedArrayEntries
(
reader_->GetRegionSelection()
);
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
stringList selectedEntries;
// enable 'internalMesh' on the first call
if (arraySelection->GetNumberOfArrays() == 0)
{
selectedEntries.setSize(1);
selectedEntries[0] = "internalMesh";
}
else
{
// preserve the currently selected values
selectedEntries = getSelectedArrayEntries
(
arraySelection
);
}
// Clear current region list/array
reader_->GetRegionSelection()->RemoveAllArrays();
arraySelection->RemoveAllArrays();
// Update region array
updateInformationInternalMesh();
updateInformationLagrangian();
updateInformationPatches();
if (reader_->GetIncludeSets())
......@@ -554,10 +581,10 @@ void Foam::vtkPV3Foam::UpdateInformation()
updateInformationZones();
}
// Update region selection with the data just read in
// restore the currently enabled values
setSelectedArrayEntries
(
reader_->GetRegionSelection(),
arraySelection,
selectedEntries
);
......@@ -610,9 +637,7 @@ void Foam::vtkPV3Foam::Update
// Convert meshes
convertMeshVolume(output);
convertMeshLagrangian(output);
convertMeshPatches(output);
if (reader_->GetIncludeZones())
......@@ -624,16 +649,14 @@ void Foam::vtkPV3Foam::Update
if (reader_->GetIncludeSets())
{
convertMeshCellSet(output);
convertMeshFaceSet(output);
convertMeshPointSet(output);
convertMeshCellSets(output);
convertMeshFaceSets(output);
convertMeshPointSets(output);
}
// Update fields
updateVolFields(output);
updatePointFields(output);
updateLagrangianFields(output);
if (debug)
......@@ -724,8 +747,7 @@ void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
Info<< "<beg> Foam::vtkPV3Foam::addPatchNames" << endl;
}
const fvMesh& mesh = *meshPtr_;
const polyBoundaryMesh& pbMesh = mesh.boundaryMesh();
const polyBoundaryMesh& pbMesh = meshPtr_->boundaryMesh();
const selectionInfo& selector = selectInfoPatches_;
......
......@@ -29,18 +29,16 @@ Description
Provides a reader interface for OpenFOAM to VTK interaction.
SourceFiles
interpolatePointToCell.C
interpolatePointToCell.H
vtkPV3Foam.C
vtkPV3Foam.H
vtkPV3FoamAddFaceSetMesh.C
vtkPV3FoamAddFaceZoneMesh.C
vtkPV3FoamAddFields.H
vtkPV3FoamI.H
vtkPV3FoamAddLagrangianMesh.C
vtkPV3FoamAddPatchMesh.C
vtkPV3FoamAddPointSetMesh.C
vtkPV3FoamAddPointZoneMesh.C
vtkPV3FoamAddSetMesh.C
vtkPV3FoamAddToSelection.H
vtkPV3FoamAddVolumeMesh.C
vtkPV3FoamAddZoneMesh.C
vtkPV3FoamConvertFaceField.H
vtkPV3FoamConvertLagrangianFields.H
vtkPV3FoamConvertMesh.C
vtkPV3FoamConvertPatchFaceField.H
......@@ -52,7 +50,7 @@ SourceFiles
vtkPV3FoamUpdateInformation.C
vtkPV3FoamUpdateInformationFields.H
// Needed by VTK?
// Needed by VTK:
vtkDataArrayTemplateImplicit.txx
\*---------------------------------------------------------------------------*/
......@@ -64,6 +62,7 @@ SourceFiles
#include "fileName.H"
#include "volPointInterpolation.H"
#include "stringList.H"
#include "wordList.H"
#include "primitivePatch.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
......@@ -304,9 +303,21 @@ private:
//- Set info
void updateInformationSets();
//- Read zone names for zoneType from file
wordList readZoneNames(const word& zoneType);
//- Zone info
void updateInformationZones();
//- Add to paraview array selection
template<class Type>
label addToSelection
(
vtkDataArraySelection *arraySelection,
const IOobjectList&,
const string& suffix = ""
);
//- Field info
template<template<class> class patchType, class meshType>
void updateInformationFields
......@@ -347,20 +358,20 @@ private:
//- Cell zone meshes
void convertMeshCellZones(vtkMultiBlockDataSet* output);
//- Cell zone meshes
//- Face zone meshes
void convertMeshFaceZones(vtkMultiBlockDataSet* output);
//- Cell zone meshes
//- Point zone meshes
void convertMeshPointZones(vtkMultiBlockDataSet* output);
//- Cell set meshes
void convertMeshCellSet(vtkMultiBlockDataSet* output);
void convertMeshCellSets(vtkMultiBlockDataSet* output);
//- Face set meshes
void convertMeshFaceSet(vtkMultiBlockDataSet* output);
void convertMeshFaceSets(vtkMultiBlockDataSet* output);
//- Point set meshes
void convertMeshPointSet(vtkMultiBlockDataSet* output);
void convertMeshPointSets(vtkMultiBlockDataSet* output);
// Add mesh functions
......@@ -430,7 +441,7 @@ private:
//- Add the fields in the selected time directory to the selection
// lists
template<class GeoField>
label addFields
label addObjectsToSelection
(
vtkDataArraySelection* fieldSelection,
const IOobjectList& objects,
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "pointSet.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPointSetMesh
(
const fvMesh& mesh,
const pointSet& pSet,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointSetMesh" << endl;
}
const pointField& meshPoints = mesh.points();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(pSet.size());
forAllConstIter(pointSet, pSet, iter)
{
vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[iter.key()]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addPointSetMesh" << endl;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPointZoneMesh
(
const fvMesh& mesh,
const labelList& pointLabels,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointZoneMesh" << endl;
}
const pointField& meshPoints = mesh.points();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(pointLabels.size());
forAll(pointLabels, pointI)
{
vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[pointLabels[pointI]]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointZoneMesh" << endl;
}
}
// ************************************************************************* //
......@@ -30,6 +30,7 @@ Description
// Foam includes
#include "faceSet.H"
#include "pointSet.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
......@@ -103,4 +104,36 @@ void Foam::vtkPV3Foam::addFaceSetMesh
}
}
void Foam::vtkPV3Foam::addPointSetMesh
(
const fvMesh& mesh,
const pointSet& pSet,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointSetMesh" << endl;
}
const pointField& meshPoints = mesh.points();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(pSet.size());
forAllConstIter(pointSet, pSet, iter)
{
vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[iter.key()]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addPointSetMesh" << endl;
}
}
// ************************************************************************* //
......@@ -22,13 +22,10 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamAddFields_H
#define vtkPV3FoamAddFields_H
#ifndef vtkPV3FoamAddToSelection_H
#define vtkPV3FoamAddToSelection_H
// FOAM includes
#include "SortableList.H"
......@@ -38,48 +35,48 @@ InClass
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
Foam::label Foam::vtkPV3Foam::addFields
template<class Type>
Foam::label Foam::vtkPV3Foam::addToSelection
(
vtkDataArraySelection *fieldSelection,
const IOobjectList& objects,
vtkDataArraySelection *arraySelection,
const IOobjectList& objectLst,
const string& suffix
)
{
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
IOobjectList objects(objectLst.lookupClass(Type::typeName));
SortableList<word> fields(fieldObjects.size());
SortableList<word> objectNames(objects.size());
label count = 0;
forAllConstIter(IOobjectList, fieldObjects, iter)
forAllConstIter(IOobjectList, objects, iter)
{
fields[count++] = iter()->name();
objectNames[count++] = iter()->name();
}
if (count)
{
fields.sort();
objectNames.sort();
forAll(fields, fieldI)
forAll (objectNames, objI)
{
if (debug)
{
Info<<" addField to GUI " << GeoField::typeName
<< ":" << fields[fieldI] << endl;
Info<<" addToSelection<" << Type::typeName << "> to GUI "
<< ":" << objectNames[objI] << endl;
}
if (suffix.size())
{
fieldSelection->AddArray
arraySelection->AddArray
(
(fields[fieldI] + suffix).c_str()
(objectNames[objI] + suffix).c_str()
);
}
else
{
fieldSelection->AddArray
arraySelection->AddArray
(