27 #include "vtkPVFoamReader.h" 36 #include "vtkDataArraySelection.h" 37 #include "vtkMultiBlockDataSet.h" 38 #include "vtkRenderer.h" 39 #include "vtkTextActor.h" 40 #include "vtkTextProperty.h" 55 void Foam::vtkPVFoam::resetCounters()
58 arrayRangeVolume_.reset();
59 arrayRangePatches_.reset();
60 arrayRangeLagrangian_.reset();
61 arrayRangeCellZones_.reset();
62 arrayRangeFaceZones_.reset();
63 arrayRangePointZones_.reset();
64 arrayRangeCellSets_.reset();
65 arrayRangeFaceSets_.reset();
66 arrayRangePointSets_.reset();
70 void Foam::vtkPVFoam::reduceMemory()
72 forAll(regionPolyDecomp_, i)
74 regionPolyDecomp_[i].clear();
79 zonePolyDecomp_[i].clear();
84 csetPolyDecomp_[i].clear();
87 if (!reader_->GetCacheMesh())
97 Time& runTime = dbPtr_();
102 int nearestIndex = timeIndex_;
103 for (
int requestI = 0; requestI < nRequest; ++requestI)
106 if (index >= 0 && index != timeIndex_)
108 nearestIndex = index;
113 if (nearestIndex < 0)
120 Info<<
"<beg> Foam::vtkPVFoam::setTime(";
121 for (
int requestI = 0; requestI < nRequest; ++requestI)
128 Info<< requestTimes[requestI];
130 Info<<
") - previousIndex = " << timeIndex_
131 <<
", nearestIndex = " << nearestIndex <<
endl;
136 if (timeIndex_ != nearestIndex)
138 timeIndex_ = nearestIndex;
139 runTime.setTime(Times[nearestIndex], nearestIndex);
142 fieldsChanged_ =
true;
159 Info<<
"<end> Foam::vtkPVFoam::setTime() - selectedTime=" 160 << Times[nearestIndex].name() <<
" index=" << timeIndex_
161 <<
"/" << Times.size()
162 <<
" meshChanged=" << Switch(meshChanged_)
163 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
170 void Foam::vtkPVFoam::updateMeshPartsStatus()
174 Info<<
"<beg> Foam::vtkPVFoam::updateMeshPartsStatus" <<
endl;
177 vtkDataArraySelection* selection = reader_->GetPartSelection();
178 label nElem = selection->GetNumberOfArrays();
180 if (partStatus_.size() != nElem)
182 partStatus_.setSize(nElem);
188 partDataset_.setSize(nElem);
192 forAll(partStatus_, partId)
194 const int setting = selection->GetArraySetting(partId);
196 if (partStatus_[partId] != setting)
198 partStatus_[partId] = setting;
204 Info<<
" part[" << partId <<
"] = " 205 << partStatus_[partId]
206 <<
" : " << selection->GetArrayName(partId) <<
endl;
211 Info<<
"<end> Foam::vtkPVFoam::updateMeshPartsStatus" <<
endl;
218 Foam::vtkPVFoam::vtkPVFoam
220 const char*
const FileName,
221 vtkPVFoamReader* reader
227 meshRegion_(polyMesh::defaultRegion),
228 meshDir_(polyMesh::meshSubDir),
231 fieldsChanged_(true),
232 arrayRangeVolume_(
"unzoned"),
233 arrayRangePatches_(
"patches"),
234 arrayRangeLagrangian_(
"lagrangian"),
235 arrayRangeCellZones_(
"cellZone"),
236 arrayRangeFaceZones_(
"faceZone"),
237 arrayRangePointZones_(
"pointZone"),
238 arrayRangeCellSets_(
"cellSet"),
239 arrayRangeFaceSets_(
"faceSet"),
240 arrayRangePointSets_(
"pointSet")
244 Info<<
"Foam::vtkPVFoam::vtkPVFoam - " << FileName <<
endl;
251 fileOperations::collatedFileOperation::maxThreadFileBufferSize = 0;
255 fileName fullCasePath(fileName(FileName).
path());
257 if (!
isDir(fullCasePath))
261 if (fullCasePath ==
".")
263 fullCasePath =
cwd();
267 if (fullCasePath.name().find(
"processor", 0) == 0)
269 const fileName globalCase = fullCasePath.path();
271 setEnv(
"FOAM_CASE", globalCase,
true);
272 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
276 setEnv(
"FOAM_CASE", fullCasePath,
true);
277 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
283 string caseName(fileName(FileName).lessExt());
289 beg != string::npos && caseName[beg] ==
'{' 290 && end != string::npos && end == caseName.size()-1
293 meshRegion_ = caseName.substr(beg+1, end-beg-1);
296 if (meshRegion_.empty())
298 meshRegion_ = polyMesh::defaultRegion;
301 if (meshRegion_ != polyMesh::defaultRegion)
303 meshDir_ = meshRegion_/polyMesh::meshSubDir;
309 Info<<
"fullCasePath=" << fullCasePath <<
nl 310 <<
"FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl 311 <<
"FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl 312 <<
"region=" << meshRegion_ <<
endl;
320 Time::controlDictName,
321 fileName(fullCasePath.path()),
322 fileName(fullCasePath.name())
326 dbPtr_().functionObjects().off();
338 Info<<
"<end> Foam::vtkPVFoam::~vtkPVFoam" <<
endl;
351 Info<<
"<beg> Foam::vtkPVFoam::updateInfo" 352 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"nullptr") <<
"] timeIndex=" 353 << timeIndex_ <<
endl;
358 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
371 if (!partSelection->GetNumberOfArrays() && !meshPtr_)
374 enabledEntries[0] =
"internalMesh";
378 enabledEntries = getSelectedArrayEntries(partSelection);
382 partSelection->RemoveAllArrays();
385 updateInfoInternalMesh(partSelection);
386 updateInfoPatches(partSelection, enabledEntries);
387 updateInfoSets(partSelection);
388 updateInfoZones(partSelection);
389 updateInfoLagrangian(partSelection);
392 setSelectedArrayEntries(partSelection, enabledEntries);
396 fieldsChanged_ =
true;
400 updateInfoFields<fvPatchField, volMesh>
402 reader_->GetVolFieldSelection()
404 updateInfoFields<pointPatchField, pointMesh>
406 reader_->GetPointFieldSelection()
408 updateInfoLagrangianFields();
413 getSelectedArrayEntries(partSelection);
414 Info<<
"<end> Foam::vtkPVFoam::updateInfo" <<
endl;
420 void Foam::vtkPVFoam::updateFoamMesh()
424 Info<<
"<beg> Foam::vtkPVFoam::updateFoamMesh" <<
endl;
428 if (!reader_->GetCacheMesh())
439 Info<<
"Creating OpenFOAM mesh for region " << meshRegion_
440 <<
" at time=" << dbPtr_().timeName()
445 meshPtr_ =
new fvMesh
462 Info<<
"Using existing OpenFOAM mesh" <<
endl;
468 Info<<
"<end> Foam::vtkPVFoam::updateFoamMesh" <<
endl;
476 vtkMultiBlockDataSet* output,
477 vtkMultiBlockDataSet* lagrangianOutput
482 cout<<
"<beg> Foam::vtkPVFoam::Update - output with " 483 << output->GetNumberOfBlocks() <<
" and " 484 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks\n";
486 lagrangianOutput->Print(cout);
489 reader_->UpdateProgress(0.1);
492 updateMeshPartsStatus();
494 reader_->UpdateProgress(0.15);
498 reader_->UpdateProgress(0.4);
503 convertMeshVolume(output, blockNo);
504 convertMeshPatches(output, blockNo);
505 reader_->UpdateProgress(0.6);
507 if (reader_->GetIncludeZones())
509 convertMeshCellZones(output, blockNo);
510 convertMeshFaceZones(output, blockNo);
511 convertMeshPointZones(output, blockNo);
512 reader_->UpdateProgress(0.65);
515 if (reader_->GetIncludeSets())
517 convertMeshCellSets(output, blockNo);
518 convertMeshFaceSets(output, blockNo);
519 convertMeshPointSets(output, blockNo);
520 reader_->UpdateProgress(0.7);
523 convertMeshLagrangian(lagrangianOutput, blockNo);
525 reader_->UpdateProgress(0.8);
528 convertVolFields(output);
529 convertPointFields(output);
530 convertLagrangianFields(lagrangianOutput);
535 reader_->UpdateProgress(0.95);
537 meshChanged_ = fieldsChanged_ =
false;
545 reader_->UpdateProgress(1.0);
552 double* tsteps =
nullptr;
556 Time& runTime = dbPtr_();
561 for (; timeI < timeLst.size(); ++timeI)
563 const word& timeName = timeLst[timeI].name();
573 ).typeHeaderOk<pointIOField>(
true)
580 nTimes = timeLst.size() - timeI;
583 if (timeI == 0 && nTimes > 1)
585 if (timeLst[timeI].
name() == runTime.constant())
594 if (nTimes > 1 && reader_->GetSkipZeroTime())
596 if (
mag(timeLst[timeI].value()) < SMALL)
605 tsteps =
new double[nTimes];
606 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
608 tsteps[stepI] = timeLst[timeI].value();
616 cout<<
"no valid dbPtr:\n";
629 vtkRenderer* renderer,
640 forAll(patchTextActorsPtrs_, patchi)
642 renderer->RemoveViewProp(patchTextActorsPtrs_[patchi]);
643 patchTextActorsPtrs_[
patchi]->Delete();
645 patchTextActorsPtrs_.
clear();
652 reader_->GetPartSelection(),
656 if (selectedPatches.empty())
661 const polyBoundaryMesh& pbMesh = meshPtr_->
boundaryMesh();
669 List<DynamicList<point>> zoneCentre(pbMesh.size());
675 const polyPatch& pp = pbMesh[
patchi];
678 if (!selectedPatches.found(pp.name()))
686 boolList featEdge(pp.nEdges(),
false);
690 const labelList& eFaces = edgeFaces[edgeI];
692 if (eFaces.size() == 1)
696 featEdge[edgeI] =
true;
698 else if (
mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
700 featEdge[edgeI] =
true;
705 patchZones
pZones(pp, featEdge);
721 zoneCentre[
patchi][zoneI] += pp[facei].centre(pp.points());
725 forAll(zoneCentre[patchi], zoneI)
727 zoneCentre[
patchi][zoneI] /= zoneNFaces[zoneI];
734 const label MAXPATCHZONES = 20;
736 label displayZoneI = 0;
740 displayZoneI +=
min(MAXPATCHZONES, nZones[patchi]);
745 Info<<
"displayed zone centres = " << displayZoneI <<
nl 746 <<
"zones per patch = " << nZones <<
endl;
750 patchTextActorsPtrs_.
setSize(displayZoneI);
754 Info<<
"constructing patch labels" <<
endl;
762 const polyPatch& pp = pbMesh[
patchi];
764 label globalZoneI = 0;
767 label nDisplayZones =
min(MAXPATCHZONES, nZones[patchi]);
769 if (nZones[patchi] >= MAXPATCHZONES)
771 increment = nZones[
patchi]/MAXPATCHZONES;
774 for (
label i = 0; i < nDisplayZones; i++)
778 Info<<
"patch name = " << pp.name() <<
nl 779 <<
"anchor = " << zoneCentre[
patchi][globalZoneI] <<
nl 780 <<
"globalZoneI = " << globalZoneI <<
endl;
785 txt->SetInput(pp.name().c_str());
788 vtkTextProperty* tprop = txt->GetTextProperty();
789 tprop->SetFontFamilyToArial();
792 tprop->SetLineSpacing(1.0);
793 tprop->SetFontSize(12);
794 tprop->SetColor(1.0, 0.0, 0.0);
795 tprop->SetJustificationToCentered();
798 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
800 txt->GetPositionCoordinate()->SetValue
802 zoneCentre[patchi][globalZoneI].
x(),
803 zoneCentre[patchi][globalZoneI].
y(),
804 zoneCentre[patchi][globalZoneI].z()
808 renderer->AddViewProp(txt);
812 patchTextActorsPtrs_[displayZoneI] = txt;
814 globalZoneI += increment;
820 patchTextActorsPtrs_.
setSize(displayZoneI);
827 os << indent <<
"Number of nodes: " 828 << (meshPtr_ ? meshPtr_->
nPoints() : 0) <<
"\n";
830 os << indent <<
"Number of cells: " 831 << (meshPtr_ ? meshPtr_->
nCells() : 0) <<
"\n";
833 os << indent <<
"Number of available time steps: " 834 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
836 os << indent <<
"mesh region: " << meshRegion_ <<
"\n";
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
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.
static void printMemory()
Simple memory used debugging information.
double * findTimes(int &nTimeSteps)
Allocate and return a list of selected times.
void renderPatchNames(vtkRenderer *, const bool show)
Add/remove patch names to/from the view.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void PrintSelf(ostream &, vtkIndent) const
Debug information.
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.
void clear()
Clear the list, i.e. set size to zero.
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
List< label > labelList
A List of labels.
HashSet wordHashSet
A HashSet with word keys.
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,.
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)