147 #include "readFields.H"
160 #include "writeDimFields.H"
161 #include "writeVolFields.H"
162 #include "writePointFields.H"
170 const polyBoundaryMesh&
patches,
171 const wordRes& allow,
191 for (
const label patchi : indices)
193 const polyPatch& pp =
patches[patchi];
195 if (isType<emptyPolyPatch>(pp))
199 else if (Pstream::parRun() &&
bool(isA<processorPolyPatch>(pp)))
204 indices[
count] = patchi;
208 indices.resize(
count);
217 vtk::outputOptions getOutputOptions(
const argList&
args)
220 vtk::outputOptions opts;
228 if (
sizeof(
floatScalar) != 4 ||
sizeof(label) != 4)
233 <<
"Using ASCII rather than legacy binary VTK format since "
234 <<
"floatScalar and/or label are not 4 bytes in size."
254 int main(
int argc,
char *argv[])
258 "General OpenFOAM to VTK file writer"
260 timeSelector::addOptions();
263 argList::setAdvanced(
"decomposeParDict");
264 argList::setAdvanced(
"noFunctionObjects");
266 argList::addBoolOption
269 "Write in ASCII format instead of binary"
271 argList::addBoolOption
274 "Write legacy format instead of xml",
277 argList::addBoolOption
280 "Decompose polyhedral cells into tets/pyramids",
283 argList::ignoreOptionCompat
288 argList::ignoreOptionCompat
298 "Convert mesh subset corresponding to specified cellSet",
305 "Convert mesh subset corresponding to specified cellZone",
312 "Convert specified faceSet only",
319 "Convert specified pointSet only",
326 "Specify single or multiple faceZones to write\n"
327 "Eg, 'cells' or '( slice \"mfp-.*\" )'.",
335 "Specify single or multiple fields to write (all by default)\n"
336 "Eg, 'T' or '(p T U \"alpha.*\")'"
339 argList::addBoolOption
342 "Write field values on processor boundaries only",
345 argList::addBoolOption
348 "Write surfaceScalarFields (eg, phi)",
351 argList::addBoolOption
354 "Write finite area fields",
357 argList::addBoolOption
360 "Use cell value on patches instead of patch value itself",
363 argList::addBoolOption
366 "Suppress output for boundary patches"
368 argList::addBoolOption
371 "Suppress output for internal volume mesh"
373 argList::addBoolOption
376 "Suppress writing lagrangian positions and fields"
378 argList::addOptionCompat(
"no-lagrangian", {
"noLagrangian", 1806});
380 argList::addBoolOption
383 "Suppress conversion of pointFields. No interpolated PointData."
385 argList::addOptionCompat(
"no-point-data", {
"noPointValues", 1806});
387 argList::addBoolOption
390 "Additional mesh id fields (cellID, procID, patchID)",
394 argList::addBoolOption
397 "Additional pointID field for internal mesh",
401 argList::addBoolOption
404 "Combine all patches into a single file"
406 argList::addOptionCompat(
"one-boundary", {
"allPatches", 1806});
414 "Operate on selected regions from regionProperties.\n"
415 "Eg, '( gas \"solid.*\" )'"
417 argList::addBoolOption
420 "Operate on all regions in regionProperties"
427 "Specify single patch or multiple patches to write\n"
428 "Eg, 'top' or '( front \".*back\" )'"
434 "Exclude single or multiple patches from writing\n"
435 "Eg, 'outlet' or '( inlet \".*Wall\" )'",
438 argList::ignoreOptionCompat
440 {
"noFaceZones", 1806},
443 argList::ignoreOptionCompat
448 argList::ignoreOptionCompat
450 {
"useTimeName", 1806},
453 argList::addBoolOption
456 "Remove any existing VTK output directory"
462 "Directory name for VTK output (default: 'VTK')"
467 const bool decomposePoly =
args.
found(
"poly-decomp");
468 const bool doBoundary = !
args.
found(
"no-boundary");
469 const bool doInternal = !
args.
found(
"no-internal");
470 const bool doLagrangian = !
args.
found(
"no-lagrangian");
471 const bool doFiniteArea =
args.
found(
"finiteAreaFields");
472 const bool doSurfaceFields =
args.
found(
"surfaceFields");
474 const bool oneBoundary =
args.
found(
"one-boundary") && doBoundary;
475 const bool nearCellValue =
args.
found(
"nearCellValue") && doBoundary;
476 const bool allRegions =
args.
found(
"allRegions");
478 const vtk::outputOptions writeOpts = getOutputOptions(
args);
480 bool processorFieldsOnly =
false;
484 if (!Pstream::parRun())
486 Info<<
"Ignoring processor patch writing in serial"
489 else if (writeOpts.legacy())
491 Info<<
"Ignoring processor patch writing in legacy format"
496 processorFieldsOnly =
true;
498 Info<<
"Writing processor patch fields only"
505 Info<<
"Using neighbouring cell value instead of patch value"
509 const bool doPointValues = !
args.
found(
"no-point-data");
512 Info<<
"Point fields and interpolated point data"
513 <<
" disabled with the '-no-point-data' option"
517 const bool withPointIds =
args.
found(
"with-point-ids");
520 Info<<
"Write point ids requested";
524 Info<<
", but ignored due to the '-no-point-data' option";
530 const bool withMeshIds =
args.
found(
"with-ids");
533 Info<<
"Writing mesh ids (cell, patch, proc) requested" <<
nl;
536 wordRes includePatches, excludePatches;
552 wordRes selectedFields;
553 const bool useFieldFilter =
557 const wordRes selectedFaceZones(
args.
getList<wordRe>(
"faceZones",
false));
564 HashTable<vtk::seriesWriter, fileName> vtkSeries;
567 wordRes selectRegions;
571 regionProperties(
runTime, IOobject::READ_IF_PRESENT).names();
573 if (regionNames.empty())
576 <<
"No regionProperties - assuming default region"
579 regionNames.resize(1);
580 regionNames.first() = fvMesh::defaultRegion;
584 Info<<
"Using all regions in regionProperties" <<
nl
590 if (selectRegions.empty())
592 regionNames.resize(1);
593 regionNames.first() = fvMesh::defaultRegion;
597 selectRegions.size() == 1 && selectRegions.first().isLiteral()
601 regionNames.resize(1);
602 regionNames.first() = selectRegions.first();
607 regionProperties(
runTime, IOobject::READ_IF_PRESENT).names();
609 if (regionNames.empty())
612 <<
"No regionProperties - assuming default region"
615 regionNames.resize(1);
616 regionNames.first() = fvMesh::defaultRegion;
622 if (regionNames.empty())
624 Info<<
"No matching regions ... stopping" <<
nl <<
endl;
628 Info<<
"Using matching regions: "
635 regionNames.resize(1);
636 regionNames.first() =
642 word cellSelectionName;
646 fvMeshSubsetProxy::subsetType cellSubsetType = fvMeshSubsetProxy::NONE;
650 if (regionNames.size() == 1)
654 vtkName = cellSelectionName;
655 cellSubsetType = fvMeshSubsetProxy::SET;
657 Info<<
"Converting cellSet " << cellSelectionName
658 <<
" only. New outside faces as \"oldInternalFaces\"."
663 vtkName = cellSelectionName;
664 cellSubsetType = fvMeshSubsetProxy::ZONE;
666 Info<<
"Converting cellZone " << cellSelectionName
667 <<
" only. New outside faces as \"oldInternalFaces\"."
679 : {
"cellSet",
"cellZone",
"faceSet",
"pointSet" }
684 Info<<
"Ignoring -" << opt <<
" for multi-regions" <<
nl;
692 Info<<
"Initial memory " << mem.update().size() <<
" kB" <<
endl;
694 #include "createMeshes.H"
703 if (Pstream::master())
717 regionDir = outputDir;
722 Info<<
"Removing old directory "
736 runTime.setTime(timeDirs[timei], timei);
739 const scalar timeValue =
runTime.value();
749 forAll(regionNames, regioni)
751 const word&
regionName = regionNames[regioni];
753 fileName regionPrefix;
766 polyMesh::readUpdateState meshState =
767 meshProxy.readUpdate();
769 const fvMesh&
mesh = meshProxy.mesh();
773 meshState == polyMesh::TOPO_CHANGE
774 || meshState == polyMesh::TOPO_PATCH_CHANGE
778 vtuMeshCells.clear();
791 IOobjectList objects(meshProxy.baseMesh(),
runTime.timeName());
795 objects.filterObjects(selectedFields);
804 objects.filterClasses
806 [](
const word& clsName)
814 if (processorFieldsOnly)
822 #include "convertVolumeFields.H"
831 #include "convertLagrangian.H"
835 if (Pstream::master() && regionNames.size() > 1)
839 outputDir/vtkName +
"-regions" + timeDesc +
".vtm"
842 vtmMultiRegion.setTime(timeValue);
843 vtmMultiRegion.write(outputName);
845 fileName seriesName(vtk::seriesWriter::base(outputName));
847 vtk::seriesWriter& series = vtkSeries(seriesName);
854 series.load(seriesName,
true, timeValue);
857 series.append(timeValue, outputName);
858 series.write(seriesName);
862 << timer.cpuTimeIncrement() <<
" s, "
863 << mem.update().size() <<
" kB" <<
endl;
868 << timer.elapsedCpuTime() <<
" s, "
869 << mem.update().peak() <<
" kB (peak)\n" <<
endl;