1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Misc helper methods and utilities
27 \*---------------------------------------------------------------------------*/
29 #include "vtkPV3Foam.H"
30 #include "vtkPV3FoamReader.h"
38 #include "vtkDataArraySelection.h"
39 #include "vtkDataSet.h"
40 #include "vtkMultiBlockDataSet.h"
41 #include "vtkInformation.h"
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void Foam::vtkPV3Foam::AddToBlock
47 vtkMultiBlockDataSet* output,
49 const partInfo& selector,
50 const label datasetNo,
51 const string& datasetName
54 const int blockNo = selector.block();
56 vtkDataObject* blockDO = output->GetBlock(blockNo);
57 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
63 FatalErrorIn("Foam::vtkPV3Foam::AddToBlock")
64 << "Block already has a vtkDataSet assigned to it"
69 block = vtkMultiBlockDataSet::New();
70 output->SetBlock(blockNo, block);
76 Info<< "block[" << blockNo << "] has "
77 << block->GetNumberOfBlocks()
78 << " datasets prior to adding set " << datasetNo
79 << " with name: " << datasetName << endl;
82 block->SetBlock(datasetNo, dataset);
84 // name the block when assigning dataset 0
87 output->GetMetaData(blockNo)->Set
89 vtkCompositeDataSet::NAME(),
94 if (datasetName.size())
96 block->GetMetaData(datasetNo)->Set
98 vtkCompositeDataSet::NAME(),
105 vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock
107 vtkMultiBlockDataSet* output,
108 const partInfo& selector,
109 const label datasetNo
112 const int blockNo = selector.block();
114 vtkDataObject* blockDO = output->GetBlock(blockNo);
115 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
119 return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
126 // ununsed at the moment
127 Foam::label Foam::vtkPV3Foam::GetNumberOfDataSets
129 vtkMultiBlockDataSet* output,
130 const partInfo& selector
133 const int blockNo = selector.block();
135 vtkDataObject* blockDO = output->GetBlock(blockNo);
136 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
139 return block->GetNumberOfBlocks();
146 Foam::word Foam::vtkPV3Foam::getPartName(int partId)
148 return getFirstWord(reader_->GetPartArrayName(partId));
152 Foam::wordHashSet Foam::vtkPV3Foam::getSelected
154 vtkDataArraySelection* select
157 int nElem = select->GetNumberOfArrays();
158 wordHashSet selections(2*nElem);
160 for (int elemI=0; elemI < nElem; ++elemI)
162 if (select->GetArraySetting(elemI))
164 selections.insert(getFirstWord(select->GetArrayName(elemI)));
172 Foam::wordHashSet Foam::vtkPV3Foam::getSelected
174 vtkDataArraySelection* select,
175 const partInfo& selector
178 int nElem = select->GetNumberOfArrays();
179 wordHashSet selections(2*nElem);
181 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
183 if (select->GetArraySetting(elemI))
185 selections.insert(getFirstWord(select->GetArrayName(elemI)));
193 Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
195 vtkDataArraySelection* select
198 stringList selections(select->GetNumberOfArrays());
201 forAll(selections, elemI)
203 if (select->GetArraySetting(elemI))
205 selections[nElem++] = select->GetArrayName(elemI);
208 selections.setSize(nElem);
213 label nElem = select->GetNumberOfArrays();
215 for (int elemI = 0; elemI < nElem; ++elemI)
217 Info<< " \"" << select->GetArrayName(elemI) << "\"";
219 Info<< " )\nselected(";
221 forAll(selections, elemI)
223 Info<< " " << selections[elemI];
232 Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
234 vtkDataArraySelection* select,
235 const partInfo& selector
238 stringList selections(selector.size());
241 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
243 if (select->GetArraySetting(elemI))
245 selections[nElem++] = select->GetArrayName(elemI);
248 selections.setSize(nElem);
254 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
256 Info<< " \"" << select->GetArrayName(elemI) << "\"";
258 Info<< " )\nselected(";
260 forAll(selections, elemI)
262 Info<< " " << selections[elemI];
271 void Foam::vtkPV3Foam::setSelectedArrayEntries
273 vtkDataArraySelection* select,
274 const stringList& selections
277 const int nElem = select->GetNumberOfArrays();
278 select->DisableAllArrays();
280 // Loop through entries, setting values from selectedEntries
281 for (int elemI=0; elemI < nElem; ++elemI)
283 string arrayName(select->GetArrayName(elemI));
285 forAll(selections, elemI)
287 if (selections[elemI] == arrayName)
289 select->EnableArray(arrayName.c_str());
297 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
299 // parse these bits of info from /proc/meminfo (Linux)
301 // MemTotal: 2062660 kB
302 // MemFree: 1124400 kB
304 // used = MemTotal - MemFree is what the free(1) uses.
306 void Foam::vtkPV3Foam::printMemory()
308 const char* meminfo = "/proc/meminfo";
312 IFstream is(meminfo);
318 while (is.getLine(line).good())
323 if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
325 if (!strcmp(tag, "MemTotal:"))
329 else if (!strcmp(tag, "MemFree:"))
336 Info << "memUsed: " << (memTotal - memFree) << " kB\n";
341 // ************************************************************************* //