27 #include "vtkPV4FoamReader.h"
32 #include "patchZones.H"
35 #include "vtkDataArraySelection.h"
36 #include "vtkMultiBlockDataSet.h"
37 #include "vtkRenderer.h"
38 #include "vtkTextActor.h"
39 #include "vtkTextProperty.h"
71 forAll(regionPolyDecomp_, i)
73 regionPolyDecomp_[i].clear();
78 zonePolyDecomp_[i].clear();
83 csetPolyDecomp_[i].clear();
86 if (!reader_->GetCacheMesh())
96 Time& runTime = dbPtr_();
101 int nearestIndex = timeIndex_;
102 for (
int requestI = 0; requestI < nRequest; ++requestI)
105 if (index >= 0 && index != timeIndex_)
107 nearestIndex = index;
112 if (nearestIndex < 0)
119 Info<<
"<beg> Foam::vtkPV4Foam::setTime(";
120 for (
int requestI = 0; requestI < nRequest; ++requestI)
127 Info<< requestTimes[requestI];
129 Info<<
") - previousIndex = " << timeIndex_
130 <<
", nearestIndex = " << nearestIndex <<
endl;
135 if (timeIndex_ != nearestIndex)
137 timeIndex_ = nearestIndex;
138 runTime.setTime(Times[nearestIndex], nearestIndex);
141 fieldsChanged_ =
true;
155 reader_->UpdateProgress(0.05);
163 Info<<
"<end> Foam::vtkPV4Foam::setTime() - selectedTime="
164 << Times[nearestIndex].name() <<
" index=" << timeIndex_
165 <<
"/" << Times.size()
166 <<
" meshChanged=" << Switch(meshChanged_)
167 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
178 Info<<
"<beg> Foam::vtkPV4Foam::updateMeshPartsStatus" <<
endl;
181 vtkDataArraySelection* selection = reader_->GetPartSelection();
182 label nElem = selection->GetNumberOfArrays();
184 if (partStatus_.size() != nElem)
186 partStatus_.setSize(nElem);
192 partDataset_.setSize(nElem);
196 forAll(partStatus_, partId)
198 const int setting = selection->GetArraySetting(partId);
200 if (partStatus_[partId] != setting)
202 partStatus_[partId] = setting;
208 Info<<
" part[" << partId <<
"] = "
209 << partStatus_[partId]
210 <<
" : " << selection->GetArrayName(partId) <<
endl;
215 Info<<
"<end> Foam::vtkPV4Foam::updateMeshPartsStatus" <<
endl;
224 const char*
const FileName,
225 vtkPV4FoamReader* reader
231 meshRegion_(polyMesh::defaultRegion),
232 meshDir_(polyMesh::meshSubDir),
235 fieldsChanged_(true),
236 arrayRangeVolume_(
"unzoned"),
237 arrayRangePatches_(
"patches"),
238 arrayRangeLagrangian_(
"lagrangian"),
239 arrayRangeCellZones_(
"cellZone"),
240 arrayRangeFaceZones_(
"faceZone"),
241 arrayRangePointZones_(
"pointZone"),
242 arrayRangeCellSets_(
"cellSet"),
243 arrayRangeFaceSets_(
"faceSet"),
244 arrayRangePointSets_(
"pointSet")
248 Info<<
"Foam::vtkPV4Foam::vtkPV4Foam - " << FileName <<
endl;
253 fileName fullCasePath(fileName(FileName).
path());
255 if (!
isDir(fullCasePath))
259 if (fullCasePath ==
".")
261 fullCasePath =
cwd();
265 if (fullCasePath.name().find(
"processor", 0) == 0)
267 const fileName globalCase = fullCasePath.path();
269 setEnv(
"FOAM_CASE", globalCase,
true);
270 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
274 setEnv(
"FOAM_CASE", fullCasePath,
true);
275 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
281 string caseName(fileName(FileName).lessExt());
287 beg != string::npos && caseName[beg] ==
'{'
288 && end != string::npos && end == caseName.size()-1
307 Info<<
"fullCasePath=" << fullCasePath <<
nl
308 <<
"FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl
309 <<
"FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl
319 fileName(fullCasePath.path()),
320 fileName(fullCasePath.name())
324 dbPtr_().functionObjects().off();
336 Info<<
"<end> Foam::vtkPV4Foam::~vtkPV4Foam" <<
endl;
349 Info<<
"<beg> Foam::vtkPV4Foam::updateInfo"
350 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"NULL") <<
"] timeIndex="
351 << timeIndex_ <<
endl;
356 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
369 if (!partSelection->GetNumberOfArrays() && !meshPtr_)
372 enabledEntries[0] =
"internalMesh";
380 partSelection->RemoveAllArrays();
383 updateInfoInternalMesh(partSelection);
384 updateInfoPatches(partSelection, enabledEntries);
385 updateInfoSets(partSelection);
386 updateInfoZones(partSelection);
387 updateInfoLagrangian(partSelection);
394 fieldsChanged_ =
true;
398 updateInfoFields<fvPatchField, volMesh>
400 reader_->GetVolFieldSelection()
402 updateInfoFields<pointPatchField, pointMesh>
404 reader_->GetPointFieldSelection()
406 updateInfoLagrangianFields();
412 Info<<
"<end> Foam::vtkPV4Foam::updateInfo" <<
endl;
422 Info<<
"<beg> Foam::vtkPV4Foam::updateFoamMesh" <<
endl;
426 if (!reader_->GetCacheMesh())
437 Info<<
"Creating OpenFOAM mesh for region " << meshRegion_
438 <<
" at time=" << dbPtr_().timeName()
443 meshPtr_ =
new fvMesh
460 Info<<
"Using existing OpenFOAM mesh" <<
endl;
466 Info<<
"<end> Foam::vtkPV4Foam::updateFoamMesh" <<
endl;
474 vtkMultiBlockDataSet* output,
475 vtkMultiBlockDataSet* lagrangianOutput
480 cout<<
"<beg> Foam::vtkPV4Foam::Update - output with "
481 << output->GetNumberOfBlocks() <<
" and "
482 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks\n";
484 lagrangianOutput->Print(cout);
487 reader_->UpdateProgress(0.1);
490 updateMeshPartsStatus();
492 reader_->UpdateProgress(0.15);
496 reader_->UpdateProgress(0.4);
501 convertMeshVolume(output, blockNo);
502 convertMeshPatches(output, blockNo);
503 reader_->UpdateProgress(0.6);
505 if (reader_->GetIncludeZones())
507 convertMeshCellZones(output, blockNo);
508 convertMeshFaceZones(output, blockNo);
509 convertMeshPointZones(output, blockNo);
510 reader_->UpdateProgress(0.65);
513 if (reader_->GetIncludeSets())
515 convertMeshCellSets(output, blockNo);
516 convertMeshFaceSets(output, blockNo);
517 convertMeshPointSets(output, blockNo);
518 reader_->UpdateProgress(0.7);
521 #ifdef VTKPV4FOAM_DUALPORT
525 convertMeshLagrangian(lagrangianOutput, blockNo);
527 reader_->UpdateProgress(0.8);
530 convertVolFields(output);
531 convertPointFields(output);
532 convertLagrangianFields(lagrangianOutput);
537 reader_->UpdateProgress(0.95);
539 meshChanged_ = fieldsChanged_ =
false;
547 reader_->UpdateProgress(1.0);
554 double* tsteps = NULL;
558 Time& runTime = dbPtr_();
563 for (; timeI < timeLst.size(); ++timeI)
565 const word&
timeName = timeLst[timeI].name();
570 && IOobject(
"points",
timeName, meshDir_, runTime).headerOk()
577 nTimes = timeLst.size() - timeI;
580 if (timeI == 0 && nTimes > 1)
582 if (timeLst[timeI].
name() == runTime.constant())
591 if (nTimes > 1 && reader_->GetSkipZeroTime())
593 if (
mag(timeLst[timeI].value()) < SMALL)
602 tsteps =
new double[nTimes];
603 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
605 tsteps[stepI] = timeLst[timeI].value();
613 cout<<
"no valid dbPtr:\n";
626 vtkRenderer* renderer,
637 forAll(patchTextActorsPtrs_, patchI)
639 renderer->RemoveViewProp(patchTextActorsPtrs_[patchI]);
640 patchTextActorsPtrs_[patchI]->Delete();
642 patchTextActorsPtrs_.clear();
649 reader_->GetPartSelection(),
653 if (selectedPatches.empty())
658 const polyBoundaryMesh& pbMesh = meshPtr_->boundaryMesh();
672 const polyPatch& pp = pbMesh[patchI];
675 if (!selectedPatches.found(pp.name()))
683 boolList featEdge(pp.nEdges(),
false);
687 const labelList& eFaces = edgeFaces[edgeI];
689 if (eFaces.size() == 1)
693 featEdge[edgeI] =
true;
695 else if (
mag(
n[eFaces[0]] &
n[eFaces[1]]) < 0.5)
697 featEdge[edgeI] =
true;
702 patchZones
pZones(pp, featEdge);
704 nZones[patchI] =
pZones.nZones();
718 zoneCentre[patchI][zoneI] += pp[faceI].centre(pp.points());
722 forAll(zoneCentre[patchI], zoneI)
724 zoneCentre[patchI][zoneI] /= zoneNFaces[zoneI];
731 const label MAXPATCHZONES = 20;
733 label displayZoneI = 0;
737 displayZoneI +=
min(MAXPATCHZONES, nZones[patchI]);
742 Info<<
"displayed zone centres = " << displayZoneI <<
nl
743 <<
"zones per patch = " << nZones <<
endl;
747 patchTextActorsPtrs_.setSize(displayZoneI);
751 Info<<
"constructing patch labels" <<
endl;
759 const polyPatch& pp = pbMesh[patchI];
761 label globalZoneI = 0;
764 label nDisplayZones =
min(MAXPATCHZONES, nZones[patchI]);
766 if (nZones[patchI] >= MAXPATCHZONES)
768 increment = nZones[patchI]/MAXPATCHZONES;
771 for (
label i = 0; i < nDisplayZones; i++)
775 Info<<
"patch name = " << pp.name() <<
nl
776 <<
"anchor = " << zoneCentre[patchI][globalZoneI] <<
nl
777 <<
"globalZoneI = " << globalZoneI <<
endl;
782 txt->SetInput(pp.name().c_str());
785 vtkTextProperty* tprop = txt->GetTextProperty();
786 tprop->SetFontFamilyToArial();
789 tprop->SetLineSpacing(1.0);
790 tprop->SetFontSize(12);
791 tprop->SetColor(1.0, 0.0, 0.0);
792 tprop->SetJustificationToCentered();
795 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
797 txt->GetPositionCoordinate()->SetValue
799 zoneCentre[patchI][globalZoneI].
x(),
800 zoneCentre[patchI][globalZoneI].
y(),
801 zoneCentre[patchI][globalZoneI].z()
805 renderer->AddViewProp(txt);
809 patchTextActorsPtrs_[displayZoneI] = txt;
811 globalZoneI += increment;
817 patchTextActorsPtrs_.setSize(displayZoneI);
824 os <<
indent <<
"Number of nodes: "
825 << (meshPtr_ ? meshPtr_->nPoints() : 0) <<
"\n";
827 os <<
indent <<
"Number of cells: "
828 << (meshPtr_ ? meshPtr_->nCells() : 0) <<
"\n";
830 os <<
indent <<
"Number of available time steps: "
831 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
833 os <<
indent <<
"mesh region: " << meshRegion_ <<
"\n";