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
491 Info<<
" Using existing OpenFOAM mesh" <<
endl;
498 meshPtr_->stitcher().reconnect(reader_->GetInterpolateVolFields());
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,
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());
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;
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";
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.