173struct polyBoundaryPatchSelector
190 const bool excludeProcPatches = UPstream::parRun();
194 for (
const label patchi : ids)
196 const auto&
pp =
pbm[patchi];
198 if (isType<emptyPolyPatch>(
pp))
202 else if (excludeProcPatches &&
bool(isA<processorPolyPatch>(
pp)))
222vtk::outputOptions getOutputOptions(
const argList&
args)
225 vtk::outputOptions opts;
227 if (
args.found(
"legacy"))
231 if (!
args.found(
"ascii"))
233 if constexpr (
sizeof(float) != 4 ||
sizeof(label) != 4)
238 <<
"Using ASCII rather than legacy binary VTK format since "
239 <<
"float and/or label are not 4 bytes in size."
250 opts.ascii(
args.found(
"ascii"));
259int main(
int argc,
char *argv[])
263 "General OpenFOAM to VTK file writer"
265 timeSelector::addOptions();
268 argList::setAdvanced(
"decomposeParDict");
270 argList::addVerboseOption();
272 argList::addBoolOption
275 "Write in ASCII format instead of binary"
277 argList::addBoolOption
280 "Write legacy format instead of xml",
283 argList::addBoolOption
286 "Decompose polyhedral cells into tets/pyramids",
289 argList::ignoreOptionCompat
294 argList::ignoreOptionCompat
304 "Convert mesh subset corresponding to specified cellSet",
311 "Convert mesh subset corresponding to specified cellZone",
318 "Convert specified faceSet only",
325 "Convert specified pointSet only",
332 "Specify single or multiple faceZones to write\n"
333 "Eg, 'cells' or '( slice \"mfp-.*\" )'.",
340 "Specify single or multiple fields to write (all by default)\n"
341 "Eg, 'T' or '(p T U \"alpha.*\")'"
347 "Exclude single or multiple fields",
350 argList::addBoolOption
353 "Suppress conversion of fields"
356 argList::addBoolOption
359 "Write field values on processor boundaries only",
362 argList::addBoolOption
365 "Write surfaceScalarFields (eg, phi)",
368 argList::addBoolOption
371 "Suppress output of finite-area mesh/fields",
374 argList::ignoreOptionCompat
376 {
"finite-area", 2112},
379 argList::ignoreOptionCompat
381 {
"finiteAreaFields", 2012},
385 argList::addBoolOption
388 "Use cell value on patches instead of patch value itself",
391 argList::addBoolOption
394 "Suppress output for boundary patches"
396 argList::addBoolOption
399 "Suppress output for internal volume mesh"
401 argList::addBoolOption
404 "Suppress writing lagrangian positions and fields"
406 argList::addOptionCompat(
"no-lagrangian", {
"noLagrangian", 1806});
408 argList::addBoolOption
411 "Suppress conversion of pointFields. No interpolated PointData."
413 argList::addOptionCompat(
"no-point-data", {
"noPointValues", 1806});
415 argList::addBoolOption
418 "Additional mesh id fields (cellID, procID, patchID)",
422 argList::addBoolOption
425 "Additional pointID field for internal mesh",
429 argList::addBoolOption
432 "Combine all patches into a single file"
434 argList::addOptionCompat(
"one-boundary", {
"allPatches", 1806});
443 "Specify single patch or multiple patches to write\n"
444 "Eg, 'top' or '( front \".*back\" )'"
450 "Exclude single or multiple patches from writing\n"
451 "Eg, 'outlet' or '( inlet \".*Wall\" )'",
454 argList::addOptionCompat(
"exclude-patches", {
"excludePatches", 2112});
456 argList::ignoreOptionCompat
458 {
"noFaceZones", 1806},
461 argList::ignoreOptionCompat
466 argList::ignoreOptionCompat
468 {
"useTimeName", 1806},
471 argList::addBoolOption
474 "Remove any existing VTK output directory"
480 "Directory name for VTK output (default: 'VTK')"
484 regionModels::allowFaModels(
false);
492 const bool decomposePoly =
args.found(
"poly-decomp");
493 const bool doBoundary = !
args.found(
"no-boundary");
494 const bool doInternal = !
args.found(
"no-internal");
495 const bool doLagrangian = !
args.found(
"no-lagrangian");
496 const bool doFiniteArea = !
args.found(
"no-finite-area");
497 const bool doSurfaceFields =
args.found(
"surfaceFields");
498 const bool oneBoundary =
args.found(
"one-boundary") && doBoundary;
499 const bool nearCellValue =
args.found(
"nearCellValue") && doBoundary;
501 const vtk::outputOptions writeOpts = getOutputOptions(
args);
503 bool processorFieldsOnly =
false;
505 if (
args.found(
"processor-fields"))
507 if (!UPstream::parRun())
509 Info<<
"Ignoring processor patch writing in serial"
512 else if (writeOpts.legacy())
514 Info<<
"Ignoring processor patch writing in legacy format"
519 processorFieldsOnly =
true;
521 Info<<
"Writing processor patch fields only"
528 Info<<
"Using neighbouring cell value instead of patch value"
532 bool doPointValues = !
args.found(
"no-point-data");
535 Info<<
"Point fields and interpolated point data"
536 <<
" disabled with the '-no-point-data' option"
540 const bool withPointIds =
args.found(
"with-point-ids");
543 Info<<
"Write point ids requested";
547 Info<<
", but ignored due to the '-no-point-data' option";
553 const bool withMeshIds =
args.found(
"with-ids");
556 Info<<
"Writing mesh ids (cell, patch, proc) requested" <<
nl;
560 polyBoundaryPatchSelector patchSelector;
566 auto& slot = patchSelector.allow_;
567 args.readListIfPresent<wordRe>(
"patches", slot)
574 auto& slot = patchSelector.deny_;
575 args.readListIfPresent<wordRe>(
"exclude-patches", slot)
583 wordRes includedFields, excludedFields;
584 bool doConvertFields = !
args.found(
"no-fields");
587 if (
args.readListIfPresent<wordRe>(
"fields", includedFields))
589 Info<<
"Including fields "
592 if (includedFields.empty())
597 doConvertFields =
false;
598 Info<<
"Field conversion disabled by '-fields ()' option" <<
nl
599 <<
"Should use -no-fields instead" <<
endl;
602 if (
args.readListIfPresent<wordRe>(
"exclude-fields", excludedFields))
604 Info<<
"Excluding fields "
608 if (!doConvertFields)
610 includedFields.clear();
611 excludedFields.clear();
616 Info<<
"Field conversion disabled with the '-no-fields' option" <<
nl;
619 const wordRes::filter fieldSelector(includedFields, excludedFields);
622 const wordRes selectedFaceZones(
args.getList<wordRe>(
"faceZones",
false));
629 HashTable<vtk::seriesWriter, fileName> vtkSeries;
645 word cellSelectionName;
649 fvMeshSubsetProxy::subsetType cellSubsetType = fvMeshSubsetProxy::NONE;
651 string vtkName =
args.globalCaseName();
655 if (
args.readIfPresent(
"cellSet", cellSelectionName))
657 vtkName = cellSelectionName;
658 cellSubsetType = fvMeshSubsetProxy::SET;
660 Info<<
"Converting cellSet " << cellSelectionName
661 <<
" only. New outside faces as \"oldInternalFaces\"."
664 else if (
args.readIfPresent(
"cellZone", cellSelectionName))
666 vtkName = cellSelectionName;
667 cellSubsetType = fvMeshSubsetProxy::ZONE;
669 Info<<
"Converting cellZone " << cellSelectionName
670 <<
" only. New outside faces as \"oldInternalFaces\"."
674 args.readIfPresent(
"faceSet", faceSetName);
675 args.readIfPresent(
"pointSet", pointSetName);
681 const char *
const opt
682 : {
"cellSet",
"cellZone",
"faceSet",
"pointSet" }
687 Info<<
"Ignoring -" << opt <<
" for multi-regions" <<
nl;
696 const word vtkDirName =
args.getOrDefault<word>(
"name",
"VTK");
698 const fileName outputDir(
args.globalPath()/vtkDirName);
700 if (UPstream::master())
707 fileName regionOutDir(outputDir/polyMesh::regionName(
regionName));
711 Info<<
"Removing old directory "
712 <<
args.relativePath(regionOutDir)
728 Info<<
"VTK mesh topology: "
729 << timer.cpuTimeIncrement() <<
" s, "
737 runTime.setTime(timeDirs[timei], timei);
740 const scalar timeValue =
runTime.value();
746 vtk::vtmWriter vtmMultiRegion;
767 polyMesh::readUpdateState meshState =
768 meshProxy.readUpdate();
770 const fvMesh&
mesh = meshProxy.mesh();
774 meshState == polyMesh::TOPO_CHANGE
775 || meshState == polyMesh::TOPO_PATCH_CHANGE
779 vtuMeshCells.clear();
792 IOobjectList objects;
795 HashTable<IOobjectList> faObjects;
801 IOobjectList(meshProxy.baseMesh(),
runTime.timeName());
807 objects.filterObjects(fieldSelector);
826 faMesh::Registry(meshProxy.baseMesh()),
828 polyMesh::regionName(areaName),
829 IOobjectOption::NO_REGISTER
835 objs.filterObjects(fieldSelector);
840 faObjects.emplace_set(areaName, std::move(objs));
846 if (processorFieldsOnly)
871 outputDir/vtkName +
"-regions" + timeDesc +
".vtm"
874 vtmMultiRegion.setTime(timeValue);
877 fileName seriesName(vtk::seriesWriter::base(
outputName));
879 vtk::seriesWriter& series = vtkSeries(seriesName);
886 series.load(seriesName,
true, timeValue);
890 series.write(seriesName);
894 << timer.cpuTimeIncrement() <<
" s, "
900 << timer.elapsedCpuTime() <<
" s, "
Helper routines for reading a field or fields, optionally with a mesh subset (using fvMeshSubsetProxy...
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
const polyBoundaryMesh & pbm
Memory usage information for the current process, and the system memory that is free.
int64_t peak() const noexcept
Peak memory at last update - (VmPeak in /proc/PID/status).
int64_t size() const noexcept
Memory size at last update - (VmSize in /proc/PID/status).
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
word outputName("finiteArea-edges.obj")
PtrList< fvMeshSubsetProxy > meshProxies(meshes.size())
PtrList< vtk::vtuCells > vtuMappings(meshes.size())
Write topoSet in VTK format.
#define WarningInFunction
Report a warning using Foam::Warning.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
bool is_point(const word &clsName)
Test if the class name appears to be a point field.
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Ostream & endl(Ostream &os)
Add newline and flush stream.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
cpuTimePosix cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
constexpr char nl
The newline '\n' character (0x0a).
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.