static void FindMapsInDir(struct block *block,char *dir) { struct dirent *ent; DIR *d; int len; char *pt, *pt2; if ( dir==NULL ) return; /* format of cidmap filename "?*-?*-[0-9]*.cidmap" */ d = opendir(dir); if ( d==NULL ) return; while ( (ent = readdir(d))!=NULL ) { if ( (len = strlen(ent->d_name))<8 ) continue; if ( strcmp(ent->d_name+len-7,".cidmap")!=0 ) continue; pt = strchr(ent->d_name, '-'); if ( pt==NULL || pt==ent->d_name ) continue; pt2 = strchr(pt+1, '-' ); if ( pt2==NULL || pt2==pt+1 || !isdigit(pt2[1])) continue; AddToBlock(block,ent->d_name,dir); } closedir(d); }
void Foam::vtkPV3Foam::convertMeshVolume ( vtkMultiBlockDataSet* output, int& blockNo ) { partInfo& selector = partInfoVolume_; selector.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; // resize for decomposed polyhedra regionPolyDecomp_.setSize(selector.size()); if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshVolume" << endl; printMemory(); } // Convert the internalMesh // this looks like more than one part, but it isn't for (int partId = selector.start(); partId < selector.end(); ++partId) { const word partName = "internalMesh"; if (!partStatus_[partId]) { continue; } vtkUnstructuredGrid* vtkmesh = volumeVTKMesh ( mesh, regionPolyDecomp_[datasetNo] ); if (vtkmesh) { AddToBlock(output, vtkmesh, selector, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshVolume" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshPatches ( vtkMultiBlockDataSet* output, int& blockNo ) { partInfo& selector = partInfoPatches_; selector.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; const polyBoundaryMesh& patches = mesh.boundaryMesh(); if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshPatches" << endl; printMemory(); } for (int partId = selector.start(); partId < selector.end(); ++partId) { const word patchName = getPartName(partId); const label patchId = patches.findPatchID(patchName); if (!partStatus_[partId] || patchId < 0) { continue; } if (debug) { Info<< "Creating VTK mesh for patch[" << patchId <<"] " << patchName << endl; } vtkPolyData* vtkmesh = patchVTKMesh(patches[patchId]); if (vtkmesh) { AddToBlock(output, vtkmesh, selector, datasetNo, patchName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshPatches" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshPointSets ( vtkMultiBlockDataSet* output, int& blockNo ) { partInfo& selector = partInfoPointSets_; selector.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl; printMemory(); } for (int partId = selector.start(); partId < selector.end(); ++partId) { word partName = getPartName(partId); if (!partStatus_[partId]) { continue; } if (debug) { Info<< "Creating VTK mesh for pointSet=" << partName << endl; } const pointSet pSet(mesh, partName); vtkPolyData* vtkmesh = pointSetVTKMesh(mesh, pSet); if (vtkmesh) { AddToBlock(output, vtkmesh, selector, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshPointSets" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshFaceSets ( vtkMultiBlockDataSet* output, int& blockNo ) { arrayRange& range = arrayRangeFaceSets_; range.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceSets" << endl; printMemory(); } for (int partId = range.start(); partId < range.end(); ++partId) { const word partName = getPartName(partId); if (!partStatus_[partId]) { continue; } if (debug) { Info<< "Creating VTK mesh for faceSet=" << partName << endl; } const faceSet fSet(mesh, partName); vtkPolyData* vtkmesh = faceSetVTKMesh(mesh, fSet); if (vtkmesh) { AddToBlock(output, vtkmesh, range, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceSets" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshPointZones ( vtkMultiBlockDataSet* output, int& blockNo ) { partInfo& selector = partInfoPointZones_; selector.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl; printMemory(); } if (selector.size()) { const pointZoneMesh& zMesh = mesh.pointZones(); for (int partId = selector.start(); partId < selector.end(); ++partId) { word zoneName = getPartName(partId); label zoneId = zMesh.findZoneID(zoneName); if (!partStatus_[partId] || zoneId < 0) { continue; } vtkPolyData* vtkmesh = pointZoneVTKMesh(mesh, zMesh[zoneId]); if (vtkmesh) { AddToBlock(output, vtkmesh, selector, datasetNo, zoneName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshPointZones" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshVolume ( vtkMultiBlockDataSet* output ) { if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshVolume" << endl; printMemory(); } const selectionInfo& selector = selectInfoVolume_; const fvMesh& mesh = *meshPtr_; // Create the internal mesh and add as dataset 0 for ( int regionId = selector.start(); regionId < selector.end(); ++regionId ) { if (!selectedRegions_[regionId]) { continue; } // word selectName = getFirstWord // ( // arraySelection->GetArrayName(regionId) // ); if (debug) { Info<< "Creating VTK internalMesh" << endl; } const label datasetId = 0; vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); addVolumeMesh(mesh, vtkmesh, superCells_); AddToBlock(output, selector, datasetId, vtkmesh, "internalMesh"); selectedRegionDatasetIds_[regionId] = datasetId; vtkmesh->Delete(); } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshVolume" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshLagrangian ( vtkMultiBlockDataSet* output, int& blockNo ) { partInfo& selector = partInfoLagrangian_; selector.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshLagrangian" << endl; printMemory(); } for (int partId = selector.start(); partId < selector.end(); ++partId) { const word cloudName = getPartName(partId); if (!partStatus_[partId]) { continue; } vtkPolyData* vtkmesh = lagrangianVTKMesh(mesh, cloudName); if (vtkmesh) { AddToBlock(output, vtkmesh, selector, datasetNo, cloudName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshLagrangian" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshLagrangian ( vtkMultiBlockDataSet* output ) { if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshLagrangian" << endl; printMemory(); } const selectionInfo& selector = selectInfoLagrangian_; const fvMesh& mesh = *meshPtr_; // Create the Lagrangian mesh and add as dataset 0 for ( int regionId = selector.start(); regionId < selector.end(); ++regionId ) { if (!selectedRegions_[regionId]) { continue; } if (debug) { Info<< "Creating VTK Lagrangian mesh" << endl; } const label datasetId = 0; vtkPolyData* vtkmesh = vtkPolyData::New(); addLagrangianMesh(mesh, vtkmesh); AddToBlock(output, selector, datasetId, vtkmesh, cloudName_); selectedRegionDatasetIds_[regionId] = datasetId; vtkmesh->Delete(); } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshLagrangian" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshCellSets ( vtkMultiBlockDataSet* output ) { if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl; printMemory(); } const selectionInfo& selector = selectInfoCellSets_; vtkDataArraySelection* arraySelection = reader_->GetRegionSelection(); // Create the cell sets and add as dataset if (selector.size()) { const fvMesh& mesh = *meshPtr_; for ( int regionId = selector.start(); regionId < selector.end(); ++regionId) { if (!selectedRegions_[regionId]) { continue; } word selectName = getFirstWord ( arraySelection->GetArrayName(regionId) ); if (debug) { Info<< "Creating VTK mesh for cellSet: " << selectName << " region index: " << regionId << endl; } const cellSet cSet(mesh, selectName); fvMeshSubset subsetter ( IOobject ( "set", mesh.time().constant(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh ); subsetter.setLargeCellSubset(cSet); const label datasetId = GetNumberOfDataSets(output, selector); vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); addVolumeMesh ( subsetter.subMesh(), vtkmesh, csetSuperCells_[datasetId] ); // renumber - superCells must contain global cell ids inplaceRenumber ( subsetter.cellMap(), csetSuperCells_[datasetId] ); AddToBlock ( output, selector, datasetId, vtkmesh, selectName + ":cellSet" ); selectedRegionDatasetIds_[regionId] = datasetId; vtkmesh->Delete(); } } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshCellSets" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshCellSets ( vtkMultiBlockDataSet* output, int& blockNo ) { partInfo& selector = partInfoCellSets_; selector.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; // resize for decomposed polyhedra csetPolyDecomp_.setSize(selector.size()); if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl; printMemory(); } for (int partId = selector.start(); partId < selector.end(); ++partId) { const word partName = getPartName(partId); if (!partStatus_[partId]) { continue; } if (debug) { Info<< "Creating VTK mesh for cellSet=" << partName << endl; } const cellSet cSet(mesh, partName); fvMeshSubset subsetMesh ( IOobject ( "set", mesh.time().constant(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh ); subsetMesh.setLargeCellSubset(cSet); vtkUnstructuredGrid* vtkmesh = volumeVTKMesh ( subsetMesh.subMesh(), csetPolyDecomp_[datasetNo] ); if (vtkmesh) { // superCells + addPointCellLabels must contain global cell ids inplaceRenumber ( subsetMesh.cellMap(), csetPolyDecomp_[datasetNo].superCells() ); inplaceRenumber ( subsetMesh.cellMap(), csetPolyDecomp_[datasetNo].addPointCellLabels() ); // copy pointMap as well, otherwise pointFields fail csetPolyDecomp_[datasetNo].pointMap() = subsetMesh.pointMap(); AddToBlock(output, vtkmesh, selector, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshCellSets" << endl; printMemory(); } }
// This transaction selection algorithm orders the mempool based // on feerate of a transaction including all unconfirmed ancestors. // Since we don't remove transactions from the mempool as we select them // for block inclusion, we need an alternate method of updating the feerate // of a transaction with its not-yet-selected ancestors as we go. // This is accomplished by walking the in-mempool descendants of selected // transactions and storing a temporary modified state in mapModifiedTxs. // Each time through the loop, we compare the best transaction in // mapModifiedTxs with the next transaction in the mempool to decide what // transaction package to work on next. void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated) { // mapModifiedTx will store sorted packages after they are modified // because some of their txs are already in the block indexed_modified_transaction_set mapModifiedTx; // Keep track of entries that failed inclusion, to avoid duplicate work CTxMemPool::setEntries failedTx; // Start by adding all descendants of previously added txs to mapModifiedTx // and modifying them for their already included ancestors UpdatePackagesForAdded(inBlock, mapModifiedTx); CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin(); CTxMemPool::txiter iter; // Limit the number of attempts to add transactions to the block when it is // close to full; this is just a simple heuristic to finish quickly if the // mempool has a lot of entries. const int64_t MAX_CONSECUTIVE_FAILURES = 1000; int64_t nConsecutiveFailed = 0; while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty()) { // First try to find a new transaction in mapTx to evaluate. if (mi != mempool.mapTx.get<ancestor_score>().end() && SkipMapTxEntry(mempool.mapTx.project<0>(mi), mapModifiedTx, failedTx)) { ++mi; continue; } // Now that mi is not stale, determine which transaction to evaluate: // the next entry from mapTx, or the best from mapModifiedTx? bool fUsingModified = false; modtxscoreiter modit = mapModifiedTx.get<ancestor_score>().begin(); if (mi == mempool.mapTx.get<ancestor_score>().end()) { // We're out of entries in mapTx; use the entry from mapModifiedTx iter = modit->iter; fUsingModified = true; } else { // Try to compare the mapTx entry to the mapModifiedTx entry iter = mempool.mapTx.project<0>(mi); if (modit != mapModifiedTx.get<ancestor_score>().end() && CompareModifiedEntry()(*modit, CTxMemPoolModifiedEntry(iter))) { // The best entry in mapModifiedTx has higher score // than the one from mapTx. // Switch which transaction (package) to consider iter = modit->iter; fUsingModified = true; } else { // Either no entry in mapModifiedTx, or it's worse than mapTx. // Increment mi for the next loop iteration. ++mi; } } // We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't // contain anything that is inBlock. assert(!inBlock.count(iter)); uint64_t packageSize = iter->GetSizeWithAncestors(); CAmount packageFees = iter->GetModFeesWithAncestors(); int64_t packageSigOpsCost = iter->GetSigOpCostWithAncestors(); if (fUsingModified) { packageSize = modit->nSizeWithAncestors; packageFees = modit->nModFeesWithAncestors; packageSigOpsCost = modit->nSigOpCostWithAncestors; } if (packageFees < blockMinFeeRate.GetFee(packageSize)) { // Everything else we might consider has a lower fee rate return; } if (!TestPackage(packageSize, packageSigOpsCost)) { if (fUsingModified) { // Since we always look at the best entry in mapModifiedTx, // we must erase failed entries so that we can consider the // next best entry on the next loop iteration mapModifiedTx.get<ancestor_score>().erase(modit); failedTx.insert(iter); } ++nConsecutiveFailed; if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight > nBlockMaxWeight - 4000) { // Give up if we're close to full and haven't succeeded in a while break; } continue; } CTxMemPool::setEntries ancestors; uint64_t nNoLimit = std::numeric_limits<uint64_t>::max(); std::string dummy; mempool.CalculateMemPoolAncestors(*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false); onlyUnconfirmed(ancestors); ancestors.insert(iter); // Test if all tx's are Final if (!TestPackageTransactions(ancestors)) { if (fUsingModified) { mapModifiedTx.get<ancestor_score>().erase(modit); failedTx.insert(iter); } continue; } // This transaction will make it in; reset the failed counter. nConsecutiveFailed = 0; // Package can be added. Sort the entries in a valid order. std::vector<CTxMemPool::txiter> sortedEntries; SortForBlock(ancestors, iter, sortedEntries); for (size_t i=0; i<sortedEntries.size(); ++i) { AddToBlock(sortedEntries[i]); // Erase from the modified set, if present mapModifiedTx.erase(sortedEntries[i]); } ++nPackagesSelected; // Update transactions that depend on each of these nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx); } }
void Foam::vtkPVFoam::convertMeshPatches ( vtkMultiBlockDataSet* output, int& blockNo ) { arrayRange& range = arrayRangePatches_; range.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; const polyBoundaryMesh& patches = mesh.boundaryMesh(); if (debug) { Info<< "<beg> Foam::vtkPVFoam::convertMeshPatches" << endl; printMemory(); } for (int partId = range.start(); partId < range.end(); ++partId) { if (!partStatus_[partId]) { continue; } const word patchName = getPartName(partId); labelHashSet patchIds(patches.patchSet(List<wordRe>(1, wordRe(patchName)))); if (debug) { Info<< "Creating VTK mesh for patches [" << patchIds <<"] " << patchName << endl; } vtkPolyData* vtkmesh = nullptr; if (patchIds.size() == 1) { vtkmesh = patchVTKMesh(patchName, patches[patchIds.begin().key()]); } else { // Patch group. Collect patch faces. label sz = 0; forAllConstIter(labelHashSet, patchIds, iter) { sz += patches[iter.key()].size(); } labelList meshFaceLabels(sz); sz = 0; forAllConstIter(labelHashSet, patchIds, iter) { const polyPatch& pp = patches[iter.key()]; forAll(pp, i) { meshFaceLabels[sz++] = pp.start()+i; } } UIndirectList<face> fcs(mesh.faces(), meshFaceLabels); uindirectPrimitivePatch pp(fcs, mesh.points()); vtkmesh = patchVTKMesh(patchName, pp); } if (vtkmesh) { AddToBlock(output, vtkmesh, range, datasetNo, patchName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } }
struct cidmap *AskUserForCIDMap(void) { struct block block; struct cidmap *map = NULL; char buffer[200]; char **choices; int i,ret; char *filename=NULL; char *reg, *ord, *pt; int supplement; memset(&block,'\0',sizeof(block)); for ( map = cidmaps; map!=NULL; map = map->next ) { sprintf(buffer,"%s-%s-%d", map->registry, map->ordering, map->supplement); AddToBlock(&block,buffer,NULL); } FindMapsInDir(&block,"."); FindMapsInDir(&block,GResourceProgramDir); FindMapsInNoLibsDir(&block,GResourceProgramDir); FindMapsInDir(&block,getFontForgeShareDir()); FindMapsInDir(&block,"/usr/share/fontforge"); choices = gcalloc(block.cur+2,sizeof(unichar_t *)); choices[0] = copy(_("Browse...")); for ( i=0; i<block.cur; ++i ) choices[i+1] = copy(block.maps[i]); ret = gwwv_choose(_("Find a cidmap file..."),(const char **) choices,i+1,0,_("Please select a CID ordering")); for ( i=0; i<=block.cur; ++i ) free( choices[i] ); free(choices); if ( ret==0 ) { filename = gwwv_open_filename(_("Find a cidmap file..."),NULL, "?*-?*-[0-9]*.cidmap",NULL); if ( filename==NULL ) ret = -1; } if ( ret!=-1 ) { if ( filename!=NULL ) /* Do nothing for now */; else if ( block.dirs[ret-1]!=NULL ) { filename = galloc(strlen(block.dirs[ret-1])+strlen(block.maps[ret-1])+3+8); strcpy(filename,block.dirs[ret-1]); strcat(filename,"/"); strcat(filename,block.maps[ret-1]); strcat(filename,".cidmap"); } if ( ret!=0 ) reg = block.maps[ret-1]; else { reg = strrchr(filename,'/'); if ( reg==NULL ) reg = filename; else ++reg; reg = copy(reg); } pt = strchr(reg,'-'); if ( pt==NULL ) ret = -1; else { *pt = '\0'; ord = pt+1; pt = strchr(ord,'-'); if ( pt==NULL ) ret = -1; else { *pt = '\0'; supplement = strtol(pt+1,NULL,10); } } if ( ret == -1 ) /* No map */; else if ( filename==NULL ) map = FindCidMap(reg,ord,supplement,NULL); else { map = LoadMapFromFile(filename,reg,ord,supplement); free(filename); } if ( ret!=0 && reg!=block.maps[ret-1] ) free(reg); /*free(filename);*/ /* Freed by loadmap */ } for ( i=0; i<block.cur; ++i ) free( block.maps[i]); free(block.maps); free(block.dirs); return( map ); }
void Foam::vtkPV3Foam::convertMeshCellZones ( vtkMultiBlockDataSet* output ) { if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl; printMemory(); } const selectionInfo& selector = selectInfoCellZones_; const fvMesh& mesh = *meshPtr_; // Create the cell zone(s) and add as DataSet(CELLZONE, 0..n) if (selector.size()) { const cellZoneMesh& czMesh = mesh.cellZones(); // use the zoneId directly instead of the name for (int zoneI=0; zoneI < selector.size(); ++zoneI) { const int regionId = selector.start() + zoneI; if (!selectedRegions_[regionId]) { continue; } if (debug) { Info<< "Creating VTK mesh for cellZone: " << zoneI << endl; } fvMeshSubset subsetter ( IOobject ( "set", mesh.time().constant(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh ); subsetter.setLargeCellSubset(labelHashSet(czMesh[zoneI])); const label datasetId = GetNumberOfDataSets(output, selector); vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); addVolumeMesh ( subsetter.subMesh(), vtkmesh, zoneSuperCells_[datasetId] ); // renumber - superCells must contain global cell ids inplaceRenumber ( subsetter.cellMap(), zoneSuperCells_[datasetId] ); AddToBlock ( output, selector, datasetId, vtkmesh, czMesh.names()[zoneI] + ":cellZone" ); selectedRegionDatasetIds_[regionId] = datasetId; vtkmesh->Delete(); } } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshCellZones" << endl; printMemory(); } }
void Foam::vtkPVblockMesh::convertMeshBlocks ( vtkMultiBlockDataSet* output, int& blockNo ) { vtkDataArraySelection* selection = reader_->GetBlockSelection(); arrayRange& range = arrayRangeBlocks_; range.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const blockMesh& blkMesh = *meshPtr_; const Foam::pointField& blockPoints = blkMesh.vertices(); if (debug) { Info<< "<beg> Foam::vtkPVblockMesh::convertMeshBlocks" << endl; } int blockI = 0; const scalar scaleFactor = blkMesh.scaleFactor(); for ( int partId = range.start(); partId < range.end(); ++partId, ++blockI ) { if (!blockStatus_[partId]) { continue; } const blockDescriptor& blockDef = blkMesh[blockI]; vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); // Convert OpenFOAM mesh vertices to VTK vtkPoints *vtkpoints = vtkPoints::New(); vtkpoints->Allocate( blockDef.nPoints() ); const labelList& blockLabels = blockDef.blockShape(); vtkmesh->Allocate(1); vtkIdType nodeIds[8]; forAll(blockLabels, ptI) { vtkInsertNextOpenFOAMPoint ( vtkpoints, blockPoints[blockLabels[ptI]], scaleFactor ); nodeIds[ptI] = ptI; } vtkmesh->InsertNextCell ( VTK_HEXAHEDRON, 8, nodeIds ); vtkmesh->SetPoints(vtkpoints); vtkpoints->Delete(); AddToBlock ( output, vtkmesh, range, datasetNo, selection->GetArrayName(partId) ); vtkmesh->Delete(); datasetNo++; }
void Foam::vtkPV3Foam::convertMeshFaceZones ( vtkMultiBlockDataSet* output, int& blockNo ) { arrayRange& range = arrayRangeFaceZones_; range.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; if (range.empty()) { return; } if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceZones" << endl; printMemory(); } const faceZoneMesh& zMesh = mesh.faceZones(); for (int partId = range.start(); partId < range.end(); ++partId) { const word zoneName = getPartName(partId); const label zoneId = zMesh.findZoneID(zoneName); if (!partStatus_[partId] || zoneId < 0) { continue; } if (debug) { Info<< "Creating VTKmesh for faceZone[" << zoneId << "] " << zoneName << endl; } vtkPolyData* vtkmesh = faceZoneVTKMesh(mesh, zMesh[zoneId]); if (vtkmesh) { AddToBlock(output, vtkmesh, range, datasetNo, zoneName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceZones" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshCellZones ( vtkMultiBlockDataSet* output, int& blockNo ) { arrayRange& range = arrayRangeCellZones_; range.block(blockNo); // set output block label datasetNo = 0; // restart at dataset 0 const fvMesh& mesh = *meshPtr_; // resize for decomposed polyhedra zonePolyDecomp_.setSize(range.size()); if (range.empty()) { return; } if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl; printMemory(); } const cellZoneMesh& zMesh = mesh.cellZones(); for (int partId = range.start(); partId < range.end(); ++partId) { const word zoneName = getPartName(partId); const label zoneId = zMesh.findZoneID(zoneName); if (!partStatus_[partId] || zoneId < 0) { continue; } if (debug) { Info<< "Creating VTK mesh for cellZone[" << zoneId << "] " << zoneName << endl; } fvMeshSubset subsetter(mesh); subsetter.setLargeCellSubset(zMesh[zoneId]); vtkUnstructuredGrid* vtkmesh = volumeVTKMesh ( subsetter.subMesh(), zonePolyDecomp_[datasetNo] ); if (vtkmesh) { // superCells + addPointCellLabels must contain global cell ids inplaceRenumber ( subsetter.cellMap(), zonePolyDecomp_[datasetNo].superCells() ); inplaceRenumber ( subsetter.cellMap(), zonePolyDecomp_[datasetNo].addPointCellLabels() ); // copy pointMap as well, otherwise pointFields fail zonePolyDecomp_[datasetNo].pointMap() = subsetter.pointMap(); AddToBlock(output, vtkmesh, range, datasetNo, zoneName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; } } // anything added? if (datasetNo) { ++blockNo; } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshCellZones" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshPointSets ( vtkMultiBlockDataSet* output ) { if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl; printMemory(); } const selectionInfo& selector = selectInfoPointSets_; vtkDataArraySelection* arraySelection = reader_->GetRegionSelection(); // Create the point sets and add as dataset if (selector.size()) { const fvMesh& mesh = *meshPtr_; for ( int regionId = selector.start(); regionId < selector.end(); ++regionId ) { if (!selectedRegions_[regionId]) { continue; } word selectName = getFirstWord ( arraySelection->GetArrayName(regionId) ); if (debug) { Info<< "Creating VTK mesh for pointSet: " << selectName << " region index: " << regionId << endl; } const pointSet pSet(mesh, selectName); const label datasetId = GetNumberOfDataSets(output, selector); vtkPolyData* vtkmesh = vtkPolyData::New(); addPointSetMesh ( mesh, pSet, vtkmesh ); AddToBlock ( output, selector, datasetId, vtkmesh, selectName + ":pointSet" ); selectedRegionDatasetIds_[regionId] = datasetId; vtkmesh->Delete(); } } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshPointSets" << endl; printMemory(); } }
void Foam::vtkPV3Foam::convertMeshPointZones ( vtkMultiBlockDataSet* output ) { if (debug) { Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl; printMemory(); } const selectionInfo& selector = selectInfoPointZones_; const fvMesh& mesh = *meshPtr_; // Create the point sets and add as dataset if (selector.size()) { const pointZoneMesh& pzMesh = mesh.pointZones(); // use the zoneId directly instead of the name for (int zoneI=0; zoneI < selector.size(); ++zoneI) { const int regionId = selector.start() + zoneI; if (!selectedRegions_[regionId]) { continue; } if (debug) { Info<< "Creating VTK mesh for pointZone: " << zoneI << endl; } const label datasetId = GetNumberOfDataSets(output, selector); vtkPolyData* vtkmesh = vtkPolyData::New(); addPointZoneMesh ( mesh, pzMesh[zoneI], vtkmesh ); AddToBlock ( output, selector, datasetId, vtkmesh, pzMesh.names()[zoneI] + ":pointZone" ); selectedRegionDatasetIds_[regionId] = datasetId; vtkmesh->Delete(); } } if (debug) { Info<< "<end> Foam::vtkPV3Foam::convertMeshPointZones" << endl; printMemory(); } }