1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Misc helper methods and utilities
28 \*---------------------------------------------------------------------------*/
30 #include "vtkPV3Foam.H"
31 #include "vtkPV3FoamReader.h"
39 #include "vtkDataArraySelection.h"
40 #include "vtkDataSet.h"
41 #include "vtkMultiBlockDataSet.h"
42 #include "vtkInformation.h"
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void Foam::vtkPV3Foam::AddToBlock
48 vtkMultiBlockDataSet* output,
50 const partInfo& selector,
51 const label datasetNo,
52 const string& datasetName
55 const int blockNo = selector.block();
57 vtkDataObject* blockDO = output->GetBlock(blockNo);
58 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
64 FatalErrorIn("Foam::vtkPV3Foam::AddToBlock")
65 << "Block already has a vtkDataSet assigned to it"
70 block = vtkMultiBlockDataSet::New();
71 output->SetBlock(blockNo, block);
77 Info<< "block[" << blockNo << "] has "
78 << block->GetNumberOfBlocks()
79 << " datasets prior to adding set " << datasetNo
80 << " with name: " << datasetName << endl;
83 block->SetBlock(datasetNo, dataset);
85 // name the block when assigning dataset 0
88 output->GetMetaData(blockNo)->Set
90 vtkCompositeDataSet::NAME(),
95 if (datasetName.size())
97 block->GetMetaData(datasetNo)->Set
99 vtkCompositeDataSet::NAME(),
106 vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock
108 vtkMultiBlockDataSet* output,
109 const partInfo& selector,
110 const label datasetNo
113 const int blockNo = selector.block();
115 vtkDataObject* blockDO = output->GetBlock(blockNo);
116 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
120 return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
127 // ununsed at the moment
128 Foam::label Foam::vtkPV3Foam::GetNumberOfDataSets
130 vtkMultiBlockDataSet* output,
131 const partInfo& selector
134 const int blockNo = selector.block();
136 vtkDataObject* blockDO = output->GetBlock(blockNo);
137 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
140 return block->GetNumberOfBlocks();
147 Foam::word Foam::vtkPV3Foam::getPartName(int partId)
149 return getFirstWord(reader_->GetPartArrayName(partId));
153 Foam::wordHashSet Foam::vtkPV3Foam::getSelected
155 vtkDataArraySelection* select
158 int nElem = select->GetNumberOfArrays();
159 wordHashSet selections(2*nElem);
161 for (int elemI=0; elemI < nElem; ++elemI)
163 if (select->GetArraySetting(elemI))
165 selections.insert(getFirstWord(select->GetArrayName(elemI)));
173 Foam::wordHashSet Foam::vtkPV3Foam::getSelected
175 vtkDataArraySelection* select,
176 const partInfo& selector
179 int nElem = select->GetNumberOfArrays();
180 wordHashSet selections(2*nElem);
182 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
184 if (select->GetArraySetting(elemI))
186 selections.insert(getFirstWord(select->GetArrayName(elemI)));
194 Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
196 vtkDataArraySelection* select
199 stringList selections(select->GetNumberOfArrays());
202 forAll(selections, elemI)
204 if (select->GetArraySetting(elemI))
206 selections[nElem++] = select->GetArrayName(elemI);
209 selections.setSize(nElem);
214 label nElem = select->GetNumberOfArrays();
216 for (int elemI = 0; elemI < nElem; ++elemI)
218 Info<< " \"" << select->GetArrayName(elemI) << "\"";
220 Info<< " )\nselected(";
222 forAll(selections, elemI)
224 Info<< " " << selections[elemI];
233 Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
235 vtkDataArraySelection* select,
236 const partInfo& selector
239 stringList selections(selector.size());
242 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
244 if (select->GetArraySetting(elemI))
246 selections[nElem++] = select->GetArrayName(elemI);
249 selections.setSize(nElem);
255 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
257 Info<< " \"" << select->GetArrayName(elemI) << "\"";
259 Info<< " )\nselected(";
261 forAll(selections, elemI)
263 Info<< " " << selections[elemI];
272 void Foam::vtkPV3Foam::setSelectedArrayEntries
274 vtkDataArraySelection* select,
275 const stringList& selections
278 const int nElem = select->GetNumberOfArrays();
279 select->DisableAllArrays();
281 // Loop through entries, setting values from selectedEntries
282 for (int elemI=0; elemI < nElem; ++elemI)
284 string arrayName(select->GetArrayName(elemI));
286 forAll(selections, elemI)
288 if (selections[elemI] == arrayName)
290 select->EnableArray(arrayName.c_str());
298 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
300 // parse these bits of info from /proc/meminfo (Linux)
302 // MemTotal: 2062660 kB
303 // MemFree: 1124400 kB
305 // used = MemTotal - MemFree is what the free(1) uses.
307 void Foam::vtkPV3Foam::printMemory()
309 const char* meminfo = "/proc/meminfo";
313 IFstream is(meminfo);
319 while (is.getLine(line).good())
324 if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
326 if (!strcmp(tag, "MemTotal:"))
330 else if (!strcmp(tag, "MemFree:"))
337 Info << "memUsed: " << (memTotal - memFree) << " kB\n";
342 // ************************************************************************* //