27 #include "vtkPVFoamReader.h" 37 #include "vtkDataArraySelection.h" 38 #include "vtkMultiBlockDataSet.h" 39 #include "vtkRenderer.h" 40 #include "vtkTextActor.h" 41 #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_();
103 int nearestIndex = timeIndex_;
104 for (
int requestI = 0; requestI < nRequest; ++requestI)
107 if (index >= 0 && index != timeIndex_)
109 nearestIndex = index;
114 if (nearestIndex < 0)
122 for (
int requestI = 0; requestI < nRequest; ++requestI)
129 Info<< requestTimes[requestI];
131 Info<<
") - previousIndex = " << timeIndex_
132 <<
", nearestIndex = " << nearestIndex <<
endl;
137 if (timeIndex_ != nearestIndex)
139 timeIndex_ = nearestIndex;
140 runTime.setTime(Times[nearestIndex], nearestIndex);
143 fieldsChanged_ =
true;
160 Info<<
" selectedTime=" 161 << Times[nearestIndex].name() <<
" index=" << timeIndex_
162 <<
"/" << Times.size()
163 <<
" meshChanged=" << Switch(meshChanged_)
164 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
171 void Foam::vtkPVFoam::updateMeshPartsStatus()
178 vtkDataArraySelection* selection = reader_->GetPartSelection();
179 label nElem = selection->GetNumberOfArrays();
181 if (partStatus_.size() != nElem)
183 partStatus_.setSize(nElem);
189 partDataset_.setSize(nElem);
193 forAll(partStatus_, partId)
195 const int setting = selection->GetArraySetting(partId);
197 if (partStatus_[partId] != setting)
199 partStatus_[partId] = setting;
205 Info<<
" part[" << partId <<
"] = " 206 << partStatus_[partId]
207 <<
" : " << selection->GetArrayName(partId) <<
endl;
217 const char*
const vtkFileName,
218 vtkPVFoamReader* reader
224 meshRegion_(polyMesh::defaultRegion),
225 meshDir_(polyMesh::meshSubDir),
228 fieldsChanged_(true),
229 arrayRangeVolume_(
"unzoned"),
230 arrayRangePatches_(
"patches"),
231 arrayRangeLagrangian_(
"lagrangian"),
232 arrayRangeCellZones_(
"cellZone"),
233 arrayRangeFaceZones_(
"faceZone"),
234 arrayRangePointZones_(
"pointZone"),
235 arrayRangeCellSets_(
"cellSet"),
236 arrayRangeFaceSets_(
"faceSet"),
237 arrayRangePointSets_(
"pointSet")
245 fileName FileName(vtkFileName);
248 fileName fullCasePath(FileName.path());
250 if (!
isDir(fullCasePath))
254 if (fullCasePath ==
".")
256 fullCasePath =
cwd();
260 if (fullCasePath.name().find(
"processors", 0) == 0)
265 fullCasePath = fullCasePath.path()/fileName(FileName.name()).lessExt();
269 if (fullCasePath.name().find(
"processor", 0) == 0)
274 const fileName globalCase = fullCasePath.
path();
276 setEnv(
"FOAM_CASE", globalCase,
true);
277 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
281 setEnv(
"FOAM_CASE", fullCasePath,
true);
282 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
288 string caseName(FileName.lessExt());
294 beg != string::npos && caseName[beg] ==
'{' 295 && end != string::npos && end == caseName.size()-1
298 meshRegion_ = caseName.substr(beg+1, end-beg-1);
301 if (meshRegion_.empty())
303 meshRegion_ = polyMesh::defaultRegion;
306 if (meshRegion_ != polyMesh::defaultRegion)
308 meshDir_ = meshRegion_/polyMesh::meshSubDir;
314 Info<<
" fullCasePath=" << fullCasePath <<
nl 315 <<
" FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl 316 <<
" FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl 317 <<
" region=" << meshRegion_ <<
endl;
321 dlLibraryTable dlTable;
323 string libsString(
getEnv(
"FOAM_LIBS"));
324 if (!libsString.empty())
326 IStringStream is(libsString);
330 dlTable.open(libNames[i]);
339 Time::controlDictName,
340 fileName(fullCasePath.path()),
341 fileName(fullCasePath.name())
345 dbPtr_().functionObjects().off();
350 configDict_.merge(dictionary(IFstream(configDictFiles[cdfi])()));
378 << (meshPtr_ ?
"set" :
"nullptr")
379 <<
"] timeIndex=" << timeIndex_ << endl;
384 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
397 bool first = !partSelection->GetNumberOfArrays() && !meshPtr_;
400 enabledEntries.setSize(1);
401 enabledEntries[0] =
"internalMesh";
405 enabledEntries = getSelectedArrayEntries(partSelection);
409 partSelection->RemoveAllArrays();
412 updateInfoInternalMesh(partSelection);
413 updateInfoPatches(partSelection, enabledEntries, first);
414 updateInfoSets(partSelection);
415 updateInfoZones(partSelection);
416 updateInfoLagrangian(partSelection);
419 setSelectedArrayEntries(partSelection, enabledEntries);
423 fieldsChanged_ =
true;
428 updateInfoLagrangianFields();
433 getSelectedArrayEntries(partSelection);
438 void Foam::vtkPVFoam::updateFoamMesh()
446 if (!reader_->GetCacheMesh())
458 <<
" Creating OpenFOAM mesh for region " << meshRegion_
459 <<
" at time=" << dbPtr_().timeName()
464 meshPtr_ =
new fvMesh
481 Info<<
" Using existing OpenFOAM mesh" <<
endl;
494 vtkMultiBlockDataSet* output,
495 vtkMultiBlockDataSet* lagrangianOutput
501 << output->GetNumberOfBlocks() <<
" and " 502 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks" <<
endl;
505 lagrangianOutput->Print(cout);
508 reader_->UpdateProgress(0.1);
511 updateMeshPartsStatus();
513 reader_->UpdateProgress(0.15);
517 reader_->UpdateProgress(0.4);
522 convertMeshVolume(output, blockNo);
523 convertMeshPatches(output, blockNo);
524 reader_->UpdateProgress(0.6);
526 if (reader_->GetIncludeZones())
528 convertMeshCellZones(output, blockNo);
529 convertMeshFaceZones(output, blockNo);
530 convertMeshPointZones(output, blockNo);
531 reader_->UpdateProgress(0.65);
534 if (reader_->GetIncludeSets())
536 convertMeshCellSets(output, blockNo);
537 convertMeshFaceSets(output, blockNo);
538 convertMeshPointSets(output, blockNo);
539 reader_->UpdateProgress(0.7);
542 convertMeshLagrangian(lagrangianOutput, blockNo);
544 reader_->UpdateProgress(0.8);
547 convertFields(output);
548 convertLagrangianFields(lagrangianOutput);
555 reader_->UpdateProgress(0.95);
557 meshChanged_ = fieldsChanged_ =
false;
565 reader_->UpdateProgress(1.0);
572 double* tsteps =
nullptr;
576 Time& runTime = dbPtr_();
583 for (; timeI < timeLst.size(); ++timeI)
585 const word& timeName = timeLst[timeI].name();
595 ).typeHeaderOk<pointIOField>(
true)
602 nTimes = timeLst.size() - timeI;
605 if (timeI == 0 && nTimes > 1)
607 if (timeLst[timeI].
name() == runTime.constant())
616 if (nTimes > 1 && reader_->GetSkipZeroTime())
618 if (
mag(timeLst[timeI].value()) < small)
627 tsteps =
new double[nTimes];
628 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
630 tsteps[stepI] = timeLst[timeI].value();
638 cout<<
"no valid dbPtr:\n";
651 vtkRenderer* renderer,
662 forAll(patchTextActorsPtrs_, patchi)
664 renderer->RemoveViewProp(patchTextActorsPtrs_[patchi]);
665 patchTextActorsPtrs_[
patchi]->Delete();
667 patchTextActorsPtrs_.
clear();
674 reader_->GetPartSelection(),
678 if (selectedPatches.empty())
683 const polyBoundaryMesh& pbMesh = meshPtr_->
boundaryMesh();
691 List<DynamicList<point>> zoneCentre(pbMesh.size());
697 const polyPatch& pp = pbMesh[
patchi];
700 if (!selectedPatches.found(pp.name()))
708 boolList featEdge(pp.nEdges(),
false);
712 const labelList& eFaces = edgeFaces[edgeI];
714 if (eFaces.size() == 1)
718 featEdge[edgeI] =
true;
720 else if (
mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
722 featEdge[edgeI] =
true;
727 patchZones
pZones(pp, featEdge);
743 zoneCentre[
patchi][zoneI] += pp[facei].centre(pp.points());
747 forAll(zoneCentre[patchi], zoneI)
749 zoneCentre[
patchi][zoneI] /= zoneNFaces[zoneI];
756 const label MAXPATCHZONES = 20;
758 label displayZoneI = 0;
762 displayZoneI +=
min(MAXPATCHZONES, nZones[patchi]);
767 Info<<
" displayed zone centres = " << displayZoneI <<
nl 768 <<
" zones per patch = " << nZones <<
endl;
772 patchTextActorsPtrs_.
setSize(displayZoneI);
776 Info<<
" constructing patch labels" <<
endl;
784 const polyPatch& pp = pbMesh[
patchi];
786 label globalZoneI = 0;
789 label nDisplayZones =
min(MAXPATCHZONES, nZones[patchi]);
791 if (nZones[patchi] >= MAXPATCHZONES)
793 increment = nZones[
patchi]/MAXPATCHZONES;
796 for (
label i = 0; i < nDisplayZones; i++)
800 Info<<
" patch name = " << pp.name() <<
nl 801 <<
" anchor = " << zoneCentre[
patchi][globalZoneI]
803 <<
" globalZoneI = " << globalZoneI <<
endl;
808 txt->SetInput(pp.name().c_str());
811 vtkTextProperty* tprop = txt->GetTextProperty();
812 tprop->SetFontFamilyToArial();
815 tprop->SetLineSpacing(1.0);
816 tprop->SetFontSize(12);
817 tprop->SetColor(1.0, 0.0, 0.0);
818 tprop->SetJustificationToCentered();
821 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
823 txt->GetPositionCoordinate()->SetValue
825 zoneCentre[patchi][globalZoneI].
x(),
826 zoneCentre[patchi][globalZoneI].
y(),
827 zoneCentre[patchi][globalZoneI].z()
831 renderer->AddViewProp(txt);
835 patchTextActorsPtrs_[displayZoneI] = txt;
837 globalZoneI += increment;
843 patchTextActorsPtrs_.
setSize(displayZoneI);
850 os << indent <<
"Number of nodes: " 851 << (meshPtr_ ? meshPtr_->
nPoints() : 0) <<
"\n";
853 os << indent <<
"Number of cells: " 854 << (meshPtr_ ? meshPtr_->
nCells() : 0) <<
"\n";
856 os << indent <<
"Number of available time steps: " 857 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
859 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.
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.
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
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.
vtkPVFoam(const char *const FileName, vtkPVFoamReader *reader)
Construct from components.
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)
#define InfoInFunction
Report an information message using Foam::Info.