151 #include "readFields.H"
152 #include "writeFuns.H"
154 #include "internalWriter.H"
155 #include "patchWriter.H"
156 #include "lagrangianWriter.H"
158 #include "writeFaceSet.H"
159 #include "writePointSet.H"
160 #include "surfaceMeshWriter.H"
161 #include "writeSurfFields.H"
166 template<
class GeoField>
167 void print(
const char* msg, Ostream& os,
const PtrList<GeoField>& flds)
174 os <<
' ' << flds[i].name();
185 os <<
' ' << flds[i];
193 const polyBoundaryMesh&
patches,
197 DynamicList<label> patchIDs(
patches.size());
199 Info<<
"Combining patches:" <<
endl;
203 const polyPatch& pp =
patches[patchI];
207 isType<emptyPolyPatch>(pp)
208 || (Pstream::parRun() && isType<processorPolyPatch>(pp))
211 Info<<
" discarding empty/processor patch " << patchI
212 <<
" " << pp.name() <<
endl;
216 Info<<
" excluding patch " << patchI
217 <<
" " << pp.name() <<
endl;
221 patchIDs.append(patchI);
222 Info<<
" patch " << patchI <<
" " << pp.name() <<
endl;
225 return patchIDs.shrink();
231 int main(
int argc,
char *argv[])
235 "legacy VTK file format writer"
237 timeSelector::addOptions();
244 "only convert the specified fields - eg '(p T U)'"
250 "convert a mesh subset corresponding to the specified cellSet"
256 "restrict conversion to the specified faceSet"
262 "restrict conversion to the specified pointSet"
264 argList::addBoolOption
267 "write in ASCII format instead of binary"
269 argList::addBoolOption
272 "write polyhedral cells without tet/pyramid decomposition"
274 argList::addBoolOption
277 "write surfaceScalarFields (e.g., phi)"
279 argList::addBoolOption
282 "use cell value on patches instead of patch value itself"
284 argList::addBoolOption
287 "do not generate file for mesh, only for patches"
289 argList::addBoolOption
294 argList::addBoolOption
297 "combine all patches into a single file"
303 "a list of patches to exclude - eg '( inlet \".*Wall\" )' "
305 argList::addBoolOption
310 argList::addBoolOption
313 "don't link processor VTK files - parallel only"
315 argList::addBoolOption
318 "use the time name instead of the time index when naming the files"
336 <<
"floatScalar and/or label are not 4 bytes in size" <<
nl
337 <<
"Hence cannot use binary VTK format. Please use -ascii"
346 <<
"Using neighbouring cell value instead of patch value"
355 <<
"Outputting cell values only" <<
nl <<
endl;
365 Info<<
"Not including patches " << excludePatches <<
nl <<
endl;
371 string vtkName = runTime.caseName();
375 vtkName = cellSetName;
377 else if (Pstream::parRun())
382 if (i != string::npos)
384 vtkName = vtkName.substr(i);
397 fileName fvPath(runTime.path()/
"VTK");
399 fileName regionPrefix =
"";
413 || cellSetName.size()
414 || faceSetName.size()
415 || pointSetName.size()
419 Info<<
"Keeping old VTK files in " << fvPath <<
nl <<
endl;
423 Info<<
"Deleting old VTK files in " << fvPath <<
nl <<
endl;
433 vtkMesh vMesh(
mesh, cellSetName);
437 HashSet<fileName> allCloudDirs;
440 runTime.setTime(
timeDirs[timeI], timeI);
445 runTime.timePath()/regionPrefix/cloud::prefix,
451 IOobjectList sprayObjs
455 cloud::prefix/cloudDirs[i]
458 IOobject* positionsPtr = sprayObjs.lookup(word(
"positions"));
462 if (allCloudDirs.insert(cloudDirs[i]))
464 Info<<
"At time: " << runTime.timeName()
465 <<
" detected cloud directory : " << cloudDirs[i]
475 runTime.setTime(
timeDirs[timeI], timeI);
477 Info<<
"Time: " << runTime.timeName() <<
endl;
480 useTimeName ? runTime.timeName() :
Foam::name(runTime.timeIndex());
484 polyMesh::readUpdateState meshState = vMesh.readUpdate();
486 const fvMesh&
mesh = vMesh.mesh();
490 meshState == polyMesh::TOPO_CHANGE
491 || meshState == polyMesh::TOPO_PATCH_CHANGE
499 if (faceSetName.size())
502 faceSet set(
mesh, faceSetName);
505 mkDir(fvPath/set.name());
507 fileName patchFileName
509 fvPath/set.name()/set.name()
515 Info<<
" FaceSet : " << patchFileName <<
endl;
522 if (pointSetName.size())
525 pointSet set(
mesh, pointSetName);
528 mkDir(fvPath/set.name());
530 fileName patchFileName
532 fvPath/set.name()/set.name()
538 Info<<
" pointSet : " << patchFileName <<
endl;
547 IOobjectList objects(
mesh, runTime.timeName());
549 HashSet<word> selectedFields;
558 PtrList<volScalarField> vsf;
559 PtrList<volVectorField> vvf;
560 PtrList<volSphericalTensorField> vSpheretf;
561 PtrList<volSymmTensorField> vSymmtf;
562 PtrList<volTensorField> vtf;
564 if (!specifiedFields || selectedFields.size())
566 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vsf);
569 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vvf);
580 print(
" volSphericalTensorFields :",
Info, vSpheretf);
590 print(
" volSymmTensorFields :",
Info, vSymmtf);
592 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf);
605 PtrList<volScalarField::DimensionedInternalField> dsf;
606 PtrList<volVectorField::DimensionedInternalField> dvf;
607 PtrList<volSphericalTensorField::DimensionedInternalField> dSpheretf;
608 PtrList<volSymmTensorField::DimensionedInternalField> dSymmtf;
609 PtrList<volTensorField::DimensionedInternalField> dtf;
611 if (!specifiedFields || selectedFields.size())
613 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dsf);
614 print(
" volScalarFields::Internal :",
Info, dsf);
616 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dvf);
617 print(
" volVectorFields::Internal :",
Info, dvf);
627 print(
" volSphericalTensorFields::Internal :",
Info, dSpheretf);
637 print(
" volSymmTensorFields::Internal :",
Info, dSymmtf);
639 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dtf);
640 print(
" volTensorFields::Internal :",
Info, dtf);
655 Info<<
" pointScalarFields : switched off"
656 <<
" (\"-noPointValues\" (at your option)\n";
657 Info<<
" pointVectorFields : switched off"
658 <<
" (\"-noPointValues\" (at your option)\n";
661 PtrList<pointScalarField> psf;
662 PtrList<pointVectorField> pvf;
663 PtrList<pointSphericalTensorField> pSpheretf;
664 PtrList<pointSymmTensorField> pSymmtf;
665 PtrList<pointTensorField> ptf;
667 if (!noPointValues && !(specifiedFields && selectedFields.empty()))
677 print(
" pointScalarFields :",
Info, psf);
687 print(
" pointVectorFields :",
Info, pvf);
697 print(
" pointSphericalTensorFields :",
Info, pSpheretf);
707 print(
" pointSymmTensorFields :",
Info, pSymmtf);
717 print(
" pointTensorFields :",
Info, ptf);
741 Info<<
" Internal : " << vtkFileName <<
endl;
744 internalWriter writer(vMesh, binary, vtkFileName);
747 writeFuns::writeCellDataHeader
751 1 + nVolFields + nDimFields
755 writer.writeCellIDs();
760 writer.write(vSpheretf);
761 writer.write(vSymmtf);
765 writer.write<scalar, volMesh>(dsf);
766 writer.write<
vector, volMesh>(dvf);
769 writer.write<
tensor, volMesh>(dtf);
773 writeFuns::writePointDataHeader
776 vMesh.nFieldPoints(),
777 nVolFields + nDimFields + nPointFields
783 writer.write(pSpheretf);
784 writer.write(pSymmtf);
788 volPointInterpolation pInterp(
mesh);
789 writer.write(pInterp, vsf);
790 writer.write(pInterp, vvf);
791 writer.write(pInterp, vSpheretf);
792 writer.write(pInterp, vSymmtf);
793 writer.write(pInterp, vtf);
795 writer.write<scalar, volMesh>(pInterp, dsf);
796 writer.write<
vector, volMesh>(pInterp, dvf);
798 writer.write<
symmTensor, volMesh>(pInterp, dSymmtf);
799 writer.write<
tensor, volMesh>(pInterp, dtf);
811 PtrList<surfaceScalarField> ssf;
822 PtrList<surfaceVectorField> svf;
833 if (ssf.size() + svf.size() > 0)
836 label sz = svf.size();
838 svf.setSize(sz+ssf.size());
844 svf.set(sz+i, ssf[i]*
n);
845 svf[sz+i].rename(ssf[i].
name());
849 mkDir(fvPath /
"surfaceFields");
851 fileName surfFileName
878 const polyBoundaryMesh&
patches =
mesh.boundaryMesh();
882 mkDir(fvPath/
"allPatches");
884 fileName patchFileName;
886 if (vMesh.useSubMesh())
889 fvPath/
"allPatches"/cellSetName
897 fvPath/
"allPatches"/
"allPatches"
903 Info<<
" Combined patches : " << patchFileName <<
endl;
915 writeFuns::writeCellDataHeader
923 writer.writePatchIDs();
928 writer.write(vSpheretf);
929 writer.write(vSymmtf);
934 writeFuns::writePointDataHeader
944 writer.write(pSpheretf);
945 writer.write(pSymmtf);
956 const polyPatch& pp =
patches[patchI];
960 mkDir(fvPath/pp.name());
962 fileName patchFileName;
964 if (vMesh.useSubMesh())
967 fvPath/pp.name()/cellSetName
975 fvPath/pp.name()/pp.name()
981 Info<<
" Patch : " << patchFileName <<
endl;
992 if (!isA<emptyPolyPatch>(pp))
995 writeFuns::writeCellDataHeader
1003 writer.writePatchIDs();
1008 writer.write(vSpheretf);
1009 writer.write(vSymmtf);
1014 writeFuns::writePointDataHeader
1025 writer.write(pSpheretf);
1026 writer.write(pSymmtf);
1029 PrimitivePatchInterpolation<primitivePatch> pInter
1035 writer.write(pInter, vsf);
1036 writer.write(pInter, vvf);
1037 writer.write(pInter, vSpheretf);
1038 writer.write(pInter, vSymmtf);
1039 writer.write(pInter, vtf);
1054 PtrList<surfaceScalarField> ssf;
1063 print(
" surfScalarFields :",
Info, ssf);
1065 PtrList<surfaceVectorField> svf;
1074 print(
" surfVectorFields :",
Info, svf);
1080 const faceZone& fz = zones[zoneI];
1082 mkDir(fvPath/fz.name());
1084 fileName patchFileName;
1086 if (vMesh.useSubMesh())
1089 fvPath/fz.name()/cellSetName
1097 fvPath/fz.name()/fz.name()
1103 Info<<
" FaceZone : " << patchFileName <<
endl;
1107 IndirectList<face>(
mesh.faces(), fz),
1111 surfaceMeshWriter writer
1120 writeFuns::writeCellDataHeader
1124 ssf.size()+svf.size()
1147 fileName lagrFileName
1150 +
"_" + timeDesc +
".vtk"
1153 Info<<
" Lagrangian: " << lagrFileName <<
endl;
1156 IOobjectList sprayObjs
1163 IOobject* positionsPtr = sprayObjs.lookup(word(
"positions"));
1167 wordList labelNames(sprayObjs.names(labelIOField::typeName));
1171 wordList scalarNames(sprayObjs.names(scalarIOField::typeName));
1172 Info<<
" scalars :";
1175 wordList vectorNames(sprayObjs.names(vectorIOField::typeName));
1176 Info<<
" vectors :";
1183 sphericalTensorIOField::typeName
1186 Info<<
" spherical tensors :";
1193 symmTensorIOField::typeName
1196 Info<<
" symm tensors :";
1199 wordList tensorNames(sprayObjs.names(tensorIOField::typeName));
1200 Info<<
" tensors :";
1203 lagrangianWriter writer
1213 writer.writeParcelHeader
1216 + scalarNames.size()
1217 + vectorNames.size()
1218 + sphereNames.size()
1220 + tensorNames.size()
1224 writer.writeIOField<
label>(labelNames);
1225 writer.writeIOField<scalar>(scalarNames);
1226 writer.writeIOField<
vector>(vectorNames);
1229 writer.writeIOField<
tensor>(tensorNames);
1233 lagrangianWriter writer
1243 writer.writeParcelHeader(0);
1255 if (Pstream::parRun() && doLinks)
1257 mkDir(runTime.path()/
".."/
"VTK");
1258 chDir(runTime.path()/
".."/
"VTK");
1260 Info<<
"Linking all processor files to " << runTime.path()/
".."/
"VTK"
1267 /
"processor" +
name(Pstream::myProcNo())
1272 label sz = dirs.size();
1282 fileName procFile(procVTK/dirs[i]/subFiles[j]);
1292 +
name(Pstream::myProcNo())
1296 if (
system(cmd.c_str()) == -1)
1299 <<
"Could not execute command " << cmd <<
endl;