openfoam/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMeshUtils.C
Mark Olesen 81891675ea Commit Paraview enhancements - quit working on sets/zones frills
- Include Sets/Zones now scans immediately to refresh the list of available
  mesh parts. Unfortunately, this also causes the object panel to be
  modified, even although the selection doesn't acutally need to change.
  This seems to be due to how the pqNamedWidgets are getting the information
  from the proxy properties. I can't figure if it's possible to acheive what
  I want, but we can probably live with the current implementation.

  After IncludeZones, simply us 'Reset' to undo the spurious GUI changes.
  Works fine - just looks a bit silly.

- Added 'Refresh' button to rescan for new times/fields.  Good for
  post-processing ongoing calculations without exiting the reader.

- Added 'Skip Zero Time' checkbox: many (some) calculations have
  data missing at time=0 (eg, rho, lagrangian, etc). This provides
  a convenient way to skip over this time.

- Future?:
  We could probably pick up favourite default values for these switches from
  ~OpenFOAM/controlDict, from a case system/paraview, or simply by making
  the casename.OpenFOAM also be an OpenFOAM dictionary with the settings.
2009-11-24 00:09:07 +01:00

359 lines
8.2 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 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
Misc helper methods and utilities
\*---------------------------------------------------------------------------*/
#include "vtkPV3blockMesh.H"
#include "vtkPV3blockMeshReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
//! @cond fileScope
// Extract up to the first non-word characters
inline word getFirstWord(const char* str)
{
if (str)
{
label n = 0;
while (str[n] && word::valid(str[n]))
{
++n;
}
return word(str, n, true);
}
else
{
return word::null;
}
}
//! @endcond fileScope
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::vtkPV3blockMesh::AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const arrayRange& range,
const label datasetNo,
const std::string& datasetName
)
{
const int blockNo = range.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (!block)
{
if (blockDO)
{
FatalErrorIn("Foam::vtkPV3blockMesh::AddToBlock")
<< "Block already has a vtkDataSet assigned to it"
<< endl;
return;
}
block = vtkMultiBlockDataSet::New();
output->SetBlock(blockNo, block);
block->Delete();
}
if (debug)
{
Info<< "block[" << blockNo << "] has "
<< block->GetNumberOfBlocks()
<< " datasets prior to adding set " << datasetNo
<< " with name: " << datasetName << endl;
}
block->SetBlock(datasetNo, dataset);
// name the block when assigning dataset 0
if (datasetNo == 0)
{
output->GetMetaData(blockNo)->Set
(
vtkCompositeDataSet::NAME(),
range.name()
);
}
if (datasetName.size())
{
block->GetMetaData(datasetNo)->Set
(
vtkCompositeDataSet::NAME(),
datasetName.c_str()
);
}
}
vtkDataSet* Foam::vtkPV3blockMesh::GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo
)
{
const int blockNo = range.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
}
return 0;
}
// ununsed at the moment
Foam::label Foam::vtkPV3blockMesh::GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const arrayRange& range
)
{
const int blockNo = range.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return block->GetNumberOfBlocks();
}
return 0;
}
Foam::wordHashSet Foam::vtkPV3blockMesh::getSelected
(
vtkDataArraySelection* select
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI=0; elemI < nElem; ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::wordHashSet Foam::vtkPV3blockMesh::getSelected
(
vtkDataArraySelection* select,
const arrayRange& range
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI = range.start(); elemI < range.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::stringList Foam::vtkPV3blockMesh::getSelectedArrayEntries
(
vtkDataArraySelection* select
)
{
stringList selections(select->GetNumberOfArrays());
label nElem = 0;
forAll(selections, elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
label nElem = select->GetNumberOfArrays();
Info<< "available(";
for (int elemI = 0; elemI < nElem; ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
Foam::stringList Foam::vtkPV3blockMesh::getSelectedArrayEntries
(
vtkDataArraySelection* select,
const arrayRange& range
)
{
stringList selections(range.size());
label nElem = 0;
for (int elemI = range.start(); elemI < range.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
Info<< "available(";
for (int elemI = range.start(); elemI < range.end(); ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
void Foam::vtkPV3blockMesh::setSelectedArrayEntries
(
vtkDataArraySelection* select,
const stringList& selections
)
{
const int nElem = select->GetNumberOfArrays();
select->DisableAllArrays();
// Loop through entries, setting values from selectedEntries
for (int elemI=0; elemI < nElem; ++elemI)
{
string arrayName(select->GetArrayName(elemI));
forAll(selections, elemI)
{
if (selections[elemI] == arrayName)
{
select->EnableArray(arrayName.c_str());
break;
}
}
}
}
void Foam::vtkPV3blockMesh::updateBoolListStatus
(
boolList& status,
vtkDataArraySelection* selection
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV3blockMesh::updateBoolListStatus" << endl;
}
const label nElem = selection->GetNumberOfArrays();
if (status.size() != nElem)
{
status.setSize(nElem);
status = false;
}
forAll(status, elemI)
{
const int setting = selection->GetArraySetting(elemI);
status[elemI] = setting;
if (debug)
{
Info<< " part[" << elemI << "] = "
<< status[elemI]
<< " : " << selection->GetArrayName(elemI) << endl;
}
}
if (debug)
{
Info<< "<end> Foam::vtkPV3blockMesh::updateBoolListStatus" << endl;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //