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
70 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"nullptr") <<
"]" <<
endl;
73 arrayRangeBlocks_.reset( arraySelection->GetNumberOfArrays() );
75 const blockMesh& blkMesh = *meshPtr_;
77 const int nBlocks = blkMesh.size();
78 for (
int blockI = 0; blockI < nBlocks; ++blockI)
80 const blockDescriptor& blockDef = blkMesh[blockI];
86 word partName(os.str());
89 if (!blockDef.zoneName().empty())
91 partName +=
" - " + blockDef.zoneName();
95 arraySelection->AddArray(partName.c_str());
98 arrayRangeBlocks_ += nBlocks;
103 getSelectedArrayEntries(arraySelection);
108 void Foam::vtkPVblockMesh::updateInfoEdges
110 vtkDataArraySelection* arraySelection
116 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"nullptr") <<
"]" <<
endl;
119 arrayRangeEdges_.reset( arraySelection->GetNumberOfArrays() );
121 const blockMesh& blkMesh = *meshPtr_;
124 const int nEdges = edges.
size();
131 ostr <<
" - " << edges[edgeI].type();
134 arraySelection->AddArray(ostr.str().c_str());
137 arrayRangeEdges_ += nEdges;
142 getSelectedArrayEntries(arraySelection);
151 const char*
const FileName,
152 vtkPVblockMeshReader* reader
158 meshRegion_(polyMesh::defaultRegion),
159 meshDir_(polyMesh::meshSubDir),
160 arrayRangeBlocks_(
"block"),
161 arrayRangeEdges_(
"edges"),
162 arrayRangeCorners_(
"corners")
170 fileName fullCasePath(fileName(FileName).path());
172 if (!
isDir(fullCasePath))
176 if (fullCasePath ==
".")
178 fullCasePath =
cwd();
182 if (fullCasePath.name().find(
"processor", 0) == 0)
184 const fileName globalCase = fullCasePath.path();
186 setEnv(
"FOAM_CASE", globalCase,
true);
187 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
191 setEnv(
"FOAM_CASE", fullCasePath,
true);
192 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
198 string caseName(fileName(FileName).lessExt());
204 beg != string::npos && caseName[beg] ==
'{'
205 && end != string::npos && end == caseName.size()-1
208 meshRegion_ = caseName.substr(beg+1, end-beg-1);
211 if (meshRegion_.empty())
213 meshRegion_ = polyMesh::defaultRegion;
216 if (meshRegion_ != polyMesh::defaultRegion)
218 meshDir_ = meshRegion_/polyMesh::meshSubDir;
224 Info<<
" fullCasePath=" << fullCasePath <<
nl
225 <<
" FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl
226 <<
" FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
endl;
234 Time::controlDictName,
235 fileName(fullCasePath.path()),
236 fileName(fullCasePath.name()),
256 forAll(pointNumberTextActorsPtrs_, pointi)
258 pointNumberTextActorsPtrs_[pointi]->Delete();
260 pointNumberTextActorsPtrs_.
clear();
273 <<
" [meshPtr=" << (meshPtr_ ?
"set" :
"nullptr") <<
"] " <<
endl;
278 vtkDataArraySelection* blockSelection = reader_->GetBlockSelection();
279 vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection();
285 bool firstTime =
false;
286 if (!blockSelection->GetNumberOfArrays() && !meshPtr_)
292 enabledParts = getSelectedArrayEntries(blockSelection);
293 enabledEdges = getSelectedArrayEntries(edgeSelection);
297 blockSelection->RemoveAllArrays();
298 edgeSelection->RemoveAllArrays();
304 updateInfoBlocks( blockSelection );
307 updateInfoEdges( edgeSelection );
312 setSelectedArrayEntries(blockSelection, enabledParts);
313 setSelectedArrayEntries(edgeSelection, enabledEdges);
318 void Foam::vtkPVblockMesh::updateFoamMesh()
331 <<
"Creating blockMesh at time=" << dbPtr_().name() <<
endl;
335 const word dictName(
"blockMeshDict");
336 fileName dictPath(dbPtr_().
system()/dictName);
343 dbPtr_().path()/dbPtr_().constant()
353 IOdictionary* meshDictPtr =
new IOdictionary
364 meshDictPtr->store();
366 meshPtr_ =
new blockMesh(*meshDictPtr, meshRegion_);
373 vtkMultiBlockDataSet* output
376 reader_->UpdateProgress(0.1);
379 updateBoolListStatus(blockStatus_, reader_->GetBlockSelection());
382 updateBoolListStatus(edgeStatus_, reader_->GetCurvedEdgesSelection());
384 reader_->UpdateProgress(0.2);
388 reader_->UpdateProgress(0.5);
393 convertMeshCorners(output, blockNo);
394 convertMeshBlocks(output, blockNo);
395 convertMeshEdges(output, blockNo);
397 reader_->UpdateProgress(0.8);
404 reader_->UpdateProgress(1.0);
410 vtkRenderer* renderer,
416 forAll(pointNumberTextActorsPtrs_, pointi)
418 renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointi]);
419 pointNumberTextActorsPtrs_[pointi]->Delete();
421 pointNumberTextActorsPtrs_.clear();
423 if (show && meshPtr_)
425 const blockMesh& blkMesh = *meshPtr_;
426 const pointField& cornerPts = blkMesh.vertices();
427 const scalar scaleFactor = blkMesh.scaleFactor();
429 pointNumberTextActorsPtrs_.
setSize(cornerPts.size());
439 txt->SetInput(os.str().c_str());
443 vtkTextProperty* tprop = txt->GetTextProperty();
444 tprop->SetFontFamilyToArial();
447 tprop->SetLineSpacing(1.0);
448 tprop->SetFontSize(14);
449 tprop->SetColor(1.0, 0.0, 1.0);
450 tprop->SetJustificationToCentered();
453 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
455 txt->GetPositionCoordinate()->SetValue
457 cornerPts[pointi].
x()*scaleFactor,
458 cornerPts[pointi].
y()*scaleFactor,
459 cornerPts[pointi].z()*scaleFactor
463 renderer->AddViewProp(txt);
467 pointNumberTextActorsPtrs_[pointi] = txt;
477 os <<
indent <<
"Number of nodes: "
478 << (meshPtr_ ? meshPtr_->nPoints() : 0) <<
"\n";
480 os <<
indent <<
"Number of cells: "
481 << (meshPtr_ ? meshPtr_->nCells() : 0) <<
"\n";
483 os <<
indent <<
"Number of available time steps: "
484 << (dbPtr_.valid() ? dbPtr_().times().size() : 0) <<
endl;
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)
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.
#define InfoInFunction
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.
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.