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
69 if (!meshPtr_.valid())
return;
71 arrayRangeBlocks_.reset(arraySelection->GetNumberOfArrays());
73 const blockMesh& blkMesh = *meshPtr_;
75 const int nBlocks = blkMesh.size();
76 for (
int blockI = 0; blockI < nBlocks; ++blockI)
78 const blockDescriptor& blockDef = blkMesh[blockI];
84 word partName(os.str());
87 if (!blockDef.zoneName().empty())
89 partName +=
" - " + blockDef.zoneName();
93 arraySelection->AddArray(partName.c_str());
96 arrayRangeBlocks_ += nBlocks;
98 if (debug) getSelectedArrayEntries(arraySelection);
102 void Foam::vtkPVblockMesh::updateInfoEdges
104 vtkDataArraySelection* arraySelection
109 if (!meshPtr_.valid())
return;
111 arrayRangeEdges_.reset(arraySelection->GetNumberOfArrays());
113 const blockMesh& blkMesh = *meshPtr_;
116 const int nEdges = edges.
size();
123 ostr <<
" - " << edges[edgeI].type();
126 arraySelection->AddArray(ostr.str().c_str());
129 arrayRangeEdges_ += nEdges;
131 if (debug) getSelectedArrayEntries(arraySelection);
139 const char*
const FileName,
140 vtkPVblockMeshReader* reader
146 meshRegion_(polyMesh::defaultRegion),
147 meshDir_(polyMesh::meshSubDir),
148 arrayRangeBlocks_(
"block"),
149 arrayRangeEdges_(
"edges"),
150 arrayRangeCorners_(
"corners")
153 <<
"fileName=" << FileName <<
endl;
156 fileName fullCasePath(fileName(FileName).path());
158 if (!
isDir(fullCasePath))
return;
160 if (fullCasePath ==
".")
162 fullCasePath =
cwd();
165 if (fullCasePath.name().find(
"processor", 0) == 0)
167 const fileName globalCase = fullCasePath.path();
169 setEnv(
"FOAM_CASE", globalCase,
true);
170 setEnv(
"FOAM_CASENAME", globalCase.name(),
true);
174 setEnv(
"FOAM_CASE", fullCasePath,
true);
175 setEnv(
"FOAM_CASENAME", fullCasePath.name(),
true);
181 string caseName(fileName(FileName).lessExt());
187 beg != string::npos && caseName[beg] ==
'{'
188 && end != string::npos && end == caseName.size()-1
191 meshRegion_ = caseName.substr(beg+1, end-beg-1);
194 if (meshRegion_.empty())
196 meshRegion_ = polyMesh::defaultRegion;
199 if (meshRegion_ != polyMesh::defaultRegion)
201 meshDir_ = meshRegion_/polyMesh::meshSubDir;
206 <<
" fullCasePath=" << fullCasePath <<
nl
207 <<
" FOAM_CASE=" <<
getEnv(
"FOAM_CASE") <<
nl
208 <<
" FOAM_CASENAME=" <<
getEnv(
"FOAM_CASENAME") <<
nl
209 <<
" region=" << meshRegion_ <<
endl;
216 Time::controlDictName,
217 fileName(fullCasePath.path()),
218 fileName(fullCasePath.name()),
231 forAll(pointNumberTextActorsPtrs_, pointi)
233 pointNumberTextActorsPtrs_[pointi]->Delete();
235 pointNumberTextActorsPtrs_.
clear();
247 vtkDataArraySelection* blockSelection = reader_->GetBlockSelection();
248 vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection();
252 !blockSelection->GetNumberOfArrays() && !meshPtr_.valid();
258 enabledBlocks = getSelectedArrayEntries(blockSelection,
false);
259 enabledEdges = getSelectedArrayEntries(edgeSelection,
false);
263 blockSelection->RemoveAllArrays();
264 edgeSelection->RemoveAllArrays();
270 updateInfoBlocks(blockSelection);
273 updateInfoEdges(edgeSelection);
278 setSelectedArrayEntries(blockSelection, enabledBlocks);
279 setSelectedArrayEntries(edgeSelection, enabledEdges);
284 void Foam::vtkPVblockMesh::updateFoamMesh()
291 autoPtr<blockMesh> newMeshPtr;
296 const word dictName(
"blockMeshDict");
297 fileName dictPath(dbPtr_().
system()/dictName);
304 dbPtr_().path()/dbPtr_().constant()
314 IOdictionary* meshDictPtr =
new IOdictionary
325 meshDictPtr->store();
337 meshPtr_.reset(newMeshPtr.ptr());
343 vtkErrorWithObjectMacro(reader_, << oss.str().c_str());
349 vtkErrorWithObjectMacro(reader_, << oss.str().c_str());
359 vtkMultiBlockDataSet* output
364 reader_->UpdateProgress(0.2);
367 updateBoolListStatus(blockStatus_, reader_->GetBlockSelection());
370 updateBoolListStatus(edgeStatus_, reader_->GetCurvedEdgesSelection());
372 reader_->UpdateProgress(0.5);
377 convertMeshCorners(output, blockNo);
378 convertMeshBlocks(output, blockNo);
379 convertMeshEdges(output, blockNo);
381 reader_->UpdateProgress(0.8);
389 reader_->UpdateProgress(1.0);
395 vtkRenderer* renderer,
402 forAll(pointNumberTextActorsPtrs_, pointi)
404 renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointi]);
405 pointNumberTextActorsPtrs_[pointi]->Delete();
407 pointNumberTextActorsPtrs_.clear();
412 if (!meshPtr_.valid())
return;
414 const blockMesh& blkMesh = *meshPtr_;
415 const pointField& cornerPts = blkMesh.vertices();
416 const scalar scaleFactor = blkMesh.scaleFactor();
418 pointNumberTextActorsPtrs_.
setSize(cornerPts.size());
428 txt->SetInput(os.str().c_str());
432 vtkTextProperty* tprop = txt->GetTextProperty();
433 tprop->SetFontFamilyToArial();
436 tprop->SetLineSpacing(1.0);
437 tprop->SetFontSize(14);
438 tprop->SetColor(1.0, 0.0, 1.0);
439 tprop->SetJustificationToCentered();
442 txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
444 txt->GetPositionCoordinate()->SetValue
446 cornerPts[pointi].
x()*scaleFactor,
447 cornerPts[pointi].
y()*scaleFactor,
448 cornerPts[pointi].z()*scaleFactor
452 renderer->AddViewProp(txt);
456 pointNumberTextActorsPtrs_[pointi] = txt;
463 os <<
indent <<
"Number of nodes: "
464 << (meshPtr_.valid() ? meshPtr_->vertices().size() : 0) <<
"\n";
466 os <<
indent <<
"Number of cells: "
467 << (meshPtr_.valid() ? meshPtr_->cells().size() : 0) <<
"\n";
469 os <<
indent <<
"Number of available time steps: "
470 << (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.
void dontThrowExceptions()
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.
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.
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.
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
Ostream & indent(Ostream &os)
Indent stream.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)