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 autoPtr<wordRes::filter>& patchSelector
177 if (patchSelector && !patchSelector().empty())
182 stringListOps::findMatching
198 for (
const label patchi : indices)
200 const polyPatch& pp =
patches[patchi];
202 if (isType<emptyPolyPatch>(pp))
206 else if (Pstream::parRun() &&
bool(isA<processorPolyPatch>(pp)))
211 indices[
count] = patchi;
215 indices.resize(count);
224vtk::outputOptions getOutputOptions(
const argList&
args)
227 vtk::outputOptions opts;
235 if (
sizeof(floatScalar) != 4 ||
sizeof(label) != 4)
240 <<
"Using ASCII rather than legacy binary VTK format since "
241 <<
"floatScalar and/or label are not 4 bytes in size."
261int main(
int argc,
char *argv[])
265 "General OpenFOAM to VTK file writer"
267 timeSelector::addOptions();
270 argList::setAdvanced(
"decomposeParDict");
271 argList::setAdvanced(
"noFunctionObjects");
273 argList::addVerboseOption(
"Additional verbosity");
275 argList::addBoolOption
278 "Write in ASCII format instead of binary"
280 argList::addBoolOption
283 "Write legacy format instead of xml",
286 argList::addBoolOption
289 "Decompose polyhedral cells into tets/pyramids",
292 argList::ignoreOptionCompat
297 argList::ignoreOptionCompat
307 "Convert mesh subset corresponding to specified cellSet",
314 "Convert mesh subset corresponding to specified cellZone",
321 "Convert specified faceSet only",
328 "Convert specified pointSet only",
335 "Specify single or multiple faceZones to write\n"
336 "Eg, 'cells' or '( slice \"mfp-.*\" )'.",
343 "Specify single or multiple fields to write (all by default)\n"
344 "Eg, 'T' or '(p T U \"alpha.*\")'"
350 "Exclude single or multiple fields",
353 argList::addBoolOption
356 "Suppress conversion of fields"
359 argList::addBoolOption
362 "Write field values on processor boundaries only",
365 argList::addBoolOption
368 "Write surfaceScalarFields (eg, phi)",
371 argList::addBoolOption
374 "Suppress output of finite-area mesh/fields",
377 argList::ignoreOptionCompat
379 {
"finite-area", 2112},
382 argList::ignoreOptionCompat
384 {
"finiteAreaFields", 2012},
388 argList::addBoolOption
391 "Use cell value on patches instead of patch value itself",
394 argList::addBoolOption
397 "Suppress output for boundary patches"
399 argList::addBoolOption
402 "Suppress output for internal volume mesh"
404 argList::addBoolOption
407 "Suppress writing lagrangian positions and fields"
409 argList::addOptionCompat(
"no-lagrangian", {
"noLagrangian", 1806});
411 argList::addBoolOption
414 "Suppress conversion of pointFields. No interpolated PointData."
416 argList::addOptionCompat(
"no-point-data", {
"noPointValues", 1806});
418 argList::addBoolOption
421 "Additional mesh id fields (cellID, procID, patchID)",
425 argList::addBoolOption
428 "Additional pointID field for internal mesh",
432 argList::addBoolOption
435 "Combine all patches into a single file"
437 argList::addOptionCompat(
"one-boundary", {
"allPatches", 1806});
445 "Specify single patch or multiple patches to write\n"
446 "Eg, 'top' or '( front \".*back\" )'"
452 "Exclude single or multiple patches from writing\n"
453 "Eg, 'outlet' or '( inlet \".*Wall\" )'",
456 argList::addOptionCompat(
"exclude-patches", {
"excludePatches", 2112});
458 argList::ignoreOptionCompat
460 {
"noFaceZones", 1806},
463 argList::ignoreOptionCompat
468 argList::ignoreOptionCompat
470 {
"useTimeName", 1806},
473 argList::addBoolOption
476 "Remove any existing VTK output directory"
482 "Directory name for VTK output (default: 'VTK')"
488 const bool decomposePoly =
args.
found(
"poly-decomp");
489 const bool doBoundary = !
args.
found(
"no-boundary");
490 const bool doInternal = !
args.
found(
"no-internal");
491 const bool doLagrangian = !
args.
found(
"no-lagrangian");
492 const bool doFiniteArea = !
args.
found(
"no-finite-area");
493 const bool doSurfaceFields =
args.
found(
"surfaceFields");
494 const bool oneBoundary =
args.
found(
"one-boundary") && doBoundary;
495 const bool nearCellValue =
args.
found(
"nearCellValue") && doBoundary;
497 const vtk::outputOptions writeOpts = getOutputOptions(
args);
499 bool processorFieldsOnly =
false;
503 if (!Pstream::parRun())
505 Info<<
"Ignoring processor patch writing in serial"
508 else if (writeOpts.legacy())
510 Info<<
"Ignoring processor patch writing in legacy format"
515 processorFieldsOnly =
true;
517 Info<<
"Writing processor patch fields only"
524 Info<<
"Using neighbouring cell value instead of patch value"
528 bool doPointValues = !
args.
found(
"no-point-data");
531 Info<<
"Point fields and interpolated point data"
532 <<
" disabled with the '-no-point-data' option"
536 const bool withPointIds =
args.
found(
"with-point-ids");
539 Info<<
"Write point ids requested";
543 Info<<
", but ignored due to the '-no-point-data' option";
549 const bool withMeshIds =
args.
found(
"with-ids");
552 Info<<
"Writing mesh ids (cell, patch, proc) requested" <<
nl;
556 wordRes includedPatches, excludedPatches;
557 autoPtr<wordRes::filter> patchSelector(
nullptr);
560 bool resetFilter =
false;
564 Info<<
"Including patches "
570 Info<<
"Excluding patches "
577 autoPtr<wordRes::filter>::New(includedPatches, excludedPatches);
582 wordRes includedFields, excludedFields;
583 autoPtr<wordRes::filter> fieldSelector(
nullptr);
584 bool doConvertFields = !
args.
found(
"no-fields");
587 bool resetFilter =
false;
590 Info<<
"Including fields "
593 resetFilter = !includedFields.empty();
595 if (includedFields.empty())
600 doConvertFields =
false;
601 Info<<
"Field conversion disabled by '-fields ()' option" <<
nl
602 <<
"Should use -no-fields instead" <<
endl;
608 Info<<
"Excluding fields "
612 if (resetFilter && doConvertFields)
615 autoPtr<wordRes::filter>::New(includedFields, excludedFields);
618 else if (doConvertFields)
620 Info<<
"Field conversion disabled with the '-no-fields' option" <<
nl;
625 const wordRes selectedFaceZones(
args.
getList<wordRe>(
"faceZones",
false));
632 HashTable<vtk::seriesWriter, fileName> vtkSeries;
638 word cellSelectionName;
642 fvMeshSubsetProxy::subsetType cellSubsetType = fvMeshSubsetProxy::NONE;
650 vtkName = cellSelectionName;
651 cellSubsetType = fvMeshSubsetProxy::SET;
653 Info<<
"Converting cellSet " << cellSelectionName
654 <<
" only. New outside faces as \"oldInternalFaces\"."
659 vtkName = cellSelectionName;
660 cellSubsetType = fvMeshSubsetProxy::ZONE;
662 Info<<
"Converting cellZone " << cellSelectionName
663 <<
" only. New outside faces as \"oldInternalFaces\"."
674 const char *
const opt
675 : {
"cellSet",
"cellZone",
"faceSet",
"pointSet" }
680 Info<<
"Ignoring -" << opt <<
" for multi-regions" <<
nl;
693 if (Pstream::master())
700 fileName regionOutDir(outputDir/polyMesh::regionName(
regionName));
704 Info<<
"Removing old directory "
717 Info<<
"Initial memory " << mem.update().size() <<
" kB" <<
endl;
720 #include "createMeshAccounting.H"
722 Info<<
"VTK mesh topology: "
723 << timer.cpuTimeIncrement() <<
" s, "
724 << mem.update().size() <<
" kB" <<
endl;
731 runTime.setTime(timeDirs[timei], timei);
734 const scalar timeValue =
runTime.value();
740 vtk::vtmWriter vtmMultiRegion;
761 polyMesh::readUpdateState meshState =
762 meshProxy.readUpdate();
764 const fvMesh&
mesh = meshProxy.mesh();
768 meshState == polyMesh::TOPO_CHANGE
769 || meshState == polyMesh::TOPO_PATCH_CHANGE
773 vtuMeshCells.clear();
785 IOobjectList objects(0);
791 IOobjectList(meshProxy.baseMesh(),
runTime.timeName());
793 if (fieldSelector && !fieldSelector().empty())
795 objects.filterObjects(fieldSelector());
804 objects.filterClasses
806 [](
const word& clsName)
808 return fieldTypes::point.found(clsName);
815 if (processorFieldsOnly)
823 #include "convertVolumeFields.H"
829 #include "convertAreaFields.H"
832 #include "convertLagrangian.H"
840 outputDir/vtkName +
"-regions" + timeDesc +
".vtm"
843 vtmMultiRegion.setTime(timeValue);
846 fileName seriesName(vtk::seriesWriter::base(
outputName));
848 vtk::seriesWriter& series = vtkSeries(seriesName);
855 series.load(seriesName,
true, timeValue);
859 series.write(seriesName);
863 << timer.cpuTimeIncrement() <<
" s, "
864 << mem.update().size() <<
" kB" <<
endl;
869 << timer.elapsedCpuTime() <<
" s, "
870 << mem.update().peak() <<
" kB (peak)\n" <<
endl;
fileName relativePath(const fileName &input, const bool caseTag=false) const
bool readListIfPresent(const word &optName, List< T > &list) const
bool found(const word &optName) const
Return true if the named option is found.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
const fileName & globalCaseName() const noexcept
Return global case name.
List< T > getList(const label index) const
Get a List of values from the argument at index.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
fileName globalPath() const
Return the full path to the global case.
Code chunk for converting volume fields on processor boundaries, included by foamToVTK.
const polyBoundaryMesh & patches
Code chunk for post-processing surface fields to VTK PolyData.
Code chunk for converting face and point sets - included by foamToVTK.
Foam::word regionName(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.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
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)
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool rmDir(const fileName &directory, const bool silent=false)
Remove a directory and its contents (optionally silencing warnings)
List< instant > instantList
List of instants.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
cpuTimeCxx 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.
Operations on lists of strings.
Write surface fields from volume mesh.