From ecb80a2ee84439ec594a234bfc234140a6623d1e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 12 Jan 2017 06:40:58 +0100 Subject: [PATCH] ENH: refactor paraview readers code to avoid duplication - as originally intended years ago, but never actually done. - use 'foamPvCore' instead of 'vtkPVReaders' to avoid potential name collisions with any 'vtk*' files and since we may reuse these functions in other foam-paraview modules (not just readers). STYLE: use same font size/colour for patch-names as for point-numbers BUG: repair issue with single time-step - paraview time-selector returns '0' as the requested time if there is only one time step. However, if we have skipped the 0/ directory, this single time step is likely a non-zero value. --- .../graphics/PVReaders/Allwclean | 2 +- .../graphics/PVReaders/Allwmake | 2 +- .../PVFoamReader/PVFoamReader/CMakeLists.txt | 2 + .../PVFoamReader/PVFoamReader_SM.xml | 11 + .../PVFoamReader/vtkPVFoamReader.cxx | 178 ++-- .../PVFoamReader/vtkPVFoamReader.h | 7 +- .../PVFoamReader/vtkPVFoam/Make/files | 3 - .../PVFoamReader/vtkPVFoam/Make/options | 4 +- .../vtkPVFoam/vtkOpenFOAMPoints.H | 79 -- .../PVFoamReader/vtkPVFoam/vtkPVFoam.C | 143 ++- .../PVFoamReader/vtkPVFoam/vtkPVFoam.H | 663 +++++-------- .../vtkPVFoam/vtkPVFoamFaceField.H | 117 --- .../vtkPVFoam/vtkPVFoamFieldTemplates.C | 909 ++++++++++++++++++ .../PVFoamReader/vtkPVFoam/vtkPVFoamFields.C | 183 ++-- .../vtkPVFoam/vtkPVFoamLagrangianFields.H | 113 --- .../PVFoamReader/vtkPVFoam/vtkPVFoamMesh.C | 121 ++- .../vtkPVFoam/vtkPVFoamMeshLagrangian.C | 11 +- .../PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C | 148 --- .../vtkPVFoam/vtkPVFoamMeshVolume.C | 39 +- .../vtkPVFoam/vtkPVFoamMeshZone.C | 75 -- .../vtkPVFoam/vtkPVFoamPatchField.H | 129 --- .../vtkPVFoam/vtkPVFoamPointFields.H | 331 ------- .../vtkPVFoam/vtkPVFoamTemplates.C | 10 +- .../vtkPVFoam/vtkPVFoamUpdateInfo.C | 151 ++- ...nfoFields.H => vtkPVFoamUpdateTemplates.C} | 25 +- .../PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C | 340 ------- .../vtkPVFoam/vtkPVFoamVolFields.H | 456 --------- .../PVblockMeshReader/CMakeLists.txt | 2 + .../vtkPVblockMeshReader.cxx | 34 +- .../PVblockMeshReader/vtkPVblockMeshReader.h | 5 +- .../vtkPVblockMesh/Make/files | 1 - .../vtkPVblockMesh/Make/options | 4 +- .../vtkPVblockMesh/vtkOpenFOAMPoints.H | 65 -- .../vtkPVblockMesh/vtkPVblockMesh.C | 42 +- .../vtkPVblockMesh/vtkPVblockMesh.H | 133 +-- .../vtkPVblockMesh/vtkPVblockMeshConvert.C | 51 +- .../vtkPVblockMesh/vtkPVblockMeshUtils.C | 316 ------ .../graphics/PVReaders/foamPv/Make/files | 3 + .../{vtkPVReaders => foamPv}/Make/options | 1 + .../vtkPVReaders.C => foamPv/foamPvCore.C} | 212 ++-- .../vtkPVReaders.H => foamPv/foamPvCore.H} | 168 ++-- .../foamPvCoreTemplates.C} | 60 +- .../foamPvFields.H} | 49 +- .../PVReaders/vtkPVReaders/Make/files | 3 - 44 files changed, 1933 insertions(+), 3468 deletions(-) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamLagrangianFields.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshZone.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPatchField.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPointFields.H rename applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/{vtkPVFoamUpdateInfoFields.H => vtkPVFoamUpdateTemplates.C} (84%) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamVolFields.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkOpenFOAMPoints.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/files rename applications/utilities/postProcessing/graphics/PVReaders/{vtkPVReaders => foamPv}/Make/options (79%) rename applications/utilities/postProcessing/graphics/PVReaders/{vtkPVReaders/vtkPVReaders.C => foamPv/foamPvCore.C} (58%) rename applications/utilities/postProcessing/graphics/PVReaders/{vtkPVReaders/vtkPVReaders.H => foamPv/foamPvCore.H} (52%) rename applications/utilities/postProcessing/graphics/PVReaders/{PVFoamReader/vtkPVFoam/vtkPVFoamAddToSelection.H => foamPv/foamPvCoreTemplates.C} (63%) rename applications/utilities/postProcessing/graphics/PVReaders/{PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H => foamPv/foamPvFields.H} (59%) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean index 23ec661742..6614154374 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean @@ -1,7 +1,7 @@ #!/bin/sh cd ${0%/*} || exit 1 # Run from this directory -wclean libso vtkPVReaders +wclean libso foamPv PVblockMeshReader/Allwclean PVFoamReader/Allwclean diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake index c6ca055da0..2f89bc4c8a 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake @@ -97,7 +97,7 @@ case "$major" in if canBuildPlugin then ( - wmakeLibPv vtkPVReaders + wmakeLibPv foamPv PVblockMeshReader/Allwmake $targetType $* PVFoamReader/Allwmake $targetType $* diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt index 40745ba928..819a476c3a 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories( $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPVFoam + ${PROJECT_SOURCE_DIR}/../../foamPv/lnInclude ) add_definitions( @@ -63,6 +64,7 @@ target_link_libraries( PVFoamReader_SM LINK_PUBLIC vtkPVFoam-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} + foamPv-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} finiteVolume OpenFOAM ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml index ebb0c3be93..82b3384a28 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml @@ -273,6 +273,17 @@ The list of point fields. + + + + Print basic information to stdout + + + + #undef EXPERIMENTAL_TIME_CACHING // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -58,10 +62,9 @@ vtkPVFoamReader::vtkPVFoamReader() SetNumberOfInputPorts(0); - FileName = nullptr; - foamData_ = nullptr; - - output0_ = nullptr; + FileName = nullptr; + backend_ = nullptr; + output0_ = nullptr; #ifdef VTKPVFOAM_DUALPORT // Add second output for the Lagrangian @@ -133,11 +136,11 @@ vtkPVFoamReader::~vtkPVFoamReader() { vtkDebugMacro(<<"Deconstructor"); - if (foamData_) + if (backend_) { // remove patch names updatePatchNamesView(false); - delete foamData_; + delete backend_; } if (FileName) @@ -188,7 +191,7 @@ int vtkPVFoamReader::RequestInformation return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); + const int nInfo = outputVector->GetNumberOfInformationObjects(); if (Foam::vtkPVFoam::debug) { @@ -199,60 +202,70 @@ int vtkPVFoamReader::RequestInformation } } - if (!foamData_) + if (!backend_) { - foamData_ = new Foam::vtkPVFoam(FileName, this); + backend_ = new Foam::vtkPVFoam(FileName, this); } else { - foamData_->updateInfo(); + backend_->updateInfo(); } - int nTimeSteps = 0; - double* timeSteps = foamData_->findTimes(nTimeSteps); + std::vector times = backend_->findTimes(this->SkipZeroTime); - if (!nTimeSteps) + if (times.empty()) { vtkErrorMacro("could not find valid OpenFOAM mesh"); // delete foamData and flag it as fatal error - delete foamData_; - foamData_ = nullptr; + delete backend_; + backend_ = nullptr; return 0; } // set identical time steps for all ports for (int infoI = 0; infoI < nInfo; ++infoI) { - outputVector->GetInformationObject(infoI)->Set + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + outInfo->Set ( vtkStreamingDemandDrivenPipeline::TIME_STEPS(), - timeSteps, - nTimeSteps + times.data(), + static_cast(times.size()) ); + + // Something like this may be useful: + // outInfo->Set + // ( + // vtkStreamingDemandDrivenPipeline::TIME_DEPENDENT_INFORMATION(), + // 1 + // ); } - if (nTimeSteps) + if (times.size()) { - double timeRange[2]; - timeRange[0] = timeSteps[0]; - timeRange[1] = timeSteps[nTimeSteps-1]; + double timeRange[2]{ times.front(), times.back() }; if (Foam::vtkPVFoam::debug > 1) { - cout<<"nTimeSteps " << nTimeSteps << "\n" - <<"timeRange " << timeRange[0] << " to " << timeRange[1] - << "\n"; + cout + <<"nInfo " << nInfo << "\n" + <<"time-range " << times.front() << ':' << times.back() << "\n" + <<"times " << times.size() << "("; - for (int timeI = 0; timeI < nTimeSteps; ++timeI) + for (const double& val : times) { - cout<< "step[" << timeI << "] = " << timeSteps[timeI] << "\n"; + cout<< ' ' << val; } + cout << " )" << std::endl; } for (int infoI = 0; infoI < nInfo; ++infoI) { - outputVector->GetInformationObject(infoI)->Set + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + outInfo->Set ( vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, @@ -261,8 +274,6 @@ int vtkPVFoamReader::RequestInformation } } - delete timeSteps; - return 1; } @@ -282,15 +293,14 @@ int vtkPVFoamReader::RequestData vtkErrorMacro("FileName has to be specified!"); return 0; } - - // catch previous error - if (!foamData_) + if (!backend_) { + // catch some previous error vtkErrorMacro("Reader failed - perhaps no mesh?"); return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); + const int nInfo = outputVector->GetNumberOfInformationObjects(); if (Foam::vtkPVFoam::debug) { @@ -315,23 +325,31 @@ int vtkPVFoamReader::RequestData { vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + int nsteps = outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()); + if ( outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) - && outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()) > 0 + && nsteps > 0 ) { - requestTime[nRequestTime++] = - outInfo->Get - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP() - ); + requestTime[nRequestTime] = + ( + 1 == nsteps + // Only one time-step available, UPDATE_TIME_STEP is unreliable + ? outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), 0) + : outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) + ); + + // outInfo->Set(vtkDataObject::DATA_TIME_STEP(), requestTime[nRequestTime]); + // this->SetTimeValue(requestedTimeValue); + ++nRequestTime; } } if (nRequestTime) { - foamData_->setTime(nRequestTime, requestTime); + backend_->setTime(nRequestTime, requestTime); } vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast @@ -362,7 +380,7 @@ int vtkPVFoamReader::RequestData // but trashes the fields and still triggers the GeometryFilter if (needsUpdate) { - foamData_->Update(output); + backend_->Update(output); output0_->ShallowCopy(output); } else @@ -391,7 +409,7 @@ int vtkPVFoamReader::RequestData #else #ifdef VTKPVFOAM_DUALPORT - foamData_->Update + backend_->Update ( output, vtkMultiBlockDataSet::SafeDownCast @@ -403,7 +421,7 @@ int vtkPVFoamReader::RequestData ); ); #else - foamData_->Update(output, output); + backend_->Update(output, output); #endif updatePatchNamesView(ShowPatchNames); @@ -411,12 +429,27 @@ int vtkPVFoamReader::RequestData #endif // Do any cleanup on the OpenFOAM side - foamData_->CleanUp(); + backend_->CleanUp(); return 1; } +void vtkPVFoamReader::PrintInfo() +{ + if (backend_) + { + backend_->printInfo(); + } + else + { + cout + <<"OpenFOAM reader not initialized\n" + << std::flush; + } +} + + void vtkPVFoamReader::SetRefresh(bool val) { Modified(); @@ -428,9 +461,9 @@ void vtkPVFoamReader::SetIncludeSets(bool val) if (IncludeSets != val) { IncludeSets = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -441,9 +474,9 @@ void vtkPVFoamReader::SetIncludeZones(bool val) if (IncludeZones != val) { IncludeZones = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -464,9 +497,9 @@ void vtkPVFoamReader::SetShowGroupsOnly(bool val) if (ShowGroupsOnly != val) { ShowGroupsOnly = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -485,7 +518,7 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) // Server manager model for querying items in the server manager pqServerManagerModel* smModel = appCore->getServerManagerModel(); - if (!smModel || !foamData_) + if (!smModel || !backend_) { return; } @@ -495,7 +528,7 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) for (int viewI=0; viewI < renderViews.size(); ++viewI) { - foamData_->renderPatchNames + backend_->renderPatchNames ( renderViews[viewI]->getRenderViewProxy()->GetRenderer(), show @@ -514,7 +547,7 @@ void vtkPVFoamReader::PrintSelf(ostream& os, vtkIndent indent) os << indent << "File name: " << (this->FileName ? this->FileName : "(none)") << "\n"; - foamData_->PrintSelf(os, indent); + backend_->PrintSelf(os, indent); os << indent << "Time step range: " << this->TimeStepRange[0] << " - " << this->TimeStepRange[1] << "\n" @@ -524,7 +557,7 @@ void vtkPVFoamReader::PrintSelf(ostream& os, vtkIndent indent) int vtkPVFoamReader::GetTimeStep() { - return foamData_ ? foamData_->timeIndex() : -1; + return backend_ ? backend_->timeIndex() : -1; } @@ -533,32 +566,24 @@ int vtkPVFoamReader::GetTimeStep() vtkDataArraySelection* vtkPVFoamReader::GetPartSelection() { - vtkDebugMacro(<<"GetPartSelection"); return PartSelection; } - int vtkPVFoamReader::GetNumberOfPartArrays() { - vtkDebugMacro(<<"GetNumberOfPartArrays"); return PartSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetPartArrayName(int index) { - vtkDebugMacro(<<"GetPartArrayName"); return PartSelection->GetArrayName(index); } - int vtkPVFoamReader::GetPartArrayStatus(const char* name) { - vtkDebugMacro(<<"GetPartArrayStatus"); return PartSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) { vtkDebugMacro("Set mesh part \"" << name << "\" status to: " << status); @@ -579,35 +604,26 @@ void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetVolFieldSelection() { - vtkDebugMacro(<<"GetVolFieldSelection"); return VolFieldSelection; } - int vtkPVFoamReader::GetNumberOfVolFieldArrays() { - vtkDebugMacro(<<"GetNumberOfVolFieldArrays"); return VolFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetVolFieldArrayName(int index) { - vtkDebugMacro(<<"GetVolFieldArrayName"); return VolFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetVolFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetVolFieldArrayStatus"); return VolFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetVolFieldArrayStatus"); if (status) { VolFieldSelection->EnableArray(name); @@ -624,35 +640,26 @@ void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetPointFieldSelection() { - vtkDebugMacro(<<"GetPointFieldSelection"); return PointFieldSelection; } - int vtkPVFoamReader::GetNumberOfPointFieldArrays() { - vtkDebugMacro(<<"GetNumberOfPointFieldArrays"); return PointFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetPointFieldArrayName(int index) { - vtkDebugMacro(<<"GetPointFieldArrayName"); return PointFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetPointFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetPointFieldArrayStatus"); return PointFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetPointFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetPointFieldArrayStatus"); if (status) { PointFieldSelection->EnableArray(name); @@ -669,39 +676,30 @@ void vtkPVFoamReader::SetPointFieldArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetLagrangianFieldSelection() { - vtkDebugMacro(<<"GetLagrangianFieldSelection"); return LagrangianFieldSelection; } - int vtkPVFoamReader::GetNumberOfLagrangianFieldArrays() { - vtkDebugMacro(<<"GetNumberOfLagrangianFieldArrays"); return LagrangianFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetLagrangianFieldArrayName(int index) { - vtkDebugMacro(<<"GetLagrangianFieldArrayName"); return LagrangianFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetLagrangianFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetLagrangianFieldArrayStatus"); return LagrangianFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetLagrangianFieldArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetLagrangianFieldArrayStatus"); if (status) { LagrangianFieldSelection->EnableArray(name); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h index 74aeedda34..28a68445cd 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h @@ -77,6 +77,10 @@ public: vtkSetStringMacro(FileName); vtkGetStringMacro(FileName); + // Description: + // Print some case information + virtual void PrintInfo(); + // Description: // OpenFOAM mesh caching control vtkSetMacro(CacheMesh, bool); @@ -250,7 +254,8 @@ private: //- Cached data for output port0 (experimental!) vtkMultiBlockDataSet* output0_; - Foam::vtkPVFoam* foamData_; + //- Backend portion of the reader + Foam::vtkPVFoam* backend_; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files index 6f9412f0af..c159826919 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files @@ -2,10 +2,7 @@ vtkPVFoam.C vtkPVFoamFields.C vtkPVFoamMesh.C vtkPVFoamMeshLagrangian.C -vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C -vtkPVFoamMeshZone.C vtkPVFoamUpdateInfo.C -vtkPVFoamUtils.C LIB = $(FOAM_LIBBIN)/libvtkPVFoam-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options index aa2b9039da..4a73939711 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options @@ -10,7 +10,7 @@ EXE_INC = \ -I$(LIB_SRC)/conversion/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ - -I../../vtkPVReaders/lnInclude \ + -I../../foamPv/lnInclude \ -I../PVFoamReader LIB_LIBS = \ @@ -18,5 +18,5 @@ LIB_LIBS = \ -lconversion \ -lgenericPatchFields \ -llagrangian \ - -L$(FOAM_LIBBIN) -lvtkPVReaders-pv${ParaView_MAJOR} \ + -L$(FOAM_LIBBIN) -lfoamPv-pv${ParaView_MAJOR} \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H deleted file mode 100644 index 2a45d73b2a..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H +++ /dev/null @@ -1,79 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkOpenFOAMPoints_H -#define vtkOpenFOAMPoints_H - -// VTK includes -#include "vtkPoints.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -inline void vtkInsertNextOpenFOAMPoint -( - vtkPoints *points, - const Foam::point& p -) -{ - points->InsertNextPoint(p.x(), p.y(), p.z()); -} - -#if 0 -// this should be faster, but didn't get it working ... -inline void vtkSetOpenFOAMPoint -( - vtkPoints *points, - const Foam::label id, - const Foam::point& p -) -{ - points->SetPoint(id, p.x(), p.y(), p.z()); -} - - -// Convert OpenFOAM mesh vertices to VTK -inline vtkPoints* vtkSetOpenFOAMPoints(const Foam::pointField& points) -{ - vtkPoints *vtkpoints = vtkPoints::New(); - vtkpoints->SetNumberOfPoints(points.size()); - forAll(points, i) - { - const Foam::point& p = points[i]; - vtkpoints->SetPoint(i, p.x(), p.y(), p.z()); - } - - return vtkpoints; -} - -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C index 0f8e09252c..9ec5d92e71 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,15 +42,11 @@ License namespace Foam { -defineTypeNameAndDebug(vtkPVFoam, 0); + defineTypeNameAndDebug(vtkPVFoam, 0); } - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -#include "vtkPVFoamAddToSelection.H" -#include "vtkPVFoamUpdateInfoFields.H" - void Foam::vtkPVFoam::resetCounters() { // Reset array range information (ids and sizes) @@ -116,14 +112,10 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[]) if (debug) { - Info<< " Foam::vtkPVFoam::setTime("; + Info<< " setTime("; for (int requestI = 0; requestI < nRequest; ++requestI) { - if (requestI) - { - Info<< ", "; - } - + if (requestI) Info<< ", "; Info<< requestTimes[requestI]; } Info<< ") - previousIndex = " << timeIndex_ @@ -160,7 +152,7 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[]) if (debug) { - Info<< " Foam::vtkPVFoam::setTime() - selectedTime=" + Info<< " setTime() - selectedTime=" << Times[nearestIndex].name() << " index=" << timeIndex_ << "/" << Times.size() << " meshChanged=" << Switch(meshChanged_) @@ -175,7 +167,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() { if (debug) { - Info<< " Foam::vtkPVFoam::updateMeshPartsStatus" << endl; + Info<< " updateMeshPartsStatus" << endl; } vtkDataArraySelection* selection = reader_->GetPartSelection(); @@ -203,7 +195,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() meshChanged_ = true; } - if (debug) + if (debug > 1) { Info<< " part[" << partId << "] = " << partStatus_[partId] @@ -212,11 +204,17 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() } if (debug) { - Info<< " Foam::vtkPVFoam::updateMeshPartsStatus" << endl; + Info<< " updateMeshPartsStatus" << endl; } } +Foam::word Foam::vtkPVFoam::getPartName(const int partId) +{ + return getFirstWord(reader_->GetPartArrayName(partId)); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::vtkPVFoam::vtkPVFoam @@ -245,7 +243,7 @@ Foam::vtkPVFoam::vtkPVFoam { if (debug) { - Info<< "Foam::vtkPVFoam::vtkPVFoam - " << FileName << endl; + Info<< "vtkPVFoam - " << FileName << endl; printMemory(); } @@ -333,7 +331,7 @@ Foam::vtkPVFoam::~vtkPVFoam() { if (debug) { - Info<< " Foam::vtkPVFoam::~vtkPVFoam" << endl; + Info<< "~vtkPVFoam" << endl; } delete meshPtr_; @@ -346,7 +344,7 @@ void Foam::vtkPVFoam::updateInfo() { if (debug) { - Info<< " Foam::vtkPVFoam::updateInfo" + Info<< " updateInfo" << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "] timeIndex=" << timeIndex_ << endl; } @@ -363,16 +361,15 @@ void Foam::vtkPVFoam::updateInfo() // time of the vtkDataArraySelection, but the qt/paraview proxy // layer doesn't care about that anyhow. - // enable 'internalMesh' on the first call - // or preserve the enabled selections stringList enabledEntries; if (!partSelection->GetNumberOfArrays() && !meshPtr_) { - enabledEntries.setSize(1); - enabledEntries[0] = "internalMesh"; + // enable 'internalMesh' on the first call + enabledEntries = { "internalMesh" }; } else { + // preserve the enabled selections enabledEntries = getSelectedArrayEntries(partSelection); } @@ -395,23 +392,12 @@ void Foam::vtkPVFoam::updateInfo() } // Update volume, point and lagrangian fields - updateInfoFields - ( - reader_->GetVolFieldSelection() - ); - updateInfoFields - ( - reader_->GetPointFieldSelection() - ); - updateInfoLagrangianFields(); + updateInfoFields(); if (debug) { - // just for debug info - getSelectedArrayEntries(partSelection); - Info<< " Foam::vtkPVFoam::updateInfo" << endl; + Info<< " updateInfo" << endl; } - } @@ -419,7 +405,7 @@ void Foam::vtkPVFoam::updateFoamMesh() { if (debug) { - Info<< " Foam::vtkPVFoam::updateFoamMesh" << endl; + Info<< " updateFoamMesh" << endl; printMemory(); } @@ -463,7 +449,7 @@ void Foam::vtkPVFoam::updateFoamMesh() if (debug) { - Info<< " Foam::vtkPVFoam::updateFoamMesh" << endl; + Info<< " updateFoamMesh" << endl; printMemory(); } } @@ -532,7 +518,7 @@ void Foam::vtkPVFoam::Update convertLagrangianFields(lagrangianOutput); if (debug) { - Info<< "done reader part" << endl; + Info<< "done reader part" << nl << endl; } reader_->UpdateProgress(0.95); @@ -548,68 +534,58 @@ void Foam::vtkPVFoam::CleanUp() } -double* Foam::vtkPVFoam::findTimes(int& nTimeSteps) +std::vector Foam::vtkPVFoam::findTimes(const bool skipZero) const { - int nTimes = 0; - double* tsteps = nullptr; + std::vector times; if (dbPtr_.valid()) { - Time& runTime = dbPtr_(); + const Time& runTime = dbPtr_(); instantList timeLst = runTime.times(); // find the first time for which this mesh appears to exist - label timeI = 0; - for (; timeI < timeLst.size(); ++timeI) + label begIndex = timeLst.size(); + forAll(timeLst, timeI) { - const word& timeName = timeLst[timeI].name(); - if ( - isFile(runTime.path()/timeName/meshDir_/"points") - && IOobject + IOobject ( "points", - timeName, + timeLst[timeI].name(), meshDir_, runTime - ).typeHeaderOk(true) + ).typeHeaderOk(false, false) ) { + begIndex = timeI; break; } } - nTimes = timeLst.size() - timeI; + label nTimes = timeLst.size() - begIndex; // skip "constant" time whenever possible - if (timeI == 0 && nTimes > 1) + if (begIndex == 0 && nTimes > 1) { - if (timeLst[timeI].name() == runTime.constant()) + if (timeLst[begIndex].name() == runTime.constant()) { - ++timeI; + ++begIndex; --nTimes; } } - // skip "0/" time if requested and possible - if (nTimes > 1 && reader_->GetSkipZeroTime()) + if (skipZero && nTimes > 1 && timeLst[begIndex].name() == "0") { - if (mag(timeLst[timeI].value()) < SMALL) - { - ++timeI; - --nTimes; - } + ++begIndex; + --nTimes; } - if (nTimes) + times.reserve(nTimes); + while (nTimes-- > 0) { - tsteps = new double[nTimes]; - for (label stepI = 0; stepI < nTimes; ++stepI, ++timeI) - { - tsteps[stepI] = timeLst[timeI].value(); - } + times.push_back(timeLst[begIndex++].value()); } } else @@ -620,10 +596,7 @@ double* Foam::vtkPVFoam::findTimes(int& nTimeSteps) } } - // vector length returned via the parameter - nTimeSteps = nTimes; - - return tsteps; + return times; } @@ -650,7 +623,7 @@ void Foam::vtkPVFoam::renderPatchNames if (show) { // get the display patches, strip off any suffix - wordHashSet selectedPatches = getSelected + hashedWordList selectedPatches = getSelected ( reader_->GetPartSelection(), arrayRangePatches_ @@ -793,8 +766,8 @@ void Foam::vtkPVFoam::renderPatchNames tprop->BoldOff(); tprop->ShadowOff(); tprop->SetLineSpacing(1.0); - tprop->SetFontSize(12); - tprop->SetColor(1.0, 0.0, 0.0); + tprop->SetFontSize(14); + tprop->SetColor(1.0, 0.0, 1.0); tprop->SetJustificationToCentered(); // Set text to use 3-D world co-ordinates @@ -840,4 +813,24 @@ void Foam::vtkPVFoam::PrintSelf(ostream& os, vtkIndent indent) const } +void Foam::vtkPVFoam::printInfo() const +{ + std::cout + << "Region: " << meshRegion_ << "\n" + << "nPoints: " << (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n" + << "nCells: " << (meshPtr_ ? meshPtr_->nCells() : 0) << "\n" + << "nTimes: " + << (dbPtr_.valid() ? dbPtr_().times().size() : 0) << "\n"; + + std::vector times = this->findTimes(reader_->GetSkipZeroTime()); + + std::cout<<" " << times.size() << "("; + for (const double& val : times) + { + std::cout<< ' ' << val; + } + std::cout << " )" << std::endl; +} + + // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H index fb3a988b86..17322e44c7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,24 +29,15 @@ Description SourceFiles vtkPVFoam.C - vtkPVFoam.H vtkPVFoamFields.C vtkPVFoamMesh.C vtkPVFoamMeshLagrangian.C - vtkPVFoamTemplates.C - vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C - vtkPVFoamMeshZone.C - vtkPVFoamFaceField.H - vtkPVFoamLagrangianFields.H - vtkPVFoamPatchField.H - vtkPVFoamPointFields.H - vtkPVFoamPoints.H + vtkPVFoamTemplates.C vtkPVFoamUpdateInfo.C - vtkPVFoamUpdateInfoFields.H vtkPVFoamUtils.C - vtkPVFoamVolFields.H - vtkPVFoamAddToSelection.H + vtkPVFoamFieldTemplates.C + vtkPVFoamUpdateTemplates.C // Needed by VTK: vtkDataArrayTemplateImplicit.txx @@ -63,6 +54,7 @@ SourceFiles #include "primitivePatch.H" #include "PrimitivePatchInterpolation.H" #include "volPointInterpolation.H" +#include "foamPvCore.H" #undef VTKPVFOAM_DUALPORT @@ -70,6 +62,7 @@ SourceFiles class vtkDataArraySelection; class vtkDataSet; +class vtkFloatArray; class vtkPoints; class vtkPVFoamReader; class vtkRenderer; @@ -90,10 +83,9 @@ class Time; class fvMesh; class IOobjectList; class polyPatch; -class faceSet; -class pointSet; template class IOField; +template class Field; template class List; /*---------------------------------------------------------------------------*\ @@ -101,84 +93,15 @@ template class List; \*---------------------------------------------------------------------------*/ class vtkPVFoam +: + private foamPvCore { + // Convenience typedefs + typedef PrimitivePatchInterpolation patchInterpolator; + + // Private classes - //- Bookkeeping for GUI checklists and the multi-block organization - class arrayRange - { - const char *name_; - int block_; - int start_; - int size_; - - public: - - arrayRange(const char *name, const int blockNo=0) - : - name_(name), - block_(blockNo), - start_(0), - size_(0) - {} - - //- Return the block holding these datasets - int block() const - { - return block_; - } - - //- Assign block number, return previous value - int block(int blockNo) - { - int prev = block_; - block_ = blockNo; - return prev; - } - - //- Return block name - const char* name() const - { - return name_; - } - - //- Return array start index - int start() const - { - return start_; - } - - //- Return array end index - int end() const - { - return start_ + size_; - } - - //- Return sublist size - int size() const - { - return size_; - } - - bool empty() const - { - return !size_; - } - - //- Reset the size to zero and optionally assign a new start - void reset(const int startAt = 0) - { - start_ = startAt; - size_ = 0; - } - - //- Increment the size - void operator+=(const int n) - { - size_ += n; - } - }; - //- Bookkeeping for polyhedral cell decomposition // hide in extra pointMap (cellSet/cellZone) for now class polyDecomp @@ -297,372 +220,258 @@ class vtkPVFoam //- List of patch names for rendering to window List patchTextActorsPtrs_; + // Private Member Functions - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static void AddToBlock - ( - vtkMultiBlockDataSet* output, - vtkDataSet* dataset, - const arrayRange&, - const label datasetNo, - const std::string& datasetName - ); - - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static vtkDataSet* GetDataSetFromBlock - ( - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static label GetNumberOfDataSets - ( - vtkMultiBlockDataSet* output, - const arrayRange& - ); - //- Reset data counters void resetCounters(); - // Update information helper functions + // Update information helper functions - //- Update the mesh parts selected in the GUI - void updateMeshPartsStatus(); + //- Update the mesh parts selected in the GUI + void updateMeshPartsStatus(); - //- Internal mesh info - void updateInfoInternalMesh(vtkDataArraySelection*); + //- Internal mesh info + void updateInfoInternalMesh(vtkDataArraySelection*); - //- Lagrangian info - void updateInfoLagrangian(vtkDataArraySelection*); + //- Lagrangian info + void updateInfoLagrangian(vtkDataArraySelection*); - //- Patch info - void updateInfoPatches(vtkDataArraySelection*, stringList&); + //- Patch info + void updateInfoPatches(vtkDataArraySelection*, stringList&); - //- Set info - void updateInfoSets(vtkDataArraySelection*); + //- Set info + void updateInfoSets(vtkDataArraySelection*); - //- Zone info - void updateInfoZones(vtkDataArraySelection*); + //- Zone info + void updateInfoZones(vtkDataArraySelection*); - //- Get non-empty zone names for zoneType from file - wordList getZoneNames(const word& zoneType) const; + //- Get non-empty zone names for zoneType from file + wordList getZoneNames(const word& zoneType) const; - //- Get non-empty zone names from mesh info - template - wordList getZoneNames - ( - const ZoneMesh& - ) const; - - //- Add objects of Type to paraview array selection - template - label addToSelection - ( - vtkDataArraySelection*, - const IOobjectList&, - const string& suffix=string::null - ); - - //- Field info - template class patchType, class meshType> - void updateInfoFields(vtkDataArraySelection*); - - //- Lagrangian field info - void updateInfoLagrangianFields(); - - - // Update helper functions - - //- OpenFOAM mesh - void updateFoamMesh(); - - //- Reduce memory footprint after conversion - void reduceMemory(); - - - // Mesh conversion functions - - //- Volume mesh - void convertMeshVolume(vtkMultiBlockDataSet*, int& blockNo); - - //- Lagrangian mesh - void convertMeshLagrangian(vtkMultiBlockDataSet*, int& blockNo); - - //- Patch meshes - void convertMeshPatches(vtkMultiBlockDataSet*, int& blockNo); - - //- Cell zone meshes - void convertMeshCellZones(vtkMultiBlockDataSet*, int& blockNo); - - //- Face zone meshes - void convertMeshFaceZones(vtkMultiBlockDataSet*, int& blockNo); - - //- Point zone meshes - void convertMeshPointZones(vtkMultiBlockDataSet*, int& blockNo); - - //- Cell set meshes - void convertMeshCellSets(vtkMultiBlockDataSet*, int& blockNo); - - //- Face set meshes - void convertMeshFaceSets(vtkMultiBlockDataSet*, int& blockNo); - - //- Point set meshes - void convertMeshPointSets(vtkMultiBlockDataSet*, int& blockNo); - - - // Add mesh functions - - //- Add internal mesh/cell set meshes - vtkUnstructuredGrid* volumeVTKMesh(const fvMesh&, polyDecomp&); - - //- Add Lagrangian mesh - vtkPolyData* lagrangianVTKMesh - ( - const fvMesh&, - const word& cloudName - ); - - //- Add patch mesh - template - vtkPolyData* patchVTKMesh(const word& name, const PatchType&); - - //- Add point zone - vtkPolyData* pointZoneVTKMesh - ( - const fvMesh&, - const labelList& pointLabels - ); - - //- Add face set mesh - vtkPolyData* faceSetVTKMesh - ( - const fvMesh&, - const faceSet& - ); - - //- Add point mesh - vtkPolyData* pointSetVTKMesh - ( - const fvMesh&, - const pointSet& - ); - - // Field conversion functions - - //- Convert volume fields - void convertVolFields(vtkMultiBlockDataSet*); - - //- Convert point fields - void convertPointFields(vtkMultiBlockDataSet*); - - //- Convert Lagrangian fields - void convertLagrangianFields(vtkMultiBlockDataSet*); - - - //- Add the fields in the selected time directory to the selection - // lists - template - label addObjectsToSelection + //- Get names of on non-empty zones from the mesh info + template + static wordList getZoneNames ( - vtkDataArraySelection*, - const IOobjectList&, - const string& suffix=string::null + const ZoneMesh& zmesh + ); + + //- Field (volume, point, lagrangian) info + void updateInfoFields(); + + //- Field info + template class patchType, class meshType> + void updateInfoFields + ( + vtkDataArraySelection* select + ); + + //- Lagrangian field info + void updateInfoLagrangianFields(vtkDataArraySelection* select); + + + // Update helper functions + + //- OpenFOAM mesh + void updateFoamMesh(); + + //- Reduce memory footprint after conversion + void reduceMemory(); + + + // Mesh conversion functions + + //- Convert volume mesh + void convertMeshVolume(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert Lagrangian points + void convertMeshLagrangian(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert mesh patches + void convertMeshPatches(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert cell zones + void convertMeshCellZones(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert face zones + void convertMeshFaceZones(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert point zones + void convertMeshPointZones(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert cell sets + void convertMeshCellSets(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert face sets + void convertMeshFaceSets(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert point sets + void convertMeshPointSets(vtkMultiBlockDataSet* output, int& blockNo); + + + // Add mesh functions + + //- Volume meshes as vtkUnstructuredGrid + vtkUnstructuredGrid* volumeVTKMesh + ( + const fvMesh& mesh, + polyDecomp& decompInfo + ); + + //- Lagrangian positions as vtkPolyData + vtkPolyData* lagrangianVTKMesh + ( + const polyMesh& mesh, + const word& cloudName + ); + + //- Patches (mesh or primitive) as vtkPolyData + template + vtkPolyData* patchVTKMesh + ( + const word& name, + const PatchType& p ); - // Convert OpenFOAM fields + // Field conversion functions - //- Volume field - all types - template - void convertVolField - ( - const PtrList>&, - const GeometricField&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); + //- Convert Field to VTK field + template + vtkFloatArray* convertFieldToVTK + ( + const word& name, + const Field& fld + ); - //- Volume fields - all types - template - void convertVolFields - ( - const fvMesh&, - const PtrList>&, - const IOobjectList&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); + //- Face set/zone field + template + vtkFloatArray* convertFaceFieldToVTK + ( + const GeometricField& fld, + const labelUList& faceLabels + ); - //- Volume internal fields (DimensionedField)- all types - template - void convertDimFields - ( - const fvMesh&, - const PtrList>&, - const IOobjectList&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); - - //- Volume field - all selected parts - template - void convertVolFieldBlock - ( - const GeometricField&, - autoPtr>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const List& decompLst - ); - - //- Volume field - template - void convertVolField - ( - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const polyDecomp& - ); - - //- Patch field - template - void convertPatchField - ( - const word& name, - const Field&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - //- Face set/zone field - template - void convertFaceField - ( - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const fvMesh&, - const labelList& faceLabels - ); - - //- Lagrangian fields - all types - template - void convertLagrangianFields - ( - const IOobjectList&, - vtkMultiBlockDataSet* output, - const label datasetNo - ); - - //- Lagrangian field - template - void convertLagrangianField - ( - const IOField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - //- Point fields - all types - template - void convertPointFields - ( - const fvMesh&, - const pointMesh&, - const IOobjectList&, - vtkMultiBlockDataSet* output - ); - - //- Point field - all selected parts - template - void convertPointFieldBlock - ( - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const List& - ); - - //- Point fields - template - void convertPointField - ( - const GeometricField&, - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const polyDecomp& - ); - - //- Patch point field - template - void convertPatchPointField - ( - const word& name, - const Field&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); + //- Volume field + template + vtkFloatArray* convertVolFieldToVTK + ( + const GeometricField& fld, + const polyDecomp& decompInfo + ); - // GUI selection helper functions + //- Convert volume fields + void convertVolFields(vtkMultiBlockDataSet* output); - //- Only keep what is listed in hashSet - static void pruneObjectList - ( - IOobjectList&, - const wordHashSet& - ); + //- Convert point fields + void convertPointFields(vtkMultiBlockDataSet* output); - //- Retrieve the current selections - static wordHashSet getSelected(vtkDataArraySelection*); + //- Convert Lagrangian fields + void convertLagrangianFields(vtkMultiBlockDataSet* output); - //- Retrieve a sub-list of the current selections - static wordHashSet getSelected - ( - vtkDataArraySelection*, - const arrayRange& - ); - //- Retrieve the current selections - static stringList getSelectedArrayEntries(vtkDataArraySelection*); + // Convert OpenFOAM fields - //- Retrieve a sub-list of the current selections - static stringList getSelectedArrayEntries - ( - vtkDataArraySelection*, - const arrayRange& - ); + //- Volume field - all types + template + void convertVolField + ( + const PtrList& patchInterpList, + const GeometricField& fld, + vtkMultiBlockDataSet* output + ); - //- Set selection(s) - static void setSelectedArrayEntries - ( - vtkDataArraySelection*, - const stringList& - ); + //- Volume fields - all types + template + void convertVolFields + ( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); - //- Get the first word from the mesh parts selection - word getPartName(const int); + //- Volume internal fields (DimensionedField)- all types + template + void convertDimFields + ( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); + //- Volume field - all selected parts + template + void convertVolFieldBlock + ( + const GeometricField& fld, + autoPtr>& ptfPtr, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst + ); + + //- Lagrangian fields - all types + template + void convertLagrangianFields + ( + const IOobjectList& objects, + vtkMultiBlockDataSet* output, + const label datasetNo + ); + + //- Point fields - all types + template + void convertPointFields + ( + const pointMesh& pMesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); + + //- Point field - all selected parts + template + void convertPointFieldBlock + ( + const GeometricField& pfld, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst + ); + + //- Point field + template + void convertPointField + ( + vtkUnstructuredGrid* vtkmesh, + const GeometricField& pfld, + const GeometricField& vfld, + const polyDecomp& decomp + ); + + + // GUI selection helper functions + + //- Only retain specified fields + static void pruneObjectList + ( + IOobjectList& objects, + const hashedWordList& retain + ); + + //- Get the first word from the reader 'parts' selection + word getPartName(const int partId); + + + // Constructors //- Disallow default bitwise copy construct - vtkPVFoam(const vtkPVFoam&); + vtkPVFoam(const vtkPVFoam&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVFoam&); + void operator=(const vtkPVFoam&) = delete; public: @@ -700,9 +509,9 @@ public: //- Clean any storage void CleanUp(); - //- Allocate and return a list of selected times - // returns the count via the parameter - double* findTimes(int& nTimeSteps); + //- Return a list of selected times. + // Use STL container since these values are used by the plugin + std::vector findTimes(const bool skipZero = false) const; //- Add/remove patch names to/from the view void renderPatchNames(vtkRenderer*, const bool show); @@ -725,9 +534,7 @@ public: //- Debug information void PrintSelf(ostream&, vtkIndent) const; - //- Simple memory used debugging information - static void printMemory(); - + void printInfo() const; }; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H deleted file mode 100644 index 69395405d5..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H +++ /dev/null @@ -1,117 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamFaceField_H -#define vtkPVFoamFaceField_H - -// VTK includes -#include "vtkCellData.h" -#include "vtkFloatArray.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkPolyData.h" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template -void Foam::vtkPVFoam::convertFaceField -( - const GeometricField& tf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo, - const fvMesh& mesh, - const labelList& faceLabels -) -{ - const label nComp = pTraits::nComponents; - const label nInternalFaces = mesh.nInternalFaces(); - const labelList& faceOwner = mesh.faceOwner(); - const labelList& faceNeigh = mesh.faceNeighbour(); - - vtkFloatArray* cellData = vtkFloatArray::New(); - cellData->SetNumberOfTuples(faceLabels.size()); - cellData->SetNumberOfComponents(nComp); - cellData->Allocate(nComp*faceLabels.size()); - cellData->SetName(tf.name().c_str()); - - if (debug) - { - Info<< "convert convertFaceField: " - << tf.name() - << " size = " << tf.size() - << " nComp=" << nComp - << " nTuples = " << faceLabels.size() << endl; - } - - float vec[nComp]; - - // for interior faces: average owner/neighbour - // for boundary faces: owner - forAll(faceLabels, facei) - { - const label faceNo = faceLabels[facei]; - if (faceNo < nInternalFaces) - { - Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]); - - for (direction d=0; d(vec); - - cellData->InsertTuple(facei, vec); - } - - - vtkPolyData::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetCellData() - ->AddArray(cellData); - - cellData->Delete(); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C new file mode 100644 index 0000000000..c6b9e3b86c --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -0,0 +1,909 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +InClass + vtkPVFoam + +\*---------------------------------------------------------------------------*/ + +#ifndef vtkPVFoamFieldTemplates_C +#define vtkPVFoamFieldTemplates_C + +// OpenFOAM includes +#include "emptyFvPatchField.H" +#include "wallPolyPatch.H" +#include "faceSet.H" +#include "volPointInterpolation.H" +#include "zeroGradientFvPatchField.H" +#include "interpolatePointToCell.H" +#include "foamPvFields.H" + +// vtk includes +#include "vtkFloatArray.h" +#include "vtkCellData.h" +#include "vtkPointData.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// volume-fields +// + +template +void Foam::vtkPVFoam::convertVolField +( + const PtrList& patchInterpList, + const GeometricField& fld, + vtkMultiBlockDataSet* output +) +{ + const fvMesh& mesh = fld.mesh(); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + const bool interpField = !patchInterpList.empty(); + const bool extrapPatch = reader_->GetExtrapolatePatches(); + + // Interpolated field (demand driven) + autoPtr> ptfPtr; + if (interpField) + { + if (debug) + { + Info<< "convertVolField interpolating:" << fld.name() << endl; + } + + ptfPtr.reset + ( + volPointInterpolation::New(mesh).interpolate(fld).ptr() + ); + } + + // Convert activated internalMesh regions + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeVolume_, + regionPolyDecomp_ + ); + + // Convert activated cellZones + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeCellZones_, + zonePolyDecomp_ + ); + + // Convert activated cellSets + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeCellSets_, + csetPolyDecomp_ + ); + + + // + // Convert patches - if activated + // + for + ( + int partId = arrayRangePatches_.start(); + partId < arrayRangePatches_.end(); + ++partId + ) + { + const word patchName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label patchId = patches.findPatchID(patchName); + + if (!partStatus_[partId] || patchId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangePatches_, datasetNo + ); + + if (!vtkmesh) + { + continue; + } + + const fvPatchField& ptf = fld.boundaryField()[patchId]; + + if + ( + isType>(ptf) + || + ( + extrapPatch + && !polyPatch::constraintType(patches[patchId].type()) + ) + ) + { + fvPatch p(ptf.patch().patch(), mesh.boundary()); + + tmp> tpptf + ( + fvPatchField(p, fld).patchInternalField() + ); + + vtkFloatArray* cdata = convertFieldToVTK(fld.name(), tpptf()); + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (patchId < patchInterpList.size()) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fld.name(), + patchInterpList[patchId].faceToPointInterpolate(tpptf)() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + else + { + vtkFloatArray* cdata = convertFieldToVTK(fld.name(), ptf); + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (patchId < patchInterpList.size()) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fld.name(), + patchInterpList[patchId].faceToPointInterpolate(ptf)() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + } + + // + // Convert face zones - if activated + // + for + ( + int partId = arrayRangeFaceZones_.start(); + partId < arrayRangeFaceZones_.end(); + ++partId + ) + { + const word zoneName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId] || datasetNo < 0) + { + continue; + } + + const faceZoneMesh& zMesh = mesh.faceZones(); + const label zoneId = zMesh.findZoneID(zoneName); + + if (zoneId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangeFaceZones_, datasetNo + ); + + if (vtkmesh) + { + vtkFloatArray* cdata = convertFaceFieldToVTK + ( + fld, + zMesh[zoneId] + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + } + + // TODO: points + } + + // + // Convert face sets - if activated + // + for + ( + int partId = arrayRangeFaceSets_.start(); + partId < arrayRangeFaceSets_.end(); + ++partId + ) + { + const word selectName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangeFaceSets_, datasetNo + ); + + if (!vtkmesh) + { + continue; + } + + const faceSet fSet(mesh, selectName); + + vtkFloatArray* cdata = convertFaceFieldToVTK + ( + fld, + fSet.sortedToc() + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + // TODO: points + } +} + + +template +void Foam::vtkPVFoam::convertVolFields +( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to GeometricField + if + ( + iter()->headerClassName() + != GeometricField::typeName + ) + { + continue; + } + + // Load field + GeometricField fld + ( + *iter(), + mesh + ); + + // Convert + convertVolField(patchInterpList, fld, output); + } +} + + +template +void Foam::vtkPVFoam::convertDimFields +( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + typedef GeometricField VolFieldType; + + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to DimensionedField + if + ( + iter()->headerClassName() + != DimensionedField::typeName + ) + { + continue; + } + + // Load field + DimensionedField dimFld(*iter(), mesh); + + // Construct volField with zero-gradient patch fields + + IOobject io(dimFld); + io.readOpt() = IOobject::NO_READ; + + PtrList> patchFields(mesh.boundary().size()); + forAll(patchFields, patchI) + { + patchFields.set + ( + patchI, + fvPatchField::New + ( + zeroGradientFvPatchField::typeName, + mesh.boundary()[patchI], + dimFld + ) + ); + } + + VolFieldType volFld + ( + io, + dimFld.mesh(), + dimFld.dimensions(), + dimFld, + patchFields + ); + volFld.correctBoundaryConditions(); + + convertVolField(patchInterpList, volFld, output); + } +} + + +template +void Foam::vtkPVFoam::convertVolFieldBlock +( + const GeometricField& fld, + autoPtr>& ptfPtr, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst +) +{ + for (int partId = range.start(); partId < range.end(); ++partId) + { + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkUnstructuredGrid* vtkmesh = + getDataFromBlock(output, range, datasetNo); + + if (!vtkmesh) + { + continue; + } + + vtkFloatArray* cdata = convertVolFieldToVTK + ( + fld, + decompLst[datasetNo] + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (ptfPtr.valid()) + { + convertPointField(vtkmesh, ptfPtr(), fld, decompLst[datasetNo]); + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// point-fields +// + +template +void Foam::vtkPVFoam::convertPointFields +( + const pointMesh& pMesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + const polyMesh& mesh = pMesh.mesh(); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + forAllConstIter(IOobjectList, objects, iter) + { + const word& fieldName = iter()->name(); + // restrict to this GeometricField + if + ( + iter()->headerClassName() + != GeometricField::typeName + ) + { + continue; + } + + if (debug) + { + Info<< "convertPointFields : " << fieldName << endl; + } + + GeometricField pfld(*iter(), pMesh); + + + // Convert activated internalMesh regions + convertPointFieldBlock + ( + pfld, + output, + arrayRangeVolume_, + regionPolyDecomp_ + ); + + // Convert activated cellZones + convertPointFieldBlock + ( + pfld, + output, + arrayRangeCellZones_, + zonePolyDecomp_ + ); + + // Convert activated cellSets + convertPointFieldBlock + ( + pfld, + output, + arrayRangeCellSets_, + csetPolyDecomp_ + ); + + + // + // Convert patches - if activated + // + for + ( + int partId = arrayRangePatches_.start(); + partId < arrayRangePatches_.end(); + ++partId + ) + { + const word patchName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label patchId = patches.findPatchID(patchName); + + if (!partStatus_[partId] || patchId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangePatches_, datasetNo + ); + + if (vtkmesh) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fieldName, + pfld.boundaryField()[patchId].patchInternalField()() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + + // + // Convert faceZones - if activated + // + for + ( + int partId = arrayRangeFaceZones_.start(); + partId < arrayRangeFaceZones_.end(); + ++partId + ) + { + const word zoneName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label zoneId = mesh.faceZones().findZoneID(zoneName); + + if (!partStatus_[partId] || zoneId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangeFaceZones_, datasetNo + ); + + if (vtkmesh) + { + // Extract the field on the zone + Field znfld + ( + pfld.primitiveField(), + mesh.faceZones()[zoneId]().meshPoints() + ); + + vtkFloatArray* pdata = convertFieldToVTK(fieldName, znfld); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + } +} + + +template +void Foam::vtkPVFoam::convertPointFieldBlock +( + const GeometricField& pfld, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst +) +{ + for (int partId = range.start(); partId < range.end(); ++partId) + { + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkUnstructuredGrid* vtkmesh = getDataFromBlock + ( + output, range, datasetNo + ); + + if (vtkmesh) + { + convertPointField + ( + vtkmesh, + pfld, + GeometricField::null(), + decompLst[datasetNo] + ); + } + } +} + + +template +void Foam::vtkPVFoam::convertPointField +( + vtkUnstructuredGrid* vtkmesh, + const GeometricField& pfld, + const GeometricField& vfld, + const polyDecomp& decomp +) +{ + if (!vtkmesh) + { + return; + } + + const label nComp = pTraits::nComponents; + const labelUList& addPointCellLabels = decomp.addPointCellLabels(); + const labelUList& pointMap = decomp.pointMap(); + + // use a pointMap or address directly into mesh + const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size()); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(nPoints + addPointCellLabels.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*(nPoints + addPointCellLabels.size())); + + // Note: using the name of the original volField + // not the name generated by the interpolation "volPointInterpolate()" + + if (&vfld != &GeometricField::null()) + { + fldData->SetName(vfld.name().c_str()); + } + else + { + fldData->SetName(pfld.name().c_str()); + } + + if (debug) + { + Info<< "convert Point field: " + << pfld.name() + << " size=" << (nPoints + addPointCellLabels.size()) + << " (" << nPoints << " + " << addPointCellLabels.size() + << ") nComp=" << nComp << endl; + } + + float vec[nComp]; + + if (pointMap.size()) + { + forAll(pointMap, i) + { + const Type& t = pfld[pointMap[i]]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + } + else + { + forAll(pfld, i) + { + const Type& t = pfld[i]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + } + + // continue insertion from here + label i = nPoints; + + if (&vfld != &GeometricField::null()) + { + forAll(addPointCellLabels, apI) + { + const Type& t = vfld[addPointCellLabels[apI]]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i++, vec); + } + } + else + { + forAll(addPointCellLabels, apI) + { + Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]); + for (direction d=0; d(vec); + + fldData->InsertTuple(i++, vec); + } + } + + vtkmesh->GetPointData()->AddArray(fldData); + fldData->Delete(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// lagrangian-fields +// + +template +void Foam::vtkPVFoam::convertLagrangianFields +( + const IOobjectList& objects, + vtkMultiBlockDataSet* output, + const label datasetNo +) +{ + const arrayRange& range = arrayRangeLagrangian_; + + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to this IOField + if (iter()->headerClassName() == IOField::typeName) + { + vtkPolyData* vtkmesh = + getDataFromBlock(output, range, datasetNo); + + if (vtkmesh) + { + IOField fld(*iter()); + + vtkFloatArray* fldData = convertFieldToVTK(fld.name(), fld); + vtkmesh->GetPointData()->AddArray(fldData); + fldData->Delete(); + } + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// low-level conversions +// + +template +vtkFloatArray* Foam::vtkPVFoam::convertFieldToVTK +( + const word& name, + const Field& fld +) +{ + if (debug) + { + Info<< "convert Field<" << pTraits::typeName << "> " + << name + << " size=" << fld.size() + << " nComp=" << label(pTraits::nComponents) << endl; + } + + const label nComp = pTraits::nComponents; + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(fld.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*fld.size()); + fldData->SetName(name.c_str()); + + float vec[nComp]; + forAll(fld, i) + { + const Type& t = fld[i]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + + return fldData; +} + + +template +vtkFloatArray* Foam::vtkPVFoam::convertFaceFieldToVTK +( + const GeometricField& fld, + const labelUList& faceLabels +) +{ + if (debug) + { + Info<< "convert face field: " + << fld.name() + << " size=" << faceLabels.size() + << " nComp=" << label(pTraits::nComponents) << endl; + } + + const fvMesh& mesh = fld.mesh(); + + const label nComp = pTraits::nComponents; + const label nInternalFaces = mesh.nInternalFaces(); + const labelList& faceOwner = mesh.faceOwner(); + const labelList& faceNeigh = mesh.faceNeighbour(); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(faceLabels.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*faceLabels.size()); + fldData->SetName(fld.name().c_str()); + + float vec[nComp]; + + // for interior faces: average owner/neighbour + // for boundary faces: owner + forAll(faceLabels, facei) + { + const label faceNo = faceLabels[facei]; + if (faceNo < nInternalFaces) + { + Type t = 0.5*(fld[faceOwner[faceNo]] + fld[faceNeigh[faceNo]]); + + for (direction d=0; d(vec); + + fldData->InsertTuple(facei, vec); + } + + return fldData; +} + + +template +vtkFloatArray* Foam::vtkPVFoam::convertVolFieldToVTK +( + const GeometricField& fld, + const polyDecomp& decompInfo +) +{ + const label nComp = pTraits::nComponents; + const labelList& superCells = decompInfo.superCells(); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(superCells.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*superCells.size()); + fldData->SetName(fld.name().c_str()); + + if (debug) + { + Info<< "convert volField: " + << fld.name() + << " size=" << superCells.size() + << " (" << fld.size() << " + " + << (superCells.size() - fld.size()) + << ") nComp=" << nComp << endl; + } + + float vec[nComp]; + forAll(superCells, i) + { + const Type& t = fld[superCells[i]]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + + return fldData; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C index 47d2c3aa07..880ca89a4f 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,6 +26,7 @@ License #include "vtkPVFoam.H" // OpenFOAM includes +#include "Cloud.H" #include "IOobjectList.H" #include "vtkPVFoamReader.h" @@ -34,29 +35,26 @@ License #include "vtkPolyData.h" #include "vtkUnstructuredGrid.h" +// Templates (only needed here) +#include "vtkPVFoamFieldTemplates.C" + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -#include "vtkPVFoamVolFields.H" -#include "vtkPVFoamPointFields.H" -#include "vtkPVFoamLagrangianFields.H" - - void Foam::vtkPVFoam::pruneObjectList ( IOobjectList& objects, - const wordHashSet& selected + const hashedWordList& retain ) { - // hash all the selected field names - if (selected.empty()) + if (retain.empty()) { objects.clear(); } - // only keep selected fields + // only retain specified fields forAllIter(IOobjectList, objects, iter) { - if (!selected.found(iter()->name())) + if (!retain.found(iter()->name())) { objects.erase(iter); } @@ -71,7 +69,8 @@ void Foam::vtkPVFoam::convertVolFields { const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + const bool interpFields = reader_->GetInterpolateVolFields(); + hashedWordList selectedFields = getSelected ( reader_->GetVolFieldSelection() ); @@ -93,80 +92,50 @@ void Foam::vtkPVFoam::convertVolFields if (debug) { - Info<< " Foam::vtkPVFoam::convertVolFields" << nl - << "converting OpenFOAM volume fields" << endl; + Info<< " convert volume fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } printMemory(); } - PtrList> - ppInterpList(mesh.boundaryMesh().size()); + PtrList interpLst; - forAll(ppInterpList, i) + if (interpFields) { - ppInterpList.set - ( - i, - new PrimitivePatchInterpolation + interpLst.setSize(mesh.boundaryMesh().size()); + + forAll(interpLst, i) + { + interpLst.set ( - mesh.boundaryMesh()[i] - ) - ); + i, + new PrimitivePatchInterpolation + ( + mesh.boundaryMesh()[i] + ) + ); + } } + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); - bool interpFields = reader_->GetInterpolateVolFields(); - - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); if (debug) { - Info<< " Foam::vtkPVFoam::convertVolFields" << endl; + Info<< " convert volume fields" << endl; printMemory(); } } @@ -179,7 +148,7 @@ void Foam::vtkPVFoam::convertPointFields { const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + hashedWordList selectedFields = getSelected ( reader_->GetPointFieldSelection() ); @@ -205,12 +174,11 @@ void Foam::vtkPVFoam::convertPointFields if (debug) { - Info<< " Foam::vtkPVFoam::convertPointFields" << nl - << "converting OpenFOAM volume fields -> point fields" << endl; + Info<< " convert volume -> point fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } printMemory(); } @@ -218,31 +186,15 @@ void Foam::vtkPVFoam::convertPointFields // Construct interpolation on the raw mesh const pointMesh& pMesh = pointMesh::New(mesh); - - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); if (debug) { - Info<< " Foam::vtkPVFoam::convertPointFields" << endl; + Info<< " convert volume -> point fields" << endl; printMemory(); } } @@ -256,7 +208,7 @@ void Foam::vtkPVFoam::convertLagrangianFields arrayRange& range = arrayRangeLagrangian_; const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + hashedWordList selectedFields = getSelected ( reader_->GetLagrangianFieldSelection() ); @@ -268,7 +220,7 @@ void Foam::vtkPVFoam::convertLagrangianFields if (debug) { - Info<< " Foam::vtkPVFoam::convertLagrangianFields" << endl; + Info<< " convert Lagrangian fields" << endl; printMemory(); } @@ -282,7 +234,6 @@ void Foam::vtkPVFoam::convertLagrangianFields continue; } - // Get the Lagrangian fields for this time and this cloud // but only keep selected fields // the region name is already in the mesh db @@ -301,43 +252,25 @@ void Foam::vtkPVFoam::convertLagrangianFields if (debug) { - Info<< "converting OpenFOAM lagrangian fields" << nl; + Info<< "converting OpenFOAM lagrangian fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } } - convertLagrangianFields