2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2010-05-12 13:27:55 +00:00
|
|
|
\\ / O peration |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / A nd | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
\\/ M anipulation |
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "vtkPV3Foam.H"
|
2010-08-26 14:22:03 +00:00
|
|
|
#include "vtkPV3FoamReader.h"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Foam includes
|
|
|
|
#include "fvMesh.H"
|
2010-08-26 14:22:03 +00:00
|
|
|
#include "Time.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#include "patchZones.H"
|
|
|
|
|
|
|
|
// VTK includes
|
|
|
|
#include "vtkDataArraySelection.h"
|
|
|
|
#include "vtkMultiBlockDataSet.h"
|
|
|
|
#include "vtkRenderer.h"
|
|
|
|
#include "vtkTextActor.h"
|
|
|
|
#include "vtkTextProperty.h"
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
defineTypeNameAndDebug(Foam::vtkPV3Foam, 0);
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
|
|
|
|
|
|
#include "vtkPV3FoamAddToSelection.H"
|
2010-08-26 14:22:03 +00:00
|
|
|
#include "vtkPV3FoamUpdateInfoFields.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
void Foam::vtkPV3Foam::resetCounters()
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
// Reset mesh part ids and sizes
|
|
|
|
partInfoVolume_.reset();
|
|
|
|
partInfoPatches_.reset();
|
|
|
|
partInfoLagrangian_.reset();
|
|
|
|
partInfoCellZones_.reset();
|
|
|
|
partInfoFaceZones_.reset();
|
|
|
|
partInfoPointZones_.reset();
|
|
|
|
partInfoCellSets_.reset();
|
|
|
|
partInfoFaceSets_.reset();
|
|
|
|
partInfoPointSets_.reset();
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
void Foam::vtkPV3Foam::reduceMemory()
|
|
|
|
{
|
|
|
|
forAll(regionPolyDecomp_, i)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
regionPolyDecomp_[i].clear();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
forAll(zonePolyDecomp_, i)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
zonePolyDecomp_[i].clear();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
forAll(csetPolyDecomp_, i)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
csetPolyDecomp_[i].clear();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (!reader_->GetCacheMesh())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
delete meshPtr_;
|
|
|
|
meshPtr_ = NULL;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
int Foam::vtkPV3Foam::setTime(int nRequest, const double requestTimes[])
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<beg> Foam::vtkPV3Foam::setTime(";
|
|
|
|
for (int requestI = 0; requestI < nRequest; ++requestI)
|
|
|
|
{
|
|
|
|
if (requestI)
|
|
|
|
{
|
|
|
|
Info<< ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< requestTimes[requestI];
|
|
|
|
}
|
|
|
|
Info << ") - previousIndex = " << timeIndex_ << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Time& runTime = dbPtr_();
|
|
|
|
|
|
|
|
// Get times list
|
|
|
|
instantList Times = runTime.times();
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
int nearestIndex = timeIndex_;
|
|
|
|
for (int requestI = 0; requestI < nRequest; ++requestI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
int index = Time::findClosestTimeIndex(Times, requestTimes[requestI]);
|
|
|
|
if (index >= 0 && index != timeIndex_)
|
|
|
|
{
|
|
|
|
nearestIndex = index;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
|
|
|
|
if (nearestIndex < 0)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
nearestIndex = 0;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
// see what has changed
|
|
|
|
if (timeIndex_ != nearestIndex)
|
|
|
|
{
|
|
|
|
timeIndex_ = nearestIndex;
|
|
|
|
runTime.setTime(Times[nearestIndex], nearestIndex);
|
|
|
|
|
|
|
|
// the fields change each time
|
|
|
|
fieldsChanged_ = true;
|
|
|
|
|
|
|
|
if (meshPtr_)
|
|
|
|
{
|
|
|
|
if (meshPtr_->readUpdate() != polyMesh::UNCHANGED)
|
|
|
|
{
|
|
|
|
meshChanged_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meshChanged_ = true;
|
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
|
|
|
|
reader_->UpdateProgress(0.05);
|
|
|
|
|
|
|
|
// this seems to be needed for catching Lagrangian fields
|
|
|
|
updateInfo();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<end> Foam::vtkPV3Foam::setTime() - selectedTime="
|
|
|
|
<< Times[nearestIndex].name() << " index=" << timeIndex_
|
|
|
|
<< "/" << Times.size()
|
|
|
|
<< " meshChanged=" << Switch(meshChanged_)
|
|
|
|
<< " fieldsChanged=" << Switch(fieldsChanged_) << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
return nearestIndex;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
void Foam::vtkPV3Foam::updateMeshPartsStatus()
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<beg> Foam::vtkPV3Foam::updateMeshPartsStatus" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
vtkDataArraySelection* selection = reader_->GetPartSelection();
|
|
|
|
label nElem = selection->GetNumberOfArrays();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (partStatus_.size() != nElem)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
partStatus_.setSize(nElem);
|
|
|
|
partStatus_ = false;
|
2010-05-12 13:27:55 +00:00
|
|
|
meshChanged_ = true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// this needs fixing if we wish to re-use the datasets
|
|
|
|
partDataset_.setSize(nElem);
|
|
|
|
partDataset_ = -1;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Read the selected mesh parts (zones, patches ...) and add to list
|
|
|
|
forAll(partStatus_, partId)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
const int setting = selection->GetArraySetting(partId);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (partStatus_[partId] != setting)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
partStatus_[partId] = setting;
|
2010-05-12 13:27:55 +00:00
|
|
|
meshChanged_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< " part[" << partId << "] = "
|
|
|
|
<< partStatus_[partId]
|
|
|
|
<< " : " << selection->GetArrayName(partId) << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<end> Foam::vtkPV3Foam::updateMeshPartsStatus" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
Foam::vtkPV3Foam::vtkPV3Foam
|
|
|
|
(
|
|
|
|
const char* const FileName,
|
|
|
|
vtkPV3FoamReader* reader
|
|
|
|
)
|
|
|
|
:
|
|
|
|
reader_(reader),
|
|
|
|
dbPtr_(NULL),
|
|
|
|
meshPtr_(NULL),
|
2010-08-26 14:22:03 +00:00
|
|
|
meshRegion_(polyMesh::defaultRegion),
|
|
|
|
meshDir_(polyMesh::meshSubDir),
|
2010-05-12 13:27:55 +00:00
|
|
|
timeIndex_(-1),
|
|
|
|
meshChanged_(true),
|
2010-08-26 14:22:03 +00:00
|
|
|
fieldsChanged_(true),
|
|
|
|
partInfoVolume_("unzoned"),
|
|
|
|
partInfoPatches_("patches"),
|
|
|
|
partInfoLagrangian_("lagrangian"),
|
|
|
|
partInfoCellZones_("cellZone"),
|
|
|
|
partInfoFaceZones_("faceZone"),
|
|
|
|
partInfoPointZones_("pointZone"),
|
|
|
|
partInfoCellSets_("cellSet"),
|
|
|
|
partInfoFaceSets_("faceSet"),
|
|
|
|
partInfoPointSets_("pointSet")
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "Foam::vtkPV3Foam::vtkPV3Foam - " << FileName << endl;
|
|
|
|
printMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
// avoid argList and get rootPath/caseName directly from the file
|
|
|
|
fileName fullCasePath(fileName(FileName).path());
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (!isDir(fullCasePath))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fullCasePath == ".")
|
|
|
|
{
|
|
|
|
fullCasePath = cwd();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the case as an environment variable - some BCs might use this
|
|
|
|
if (fullCasePath.name().find("processor", 0) == 0)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
const fileName globalCase = fullCasePath.path();
|
|
|
|
|
|
|
|
setEnv("FOAM_CASE", globalCase, true);
|
|
|
|
setEnv("FOAM_CASENAME", globalCase.name(), true);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setEnv("FOAM_CASE", fullCasePath, true);
|
2010-08-26 14:22:03 +00:00
|
|
|
setEnv("FOAM_CASENAME", fullCasePath.name(), true);
|
|
|
|
}
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
// look for 'case{region}.FOAM'
|
2010-08-26 14:22:03 +00:00
|
|
|
// could be stringent and insist the prefix match the directory name...
|
|
|
|
// Note: cannot use fileName::name() due to the embedded '{}'
|
|
|
|
string caseName(fileName(FileName).lessExt());
|
|
|
|
string::size_type beg = caseName.find_last_of("/{");
|
|
|
|
string::size_type end = caseName.find('}', beg);
|
|
|
|
|
|
|
|
if
|
|
|
|
(
|
|
|
|
beg != string::npos && caseName[beg] == '{'
|
|
|
|
&& end != string::npos && end == caseName.size()-1
|
|
|
|
)
|
|
|
|
{
|
|
|
|
meshRegion_ = caseName.substr(beg+1, end-beg-1);
|
|
|
|
|
|
|
|
// some safety
|
|
|
|
if (!meshRegion_.size())
|
|
|
|
{
|
|
|
|
meshRegion_ = polyMesh::defaultRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meshRegion_ != polyMesh::defaultRegion)
|
|
|
|
{
|
|
|
|
meshDir_ = meshRegion_/polyMesh::meshSubDir;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "fullCasePath=" << fullCasePath << nl
|
2010-08-26 14:22:03 +00:00
|
|
|
<< "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
|
|
|
|
<< "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
|
|
|
|
<< "region=" << meshRegion_ << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create time object
|
|
|
|
dbPtr_.reset
|
|
|
|
(
|
|
|
|
new Time
|
|
|
|
(
|
|
|
|
Time::controlDictName,
|
|
|
|
fileName(fullCasePath.path()),
|
|
|
|
fileName(fullCasePath.name())
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
dbPtr_().functionObjects().off();
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
updateInfo();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
Foam::vtkPV3Foam::~vtkPV3Foam()
|
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "<end> Foam::vtkPV3Foam::~vtkPV3Foam" << endl;
|
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
delete meshPtr_;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
void Foam::vtkPV3Foam::updateInfo()
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<beg> Foam::vtkPV3Foam::updateInfo"
|
|
|
|
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "] timeIndex="
|
|
|
|
<< timeIndex_ << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resetCounters();
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// enable 'internalMesh' on the first call
|
2010-08-26 14:22:03 +00:00
|
|
|
// or preserve the enabled selections
|
|
|
|
stringList enabledEntries;
|
|
|
|
if (!partSelection->GetNumberOfArrays() && !meshPtr_)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
enabledEntries.setSize(1);
|
|
|
|
enabledEntries[0] = "internalMesh";
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
enabledEntries = getSelectedArrayEntries(partSelection);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Clear current mesh parts list
|
|
|
|
partSelection->RemoveAllArrays();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Update mesh parts list - add Lagrangian at the bottom
|
|
|
|
updateInfoInternalMesh();
|
|
|
|
updateInfoPatches();
|
|
|
|
updateInfoSets();
|
|
|
|
updateInfoZones();
|
|
|
|
updateInfoLagrangian();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// restore the enabled selections
|
|
|
|
setSelectedArrayEntries(partSelection, enabledEntries);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
if (meshChanged_)
|
|
|
|
{
|
|
|
|
fieldsChanged_ = true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Update volume, point and lagrangian fields
|
|
|
|
updateInfoFields<fvPatchField, volMesh>
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
|
|
|
reader_->GetVolFieldSelection()
|
|
|
|
);
|
2010-08-26 14:22:03 +00:00
|
|
|
updateInfoFields<pointPatchField, pointMesh>
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
|
|
|
reader_->GetPointFieldSelection()
|
|
|
|
);
|
2010-08-26 14:22:03 +00:00
|
|
|
updateInfoLagrangianFields();
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "<end> Foam::vtkPV3Foam::updateInfo" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
void Foam::vtkPV3Foam::updateFoamMesh()
|
|
|
|
{
|
2010-05-12 13:27:55 +00:00
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<beg> Foam::vtkPV3Foam::updateFoamMesh" << endl;
|
|
|
|
printMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reader_->GetCacheMesh())
|
|
|
|
{
|
|
|
|
delete meshPtr_;
|
|
|
|
meshPtr_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if the FOAM mesh has been created
|
|
|
|
if (!meshPtr_)
|
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "Creating Foam mesh for region " << meshRegion_
|
|
|
|
<< " at time=" << dbPtr_().timeName()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
meshPtr_ = new fvMesh
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
meshRegion_,
|
|
|
|
dbPtr_().timeName(),
|
|
|
|
dbPtr_(),
|
|
|
|
IOobject::MUST_READ
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
meshChanged_ = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "Using existing Foam mesh" << endl;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "<end> Foam::vtkPV3Foam::updateFoamMesh" << endl;
|
|
|
|
printMemory();
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::vtkPV3Foam::Update
|
|
|
|
(
|
2010-08-26 14:22:03 +00:00
|
|
|
vtkMultiBlockDataSet* output,
|
|
|
|
vtkMultiBlockDataSet* lagrangianOutput
|
2010-05-12 13:27:55 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
cout<< "<beg> Foam::vtkPV3Foam::Update - output with "
|
|
|
|
<< output->GetNumberOfBlocks() << " and "
|
|
|
|
<< lagrangianOutput->GetNumberOfBlocks() << " blocks\n";
|
2010-05-12 13:27:55 +00:00
|
|
|
output->Print(cout);
|
2010-08-26 14:22:03 +00:00
|
|
|
lagrangianOutput->Print(cout);
|
2010-05-12 13:27:55 +00:00
|
|
|
printMemory();
|
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
reader_->UpdateProgress(0.1);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Set up mesh parts selection(s)
|
|
|
|
updateMeshPartsStatus();
|
|
|
|
|
|
|
|
reader_->UpdateProgress(0.15);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Update the Foam mesh
|
|
|
|
updateFoamMesh();
|
|
|
|
reader_->UpdateProgress(0.4);
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Convert meshes - start port0 at block=0
|
|
|
|
int blockNo = 0;
|
|
|
|
|
|
|
|
convertMeshVolume(output, blockNo);
|
|
|
|
convertMeshPatches(output, blockNo);
|
|
|
|
reader_->UpdateProgress(0.6);
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
if (reader_->GetIncludeZones())
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
convertMeshCellZones(output, blockNo);
|
|
|
|
convertMeshFaceZones(output, blockNo);
|
|
|
|
convertMeshPointZones(output, blockNo);
|
|
|
|
reader_->UpdateProgress(0.65);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (reader_->GetIncludeSets())
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
convertMeshCellSets(output, blockNo);
|
|
|
|
convertMeshFaceSets(output, blockNo);
|
|
|
|
convertMeshPointSets(output, blockNo);
|
|
|
|
reader_->UpdateProgress(0.7);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
|
|
|
|
#ifdef VTKPV3FOAM_DUALPORT
|
|
|
|
// restart port1 at block=0
|
|
|
|
blockNo = 0;
|
|
|
|
#endif
|
|
|
|
convertMeshLagrangian(lagrangianOutput, blockNo);
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
reader_->UpdateProgress(0.8);
|
|
|
|
|
|
|
|
// Update fields
|
2010-08-26 14:22:03 +00:00
|
|
|
convertVolFields(output);
|
|
|
|
convertPointFields(output);
|
|
|
|
convertLagrangianFields(lagrangianOutput);
|
|
|
|
reader_->UpdateProgress(0.95);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
meshChanged_ = fieldsChanged_ = false;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
void Foam::vtkPV3Foam::CleanUp()
|
|
|
|
{
|
|
|
|
// reclaim some memory
|
|
|
|
reduceMemory();
|
|
|
|
reader_->UpdateProgress(1.0);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double* Foam::vtkPV3Foam::findTimes(int& nTimeSteps)
|
|
|
|
{
|
|
|
|
int nTimes = 0;
|
|
|
|
double* tsteps = NULL;
|
|
|
|
|
|
|
|
if (dbPtr_.valid())
|
|
|
|
{
|
|
|
|
Time& runTime = dbPtr_();
|
|
|
|
instantList timeLst = runTime.times();
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// find the first time for which this mesh appears to exist
|
2010-05-12 13:27:55 +00:00
|
|
|
label timeI = 0;
|
2010-08-26 14:22:03 +00:00
|
|
|
for (; timeI < timeLst.size(); ++timeI)
|
|
|
|
{
|
|
|
|
const word& timeName = timeLst[timeI].name();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if
|
|
|
|
(
|
|
|
|
isFile(runTime.path()/timeName/meshDir_/"points")
|
|
|
|
&& IOobject("points", timeName, meshDir_, runTime).headerOk()
|
|
|
|
)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nTimes = timeLst.size() - timeI;
|
|
|
|
|
|
|
|
// always skip "constant" time if possible
|
|
|
|
if (timeI == 0 && nTimes > 1)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
timeI = 1;
|
|
|
|
--nTimes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nTimes)
|
|
|
|
{
|
|
|
|
tsteps = new double[nTimes];
|
|
|
|
for (label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
|
|
|
|
{
|
|
|
|
tsteps[stepI] = timeLst[timeI].value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
cout<< "no valid dbPtr:\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vector length returned via the parameter
|
|
|
|
nTimeSteps = nTimes;
|
|
|
|
|
|
|
|
return tsteps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
|
|
|
|
{
|
|
|
|
// Remove any patch names previously added to the renderer
|
|
|
|
removePatchNames(renderer);
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// get the display patches, strip off any suffix
|
|
|
|
wordHashSet selectedPatches = getSelected
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
2010-08-26 14:22:03 +00:00
|
|
|
reader_->GetPartSelection(),
|
|
|
|
partInfoPatches_
|
2010-05-12 13:27:55 +00:00
|
|
|
);
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (!selectedPatches.size())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<beg> Foam::vtkPV3Foam::addPatchNames" << nl
|
|
|
|
<<"... add patches: " << selectedPatches << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
const polyBoundaryMesh& pbMesh = meshPtr_->boundaryMesh();
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
// Find the total number of zones
|
|
|
|
// Each zone will take the patch name
|
|
|
|
// Number of zones per patch ... zero zones should be skipped
|
|
|
|
labelList nZones(pbMesh.size(), 0);
|
|
|
|
|
|
|
|
// Per global zone number the average face centre position
|
|
|
|
DynamicList<point> zoneCentre(pbMesh.size());
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "... determining patch zones" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through all patches to determine zones, and centre of each zone
|
|
|
|
forAll(pbMesh, patchI)
|
|
|
|
{
|
|
|
|
const polyPatch& pp = pbMesh[patchI];
|
|
|
|
|
|
|
|
// Only include the patch if it is selected
|
2010-08-26 14:22:03 +00:00
|
|
|
if (!selectedPatches.found(pp.name()))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
continue;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
const labelListList& edgeFaces = pp.edgeFaces();
|
|
|
|
const vectorField& n = pp.faceNormals();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
boolList featEdge(pp.nEdges(), false);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
forAll(edgeFaces, edgeI)
|
|
|
|
{
|
|
|
|
const labelList& eFaces = edgeFaces[edgeI];
|
|
|
|
|
|
|
|
if (eFaces.size() == 1)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
// Note: could also do ones with > 2 faces but this gives
|
|
|
|
// too many zones for baffles
|
|
|
|
featEdge[edgeI] = true;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
else if (mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
|
|
|
|
{
|
|
|
|
featEdge[edgeI] = true;
|
|
|
|
}
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Do topological analysis of patch, find disconnected regions
|
|
|
|
patchZones pZones(pp, featEdge);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
nZones[patchI] = pZones.nZones();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
labelList zoneNFaces(pZones.nZones(), 0);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Save start of information for current patch
|
|
|
|
label patchStart = zoneCentre.size();
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Create storage for additional zone centres
|
|
|
|
forAll(zoneNFaces, zoneI)
|
|
|
|
{
|
|
|
|
zoneCentre.append(vector::zero);
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Do averaging per individual zone
|
|
|
|
forAll(pp, faceI)
|
|
|
|
{
|
|
|
|
label zoneI = pZones[faceI];
|
|
|
|
zoneCentre[patchStart+zoneI] += pp[faceI].centre(pp.points());
|
|
|
|
zoneNFaces[zoneI]++;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
for (label i=0; i<nZones[patchI]; i++)
|
|
|
|
{
|
|
|
|
zoneCentre[patchStart + i] /= zoneNFaces[i];
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
|
|
|
|
// Count number of zones we're actually going to display. This is truncated
|
|
|
|
// to a max per patch
|
|
|
|
|
|
|
|
const label MAXPATCHZONES = 20;
|
|
|
|
|
|
|
|
label displayZoneI = 0;
|
|
|
|
|
|
|
|
forAll(pbMesh, patchI)
|
|
|
|
{
|
|
|
|
displayZoneI += min(MAXPATCHZONES, nZones[patchI]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
zoneCentre.shrink();
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "patch zone centres = " << zoneCentre << nl
|
2010-08-26 14:22:03 +00:00
|
|
|
<< "displayed zone centres = " << displayZoneI << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< "zones per patch = " << nZones << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the size of the patch labels to max number of zones
|
2010-08-26 14:22:03 +00:00
|
|
|
patchTextActorsPtrs_.setSize(displayZoneI);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "constructing patch labels" << endl;
|
|
|
|
}
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
// Actor index
|
|
|
|
displayZoneI = 0;
|
|
|
|
|
|
|
|
// Index in zone centres
|
2010-05-12 13:27:55 +00:00
|
|
|
label globalZoneI = 0;
|
2010-08-26 14:22:03 +00:00
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
forAll(pbMesh, patchI)
|
|
|
|
{
|
|
|
|
const polyPatch& pp = pbMesh[patchI];
|
|
|
|
|
|
|
|
// Only selected patches will have a non-zero number of zones
|
2010-08-26 14:22:03 +00:00
|
|
|
label nDisplayZones = min(MAXPATCHZONES, nZones[patchI]);
|
|
|
|
label increment = 1;
|
|
|
|
if (nZones[patchI] >= MAXPATCHZONES)
|
|
|
|
{
|
|
|
|
increment = nZones[patchI]/MAXPATCHZONES;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (label i = 0; i < nDisplayZones; i++)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
Info<< "patch name = " << pp.name() << nl
|
|
|
|
<< "anchor = " << zoneCentre[globalZoneI] << nl
|
|
|
|
<< "globalZoneI = " << globalZoneI << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkTextActor* txt = vtkTextActor::New();
|
|
|
|
|
|
|
|
txt->SetInput(pp.name().c_str());
|
|
|
|
|
|
|
|
// Set text properties
|
|
|
|
vtkTextProperty* tprop = txt->GetTextProperty();
|
|
|
|
tprop->SetFontFamilyToArial();
|
|
|
|
tprop->BoldOff();
|
|
|
|
tprop->ShadowOff();
|
|
|
|
tprop->SetLineSpacing(1.0);
|
|
|
|
tprop->SetFontSize(12);
|
|
|
|
tprop->SetColor(1.0, 0.0, 0.0);
|
|
|
|
tprop->SetJustificationToCentered();
|
|
|
|
|
|
|
|
// Set text to use 3-D world co-ordinates
|
|
|
|
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
|
|
|
|
|
|
|
|
txt->GetPositionCoordinate()->SetValue
|
|
|
|
(
|
|
|
|
zoneCentre[globalZoneI].x(),
|
|
|
|
zoneCentre[globalZoneI].y(),
|
|
|
|
zoneCentre[globalZoneI].z()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add text to each renderer
|
|
|
|
renderer->AddViewProp(txt);
|
|
|
|
|
|
|
|
// Maintain a list of text labels added so that they can be
|
|
|
|
// removed later
|
2010-08-26 14:22:03 +00:00
|
|
|
patchTextActorsPtrs_[displayZoneI] = txt;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
globalZoneI += increment;
|
|
|
|
displayZoneI++;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize the patch names list to the actual number of patch names added
|
2010-08-26 14:22:03 +00:00
|
|
|
patchTextActorsPtrs_.setSize(displayZoneI);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
2010-08-26 14:22:03 +00:00
|
|
|
Info<< "<end> Foam::vtkPV3Foam::addPatchNames" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::vtkPV3Foam::removePatchNames(vtkRenderer* renderer)
|
|
|
|
{
|
|
|
|
forAll(patchTextActorsPtrs_, patchI)
|
|
|
|
{
|
|
|
|
renderer->RemoveViewProp(patchTextActorsPtrs_[patchI]);
|
|
|
|
patchTextActorsPtrs_[patchI]->Delete();
|
|
|
|
}
|
2010-08-26 14:22:03 +00:00
|
|
|
patchTextActorsPtrs_.clear();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::vtkPV3Foam::PrintSelf(ostream& os, vtkIndent indent) const
|
|
|
|
{
|
|
|
|
os << indent << "Number of nodes: "
|
|
|
|
<< (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n";
|
|
|
|
|
|
|
|
os << indent << "Number of cells: "
|
|
|
|
<< (meshPtr_ ? meshPtr_->nCells() : 0) << "\n";
|
|
|
|
|
|
|
|
os << indent << "Number of available time steps: "
|
|
|
|
<< (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl;
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
os << indent << "mesh region: " << meshRegion_ << "\n";
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ************************************************************************* //
|