27 #include "vtkPVblockMeshReader.h"
37 #include "vtkDataArraySelection.h"
38 #include "vtkMultiBlockDataSet.h"
39 #include "vtkRenderer.h"
40 #include "vtkTextActor.h"
41 #include "vtkTextProperty.h"
53 void Foam::vtkPVblockMesh::resetCounters()
56 arrayRangeBlocks_.reset();
57 arrayRangeEdges_.reset();
58 arrayRangeCorners_.reset();
62 void Foam::vtkPVblockMesh::updateInfoBlocks
64 vtkDataArraySelection* arraySelection
67 arrayRangeBlocks_.reset(arraySelection->GetNumberOfArrays());
69 const blockMesh& blkMesh = *meshPtr_;
71 const int nBlocks = blkMesh.size();
72 for (
int blockI = 0; blockI < nBlocks; ++blockI)
74 const blockDescriptor& blockDef = blkMesh[blockI];
80 word partName(os.str());
83 if (!blockDef.zoneName().empty())
85 partName +=
" - " + blockDef.zoneName();
89 arraySelection->AddArray(partName.c_str());
92 arrayRangeBlocks_ += nBlocks;
94 if (debug) getSelectedArrayEntries(arraySelection);
98 void Foam::vtkPVblockMesh::updateInfoEdges
100 vtkDataArraySelection* arraySelection
105 arrayRangeEdges_.reset(arraySelection->GetNumberOfArrays());
107 const blockMesh& blkMesh = *meshPtr_;
110 const int nEdges = edges.
size();
117 ostr <<
" - " << edges[edgeI].type();
120 arraySelection->AddArray(ostr.str().c_str());
123 arrayRangeEdges_ += nEdges;
125 if (debug) getSelectedArrayEntries(arraySelection);
133 const char*
const FileName,
134 vtkPVblockMeshReader* reader
140 meshRegion_(polyMesh::defaultRegion),
141 meshDir_(polyMesh::meshSubDir),
142 arrayRangeBlocks_(
"block"),
143 arrayRangeEdges_(
"edges"),
144 arrayRangeCorners_(
"corners")
147 <<
"fileName=" << FileName <<
endl;
150 fileName fullCasePath(fileName(FileName).path());
152 if (!
isDir(fullCasePath))
return;
154 if (fullCasePath ==
".")
156 fullCasePath =
cwd();
159 if (fullCasePath.name().find(
"processor", 0) == 0)
161 const fileName globalCase = fullCasePath.path();
163 setEnv(
"FOAM_CASE", globalCase,
true);
164 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
168 setEnv(
"FOAM_CASE", fullCasePath,
true);
169 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
175 string caseName(fileName(FileName).lessExt());
181 beg != string::npos && caseName[beg] ==
'{'
182 && end != string::npos && end == caseName.size()-1
185 meshRegion_ = caseName.substr(beg+1, end-beg-1);
188 if (meshRegion_.empty())
190 meshRegion_ = polyMesh::defaultRegion;
193 if (meshRegion_ != polyMesh::defaultRegion)
195 meshDir_ = meshRegion_/polyMesh::meshSubDir;
200 <<
" fullCasePath=" << fullCasePath <<
nl
201 <<
" FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl
202 <<
" FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl
203 <<
" region=" << meshRegion_ <<
endl;
210 Time::controlDictName,
211 fileName(fullCasePath.path()),
212 fileName(fullCasePath.name()),
226 forAll(pointNumberTextActorsPtrs_, pointi)
228 pointNumberTextActorsPtrs_[pointi]->Delete();
230 pointNumberTextActorsPtrs_.
clear();
242 vtkDataArraySelection* blockSelection = reader_->GetBlockSelection();
243 vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection();
247 !blockSelection->GetNumberOfArrays() && !meshPtr_;
253 enabledParts = getSelectedArrayEntries(blockSelection,
false);
254 enabledEdges = getSelectedArrayEntries(edgeSelection,
false);
258 blockSelection->RemoveAllArrays();
259 edgeSelection->RemoveAllArrays();
265 updateInfoBlocks(blockSelection);
268 updateInfoEdges(edgeSelection);
273 setSelectedArrayEntries(blockSelection, enabledParts);
274 setSelectedArrayEntries(edgeSelection, enabledEdges);
279 void Foam::vtkPVblockMesh::updateFoamMesh()
285 const word dictName(
"blockMeshDict");
286 fileName dictPath(dbPtr_().
system()/dictName);
293 dbPtr_().path()/dbPtr_().constant()
303 IOdictionary* meshDictPtr =
new IOdictionary
314 meshDictPtr->store();
316 meshPtr_ =
new blockMesh
328 vtkMultiBlockDataSet* output
331 reader_->UpdateProgress(0.1);
334 updateBoolListStatus(blockStatus_, reader_->GetBlockSelection());
337 updateBoolListStatus(edgeStatus_, reader_->GetCurvedEdgesSelection());
339 reader_->UpdateProgress(0.2);
343 reader_->UpdateProgress(0.5);
348 convertMeshCorners(output, blockNo);
349 convertMeshBlocks(output, blockNo);
350 convertMeshEdges(output, blockNo);
352 reader_->UpdateProgress(0.8);
358 reader_->UpdateProgress(1.0);
364 vtkRenderer* renderer,
370 forAll(pointNumberTextActorsPtrs_, pointi)
372 renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointi]);
373 pointNumberTextActorsPtrs_[pointi]->Delete();
375 pointNumberTextActorsPtrs_.clear();
377 if (show && meshPtr_)
379 const blockMesh& blkMesh = *meshPtr_;
380 const pointField& cornerPts = blkMesh.vertices();
381 const scalar scaleFactor = blkMesh.scaleFactor();
383 pointNumberTextActorsPtrs_.
setSize(cornerPts.size());
393 txt->SetInput(os.str().c_str());
397 vtkTextProperty* tprop = txt->GetTextProperty();
398 tprop->SetFontFamilyToArial();
401 tprop->SetLineSpacing(1.0);
402 tprop->SetFontSize(14);
403 tprop->SetColor(1.0, 0.0, 1.0);
404 tprop->SetJustificationToCentered();
407 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
409 txt->GetPositionCoordinate()->SetValue
411 cornerPts[pointi].
x()*scaleFactor,
412 cornerPts[pointi].
y()*scaleFactor,
413 cornerPts[pointi].z()*scaleFactor
417 renderer->AddViewProp(txt);
421 pointNumberTextActorsPtrs_[pointi] = txt;
429 os <<
indent <<
"Number of nodes: "
430 << (meshPtr_ ? meshPtr_->vertices().size() : 0) <<
"\n";
432 os <<
indent <<
"Number of cells: "
433 << (meshPtr_ ? meshPtr_->cells().size() : 0) <<
"\n";
435 os <<
indent <<
"Number of available time steps: "
436 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
"\n";
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
graph_traits< Graph >::vertices_size_type size_type
#define forAll(list, i)
Loop across all elements in list.
void clear()
Clear the list, i.e. set size to zero.
void setSize(const label)
Reset size of List.
label size() const
Return the number of elements in the UPtrList.
static void write(Ostream &, const label blocki, const dictionary &)
Write block index with dictionary lookup.
static void write(Ostream &, const label, const dictionary &)
Write vertex index with optional name backsubstitution.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
~vtkPVblockMesh()
Destructor.
void Update(vtkMultiBlockDataSet *output)
Update.
void PrintSelf(ostream &, vtkIndent) const
Debug information.
void CleanUp()
Clean any storage.
void renderPointNumbers(vtkRenderer *, const bool show)
Add/remove point numbers to/from the view.
vtkPVblockMesh(const char *const FileName, vtkPVblockMeshReader *reader)
Construct from components.
void updateInfo()
Update information.
#define DebugInfo
Report an information message using Foam::Info.
#define DebugInFunction
Report an information message using Foam::Info.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
fileName cwd()
Return current working directory path name.
int system(const std::string &command)
Execute the specified command.
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
vectorField pointField
pointField is a vectorField.
labelList first(const UList< labelPair > &p)
PtrList< blockEdge > blockEdgeList
A PtrList of blockEdges.
defineTypeNameAndDebug(combustionModel, 0)
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
string getEnv(const word &)
Return environment variable of given name.
List< string > stringList
A List of strings.
Ostream & indent(Ostream &os)
Indent stream.