Commit 321a91f4 authored by Mark Olesen's avatar Mark Olesen

PV3FoamReader fixes

  - added printMemory() method to aid debugging memory used
  - call UpdateInformation() if the mesh has changed
  - automatic activation of "internalMesh", "p", "U"
    is suppressed if a fvMesh is cached. Otherwise,
    appearing/disappearing volFields can cause a crash

  Note:
  The message "had to make up a selection value" that sometimes occurs
  seems to be paraview related (see paraview mailing list),
parent ad009d0c
......@@ -32,6 +32,7 @@ License
#include "IOobjectList.H"
#include "patchZones.H"
#include "vtkPV3FoamReader.h"
#include "IFstream.H"
// VTK includes
#include "vtkCharArray.h"
......@@ -212,6 +213,8 @@ bool Foam::vtkPV3Foam::setTime(const double& requestedTime)
if (meshPtr_->readUpdate() != polyMesh::UNCHANGED)
{
meshChanged_ = true;
// patches, zones etc might have changed
UpdateInformation();
}
}
else
......@@ -396,7 +399,6 @@ Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
Info<< " )" << endl;
}
selections.setSize(nElem);
return selections;
}
......@@ -480,6 +482,7 @@ Foam::vtkPV3Foam::vtkPV3Foam
if (debug)
{
Info<< "Foam::vtkPV3Foam::vtkPV3Foam - " << FileName << endl;
printMemory();
}
// avoid argList and get rootPath/caseName directly from the file
......@@ -565,7 +568,7 @@ void Foam::vtkPV3Foam::UpdateInformation()
stringList selectedEntries;
// enable 'internalMesh' on the first call
if (arraySelection->GetNumberOfArrays() == 0)
if (arraySelection->GetNumberOfArrays() == 0 && !meshPtr_)
{
selectedEntries.setSize(1);
selectedEntries[0] = "internalMesh";
......@@ -647,6 +650,7 @@ void Foam::vtkPV3Foam::Update
output->Print(cout);
cout<< " has " << output->GetNumberOfBlocks() << " blocks\n";
printMemory();
}
// Set up region selection(s)
......@@ -713,6 +717,7 @@ void Foam::vtkPV3Foam::Update
output->GetInformation()->Print(cout);
cout<<"ShouldIReleaseData :" << output->ShouldIReleaseData() << "\n";
printMemory();
}
meshChanged_ = fieldsChanged_ = false;
......@@ -787,7 +792,7 @@ void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
if (debug)
{
Info<<"... add patches: " << selectedPatches <<endl;
Info<<"... add patches: " << selectedPatches << endl;
}
// Find the total number of zones
......@@ -876,8 +881,8 @@ void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
if (debug)
{
Info<< "patch zone centres = " << zoneCentre << endl;
Info<< "zones per patch = " << nZones << endl;
Info<< "patch zone centres = " << zoneCentre << nl
<< "zones per patch = " << nZones << endl;
}
// Set the size of the patch labels to max number of zones
......@@ -898,9 +903,9 @@ void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
{
if (debug)
{
Info<< "patch name = " << pp.name() << endl;
Info<< "anchor = " << zoneCentre[globalZoneI] << endl;
Info<< "globalZoneI = " << globalZoneI << endl;
Info<< "patch name = " << pp.name() << nl
<< "anchor = " << zoneCentre[globalZoneI] << nl
<< "globalZoneI = " << globalZoneI << endl;
}
vtkTextActor* txt = vtkTextActor::New();
......@@ -967,14 +972,56 @@ void Foam::vtkPV3Foam::removePatchNames(vtkRenderer* renderer)
void Foam::vtkPV3Foam::PrintSelf(ostream& os, vtkIndent indent) const
{
os << indent << "Number of meshes: " << nMesh_ << "\n";
os << indent << "Number of nodes: "
os << indent << "Number of nodes: "
<< (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n";
os << indent << "Number of cells: "
os << indent << "Number of cells: "
<< (meshPtr_ ? meshPtr_->nCells() : 0) << "\n";
os << indent << "Number of available time steps: "
<< (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl;
}
// parse these bits of info from /proc/meminfo (Linux)
//
// MemTotal: 2062660 kB
// MemFree: 1124400 kB
//
// used = MemTotal - MemFree is what the free(1) uses.
//
void Foam::vtkPV3Foam::printMemory()
{
const char* meminfo = "/proc/meminfo";
if (exists(meminfo))
{
IFstream is(meminfo);
label memTotal = 0;
label memFree = 0;
string line;
while (is.getLine(line).good())
{
char tag[32];
int value;
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
{
if (!strcmp(tag, "MemTotal:"))
{
memTotal = value;
}
else if (!strcmp(tag, "MemFree:"))
{
memFree = value;
}
}
}
Info << "memUsed: " << (memTotal - memFree) << " kB\n";
}
}
// ************************************************************************* //
......@@ -628,7 +628,7 @@ public:
// Member Functions
//- Update
//- Update
void UpdateInformation();
void Update(vtkMultiBlockDataSet* output);
......@@ -653,6 +653,9 @@ public:
//- Debug information
void PrintSelf(ostream&, vtkIndent) const;
//- Simple memory used debugging information
static void printMemory();
};
......
......@@ -52,6 +52,7 @@ void Foam::vtkPV3Foam::addLagrangianMesh
{
Info<< "<beg> Foam::vtkPV3Foam::addLagrangianMesh - timePath "
<< mesh.time().timePath()/"lagrangian" << endl;
printMemory();
}
fileNameList cloudDirs
......@@ -103,6 +104,7 @@ void Foam::vtkPV3Foam::addLagrangianMesh
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addLagrangianMesh" << endl;
printMemory();
}
}
......
......@@ -49,6 +49,7 @@ void Foam::vtkPV3Foam::addPatchMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPatchMesh - " << p.name() << endl;
printMemory();
}
// Convert Foam mesh vertices to VTK
......@@ -88,6 +89,7 @@ void Foam::vtkPV3Foam::addPatchMesh
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addPatchMesh - " << p.name() << endl;
printMemory();
}
}
......
......@@ -50,6 +50,7 @@ void Foam::vtkPV3Foam::addFaceSetMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addFaceSetMesh" << endl;
printMemory();
}
// Construct primitivePatch of faces in fSet.
......@@ -101,6 +102,7 @@ void Foam::vtkPV3Foam::addFaceSetMesh
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addFaceSetMesh" << endl;
printMemory();
}
}
......@@ -115,6 +117,7 @@ void Foam::vtkPV3Foam::addPointSetMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointSetMesh" << endl;
printMemory();
}
const pointField& meshPoints = mesh.points();
......@@ -133,6 +136,7 @@ void Foam::vtkPV3Foam::addPointSetMesh
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addPointSetMesh" << endl;
printMemory();
}
}
......
......@@ -55,6 +55,7 @@ void Foam::vtkPV3Foam::addVolumeMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addVolumeMesh" << endl;
printMemory();
}
// Number of additional points needed by the decomposition of polyhedra
......@@ -354,6 +355,7 @@ void Foam::vtkPV3Foam::addVolumeMesh
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addVolumeMesh" << endl;
printMemory();
}
}
......
......@@ -49,6 +49,7 @@ void Foam::vtkPV3Foam::addFaceZoneMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addFaceZoneMesh" << endl;
printMemory();
}
// Construct primitivePatch of faces in fSet.
......@@ -99,6 +100,7 @@ void Foam::vtkPV3Foam::addFaceZoneMesh
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::addFaceZoneMesh" << endl;
printMemory();
}
}
......@@ -114,6 +116,7 @@ void Foam::vtkPV3Foam::addPointZoneMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointZoneMesh" << endl;
printMemory();
}
const pointField& meshPoints = mesh.points();
......@@ -132,6 +135,7 @@ void Foam::vtkPV3Foam::addPointZoneMesh
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::addPointZoneMesh" << endl;
printMemory();
}
}
......
......@@ -51,6 +51,7 @@ void Foam::vtkPV3Foam::convertMeshVolume
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshVolume" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoVolume_;
......@@ -92,6 +93,7 @@ void Foam::vtkPV3Foam::convertMeshVolume
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshVolume" << endl;
printMemory();
}
}
......@@ -104,6 +106,7 @@ void Foam::vtkPV3Foam::convertMeshLagrangian
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoLagrangian_;
......@@ -139,6 +142,7 @@ void Foam::vtkPV3Foam::convertMeshLagrangian
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
printMemory();
}
}
......@@ -151,6 +155,7 @@ void Foam::vtkPV3Foam::convertMeshPatches
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshPatches" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoPatches_;
......@@ -209,6 +214,7 @@ void Foam::vtkPV3Foam::convertMeshPatches
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshPatches" << endl;
printMemory();
}
}
......@@ -221,6 +227,7 @@ void Foam::vtkPV3Foam::convertMeshCellZones
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoCellZones_;
......@@ -281,6 +288,7 @@ void Foam::vtkPV3Foam::convertMeshCellZones
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
printMemory();
}
}
......@@ -293,6 +301,7 @@ void Foam::vtkPV3Foam::convertMeshCellSets
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoCellSets_;
......@@ -360,6 +369,7 @@ void Foam::vtkPV3Foam::convertMeshCellSets
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
printMemory();
}
}
......@@ -372,6 +382,7 @@ void Foam::vtkPV3Foam::convertMeshFaceZones
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoFaceZones_;
......@@ -422,6 +433,7 @@ void Foam::vtkPV3Foam::convertMeshFaceZones
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
printMemory();
}
}
......@@ -434,6 +446,7 @@ void Foam::vtkPV3Foam::convertMeshFaceSets
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceSets" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoFaceSets_;
......@@ -492,6 +505,7 @@ void Foam::vtkPV3Foam::convertMeshFaceSets
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceSets" << endl;
printMemory();
}
}
......@@ -504,6 +518,7 @@ void Foam::vtkPV3Foam::convertMeshPointZones
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoPointZones_;
......@@ -554,6 +569,7 @@ void Foam::vtkPV3Foam::convertMeshPointZones
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
printMemory();
}
}
......@@ -567,6 +583,7 @@ void Foam::vtkPV3Foam::convertMeshPointSets
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
printMemory();
}
const selectionInfo& selector = selectInfoPointSets_;
......@@ -625,6 +642,7 @@ void Foam::vtkPV3Foam::convertMeshPointSets
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
printMemory();
}
}
......
......@@ -48,6 +48,7 @@ void Foam::vtkPV3Foam::updateFoamMesh()
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::updateFoamMesh" << endl;
printMemory();
}
if (!reader_->GetCacheMesh())
......@@ -86,6 +87,7 @@ void Foam::vtkPV3Foam::updateFoamMesh()
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::updateFoamMesh" << endl;
printMemory();
}
}
......@@ -98,6 +100,7 @@ void Foam::vtkPV3Foam::updateVolFields
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::updateVolFields" << endl;
printMemory();
}
const fvMesh& mesh = *meshPtr_;
......@@ -162,6 +165,7 @@ void Foam::vtkPV3Foam::updateVolFields
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::updateVolFields" << endl;
printMemory();
}
}
......@@ -174,6 +178,7 @@ void Foam::vtkPV3Foam::updatePointFields
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::updatePointFields" << endl;
printMemory();
}
const fvMesh& mesh = *meshPtr_;
......@@ -213,6 +218,7 @@ void Foam::vtkPV3Foam::updatePointFields
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::updatePointFields" << endl;
printMemory();
}
}
......@@ -225,6 +231,7 @@ void Foam::vtkPV3Foam::updateLagrangianFields
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::updateLagrangianFields" << endl;
printMemory();
}
const fvMesh& mesh = *meshPtr_;
......@@ -276,6 +283,7 @@ void Foam::vtkPV3Foam::updateLagrangianFields
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::updateLagrangianFields" << endl;
printMemory();
}
}
......
......@@ -211,42 +211,68 @@ void Foam::vtkPV3Foam::updateInformationPatches()
}
vtkDataArraySelection *arraySelection = reader_->GetRegionSelection();
// Read patches
polyBoundaryMeshEntries patchEntries
(
IOobject
(
"boundary",
dbPtr_().findInstance(polyMesh::meshSubDir, "boundary"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
selectInfoPatches_ = arraySelection->GetNumberOfArrays();
int nPatches = 0;
// Start regions at patches
forAll (patchEntries, entryI)
if (meshPtr_)
{
label nFaces(readLabel(patchEntries[entryI].dict().lookup("nFaces")));
// Valid patch if nFace > 0
if (nFaces)
const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
forAll (patches, patchI)
{
// Add patch to GUI region list
arraySelection->AddArray
const polyPatch& pp = patches[patchI];
if (pp.size())
{
// Add patch to GUI region list
arraySelection->AddArray
(
(pp.name() + " - patch").c_str()
);
++nPatches;
}
}
}
else
{
// Read patches
polyBoundaryMeshEntries patchEntries
(
IOobject
(
(patchEntries[entryI].keyword() + " - patch").c_str()
"boundary",
dbPtr_().findInstance(polyMesh::meshSubDir, "boundary"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
// Start regions at patches
forAll (patchEntries, entryI)
{
label nFaces
(
readLabel(patchEntries[entryI].dict().lookup("nFaces"))
);
++nPatches;
// Valid patch if nFace > 0
if (nFaces)
{
// Add patch to GUI region list
arraySelection->AddArray
(
(patchEntries[entryI].keyword() + " - patch").c_str()
);
++nPatches;
}
}
}
selectInfoPatches_ += nPatches;
if (debug)
......@@ -269,26 +295,26 @@ void Foam::vtkPV3Foam::updateInformationZones()
vtkDataArraySelection *arraySelection = reader_->GetRegionSelection();
wordList zoneNames;
wordList namesLst;
//
// cellZones information
// ~~~~~~~~~~~~~~~~~~~~~
if (meshPtr_)
{
zoneNames = meshPtr_->cellZones().names();
namesLst = meshPtr_->cellZones().names();
}
else
{
zoneNames = readZoneNames("cellZones");
namesLst = readZoneNames("cellZones");
}
selectInfoCellZones_ = arraySelection->GetNumberOfArrays();
forAll (zoneNames, zoneI)
forAll (namesLst, elemI)
{
arraySelection->AddArray((zoneNames[zoneI] + " - cellZone").c_str());
arraySelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
}
selectInfoCellZones_ += zoneNames.size();
selectInfoCellZones_ += namesLst.size();
zoneSuperCells_.setSize(selectInfoCellZones_.size());
......@@ -297,19 +323,19 @@ void Foam::vtkPV3Foam::updateInformationZones()
// ~~~~~~~~~~~~~~~~~~~~~
if (meshPtr_)
{
zoneNames = meshPtr_->faceZones().names();
namesLst = meshPtr_->faceZones().names();
}
else
{
zoneNames = readZoneNames("faceZones");
namesLst = readZoneNames("faceZones");
}
selectInfoFaceZones_ = arraySelection->GetNumberOfArrays();
forAll (zoneNames, zoneI)
forAll (namesLst, elemI)
{
arraySelection->AddArray((zoneNames[zoneI] + " - faceZone").c_str());
arraySelection->AddArray((namesLst[elemI] + " - faceZone").c_str());
}
selectInfoFaceZones_ += zoneNames.size();
selectInfoFaceZones_ += namesLst.size();
//
......@@ -317,19 +343,19 @@ void Foam::vtkPV3Foam::updateInformationZones()
// ~~~~~~~~~~~~~~~~~~~~~~
if (meshPtr_)
{
zoneNames = meshPtr_->pointZones().names();
namesLst = meshPtr_->pointZones().names();
}
else
{
zoneNames = readZoneNames("pointZones");