diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader_SM.xml index 56d790918e..5e4c7c9725 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader_SM.xml @@ -156,7 +156,7 @@ command="SetIncludeZones" label="Include Zones" number_of_elements="1" - default_values="0" + default_values="1" animateable="0"> Allow selection of zones @@ -206,27 +206,27 @@ - + - + - Select volume fields to load + Select fields to load @@ -256,44 +256,16 @@ - - - - - - - - - - - - Select point fields to load - - - - - + + - - diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.cxx index df8a888ea6..7a3b8285f3 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.cxx @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,14 +71,13 @@ vtkPVFoamReader::vtkPVFoamReader() ExtrapolatePatches = 0; UseVTKPolyhedron = 0; IncludeSets = 0; - IncludeZones = 0; + IncludeZones = 1; ShowPatchNames = 0; ShowGroupsOnly = 0; InterpolateVolFields = 1; PartSelection = vtkDataArraySelection::New(); - VolFieldSelection = vtkDataArraySelection::New(); - PointFieldSelection = vtkDataArraySelection::New(); + FieldSelection = vtkDataArraySelection::New(); LagrangianFieldSelection = vtkDataArraySelection::New(); // Setup the selection callback to modify this object when an array @@ -95,12 +94,7 @@ vtkPVFoamReader::vtkPVFoamReader() vtkCommand::ModifiedEvent, this->SelectionObserver ); - VolFieldSelection->AddObserver - ( - vtkCommand::ModifiedEvent, - this->SelectionObserver - ); - PointFieldSelection->AddObserver + FieldSelection->AddObserver ( vtkCommand::ModifiedEvent, this->SelectionObserver @@ -138,15 +132,13 @@ vtkPVFoamReader::~vtkPVFoamReader() PartSelection->RemoveObserver(this->SelectionObserver); - VolFieldSelection->RemoveObserver(this->SelectionObserver); - PointFieldSelection->RemoveObserver(this->SelectionObserver); + FieldSelection->RemoveObserver(this->SelectionObserver); LagrangianFieldSelection->RemoveObserver(this->SelectionObserver); SelectionObserver->Delete(); PartSelection->Delete(); - VolFieldSelection->Delete(); - PointFieldSelection->Delete(); + FieldSelection->Delete(); LagrangianFieldSelection->Delete(); } @@ -509,91 +501,46 @@ void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) // ---------------------------------------------------------------------- -// volField selection list control +// Field selection list control -vtkDataArraySelection* vtkPVFoamReader::GetVolFieldSelection() +vtkDataArraySelection* vtkPVFoamReader::GetFieldSelection() { - vtkDebugMacro(<<"GetVolFieldSelection"); - return VolFieldSelection; + vtkDebugMacro(<<"GetFieldSelection"); + return FieldSelection; } -int vtkPVFoamReader::GetNumberOfVolFieldArrays() +int vtkPVFoamReader::GetNumberOfFieldArrays() { - vtkDebugMacro(<<"GetNumberOfVolFieldArrays"); - return VolFieldSelection->GetNumberOfArrays(); + vtkDebugMacro(<<"GetNumberOfFieldArrays"); + return FieldSelection->GetNumberOfArrays(); } -const char* vtkPVFoamReader::GetVolFieldArrayName(int index) +const char* vtkPVFoamReader::GetFieldArrayName(int index) { - vtkDebugMacro(<<"GetVolFieldArrayName"); - return VolFieldSelection->GetArrayName(index); + vtkDebugMacro(<<"GetFieldArrayName"); + return FieldSelection->GetArrayName(index); } -int vtkPVFoamReader::GetVolFieldArrayStatus(const char* name) +int vtkPVFoamReader::GetFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetVolFieldArrayStatus"); - return VolFieldSelection->ArrayIsEnabled(name); + vtkDebugMacro(<<"GetFieldArrayStatus"); + return FieldSelection->ArrayIsEnabled(name); } -void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) +void vtkPVFoamReader::SetFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetVolFieldArrayStatus"); + vtkDebugMacro(<<"SetFieldArrayStatus"); if (status) { - VolFieldSelection->EnableArray(name); + FieldSelection->EnableArray(name); } else { - VolFieldSelection->DisableArray(name); - } -} - - -// ---------------------------------------------------------------------- -// pointField selection list control - -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); - } - else - { - PointFieldSelection->DisableArray(name); + FieldSelection->DisableArray(name); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.h index 9d59cbd5c2..67f8b7362d 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoamReader.h @@ -63,7 +63,6 @@ class vtkPVFoamReader public vtkMultiBlockDataSetAlgorithm { public: - vtkTypeMacro(vtkPVFoamReader, vtkMultiBlockDataSetAlgorithm); void PrintSelf(ostream&, vtkIndent); @@ -140,20 +139,12 @@ public: const char* GetPartArrayName(int index); // Description: - // volField selection list control - virtual vtkDataArraySelection* GetVolFieldSelection(); - int GetNumberOfVolFieldArrays(); - int GetVolFieldArrayStatus(const char* name); - void SetVolFieldArrayStatus(const char* name, int status); - const char* GetVolFieldArrayName(int index); - - // Description: - // pointField selection list control - virtual vtkDataArraySelection* GetPointFieldSelection(); - int GetNumberOfPointFieldArrays(); - int GetPointFieldArrayStatus(const char* name); - void SetPointFieldArrayStatus(const char* name, int status); - const char* GetPointFieldArrayName(int index); + // Field selection list control + virtual vtkDataArraySelection* GetFieldSelection(); + int GetNumberOfFieldArrays(); + int GetFieldArrayStatus(const char* name); + void SetFieldArrayStatus(const char* name, int status); + const char* GetFieldArrayName(int index); // Description: // lagrangianField selection list control @@ -182,9 +173,6 @@ protected: //- Construct null vtkPVFoamReader(); - //- Disallow default bitwise copy construction - vtkPVFoamReader(const vtkPVFoamReader&) = delete; - //- Destructor ~vtkPVFoamReader(); @@ -213,12 +201,15 @@ protected: //- The file name for this case char* FileName; - //- Disallow default bitwise assignment - void operator=(const vtkPVFoamReader&) = delete; - private: + //- Disallow default bitwise copy construct + vtkPVFoamReader(const vtkPVFoamReader&); + + //- Disallow default bitwise assignment + void operator=(const vtkPVFoamReader&); + //- Add/remove patch names to/from the view void updatePatchNamesView(const bool show); @@ -236,8 +227,7 @@ private: int InterpolateVolFields; vtkDataArraySelection* PartSelection; - vtkDataArraySelection* VolFieldSelection; - vtkDataArraySelection* PointFieldSelection; + vtkDataArraySelection* FieldSelection; vtkDataArraySelection* LagrangianFieldSelection; //- Cached data for output port0 (experimental!) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMeshReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMeshReader.h index ed55b0789d..2b6139da0c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMeshReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMeshReader.h @@ -113,9 +113,6 @@ protected: //- Construct null vtkPVblockMeshReader(); - //- Disallow default bitwise copy construction - vtkPVblockMeshReader(const vtkPVblockMeshReader&) = delete; - //- Destructor ~vtkPVblockMeshReader(); @@ -143,12 +140,15 @@ protected: char* FileName; - //- Disallow default bitwise assignment - void operator=(const vtkPVblockMeshReader&) = delete; - private: + //- Disallow default bitwise copy construct + vtkPVblockMeshReader(const vtkPVblockMeshReader&); + + //- Disallow default bitwise assignment + void operator=(const vtkPVblockMeshReader&); + //- Add/remove point numbers to/from the view void updatePointNumbersView(const bool show); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkOpenFOAMPoints.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkOpenFOAMPoints.H index 8349f01c25..a9a85aa21e 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkOpenFOAMPoints.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkOpenFOAMPoints.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,34 +43,6 @@ inline void vtkInsertNextOpenFOAMPoint 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C index 901dd6078a..a62c87a367 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,7 +51,6 @@ namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // #include "vtkPVFoamAddToSelection.H" -#include "vtkPVFoamUpdateInfoFields.H" void Foam::vtkPVFoam::resetCounters() { @@ -428,14 +427,51 @@ void Foam::vtkPVFoam::updateInfo() } // Update volume, point and lagrangian fields - updateInfoFields - ( - reader_->GetVolFieldSelection() - ); - updateInfoFields - ( - reader_->GetPointFieldSelection() - ); + updateInfoFields(); + updateInfoLagrangianFields(); + + { + // Use the db directly since this might be called without a mesh, + // but the region must get added back in + word regionPrefix; + if (meshRegion_ != polyMesh::defaultRegion) + { + regionPrefix = meshRegion_; + } + + vtkDataArraySelection* select = reader_->GetFieldSelection(); + + stringList enabledEntries(getSelectedArrayEntries(select)); + select->RemoveAllArrays(); + + const Time& runTime = dbPtr_(); + const instantList times = runTime.times(); + addToSelection + ( + select, + runTime, + times, + regionPrefix + ); + addToSelection + ( + select, + runTime, + times, + regionPrefix + ); + addToSelection + ( + select, + runTime, + times, + regionPrefix + ); + + // Restore the enabled selections + setSelectedArrayEntries(select, enabledEntries); + } + updateInfoLagrangianFields(); if (debug) @@ -556,13 +592,14 @@ void Foam::vtkPVFoam::Update reader_->UpdateProgress(0.8); // Update fields - convertVolFields(output); - convertPointFields(output); + convertFields(output); convertLagrangianFields(lagrangianOutput); + if (debug) { Info<< "done reader part" << endl; } + reader_->UpdateProgress(0.95); meshChanged_ = fieldsChanged_ = false; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H index 36a37a7749..f6d541bdd8 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H @@ -37,13 +37,12 @@ SourceFiles vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C vtkPVFoamMeshZone.C - vtkPVFoamFaceField.H + vtkPVFoamSurfaceField.H vtkPVFoamLagrangianFields.H vtkPVFoamPatchField.H vtkPVFoamPointFields.H vtkPVFoamPoints.H vtkPVFoamUpdateInfo.C - vtkPVFoamUpdateInfoFields.H vtkPVFoamUtils.C vtkPVFoamVolFields.H vtkPVFoamAddToSelection.H @@ -68,6 +67,8 @@ SourceFiles #include "primitivePatch.H" #include "PrimitivePatchInterpolation.H" #include "volPointInterpolation.H" +#include "surfaceFieldsFwd.H" +#include "instantList.H" // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // @@ -380,9 +381,19 @@ class vtkPVFoam const string& suffix=string::null ); - //- Field info + //- Add objects of Type to paraview array selection template class patchType, class meshType> - void updateInfoFields(vtkDataArraySelection*); + void addToSelection + ( + vtkDataArraySelection *select, + const Time& runTime, + const instantList& times, + const word& regionPrefix, + const string& suffix=string::null + ); + + //- Field info + void updateInfoFields(); //- Lagrangian field info void updateInfoLagrangianFields(); @@ -475,11 +486,8 @@ class vtkPVFoam // Field conversion functions - //- Convert volume fields - void convertVolFields(vtkMultiBlockDataSet*); - - //- Convert point fields - void convertPointFields(vtkMultiBlockDataSet*); + //- Convert fields + void convertFields(vtkMultiBlockDataSet*); //- Convert Lagrangian fields void convertLagrangianFields(vtkMultiBlockDataSet*); @@ -542,9 +550,9 @@ class vtkPVFoam const label datasetNo ); - //- Face set/zone field + //- Face set/zone field from volField template - void convertFaceField + void convertSurfaceField ( const GeometricField&, vtkMultiBlockDataSet* output, @@ -554,6 +562,27 @@ class vtkPVFoam const labelList& faceLabels ); + //- Face set/zone field from surfaceField + template + void convertSurfaceField + ( + const GeometricField& tf, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const label datasetNo, + const fvMesh& mesh, + const labelList& faceLabels + ); + + //- Surface fields - all types + template + void convertSurfaceFields + ( + const fvMesh& mesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); + //- Lagrangian fields - all types template void convertLagrangianFields diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamAddToSelection.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamAddToSelection.H index a68cd4deb1..921479d4e3 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamAddToSelection.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamAddToSelection.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,6 +29,7 @@ License // OpenFOAM includes #include "IOobjectList.H" #include "SortableList.H" +#include "surfaceFields.H" // VTK includes #include "vtkDataArraySelection.h" @@ -67,6 +68,56 @@ Foam::label Foam::vtkPVFoam::addToSelection } +template class patchType, class meshType> +void Foam::vtkPVFoam::addToSelection +( + vtkDataArraySelection *select, + const Time& runTime, + const instantList& times, + const word& regionPrefix, + const string& suffix +) +{ + forAll(times, timei) + { + // Search for list of objects for this time and mesh region + IOobjectList objects(runTime, times[timei].name(), regionPrefix); + + //- Add volume fields to GUI + addToSelection> + ( + select, + objects, + suffix + ); + addToSelection> + ( + select, + objects, + suffix + ); + addToSelection> + ( + select, + objects, + suffix + ); + addToSelection> + ( + select, + objects, + suffix + ); + addToSelection> + ( + select, + objects, + suffix + ); + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFaceField.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFaceField.H deleted file mode 100644 index e8706339c7..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFaceField.H +++ /dev/null @@ -1,117 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 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/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C index 6037cc14a2..801274b7c4 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -82,7 +82,7 @@ Foam::IOobjectList Foam::vtkPVFoam::getObjects } -void Foam::vtkPVFoam::convertVolFields +void Foam::vtkPVFoam::convertFields ( vtkMultiBlockDataSet* output ) @@ -91,7 +91,7 @@ void Foam::vtkPVFoam::convertVolFields wordHashSet selectedFields = getSelected ( - reader_->GetVolFieldSelection() + reader_->GetFieldSelection() ); if (selectedFields.empty()) @@ -168,92 +168,24 @@ void Foam::vtkPVFoam::convertVolFields mesh, ppInterpList, objects, interpFields, output ); - if (debug) - { - Info<< " Foam::vtkPVFoam::convertVolFields" << endl; - printMemory(); - } -} - - -void Foam::vtkPVFoam::convertPointFields -( - vtkMultiBlockDataSet* output -) -{ - const fvMesh& mesh = *meshPtr_; - - wordHashSet selectedFields = getSelected - ( - reader_->GetPointFieldSelection() - ); - - if (selectedFields.empty()) - { - if (debug) - { - Info<< "no point fields selected" << endl; - } - return; - } - - // Get objects (fields) for this time - only keep selected fields - // the region name is already in the mesh db - IOobjectList objects - ( - getObjects - ( - selectedFields, - mesh, - dbPtr_().timeName() - ) - ); - - if (objects.empty()) - { - return; - } - - if (debug) - { - Info<< " Foam::vtkPVFoam::convertPointFields" << nl - << "converting OpenFOAM volume fields -> point fields" << endl; - forAllConstIter(IOobjectList, objects, iter) - { - Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; - } - printMemory(); - } + convertSurfaceFields(mesh, objects, output); + convertSurfaceFields(mesh, objects, output); + convertSurfaceFields(mesh, objects, output); + convertSurfaceFields(mesh, objects, output); + convertSurfaceFields(mesh, objects, output); // 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(mesh, pMesh, objects, output); + convertPointFields(mesh, pMesh, objects, output); + convertPointFields(mesh, pMesh, objects, output); + convertPointFields(mesh, pMesh, objects, output); + convertPointFields(mesh, pMesh, objects, output); if (debug) { - Info<< " Foam::vtkPVFoam::convertPointFields" << endl; + Info<< " Foam::vtkPVFoam::convertVolFields" << endl; printMemory(); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamSurfaceField.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamSurfaceField.H new file mode 100644 index 0000000000..d016ae22c1 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamSurfaceField.H @@ -0,0 +1,318 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2019 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 vtkPVFoamSurfaceField_H +#define vtkPVFoamSurfaceField_H + +#include "surfaceFields.H" +#include "emptyFvsPatchField.H" + +// VTK includes +#include "vtkCellData.h" +#include "vtkFloatArray.h" +#include "vtkMultiBlockDataSet.h" +#include "vtkPolyData.h" + +#include "vtkOpenFOAMTupleRemap.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void Foam::vtkPVFoam::convertSurfaceField +( + 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 convertSurfaceField: " + << 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(); +} + + +template +void Foam::vtkPVFoam::convertSurfaceField +( + 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(); + + 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 convertSurfaceField: " + << tf.name() + << " size = " << tf.size() + << " nComp=" << nComp + << " nTuples = " << faceLabels.size() << endl; + } + + // To avoid whichPatch first flatten the field + Field flatFld(mesh.nFaces(), Zero); + SubField(flatFld, nInternalFaces) = tf.internalField(); + forAll(tf.boundaryField(), patchi) + { + const fvsPatchField& fvs = tf.boundaryField()[patchi]; + + SubField + ( + flatFld, + fvs.size(), + fvs.patch().start() + ) = fvs; + } + + + // For interior faces: average owner/neighbour + // For boundary faces: owner + forAll(faceLabels, facei) + { + const label faceNo = faceLabels[facei]; + + float vec[nComp]; + for (direction d=0; d(vec); + + cellData->InsertTuple(facei, vec); + } + + vtkPolyData::SafeDownCast + ( + GetDataSetFromBlock(output, range, datasetNo) + ) ->GetCellData() + ->AddArray(cellData); + + cellData->Delete(); +} + + +template +void Foam::vtkPVFoam::convertSurfaceFields +( + const fvMesh& mesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + forAllConstIter(IOobjectList, objects, iter) + { + // Restrict to GeometricField + if + ( + iter()->headerClassName() + != GeometricField::typeName + ) + { + continue; + } + + // Load field + const GeometricField tf + ( + *iter(), + mesh + ); + + // 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 = mesh.boundaryMesh().findPatchID(patchName); + + if (!partStatus_[partId] || datasetNo < 0 || patchId < 0) + { + continue; + } + + const fvsPatchField& ptf = tf.boundaryField()[patchId]; + + if (!isType>(ptf)) + { + convertPatchField + ( + tf.name(), + ptf, + output, + arrayRangePatches_, + datasetNo + ); + } + } + + + // 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; + } + + convertSurfaceField + ( + tf, + output, + arrayRangeFaceZones_, + datasetNo, + mesh, + zMesh[zoneId] + ); + } + + // 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] || datasetNo < 0) + { + continue; + } + + const faceSet fSet(mesh, selectName); + + convertSurfaceField + ( + tf, + output, + arrayRangeFaceSets_, + datasetNo, + mesh, + fSet.toc() + ); + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C index 70897f87f7..39e0f06ef6 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C @@ -26,6 +26,7 @@ License #include "vtkPVFoam.H" // OpenFOAM includes +#include "vtkPVFoamReader.h" #include "cellSet.H" #include "faceSet.H" #include "pointSet.H" @@ -34,11 +35,10 @@ License #include "polyBoundaryMeshEntries.H" #include "entry.H" #include "Cloud.H" -#include "vtkPVFoamReader.h" +#include "surfaceFields.H" -// local headers +// Local includes #include "vtkPVFoamAddToSelection.H" -#include "vtkPVFoamUpdateInfoFields.H" // VTK includes #include "vtkDataArraySelection.h" @@ -68,7 +68,7 @@ public: close(); } - // Member Functions + // Member functions bool writeData(Ostream&) const { @@ -252,7 +252,6 @@ void Foam::vtkPVFoam::updateInfoPatches const wordList allPatchNames = patches.names(); // Add patch groups - // ~~~~~~~~~~~~~~~~ for ( @@ -303,7 +302,6 @@ void Foam::vtkPVFoam::updateInfoPatches // Add patches - // ~~~~~~~~~~~ if (!reader_->GetShowGroupsOnly()) { @@ -350,7 +348,6 @@ void Foam::vtkPVFoam::updateInfoPatches // Read patches and determine sizes - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ wordList names(patchEntries.size()); labelList sizes(patchEntries.size()); @@ -365,7 +362,6 @@ void Foam::vtkPVFoam::updateInfoPatches // Add (non-zero) patch groups to the list of mesh parts - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HashTable groups(patchEntries.size()); @@ -450,7 +446,6 @@ void Foam::vtkPVFoam::updateInfoPatches // Add (non-zero) patches to the list of mesh parts - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (!reader_->GetShowGroupsOnly()) { @@ -527,9 +522,7 @@ void Foam::vtkPVFoam::updateInfoZones wordList namesLst; - // // cellZones information - // ~~~~~~~~~~~~~~~~~~~~~ if (meshPtr_) { namesLst = getZoneNames(meshPtr_->cellZones()); @@ -550,9 +543,7 @@ void Foam::vtkPVFoam::updateInfoZones arrayRangeCellZones_ += namesLst.size(); - // // faceZones information - // ~~~~~~~~~~~~~~~~~~~~~ if (meshPtr_) { namesLst = getZoneNames(meshPtr_->faceZones()); @@ -573,9 +564,7 @@ void Foam::vtkPVFoam::updateInfoZones arrayRangeFaceZones_ += namesLst.size(); - // // pointZones information - // ~~~~~~~~~~~~~~~~~~~~~~ if (meshPtr_) { namesLst = getZoneNames(meshPtr_->pointZones()); @@ -681,6 +670,105 @@ void Foam::vtkPVFoam::updateInfoSets } +void Foam::vtkPVFoam::updateInfoFields() +{ + if (debug) + { + Info<< " Foam::vtkPVFoam::updateInfoFields " + " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" + << endl; + } + + vtkDataArraySelection* fieldSelection = reader_->GetFieldSelection(); + + // Use the db directly since this might be called without a mesh, + // but the region must get added back in + word regionPrefix; + if (meshRegion_ != polyMesh::defaultRegion) + { + regionPrefix = meshRegion_; + } + + const Time& runTime = dbPtr_(); + const instantList times = runTime.times(); + + stringList enabledEntries; + + if (fieldSelection->GetNumberOfArrays() == 0 && !meshPtr_) + { + const wordReList defaultFieldRes + ( + configDict_.lookupOrDefault + ( + "defaultFields", + wordReList(wordList{"p", "U"}) + ) + ); + + wordHashSet objectNameSet; + forAll(times, timei) + { + // Search for list of objects for this time and mesh region + IOobjectList objects(runTime, times[timei].name(), regionPrefix); + + forAllConstIter(IOobjectList, objects, iter) + { + objectNameSet.insert(iter.key()); + } + } + + const wordList objectNames(objectNameSet.toc()); + const labelList defaultFields + ( + findStrings(defaultFieldRes, objectNames) + ); + + enabledEntries.setSize(defaultFields.size()); + forAll(defaultFields, i) + { + enabledEntries[i] = objectNames[defaultFields[i]]; + } + } + else + { + // Preserve the enabled selections + enabledEntries = getSelectedArrayEntries(fieldSelection); + } + + fieldSelection->RemoveAllArrays(); + + addToSelection + ( + fieldSelection, + runTime, + times, + regionPrefix + ); + addToSelection + ( + fieldSelection, + runTime, + times, + regionPrefix + ); + addToSelection + ( + fieldSelection, + runTime, + times, + regionPrefix + ); + + // Restore the enabled selections + setSelectedArrayEntries(fieldSelection, enabledEntries); + + if (debug) + { + Info<< " Foam::vtkPVFoam::updateInfoFields" << endl; + } +} + + void Foam::vtkPVFoam::updateInfoLagrangianFields() { if (debug) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfoFields.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfoFields.H deleted file mode 100644 index a1d623d75e..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfoFields.H +++ /dev/null @@ -1,149 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 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 vtkPVFoamUpdateInfoFields_H -#define vtkPVFoamUpdateInfoFields_H - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template class patchType, class meshType> -void Foam::vtkPVFoam::updateInfoFields -( - vtkDataArraySelection* select -) -{ - if (debug) - { - Info<< " Foam::vtkPVFoam::updateInfoFields <" - << meshType::Mesh::typeName - << "> [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" - << endl; - } - - // Use the db directly since this might be called without a mesh, - // but the region must get added back in - word regionPrefix; - if (meshRegion_ != polyMesh::defaultRegion) - { - regionPrefix = meshRegion_; - } - - const instantList times = dbPtr_().times(); - - stringList enabledEntries; - - if (select->GetNumberOfArrays() == 0 && !meshPtr_) - { - const wordReList defaultFieldRes - ( - configDict_.lookupOrDefault - ( - "defaultFields", - wordReList(wordList{"p", "U"}) - ) - ); - - wordHashSet objectNameSet; - forAll(times, timei) - { - // Search for list of objects for this time and mesh region - IOobjectList objects(dbPtr_(), times[timei].name(), regionPrefix); - - forAllConstIter(IOobjectList, objects, iter) - { - objectNameSet.insert(iter.key()); - } - } - - const wordList objectNames(objectNameSet.toc()); - const labelList defaultFields - ( - findStrings(defaultFieldRes, objectNames) - ); - - enabledEntries.setSize(defaultFields.size()); - forAll(defaultFields, i) - { - enabledEntries[i] = objectNames[defaultFields[i]]; - } - } - else - { - // Preserve the enabled selections - enabledEntries = getSelectedArrayEntries(select); - } - - select->RemoveAllArrays(); - - forAll(times, timei) - { - // Search for list of objects for this time and mesh region - IOobjectList objects(dbPtr_(), times[timei].name(), regionPrefix); - - //- Add volume fields to GUI - addToSelection> - ( - select, - objects - ); - addToSelection> - ( - select, - objects - ); - addToSelection> - ( - select, - objects - ); - addToSelection> - ( - select, - objects - ); - addToSelection> - ( - select, - objects - ); - } - - // Restore the enabled selections - setSelectedArrayEntries(select, enabledEntries); - - if (debug) - { - Info<< " Foam::vtkPVFoam::updateInfoFields" << endl; - } -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUtils.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUtils.C index a32ef20a64..c0e55ef921 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUtils.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUtils.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,7 +45,6 @@ Description namespace Foam { - //! \cond fileScope // Extract up to the first non-word characters inline word getFirstWord(const char* str) { @@ -64,8 +63,6 @@ namespace Foam } } - //! \endcond - } // End namespace Foam diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamVolFields.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamVolFields.H index e6ab45f93f..29c91501c0 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamVolFields.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamVolFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,7 +35,7 @@ InClass #include "faceSet.H" #include "volPointInterpolation.H" -#include "vtkPVFoamFaceField.H" +#include "vtkPVFoamSurfaceField.H" #include "vtkPVFoamPatchField.H" #include "vtkOpenFOAMTupleRemap.H" @@ -121,9 +121,7 @@ void Foam::vtkPVFoam::convertVolFields ); - // // Convert patches - if activated - // for ( int partId = arrayRangePatches_.start(); @@ -205,9 +203,7 @@ void Foam::vtkPVFoam::convertVolFields } } - // // Convert face zones - if activated - // for ( int partId = arrayRangeFaceZones_.start(); @@ -231,7 +227,7 @@ void Foam::vtkPVFoam::convertVolFields continue; } - convertFaceField + convertSurfaceField ( tf, output, @@ -240,13 +236,9 @@ void Foam::vtkPVFoam::convertVolFields mesh, zMesh[zoneId] ); - - // TODO: points } - // // Convert face sets - if activated - // for ( int partId = arrayRangeFaceSets_.start(); @@ -264,7 +256,7 @@ void Foam::vtkPVFoam::convertVolFields const faceSet fSet(mesh, selectName); - convertFaceField + convertSurfaceField ( tf, output, @@ -273,8 +265,6 @@ void Foam::vtkPVFoam::convertVolFields mesh, fSet.toc() ); - - // TODO: points } } }