27 #include "vtkPVFoamReader.h" 37 #include "vtkDataArraySelection.h" 38 #include "vtkMultiBlockDataSet.h" 39 #include "vtkRenderer.h" 40 #include "vtkTextActor.h" 41 #include "vtkTextProperty.h" 56 void Foam::vtkPVFoam::resetCounters()
59 arrayRangeVolume_.reset();
60 arrayRangePatches_.reset();
61 arrayRangeLagrangian_.reset();
62 arrayRangeCellZones_.reset();
63 arrayRangeFaceZones_.reset();
64 arrayRangePointZones_.reset();
65 arrayRangeCellSets_.reset();
66 arrayRangeFaceSets_.reset();
67 arrayRangePointSets_.reset();
71 void Foam::vtkPVFoam::reduceMemory()
73 forAll(regionPolyDecomp_, i)
75 regionPolyDecomp_[i].clear();
80 zonePolyDecomp_[i].clear();
85 csetPolyDecomp_[i].clear();
88 if (!reader_->GetCacheMesh())
98 Time& runTime = dbPtr_();
104 int nearestIndex = timeIndex_;
105 for (
int requestI = 0; requestI < nRequest; ++requestI)
108 if (index >= 0 && index != timeIndex_)
110 nearestIndex = index;
115 if (nearestIndex < 0)
122 Info<<
"<beg> Foam::vtkPVFoam::setTime(";
123 for (
int requestI = 0; requestI < nRequest; ++requestI)
130 Info<< requestTimes[requestI];
132 Info<<
") - previousIndex = " << timeIndex_
133 <<
", nearestIndex = " << nearestIndex <<
endl;
138 if (timeIndex_ != nearestIndex)
140 timeIndex_ = nearestIndex;
141 runTime.setTime(Times[nearestIndex], nearestIndex);
144 fieldsChanged_ =
true;
161 Info<<
"<end> Foam::vtkPVFoam::setTime() - selectedTime=" 162 << Times[nearestIndex].name() <<
" index=" << timeIndex_
163 <<
"/" << Times.size()
164 <<
" meshChanged=" << Switch(meshChanged_)
165 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
172 void Foam::vtkPVFoam::updateMeshPartsStatus()
176 Info<<
"<beg> Foam::vtkPVFoam::updateMeshPartsStatus" <<
endl;
179 vtkDataArraySelection* selection = reader_->GetPartSelection();
180 label nElem = selection->GetNumberOfArrays();
182 if (partStatus_.size() != nElem)
184 partStatus_.setSize(nElem);
190 partDataset_.setSize(nElem);
194 forAll(partStatus_, partId)
196 const int setting = selection->GetArraySetting(partId);
198 if (partStatus_[partId] != setting)
200 partStatus_[partId] = setting;
206 Info<<
" part[" << partId <<
"] = " 207 << partStatus_[partId]
208 <<
" : " << selection->GetArrayName(partId) <<
endl;
213 Info<<
"<end> Foam::vtkPVFoam::updateMeshPartsStatus" <<
endl;
220 Foam::vtkPVFoam::vtkPVFoam
222 const char*
const vtkFileName,
223 vtkPVFoamReader* reader
229 meshRegion_(polyMesh::defaultRegion),
230 meshDir_(polyMesh::meshSubDir),
233 fieldsChanged_(true),
234 arrayRangeVolume_(
"unzoned"),
235 arrayRangePatches_(
"patches"),
236 arrayRangeLagrangian_(
"lagrangian"),
237 arrayRangeCellZones_(
"cellZone"),
238 arrayRangeFaceZones_(
"faceZone"),
239 arrayRangePointZones_(
"pointZone"),
240 arrayRangeCellSets_(
"cellSet"),
241 arrayRangeFaceSets_(
"faceSet"),
242 arrayRangePointSets_(
"pointSet")
246 Info<<
"Foam::vtkPVFoam::vtkPVFoam - " << vtkFileName <<
endl;
250 fileName FileName(vtkFileName);
253 fileName fullCasePath(FileName.path());
255 if (!
isDir(fullCasePath))
259 if (fullCasePath ==
".")
261 fullCasePath =
cwd();
265 if (fullCasePath.name().find(
"processors", 0) == 0)
270 fullCasePath = fullCasePath.path()/fileName(FileName.name()).lessExt();
274 if (fullCasePath.name().find(
"processor", 0) == 0)
279 const fileName globalCase = fullCasePath.
path();
281 setEnv(
"FOAM_CASE", globalCase,
true);
282 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
286 setEnv(
"FOAM_CASE", fullCasePath,
true);
287 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
293 string caseName(FileName.lessExt());
299 beg != string::npos && caseName[beg] ==
'{' 300 && end != string::npos && end == caseName.size()-1
303 meshRegion_ = caseName.substr(beg+1, end-beg-1);
306 if (meshRegion_.empty())
308 meshRegion_ = polyMesh::defaultRegion;
311 if (meshRegion_ != polyMesh::defaultRegion)
313 meshDir_ = meshRegion_/polyMesh::meshSubDir;
319 Info<<
"fullCasePath=" << fullCasePath <<
nl 320 <<
"FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl 321 <<
"FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl 322 <<
"region=" << meshRegion_ <<
endl;
330 Time::controlDictName,
331 fileName(fullCasePath.path()),
332 fileName(fullCasePath.name())
336 dbPtr_().functionObjects().off();
341 configDict_.merge(dictionary(IFstream(configDictFiles[cdfi])()));
354 Info<<
"<end> Foam::vtkPVFoam::~vtkPVFoam" <<
endl;
367 Info<<
"<beg> Foam::vtkPVFoam::updateInfo" 368 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"nullptr") <<
"] timeIndex=" 369 << timeIndex_ <<
endl;
374 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
387 bool first = !partSelection->GetNumberOfArrays() && !meshPtr_;
390 enabledEntries.setSize(1);
391 enabledEntries[0] =
"internalMesh";
395 enabledEntries = getSelectedArrayEntries(partSelection);
399 partSelection->RemoveAllArrays();
402 updateInfoInternalMesh(partSelection);
403 updateInfoPatches(partSelection, enabledEntries, first);
404 updateInfoSets(partSelection);
405 updateInfoZones(partSelection);
406 updateInfoLagrangian(partSelection);
409 setSelectedArrayEntries(partSelection, enabledEntries);
413 fieldsChanged_ =
true;
417 updateInfoFields<fvPatchField, volMesh>
419 reader_->GetVolFieldSelection()
421 updateInfoFields<pointPatchField, pointMesh>
423 reader_->GetPointFieldSelection()
425 updateInfoLagrangianFields();
430 getSelectedArrayEntries(partSelection);
431 Info<<
"<end> Foam::vtkPVFoam::updateInfo" <<
endl;
437 void Foam::vtkPVFoam::updateFoamMesh()
441 Info<<
"<beg> Foam::vtkPVFoam::updateFoamMesh" <<
endl;
445 if (!reader_->GetCacheMesh())
456 Info<<
"Creating OpenFOAM mesh for region " << meshRegion_
457 <<
" at time=" << dbPtr_().timeName()
462 meshPtr_ =
new fvMesh
479 Info<<
"Using existing OpenFOAM mesh" <<
endl;
485 Info<<
"<end> Foam::vtkPVFoam::updateFoamMesh" <<
endl;
493 vtkMultiBlockDataSet* output,
494 vtkMultiBlockDataSet* lagrangianOutput
499 cout<<
"<beg> Foam::vtkPVFoam::Update - output with " 500 << output->GetNumberOfBlocks() <<
" and " 501 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks\n";
503 lagrangianOutput->Print(cout);
506 reader_->UpdateProgress(0.1);
509 updateMeshPartsStatus();
511 reader_->UpdateProgress(0.15);
515 reader_->UpdateProgress(0.4);
520 convertMeshVolume(output, blockNo);
521 convertMeshPatches(output, blockNo);
522 reader_->UpdateProgress(0.6);
524 if (reader_->GetIncludeZones())
526 convertMeshCellZones(output, blockNo);
527 convertMeshFaceZones(output, blockNo);
528 convertMeshPointZones(output, blockNo);
529 reader_->UpdateProgress(0.65);
532 if (reader_->GetIncludeSets())
534 convertMeshCellSets(output, blockNo);
535 convertMeshFaceSets(output, blockNo);
536 convertMeshPointSets(output, blockNo);
537 reader_->UpdateProgress(0.7);
540 convertMeshLagrangian(lagrangianOutput, blockNo);
542 reader_->UpdateProgress(0.8);
545 convertVolFields(output);
546 convertPointFields(output);
547 convertLagrangianFields(lagrangianOutput);
552 reader_->UpdateProgress(0.95);
554 meshChanged_ = fieldsChanged_ =
false;
562 reader_->UpdateProgress(1.0);
569 double* tsteps =
nullptr;
573 Time& runTime = dbPtr_();
580 for (; timeI < timeLst.size(); ++timeI)
582 const word& timeName = timeLst[timeI].name();
592 ).typeHeaderOk<pointIOField>(
true)
599 nTimes = timeLst.size() - timeI;
602 if (timeI == 0 && nTimes > 1)
604 if (timeLst[timeI].
name() == runTime.constant())
613 if (nTimes > 1 && reader_->GetSkipZeroTime())
615 if (
mag(timeLst[timeI].value()) < small)
624 tsteps =
new double[nTimes];
625 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
627 tsteps[stepI] = timeLst[timeI].value();
635 cout<<
"no valid dbPtr:\n";
648 vtkRenderer* renderer,
659 forAll(patchTextActorsPtrs_, patchi)
661 renderer->RemoveViewProp(patchTextActorsPtrs_[patchi]);
662 patchTextActorsPtrs_[
patchi]->Delete();
664 patchTextActorsPtrs_.
clear();
671 reader_->GetPartSelection(),
675 if (selectedPatches.empty())
680 const polyBoundaryMesh& pbMesh = meshPtr_->
boundaryMesh();
688 List<DynamicList<point>> zoneCentre(pbMesh.size());
694 const polyPatch& pp = pbMesh[
patchi];
697 if (!selectedPatches.found(pp.name()))
705 boolList featEdge(pp.nEdges(),
false);
709 const labelList& eFaces = edgeFaces[edgeI];
711 if (eFaces.size() == 1)
715 featEdge[edgeI] =
true;
717 else if (
mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
719 featEdge[edgeI] =
true;
724 patchZones
pZones(pp, featEdge);
740 zoneCentre[
patchi][zoneI] += pp[facei].centre(pp.points());
744 forAll(zoneCentre[patchi], zoneI)
746 zoneCentre[
patchi][zoneI] /= zoneNFaces[zoneI];
753 const label MAXPATCHZONES = 20;
755 label displayZoneI = 0;
759 displayZoneI +=
min(MAXPATCHZONES, nZones[patchi]);
764 Info<<
"displayed zone centres = " << displayZoneI <<
nl 765 <<
"zones per patch = " << nZones <<
endl;
769 patchTextActorsPtrs_.
setSize(displayZoneI);
773 Info<<
"constructing patch labels" <<
endl;
781 const polyPatch& pp = pbMesh[
patchi];
783 label globalZoneI = 0;
786 label nDisplayZones =
min(MAXPATCHZONES, nZones[patchi]);
788 if (nZones[patchi] >= MAXPATCHZONES)
790 increment = nZones[
patchi]/MAXPATCHZONES;
793 for (
label i = 0; i < nDisplayZones; i++)
797 Info<<
"patch name = " << pp.name() <<
nl 798 <<
"anchor = " << zoneCentre[
patchi][globalZoneI] <<
nl 799 <<
"globalZoneI = " << globalZoneI <<
endl;
804 txt->SetInput(pp.name().c_str());
807 vtkTextProperty* tprop = txt->GetTextProperty();
808 tprop->SetFontFamilyToArial();
811 tprop->SetLineSpacing(1.0);
812 tprop->SetFontSize(12);
813 tprop->SetColor(1.0, 0.0, 0.0);
814 tprop->SetJustificationToCentered();
817 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
819 txt->GetPositionCoordinate()->SetValue
821 zoneCentre[patchi][globalZoneI].
x(),
822 zoneCentre[patchi][globalZoneI].
y(),
823 zoneCentre[patchi][globalZoneI].z()
827 renderer->AddViewProp(txt);
831 patchTextActorsPtrs_[displayZoneI] = txt;
833 globalZoneI += increment;
839 patchTextActorsPtrs_.
setSize(displayZoneI);
846 os << indent <<
"Number of nodes: " 847 << (meshPtr_ ? meshPtr_->
nPoints() : 0) <<
"\n";
849 os << indent <<
"Number of cells: " 850 << (meshPtr_ ? meshPtr_->
nCells() : 0) <<
"\n";
852 os << indent <<
"Number of available time steps: " 853 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
855 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.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
void PrintSelf(ostream &, vtkIndent) const
Debug information.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
fileNameList findEtcFiles(const fileName &, bool mandatory=false, bool findFirst=false)
Search for files from user/group/shipped directories.
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?
Functions to search 'etc' directories for configuration files etc.
List< label > labelList
A List of labels.
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName) const =0
Search for an object. checkGlobal : also check undecomposed case.
HashSet wordHashSet
A HashSet with word keys.
const fileOperation & fileHandler()
Get current file handler.
graph_traits< Graph >::vertices_size_type size_type
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
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.
fileName path() const
Return directory path name (part before last /)
List< fileName > fileNameList
A List of fileNames.
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)