27 #include "vtkPV3FoamReader.h" 35 #include "vtkDataArraySelection.h" 36 #include "vtkMultiBlockDataSet.h" 37 #include "vtkRenderer.h" 38 #include "vtkTextActor.h" 39 #include "vtkTextProperty.h" 54 void Foam::vtkPV3Foam::resetCounters()
57 arrayRangeVolume_.reset();
58 arrayRangePatches_.reset();
59 arrayRangeLagrangian_.reset();
60 arrayRangeCellZones_.reset();
61 arrayRangeFaceZones_.reset();
62 arrayRangePointZones_.reset();
63 arrayRangeCellSets_.reset();
64 arrayRangeFaceSets_.reset();
65 arrayRangePointSets_.reset();
69 void Foam::vtkPV3Foam::reduceMemory()
71 forAll(regionPolyDecomp_, i)
73 regionPolyDecomp_[i].clear();
78 zonePolyDecomp_[i].clear();
83 csetPolyDecomp_[i].clear();
86 if (!reader_->GetCacheMesh())
96 Time& runTime = dbPtr_();
101 int nearestIndex = timeIndex_;
102 for (
int requestI = 0; requestI < nRequest; ++requestI)
105 if (index >= 0 && index != timeIndex_)
107 nearestIndex = index;
112 if (nearestIndex < 0)
119 Info<<
"<beg> Foam::vtkPV3Foam::setTime(";
120 for (
int requestI = 0; requestI < nRequest; ++requestI)
127 Info<< requestTimes[requestI];
129 Info<<
") - previousIndex = " << timeIndex_
130 <<
", nearestIndex = " << nearestIndex <<
endl;
135 if (timeIndex_ != nearestIndex)
137 timeIndex_ = nearestIndex;
138 runTime.setTime(Times[nearestIndex], nearestIndex);
141 fieldsChanged_ =
true;
155 reader_->UpdateProgress(0.05);
163 Info<<
"<end> Foam::vtkPV3Foam::setTime() - selectedTime=" 164 << Times[nearestIndex].name() <<
" index=" << timeIndex_
165 <<
"/" << Times.size()
166 <<
" meshChanged=" << Switch(meshChanged_)
167 <<
" fieldsChanged=" << Switch(fieldsChanged_) <<
endl;
174 void Foam::vtkPV3Foam::updateMeshPartsStatus()
178 Info<<
"<beg> Foam::vtkPV3Foam::updateMeshPartsStatus" <<
endl;
181 vtkDataArraySelection* selection = reader_->GetPartSelection();
182 label nElem = selection->GetNumberOfArrays();
184 if (partStatus_.size() != nElem)
186 partStatus_.setSize(nElem);
192 partDataset_.setSize(nElem);
196 forAll(partStatus_, partId)
198 const int setting = selection->GetArraySetting(partId);
200 if (partStatus_[partId] != setting)
202 partStatus_[partId] = setting;
208 Info<<
" part[" << partId <<
"] = " 209 << partStatus_[partId]
210 <<
" : " << selection->GetArrayName(partId) <<
endl;
215 Info<<
"<end> Foam::vtkPV3Foam::updateMeshPartsStatus" <<
endl;
222 Foam::vtkPV3Foam::vtkPV3Foam
224 const char*
const FileName,
225 vtkPV3FoamReader* reader
231 meshRegion_(polyMesh::defaultRegion),
232 meshDir_(polyMesh::meshSubDir),
235 fieldsChanged_(true),
236 arrayRangeVolume_(
"unzoned"),
237 arrayRangePatches_(
"patches"),
238 arrayRangeLagrangian_(
"lagrangian"),
239 arrayRangeCellZones_(
"cellZone"),
240 arrayRangeFaceZones_(
"faceZone"),
241 arrayRangePointZones_(
"pointZone"),
242 arrayRangeCellSets_(
"cellSet"),
243 arrayRangeFaceSets_(
"faceSet"),
244 arrayRangePointSets_(
"pointSet")
248 Info<<
"Foam::vtkPV3Foam::vtkPV3Foam - " << FileName <<
endl;
253 fileName fullCasePath(fileName(FileName).
path());
255 if (!
isDir(fullCasePath))
259 if (fullCasePath ==
".")
261 fullCasePath =
cwd();
265 if (fullCasePath.name().find(
"processor", 0) == 0)
267 const fileName globalCase = fullCasePath.path();
269 setEnv(
"FOAM_CASE", globalCase,
true);
270 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
274 setEnv(
"FOAM_CASE", fullCasePath,
true);
275 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
281 string caseName(fileName(FileName).lessExt());
287 beg != string::npos && caseName[beg] ==
'{' 288 && end != string::npos && end == caseName.size()-1
291 meshRegion_ = caseName.substr(beg+1, end-beg-1);
294 if (meshRegion_.empty())
296 meshRegion_ = polyMesh::defaultRegion;
299 if (meshRegion_ != polyMesh::defaultRegion)
301 meshDir_ = meshRegion_/polyMesh::meshSubDir;
307 Info<<
"fullCasePath=" << fullCasePath <<
nl 308 <<
"FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl 309 <<
"FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl 310 <<
"region=" << meshRegion_ <<
endl;
318 Time::controlDictName,
319 fileName(fullCasePath.path()),
320 fileName(fullCasePath.name())
324 dbPtr_().functionObjects().off();
336 Info<<
"<end> Foam::vtkPV3Foam::~vtkPV3Foam" <<
endl;
349 Info<<
"<beg> Foam::vtkPV3Foam::updateInfo" 350 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"NULL") <<
"] timeIndex=" 351 << timeIndex_ <<
endl;
356 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
369 if (!partSelection->GetNumberOfArrays() && !meshPtr_)
372 enabledEntries[0] =
"internalMesh";
376 enabledEntries = getSelectedArrayEntries(partSelection);
380 partSelection->RemoveAllArrays();
383 updateInfoInternalMesh(partSelection);
384 updateInfoPatches(partSelection, enabledEntries);
385 updateInfoSets(partSelection);
386 updateInfoZones(partSelection);
387 updateInfoLagrangian(partSelection);
390 setSelectedArrayEntries(partSelection, enabledEntries);
394 fieldsChanged_ =
true;
398 updateInfoFields<fvPatchField, volMesh>
400 reader_->GetVolFieldSelection()
402 updateInfoFields<pointPatchField, pointMesh>
404 reader_->GetPointFieldSelection()
406 updateInfoLagrangianFields();
411 getSelectedArrayEntries(partSelection);
412 Info<<
"<end> Foam::vtkPV3Foam::updateInfo" <<
endl;
418 void Foam::vtkPV3Foam::updateFoamMesh()
422 Info<<
"<beg> Foam::vtkPV3Foam::updateFoamMesh" <<
endl;
426 if (!reader_->GetCacheMesh())
437 Info<<
"Creating OpenFOAM mesh for region " << meshRegion_
438 <<
" at time=" << dbPtr_().timeName()
443 meshPtr_ =
new fvMesh
460 Info<<
"Using existing OpenFOAM mesh" <<
endl;
466 Info<<
"<end> Foam::vtkPV3Foam::updateFoamMesh" <<
endl;
474 vtkMultiBlockDataSet* output,
475 vtkMultiBlockDataSet* lagrangianOutput
480 cout<<
"<beg> Foam::vtkPV3Foam::Update - output with " 481 << output->GetNumberOfBlocks() <<
" and " 482 << lagrangianOutput->GetNumberOfBlocks() <<
" blocks\n";
484 lagrangianOutput->Print(cout);
487 reader_->UpdateProgress(0.1);
490 updateMeshPartsStatus();
492 reader_->UpdateProgress(0.15);
496 reader_->UpdateProgress(0.4);
501 convertMeshVolume(output, blockNo);
502 convertMeshPatches(output, blockNo);
503 reader_->UpdateProgress(0.6);
505 if (reader_->GetIncludeZones())
507 convertMeshCellZones(output, blockNo);
508 convertMeshFaceZones(output, blockNo);
509 convertMeshPointZones(output, blockNo);
510 reader_->UpdateProgress(0.65);
513 if (reader_->GetIncludeSets())
515 convertMeshCellSets(output, blockNo);
516 convertMeshFaceSets(output, blockNo);
517 convertMeshPointSets(output, blockNo);
518 reader_->UpdateProgress(0.7);
521 #ifdef VTKPV3FOAM_DUALPORT 525 convertMeshLagrangian(lagrangianOutput, blockNo);
527 reader_->UpdateProgress(0.8);
530 convertVolFields(output);
531 convertPointFields(output);
532 convertLagrangianFields(lagrangianOutput);
537 reader_->UpdateProgress(0.95);
539 meshChanged_ = fieldsChanged_ =
false;
547 reader_->UpdateProgress(1.0);
554 double* tsteps = NULL;
558 Time& runTime = dbPtr_();
563 for (; timeI < timeLst.size(); ++timeI)
565 const word& timeName = timeLst[timeI].name();
569 isFile(runTime.path()/timeName/meshDir_/
"points")
570 && IOobject(
"points", timeName, meshDir_, runTime).headerOk()
577 nTimes = timeLst.size() - timeI;
580 if (timeI == 0 && nTimes > 1)
582 if (timeLst[timeI].
name() == runTime.constant())
591 if (nTimes > 1 && reader_->GetSkipZeroTime())
593 if (
mag(timeLst[timeI].value()) < SMALL)
602 tsteps =
new double[nTimes];
603 for (
label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
605 tsteps[stepI] = timeLst[timeI].value();
613 cout<<
"no valid dbPtr:\n";
633 forAll(patchTextActorsPtrs_, patchi)
635 renderer->RemoveViewProp(patchTextActorsPtrs_[patchi]);
636 patchTextActorsPtrs_[
patchi]->Delete();
638 patchTextActorsPtrs_.
clear();
645 reader_->GetPartSelection(),
649 if (selectedPatches.empty())
654 const polyBoundaryMesh& pbMesh = meshPtr_->
boundaryMesh();
662 List<DynamicList<point>> zoneCentre(pbMesh.size());
668 const polyPatch& pp = pbMesh[
patchi];
671 if (!selectedPatches.found(pp.name()))
679 boolList featEdge(pp.nEdges(),
false);
683 const labelList& eFaces = edgeFaces[edgeI];
685 if (eFaces.size() == 1)
689 featEdge[edgeI] =
true;
691 else if (
mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
693 featEdge[edgeI] =
true;
698 patchZones
pZones(pp, featEdge);
714 zoneCentre[
patchi][zoneI] += pp[facei].centre(pp.points());
718 forAll(zoneCentre[patchi], zoneI)
720 zoneCentre[
patchi][zoneI] /= zoneNFaces[zoneI];
727 const label MAXPATCHZONES = 20;
729 label displayZoneI = 0;
733 displayZoneI +=
min(MAXPATCHZONES, nZones[patchi]);
738 Info<<
"displayed zone centres = " << displayZoneI <<
nl 739 <<
"zones per patch = " << nZones <<
endl;
743 patchTextActorsPtrs_.
setSize(displayZoneI);
747 Info<<
"constructing patch labels" <<
endl;
755 const polyPatch& pp = pbMesh[
patchi];
757 label globalZoneI = 0;
760 label nDisplayZones =
min(MAXPATCHZONES, nZones[patchi]);
762 if (nZones[patchi] >= MAXPATCHZONES)
764 increment = nZones[
patchi]/MAXPATCHZONES;
767 for (
label i = 0; i < nDisplayZones; i++)
771 Info<<
"patch name = " << pp.name() <<
nl 772 <<
"anchor = " << zoneCentre[
patchi][globalZoneI] <<
nl 773 <<
"globalZoneI = " << globalZoneI <<
endl;
778 txt->SetInput(pp.name().c_str());
781 vtkTextProperty* tprop = txt->GetTextProperty();
782 tprop->SetFontFamilyToArial();
785 tprop->SetLineSpacing(1.0);
786 tprop->SetFontSize(12);
787 tprop->SetColor(1.0, 0.0, 0.0);
788 tprop->SetJustificationToCentered();
791 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
793 txt->GetPositionCoordinate()->SetValue
795 zoneCentre[patchi][globalZoneI].
x(),
796 zoneCentre[patchi][globalZoneI].
y(),
797 zoneCentre[patchi][globalZoneI].z()
801 renderer->AddViewProp(txt);
805 patchTextActorsPtrs_[displayZoneI] = txt;
807 globalZoneI += increment;
813 patchTextActorsPtrs_.
setSize(displayZoneI);
820 os << indent <<
"Number of nodes: " 821 << (meshPtr_ ? meshPtr_->
nPoints() : 0) <<
"\n";
823 os << indent <<
"Number of cells: " 824 << (meshPtr_ ? meshPtr_->
nCells() : 0) <<
"\n";
826 os << indent <<
"Number of available time steps: " 827 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
829 os << indent <<
"mesh region: " << meshRegion_ <<
"\n";
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.
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
void renderPatchNames(vtkRenderer *, const bool show)
Add/remove patch names to/from the view.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
static void printMemory()
Simple memory used debugging information.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
List< bool > boolList
Bool container classes.
void clear()
Clear the list, i.e. set size to zero.
int setTime(int count, const double requestTimes[])
Set the runTime to the first plausible request time,.
void PrintSelf(ostream &, vtkIndent) const
Debug information.
List< label > labelList
A List of labels.
double * findTimes(int &nTimeSteps)
Allocate and return a list of selected times.
HashSet wordHashSet
A HashSet with word keys.
void Update(vtkMultiBlockDataSet *output, vtkMultiBlockDataSet *lagrangianOutput)
graph_traits< Graph >::vertices_size_type size_type
void CleanUp()
Clean any storage.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
List< string > stringList
A List of strings.
void setSize(const label)
Reset size of List.
fileName cwd()
Return current working directory path name.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
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)