vtkPV3blockMeshUtils.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Description
25  Misc helper methods and utilities
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "vtkPV3blockMesh.H"
30 #include "vtkPV3blockMeshReader.h"
31 
32 // VTK includes
33 #include "vtkDataArraySelection.h"
34 #include "vtkDataSet.h"
35 #include "vtkMultiBlockDataSet.h"
36 #include "vtkInformation.h"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
43  // Extract up to the first non-word characters
44  inline word getFirstWord(const char* str)
45  {
46  if (str)
47  {
48  label n = 0;
49  while (str[n] && word::valid(str[n]))
50  {
51  ++n;
52  }
53  return word(str, n, true);
54  }
55  else
56  {
57  return word::null;
58  }
59 
60  }
62 
63 } // End namespace Foam
64 
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
70 (
71  vtkMultiBlockDataSet* output,
72  vtkDataSet* dataset,
73  const arrayRange& range,
74  const label datasetNo,
75  const std::string& datasetName
76 )
77 {
78  const int blockNo = range.block();
79 
80  vtkDataObject* blockDO = output->GetBlock(blockNo);
81  vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
82 
83  if (!block)
84  {
85  if (blockDO)
86  {
88  << "Block already has a vtkDataSet assigned to it"
89  << endl;
90  return;
91  }
92 
94  output->SetBlock(blockNo, block);
95  block->Delete();
96  }
97 
98  if (debug)
99  {
100  Info<< "block[" << blockNo << "] has "
101  << block->GetNumberOfBlocks()
102  << " datasets prior to adding set " << datasetNo
103  << " with name: " << datasetName << endl;
104  }
105 
106  block->SetBlock(datasetNo, dataset);
107 
108  // name the block when assigning dataset 0
109  if (datasetNo == 0)
110  {
111  output->GetMetaData(blockNo)->Set
112  (
113  vtkCompositeDataSet::NAME(),
114  range.name()
115  );
116  }
117 
118  if (datasetName.size())
119  {
120  block->GetMetaData(datasetNo)->Set
121  (
122  vtkCompositeDataSet::NAME(),
123  datasetName.c_str()
124  );
125  }
126 }
127 
128 
130 (
131  vtkMultiBlockDataSet* output,
132  const arrayRange& range,
133  const label datasetNo
134 )
135 {
136  const int blockNo = range.block();
137 
138  vtkDataObject* blockDO = output->GetBlock(blockNo);
139  vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
140 
141  if (block)
142  {
143  return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
144  }
145 
146  return 0;
147 }
148 
149 
150 // ununsed at the moment
152 (
153  vtkMultiBlockDataSet* output,
154  const arrayRange& range
155 )
156 {
157  const int blockNo = range.block();
158 
159  vtkDataObject* blockDO = output->GetBlock(blockNo);
160  vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
161  if (block)
162  {
163  return block->GetNumberOfBlocks();
164  }
165 
166  return 0;
167 }
168 
169 
171 (
172  vtkDataArraySelection* select
173 )
174 {
175  int nElem = select->GetNumberOfArrays();
176  wordHashSet selections(2*nElem);
177 
178  for (int elemI=0; elemI < nElem; ++elemI)
179  {
180  if (select->GetArraySetting(elemI))
181  {
182  selections.insert(getFirstWord(select->GetArrayName(elemI)));
183  }
184  }
185 
186  return selections;
187 }
188 
189 
191 (
192  vtkDataArraySelection* select,
193  const arrayRange& range
194 )
195 {
196  int nElem = select->GetNumberOfArrays();
197  wordHashSet selections(2*nElem);
198 
199  for (int elemI = range.start(); elemI < range.end(); ++elemI)
200  {
201  if (select->GetArraySetting(elemI))
202  {
203  selections.insert(getFirstWord(select->GetArrayName(elemI)));
204  }
205  }
206 
207  return selections;
208 }
209 
210 
212 (
213  vtkDataArraySelection* select
214 )
215 {
216  stringList selections(select->GetNumberOfArrays());
217  label nElem = 0;
218 
219  forAll(selections, elemI)
220  {
221  if (select->GetArraySetting(elemI))
222  {
223  selections[nElem++] = select->GetArrayName(elemI);
224  }
225  }
226  selections.setSize(nElem);
227 
228 
229  if (debug)
230  {
231  label nElem = select->GetNumberOfArrays();
232  Info<< "available(";
233  for (int elemI = 0; elemI < nElem; ++elemI)
234  {
235  Info<< " \"" << select->GetArrayName(elemI) << "\"";
236  }
237  Info<< " )\nselected(";
238 
239  forAll(selections, elemI)
240  {
241  Info<< " " << selections[elemI];
242  }
243  Info<< " )\n";
244  }
245 
246  return selections;
247 }
248 
249 
251 (
252  vtkDataArraySelection* select,
253  const arrayRange& range
254 )
255 {
256  stringList selections(range.size());
257  label nElem = 0;
258 
259  for (int elemI = range.start(); elemI < range.end(); ++elemI)
260  {
261  if (select->GetArraySetting(elemI))
262  {
263  selections[nElem++] = select->GetArrayName(elemI);
264  }
265  }
266  selections.setSize(nElem);
267 
268 
269  if (debug)
270  {
271  Info<< "available(";
272  for (int elemI = range.start(); elemI < range.end(); ++elemI)
273  {
274  Info<< " \"" << select->GetArrayName(elemI) << "\"";
275  }
276  Info<< " )\nselected(";
277 
278  forAll(selections, elemI)
279  {
280  Info<< " " << selections[elemI];
281  }
282  Info<< " )\n";
283  }
284 
285  return selections;
286 }
287 
288 
290 (
291  vtkDataArraySelection* select,
292  const stringList& selections
293 )
294 {
295  const int nElem = select->GetNumberOfArrays();
296  select->DisableAllArrays();
297 
298  // Loop through entries, setting values from selectedEntries
299  for (int elemI=0; elemI < nElem; ++elemI)
300  {
301  string arrayName(select->GetArrayName(elemI));
302 
303  forAll(selections, elemI)
304  {
305  if (selections[elemI] == arrayName)
306  {
307  select->EnableArray(arrayName.c_str());
308  break;
309  }
310  }
311  }
312 }
313 
314 
316 (
317  boolList& status,
318  vtkDataArraySelection* selection
319 )
320 {
321  if (debug)
322  {
323  Info<< "<beg> Foam::vtkPV3blockMesh::updateBoolListStatus" << endl;
324  }
325 
326  const label nElem = selection->GetNumberOfArrays();
327  if (status.size() != nElem)
328  {
329  status.setSize(nElem);
330  status = false;
331  }
332 
333  forAll(status, elemI)
334  {
335  const int setting = selection->GetArraySetting(elemI);
336 
337  status[elemI] = setting;
338 
339  if (debug)
340  {
341  Info<< " part[" << elemI << "] = "
342  << status[elemI]
343  << " : " << selection->GetArrayName(elemI) << endl;
344  }
345  }
346  if (debug)
347  {
348  Info<< "<end> Foam::vtkPV3blockMesh::updateBoolListStatus" << endl;
349  }
350 }
351 
352 
353 
354 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
355 
356 
357 // ************************************************************************* //
Foam::vtkPV3blockMesh::AddToBlock
static void AddToBlock(vtkMultiBlockDataSet *output, vtkDataSet *dataset, const arrayRange &, const label datasetNo, const std::string &datasetName)
Definition: vtkPV3blockMeshUtils.C:71
Foam::vtkPV3blockMesh::getSelectedArrayEntries
static stringList getSelectedArrayEntries(vtkDataArraySelection *)
Retrieve the current selections.
Definition: vtkPV3blockMeshUtils.C:213
Foam::vtkPV3blockMesh::arrayRange
Bookkeeping for GUI checklists and the multi-block organization.
Definition: vtkPV3blockMesh.H:89
Foam::word::valid
static bool valid(char)
Is this character valid for a word.
Definition: wordI.H:117
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::vtkPV3blockMesh::updateBoolListStatus
static void updateBoolListStatus(boolList &, vtkDataArraySelection *)
Update boolList from GUI selection.
Definition: vtkPV3blockMeshUtils.C:317
Foam::vtkPV3blockMesh::GetNumberOfDataSets
static label GetNumberOfDataSets(vtkMultiBlockDataSet *output, const arrayRange &)
Definition: vtkPV3blockMeshUtils.C:153
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::vtkPV3blockMesh::getSelected
static wordHashSet getSelected(vtkDataArraySelection *)
Retrieve the current selections.
Definition: vtkPV3blockMeshUtils.C:172
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Info
messageStream Info
Foam::vtkPV3blockMesh::GetDataSetFromBlock
static vtkDataSet * GetDataSetFromBlock(vtkMultiBlockDataSet *output, const arrayRange &, const label datasetNo)
Definition: vtkPV3blockMeshUtils.C:131
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::List::setSize
void setSize(const label)
Reset size of List.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::vtkPV3blockMesh::setSelectedArrayEntries
static void setSelectedArrayEntries(vtkDataArraySelection *, const stringList &)
Set selection(s)
Definition: vtkPV3blockMeshUtils.C:291
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
vtkPV3blockMesh.H