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()),
359 configDict_.merge(dictionary(IFstream(configDictFiles[cdfi])()));
387 << (meshPtr_ ?
"set" :
"nullptr")
388 <<
"] timeIndex=" << timeIndex_ <<
endl;
393 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
406 bool first = !partSelection->GetNumberOfArrays() && !meshPtr_;
410 enabledEntries[0] =
"internalMesh";
414 enabledEntries = getSelectedArrayEntries(partSelection);
418 partSelection->RemoveAllArrays();
421 updateInfoInternalMesh(partSelection);
422 updateInfoPatches(partSelection, enabledEntries,
first);
423 updateInfoSets(partSelection);
424 updateInfoZones(partSelection);
425 updateInfoLagrangian(partSelection);
428 setSelectedArrayEntries(partSelection, enabledEntries);
432 fieldsChanged_ =
true;
437 updateInfoLagrangianFields();
442 getSelectedArrayEntries(partSelection);
447 void Foam::vtkPVFoam::updateFoamMesh()
455 if (!reader_->GetCacheMesh())
467 <<
" Creating OpenFOAM mesh for region " << meshRegion_
468 <<
" at time=" << dbPtr_().
name() <<
endl;
471 meshPtr_ =
new fvMesh
490 Info<<
" Using existing OpenFOAM mesh" <<
endl;
497 meshPtr_->stitcher().reconnect(reader_->GetInterpolateVolFields());
509 vtkMultiBlockDataSet* output,
510 vtkMultiBlockDataSet* lagrangianOutput
516 << output->GetNumberOfBlocks() <<
" and "
517 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks" <<
endl;
520 lagrangianOutput->Print(cout);
524 reader_->UpdateProgress(0.1);
527 topoChangePartsStatus();
529 reader_->UpdateProgress(0.15);
533 reader_->UpdateProgress(0.4);
538 convertMeshVolume(output, blockNo);
539 convertMeshPatches(output, blockNo);
540 reader_->UpdateProgress(0.6);
542 if (reader_->GetIncludeZones())
544 convertMeshCellZones(output, blockNo);
545 convertMeshFaceZones(output, blockNo);
546 convertMeshPointZones(output, blockNo);
547 reader_->UpdateProgress(0.65);
550 if (reader_->GetIncludeSets())
552 convertMeshCellSets(output, blockNo);
553 convertMeshFaceSets(output, blockNo);
554 convertMeshPointSets(output, blockNo);
555 reader_->UpdateProgress(0.7);
558 convertMeshLagrangian(lagrangianOutput, blockNo);
560 reader_->UpdateProgress(0.8);
563 convertFields(output);
564 convertLagrangianFields(lagrangianOutput);
571 reader_->UpdateProgress(0.95);
573 meshChanged_ = fieldsChanged_ =
false;
581 reader_->UpdateProgress(1.0);
588 double* tsteps =
nullptr;
592 Time& runTime = dbPtr_();
599 for (; timeI < timeLst.size(); ++timeI)
601 const word&
timeName = timeLst[timeI].name();
605 typeIOobject<pointIOField>
618 nTimes = timeLst.size() - timeI;
621 if (timeI == 0 && nTimes > 1)
623 if (timeLst[timeI].
name() == runTime.constant())
632 if (nTimes > 1 && reader_->GetSkipZeroTime())
634 if (
mag(timeLst[timeI].value()) < small)
643 tsteps =
new double[nTimes];
644 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
646 tsteps[stepI] = timeLst[timeI].value();
654 cout<<
"no valid dbPtr:\n";
667 vtkRenderer* renderer,
680 renderer->RemoveViewProp(patchTextActorsPtrs_[
patchi]);
681 patchTextActorsPtrs_[
patchi]->Delete();
683 patchTextActorsPtrs_.clear();
690 reader_->GetPartSelection(),
694 if (selectedPatches.empty())
699 const polyBoundaryMesh& pbMesh = meshPtr_->boundaryMesh();
707 List<DynamicList<point>> zoneCentre(pbMesh.size());
713 const polyPatch& pp = pbMesh[
patchi];
716 if (!selectedPatches.found(pp.name()))
724 boolList featEdge(pp.nEdges(),
false);
728 const labelList& eFaces = edgeFaces[edgeI];
730 if (eFaces.size() == 1)
734 featEdge[edgeI] =
true;
736 else if (
mag(
n[eFaces[0]] &
n[eFaces[1]]) < 0.5)
738 featEdge[edgeI] =
true;
743 patchZones
pZones(pp, featEdge);
759 zoneCentre[
patchi][zoneI] += pp[facei].centre(pp.points());
765 zoneCentre[
patchi][zoneI] /= zoneNFaces[zoneI];
772 const label MAXPATCHZONES = 20;
774 label displayZoneI = 0;
778 displayZoneI +=
min(MAXPATCHZONES, nZones[
patchi]);
783 Info<<
" displayed zone centres = " << displayZoneI <<
nl
784 <<
" zones per patch = " << nZones <<
endl;
788 patchTextActorsPtrs_.setSize(displayZoneI);
792 Info<<
" constructing patch labels" <<
endl;
800 const polyPatch& pp = pbMesh[
patchi];
802 label globalZoneI = 0;
807 if (nZones[
patchi] >= MAXPATCHZONES)
809 increment = nZones[
patchi]/MAXPATCHZONES;
812 for (
label i = 0; i < nDisplayZones; i++)
816 Info<<
" patch name = " << pp.name() <<
nl
817 <<
" anchor = " << zoneCentre[
patchi][globalZoneI]
819 <<
" globalZoneI = " << globalZoneI <<
endl;
824 txt->SetInput(pp.name().c_str());
827 vtkTextProperty* tprop = txt->GetTextProperty();
828 tprop->SetFontFamilyToArial();
831 tprop->SetLineSpacing(1.0);
832 tprop->SetFontSize(12);
833 tprop->SetColor(1.0, 0.0, 0.0);
834 tprop->SetJustificationToCentered();
837 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
839 txt->GetPositionCoordinate()->SetValue
841 zoneCentre[
patchi][globalZoneI].
x(),
842 zoneCentre[
patchi][globalZoneI].
y(),
843 zoneCentre[
patchi][globalZoneI].z()
847 renderer->AddViewProp(txt);
851 patchTextActorsPtrs_[displayZoneI] = txt;
853 globalZoneI += increment;
859 patchTextActorsPtrs_.setSize(displayZoneI);
866 os <<
indent <<
"Number of nodes: "
867 << (meshPtr_ ? meshPtr_->nPoints() : 0) <<
"\n";
869 os <<
indent <<
"Number of cells: "
870 << (meshPtr_ ? meshPtr_->nCells() : 0) <<
"\n";
872 os <<
indent <<
"Number of available time steps: "
873 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
875 os <<
indent <<
"mesh region: " << meshRegion_ <<
"\n";
graph_traits< Graph >::vertices_size_type size_type
#define forAll(list, i)
Loop across all elements in list.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
virtual const fileName & name() const
Return the name of the stream.
void setSize(const label)
Reset size of List.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
fileName path() const
Return directory path name (part before last /)
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
virtual fileName filePath(const bool globalFile, const IOobject &, const word &typeName) const =0
Search for an object. globalFile : also check undecomposed case.
int setTime(int count, const double requestTimes[])
Set the runTime to the first plausible request time,.
void PrintSelf(ostream &, vtkIndent) const
Debug information.
void renderPatchNames(vtkRenderer *, const bool show)
Add/remove patch names to/from the view.
vtkPVFoam(const char *const FileName, vtkPVFoamReader *reader)
Construct from components.
void CleanUp()
Clean any storage.
double * findTimes(int &nTimeSteps)
Allocate and return a list of selected times.
void Update(vtkMultiBlockDataSet *output, vtkMultiBlockDataSet *lagrangianOutput)
Update.
void updateInfo()
Update information for selection dialogs.
IOporosityModelList pZones(mesh)
Functions to search 'etc' directories for configuration files etc.
#define InfoInFunction
Report an information message using Foam::Info.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
const fileOperation & fileHandler()
Get current file handler.
fileName cwd()
Return current working directory path name.
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable.
List< fileName > fileNameList
A List of fileNames.
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
List< bool > boolList
Bool container classes.
labelList first(const UList< labelPair > &p)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< instant > instantList
List of instants.
List< labelList > labelListList
A List of labelList.
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Field< vector > vectorField
Specialisation of Field<T> for vector.
string getEnv(const word &)
Return environment variable of given name.
fileNameList findEtcFiles(const fileName &, bool mandatory=false, bool findFirst=false)
Search for files from user/group/shipped directories.
HashSet wordHashSet
A HashSet with word keys.
List< string > stringList
A List of strings.
Ostream & indent(Ostream &os)
Indent stream.