From 6179a6fd5aab6d692cf76c6edd0624116a51605a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 15:20:57 +0200 Subject: [PATCH] checkin paraview3.3 reader as 'work-in-progress' --- .../graphics/PV3-3FoamReader/Allwmake | 18 + .../PV3FoamReader/CMakeLists.txt | 54 + .../PV3FoamReader/PV3FoamReader.qrc | 5 + .../PV3FoamReader/PV3FoamReader.xml | 6 + .../PV3FoamReader/PV3FoamReader_SM.xml | 261 +++++ .../PV3FoamReader/vtkPV3FoamReader.cxx | 748 ++++++++++++ .../PV3FoamReader/vtkPV3FoamReader.h | 207 ++++ .../PV3-3FoamReader/vtkPV3Foam/Make/files | 13 + .../PV3-3FoamReader/vtkPV3Foam/Make/options | 16 + .../vtkDataArrayTemplateImplicit.txx | 0 .../PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.C | 1014 +++++++++++++++++ .../PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.H | 737 ++++++++++++ .../vtkPV3Foam/vtkPV3FoamAddFaceSetMesh.C | 101 ++ .../vtkPV3Foam/vtkPV3FoamAddFaceZoneMesh.C | 100 ++ .../vtkPV3Foam/vtkPV3FoamAddFields.H | 96 ++ .../vtkPV3Foam/vtkPV3FoamAddLagrangianMesh.C | 105 ++ .../vtkPV3Foam/vtkPV3FoamAddPatchMesh.C | 90 ++ .../vtkPV3Foam/vtkPV3FoamAddPointSetMesh.C | 68 ++ .../vtkPV3Foam/vtkPV3FoamAddPointZoneMesh.C | 67 ++ .../vtkPV3Foam/vtkPV3FoamAddVolumeMesh.C | 360 ++++++ .../vtkPV3Foam/vtkPV3FoamConvertFaceField.H | 286 +++++ .../vtkPV3FoamConvertLagrangianFields.H | 179 +++ .../vtkPV3Foam/vtkPV3FoamConvertMesh.C | 587 ++++++++++ .../vtkPV3FoamConvertPatchFaceField.H | 121 ++ .../vtkPV3FoamConvertPatchPointField.H | 116 ++ .../vtkPV3Foam/vtkPV3FoamConvertPointFields.H | 274 +++++ .../vtkPV3Foam/vtkPV3FoamConvertVolFields.H | 459 ++++++++ .../PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamI.H | 77 ++ .../vtkPV3Foam/vtkPV3FoamInsertNextPoint.H | 52 + .../vtkPV3Foam/vtkPV3FoamUpdate.C | 239 ++++ .../vtkPV3Foam/vtkPV3FoamUpdateInformation.C | 417 +++++++ .../vtkPV3FoamUpdateInformationFields.H | 97 ++ 32 files changed, 6970 insertions(+) create mode 100755 applications/utilities/postProcessing/graphics/PV3-3FoamReader/Allwmake create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/CMakeLists.txt create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.qrc create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.xml create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader_SM.xml create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.h create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/files create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/options create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkDataArrayTemplateImplicit.txx create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddFaceSetMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddFaceZoneMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddFields.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddLagrangianMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddPatchMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddPointSetMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddPointZoneMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamAddVolumeMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertFaceField.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertLagrangianFields.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertMesh.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchFaceField.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchPointField.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPointFields.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamConvertVolFields.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamI.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamInsertNextPoint.H create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamUpdate.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInformation.C create mode 100644 applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInformationFields.H diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/Allwmake b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/Allwmake new file mode 100755 index 0000000000..9a91c33990 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/Allwmake @@ -0,0 +1,18 @@ +#!/bin/sh +set -x + +if [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ] +then + case "$ParaView_VERSION" in + 3*) + wmake libso vtkPV3Foam + ( + cd PV3FoamReader + mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1 + cd Make/$WM_OPTIONS + cmake ../.. + make + ) + ;; + esac +fi diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/CMakeLists.txt new file mode 100644 index 0000000000..fc69d0e60a --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/CMakeLists.txt @@ -0,0 +1,54 @@ + +# create a plugin that adds a reader to the ParaView GUI +# it is added in the file dialog when doing opens/saves. + +# The qrc file is processed by Qt's resource compiler (rcc) +# the qrc file must have a resource prefix of "/ParaViewResources" +# and ParaView will read anything contained under that prefix +# the pqReader.xml file contains xml defining readers with their +# file extensions and descriptions. + +FIND_PACKAGE(ParaView REQUIRED) +INCLUDE(${PARAVIEW_USE_FILE}) + +LINK_DIRECTORIES( + $ENV{FOAM_LIBBIN} +) + +INCLUDE_DIRECTORIES( + $ENV{FOAM_SRC}/OpenFOAM/lnInclude + $ENV{FOAM_SRC}/finiteVolume/lnInclude + ${PROJECT_SOURCE_DIR}/../vtkPV3Foam +) + +ADD_DEFINITIONS( + -D$ENV{WM_PRECISION_OPTION} +) + +# Set output library destination to plugin folder +SET( + LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} + CACHE INTERNAL + "Single output directory for building all libraries." +) + +# Build the server-side plugin +ADD_PARAVIEW_PLUGIN( + PV3FoamReader_SM "1.0" + SERVER_MANAGER_XML PV3FoamReader_SM.xml + SERVER_MANAGER_SOURCES vtkPV3FoamReader.cxx +) + +# Build the client-side plugin +ADD_PARAVIEW_PLUGIN( + PV3FoamReader + "1.0" + GUI_RESOURCES PV3FoamReader.qrc +) + +TARGET_LINK_LIBRARIES( + PV3FoamReader_SM + OpenFOAM + finiteVolume + vtkPV3Foam +) diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.qrc b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.qrc new file mode 100644 index 0000000000..7394bb80df --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.qrc @@ -0,0 +1,5 @@ + + + PV3FoamReader.xml + + diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.xml b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.xml new file mode 100644 index 0000000000..4276a23afc --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader.xml @@ -0,0 +1,6 @@ + + + + diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader_SM.xml b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader_SM.xml new file mode 100644 index 0000000000..8ba3a93d30 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/PV3FoamReader_SM.xml @@ -0,0 +1,261 @@ + + + + + + + + + + + + + + + Available timestep values. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx new file mode 100644 index 0000000000..091af74399 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx @@ -0,0 +1,748 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: vtkPV3FoamReader.cxx,v $ + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +#include "vtkPV3FoamReader.h" + +#include "pqApplicationCore.h" +#include "pqRenderView.h" +#include "pqServerManagerModel.h" + +// VTK includes +#include "vtkCallbackCommand.h" +#include "vtkCellArray.h" +#include "vtkCellData.h" +#include "vtkDataArraySelection.h" +#include "vtkDirectory.h" +#include "vtkDoubleArray.h" +#include "vtkErrorCode.h" +#include "vtkFloatArray.h" +#include "vtkInformation.h" +#include "vtkInformationVector.h" +#include "vtkIntArray.h" +#include "vtkMultiBlockDataSet.h" +#include "vtkObjectFactory.h" +#include "vtkPoints.h" +#include "vtkRenderer.h" +#include "vtkSMRenderViewProxy.h" +#include "vtkStreamingDemandDrivenPipeline.h" +#include "vtkStringArray.h" +#include "vtkUnstructuredGrid.h" +#include "vtkUnstructuredGridAlgorithm.h" +#include "vtkAlgorithmOutput.h" +#include "vtkMultiBlockDataSet.h" + +// Foam includes +#include "vtkPV3Foam.H" + +vtkCxxRevisionMacro(vtkPV3FoamReader, "$Revision: 1.2$"); +vtkStandardNewMacro(vtkPV3FoamReader); + + +vtkPV3FoamReader::vtkPV3FoamReader() +{ + Debug = 0; + vtkDebugMacro(<<"Constructor"); + + SetNumberOfInputPorts(0); + + FileName = NULL; + foamData_ = NULL; + + CacheMesh = 0; + + UpdateGUI = 1; + UpdateGUIOld = 1; + TimeStep = 0; + TimeStepRange[0] = 0; + TimeStepRange[1] = 0; + + ShowPatchNames = 0; + + TimeSelection = vtkDataArraySelection::New(); + RegionSelection = vtkDataArraySelection::New(); + VolFieldSelection = vtkDataArraySelection::New(); + PointFieldSelection = vtkDataArraySelection::New(); + LagrangianFieldSelection = vtkDataArraySelection::New(); + + // Setup the selection callback to modify this object when an array + // selection is changed. + SelectionObserver = vtkCallbackCommand::New(); + SelectionObserver->SetCallback + ( + &vtkPV3FoamReader::SelectionModifiedCallback + ); + SelectionObserver->SetClientData(this); + + TimeSelection->AddObserver + ( + vtkCommand::ModifiedEvent, + this->SelectionObserver + ); + RegionSelection->AddObserver + ( + vtkCommand::ModifiedEvent, + this->SelectionObserver + ); + VolFieldSelection->AddObserver + ( + vtkCommand::ModifiedEvent, + this->SelectionObserver + ); + PointFieldSelection->AddObserver + ( + vtkCommand::ModifiedEvent, + this->SelectionObserver + ); + LagrangianFieldSelection->AddObserver + ( + vtkCommand::ModifiedEvent, + this->SelectionObserver + ); +} + +vtkPV3FoamReader::~vtkPV3FoamReader() +{ + vtkDebugMacro(<<"Deconstructor"); + cout << "Destroy ~vtkPV3FoamReader\n"; + + if (foamData_) + { + delete foamData_; + } + + if (FileName) + { + delete [] FileName; + } + + TimeSelection->RemoveObserver(this->SelectionObserver); + RegionSelection->RemoveObserver(this->SelectionObserver); + VolFieldSelection->RemoveObserver(this->SelectionObserver); + PointFieldSelection->RemoveObserver(this->SelectionObserver); + LagrangianFieldSelection->RemoveObserver(this->SelectionObserver); + + SelectionObserver->Delete(); + + TimeSelection->Delete(); + RegionSelection->Delete(); + VolFieldSelection->Delete(); + PointFieldSelection->Delete(); + LagrangianFieldSelection->Delete(); +} + + +// Do everything except set the output info +int vtkPV3FoamReader::RequestInformation +( + vtkInformation* vtkNotUsed(request), + vtkInformationVector** vtkNotUsed(inputVector), + vtkInformationVector* outputVector +) +{ + vtkDebugMacro(<<"RequestInformation"); + cout<<"REQUEST_INFORMATION\n"; + + if (!FileName) + { + vtkErrorMacro("FileName has to be specified!"); + return 0; + } + + { + vtkInformation* outputInfo = this->GetOutputPortInformation(0); + outputInfo->Print(cout); + + vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast + ( + outputInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT()) + ); + if (output) + { + output->Print(cout); + } + else + { + cout << "no output\n"; + } + + cout << "GetExecutive:\n"; + + this->GetExecutive()->GetOutputInformation(0)->Print(cout); + } + + { + int nInfo = outputVector->GetNumberOfInformationObjects(); + cout<<"requestInfo with " << nInfo << " items\n"; + for (int i=0; iGetInformationObject(i); + info->Print(cout); + } + } + + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + if (!foamData_) + { + vtkDebugMacro("RequestInformation: creating foamData_"); + vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast + ( + outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT()) + ); + foamData_ = new Foam::vtkPV3Foam(FileName, this, output); + foamData_->UpdateInformation(); + } + else + { + vtkDebugMacro("RequestInformation: updating information"); + + foamData_->UpdateInformation(); + } + + int nTimeSteps = 0; + double* timeSteps = foamData_->timeSteps(nTimeSteps); + + cout<<"Have nTimeSteps: " << nTimeSteps << "\n"; + + outInfo->Set + ( + vtkStreamingDemandDrivenPipeline::TIME_STEPS(), + timeSteps, + nTimeSteps + ); + + double timeRange[2]; + if (nTimeSteps) + { + timeRange[0] = timeSteps[0]; + timeRange[1] = timeSteps[nTimeSteps-1]; + + cout<<"nTimeSteps " << nTimeSteps << "\n"; + cout<<"timeRange " << timeRange[0] << " -> " << timeRange[1] << "\n"; + +// for (int i = 0; i < nTimeSteps; ++i) +// { +// cout<<"step[" << i << "] = " << timeSteps[i] << "\n"; +// } + + outInfo->Set + ( + vtkStreamingDemandDrivenPipeline::TIME_RANGE(), + timeRange, + 2 + ); + } + + delete timeSteps; + + cout<<"done RequestInformation\n"; + return 1; +} + + +// Set the output info +int vtkPV3FoamReader::RequestData +( + vtkInformation* vtkNotUsed(request), + vtkInformationVector** vtkNotUsed(inputVector), + vtkInformationVector* outputVector +) +{ + vtkDebugMacro(<<"RequestData"); + cout<<"REQUEST_DATA\n"; + + if (!FileName) + { + vtkErrorMacro("FileName has to be specified!"); + return 0; + } + + { + int nInfo = outputVector->GetNumberOfInformationObjects(); + cout<<"requestData with " << nInfo << " items\n"; + for (int i=0; iGetInformationObject(i); + info->Print(cout); + } + } + + vtkInformation* outInfo = outputVector->GetInformationObject(0); + vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast + ( + outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT()) + ); + +#if 1 + { + vtkInformation* outputInfo = this->GetOutputPortInformation(0); + outputInfo->Print(cout); + + vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast + ( + outputInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT()) + ); + if (output) + { + output->Print(cout); + } + else + { + cout << "no output\n"; + } + + vtkInformation* execInfo = this->GetExecutive()->GetOutputInformation(0); + execInfo->Print(cout); + + outInfo->Print(cout); + + vtkMultiBlockDataSet* dobj = vtkMultiBlockDataSet::SafeDownCast + ( + outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT()) + ); + if (dobj) + { + dobj->Print(cout); + + vtkInformation* dobjInfo = dobj->GetInformation(); + dobjInfo->Print(cout); + } + else + { + cout << "no data_object\n"; + } + + + } +#endif + + if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS())) + { + cout<<"Has UPDATE_TIME_STEPS\n"; + cout<<"output->GetNumberOfBlocks() " << output->GetNumberOfBlocks() << + "\n"; + + // Get the requested time step. + // We only supprt requests of a single time step + int nRequestedTimeSteps = outInfo->Length + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + ); + if (nRequestedTimeSteps >= 1) + { + double *requestedTimeSteps = outInfo->Get + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + ); + + foamData_->setTime(requestedTimeSteps[0]); + } + } + + if + ( + (UpdateGUIOld == GetUpdateGUI()) + || (output->GetNumberOfBlocks() == 0) + ) + { + foamData_->Update(output); + + if (ShowPatchNames == 1) + { + addPatchNamesToView(); + } + else + { + removePatchNamesFromView(); + } + } + UpdateGUIOld = GetUpdateGUI(); + + cout<<"done RequestData\n"; + cout<<"done output->GetNumberOfBlocks() " + << output->GetNumberOfBlocks() << "\n"; + + return 1; +} + + +void vtkPV3FoamReader::addPatchNamesToView() +{ + pqApplicationCore* appCore = pqApplicationCore::instance(); + + // Server manager model for querying items in the server manager + pqServerManagerModel* smModel = appCore->getServerManagerModel(); + + // Get all the pqRenderView instances + QList renderViews = smModel->findItems(); + + for (int viewI=0; viewIaddPatchNames + ( + renderViews[viewI]->getRenderViewProxy()->GetRenderer() + ); + } +} + + +void vtkPV3FoamReader::removePatchNamesFromView() +{ + pqApplicationCore* appCore = pqApplicationCore::instance(); + + // Server manager model for querying items in the server manager + pqServerManagerModel* smModel = appCore->getServerManagerModel(); + + // Get all the pqRenderView instances + QList renderViews = smModel->findItems(); + + for (int viewI=0; viewIremovePatchNames + ( + renderViews[viewI]->getRenderViewProxy()->GetRenderer() + ); + } +} + + +void vtkPV3FoamReader::PrintSelf +( + ostream& os, + vtkIndent indent +) +{ + vtkDebugMacro(<<"PrintSelf"); + + this->Superclass::PrintSelf(os,indent); + os<< indent << "File name: " + << (this->FileName ? this->FileName : "(none)") << "\n"; + os<< indent << "Number of meshes: " << foamData_->numberOfMeshes() << "\n"; + os<< indent << "Number of nodes: " << foamData_->numberOfPoints() << "\n"; + os<< indent << "Number of cells: " << foamData_->numberOfCells() << "\n"; + os<< indent << "Number of available time steps: " << foamData_->numberOfAvailableTimes() + << endl; + os<< indent << "Time step range: " + << this->TimeStepRange[0] << " - " << this->TimeStepRange[1] + << endl; + os<< indent << "Time step: " << this->TimeStep << endl; + return; +} + + +vtkDataArraySelection* vtkPV3FoamReader::GetTimeSelection() +{ + vtkDebugMacro(<<"GetTimeSelection"); + + return TimeSelection; +} + + +int vtkPV3FoamReader::GetNumberOfTimeArrays() +{ + vtkDebugMacro(<<"GetNumberOf TimeArrays"); + + return TimeSelection->GetNumberOfArrays(); +} + + +const char* vtkPV3FoamReader::GetTimeArrayName +( + int index +) +{ + vtkDebugMacro(<<"GetTimeArrayName"); + + return TimeSelection->GetArrayName(index); +} + + +int vtkPV3FoamReader::GetTimeArrayStatus +( + const char* name +) +{ + vtkDebugMacro(<<"GetTimeArrayStatus"); + + return TimeSelection->ArrayIsEnabled(name); +} + + +void vtkPV3FoamReader::SetTimeArrayStatus +( + const char* name, + int status +) +{ + vtkDebugMacro(<<"SetTimeArrayStatus"); + + if (status) + { + TimeSelection->EnableArray(name); + } + else + { + TimeSelection->DisableArray(name); + } +} + + +vtkDataArraySelection* vtkPV3FoamReader::GetRegionSelection() +{ + vtkDebugMacro(<<"GetRegionSelection"); + + return RegionSelection; +} + + +int vtkPV3FoamReader::GetNumberOfRegionArrays() +{ + vtkDebugMacro(<<"GetNumberOfRegionArrays"); + + return RegionSelection->GetNumberOfArrays(); +} + + +const char* vtkPV3FoamReader::GetRegionArrayName +( + int index +) +{ + vtkDebugMacro(<<"GetRegionArrayName"); + + return RegionSelection->GetArrayName(index); +} + + +int vtkPV3FoamReader::GetRegionArrayStatus +( + const char* name +) +{ + vtkDebugMacro(<<"GetRegionArrayStatus"); + + return RegionSelection->ArrayIsEnabled(name); +} + + +void vtkPV3FoamReader::SetRegionArrayStatus +( + const char* name, + int status +) +{ + vtkDebugMacro(<<"SetRegionArrayStatus"); + + if(status) + { + RegionSelection->EnableArray(name); + } + else + { + RegionSelection->DisableArray(name); + } +} + + +vtkDataArraySelection* vtkPV3FoamReader::GetVolFieldSelection() +{ + vtkDebugMacro(<<"GetVolFieldSelection"); + + return VolFieldSelection; +} + + +int vtkPV3FoamReader::GetNumberOfVolFieldArrays() +{ + vtkDebugMacro(<<"GetNumberOfVolFieldArrays"); + + return VolFieldSelection->GetNumberOfArrays(); +} + + +const char* vtkPV3FoamReader::GetVolFieldArrayName +( + int index +) +{ + vtkDebugMacro(<<"GetVolFieldArrayName"); + + return VolFieldSelection->GetArrayName(index); +} + + +int vtkPV3FoamReader::GetVolFieldArrayStatus +( + const char* name +) +{ + vtkDebugMacro(<<"GetVolFieldArrayStatus"); + + return VolFieldSelection->ArrayIsEnabled(name); +} + + +void vtkPV3FoamReader::SetVolFieldArrayStatus +( + const char* name, + int status +) +{ + vtkDebugMacro(<<"SetVolFieldArrayStatus"); + + if (status) + { + VolFieldSelection->EnableArray(name); + } + else + { + VolFieldSelection->DisableArray(name); + } +} + + +vtkDataArraySelection* vtkPV3FoamReader::GetPointFieldSelection() +{ + vtkDebugMacro(<<"GetPointFieldSelection"); + + return PointFieldSelection; +} + + +int vtkPV3FoamReader::GetNumberOfPointFieldArrays() +{ + vtkDebugMacro(<<"GetNumberOfPointFieldArrays"); + + return PointFieldSelection->GetNumberOfArrays(); +} + + +const char* vtkPV3FoamReader::GetPointFieldArrayName +( + int index +) +{ + vtkDebugMacro(<<"GetPointFieldArrayName"); + + return PointFieldSelection->GetArrayName(index); +} + + +int vtkPV3FoamReader::GetPointFieldArrayStatus +( + const char* name +) +{ + vtkDebugMacro(<<"GetPointFieldArrayStatus"); + + return PointFieldSelection->ArrayIsEnabled(name); +} + + +void vtkPV3FoamReader::SetPointFieldArrayStatus +( + const char* name, + int status +) +{ + vtkDebugMacro(<<"SetPointFieldArrayStatus"); + + if (status) + { + PointFieldSelection->EnableArray(name); + } + else + { + PointFieldSelection->DisableArray(name); + } +} + + +vtkDataArraySelection* vtkPV3FoamReader::GetLagrangianFieldSelection() +{ + vtkDebugMacro(<<"GetLagrangianFieldSelection"); + + return LagrangianFieldSelection; +} + + +int vtkPV3FoamReader::GetNumberOfLagrangianFieldArrays() +{ + vtkDebugMacro(<<"GetNumberOfLagrangianFieldArrays"); + + return LagrangianFieldSelection->GetNumberOfArrays(); +} + + +const char* vtkPV3FoamReader::GetLagrangianFieldArrayName +( + int index +) +{ + vtkDebugMacro(<<"GetLagrangianFieldArrayName"); + + return LagrangianFieldSelection->GetArrayName(index); +} + + +int vtkPV3FoamReader::GetLagrangianFieldArrayStatus +( + const char* name +) +{ + vtkDebugMacro(<<"GetLagrangianFieldArrayStatus"); + + return LagrangianFieldSelection->ArrayIsEnabled(name); +} + + +void vtkPV3FoamReader::SetLagrangianFieldArrayStatus +( + const char* name, + int status +) +{ + vtkDebugMacro(<<"SetLagrangianFieldArrayStatus"); + + if (status) + { + LagrangianFieldSelection->EnableArray(name); + } + else + { + LagrangianFieldSelection->DisableArray(name); + } +} + + +void vtkPV3FoamReader::SelectionModifiedCallback +( + vtkObject*, + unsigned long, + void* clientdata, + void* +) +{ + static_cast(clientdata)->SelectionModified(); +} + + +void vtkPV3FoamReader::SelectionModified() +{ + vtkDebugMacro(<<"SelectionModified"); + + Modified(); +} + diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.h b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.h new file mode 100644 index 0000000000..9e64260f81 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/PV3FoamReader/vtkPV3FoamReader.h @@ -0,0 +1,207 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: vtkPV3FoamReader.h,v $ + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +// .NAME vtkPV3FoamReader - reads a dataset in OpenFOAM format +// .SECTION Description +// vtkPV3FoamReader creates an multiblock dataset. It reads a controlDict +// file, mesh information, and time dependent data. The controlDict file +// contains timestep information. The polyMesh folders contain mesh information +// The time folders contain transient data for the cells Each folder can +// contain any number of data files. + +#ifndef __vtkPV3FoamReader_h +#define __vtkPV3FoamReader_h + +#include "vtkMultiBlockDataSetAlgorithm.h" + +// Foam forward declarations +namespace Foam +{ + class vtkPV3Foam; +} + +// VTK forward declarations +class vtkUnstructuredGrid; +class vtkPoints; +class vtkIntArray; +class vtkFloatArray; +class vtkDoubleArray; +class vtkDataArraySelection; +class vtkCallbackCommand; + + +class VTK_IO_EXPORT vtkPV3FoamReader +: + public vtkMultiBlockDataSetAlgorithm +{ +public: + + static vtkPV3FoamReader* New(); + + vtkTypeRevisionMacro + ( + vtkPV3FoamReader, + vtkMultiBlockDataSetAlgorithm + ); + + void PrintSelf + ( + ostream& os, + vtkIndent indent + ); + + // Description: + // Set/Get the filename. + vtkSetStringMacro(FileName); + vtkGetStringMacro(FileName); + + // GUI update control + vtkSetMacro(UpdateGUI, int); + vtkGetMacro(UpdateGUI, int); + + // FOAM mesh caching control + vtkSetMacro(CacheMesh, int); + vtkGetMacro(CacheMesh, int); + + // FOAM extrapolate internal values onto the walls + vtkSetMacro(ExtrapolateWalls, int); + vtkGetMacro(ExtrapolateWalls, int); + + // FOAM read sets control + vtkSetMacro(IncludeSets, int); + vtkGetMacro(IncludeSets, int); + + // FOAM read zones control + vtkSetMacro(IncludeZones, int); + vtkGetMacro(IncludeZones, int); + + // FOAM patch names control + vtkSetMacro(ShowPatchNames, int); + vtkGetMacro(ShowPatchNames, int); + + // Time-step slider control + vtkSetMacro(TimeStep, int); + vtkGetMacro(TimeStep, int); + vtkSetVector2Macro(TimeStepRange, int); + vtkGetVector2Macro(TimeStepRange, int); + + // Time selection list control + vtkDataArraySelection* GetTimeSelection(); + int GetNumberOfTimeArrays(); + const char* GetTimeArrayName(int index); + int GetTimeArrayStatus(const char* name); + void SetTimeArrayStatus(const char* name, int status); + + + // Region selection list control + vtkDataArraySelection* GetRegionSelection(); + int GetNumberOfRegionArrays(); + const char* GetRegionArrayName(int index); + int GetRegionArrayStatus(const char* name); + void SetRegionArrayStatus(const char* name, int status); + + // volField selection list control + vtkDataArraySelection* GetVolFieldSelection(); + int GetNumberOfVolFieldArrays(); + const char* GetVolFieldArrayName(int index); + int GetVolFieldArrayStatus(const char* name); + void SetVolFieldArrayStatus(const char* name, int status); + + // pointField selection list control + vtkDataArraySelection* GetPointFieldSelection(); + int GetNumberOfPointFieldArrays(); + const char* GetPointFieldArrayName(int index); + int GetPointFieldArrayStatus(const char* name); + void SetPointFieldArrayStatus(const char* name, int status); + + // lagrangianField selection list control + vtkDataArraySelection* GetLagrangianFieldSelection(); + int GetNumberOfLagrangianFieldArrays(); + const char* GetLagrangianFieldArrayName(int index); + int GetLagrangianFieldArrayStatus(const char* name); + void SetLagrangianFieldArrayStatus(const char* name, int status); + + // Callback registered with the SelectionObserver + // for all the selection lists + static void SelectionModifiedCallback + ( + vtkObject* caller, + unsigned long eid, + void* clientdata, + void* calldata + ); + + void SelectionModified(); + + +protected: + + vtkPV3FoamReader(); + ~vtkPV3FoamReader(); + + char* FileName; + + virtual int RequestData + ( + vtkInformation*, + vtkInformationVector**, + vtkInformationVector* + ); + + virtual int RequestInformation + ( + vtkInformation*, + vtkInformationVector**, + vtkInformationVector* + ); + + // The observer to modify this object when the array selections + // are modified + vtkCallbackCommand* SelectionObserver; + + +private: + + vtkPV3FoamReader(const vtkPV3FoamReader&); // Not implemented. + void operator=(const vtkPV3FoamReader&); // Not implemented. + + //- Add patch names to the view + void addPatchNamesToView(); + + //- Remove patch names from the view + void removePatchNamesFromView(); + + int CacheMesh; + int ExtrapolateWalls; + int IncludeSets; + int IncludeZones; + int ShowPatchNames; + + int UpdateGUI; + int UpdateGUIOld; + int TimeStep; + int TimeStepRange[2]; + + vtkDataArraySelection* TimeSelection; + vtkDataArraySelection* RegionSelection; + vtkDataArraySelection* VolFieldSelection; + vtkDataArraySelection* PointFieldSelection; + vtkDataArraySelection* LagrangianFieldSelection; + + //BTX + Foam::vtkPV3Foam* foamData_; + //ETX +}; + +#endif diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/files b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/files new file mode 100644 index 0000000000..ba65793d66 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/files @@ -0,0 +1,13 @@ +vtkPV3Foam.C +vtkPV3FoamAddVolumeMesh.C +vtkPV3FoamAddLagrangianMesh.C +vtkPV3FoamAddPatchMesh.C +vtkPV3FoamAddFaceZoneMesh.C +vtkPV3FoamAddPointZoneMesh.C +vtkPV3FoamAddFaceSetMesh.C +vtkPV3FoamAddPointSetMesh.C +vtkPV3FoamUpdate.C +vtkPV3FoamUpdateInformation.C +vtkPV3FoamConvertMesh.C + +LIB = $(FOAM_LIBBIN)/libvtkPV3Foam diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/options b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/options new file mode 100644 index 0000000000..650b286a7d --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/Make/options @@ -0,0 +1,16 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/lagrangian/basic/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(ParaView_DIR) \ + -I$(ParaView_DIR)/VTK \ + -I$(ParaView_DIR)/VTK/Common \ + -I$(ParaView_DIR)/VTK/Filtering \ + -I$(ParaView_DIR)/VTK/Rendering \ + -I../PV3FoamReader + +LIB_LIBS = \ + -lfiniteVolume \ + -llagrangian \ + -lmeshTools \ + $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkDataArrayTemplateImplicit.txx b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkDataArrayTemplateImplicit.txx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.C b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.C new file mode 100644 index 0000000000..14961222ab --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.C @@ -0,0 +1,1014 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "vtkPV3Foam.H" + +// Foam includes +#include "argList.H" +#include "JobInfo.H" +#include "Time.H" +#include "fvMesh.H" +#include "IOobjectList.H" +#include "patchZones.H" +#include "vtkPV3FoamReader.h" + +// VTK includes +#include "vtkCharArray.h" +#include "vtkDataArraySelection.h" +#include "vtkDataSet.h" +#include "vtkFieldData.h" +#include "vtkMultiBlockDataSet.h" +#include "vtkRenderer.h" +#include "vtkTextActor.h" +#include "vtkTextProperty.h" +#include "vtkPolyData.h" +#include "vtkUnstructuredGrid.h" +#include "vtkInformation.h" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::vtkPV3Foam, 0); + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +#include "vtkPV3FoamAddFields.H" +#include "vtkPV3FoamUpdateInformationFields.H" + + +void Foam::vtkPV3Foam::AddToBlock +( + vtkMultiBlockDataSet* output, + const selectionInfo& selector, + const label datasetNo, + vtkDataSet* dataset, + const string& blockName +) +{ + const int blockNo = selector.block(); + + vtkDataObject* blockDO = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + if (blockDO && !block) + { + FatalErrorIn("Foam::vtkPV3Foam::AddToBlock") + << "Block already has a vtkDataSet assigned to it" << nl << endl; + return; + } + + if (!block) + { + block = vtkMultiBlockDataSet::New(); + output->SetBlock(blockNo, block); + block->Delete(); + } + + if (block) + { + Info<< "block[" << blockNo << "] has " + << block->GetNumberOfBlocks() + << " datasets prior to adding set " << datasetNo + << " with name: " << blockName << endl; + + // when assigning dataset 0, also name the parent block + if (!datasetNo && selector.name()) + { + output->GetMetaData(blockNo)->Set + ( + vtkCompositeDataSet::NAME(), + selector.name() + ); + } + } + + + block->SetBlock(datasetNo, dataset); + + if (blockName.size()) + { + block->GetMetaData(datasetNo)->Set + ( + vtkCompositeDataSet::NAME(), blockName.c_str() + ); + } + +} + + +vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock +( + vtkMultiBlockDataSet* output, + const selectionInfo& selector, + const label datasetNo +) +{ + const int blockNo = selector.block(); + + vtkDataObject* blockDO = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + if (block) + { + return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo)); + } + + return 0; +} + + +Foam::label Foam::vtkPV3Foam::GetNumberOfDataSets +( + vtkMultiBlockDataSet* output, + const selectionInfo& selector +) +{ + const int blockNo = selector.block(); + + vtkDataObject* blockDO = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + if (block) + { + return block->GetNumberOfBlocks(); + } + + return 0; +} + + +void Foam::vtkPV3Foam::resetCounters() +{ + // Reset region ids and sizes + selectInfoVolume_.reset(); + selectInfoPatches_.reset(); + selectInfoLagrangian_.reset(); + selectInfoCellZones_.reset(); + selectInfoFaceZones_.reset(); + selectInfoPointZones_.reset(); + selectInfoCellSets_.reset(); + selectInfoFaceSets_.reset(); + selectInfoPointSets_.reset(); +} + + +void Foam::vtkPV3Foam::initializeTime() +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::initializeTime" << endl; + } + + Time& runTime = dbPtr_(); + + // Get times list + instantList times = runTime.times(); + + vtkDataArraySelection* arraySelection = reader_->GetTimeSelection(); + + // only execute this if there is a mismatch between + // the times available according to FOAM and according to VTK + int nArrays = arraySelection->GetNumberOfArrays(); + + if (nArrays && nArrays == times.size() - 1) + { + return; + } + + // preserve the currently selected values + const stringList selectedEntries = getSelectedArrayEntries + ( + arraySelection + ); + // Clear current time lists + arraySelection->RemoveAllArrays(); + + // "constant" is implicit - skip it + // All the time selections are enabled by default + for (label timeI = 1; timeI < times.size(); ++timeI) + { + arraySelection->AddArray + ( + times[timeI].name().c_str() + ); + } + + // TODO: select latestTime from the current selections + // restore selections + if (selectedEntries.size()) + { + // Update time selection according to the data just read in + setSelectedArrayEntries + ( + arraySelection, + selectedEntries + ); + + Info << "last selected: " << selectedEntries[selectedEntries.size()-1] << endl; + } + +/* + if (debug) + { + Info<< "Selecting time " << times[timeIndex].name() << endl; + } + + runTime.setTime(times[timeIndex], timeIndex); + */ +} + + +bool Foam::vtkPV3Foam::setTime(const double& requestedTime) +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::setTime(" + << requestedTime << ")" << endl; + } + + Time& runTime = dbPtr_(); + + // Get times list + instantList times = runTime.times(); + + // logic as per "checkTimeOption.H" + bool found = false; + int nearestIndex = -1; + scalar nearestDiff = Foam::GREAT; + + forAll (times, timeIndex) + { + if (times[timeIndex].name() == "constant") continue; + + scalar diff = fabs(times[timeIndex].value() - requestedTime); + if (diff < nearestDiff) + { + nearestDiff = diff; + nearestIndex = timeIndex; + } + } + + if (nearestIndex == -1) + { + nearestIndex = 0; + found = false; + } + else + { + found = true; + } + + if (debug) + { + Info<< "Selecting time " << times[nearestIndex].name() << endl; + } + + runTime.setTime(times[nearestIndex], nearestIndex); + return found; +} + + +void Foam::vtkPV3Foam::updateSelectedRegions() +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::updateSelectedRegions" << endl; + } + + vtkDataArraySelection* arraySelection = reader_->GetRegionSelection(); + + const label nRegions = arraySelection->GetNumberOfArrays(); + + selectedRegions_.setSize(nRegions); + selectedRegionDatasetIds_.setSize(nRegions); + + // Read the selected patches and add to the region list + for (int regionId=0; regionId < nRegions; ++regionId) + { + selectedRegions_[regionId] = arraySelection->GetArraySetting(regionId); + selectedRegionDatasetIds_[regionId] = -1; + + if (debug) + { + Info<< "region " << regionId + << " = " << selectedRegions_[regionId] << endl; + } + } +} + + +Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries +( + vtkDataArraySelection* arraySelection, + const bool firstWord +) +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::getSelectedArrayEntries" << endl; + } + + stringList selections(arraySelection->GetNumberOfArrays()); + label nElem = 0; + forAll (selections, elemI) + { + if (arraySelection->GetArraySetting(elemI)) + { + if (firstWord) + { + selections[nElem] = getFirstWord + ( + arraySelection->GetArrayName(elemI) + ); + } + else + { + selections[nElem] = arraySelection->GetArrayName(elemI); + } + ++nElem; + } + } + + selections.setSize(nElem); + if (debug) + { + Info<< "Active array: " << selections << endl; + } + + return selections; +} + + +Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries +( + vtkDataArraySelection* arraySelection, + const selectionInfo& selector, + const bool firstWord +) +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::getSelectedArrayEntries" << endl; + } + + stringList selections(selector.size()); + label nElem = 0; + + for + ( + int regionId = selector.start(); + regionId < selector.end(); + ++regionId + ) + { + if (arraySelection->GetArraySetting(regionId)) + { + if (firstWord) + { + selections[nElem] = getFirstWord + ( + arraySelection->GetArrayName(regionId) + ); + } + else + { + selections[nElem] = arraySelection->GetArrayName(regionId); + } + + ++nElem; + } + } + + selections.setSize(nElem); + if (debug) + { + Info<< "Active array: " << selections << endl; + } + + return selections; +} + + +void Foam::vtkPV3Foam::setSelectedArrayEntries +( + vtkDataArraySelection* arraySelection, + const stringList& selections +) +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::setSelectedArrayEntries" << endl; + } + const label nEntries = arraySelection->GetNumberOfArrays(); + + // Reset all current entries to 'not selected' + arraySelection->DisableAllArrays(); + + // Loop through entries, setting values from selectedEntries + forAll (selections, elemI) + { + if (debug) + { + Info<< "selections[" << elemI << "] = " << selections[elemI] + << endl; + } + + for (label i=0; iGetArrayName(i); + + if (arrayName == selections[elemI]) + { + if (debug) + { + Info<< "enabling array: " << arrayName << " Index = " + << i + << endl; + } + + arraySelection->EnableArray + ( + arrayName.c_str() + ); + break; + } + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::vtkPV3Foam::vtkPV3Foam +( + const char* const FileName, + vtkPV3FoamReader* reader, + vtkMultiBlockDataSet* output +) +: + reader_(reader), + output_(output), + dbPtr_(NULL), + meshPtr_(NULL), + selectInfoVolume_(VOLUME, "unzoned"), + selectInfoPatches_(PATCHES, "patches"), + selectInfoLagrangian_(LAGRANGIAN, "lagrangian"), + selectInfoCellZones_(CELLZONE, "cellZone"), + selectInfoFaceZones_(FACEZONE, "faceZone"), + selectInfoPointZones_(POINTZONE, "pointZone"), + selectInfoCellSets_(CELLSET, "cellSet"), + selectInfoFaceSets_(FACESET, "faceSet"), + selectInfoPointSets_(POINTSET, "pointSet"), + patchTextActorsPtrs_(0), + nMesh_(0) +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::vtkPV3Foam with " + << FileName << endl; + } + + // avoid argList and get rootPath/caseName directly from the file + fileName fullCasePath(fileName(FileName).path()); + + if (!dir(fullCasePath)) + { + return; + } + if (fullCasePath == ".") + { + fullCasePath = cwd(); + } + + // Create time object + dbPtr_.reset + ( + new Time + ( + Time::controlDictName, + fileName(fullCasePath.path()), + fileName(fullCasePath.name()) + ) + ); + + dbPtr_().functionObjects().off(); + + cout<<"constructed with output: "; + output_->Print(cout), + + resetCounters(); + + // Set initial cloud name + // TODO - TEMPORARY MEASURE UNTIL CAN PROCESS MULTIPLE CLOUDS + cloudName_ = ""; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::vtkPV3Foam::~vtkPV3Foam() +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::~vtkPV3Foam" << endl; + } + + if (meshPtr_) + { + delete meshPtr_; + meshPtr_ = NULL; + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::vtkPV3Foam::UpdateInformation() +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::UpdateInformation" << nl + << "TimeStep = " << reader_->GetTimeStep() << endl; + } + + resetCounters(); + + // preserve the currently selected values + const stringList selectedEntries = getSelectedArrayEntries + ( + reader_->GetRegionSelection() + ); + // Clear current region list/array + reader_->GetRegionSelection()->RemoveAllArrays(); + + initializeTime(); + + // Update region array + updateInformationInternalMesh(); + + updateInformationLagrangian(); + + updateInformationPatches(); + + if (reader_->GetIncludeSets()) + { + updateInformationSets(); + } + + if (reader_->GetIncludeZones()) + { + updateInformationZones(); + } + + // Update region selection with the data just read in + setSelectedArrayEntries + ( + reader_->GetRegionSelection(), + selectedEntries + ); + + // Update volField array + updateInformationFields + ( + reader_->GetVolFieldSelection() + ); + + // Update pointField array + updateInformationFields + ( + reader_->GetPointFieldSelection() + ); + + // Update lagrangian field array + updateInformationLagrangianFields(); +} + + +void Foam::vtkPV3Foam::Update +( + vtkMultiBlockDataSet* output +) +{ + if (debug) + { + Info<< "entered Foam::vtkPV3Foam::Update" << endl; + cout<<"Update\n"; + output->Print(cout); + + cout<<"Internally:\n"; + output_->Print(cout); + + cout<< " has " << output_->GetNumberOfBlocks() << " blocks\n"; + } + + + + // Set up region selection(s) + updateSelectedRegions(); + + // Update the Foam mesh + updateFoamMesh(); + + // Convert meshes + convertMeshVolume(output); + + convertMeshLagrangian(output); + + convertMeshPatches(output); + + if (reader_->GetIncludeZones()) + { + convertMeshCellZones(output); + convertMeshFaceZones(output); + convertMeshPointZones(output); + } + + if (reader_->GetIncludeSets()) + { + convertMeshCellSet(output); + convertMeshFaceSet(output); + convertMeshPointSet(output); + } + + // Update fields + updateVolFields(output); + + updatePointFields(output); + + updateLagrangianFields(output); + + if (debug) + { + Info<< "Number of data sets after update" << nl + << " VOLUME = " + << GetNumberOfDataSets(output, selectInfoVolume_) << nl + << " PATCHES = " + << GetNumberOfDataSets(output, selectInfoPatches_) << nl + << " LAGRANGIAN = " + << GetNumberOfDataSets(output, selectInfoLagrangian_) << nl + << " CELLZONE = " + << GetNumberOfDataSets(output, selectInfoCellZones_) << nl + << " FACEZONE = " + << GetNumberOfDataSets(output, selectInfoFaceZones_) << nl + << " POINTZONE = " + << GetNumberOfDataSets(output, selectInfoPointZones_) << nl + << " CELLSET = " + << GetNumberOfDataSets(output, selectInfoCellSets_) << nl + << " FACESET = " + << GetNumberOfDataSets(output, selectInfoFaceSets_) << nl + << " POINTSET = " + << GetNumberOfDataSets(output, selectInfoPointSets_) << nl; + + // traverse blocks: + + int nBlocks = output->GetNumberOfBlocks(); + Info << "nBlocks = " << nBlocks << endl; + + cout<< "done Update\n"; + output_->Print(cout); + cout<< " has " << output_->GetNumberOfBlocks() << " blocks\n"; + output_->GetInformation()->Print(cout); + + cout <<"ShouldIReleaseData :" << output_->ShouldIReleaseData() << "\n"; + } +} + + +double* Foam::vtkPV3Foam::timeSteps(int& nTimeSteps) +{ + int nTimes = 0; + double* ts = NULL; + + vtkDataArraySelection* arraySelection = reader_->GetTimeSelection(); + + if (dbPtr_.valid()) + { + Time& runTime = dbPtr_(); + + instantList times = runTime.times(); + List selected = List(times.size(), false); + + const label nSelectedTimes = arraySelection->GetNumberOfArrays(); + + for (int i = 0; i < nSelectedTimes; ++i) + { + // always skip "constant" time + const int timeI = i + 1; + if + ( + arraySelection->GetArraySetting(i) + && timeI < times.size() + ) + { +#if 0 + Info<<"timeSelection[" + << i + <<"] = " + << arraySelection->GetArraySetting(i) + << " is " + << arraySelection->GetArrayName(i) << endl; +#endif + selected[timeI] = true; + ++nTimes; + } + } + + if (debug) + { + Info<< "selected " << nTimes << " times "; + Info<< "found " << times.size() << " times: ("; + forAll(times, timeI) + { + Info<< " " << times[timeI].value(); + } + Info<< " )" << endl; + } + + if (nTimes) + { + ts = new double[nTimes]; + int stepI = 0; + + forAll(selected, selectI) + { + if (selected[selectI]) + { + ts[stepI] = times[selectI].value(); + stepI++; + } + } + } + } + else + { + if (debug) + { + Info<< "no valid dbPtr:" <GetRegionSelection(), + selector, + true + ); + + Info<<"patches: " << selectedPatches < zoneCentre(pbMesh.size()); + + if (debug) + { + Info<< "determining patch zones" << endl; + } + + // Loop through all patches to determine zones, and centre of each zone + forAll(pbMesh, patchI) + { + const polyPatch& pp = pbMesh[patchI]; + + // Only include the patch if it is selected + bool isSelected = false; + forAll(selectedPatches, elemI) + { + if (pp.name() == selectedPatches[elemI]) + { + isSelected = true; + break; + } + } + + if (isSelected) + { + const labelListList& edgeFaces = pp.edgeFaces(); + const vectorField& n = pp.faceNormals(); + + boolList featEdge(pp.nEdges(), false); + + forAll(edgeFaces, edgeI) + { + const labelList& eFaces = edgeFaces[edgeI]; + + if (eFaces.size() != 2) + { + featEdge[edgeI] = true; + } + else if (mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5) + { + featEdge[edgeI] = true; + } + } + + // Do topological analysis of patch. Determine disconnected regions + patchZones pZones(pp, featEdge); + + nZones[patchI] = pZones.nZones(); + + labelList zoneNFaces(pZones.nZones(), 0); + + // Save start of information for current patch + label patchStart = zoneCentre.size(); + + // Create storage for additional zone centres + forAll(zoneNFaces, zoneI) + { + zoneCentre.append(vector::zero); + } + + // Do averaging per individual zone + + forAll(pp, faceI) + { + label zoneI = pZones[faceI]; + zoneCentre[patchStart+zoneI] += pp[faceI].centre(pp.points()); + zoneNFaces[zoneI]++; + } + + for (label i=0; iRemoveViewProp(patchTextActorsPtrs_[patchI]); + patchTextActorsPtrs_[patchI]->Delete(); + } + patchTextActorsPtrs_.setSize(0); +} + + +int Foam::vtkPV3Foam::numberOfAvailableTimes() const +{ + if (dbPtr_.valid()) + { + return dbPtr_().times().size(); + } + else + { + return 0; + } +} + + +int Foam::vtkPV3Foam::numberOfPoints() +{ + if (meshPtr_) + { + return meshPtr_->nPoints(); + } + else + { + return 0; + } +} + + +int Foam::vtkPV3Foam::numberOfCells() +{ + if (meshPtr_) + { + return meshPtr_->nCells(); + } + { + return 0; + } +} + + +int Foam::vtkPV3Foam::numberOfMeshes() const +{ + return nMesh_; +} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.H b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.H new file mode 100644 index 0000000000..eda35bab51 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PV3-3FoamReader/vtkPV3Foam/vtkPV3Foam.H @@ -0,0 +1,737 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::vtkPV3Foam + +Description + Provides a reader interface for OpenFOAM to VTK interaction. + +SourceFiles + interpolatePointToCell.C + interpolatePointToCell.H + vtkPV3Foam.C + vtkPV3Foam.H + vtkPV3FoamAddFaceSetMesh.C + vtkPV3FoamAddFaceZoneMesh.C + vtkPV3FoamAddFields.H + vtkPV3FoamAddLagrangianMesh.C + vtkPV3FoamAddPatchMesh.C + vtkPV3FoamAddPointSetMesh.C + vtkPV3FoamAddPointZoneMesh.C + vtkPV3FoamAddVolumeMesh.C + vtkPV3FoamConvertLagrangianFields.H + vtkPV3FoamConvertMesh.C + vtkPV3FoamConvertPatchFaceField.H + vtkPV3FoamConvertPatchPointField.H + vtkPV3FoamConvertPointFields.H + vtkPV3FoamConvertVolFields.H + vtkPV3FoamInsertNextPoint.H + vtkPV3FoamUpdate.C + vtkPV3FoamUpdateInformation.C + vtkPV3FoamUpdateInformationFields.H + + // Needed by VTK? + vtkDataArrayTemplateImplicit.txx + +\*---------------------------------------------------------------------------*/ + +#ifndef vtkPV3Foam_H +#define vtkPV3Foam_H + +#include "className.H" +#include "fileName.H" +#include "volPointInterpolation.H" +#include "stringList.H" + + +// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // + +class vtkDataArraySelection; +class vtkDataSet; +class vtkMultiBlockDataSet; +class vtkPoints; +class vtkPV3FoamReader; +class vtkRenderer; +class vtkTextActor; +class vtkPolyData; +class vtkUnstructuredGrid; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Foam class forward declarations +class argList; +class Time; +class fvMesh; +class IOobjectList; +class polyPatch; +class faceSet; +class pointSet; + +template +class IOField; + +template +class List; + +/*---------------------------------------------------------------------------*\ + Class vtkPV3Foam Declaration +\*---------------------------------------------------------------------------*/ + +class vtkPV3Foam +{ +public: + + // Public data + + //- bookkeeping for the GUI checklists and the multi-block organization + class selectionInfo + { + int block_; + const char *name_; + int start_; + int size_; + + public: + + selectionInfo(const int blockNo, const char *name) + : + block_(blockNo), + name_(name), + start_(-1), + size_(0) + {} + + //- Return the block holding these datasets + const int block() const + { + return block_; + } + + const char* name() const + { + return name_; + } + + const int start() const + { + return start_; + } + + const int end() const + { + return start_ + size_; + } + + const int size() const + { + return size_; + } + + void reset() + { + start_ = -1; + size_ = 0; + } + + //- Assign new start and reset the size + void operator=(const int i) + { + start_ = i; + size_ = 0; + } + + //- Increment the size + void operator+=(const int n) + { + size_ += n; + } + }; + +private: + + // Private data + + //BTX + //- Indices for datasets in vtkMultiBlockDataSet + enum + { + VOLUME = 0, // internal mesh + PATCHES = 1, // patches + LAGRANGIAN = 2, + CELLZONE = 3, + FACEZONE = 4, + POINTZONE = 5, + CELLSET = 6, + FACESET = 7, + POINTSET = 8 + }; + //ETX + + //- Access to the controlling vtkPV3FoamReader + vtkPV3FoamReader* reader_; + + //- Access to the output block + vtkMultiBlockDataSet* output_; + + //- Foam time control + autoPtr