diff --git a/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFieldTemplates.C b/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFieldTemplates.C index 6b2f6adad1a5c17b349dd4da165feb08520b7bb9..b04583d7e2e18cffdd7104e42c87d5de0a255ccb 100644 --- a/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFieldTemplates.C +++ b/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFieldTemplates.C @@ -43,16 +43,15 @@ void Foam::vtk::faMeshAdaptor::convertAreaFields const wordRes& selectFields ) { - typedef GeometricField FieldType; + const auto& obr = mesh_.mesh(); - // Restrict to GeometricField - const wordList names(mesh_.mesh().sortedNames(selectFields)); + typedef GeometricField fieldType; - for (const word& fieldName : names) + for (const word& fieldName : obr.sortedNames(selectFields)) { convertAreaField ( - mesh_.mesh().lookupObject(fieldName) + obr.lookupObject(fieldName) ); } } @@ -97,37 +96,8 @@ Foam::vtk::faMeshAdaptor::convertAreaFieldToVTK const foamVtpData& vtpData ) const { - const int nComp(pTraits::nComponents); - - auto data = vtkSmartPointer::New(); - data->SetName(fld.name().c_str()); - data->SetNumberOfComponents(nComp); - data->SetNumberOfTuples(fld.size()); - - const label len = fld.size(); - - if (debug) - { - Info<< "convert areaField: " - << fld.name() - << " size=" << len - << " nComp=" << nComp << endl; - } - - float scratch[nComp]; - for (label i=0; i < len; ++i) - { - const Type& t = fld[i]; - for (direction d=0; d(scratch); - - data->SetTuple(i, scratch); - } - - return data; + // The vtpData is not used for anything + return vtk::Tools::convertFieldToVTK(fld.name(), fld); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFields.C b/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFields.C index 01842369a7ead47bf7a75d8fd8dab67e387b05b3..7b301fadbd54c1634208cdcd2cc6070a23e65640 100644 --- a/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFields.C +++ b/src/catalyst/areaMesh/foamVtkFaMeshAdaptorFields.C @@ -34,28 +34,6 @@ License // Templates (only needed here) #include "foamVtkFaMeshAdaptorFieldTemplates.C" -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace Foam -{ - -template -static wordHashSet supportedTypes() -{ - // typedef DimensionedField DimFieldType; - typedef GeometricField AreaFieldType; - - wordHashSet types; - - // TODO: types.insert(DimFieldType::typeName); - types.insert(AreaFieldType::typeName); - - return types; -} - -} // End namespace Foam - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields @@ -63,30 +41,20 @@ Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields const wordRes& selectFields ) const { - wordHashSet allFields; - // Quick exit if no volume fields can be converted. // This could be refined HashTable objects = mesh_.mesh().classes(selectFields); - if (objects.empty()) - { - return allFields; - } - - wordHashSet types; - - types += supportedTypes(); - types += supportedTypes(); - types += supportedTypes(); - types += supportedTypes(); - types += supportedTypes(); - - objects.retain(types); + wordHashSet allFields(2*objects.size()); forAllConstIters(objects, iter) { - allFields += iter.object(); + const word& clsName = iter.key(); + + if (fieldTypes::area.found(clsName)) + { + allFields += iter.object(); + } } return allFields; diff --git a/src/catalyst/areaMesh/foamVtkFaMeshAdaptorGeom.C b/src/catalyst/areaMesh/foamVtkFaMeshAdaptorGeom.C index 29d34ab02adc542f072d48aa9bb8d757509dc817..2ccf0e0303cf65c7041cce89459870bd344aaf5a 100644 --- a/src/catalyst/areaMesh/foamVtkFaMeshAdaptorGeom.C +++ b/src/catalyst/areaMesh/foamVtkFaMeshAdaptorGeom.C @@ -40,19 +40,16 @@ void Foam::vtk::faMeshAdaptor::convertGeometryInternal() if (meshState_ == polyMesh::UNCHANGED) { // Without movement is easy. - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo + << "reuse " << longName << nl; + vtpData.reuse(); return; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo + << "move points " << longName << nl; vtkgeom = vtpData.getCopy(); vtkgeom->SetPoints @@ -64,10 +61,8 @@ void Foam::vtk::faMeshAdaptor::convertGeometryInternal() if (!vtkgeom) { - if (debug) - { - Info<< "Nothing usable from cache - create new geometry" << nl; - } + DebugInfo + << "Nothing usable from cache - create new geometry" << nl; vtkgeom = vtk::Tools::Patch::mesh(mesh_.patch()); } diff --git a/src/catalyst/cloud/foamVtkCloudAdaptorTemplates.C b/src/catalyst/cloud/foamVtkCloudAdaptorTemplates.C index d2f657c7de2a5e7106e1c445168b7ba6878d9777..ee8715ae91ac455ba2c30897eeefcf23c1c6ff8d 100644 --- a/src/catalyst/cloud/foamVtkCloudAdaptorTemplates.C +++ b/src/catalyst/cloud/foamVtkCloudAdaptorTemplates.C @@ -37,25 +37,28 @@ Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields const objectRegistry& obr ) { - const wordList fieldNames(obr.sortedNames>()); + typedef IOField fieldType; - for (const word& fieldName : fieldNames) + label nFields = 0; + + for (const word& fieldName : obr.sortedNames()) { - const auto& fld = obr.lookupObject>(fieldName); + const auto& fld = obr.lookupObject(fieldName); - vtkSmartPointer data = - vtk::Tools::convertFieldToVTK - ( - fieldName, - fld - ); + vtkSmartPointer data = vtk::Tools::convertFieldToVTK + ( + fld.name(), + fld + ); // Provide identical data as cell and as point data vtkmesh->GetCellData()->AddArray(data); vtkmesh->GetPointData()->AddArray(data); + + ++nFields; } - return fieldNames.size(); + return nFields; } diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H b/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H index b00e944f49b27c4a807b66a73c639644c15fb311..eef12f1b4657af9a4836f84f63fa2e4c0eccfe86 100644 --- a/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H +++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H @@ -141,7 +141,6 @@ private: public vtk::Caching, public foamVtkMeshMaps { - //- The vtk points for the mesh (and decomposition) vtkSmartPointer points ( diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptorFieldTemplates.C b/src/catalyst/volMesh/foamVtkFvMeshAdaptorFieldTemplates.C index 31b74a2a00718ce6fe65232ae475019eb0994a53..b3125dd5741cb78daf59e41d1ef73aec96b97cc9 100644 --- a/src/catalyst/volMesh/foamVtkFvMeshAdaptorFieldTemplates.C +++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptorFieldTemplates.C @@ -173,17 +173,20 @@ void Foam::vtk::fvMeshAdaptor::convertVolFields const wordRes& selectFields ) { - typedef GeometricField FieldType; + typedef GeometricField fieldType; // Restrict to GeometricField - const wordList names(mesh_.sortedNames(selectFields)); - for (const word& fieldName : names) + for + ( + const word& fieldName + : mesh_.sortedNames(selectFields) + ) { convertVolField ( patchInterpList, - mesh_.lookupObject(fieldName) + mesh_.lookupObject(fieldName) ); } } @@ -274,75 +277,50 @@ vtkSmartPointer Foam::vtk::fvMeshAdaptor::convertPointField data->SetName(pfld.name().c_str()); } - if (debug) - { - Info<< "convert Point field: " - << pfld.name() - << " size=" << (nPoints + addPointCellLabels.size()) - << " (" << nPoints << " + " << addPointCellLabels.size() - << ") nComp=" << nComp << endl; - } + DebugInfo + << "convert Point field: " << pfld.name() + << " size=" << (nPoints + addPointCellLabels.size()) + << " (" << nPoints << " + " << addPointCellLabels.size() + << ") nComp=" << nComp << endl; - float vec[pTraits::nComponents]; - label pointi = 0; + float scratch[pTraits::nComponents]; + + vtkIdType pointi = 0; if (pointMap.size()) { - forAll(pointMap, i) + for (const label meshPointi : pointMap) { - const Type& t = pfld[pointMap[i]]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + foamToVtkTuple(scratch, pfld[meshPointi]); + data->SetTuple(pointi++, scratch); } } else { - forAll(pfld, i) + for (const Type& val : pfld) { - const Type& t = pfld[i]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + foamToVtkTuple(scratch, val); + data->SetTuple(pointi++, scratch); } } // Continue with additional points + // - correspond to cell centres if (notNull(vfld)) { - forAll(addPointCellLabels, apI) + for (const label meshCelli : addPointCellLabels) { - const Type& t = vfld[addPointCellLabels[apI]]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + foamToVtkTuple(scratch, vfld[meshCelli]); + data->SetTuple(pointi++, scratch); } } else { - forAll(addPointCellLabels, apI) + for (const label meshCelli : addPointCellLabels) { - Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]); - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + foamToVtkTuple(scratch, interpolatePointToCell(pfld, meshCelli)); + data->SetTuple(pointi++, scratch); } } @@ -371,27 +349,21 @@ Foam::vtk::fvMeshAdaptor::convertVolFieldToVTK data->SetNumberOfComponents(nComp); data->SetNumberOfTuples(cellMap.size()); - if (debug) - { - Info<< "convert volField: " - << fld.name() - << " size=" << cellMap.size() - << " (" << fld.size() << " + " - << (cellMap.size() - fld.size()) - << ") nComp=" << nComp << endl; - } + DebugInfo + << "convert volField: " << fld.name() + << " size=" << cellMap.size() + << " (" << fld.size() << " + " + << (cellMap.size() - fld.size()) + << ") nComp=" << nComp << endl; - float scratch[nComp]; - forAll(cellMap, i) - { - const Type& t = fld[cellMap[i]]; - for (direction d=0; d(scratch); - data->SetTuple(i, scratch); + float scratch[pTraits::nComponents]; + + vtkIdType celli = 0; + for (const label meshCelli : cellMap) + { + foamToVtkTuple(scratch, fld[meshCelli]); + data->SetTuple(celli++, scratch); } return data; diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptorFields.C b/src/catalyst/volMesh/foamVtkFvMeshAdaptorFields.C index 33f293f1f3913a55d63f613b2a417ed2cbe74cb8..a527dd58847f5775027b8dcb2b635fc8267a43ff 100644 --- a/src/catalyst/volMesh/foamVtkFvMeshAdaptorFields.C +++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptorFields.C @@ -34,55 +34,30 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -namespace Foam -{ - -template -static wordHashSet supportedTypes() -{ - // typedef DimensionedField DimFieldType; - typedef GeometricField VolFieldType; - - wordHashSet types; - - // TODO: types.insert(DimFieldType::typeName); - types.insert(VolFieldType::typeName); - - return types; -} - -} // End namespace Foam - - Foam::wordHashSet Foam::vtk::fvMeshAdaptor::knownFields ( const wordRes& selectFields ) const { - wordHashSet allFields; - // Quick exit if no volume fields can be converted. // This could be refined HashTable objects = mesh_.classes(selectFields); - if (objects.empty()) - { - return allFields; - } - - wordHashSet types; - - types += supportedTypes(); - types += supportedTypes(); - types += supportedTypes(); - types += supportedTypes(); - types += supportedTypes(); - - objects.retain(types); + wordHashSet allFields(2*objects.size()); forAllConstIters(objects, iter) { - allFields += iter.object(); + const word& clsName = iter.key(); + + if + ( + fieldTypes::volume.found(clsName) + // TODO + // || fieldTypes::internal.found(clsName) + ) + { + allFields += iter.object(); + } } return allFields; diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C b/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C index 1ab3c860b2f5ad5d37ad29b33027c961ca6129fb..87f74b1df3b3993fb648a18ca6bbdcca2febc04f 100644 --- a/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C +++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C @@ -52,19 +52,17 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryInternal() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo + << "reuse " << longName << nl; + vtuData.reuse(); // No movement - simply reuse return; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo + << "move points " << longName << nl; + vtkgeom = vtuData.getCopy(); vtkgeom->SetPoints(vtuData.points(mesh_)); } @@ -72,10 +70,8 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryInternal() if (!vtkgeom) { - if (debug) - { - Info<< "Nothing usable from cache - create new geometry" << nl; - } + DebugInfo + << "Nothing usable from cache - create new geometry" << nl; // Nothing usable from cache - create new geometry vtkgeom = vtuData.internal(mesh_, decomposePoly_); @@ -103,20 +99,18 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryBoundary() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo + << "reuse " << longName << nl; + vtpData.reuse(); // No movement - simply reuse continue; } else if (meshState_ == polyMesh::POINTS_MOVED) { // Point movement on single patch - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo + << "move points " << longName << nl; + vtkgeom = vtpData.getCopy(); vtkgeom->SetPoints(vtk::Tools::Patch::points(pp)); } @@ -124,11 +118,9 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryBoundary() vtpData.clear(); // Remove any old mappings - if (debug) - { - Info<< "Creating VTK mesh for patch [" << patchId <<"] " - << longName << endl; - } + DebugInfo + << "Creating VTK mesh for patch [" << patchId <<"] " + << longName << endl; // Unused information vtpData.additionalIds().clear(); diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeomVtu.C b/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeomVtu.C index d1c735a281435ce8d8a0ecec65156825d01f78b5..6797a8411aab569bdb9e47f3632e8c741770e0f5 100644 --- a/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeomVtu.C +++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeomVtu.C @@ -48,23 +48,21 @@ Foam::vtk::fvMeshAdaptor::foamVtuData::points const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = this->additionalIds(); + const labelUList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size()); // Normal points - label pointId = 0; + vtkIdType pointId = 0; for (const point& p : pts) { - vtkpoints->SetPoint(pointId, p.v_); - ++pointId; + vtkpoints->SetPoint(pointId++, p.v_); } // Cell centres - for (const label ptId : addPoints) + for (const label meshCelli : addPoints) { - vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); } return vtkpoints; @@ -85,23 +83,21 @@ Foam::vtk::fvMeshAdaptor::foamVtuData::points const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = this->additionalIds(); + const labelUList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size()); // Normal points - label pointId = 0; - for (const label ptId : pointMap) + vtkIdType pointId = 0; + for (const label meshPointi : pointMap) { - vtkpoints->SetPoint(pointId, pts[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, pts[meshPointi].v_); } // Cell centres - for (const label ptId : addPoints) + for (const label meshCelli : addPoints) { - vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); } return vtkpoints;