1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "vtkPV3blockMesh.H"
27 #include "vtkPV3blockMeshReader.h"
30 #include "blockMesh.H"
32 #include "patchZones.H"
33 #include "OStringStream.H"
36 #include "vtkDataArraySelection.h"
37 #include "vtkMultiBlockDataSet.h"
38 #include "vtkRenderer.h"
39 #include "vtkTextActor.h"
40 #include "vtkTextProperty.h"
42 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 defineTypeNameAndDebug(Foam::vtkPV3blockMesh, 0);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 void Foam::vtkPV3blockMesh::resetCounters()
50 // Reset mesh part ids and sizes
51 arrayRangeBlocks_.reset();
52 arrayRangeEdges_.reset();
53 arrayRangeCorners_.reset();
57 void Foam::vtkPV3blockMesh::updateInfoBlocks
59 vtkDataArraySelection* arraySelection
64 Info<< "<beg> Foam::vtkPV3blockMesh::updateInfoBlocks"
65 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
68 arrayRangeBlocks_.reset( arraySelection->GetNumberOfArrays() );
70 const blockMesh& blkMesh = *meshPtr_;
71 const int nBlocks = blkMesh.size();
72 for (int blockI = 0; blockI < nBlocks; ++blockI)
74 const blockDescriptor& blockDef = blkMesh[blockI].blockDef();
76 word partName = Foam::name(blockI);
78 // append the (optional) zone name
79 if (!blockDef.zoneName().empty())
81 partName += " - " + blockDef.zoneName();
84 // Add blockId and zoneName to GUI list
85 arraySelection->AddArray(partName.c_str());
88 arrayRangeBlocks_ += nBlocks;
92 // just for debug info
93 getSelectedArrayEntries(arraySelection);
95 Info<< "<end> Foam::vtkPV3blockMesh::updateInfoBlocks" << endl;
100 void Foam::vtkPV3blockMesh::updateInfoEdges
102 vtkDataArraySelection* arraySelection
107 Info<< "<beg> Foam::vtkPV3blockMesh::updateInfoEdges"
108 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
111 arrayRangeEdges_.reset( arraySelection->GetNumberOfArrays() );
113 const blockMesh& blkMesh = *meshPtr_;
114 const curvedEdgeList& edges = blkMesh.edges();
116 const int nEdges = edges.size();
121 ostr<< edges[edgeI].start() << ":" << edges[edgeI].end() << " - "
122 << edges[edgeI].type();
124 // Add "beg:end - type" to GUI list
125 arraySelection->AddArray(ostr.str().c_str());
128 arrayRangeEdges_ += nEdges;
132 // just for debug info
133 getSelectedArrayEntries(arraySelection);
135 Info<< "<end> Foam::vtkPV3blockMesh::updateInfoEdges" << endl;
140 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
142 Foam::vtkPV3blockMesh::vtkPV3blockMesh
144 const char* const FileName,
145 vtkPV3blockMeshReader* reader
151 meshRegion_(polyMesh::defaultRegion),
152 meshDir_(polyMesh::meshSubDir),
153 arrayRangeBlocks_("block"),
154 arrayRangeEdges_("edges"),
155 arrayRangeCorners_("corners")
159 Info<< "Foam::vtkPV3blockMesh::vtkPV3blockMesh - "
163 // avoid argList and get rootPath/caseName directly from the file
164 fileName fullCasePath(fileName(FileName).path());
166 if (!isDir(fullCasePath))
170 if (fullCasePath == ".")
172 fullCasePath = cwd();
175 // Set the case as an environment variable - some BCs might use this
176 if (fullCasePath.name().find("processor", 0) == 0)
178 const fileName globalCase = fullCasePath.path();
180 setEnv("FOAM_CASE", globalCase, true);
181 setEnv("FOAM_CASENAME", globalCase.name(), true);
185 setEnv("FOAM_CASE", fullCasePath, true);
186 setEnv("FOAM_CASENAME", fullCasePath.name(), true);
189 // look for 'case{region}.OpenFOAM'
190 // could be stringent and insist the prefix match the directory name...
191 // Note: cannot use fileName::name() due to the embedded '{}'
192 string caseName(fileName(FileName).lessExt());
193 string::size_type beg = caseName.find_last_of("/{");
194 string::size_type end = caseName.find('}', beg);
198 beg != string::npos && caseName[beg] == '{'
199 && end != string::npos && end == caseName.size()-1
202 meshRegion_ = caseName.substr(beg+1, end-beg-1);
205 if (meshRegion_.empty())
207 meshRegion_ = polyMesh::defaultRegion;
210 if (meshRegion_ != polyMesh::defaultRegion)
212 meshDir_ = meshRegion_/polyMesh::meshSubDir;
218 Info<< "fullCasePath=" << fullCasePath << nl
219 << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
220 << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << endl;
223 // Create time object
228 Time::controlDictName,
229 fileName(fullCasePath.path()),
230 fileName(fullCasePath.name())
234 dbPtr_().functionObjects().off();
240 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
242 Foam::vtkPV3blockMesh::~vtkPV3blockMesh()
246 Info<< "<end> Foam::vtkPV3blockMesh::~vtkPV3blockMesh" << endl;
249 // Hmm. pointNumberTextActors are not getting removed
251 forAll(pointNumberTextActorsPtrs_, pointI)
253 pointNumberTextActorsPtrs_[pointI]->Delete();
255 pointNumberTextActorsPtrs_.clear();
261 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
263 void Foam::vtkPV3blockMesh::updateInfo()
267 Info<< "<beg> Foam::vtkPV3blockMesh::updateInfo"
268 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "] " << endl;
273 vtkDataArraySelection* blockSelection = reader_->GetBlockSelection();
274 vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection();
276 // enable 'internalMesh' on the first call
277 // or preserve the enabled selections
278 stringList enabledParts;
279 stringList enabledEdges;
280 bool firstTime = false;
281 if (!blockSelection->GetNumberOfArrays() && !meshPtr_)
287 enabledParts = getSelectedArrayEntries(blockSelection);
288 enabledEdges = getSelectedArrayEntries(edgeSelection);
291 // Clear current mesh parts list
292 blockSelection->RemoveAllArrays();
293 edgeSelection->RemoveAllArrays();
298 // Update mesh parts list
299 updateInfoBlocks( blockSelection );
301 // Update curved edges list
302 updateInfoEdges( edgeSelection );
304 // restore the enabled selections
307 setSelectedArrayEntries(blockSelection, enabledParts);
308 setSelectedArrayEntries(edgeSelection, enabledEdges);
313 Info<< "<end> Foam::vtkPV3blockMesh::updateInfo" << endl;
318 void Foam::vtkPV3blockMesh::updateFoamMesh()
322 Info<< "<beg> Foam::vtkPV3blockMesh::updateFoamMesh" << endl;
325 // Check to see if the OpenFOAM mesh has been created
330 Info<< "Creating blockMesh at time=" << dbPtr_().timeName()
334 IOdictionary meshDict
342 IOobject::MUST_READ_IF_MODIFIED,
348 meshPtr_ = new blockMesh(meshDict, meshRegion_);
354 Info<< "<end> Foam::vtkPV3blockMesh::updateFoamMesh" << endl;
359 void Foam::vtkPV3blockMesh::Update
361 vtkMultiBlockDataSet* output
364 reader_->UpdateProgress(0.1);
366 // Set up mesh parts selection(s)
367 updateBoolListStatus(blockStatus_, reader_->GetBlockSelection());
369 // Set up curved edges selection(s)
370 updateBoolListStatus(edgeStatus_, reader_->GetCurvedEdgesSelection());
372 reader_->UpdateProgress(0.2);
374 // Update the OpenFOAM mesh
376 reader_->UpdateProgress(0.5);
378 // Convert mesh elemente
381 convertMeshCorners(output, blockNo);
382 convertMeshBlocks(output, blockNo);
383 convertMeshEdges(output, blockNo);
385 reader_->UpdateProgress(0.8);
390 void Foam::vtkPV3blockMesh::CleanUp()
392 reader_->UpdateProgress(1.0);
396 void Foam::vtkPV3blockMesh::renderPointNumbers
398 vtkRenderer* renderer,
402 // always remove old actors first
404 forAll(pointNumberTextActorsPtrs_, pointI)
406 renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointI]);
407 pointNumberTextActorsPtrs_[pointI]->Delete();
409 pointNumberTextActorsPtrs_.clear();
411 if (show && meshPtr_)
413 const pointField& cornerPts = meshPtr_->blockPointField();
414 const scalar scaleFactor = meshPtr_->scaleFactor();
416 pointNumberTextActorsPtrs_.setSize(cornerPts.size());
417 forAll(cornerPts, pointI)
419 vtkTextActor* txt = vtkTextActor::New();
421 txt->SetInput(Foam::name(pointI).c_str());
423 // Set text properties
424 vtkTextProperty* tprop = txt->GetTextProperty();
425 tprop->SetFontFamilyToArial();
428 tprop->SetLineSpacing(1.0);
429 tprop->SetFontSize(14);
430 tprop->SetColor(1.0, 0.0, 1.0);
431 tprop->SetJustificationToCentered();
433 // Set text to use 3-D world co-ordinates
434 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
436 txt->GetPositionCoordinate()->SetValue
438 cornerPts[pointI].x()*scaleFactor,
439 cornerPts[pointI].y()*scaleFactor,
440 cornerPts[pointI].z()*scaleFactor
443 // Add text to each renderer
444 renderer->AddViewProp(txt);
446 // Maintain a list of text labels added so that they can be
448 pointNumberTextActorsPtrs_[pointI] = txt;
455 void Foam::vtkPV3blockMesh::PrintSelf(ostream& os, vtkIndent indent) const
458 os << indent << "Number of nodes: "
459 << (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n";
461 os << indent << "Number of cells: "
462 << (meshPtr_ ? meshPtr_->nCells() : 0) << "\n";
464 os << indent << "Number of available time steps: "
465 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl;
469 // ************************************************************************* //