27 #include "vtkPVFoamReader.h" 38 #include "vtkDataArraySelection.h" 39 #include "vtkMultiBlockDataSet.h" 40 #include "vtkRenderer.h" 41 #include "vtkTextActor.h" 42 #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)
123 for (
int requestI = 0; requestI < nRequest; ++requestI)
130 Info<< requestTimes[requestI];
132 Info<<
") - previousIndex = " << timeIndex_
133 <<
", nearestIndex = " << nearestIndex <<
endl;
137 if (timeIndex_ != nearestIndex)
139 timeIndex_ = nearestIndex;
140 runTime.setTime(Times[nearestIndex], nearestIndex);
143 fieldsChanged_ =
true;
165 meshPtr_->stitcher().reconnect(reader_->GetInterpolateVolFields());
170 Info<<
" selectedTime=" 171 << Times[nearestIndex].name() <<
" index=" << timeIndex_
172 <<
"/" << Times.size()
173 <<
" meshChanged=" << Switch(meshChanged_)
174 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
181 void Foam::vtkPVFoam::topoChangePartsStatus()
188 vtkDataArraySelection* selection = reader_->GetPartSelection();
189 label nElem = selection->GetNumberOfArrays();
191 if (partStatus_.size() != nElem)
193 partStatus_.setSize(nElem);
199 partDataset_.setSize(nElem);
203 forAll(partStatus_, partId)
205 const int setting = selection->GetArraySetting(partId);
207 if (partStatus_[partId] != setting)
209 partStatus_[partId] = setting;
215 Info<<
" part[" << partId <<
"] = " 216 << partStatus_[partId]
217 <<
" : " << selection->GetArrayName(partId) <<
endl;
227 const char*
const vtkFileName,
228 vtkPVFoamReader* reader
234 meshRegion_(polyMesh::defaultRegion),
235 meshDir_(polyMesh::meshSubDir),
238 fieldsChanged_(true),
239 arrayRangeVolume_(
"unzoned"),
240 arrayRangePatches_(
"patches"),
241 arrayRangeLagrangian_(
"lagrangian"),
242 arrayRangeCellZones_(
"cellZone"),
243 arrayRangeFaceZones_(
"faceZone"),
244 arrayRangePointZones_(
"pointZone"),
245 arrayRangeCellSets_(
"cellSet"),
246 arrayRangeFaceSets_(
"faceSet"),
247 arrayRangePointSets_(
"pointSet")
255 fileName FileName(vtkFileName);
258 fileName fullCasePath(FileName.path());
260 if (!
isDir(fullCasePath))
264 if (fullCasePath ==
".")
266 fullCasePath =
cwd();
270 if (fullCasePath.name().find(
"processors", 0) == 0)
275 fullCasePath = fullCasePath.path()/fileName(FileName.name()).lessExt();
279 if (fullCasePath.name().find(
"processor", 0) == 0)
284 const fileName globalCase = fullCasePath.
path();
286 setEnv(
"FOAM_CASE", globalCase,
true);
287 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
291 setEnv(
"FOAM_CASE", fullCasePath,
true);
292 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
298 string caseName(FileName.lessExt());
304 beg != string::npos && caseName[beg] ==
'{' 305 && end != string::npos && end == caseName.size()-1
308 meshRegion_ = caseName.substr(beg+1, end-beg-1);
311 if (meshRegion_.empty())
313 meshRegion_ = polyMesh::defaultRegion;
316 if (meshRegion_ != polyMesh::defaultRegion)
318 meshDir_ = meshRegion_/polyMesh::meshSubDir;
324 Info<<
" fullCasePath=" << fullCasePath <<
nl 325 <<
" FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl 326 <<
" FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl 327 <<
" region=" << meshRegion_ <<
endl;
331 dlLibraryTable dlTable;
333 string libsString(
getEnv(
"FOAM_LIBS"));
334 if (!libsString.empty())
336 IStringStream is(libsString);
340 dlTable.open(libNames[i]);
349 Time::controlDictName,
350 fileName(fullCasePath.path()),
351 fileName(fullCasePath.name())
355 dbPtr_().functionObjects().off();
360 configDict_.merge(dictionary(IFstream(configDictFiles[cdfi])()));
388 << (meshPtr_ ?
"set" :
"nullptr")
389 <<
"] timeIndex=" << timeIndex_ << endl;
394 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
407 bool first = !partSelection->GetNumberOfArrays() && !meshPtr_;
410 enabledEntries.setSize(1);
411 enabledEntries[0] =
"internalMesh";
415 enabledEntries = getSelectedArrayEntries(partSelection);
419 partSelection->RemoveAllArrays();
422 updateInfoInternalMesh(partSelection);
423 updateInfoPatches(partSelection, enabledEntries, first);
424 updateInfoSets(partSelection);
425 updateInfoZones(partSelection);
426 updateInfoLagrangian(partSelection);
429 setSelectedArrayEntries(partSelection, enabledEntries);
433 fieldsChanged_ =
true;
438 updateInfoLagrangianFields();
443 getSelectedArrayEntries(partSelection);
448 void Foam::vtkPVFoam::updateFoamMesh()
456 if (!reader_->GetCacheMesh())
468 <<
" Creating OpenFOAM mesh for region " << meshRegion_
469 <<
" at time=" << dbPtr_().timeName() <<
endl;
472 meshPtr_ =
new fvMesh
491 Info<<
" Using existing OpenFOAM mesh" <<
endl;
510 vtkMultiBlockDataSet* output,
511 vtkMultiBlockDataSet* lagrangianOutput
517 << output->GetNumberOfBlocks() <<
" and " 518 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks" <<
endl;
521 lagrangianOutput->Print(cout);
525 reader_->UpdateProgress(0.1);
528 topoChangePartsStatus();
530 reader_->UpdateProgress(0.15);
534 reader_->UpdateProgress(0.4);
539 convertMeshVolume(output, blockNo);
540 convertMeshPatches(output, blockNo);
541 reader_->UpdateProgress(0.6);
543 if (reader_->GetIncludeZones())
545 convertMeshCellZones(output, blockNo);
546 convertMeshFaceZones(output, blockNo);
547 convertMeshPointZones(output, blockNo);
548 reader_->UpdateProgress(0.65);
551 if (reader_->GetIncludeSets())
553 convertMeshCellSets(output, blockNo);
554 convertMeshFaceSets(output, blockNo);
555 convertMeshPointSets(output, blockNo);
556 reader_->UpdateProgress(0.7);
559 convertMeshLagrangian(lagrangianOutput, blockNo);
561 reader_->UpdateProgress(0.8);
564 convertFields(output);
565 convertLagrangianFields(lagrangianOutput);
572 reader_->UpdateProgress(0.95);
574 meshChanged_ = fieldsChanged_ =
false;
582 reader_->UpdateProgress(1.0);
589 double* tsteps =
nullptr;
593 Time& runTime = dbPtr_();
600 for (; timeI < timeLst.size(); ++timeI)
602 const word& timeName = timeLst[timeI].name();
606 typeIOobject<pointIOField>
619 nTimes = timeLst.size() - timeI;
622 if (timeI == 0 && nTimes > 1)
624 if (timeLst[timeI].
name() == runTime.constant())
633 if (nTimes > 1 && reader_->GetSkipZeroTime())
635 if (
mag(timeLst[timeI].value()) < small)
644 tsteps =
new double[nTimes];
645 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
647 tsteps[stepI] = timeLst[timeI].value();
655 cout<<
"no valid dbPtr:\n";
668 vtkRenderer* renderer,
679 forAll(patchTextActorsPtrs_, patchi)
681 renderer->RemoveViewProp(patchTextActorsPtrs_[patchi]);
682 patchTextActorsPtrs_[
patchi]->Delete();
684 patchTextActorsPtrs_.
clear();
691 reader_->GetPartSelection(),
695 if (selectedPatches.empty())
700 const polyBoundaryMesh& pbMesh = meshPtr_->
boundaryMesh();
708 List<DynamicList<point>> zoneCentre(pbMesh.size());
714 const polyPatch& pp = pbMesh[
patchi];
717 if (!selectedPatches.found(pp.name()))
725 boolList featEdge(pp.nEdges(),
false);
729 const labelList& eFaces = edgeFaces[edgeI];
731 if (eFaces.size() == 1)
735 featEdge[edgeI] =
true;
737 else if (
mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
739 featEdge[edgeI] =
true;
744 patchZones
pZones(pp, featEdge);
760 zoneCentre[
patchi][zoneI] += pp[facei].centre(pp.points());
764 forAll(zoneCentre[patchi], zoneI)
766 zoneCentre[
patchi][zoneI] /= zoneNFaces[zoneI];
773 const label MAXPATCHZONES = 20;
775 label displayZoneI = 0;
779 displayZoneI +=
min(MAXPATCHZONES, nZones[patchi]);
784 Info<<
" displayed zone centres = " << displayZoneI <<
nl 785 <<
" zones per patch = " << nZones <<
endl;
789 patchTextActorsPtrs_.
setSize(displayZoneI);
793 Info<<
" constructing patch labels" <<
endl;
801 const polyPatch& pp = pbMesh[
patchi];
803 label globalZoneI = 0;
806 label nDisplayZones =
min(MAXPATCHZONES, nZones[patchi]);
808 if (nZones[patchi] >= MAXPATCHZONES)
810 increment = nZones[
patchi]/MAXPATCHZONES;
813 for (
label i = 0; i < nDisplayZones; i++)
817 Info<<
" patch name = " << pp.name() <<
nl 818 <<
" anchor = " << zoneCentre[
patchi][globalZoneI]
820 <<
" globalZoneI = " << globalZoneI <<
endl;
825 txt->SetInput(pp.name().c_str());
828 vtkTextProperty* tprop = txt->GetTextProperty();
829 tprop->SetFontFamilyToArial();
832 tprop->SetLineSpacing(1.0);
833 tprop->SetFontSize(12);
834 tprop->SetColor(1.0, 0.0, 0.0);
835 tprop->SetJustificationToCentered();
838 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
840 txt->GetPositionCoordinate()->SetValue
842 zoneCentre[patchi][globalZoneI].
x(),
843 zoneCentre[patchi][globalZoneI].
y(),
844 zoneCentre[patchi][globalZoneI].z()
848 renderer->AddViewProp(txt);
852 patchTextActorsPtrs_[displayZoneI] = txt;
854 globalZoneI += increment;
860 patchTextActorsPtrs_.
setSize(displayZoneI);
867 os << indent <<
"Number of nodes: " 868 << (meshPtr_ ? meshPtr_->
nPoints() : 0) <<
"\n";
870 os << indent <<
"Number of cells: " 871 << (meshPtr_ ? meshPtr_->
nCells() : 0) <<
"\n";
873 os << indent <<
"Number of available time steps: " 874 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
876 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.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
static void printMemory()
Simple memory used debugging information.
double * findTimes(int &nTimeSteps)
Allocate and return a list of selected times.
void updateInfo()
Update information for selection dialogs.
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)
Update.
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.
virtual fileName filePath(const bool globalFile, const IOobject &, const word &typeName) const =0
Search for an object. globalFile : also check undecomposed case.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< label > labelList
A List of labels.
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)
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.
const fvMeshStitcher & stitcher() const
Return the stitcher function class.
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 /)
void reconnect(const bool geometric) const
Re-compute the connection. Topology is preserved. Permits a change.
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.