PVFoamReader: Added support for visualising surfaceFields

To avoid additional clutter in the interface volFields, surfaceFields and
pointFields are now selected from a single fields selection box consistent with
the single directory with guaranteed unique names in which they are stored.

Note that when visualising the "phi" flux fields that these are extensive, the
value depends directly on the face area, so unless the mesh is uniform
interpolated continuous colour plots are not physical or informative.

Based on proposal contributed by Mattijs Janssens
This commit is contained in:
Henry Weller
2019-07-15 11:16:35 +01:00
parent 26187dd89d
commit b7c0646ed9
15 changed files with 635 additions and 578 deletions

View File

@ -156,7 +156,7 @@
command="SetIncludeZones"
label="Include Zones"
number_of_elements="1"
default_values="0"
default_values="1"
animateable="0">
<Documentation>
Allow selection of zones
@ -206,27 +206,27 @@
<!-- Available Volume Fields array -->
<StringVectorProperty
name="VolFieldArrayStatus"
name="FieldArrayStatus"
information_only="1">
<ArraySelectionInformationHelper attribute_name="VolField"/>
<ArraySelectionInformationHelper attribute_name="Field"/>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldStatus"
label="Volume Fields"
command="SetVolFieldArrayStatus"
name="FieldStatus"
label="Fields"
command="SetFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="VolFieldArrayStatus"
information_property="FieldArrayStatus"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="VolFieldArrayStatus" function="ArrayList"/>
<Property name="FieldArrayStatus" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
<Documentation>
Select volume fields to load
Select fields to load
</Documentation>
</StringVectorProperty>
@ -256,44 +256,16 @@
</Documentation>
</StringVectorProperty>
<!-- Available pointFields array -->
<StringVectorProperty
name="PointFieldArrayStatus"
information_only="1">
<ArraySelectionInformationHelper attribute_name="PointField"/>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldStatus"
label="Point Fields"
command="SetPointFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="PointFieldArrayStatus"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="PointFieldArrayStatus" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
<Documentation>
Select point fields to load
</Documentation>
</StringVectorProperty>
<PropertyGroup label="Selection">
<Property name="UiIncludeSets"/>
<Property name="UiIncludeZones"/>
<Property name="UiShowGroupsOnly"/>
<Property name="PartArrayStatus"/>
<Property name="PartStatus"/>
<Property name="VolFieldArrayStatus"/>
<Property name="VolFieldStatus"/>
<Property name="FieldArrayStatus"/>
<Property name="FieldStatus"/>
<Property name="LagrangianFieldArrayStatus"/>
<Property name="LagrangianFieldStatus"/>
<Property name="PointFieldArrayStatus"/>
<Property name="PointFieldStatus"/>
</PropertyGroup>
<Hints>

View File

@ -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);
}
}

View File

@ -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!)

View File

@ -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);

View File

@ -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
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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<fvPatchField, volMesh>
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<fvPatchField, volMesh>
(
reader_->GetVolFieldSelection()
select,
runTime,
times,
regionPrefix
);
updateInfoFields<pointPatchField, pointMesh>
addToSelection<fvsPatchField, surfaceMesh>
(
reader_->GetPointFieldSelection()
select,
runTime,
times,
regionPrefix
);
addToSelection<pointPatchField, pointMesh>
(
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;

View File

@ -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<template<class> 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<class Type>
void convertFaceField
void convertSurfaceField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
@ -554,6 +562,27 @@ class vtkPVFoam
const labelList& faceLabels
);
//- Face set/zone field from surfaceField
template<class Type>
void convertSurfaceField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& tf,
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
);
//- Surface fields - all types
template<class Type>
void convertSurfaceFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
);
//- Lagrangian fields - all types
template<class Type>
void convertLagrangianFields

View File

@ -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<template<class> 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<GeometricField<scalar, patchType, meshType>>
(
select,
objects,
suffix
);
addToSelection<GeometricField<vector, patchType, meshType>>
(
select,
objects,
suffix
);
addToSelection<GeometricField<sphericalTensor, patchType, meshType>>
(
select,
objects,
suffix
);
addToSelection<GeometricField<symmTensor, patchType, meshType>>
(
select,
objects,
suffix
);
addToSelection<GeometricField<tensor, patchType, meshType>>
(
select,
objects,
suffix
);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
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<class Type>
void Foam::vtkPVFoam::convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
)
{
const label nComp = pTraits<Type>::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<nComp; ++d)
{
vec[d] = component(t, d);
}
}
else
{
const Type& t = tf[faceOwner[faceNo]];
for (direction d=0; d<nComp; ++d)
{
vec[d] = component(t, d);
}
}
vtkOpenFOAMTupleRemap<Type>(vec);
cellData->InsertTuple(facei, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, range, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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<< "<end> 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<< "<beg> Foam::vtkPVFoam::convertPointFields" << nl
<< "converting OpenFOAM volume fields -> point fields" << endl;
forAllConstIter(IOobjectList, objects, iter)
{
Info<< " " << iter()->name()
<< " == " << iter()->objectPath() << nl;
}
printMemory();
}
convertSurfaceFields<scalar>(mesh, objects, output);
convertSurfaceFields<vector>(mesh, objects, output);
convertSurfaceFields<sphericalTensor>(mesh, objects, output);
convertSurfaceFields<symmTensor>(mesh, objects, output);
convertSurfaceFields<tensor>(mesh, objects, output);
// Construct interpolation on the raw mesh
const pointMesh& pMesh = pointMesh::New(mesh);
convertPointFields<scalar>
(
mesh, pMesh, objects, output
);
convertPointFields<vector>
(
mesh, pMesh, objects, output
);
convertPointFields<sphericalTensor>
(
mesh, pMesh, objects, output
);
convertPointFields<symmTensor>
(
mesh, pMesh, objects, output
);
convertPointFields<tensor>
(
mesh, pMesh, objects, output
);
convertPointFields<scalar>(mesh, pMesh, objects, output);
convertPointFields<vector>(mesh, pMesh, objects, output);
convertPointFields<sphericalTensor>(mesh, pMesh, objects, output);
convertPointFields<symmTensor>(mesh, pMesh, objects, output);
convertPointFields<tensor>(mesh, pMesh, objects, output);
if (debug)
{
Info<< "<end> Foam::vtkPVFoam::convertPointFields" << endl;
Info<< "<end> Foam::vtkPVFoam::convertVolFields" << endl;
printMemory();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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<class Type>
void Foam::vtkPVFoam::convertSurfaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
)
{
const label nComp = pTraits<Type>::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<nComp; ++d)
{
vec[d] = component(t, d);
}
}
else
{
const Type& t = tf[faceOwner[faceNo]];
for (direction d=0; d<nComp; ++d)
{
vec[d] = component(t, d);
}
}
vtkOpenFOAMTupleRemap<Type>(vec);
cellData->InsertTuple(facei, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, range, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
template<class Type>
void Foam::vtkPVFoam::convertSurfaceField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& tf,
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
)
{
const label nComp = pTraits<Type>::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<Type> flatFld(mesh.nFaces(), Zero);
SubField<Type>(flatFld, nInternalFaces) = tf.internalField();
forAll(tf.boundaryField(), patchi)
{
const fvsPatchField<Type>& fvs = tf.boundaryField()[patchi];
SubField<Type>
(
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<nComp; ++d)
{
vec[d] = component(flatFld[faceNo], d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
cellData->InsertTuple(facei, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, range, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
template<class Type>
void Foam::vtkPVFoam::convertSurfaceFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
)
{
forAllConstIter(IOobjectList, objects, iter)
{
// Restrict to GeometricField<Type, ...>
if
(
iter()->headerClassName()
!= GeometricField<Type, fvsPatchField, surfaceMesh>::typeName
)
{
continue;
}
// Load field
const GeometricField<Type, fvsPatchField, surfaceMesh> 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<Type>& ptf = tf.boundaryField()[patchId];
if (!isType<emptyFvsPatchField<Type>>(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
// ************************************************************************* //

View File

@ -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<labelList, word> 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<< "<beg> 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<fvPatchField, volMesh>
(
fieldSelection,
runTime,
times,
regionPrefix
);
addToSelection<fvsPatchField, surfaceMesh>
(
fieldSelection,
runTime,
times,
regionPrefix
);
addToSelection<pointPatchField, pointMesh>
(
fieldSelection,
runTime,
times,
regionPrefix
);
// Restore the enabled selections
setSelectedArrayEntries(fieldSelection, enabledEntries);
if (debug)
{
Info<< "<end> Foam::vtkPVFoam::updateInfoFields" << endl;
}
}
void Foam::vtkPVFoam::updateInfoLagrangianFields()
{
if (debug)

View File

@ -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 <http://www.gnu.org/licenses/>.
InClass
vtkPVFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkPVFoamUpdateInfoFields_H
#define vtkPVFoamUpdateInfoFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<template<class> class patchType, class meshType>
void Foam::vtkPVFoam::updateInfoFields
(
vtkDataArraySelection* select
)
{
if (debug)
{
Info<< "<beg> 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<GeometricField<scalar, patchType, meshType>>
(
select,
objects
);
addToSelection<GeometricField<vector, patchType, meshType>>
(
select,
objects
);
addToSelection<GeometricField<sphericalTensor, patchType, meshType>>
(
select,
objects
);
addToSelection<GeometricField<symmTensor, patchType, meshType>>
(
select,
objects
);
addToSelection<GeometricField<tensor, patchType, meshType>>
(
select,
objects
);
}
// Restore the enabled selections
setSelectedArrayEntries(select, enabledEntries);
if (debug)
{
Info<< "<end> Foam::vtkPVFoam::updateInfoFields" << endl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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

View File

@ -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
}
}
}