OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

vtkPV3FoamMesh.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "vtkPV3Foam.H"
00030 
00031 // Foam includes
00032 #include "cellSet.H"
00033 #include "faceSet.H"
00034 #include "pointSet.H"
00035 #include "fvMeshSubset.H"
00036 #include "vtkPV3FoamReader.h"
00037 
00038 // VTK includes
00039 #include "vtkDataArraySelection.h"
00040 #include "vtkMultiBlockDataSet.h"
00041 #include "vtkPolyData.h"
00042 #include "vtkUnstructuredGrid.h"
00043 
00044 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00045 
00046 void Foam::vtkPV3Foam::convertMeshVolume
00047 (
00048     vtkMultiBlockDataSet* output,
00049     int& blockNo
00050 )
00051 {
00052     partInfo& selector = partInfoVolume_;
00053     selector.block(blockNo);   // set output block
00054     label datasetNo = 0;       // restart at dataset 0
00055     const fvMesh& mesh = *meshPtr_;
00056 
00057     // resize for decomposed polyhedra
00058     regionPolyDecomp_.setSize(selector.size());
00059 
00060     if (debug)
00061     {
00062         Info<< "<beg> Foam::vtkPV3Foam::convertMeshVolume" << endl;
00063         printMemory();
00064     }
00065 
00066     // Convert the internalMesh
00067     // this looks like more than one part, but it isn't
00068     for (int partId = selector.start(); partId < selector.end(); ++partId)
00069     {
00070         const word partName = "internalMesh";
00071 
00072         if (!partStatus_[partId])
00073         {
00074             continue;
00075         }
00076 
00077         vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
00078         (
00079             mesh,
00080             regionPolyDecomp_[datasetNo]
00081         );
00082 
00083         if (vtkmesh)
00084         {
00085             AddToBlock(output, vtkmesh, selector, datasetNo, partName);
00086             vtkmesh->Delete();
00087 
00088             partDataset_[partId] = datasetNo++;
00089         }
00090     }
00091 
00092     // anything added?
00093     if (datasetNo)
00094     {
00095         ++blockNo;
00096     }
00097 
00098     if (debug)
00099     {
00100         Info<< "<end> Foam::vtkPV3Foam::convertMeshVolume" << endl;
00101         printMemory();
00102     }
00103 }
00104 
00105 
00106 void Foam::vtkPV3Foam::convertMeshLagrangian
00107 (
00108     vtkMultiBlockDataSet* output,
00109     int& blockNo
00110 )
00111 {
00112     partInfo& selector = partInfoLagrangian_;
00113     selector.block(blockNo);   // set output block
00114     label datasetNo = 0;       // restart at dataset 0
00115     const fvMesh& mesh = *meshPtr_;
00116 
00117     if (debug)
00118     {
00119         Info<< "<beg> Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
00120         printMemory();
00121     }
00122 
00123     for (int partId = selector.start(); partId < selector.end(); ++partId)
00124     {
00125         const word cloudName = getPartName(partId);
00126 
00127         if (!partStatus_[partId])
00128         {
00129             continue;
00130         }
00131 
00132         vtkPolyData* vtkmesh = lagrangianVTKMesh(mesh, cloudName);
00133 
00134         if (vtkmesh)
00135         {
00136             AddToBlock(output, vtkmesh, selector, datasetNo, cloudName);
00137             vtkmesh->Delete();
00138 
00139             partDataset_[partId] = datasetNo++;
00140         }
00141     }
00142 
00143     // anything added?
00144     if (datasetNo)
00145     {
00146         ++blockNo;
00147     }
00148 
00149     if (debug)
00150     {
00151         Info<< "<end> Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
00152         printMemory();
00153     }
00154 }
00155 
00156 
00157 void Foam::vtkPV3Foam::convertMeshPatches
00158 (
00159     vtkMultiBlockDataSet* output,
00160     int& blockNo
00161 )
00162 {
00163     partInfo& selector = partInfoPatches_;
00164     selector.block(blockNo);   // set output block
00165     label datasetNo = 0;       // restart at dataset 0
00166     const fvMesh& mesh = *meshPtr_;
00167     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00168 
00169     if (debug)
00170     {
00171         Info<< "<beg> Foam::vtkPV3Foam::convertMeshPatches" << endl;
00172         printMemory();
00173     }
00174 
00175     for (int partId = selector.start(); partId < selector.end(); ++partId)
00176     {
00177         const word patchName = getPartName(partId);
00178         const label  patchId = patches.findPatchID(patchName);
00179 
00180         if (!partStatus_[partId] || patchId < 0)
00181         {
00182             continue;
00183         }
00184 
00185         if (debug)
00186         {
00187             Info<< "Creating VTK mesh for patch[" << patchId <<"] "
00188                 << patchName  << endl;
00189         }
00190 
00191         vtkPolyData* vtkmesh = patchVTKMesh(patches[patchId]);
00192 
00193         if (vtkmesh)
00194         {
00195             AddToBlock(output, vtkmesh, selector, datasetNo, patchName);
00196             vtkmesh->Delete();
00197 
00198             partDataset_[partId] = datasetNo++;
00199         }
00200     }
00201 
00202     // anything added?
00203     if (datasetNo)
00204     {
00205         ++blockNo;
00206     }
00207 
00208     if (debug)
00209     {
00210         Info<< "<end> Foam::vtkPV3Foam::convertMeshPatches" << endl;
00211         printMemory();
00212     }
00213 }
00214 
00215 
00216 void Foam::vtkPV3Foam::convertMeshCellZones
00217 (
00218     vtkMultiBlockDataSet* output,
00219     int& blockNo
00220 )
00221 {
00222     partInfo& selector = partInfoCellZones_;
00223     selector.block(blockNo);   // set output block
00224     label datasetNo = 0;       // restart at dataset 0
00225     const fvMesh& mesh = *meshPtr_;
00226 
00227     // resize for decomposed polyhedra
00228     zonePolyDecomp_.setSize(selector.size());
00229 
00230     if (!selector.size())
00231     {
00232         return;
00233     }
00234 
00235     if (debug)
00236     {
00237         Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
00238         printMemory();
00239     }
00240 
00241     const cellZoneMesh& zMesh = mesh.cellZones();
00242     for (int partId = selector.start(); partId < selector.end(); ++partId)
00243     {
00244         const word zoneName = getPartName(partId);
00245         const label  zoneId = zMesh.findZoneID(zoneName);
00246 
00247         if (!partStatus_[partId] || zoneId < 0)
00248         {
00249             continue;
00250         }
00251 
00252         if (debug)
00253         {
00254             Info<< "Creating VTK mesh for cellZone[" << zoneId << "] "
00255                 << zoneName << endl;
00256         }
00257 
00258         fvMeshSubset subsetter(mesh);
00259         subsetter.setLargeCellSubset(zMesh[zoneId]);
00260 
00261         vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
00262         (
00263             subsetter.subMesh(),
00264             zonePolyDecomp_[datasetNo]
00265         );
00266 
00267         if (vtkmesh)
00268         {
00269             // superCells + addPointCellLabels must contain global cell ids
00270             inplaceRenumber
00271             (
00272                 subsetter.cellMap(),
00273                 zonePolyDecomp_[datasetNo].superCells()
00274             );
00275             inplaceRenumber
00276             (
00277                 subsetter.cellMap(),
00278                 zonePolyDecomp_[datasetNo].addPointCellLabels()
00279             );
00280 
00281             // copy pointMap as well, otherwise pointFields fail
00282             zonePolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();
00283 
00284             AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
00285             vtkmesh->Delete();
00286 
00287             partDataset_[partId] = datasetNo++;
00288         }
00289     }
00290 
00291     // anything added?
00292     if (datasetNo)
00293     {
00294         ++blockNo;
00295     }
00296 
00297     if (debug)
00298     {
00299         Info<< "<end> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
00300         printMemory();
00301     }
00302 }
00303 
00304 
00305 void Foam::vtkPV3Foam::convertMeshCellSets
00306 (
00307     vtkMultiBlockDataSet* output,
00308     int& blockNo
00309 )
00310 {
00311     partInfo& selector = partInfoCellSets_;
00312     selector.block(blockNo);   // set output block
00313     label datasetNo = 0;       // restart at dataset 0
00314     const fvMesh& mesh = *meshPtr_;
00315 
00316     // resize for decomposed polyhedra
00317     csetPolyDecomp_.setSize(selector.size());
00318 
00319     if (debug)
00320     {
00321         Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
00322         printMemory();
00323     }
00324 
00325     for (int partId = selector.start(); partId < selector.end(); ++partId)
00326     {
00327         const word partName = getPartName(partId);
00328 
00329         if (!partStatus_[partId])
00330         {
00331             continue;
00332         }
00333 
00334         if (debug)
00335         {
00336             Info<< "Creating VTK mesh for cellSet=" << partName << endl;
00337         }
00338 
00339         const cellSet cSet(mesh, partName);
00340         fvMeshSubset subsetter(mesh);
00341         subsetter.setLargeCellSubset(cSet);
00342 
00343         vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
00344         (
00345             subsetter.subMesh(),
00346             csetPolyDecomp_[datasetNo]
00347         );
00348 
00349         if (vtkmesh)
00350         {
00351             // superCells + addPointCellLabels must contain global cell ids
00352             inplaceRenumber
00353             (
00354                 subsetter.cellMap(),
00355                 csetPolyDecomp_[datasetNo].superCells()
00356             );
00357             inplaceRenumber
00358             (
00359                 subsetter.cellMap(),
00360                 csetPolyDecomp_[datasetNo].addPointCellLabels()
00361             );
00362 
00363             // copy pointMap as well, otherwise pointFields fail
00364             csetPolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();
00365 
00366             AddToBlock(output, vtkmesh, selector, datasetNo, partName);
00367             vtkmesh->Delete();
00368 
00369             partDataset_[partId] = datasetNo++;
00370         }
00371     }
00372 
00373     // anything added?
00374     if (datasetNo)
00375     {
00376         ++blockNo;
00377     }
00378 
00379     if (debug)
00380     {
00381         Info<< "<end> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
00382         printMemory();
00383     }
00384 }
00385 
00386 
00387 void Foam::vtkPV3Foam::convertMeshFaceZones
00388 (
00389     vtkMultiBlockDataSet* output,
00390     int& blockNo
00391 )
00392 {
00393     partInfo& selector = partInfoFaceZones_;
00394     selector.block(blockNo);   // set output block
00395     label datasetNo = 0;       // restart at dataset 0
00396     const fvMesh& mesh = *meshPtr_;
00397 
00398     if (!selector.size())
00399     {
00400         return;
00401     }
00402 
00403     if (debug)
00404     {
00405         Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
00406         printMemory();
00407     }
00408 
00409     const faceZoneMesh& zMesh = mesh.faceZones();
00410     for (int partId = selector.start(); partId < selector.end(); ++partId)
00411     {
00412         const word zoneName = getPartName(partId);
00413         const label  zoneId = zMesh.findZoneID(zoneName);
00414 
00415         if (!partStatus_[partId] || zoneId < 0)
00416         {
00417             continue;
00418         }
00419 
00420         if (debug)
00421         {
00422             Info<< "Creating VTKmesh for faceZone[" << zoneId << "] "
00423                 << zoneName << endl;
00424         }
00425 
00426         vtkPolyData* vtkmesh = faceZoneVTKMesh(mesh, zMesh[zoneId]);
00427         if (vtkmesh)
00428         {
00429             AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
00430             vtkmesh->Delete();
00431 
00432             partDataset_[partId] = datasetNo++;
00433         }
00434     }
00435 
00436     // anything added?
00437     if (datasetNo)
00438     {
00439         ++blockNo;
00440     }
00441 
00442     if (debug)
00443     {
00444         Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
00445         printMemory();
00446     }
00447 }
00448 
00449 
00450 void Foam::vtkPV3Foam::convertMeshFaceSets
00451 (
00452     vtkMultiBlockDataSet* output,
00453     int& blockNo
00454 )
00455 {
00456     partInfo& selector = partInfoFaceSets_;
00457     selector.block(blockNo);   // set output block
00458     label datasetNo = 0;       // restart at dataset 0
00459     const fvMesh& mesh = *meshPtr_;
00460 
00461     if (debug)
00462     {
00463         Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceSets" << endl;
00464         printMemory();
00465     }
00466 
00467     for (int partId = selector.start(); partId < selector.end(); ++partId)
00468     {
00469         const word partName = getPartName(partId);
00470 
00471         if (!partStatus_[partId])
00472         {
00473             continue;
00474         }
00475 
00476         if (debug)
00477         {
00478             Info<< "Creating VTK mesh for faceSet=" << partName << endl;
00479         }
00480 
00481         const faceSet fSet(mesh, partName);
00482 
00483         vtkPolyData* vtkmesh = faceSetVTKMesh(mesh, fSet);
00484         if (vtkmesh)
00485         {
00486             AddToBlock(output, vtkmesh, selector, datasetNo, partName);
00487             vtkmesh->Delete();
00488 
00489             partDataset_[partId] = datasetNo++;
00490         }
00491     }
00492 
00493     // anything added?
00494     if (datasetNo)
00495     {
00496         ++blockNo;
00497     }
00498 
00499     if (debug)
00500     {
00501         Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceSets" << endl;
00502         printMemory();
00503     }
00504 }
00505 
00506 
00507 void Foam::vtkPV3Foam::convertMeshPointZones
00508 (
00509     vtkMultiBlockDataSet* output,
00510     int& blockNo
00511 )
00512 {
00513     partInfo& selector = partInfoPointZones_;
00514     selector.block(blockNo);   // set output block
00515     label datasetNo = 0;       // restart at dataset 0
00516     const fvMesh& mesh = *meshPtr_;
00517 
00518     if (debug)
00519     {
00520         Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
00521         printMemory();
00522     }
00523 
00524     if (selector.size())
00525     {
00526         const pointZoneMesh& zMesh = mesh.pointZones();
00527         for (int partId = selector.start(); partId < selector.end(); ++partId)
00528         {
00529             word zoneName = getPartName(partId);
00530             label zoneId = zMesh.findZoneID(zoneName);
00531 
00532             if (!partStatus_[partId] || zoneId < 0)
00533             {
00534                 continue;
00535             }
00536 
00537             vtkPolyData* vtkmesh = pointZoneVTKMesh(mesh, zMesh[zoneId]);
00538             if (vtkmesh)
00539             {
00540                 AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
00541                 vtkmesh->Delete();
00542 
00543                 partDataset_[partId] = datasetNo++;
00544             }
00545         }
00546     }
00547 
00548     // anything added?
00549     if (datasetNo)
00550     {
00551         ++blockNo;
00552     }
00553 
00554     if (debug)
00555     {
00556         Info<< "<end> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
00557         printMemory();
00558     }
00559 }
00560 
00561 
00562 
00563 void Foam::vtkPV3Foam::convertMeshPointSets
00564 (
00565     vtkMultiBlockDataSet* output,
00566     int& blockNo
00567 )
00568 {
00569     partInfo& selector = partInfoPointSets_;
00570     selector.block(blockNo);   // set output block
00571     label datasetNo = 0;       // restart at dataset 0
00572     const fvMesh& mesh = *meshPtr_;
00573 
00574     if (debug)
00575     {
00576         Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
00577         printMemory();
00578     }
00579 
00580     for (int partId = selector.start(); partId < selector.end(); ++partId)
00581     {
00582         word partName = getPartName(partId);
00583 
00584         if (!partStatus_[partId])
00585         {
00586             continue;
00587         }
00588 
00589         if (debug)
00590         {
00591             Info<< "Creating VTK mesh for pointSet=" << partName << endl;
00592         }
00593 
00594         const pointSet pSet(mesh, partName);
00595 
00596         vtkPolyData* vtkmesh = pointSetVTKMesh(mesh, pSet);
00597         if (vtkmesh)
00598         {
00599             AddToBlock(output, vtkmesh, selector, datasetNo, partName);
00600             vtkmesh->Delete();
00601 
00602             partDataset_[partId] = datasetNo++;
00603         }
00604     }
00605 
00606     // anything added?
00607     if (datasetNo)
00608     {
00609         ++blockNo;
00610     }
00611 
00612     if (debug)
00613     {
00614         Info<< "<end> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
00615         printMemory();
00616     }
00617 }
00618 
00619 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd