27 #include "vtkPVFoamReader.h" 35 #include "vtkDataArraySelection.h" 36 #include "vtkMultiBlockDataSet.h" 37 #include "vtkRenderer.h" 38 #include "vtkTextActor.h" 39 #include "vtkTextProperty.h" 54 void Foam::vtkPVFoam::resetCounters()
57 arrayRangeVolume_.reset();
58 arrayRangePatches_.reset();
59 arrayRangeLagrangian_.reset();
60 arrayRangeCellZones_.reset();
61 arrayRangeFaceZones_.reset();
62 arrayRangePointZones_.reset();
63 arrayRangeCellSets_.reset();
64 arrayRangeFaceSets_.reset();
65 arrayRangePointSets_.reset();
69 void Foam::vtkPVFoam::reduceMemory()
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::vtkPVFoam::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::vtkPVFoam::setTime() - selectedTime=" 164 << Times[nearestIndex].name() <<
" index=" << timeIndex_
165 <<
"/" << Times.size()
166 <<
" meshChanged=" << Switch(meshChanged_)
167 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
174 void Foam::vtkPVFoam::updateMeshPartsStatus()
178 Info<<
"<beg> Foam::vtkPVFoam::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::vtkPVFoam::updateMeshPartsStatus" <<
endl;
222 Foam::vtkPVFoam::vtkPVFoam
224 const char*
const FileName,
225 vtkPVFoamReader* 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::vtkPVFoam::vtkPVFoam - " << 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
291 meshRegion_ = caseName.substr(beg+1, end-beg-1);
294 if (meshRegion_.empty())
307 Info<<
"fullCasePath=" << fullCasePath <<
nl 308 <<
"FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl 309 <<
"FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl 310 <<
"region=" << meshRegion_ <<
endl;
319 fileName(fullCasePath.path()),
320 fileName(fullCasePath.name())
324 dbPtr_().functionObjects().off();
336 Info<<
"<end> Foam::vtkPVFoam::~vtkPVFoam" <<
endl;
349 Info<<
"<beg> Foam::vtkPVFoam::updateInfo" 350 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"NULL") <<
"] timeIndex=" 351 << timeIndex_ <<
endl;
356 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
369 if (!partSelection->GetNumberOfArrays() && !meshPtr_)
372 enabledEntries[0] =
"internalMesh";
376 enabledEntries = getSelectedArrayEntries(partSelection);
380 partSelection->RemoveAllArrays();
383 updateInfoInternalMesh(partSelection);
384 updateInfoPatches(partSelection, enabledEntries);
385 updateInfoSets(partSelection);
386 updateInfoZones(partSelection);
387 updateInfoLagrangian(partSelection);
390 setSelectedArrayEntries(partSelection, enabledEntries);
394 fieldsChanged_ =
true;
398 updateInfoFields<fvPatchField, volMesh>
400 reader_->GetVolFieldSelection()
402 updateInfoFields<pointPatchField, pointMesh>
404 reader_->GetPointFieldSelection()
406 updateInfoLagrangianFields();
411 getSelectedArrayEntries(partSelection);
412 Info<<
"<end> Foam::vtkPVFoam::updateInfo" <<
endl;
418 void Foam::vtkPVFoam::updateFoamMesh()
422 Info<<
"<beg> Foam::vtkPVFoam::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::vtkPVFoam::updateFoamMesh" <<
endl;
474 vtkMultiBlockDataSet* output,
475 vtkMultiBlockDataSet* lagrangianOutput
480 cout<<
"<beg> Foam::vtkPVFoam::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 VTKPVFOAM_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();
569 isFile(runTime.path()/timeName/meshDir_/
"points")
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();
666 List<DynamicList<point>> zoneCentre(pbMesh.size());
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);
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";
string getEnv(const word &)
Return environment variable of given name.
List< instant > instantList
List of instants.
List< labelList > labelListList
A List of labelList.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
double * findTimes(int &nTimeSteps)
Allocate and return a list of selected times.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
void renderPatchNames(vtkRenderer *, const bool show)
Add/remove patch names to/from the view.
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
void Update(vtkMultiBlockDataSet *output, vtkMultiBlockDataSet *lagrangianOutput)
List< bool > boolList
Bool container classes.
void CleanUp()
Clean any storage.
List< label > labelList
A List of labels.
HashSet wordHashSet
A HashSet with word keys.
static word controlDictName
The default control dictionary name (normally "controlDict")
graph_traits< Graph >::vertices_size_type size_type
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
List< string > stringList
A List of strings.
void setSize(const label)
Reset size of List.
int setTime(int count, const double requestTimes[])
Set the runTime to the first plausible request time,.
void PrintSelf(ostream &, vtkIndent) const
Debug information.
fileName cwd()
Return current working directory path name.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
IOporosityModelList pZones(mesh)