Commit 2b47e9fa authored by mattijs's avatar mattijs
Browse files

ENH: GeometricField: support patch groups

parent f6857b20
......@@ -87,8 +87,6 @@ void Foam::vtkPV3Foam::reduceMemory()
}
int Foam::vtkPV3Foam::setTime(int nRequest, const double requestTimes[])
{
Time& runTime = dbPtr_();
......@@ -214,6 +212,7 @@ void Foam::vtkPV3Foam::updateMeshPartsStatus()
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkPV3Foam::vtkPV3Foam
......@@ -378,7 +377,7 @@ void Foam::vtkPV3Foam::updateInfo()
// Update mesh parts list - add Lagrangian at the bottom
updateInfoInternalMesh(partSelection);
updateInfoPatches(partSelection);
updateInfoPatches(partSelection, enabledEntries);
updateInfoSets(partSelection);
updateInfoZones(partSelection);
updateInfoLagrangian(partSelection);
......
......@@ -347,7 +347,7 @@ class vtkPV3Foam
void updateInfoLagrangian(vtkDataArraySelection*);
//- Patch info
void updateInfoPatches(vtkDataArraySelection*);
void updateInfoPatches(vtkDataArraySelection*, stringList&);
//- Set info
void updateInfoSets(vtkDataArraySelection*);
......@@ -554,18 +554,6 @@ class vtkPV3Foam
const labelList& faceLabels
);
//- face set/zone field
template<class Type>
void convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const arrayRange&,
const label datasetNo,
const fvMesh&,
const faceSet&
);
//- Lagrangian fields - all types
template<class Type>
void convertLagrangianFields
......
......@@ -110,79 +110,6 @@ void Foam::vtkPV3Foam::convertFaceField
}
template<class Type>
void Foam::vtkPV3Foam::convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo,
const fvMesh& mesh,
const faceSet& fSet
)
{
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(fSet.size());
cellData->SetNumberOfComponents(nComp);
cellData->Allocate(nComp*fSet.size());
cellData->SetName(tf.name().c_str());
if (debug)
{
Info<< "convert convertFaceField: "
<< tf.name()
<< " size = " << tf.size()
<< " nComp=" << nComp
<< " nTuples = " << fSet.size() << endl;
}
float vec[nComp];
// for interior faces: average owner/neighbour
// for boundary faces: owner
label faceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
const label faceNo = iter.key();
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);
++faceI;
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, range, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
......
......@@ -221,7 +221,8 @@ void Foam::vtkPV3Foam::updateInfoLagrangian
void Foam::vtkPV3Foam::updateInfoPatches
(
vtkDataArraySelection* arraySelection
vtkDataArraySelection* arraySelection,
stringList& enabledEntries
)
{
if (debug)
......@@ -230,12 +231,63 @@ void Foam::vtkPV3Foam::updateInfoPatches
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
}
HashSet<string> enabledEntriesSet(enabledEntries);
arrayRangePatches_.reset(arraySelection->GetNumberOfArrays());
int nPatches = 0;
if (meshPtr_)
{
const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
const HashTable<labelList, word>& groups = patches.groupPatchIDs();
const wordList allPatchNames = patches.names();
// Add patch groups
// ~~~~~~~~~~~~~~~~
for
(
HashTable<labelList, word>::const_iterator iter = groups.begin();
iter != groups.end();
++iter
)
{
const word& groupName = iter.key();
const labelList& patchIDs = iter();
label nFaces = 0;
forAll(patchIDs, i)
{
nFaces += patches[patchIDs[i]].size();
}
// Valid patch if nFace > 0 - add patch to GUI list
if (nFaces)
{
string vtkGrpName = groupName + " - group";
arraySelection->AddArray(vtkGrpName.c_str());
++nPatches;
if (enabledEntriesSet.found(vtkGrpName))
{
forAll(patchIDs, i)
{
const polyPatch& pp = patches[patchIDs[i]];
string vtkPatchName = pp.name() + " - patch";
enabledEntriesSet.insert(vtkPatchName);
}
enabledEntriesSet.erase(vtkGrpName);
}
}
}
// Add patches
// ~~~~~~~~~~~
forAll(patches, patchI)
{
const polyPatch& pp = patches[patchI];
......@@ -277,20 +329,101 @@ void Foam::vtkPV3Foam::updateInfoPatches
{
polyBoundaryMeshEntries patchEntries(ioObj);
// Add (non-zero) patches to the list of mesh parts
forAll(patchEntries, entryI)
// Read patches and determine sizes
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wordList names(patchEntries.size());
labelList sizes(patchEntries.size());
forAll(patchEntries, patchI)
{
label nFaces
(
readLabel(patchEntries[entryI].dict().lookup("nFaces"))
);
const dictionary& patchDict = patchEntries[patchI].dict();
sizes[patchI] = readLabel(patchDict.lookup("nFaces"));
names[patchI] = patchEntries[patchI].keyword();
}
// Add (non-zero) patch groups to the list of mesh parts
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HashTable<labelList, word> groups(patchEntries.size());
forAll(patchEntries, patchI)
{
const dictionary& patchDict = patchEntries[patchI].dict();
wordList groupNames;
patchDict.readIfPresent("inGroups", groupNames);
forAll(groupNames, groupI)
{
HashTable<labelList, word>::iterator iter = groups.find
(
groupNames[groupI]
);
if (iter != groups.end())
{
iter().append(patchI);
}
else
{
groups.insert(groupNames[groupI], labelList(1, patchI));
}
}
}
for
(
HashTable<labelList, word>::const_iterator iter =
groups.begin();
iter != groups.end();
++iter
)
{
const word& groupName = iter.key();
const labelList& patchIDs = iter();
label nFaces = 0;
forAll(patchIDs, i)
{
nFaces += sizes[patchIDs[i]];
}
// Valid patch if nFace > 0 - add patch to GUI list
if (nFaces)
{
string vtkGrpName = groupName + " - group";
arraySelection->AddArray(vtkGrpName.c_str());
++nPatches;
if (enabledEntriesSet.found(vtkGrpName))
{
forAll(patchIDs, i)
{
string vtkPatchName =
names[patchIDs[i]] + " - patch";
enabledEntriesSet.insert(vtkPatchName);
}
enabledEntriesSet.erase(vtkGrpName);
}
}
}
// Add (non-zero) patches to the list of mesh parts
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forAll(names, patchI)
{
// Valid patch if nFace > 0 - add patch to GUI list
if (sizes[patchI])
{
arraySelection->AddArray
(
(patchEntries[entryI].keyword() + " - patch").c_str()
(names[patchI] + " - patch").c_str()
);
++nPatches;
......@@ -300,6 +433,9 @@ void Foam::vtkPV3Foam::updateInfoPatches
}
arrayRangePatches_ += nPatches;
// Update enabled entries in case of group selection
enabledEntries = enabledEntriesSet.toc();
if (debug)
{
// just for debug info
......
......@@ -271,7 +271,7 @@ void Foam::vtkPV3Foam::convertVolFields
arrayRangeFaceSets_,
datasetNo,
mesh,
fSet
fSet.toc()
);
// TODO: points
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment