Go to the documentation of this file.
147 #include "readFields.H"
159 #include "writeAreaFields.H"
160 #include "writeDimFields.H"
161 #include "writeVolFields.H"
162 #include "writePointFields.H"
171 const polyBoundaryMesh&
patches,
172 const wordRes& allow,
192 for (
const label patchi : indices)
194 const polyPatch& pp =
patches[patchi];
196 if (isType<emptyPolyPatch>(pp))
200 else if (Pstream::parRun() &&
bool(isA<processorPolyPatch>(pp)))
205 indices[
count] = patchi;
209 indices.resize(
count);
218 vtk::outputOptions getOutputOptions(
const argList&
args)
221 vtk::outputOptions opts;
229 if (
sizeof(
floatScalar) != 4 ||
sizeof(label) != 4)
234 <<
"Using ASCII rather than legacy binary VTK format since "
235 <<
"floatScalar and/or label are not 4 bytes in size."
255 int main(
int argc,
char *argv[])
259 "General OpenFOAM to VTK file writer"
261 timeSelector::addOptions();
264 argList::setAdvanced(
"decomposeParDict");
265 argList::setAdvanced(
"noFunctionObjects");
267 argList::addBoolOption
270 "Write in ASCII format instead of binary"
272 argList::addBoolOption
275 "Write legacy format instead of xml",
278 argList::addBoolOption
281 "Decompose polyhedral cells into tets/pyramids",
284 argList::ignoreOptionCompat
289 argList::ignoreOptionCompat
299 "Convert mesh subset corresponding to specified cellSet",
306 "Convert mesh subset corresponding to specified cellZone",
313 "Convert specified faceSet only",
320 "Convert specified pointSet only",
327 "Specify single or multiple faceZones to write\n"
328 "Eg, 'cells' or '( slice \"mfp-.*\" )'.",
336 "Specify single or multiple fields to write (all by default)\n"
337 "Eg, 'T' or '(p T U \"alpha.*\")'"
340 argList::addBoolOption
343 "Write field values on processor boundaries only",
346 argList::addBoolOption
349 "Write surfaceScalarFields (eg, phi)",
352 argList::addBoolOption
355 "Write finite area fields",
358 argList::addOptionCompat(
"finite-area", {
"finiteAreaFields", 2012});
359 argList::addBoolOption
362 "Use cell value on patches instead of patch value itself",
365 argList::addBoolOption
368 "Suppress output for boundary patches"
370 argList::addBoolOption
373 "Suppress output for internal volume mesh"
375 argList::addBoolOption
378 "Suppress writing lagrangian positions and fields"
380 argList::addOptionCompat(
"no-lagrangian", {
"noLagrangian", 1806});
382 argList::addBoolOption
385 "Suppress conversion of pointFields. No interpolated PointData."
387 argList::addOptionCompat(
"no-point-data", {
"noPointValues", 1806});
389 argList::addBoolOption
392 "Additional mesh id fields (cellID, procID, patchID)",
396 argList::addBoolOption
399 "Additional pointID field for internal mesh",
403 argList::addBoolOption
406 "Combine all patches into a single file"
408 argList::addOptionCompat(
"one-boundary", {
"allPatches", 1806});
416 "Specify single patch or multiple patches to write\n"
417 "Eg, 'top' or '( front \".*back\" )'"
423 "Exclude single or multiple patches from writing\n"
424 "Eg, 'outlet' or '( inlet \".*Wall\" )'",
427 argList::ignoreOptionCompat
429 {
"noFaceZones", 1806},
432 argList::ignoreOptionCompat
437 argList::ignoreOptionCompat
439 {
"useTimeName", 1806},
442 argList::addBoolOption
445 "Remove any existing VTK output directory"
451 "Directory name for VTK output (default: 'VTK')"
456 const bool decomposePoly =
args.
found(
"poly-decomp");
457 const bool doBoundary = !
args.
found(
"no-boundary");
458 const bool doInternal = !
args.
found(
"no-internal");
459 const bool doLagrangian = !
args.
found(
"no-lagrangian");
460 const bool doFiniteArea =
args.
found(
"finite-area");
461 const bool doSurfaceFields =
args.
found(
"surfaceFields");
463 const bool oneBoundary =
args.
found(
"one-boundary") && doBoundary;
464 const bool nearCellValue =
args.
found(
"nearCellValue") && doBoundary;
466 const vtk::outputOptions writeOpts = getOutputOptions(
args);
468 bool processorFieldsOnly =
false;
472 if (!Pstream::parRun())
474 Info<<
"Ignoring processor patch writing in serial"
477 else if (writeOpts.legacy())
479 Info<<
"Ignoring processor patch writing in legacy format"
484 processorFieldsOnly =
true;
486 Info<<
"Writing processor patch fields only"
493 Info<<
"Using neighbouring cell value instead of patch value"
497 const bool doPointValues = !
args.
found(
"no-point-data");
500 Info<<
"Point fields and interpolated point data"
501 <<
" disabled with the '-no-point-data' option"
505 const bool withPointIds =
args.
found(
"with-point-ids");
508 Info<<
"Write point ids requested";
512 Info<<
", but ignored due to the '-no-point-data' option";
518 const bool withMeshIds =
args.
found(
"with-ids");
521 Info<<
"Writing mesh ids (cell, patch, proc) requested" <<
nl;
524 wordRes includePatches, excludePatches;
540 wordRes selectedFields;
541 const bool useFieldFilter =
545 const wordRes selectedFaceZones(
args.
getList<wordRe>(
"faceZones",
false));
552 HashTable<vtk::seriesWriter, fileName> vtkSeries;
558 word cellSelectionName;
562 fvMeshSubsetProxy::subsetType cellSubsetType = fvMeshSubsetProxy::NONE;
570 vtkName = cellSelectionName;
571 cellSubsetType = fvMeshSubsetProxy::SET;
573 Info<<
"Converting cellSet " << cellSelectionName
574 <<
" only. New outside faces as \"oldInternalFaces\"."
579 vtkName = cellSelectionName;
580 cellSubsetType = fvMeshSubsetProxy::ZONE;
582 Info<<
"Converting cellZone " << cellSelectionName
583 <<
" only. New outside faces as \"oldInternalFaces\"."
595 : {
"cellSet",
"cellZone",
"faceSet",
"pointSet" }
600 Info<<
"Ignoring -" << opt <<
" for multi-regions" <<
nl;
613 if (Pstream::master())
625 fileName regionalDir(outputDir/
regionDir);
629 Info<<
"Removing old directory "
642 Info<<
"Initial memory " << mem.update().size() <<
" kB" <<
endl;
645 #include "createMeshAccounting.H"
647 Info<<
"VTK mesh topology: "
648 << timer.cpuTimeIncrement() <<
" s, "
649 << mem.update().size() <<
" kB" <<
endl;
656 runTime.setTime(timeDirs[timei], timei);
659 const scalar timeValue =
runTime.value();
688 polyMesh::readUpdateState meshState =
689 meshProxy.readUpdate();
691 const fvMesh&
mesh = meshProxy.mesh();
695 meshState == polyMesh::TOPO_CHANGE
696 || meshState == polyMesh::TOPO_PATCH_CHANGE
700 vtuMeshCells.clear();
713 IOobjectList objects(meshProxy.baseMesh(),
runTime.timeName());
717 objects.filterObjects(selectedFields);
726 objects.filterClasses
728 [](
const word& clsName)
736 if (processorFieldsOnly)
744 #include "convertVolumeFields.H"
750 #include "convertAreaFields.H"
753 #include "convertLagrangian.H"
761 outputDir/vtkName +
"-regions" + timeDesc +
".vtm"
764 vtmMultiRegion.setTime(timeValue);
767 fileName seriesName(vtk::seriesWriter::base(
outputName));
769 vtk::seriesWriter& series = vtkSeries(seriesName);
776 series.load(seriesName,
true, timeValue);
780 series.write(seriesName);
784 << timer.cpuTimeIncrement() <<
" s, "
785 << mem.update().size() <<
" kB" <<
endl;
790 << timer.elapsedCpuTime() <<
" s, "
791 << mem.update().peak() <<
" kB (peak)\n" <<
endl;
List< label > labelList
A List of labels.
Write surface fields from volume mesh.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
float floatScalar
A typedef for float.
const fileName & globalCaseName() const noexcept
Return global case name.
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with 'name()' that matches.
bool readListIfPresent(const word &optName, List< T > &list) const
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< instant > instantList
List of instants.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Code chunk for converting volume fields on processor boundaries, included by foamToVTK.
#define forAll(list, i)
Loop across all elements in list.
word outputName("finiteArea-edges.obj")
cpuTimeCxx cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Code chunk for converting face and point sets - included by foamToVTK.
Code chunk for post-processing surface fields to VTK PolyData.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
PtrList< fvMeshSubsetProxy > meshProxies(meshes.size())
bool rmDir(const fileName &directory, const bool silent=false)
Remove a directory and its contents (optionally silencing warnings)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
PtrList< vtk::vtuCells > vtuMappings(meshes.size())
fileName globalPath() const
Return the full path to the global case.
const polyBoundaryMesh & patches
List< T > getList(const label index) const
Get a List of values from the argument at index.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Operations on lists of strings.
Write topoSet in VTK format.
vector point
Point is a vector.
Foam::argList args(argc, argv)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
#define WarningInFunction
Report a warning using Foam::Warning.
fileName relativePath(const fileName &input, const bool caseTag=false) const
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
bool found(const word &optName) const
Return true if the named option is found.