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[])
236 "legacy VTK file format writer"
238 timeSelector::addOptions();
245 "only convert the specified fields - eg '(p T U)'"
251 "convert a mesh subset corresponding to the specified cellSet"
257 "restrict conversion to the specified faceSet"
263 "restrict conversion to the specified pointSet"
265 argList::addBoolOption
268 "write in ASCII format instead of binary"
270 argList::addBoolOption
273 "write polyhedral cells without tet/pyramid decomposition"
275 argList::addBoolOption
278 "write surfaceScalarFields (e.g., phi)"
280 argList::addBoolOption
283 "use cell value on patches instead of patch value itself"
285 argList::addBoolOption
288 "do not generate file for mesh, only for patches"
290 argList::addBoolOption
295 argList::addBoolOption
298 "combine all patches into a single file"
304 "a list of patches to exclude - eg '( inlet \".*Wall\" )' "
306 argList::addBoolOption
311 argList::addBoolOption
314 "don't link processor VTK files - parallel only"
316 argList::addBoolOption
319 "use the time name instead of the time index when naming the files"
337 <<
"doubleScalar and/or label are not 4 bytes in size" <<
nl
338 <<
"Hence cannot use binary VTK format. Please use -ascii"
347 <<
"Using neighbouring cell value instead of patch value"
356 <<
"Outputting cell values only" <<
nl <<
endl;
366 Info<<
"Not including patches " << excludePatches <<
nl <<
endl;
372 string vtkName = runTime.caseName();
376 vtkName = cellSetName;
378 else if (Pstream::parRun())
383 if (i != string::npos)
385 vtkName = vtkName.substr(i);
398 fileName fvPath(runTime.path()/
"VTK");
400 fileName regionPrefix =
"";
414 || cellSetName.size()
415 || faceSetName.size()
416 || pointSetName.size()
420 Info<<
"Keeping old VTK files in " << fvPath <<
nl <<
endl;
424 Info<<
"Deleting old VTK files in " << fvPath <<
nl <<
endl;
434 vtkMesh vMesh(
mesh, cellSetName);
438 HashSet<fileName> allCloudDirs;
441 runTime.setTime(
timeDirs[timeI], timeI);
446 runTime.timePath()/regionPrefix/cloud::prefix,
452 IOobjectList sprayObjs
456 cloud::prefix/cloudDirs[i]
459 IOobject* positionsPtr = sprayObjs.lookup(word(
"positions"));
463 if (allCloudDirs.insert(cloudDirs[i]))
465 Info<<
"At time: " << runTime.timeName()
466 <<
" detected cloud directory : " << cloudDirs[i]
476 runTime.setTime(
timeDirs[timeI], timeI);
478 Info<<
"Time: " << runTime.timeName() <<
endl;
481 useTimeName ? runTime.timeName() :
Foam::name(runTime.timeIndex());
485 polyMesh::readUpdateState meshState = vMesh.readUpdate();
487 const fvMesh&
mesh = vMesh.mesh();
491 meshState == polyMesh::TOPO_CHANGE
492 || meshState == polyMesh::TOPO_PATCH_CHANGE
500 if (faceSetName.size())
503 faceSet set(
mesh, faceSetName);
506 mkDir(fvPath/set.name());
508 fileName patchFileName
510 fvPath/set.name()/set.name()
516 Info<<
" FaceSet : " << patchFileName <<
endl;
523 if (pointSetName.size())
526 pointSet set(
mesh, pointSetName);
529 mkDir(fvPath/set.name());
531 fileName patchFileName
533 fvPath/set.name()/set.name()
539 Info<<
" pointSet : " << patchFileName <<
endl;
548 IOobjectList objects(
mesh, runTime.timeName());
550 HashSet<word> selectedFields;
559 PtrList<volScalarField> vsf;
560 PtrList<volVectorField> vvf;
561 PtrList<volSphericalTensorField> vSpheretf;
562 PtrList<volSymmTensorField> vSymmtf;
563 PtrList<volTensorField> vtf;
565 if (!specifiedFields || selectedFields.size())
567 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vsf);
570 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vvf);
581 print(
" volSphericalTensorFields :",
Info, vSpheretf);
591 print(
" volSymmTensorFields :",
Info, vSymmtf);
593 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf);
606 PtrList<volScalarField::DimensionedInternalField> dsf;
607 PtrList<volVectorField::DimensionedInternalField> dvf;
608 PtrList<volSphericalTensorField::DimensionedInternalField> dSpheretf;
609 PtrList<volSymmTensorField::DimensionedInternalField> dSymmtf;
610 PtrList<volTensorField::DimensionedInternalField> dtf;
612 if (!specifiedFields || selectedFields.size())
614 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dsf);
615 print(
" volScalarFields::Internal :",
Info, dsf);
617 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dvf);
618 print(
" volVectorFields::Internal :",
Info, dvf);
628 print(
" volSphericalTensorFields::Internal :",
Info, dSpheretf);
638 print(
" volSymmTensorFields::Internal :",
Info, dSymmtf);
640 readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dtf);
641 print(
" volTensorFields::Internal :",
Info, dtf);
656 Info<<
" pointScalarFields : switched off"
657 <<
" (\"-noPointValues\" (at your option)\n";
658 Info<<
" pointVectorFields : switched off"
659 <<
" (\"-noPointValues\" (at your option)\n";
662 PtrList<pointScalarField> psf;
663 PtrList<pointVectorField> pvf;
664 PtrList<pointSphericalTensorField> pSpheretf;
665 PtrList<pointSymmTensorField> pSymmtf;
666 PtrList<pointTensorField> ptf;
668 if (!noPointValues && !(specifiedFields && selectedFields.empty()))
678 print(
" pointScalarFields :",
Info, psf);
688 print(
" pointVectorFields :",
Info, pvf);
698 print(
" pointSphericalTensorFields :",
Info, pSpheretf);
708 print(
" pointSymmTensorFields :",
Info, pSymmtf);
718 print(
" pointTensorFields :",
Info, ptf);
742 Info<<
" Internal : " << vtkFileName <<
endl;
745 internalWriter writer(vMesh, binary, vtkFileName);
748 writeFuns::writeCellDataHeader
752 1 + nVolFields + nDimFields
756 writer.writeCellIDs();
761 writer.write(vSpheretf);
762 writer.write(vSymmtf);
766 writer.write<scalar, volMesh>(dsf);
767 writer.write<
vector, volMesh>(dvf);
770 writer.write<
tensor, volMesh>(dtf);
774 writeFuns::writePointDataHeader
777 vMesh.nFieldPoints(),
778 nVolFields + nDimFields + nPointFields
784 writer.write(pSpheretf);
785 writer.write(pSymmtf);
789 volPointInterpolation pInterp(
mesh);
790 writer.write(pInterp, vsf);
791 writer.write(pInterp, vvf);
792 writer.write(pInterp, vSpheretf);
793 writer.write(pInterp, vSymmtf);
794 writer.write(pInterp, vtf);
796 writer.write<scalar, volMesh>(pInterp, dsf);
797 writer.write<
vector, volMesh>(pInterp, dvf);
799 writer.write<
symmTensor, volMesh>(pInterp, dSymmtf);
800 writer.write<
tensor, volMesh>(pInterp, dtf);
812 PtrList<surfaceScalarField> ssf;
823 PtrList<surfaceVectorField> svf;
834 if (ssf.size() + svf.size() > 0)
837 label sz = svf.size();
839 svf.setSize(sz+ssf.size());
845 svf.set(sz+i, ssf[i]*
n);
846 svf[sz+i].rename(ssf[i].
name());
850 mkDir(fvPath /
"surfaceFields");
852 fileName surfFileName
879 const polyBoundaryMesh&
patches =
mesh.boundaryMesh();
883 mkDir(fvPath/
"allPatches");
885 fileName patchFileName;
887 if (vMesh.useSubMesh())
890 fvPath/
"allPatches"/cellSetName
898 fvPath/
"allPatches"/
"allPatches"
904 Info<<
" Combined patches : " << patchFileName <<
endl;
916 writeFuns::writeCellDataHeader
924 writer.writePatchIDs();
929 writer.write(vSpheretf);
930 writer.write(vSymmtf);
935 writeFuns::writePointDataHeader
945 writer.write(pSpheretf);
946 writer.write(pSymmtf);
957 const polyPatch& pp =
patches[patchI];
961 mkDir(fvPath/pp.name());
963 fileName patchFileName;
965 if (vMesh.useSubMesh())
968 fvPath/pp.name()/cellSetName
976 fvPath/pp.name()/pp.name()
982 Info<<
" Patch : " << patchFileName <<
endl;
993 if (!isA<emptyPolyPatch>(pp))
996 writeFuns::writeCellDataHeader
1004 writer.writePatchIDs();
1009 writer.write(vSpheretf);
1010 writer.write(vSymmtf);
1015 writeFuns::writePointDataHeader
1026 writer.write(pSpheretf);
1027 writer.write(pSymmtf);
1030 PrimitivePatchInterpolation<primitivePatch> pInter
1036 writer.write(pInter, vsf);
1037 writer.write(pInter, vvf);
1038 writer.write(pInter, vSpheretf);
1039 writer.write(pInter, vSymmtf);
1040 writer.write(pInter, vtf);
1055 PtrList<surfaceScalarField> ssf;
1064 print(
" surfScalarFields :",
Info, ssf);
1066 PtrList<surfaceVectorField> svf;
1075 print(
" surfVectorFields :",
Info, svf);
1081 const faceZone& fz = zones[zoneI];
1083 mkDir(fvPath/fz.name());
1085 fileName patchFileName;
1087 if (vMesh.useSubMesh())
1090 fvPath/fz.name()/cellSetName
1098 fvPath/fz.name()/fz.name()
1104 Info<<
" FaceZone : " << patchFileName <<
endl;
1108 IndirectList<face>(
mesh.faces(), fz),
1112 surfaceMeshWriter writer
1121 writeFuns::writeCellDataHeader
1125 ssf.size()+svf.size()
1148 fileName lagrFileName
1151 +
"_" + timeDesc +
".vtk"
1154 Info<<
" Lagrangian: " << lagrFileName <<
endl;
1157 IOobjectList sprayObjs
1164 IOobject* positionsPtr = sprayObjs.lookup(word(
"positions"));
1168 wordList labelNames(sprayObjs.names(labelIOField::typeName));
1172 wordList scalarNames(sprayObjs.names(scalarIOField::typeName));
1173 Info<<
" scalars :";
1176 wordList vectorNames(sprayObjs.names(vectorIOField::typeName));
1177 Info<<
" vectors :";
1184 sphericalTensorIOField::typeName
1187 Info<<
" spherical tensors :";
1194 symmTensorIOField::typeName
1197 Info<<
" symm tensors :";
1200 wordList tensorNames(sprayObjs.names(tensorIOField::typeName));
1201 Info<<
" tensors :";
1204 lagrangianWriter writer
1214 writer.writeParcelHeader
1217 + scalarNames.size()
1218 + vectorNames.size()
1219 + sphereNames.size()
1221 + tensorNames.size()
1225 writer.writeIOField<
label>(labelNames);
1226 writer.writeIOField<scalar>(scalarNames);
1227 writer.writeIOField<
vector>(vectorNames);
1230 writer.writeIOField<
tensor>(tensorNames);
1234 lagrangianWriter writer
1244 writer.writeParcelHeader(0);
1256 if (Pstream::parRun() && doLinks)
1258 mkDir(runTime.path()/
".."/
"VTK");
1259 chDir(runTime.path()/
".."/
"VTK");
1261 Info<<
"Linking all processor files to " << runTime.path()/
".."/
"VTK"
1268 /
"processor" +
name(Pstream::myProcNo())
1273 label sz = dirs.size();
1283 fileName procFile(procVTK/dirs[i]/subFiles[j]);
1293 +
name(Pstream::myProcNo())
1297 if (
system(cmd.c_str()) == -1)
1300 <<
"Could not execute command " << cmd <<
endl;