foamToVTK.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  foamToVTK
26 
27 Description
28  Legacy VTK file format writer.
29 
30  - handles volScalar, volVector, pointScalar, pointVector, surfaceScalar
31  fields.
32  - mesh topo changes.
33  - both ascii and binary.
34  - single time step writing.
35  - write subset only.
36  - automatic decomposition of cells; polygons on boundary undecomposed since
37  handled by vtk.
38 
39 Usage
40 
41  - foamToVTK [OPTION]
42 
43  \param -ascii \n
44  Write VTK data in ASCII format instead of binary.
45 
46  \param -mesh <name>\n
47  Use a different mesh name (instead of -region)
48 
49  \param -fields <fields>\n
50  Convert selected fields only. For example,
51  \verbatim
52  -fields "( p T U )"
53  \endverbatim
54  The quoting is required to avoid shell expansions and to pass the
55  information as a single argument.
56 
57  \param -surfaceFields \n
58  Write surfaceScalarFields (e.g., phi)
59 
60  \param -cellSet <name>\n
61  \param -faceSet <name>\n
62  \param -pointSet <name>\n
63  Restrict conversion to the cellSet, faceSet or pointSet.
64 
65  \param -nearCellValue \n
66  Output cell value on patches instead of patch value itself
67 
68  \param -noInternal \n
69  Do not generate file for mesh, only for patches
70 
71  \param -noPointValues \n
72  No pointFields
73 
74  \param -noFaceZones \n
75  No faceZones
76 
77  \param -noLinks \n
78  (in parallel) do not link processor files to master
79 
80  \param poly \n
81  write polyhedral cells without tet/pyramid decomposition
82 
83  \param -allPatches \n
84  Combine all patches into a single file
85 
86  \param -excludePatches <patchNames>\n
87  Specify patches (wildcards) to exclude. For example,
88  \verbatim
89  -excludePatches '( inlet_1 inlet_2 "proc.*")'
90  \endverbatim
91  The quoting is required to avoid shell expansions and to pass the
92  information as a single argument. The double quotes denote a regular
93  expression.
94 
95  \param -useTimeName \n
96  use the time index in the VTK file name instead of the time index
97 
98 Note
99  mesh subset is handled by vtkMesh. Slight inconsistency in
100  interpolation: on the internal field it interpolates the whole volField
101  to the whole-mesh pointField and then selects only those values it
102  needs for the subMesh (using the fvMeshSubset cellMap(), pointMap()
103  functions). For the patches however it uses the
104  fvMeshSubset.interpolate function to directly interpolate the
105  whole-mesh values onto the subset patch.
106 
107 Note
108  new file format: \n
109  no automatic timestep recognition.
110  However can have .pvd file format which refers to time simulation
111  if XML *.vtu files are available:
112 
113  \verbatim
114  <?xml version="1.0"?>
115  <VTKFile type="Collection"
116  version="0.1"
117  byte_order="LittleEndian"
118  compressor="vtkZLibDataCompressor">
119  <Collection>
120  <DataSet timestep="50" file="pitzDaily_2.vtu"/>
121  <DataSet timestep="100" file="pitzDaily_3.vtu"/>
122  <DataSet timestep="150" file="pitzDaily_4.vtu"/>
123  <DataSet timestep="200" file="pitzDaily_5.vtu"/>
124  <DataSet timestep="250" file="pitzDaily_6.vtu"/>
125  <DataSet timestep="300" file="pitzDaily_7.vtu"/>
126  <DataSet timestep="350" file="pitzDaily_8.vtu"/>
127  <DataSet timestep="400" file="pitzDaily_9.vtu"/>
128  <DataSet timestep="450" file="pitzDaily_10.vtu"/>
129  <DataSet timestep="500" file="pitzDaily_11.vtu"/>
130  </Collection>
131  </VTKFile>
132  \endverbatim
133 
134 \*---------------------------------------------------------------------------*/
135 
136 #include "fvCFD.H"
137 #include "pointMesh.H"
138 #include "volPointInterpolation.H"
139 #include "emptyPolyPatch.H"
140 #include "labelIOField.H"
141 #include "scalarIOField.H"
142 #include "sphericalTensorIOField.H"
143 #include "symmTensorIOField.H"
144 #include "tensorIOField.H"
145 #include "faceZoneMesh.H"
146 #include "Cloud.H"
147 #include "passiveParticle.H"
148 #include "stringListOps.H"
149 
150 #include "vtkMesh.H"
151 #include "readFields.H"
152 #include "writeFuns.H"
153 
154 #include "internalWriter.H"
155 #include "patchWriter.H"
156 #include "lagrangianWriter.H"
157 
158 #include "writeFaceSet.H"
159 #include "writePointSet.H"
160 #include "surfaceMeshWriter.H"
161 #include "writeSurfFields.H"
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 template<class GeoField>
167 void print(const char* msg, Ostream& os, const PtrList<GeoField>& flds)
168 {
169  if (flds.size())
170  {
171  os << msg;
172  forAll(flds, i)
173  {
174  os << ' ' << flds[i].name();
175  }
176  os << endl;
177  }
178 }
179 
180 
181 void print(Ostream& os, const wordList& flds)
182 {
183  forAll(flds, i)
184  {
185  os << ' ' << flds[i];
186  }
187  os << endl;
188 }
189 
190 
192 (
193  const polyBoundaryMesh& patches,
194  const List<wordRe>& excludePatches //HashSet<word>& excludePatches
195 )
196 {
197  DynamicList<label> patchIDs(patches.size());
198 
199  Info<< "Combining patches:" << endl;
200 
201  forAll(patches, patchI)
202  {
203  const polyPatch& pp = patches[patchI];
204 
205  if
206  (
207  isType<emptyPolyPatch>(pp)
208  || (Pstream::parRun() && isType<processorPolyPatch>(pp))
209  )
210  {
211  Info<< " discarding empty/processor patch " << patchI
212  << " " << pp.name() << endl;
213  }
214  else if (findStrings(excludePatches, pp.name()))
215  {
216  Info<< " excluding patch " << patchI
217  << " " << pp.name() << endl;
218  }
219  else
220  {
221  patchIDs.append(patchI);
222  Info<< " patch " << patchI << " " << pp.name() << endl;
223  }
224  }
225  return patchIDs.shrink();
226 }
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 int main(int argc, char *argv[])
232 {
233  cout.setf(ios_base::fixed, ios_base::floatfield);//十进制计数法,不是科学计数法
234 argList::addNote
235  (
236  "legacy VTK file format writer"
237  );
238  timeSelector::addOptions();
239 
240  #include "addRegionOption.H"
241  argList::addOption
242  (
243  "fields",
244  "wordList",
245  "only convert the specified fields - eg '(p T U)'"
246  );
247  argList::addOption
248  (
249  "cellSet",
250  "name",
251  "convert a mesh subset corresponding to the specified cellSet"
252  );
253  argList::addOption
254  (
255  "faceSet",
256  "name",
257  "restrict conversion to the specified faceSet"
258  );
259  argList::addOption
260  (
261  "pointSet",
262  "name",
263  "restrict conversion to the specified pointSet"
264  );
265  argList::addBoolOption
266  (
267  "ascii",
268  "write in ASCII format instead of binary"
269  );
270  argList::addBoolOption
271  (
272  "poly",
273  "write polyhedral cells without tet/pyramid decomposition"
274  );
275  argList::addBoolOption
276  (
277  "surfaceFields",
278  "write surfaceScalarFields (e.g., phi)"
279  );
280  argList::addBoolOption
281  (
282  "nearCellValue",
283  "use cell value on patches instead of patch value itself"
284  );
285  argList::addBoolOption
286  (
287  "noInternal",
288  "do not generate file for mesh, only for patches"
289  );
290  argList::addBoolOption
291  (
292  "noPointValues",
293  "no pointFields"
294  );
295  argList::addBoolOption
296  (
297  "allPatches",
298  "combine all patches into a single file"
299  );
300  argList::addOption
301  (
302  "excludePatches",
303  "wordReList",
304  "a list of patches to exclude - eg '( inlet \".*Wall\" )' "
305  );
306  argList::addBoolOption
307  (
308  "noFaceZones",
309  "no faceZones"
310  );
311  argList::addBoolOption
312  (
313  "noLinks",
314  "don't link processor VTK files - parallel only"
315  );
316  argList::addBoolOption
317  (
318  "useTimeName",
319  "use the time name instead of the time index when naming the files"
320  );
321 
322  #include "setRootCase.H"
323  #include "createTime.H"
324 
325  const bool doWriteInternal = !args.optionFound("noInternal");
326  const bool doFaceZones = !args.optionFound("noFaceZones");
327  const bool doLinks = !args.optionFound("noLinks");
328  const bool binary = !args.optionFound("ascii");
329  const bool useTimeName = args.optionFound("useTimeName");
330 
331  // decomposition of polyhedral cells into tets/pyramids cells
332  vtkTopo::decomposePoly = !args.optionFound("poly");
333 
334  if (binary && (sizeof(doubleScalar) != 4 || sizeof(label) != 4))
335  {
337  << "doubleScalar and/or label are not 4 bytes in size" << nl
338  << "Hence cannot use binary VTK format. Please use -ascii"
339  << exit(FatalError);
340  }
341 
342  const bool nearCellValue = args.optionFound("nearCellValue");
343 
344  if (nearCellValue)
345  {
347  << "Using neighbouring cell value instead of patch value"
348  << nl << endl;
349  }
350 
351  const bool noPointValues = args.optionFound("noPointValues");
352 
353  if (noPointValues)
354  {
356  << "Outputting cell values only" << nl << endl;
357  }
358 
359  const bool allPatches = args.optionFound("allPatches");
360 
361  List<wordRe> excludePatches;
362  if (args.optionFound("excludePatches"))
363  {
364  args.optionLookup("excludePatches")() >> excludePatches;
365 
366  Info<< "Not including patches " << excludePatches << nl << endl;
367  }
368 
369  word cellSetName;
370  word faceSetName;
371  word pointSetName;
372  string vtkName = runTime.caseName();
373 
374  if (args.optionReadIfPresent("cellSet", cellSetName))
375  {
376  vtkName = cellSetName;
377  }
378  else if (Pstream::parRun())
379  {
380  // Strip off leading casename, leaving just processor_DDD ending.
381  string::size_type i = vtkName.rfind("processor");
382 
383  if (i != string::npos)
384  {
385  vtkName = vtkName.substr(i);
386  }
387  }
388  args.optionReadIfPresent("faceSet", faceSetName);
389  args.optionReadIfPresent("pointSet", pointSetName);
390 
391 
392 
393  instantList timeDirs = timeSelector::select0(runTime, args);
394 
395  #include "createNamedMesh.H"
396 
397  // VTK/ directory in the case
398  fileName fvPath(runTime.path()/"VTK");
399  // Directory of mesh (region0 gets filtered out)
400  fileName regionPrefix = "";
401 
402  if (regionName != polyMesh::defaultRegion)
403  {
404  fvPath = fvPath/regionName;
405  regionPrefix = regionName;
406  }
407 
408  if (isDir(fvPath))
409  {
410  if
411  (
412  args.optionFound("time")
413  || args.optionFound("latestTime")
414  || cellSetName.size()
415  || faceSetName.size()
416  || pointSetName.size()
417  || regionName != polyMesh::defaultRegion
418  )
419  {
420  Info<< "Keeping old VTK files in " << fvPath << nl << endl;
421  }
422  else
423  {
424  Info<< "Deleting old VTK files in " << fvPath << nl << endl;
425 
426  rmDir(fvPath);
427  }
428  }
429 
430  mkDir(fvPath);
431 
432 
433  // Mesh wrapper; does subsetting and decomposition
434  vtkMesh vMesh(mesh, cellSetName);
435 
436 
437  // Scan for all possible lagrangian clouds
438  HashSet<fileName> allCloudDirs;
439  forAll(timeDirs, timeI)
440  {
441  runTime.setTime(timeDirs[timeI], timeI);
442  fileNameList cloudDirs
443  (
444  readDir
445  (
446  runTime.timePath()/regionPrefix/cloud::prefix,
447  fileName::DIRECTORY
448  )
449  );
450  forAll(cloudDirs, i)
451  {
452  IOobjectList sprayObjs
453  (
454  mesh,
455  runTime.timeName(),
456  cloud::prefix/cloudDirs[i]
457  );
458 
459  IOobject* positionsPtr = sprayObjs.lookup(word("positions"));
460 
461  if (positionsPtr)
462  {
463  if (allCloudDirs.insert(cloudDirs[i]))
464  {
465  Info<< "At time: " << runTime.timeName()
466  << " detected cloud directory : " << cloudDirs[i]
467  << endl;
468  }
469  }
470  }
471  }
472 
473 
474  forAll(timeDirs, timeI)
475  {
476  runTime.setTime(timeDirs[timeI], timeI);
477 
478  Info<< "Time: " << runTime.timeName() << endl;
479 
480  word timeDesc =
481  useTimeName ? runTime.timeName() : Foam::name(runTime.timeIndex());
482 
483  // Check for new polyMesh/ and update mesh, fvMeshSubset and cell
484  // decomposition.
485  polyMesh::readUpdateState meshState = vMesh.readUpdate();
486 
487  const fvMesh& mesh = vMesh.mesh();
488 
489  if
490  (
491  meshState == polyMesh::TOPO_CHANGE
492  || meshState == polyMesh::TOPO_PATCH_CHANGE
493  )
494  {
495  Info<< " Read new mesh" << nl << endl;
496  }
497 
498 
499  // If faceSet: write faceSet only (as polydata)
500  if (faceSetName.size())
501  {
502  // Load the faceSet
503  faceSet set(mesh, faceSetName);
504 
505  // Filename as if patch with same name.
506  mkDir(fvPath);
507 
508  fileName patchFileName
509  (
510  fvPath/set.name()
511  + "_"
512  + timeDesc
513  + ".vtk"
514  );
515 
516  Info<< " FaceSet : " << patchFileName << endl;
517 
518  writeFaceSet(binary, vMesh, set, patchFileName);
519 
520  continue;
521  }
522  // If pointSet: write pointSet only (as polydata)
523  if (pointSetName.size())
524  {
525  // Load the pointSet
526  pointSet set(mesh, pointSetName);
527 
528  // Filename as if patch with same name.
529  mkDir(fvPath);
530 
531  fileName patchFileName
532  (
533  fvPath/set.name()
534  + "_"
535  + timeDesc
536  + ".vtk"
537  );
538 
539  Info<< " pointSet : " << patchFileName << endl;
540 
541  writePointSet(binary, vMesh, set, patchFileName);
542 
543  continue;
544  }
545 
546 
547  // Search for list of objects for this time
548  IOobjectList objects(mesh, runTime.timeName());
549 
550  HashSet<word> selectedFields;
551  bool specifiedFields = args.optionReadIfPresent
552  (
553  "fields",
554  selectedFields
555  );
556 
557  // Construct the vol fields (on the original mesh if subsetted)
558 
564 
565  if (!specifiedFields || selectedFields.size())
566  {
567  readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vsf);
568  print(" volScalarFields :", Info, vsf);
569 
570  readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vvf);
571  print(" volVectorFields :", Info, vvf);
572 
573  readFields
574  (
575  vMesh,
576  vMesh.baseMesh(),
577  objects,
578  selectedFields,
579  vSpheretf
580  );
581  print(" volSphericalTensorFields :", Info, vSpheretf);
582 
583  readFields
584  (
585  vMesh,
586  vMesh.baseMesh(),
587  objects,
588  selectedFields,
589  vSymmtf
590  );
591  print(" volSymmTensorFields :", Info, vSymmtf);
592 
593  readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf);
594  print(" volTensorFields :", Info, vtf);
595  }
596 
597  label nVolFields =
598  vsf.size()
599  + vvf.size()
600  + vSpheretf.size()
601  + vSymmtf.size()
602  + vtf.size();
603 
604 
605  // Construct dimensioned fields
611 
612  if (!specifiedFields || selectedFields.size())
613  {
614  readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dsf);
615  print(" volScalarFields::Internal :", Info, dsf);
616 
617  readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dvf);
618  print(" volVectorFields::Internal :", Info, dvf);
619 
620  readFields
621  (
622  vMesh,
623  vMesh.baseMesh(),
624  objects,
625  selectedFields,
626  dSpheretf
627  );
628  print(" volSphericalTensorFields::Internal :", Info, dSpheretf);
629 
630  readFields
631  (
632  vMesh,
633  vMesh.baseMesh(),
634  objects,
635  selectedFields,
636  dSymmtf
637  );
638  print(" volSymmTensorFields::Internal :", Info, dSymmtf);
639 
640  readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dtf);
641  print(" volTensorFields::Internal :", Info, dtf);
642  }
643 
644  label nDimFields =
645  dsf.size()
646  + dvf.size()
647  + dSpheretf.size()
648  + dSymmtf.size()
649  + dtf.size();
650 
651 
652  // Construct pointMesh only if nessecary since constructs edge
653  // addressing (expensive on polyhedral meshes)
654  if (noPointValues)
655  {
656  Info<< " pointScalarFields : switched off"
657  << " (\"-noPointValues\" (at your option)\n";
658  Info<< " pointVectorFields : switched off"
659  << " (\"-noPointValues\" (at your option)\n";
660  }
661 
667 
668  if (!noPointValues && !(specifiedFields && selectedFields.empty()))
669  {
670  readFields
671  (
672  vMesh,
673  pointMesh::New(vMesh.baseMesh()),
674  objects,
675  selectedFields,
676  psf
677  );
678  print(" pointScalarFields :", Info, psf);
679 
680  readFields
681  (
682  vMesh,
683  pointMesh::New(vMesh.baseMesh()),
684  objects,
685  selectedFields,
686  pvf
687  );
688  print(" pointVectorFields :", Info, pvf);
689 
690  readFields
691  (
692  vMesh,
693  pointMesh::New(vMesh.baseMesh()),
694  objects,
695  selectedFields,
696  pSpheretf
697  );
698  print(" pointSphericalTensorFields :", Info, pSpheretf);
699 
700  readFields
701  (
702  vMesh,
703  pointMesh::New(vMesh.baseMesh()),
704  objects,
705  selectedFields,
706  pSymmtf
707  );
708  print(" pointSymmTensorFields :", Info, pSymmtf);
709 
710  readFields
711  (
712  vMesh,
713  pointMesh::New(vMesh.baseMesh()),
714  objects,
715  selectedFields,
716  ptf
717  );
718  print(" pointTensorFields :", Info, ptf);
719  }
720  Info<< endl;
721 
722  label nPointFields =
723  psf.size()
724  + pvf.size()
725  + pSpheretf.size()
726  + pSymmtf.size()
727  + ptf.size();
728 
729  Info<< " begin internal " << endl;
730  if (doWriteInternal)
731  {
732  //
733  // Create file and write header
734  //
735  fileName vtkFileName
736  (
737  fvPath/vtkName
738  + "_"
739  + timeDesc
740  + ".vtk"
741  );
742 
743  Info<< " Internal : " << vtkFileName << endl;
744 
745  Info << "writer defined!!" << endl <<endl;
746  // Write mesh
747  internalWriter writer(vMesh, binary, vtkFileName);
748  Info << "write defined OK!!" << endl;
749  // VolFields + cellID
750  writeFuns::writeCellDataHeader
751  (
752  writer.os(),
753  vMesh.nFieldCells(),
754  1 + nVolFields + nDimFields
755  );
756 
757  Info << "writeHeader defined!!" << endl;
758  // Write cellID field
759  writer.writeCellIDs();
760 
761  Info << "writeField defined!!" << endl;
762  // Write volFields
763  writer.write(vsf);
764  writer.write(vvf);
765  writer.write(vSpheretf);
766  writer.write(vSymmtf);
767  writer.write(vtf);
768 
769  // Write dimensionedFields
770  writer.write<scalar, volMesh>(dsf);
771  writer.write<vector, volMesh>(dvf);
772  writer.write<sphericalTensor, volMesh>(dSpheretf);
773  writer.write<symmTensor, volMesh>(dSymmtf);
774  writer.write<tensor, volMesh>(dtf);
775 
776  if (!noPointValues)
777  {
778  writeFuns::writePointDataHeader
779  (
780  writer.os(),
781  vMesh.nFieldPoints(),
782  nVolFields + nDimFields + nPointFields
783  );
784 
785  // pointFields
786  writer.write(psf);
787  writer.write(pvf);
788  writer.write(pSpheretf);
789  writer.write(pSymmtf);
790  writer.write(ptf);
791 
792  // Interpolated volFields
793  volPointInterpolation pInterp(mesh);
794  writer.write(pInterp, vsf);
795  writer.write(pInterp, vvf);
796  writer.write(pInterp, vSpheretf);
797  writer.write(pInterp, vSymmtf);
798  writer.write(pInterp, vtf);
799 
800  writer.write<scalar, volMesh>(pInterp, dsf);
801  writer.write<vector, volMesh>(pInterp, dvf);
802  writer.write<sphericalTensor, volMesh>(pInterp, dSpheretf);
803  writer.write<symmTensor, volMesh>(pInterp, dSymmtf);
804  writer.write<tensor, volMesh>(pInterp, dtf);
805  }
806  }
807 
808  //---------------------------------------------------------------------
809  //
810  // Write surface fields
811  //
812  //---------------------------------------------------------------------
813 
814  if (args.optionFound("surfaceFields"))
815  {
817  readFields
818  (
819  vMesh,
820  vMesh.baseMesh(),
821  objects,
822  selectedFields,
823  ssf
824  );
825  print(" surfScalarFields :", Info, ssf);
826 
828  readFields
829  (
830  vMesh,
831  vMesh.baseMesh(),
832  objects,
833  selectedFields,
834  svf
835  );
836  print(" surfVectorFields :", Info, svf);
837 
838  if (ssf.size() + svf.size() > 0)
839  {
840  // Rework the scalar fields into vectorfields.
841  label sz = svf.size();
842 
843  svf.setSize(sz+ssf.size());
844 
846 
847  forAll(ssf, i)
848  {
849  svf.set(sz+i, ssf[i]*n);
850  svf[sz+i].rename(ssf[i].name());
851  }
852  ssf.clear();
853 
854  mkDir(fvPath / "surfaceFields");
855 
856  fileName surfFileName
857  (
858  fvPath
859  /"surfaceFields"
860  /"surfaceFields"
861  + "_"
862  + timeDesc
863  + ".vtk"
864  );
865 
867  (
868  binary,
869  vMesh,
870  surfFileName,
871  svf
872  );
873  }
874  }
875 
876 
877  //---------------------------------------------------------------------
878  //
879  // Write patches (POLYDATA file, one for each patch)
880  //
881  //---------------------------------------------------------------------
882 
884 
885  if (allPatches)
886  {
887  mkDir(fvPath/"allPatches");
888 
889  fileName patchFileName;
890 
891  if (vMesh.useSubMesh())
892  {
893  patchFileName =
894  fvPath/"allPatches"/cellSetName
895  + "_"
896  + timeDesc
897  + ".vtk";
898  }
899  else
900  {
901  patchFileName =
902  fvPath/"allPatches"/"allPatches"
903  + "_"
904  + timeDesc
905  + ".vtk";
906  }
907 
908  Info<< " Combined patches : " << patchFileName << endl;
909 
911  (
912  vMesh,
913  binary,
914  nearCellValue,
915  patchFileName,
916  getSelectedPatches(patches, excludePatches)
917  );
918 
919  // VolFields + patchID
920  writeFuns::writeCellDataHeader
921  (
922  writer.os(),
923  writer.nFaces(),
924  1+nVolFields
925  );
926 
927  // Write patchID field
928  writer.writePatchIDs();
929 
930  // Write volFields
931  writer.write(vsf);
932  writer.write(vvf);
933  writer.write(vSpheretf);
934  writer.write(vSymmtf);
935  writer.write(vtf);
936 
937  if (!noPointValues)
938  {
939  writeFuns::writePointDataHeader
940  (
941  writer.os(),
942  writer.nPoints(),
943  nPointFields
944  );
945 
946  // Write pointFields
947  writer.write(psf);
948  writer.write(pvf);
949  writer.write(pSpheretf);
950  writer.write(pSymmtf);
951  writer.write(ptf);
952 
953  // no interpolated volFields since I cannot be bothered to
954  // create the patchInterpolation for all subpatches.
955  }
956  }
957  else
958  {
959  forAll(patches, patchI)
960  {
961  const polyPatch& pp = patches[patchI];
962 
963  if (!findStrings(excludePatches, pp.name()))
964  {
965  mkDir(fvPath);
966 
967  fileName patchFileName;
968 
969  if (vMesh.useSubMesh())
970  {
971  patchFileName =
972  fvPath/cellSetName
973  + "_"
974  + timeDesc
975  + ".vtk";
976  }
977  else
978  {
979  patchFileName =
980  fvPath/pp.name()
981  + "_"
982  + timeDesc
983  + ".vtk";
984  }
985 
986  Info<< " Patch : " << patchFileName << endl;
987 
989  (
990  vMesh,
991  binary,
992  nearCellValue,
993  patchFileName,
994  labelList(1, patchI)
995  );
996 
997  if (!isA<emptyPolyPatch>(pp))
998  {
999  // VolFields + patchID
1000  writeFuns::writeCellDataHeader
1001  (
1002  writer.os(),
1003  writer.nFaces(),
1004  1+nVolFields
1005  );
1006 
1007  // Write patchID field
1008  writer.writePatchIDs();
1009 
1010  // Write volFields
1011  writer.write(vsf);
1012  writer.write(vvf);
1013  writer.write(vSpheretf);
1014  writer.write(vSymmtf);
1015  writer.write(vtf);
1016 
1017  if (!noPointValues)
1018  {
1019  writeFuns::writePointDataHeader
1020  (
1021  writer.os(),
1022  writer.nPoints(),
1023  nVolFields
1024  + nPointFields
1025  );
1026 
1027  // Write pointFields
1028  writer.write(psf);
1029  writer.write(pvf);
1030  writer.write(pSpheretf);
1031  writer.write(pSymmtf);
1032  writer.write(ptf);
1033 
1035  (
1036  pp
1037  );
1038 
1039  // Write interpolated volFields
1040  writer.write(pInter, vsf);
1041  writer.write(pInter, vvf);
1042  writer.write(pInter, vSpheretf);
1043  writer.write(pInter, vSymmtf);
1044  writer.write(pInter, vtf);
1045  }
1046  }
1047  }
1048  }
1049  }
1050 
1051  //---------------------------------------------------------------------
1052  //
1053  // Write faceZones (POLYDATA file, one for each zone)
1054  //
1055  //---------------------------------------------------------------------
1056 
1057  if (doFaceZones)
1058  {
1060  readFields
1061  (
1062  vMesh,
1063  vMesh.baseMesh(),
1064  objects,
1065  selectedFields,
1066  ssf
1067  );
1068  print(" surfScalarFields :", Info, ssf);
1069 
1071  readFields
1072  (
1073  vMesh,
1074  vMesh.baseMesh(),
1075  objects,
1076  selectedFields,
1077  svf
1078  );
1079  print(" surfVectorFields :", Info, svf);
1080 
1081  const faceZoneMesh& zones = mesh.faceZones();
1082 
1083  forAll(zones, zoneI)
1084  {
1085  const faceZone& fz = zones[zoneI];
1086 
1087  mkDir(fvPath);
1088 
1089  fileName patchFileName;
1090 
1091  if (vMesh.useSubMesh())
1092  {
1093  patchFileName =
1094  fvPath/cellSetName
1095  + "_"
1096  + timeDesc
1097  + ".vtk";
1098  }
1099  else
1100  {
1101  patchFileName =
1102  fvPath/fz.name()
1103  + "_"
1104  + timeDesc
1105  + ".vtk";
1106  }
1107 
1108  Info<< " FaceZone : " << patchFileName << endl;
1109 
1111  (
1112  IndirectList<face>(mesh.faces(), fz),
1113  mesh.points()
1114  );
1115 
1117  (
1118  binary,
1119  pp,
1120  fz.name(),
1121  patchFileName
1122  );
1123 
1124  // Number of fields
1125  writeFuns::writeCellDataHeader
1126  (
1127  writer.os(),
1128  pp.size(),
1129  ssf.size()+svf.size()
1130  );
1131 
1132  writer.write(ssf);
1133  writer.write(svf);
1134  }
1135  }
1136 
1137 
1138 
1139  //---------------------------------------------------------------------
1140  //
1141  // Write lagrangian data
1142  //
1143  //---------------------------------------------------------------------
1144 
1145  forAllConstIter(HashSet<fileName>, allCloudDirs, iter)
1146  {
1147  const fileName& cloudName = iter.key();
1148 
1149  // Always create the cloud directory.
1150  mkDir(fvPath/cloud::prefix/cloudName);
1151 
1152  fileName lagrFileName
1153  (
1154  fvPath/cloud::prefix/cloudName/cloudName
1155  + "_" + timeDesc + ".vtk"
1156  );
1157 
1158  Info<< " Lagrangian: " << lagrFileName << endl;
1159 
1160 
1161  IOobjectList sprayObjs
1162  (
1163  mesh,
1164  runTime.timeName(),
1165  cloud::prefix/cloudName
1166  );
1167 
1168  IOobject* positionsPtr = sprayObjs.lookup(word("positions"));
1169 
1170  if (positionsPtr)
1171  {
1172  wordList labelNames(sprayObjs.names(labelIOField::typeName));
1173  Info<< " labels :";
1174  print(Info, labelNames);
1175 
1176  wordList scalarNames(sprayObjs.names(scalarIOField::typeName));
1177  Info<< " scalars :";
1178  print(Info, scalarNames);
1179 
1180  wordList vectorNames(sprayObjs.names(vectorIOField::typeName));
1181  Info<< " vectors :";
1182  print(Info, vectorNames);
1183 
1184  wordList sphereNames
1185  (
1186  sprayObjs.names
1187  (
1188  sphericalTensorIOField::typeName
1189  )
1190  );
1191  Info<< " spherical tensors :";
1192  print(Info, sphereNames);
1193 
1194  wordList symmNames
1195  (
1196  sprayObjs.names
1197  (
1198  symmTensorIOField::typeName
1199  )
1200  );
1201  Info<< " symm tensors :";
1202  print(Info, symmNames);
1203 
1204  wordList tensorNames(sprayObjs.names(tensorIOField::typeName));
1205  Info<< " tensors :";
1206  print(Info, tensorNames);
1207 
1209  (
1210  vMesh,
1211  binary,
1212  lagrFileName,
1213  cloudName,
1214  false
1215  );
1216 
1217  // Write number of fields
1218  writer.writeParcelHeader
1219  (
1220  labelNames.size()
1221  + scalarNames.size()
1222  + vectorNames.size()
1223  + sphereNames.size()
1224  + symmNames.size()
1225  + tensorNames.size()
1226  );
1227 
1228  // Fields
1229  writer.writeIOField<label>(labelNames);
1230  writer.writeIOField<scalar>(scalarNames);
1231  writer.writeIOField<vector>(vectorNames);
1232  writer.writeIOField<sphericalTensor>(sphereNames);
1233  writer.writeIOField<symmTensor>(symmNames);
1234  writer.writeIOField<tensor>(tensorNames);
1235  }
1236  else
1237  {
1239  (
1240  vMesh,
1241  binary,
1242  lagrFileName,
1243  cloudName,
1244  true
1245  );
1246 
1247  // Write number of fields
1248  writer.writeParcelHeader(0);
1249  }
1250  }
1251  }
1252 
1253 
1254  //---------------------------------------------------------------------
1255  //
1256  // Link parallel outputs back to undecomposed case for ease of loading
1257  //
1258  //---------------------------------------------------------------------
1259 
1260  if (Pstream::parRun() && doLinks)
1261  {
1262  mkDir(runTime.path()/".."/"VTK");
1263  chDir(runTime.path()/".."/"VTK");
1264 
1265  Info<< "Linking all processor files to " << runTime.path()/".."/"VTK"
1266  << endl;
1267 
1268  // Get list of vtk files
1269  fileName procVTK
1270  (
1271  fileName("..")
1272  /"processor" + name(Pstream::myProcNo())
1273  /"VTK"
1274  );
1275 
1276  fileNameList dirs(readDir(procVTK, fileName::DIRECTORY));
1277  label sz = dirs.size();
1278  dirs.setSize(sz+1);
1279  dirs[sz] = ".";
1280 
1281  forAll(dirs, i)
1282  {
1283  fileNameList subFiles(readDir(procVTK/dirs[i], fileName::FILE));
1284 
1285  forAll(subFiles, j)
1286  {
1287  fileName procFile(procVTK/dirs[i]/subFiles[j]);
1288 
1289  if (exists(procFile))
1290  {
1291  string cmd
1292  (
1293  "ln -s "
1294  + procFile
1295  + " "
1296  + "processor"
1297  + name(Pstream::myProcNo())
1298  + "_"
1299  + procFile.name()
1300  );
1301  if (system(cmd.c_str()) == -1)
1302  {
1304  << "Could not execute command " << cmd << endl;
1305  }
1306  }
1307  }
1308  }
1309  }
1310 
1311  Info<< "End\n" << endl;
1312 
1313  return 0;
1314 }
1315 
1316 
1317 // ************************************************************************* //
patchWriter.H
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::doubleScalar
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:49
Foam::sphericalTensor
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars.
Definition: sphericalTensor.H:48
Foam::SymmTensor< scalar >
writePointSet.H
Write pointSet to vtk polydata file. Only one data which is original pointID.
writeFuns.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
print
void print(const char *msg, Ostream &os, const PtrList< GeoField > &flds)
Definition: foamToVTK.C:164
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::exists
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:608
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:47
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Cloud.H
Foam::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
tensorIOField.H
Foam::faceSet
A list of face labels.
Definition: faceSet.H:48
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
scalarIOField.H
Foam::vtkMesh
Encapsulation of VTK mesh data. Holds mesh or meshsubset and polyhedral-cell decomposition on it.
Definition: vtkMesh.H:52
Foam::IOobjectList::names
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:221
surfaceMeshWriter.H
Foam::internalWriter
Write fields (internal).
Definition: internalWriter.H:56
readFields.H
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
writeFaceSet.H
Write faceSet to vtk polydata file. Only one data which is original faceID.
writeSurfFields.H
Write a patch with its data.
Foam::fileName::name
word name() const
Return file name (part beyond last /)
Definition: fileName.C:212
Foam::writeFaceSet
void writeFaceSet(const bool binary, const vtkMesh &vMesh, const faceSet &set, const fileName &fileName)
Definition: writeFaceSet.C:33
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::vtkMesh::baseMesh
const fvMesh & baseMesh() const
Whole mesh.
Definition: vtkMesh.H:92
Foam::fvMesh::magSf
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
Definition: fvMeshGeometry.C:358
Foam::patchWriter
Write patch fields.
Definition: patchWriter.H:59
n
label n
Definition: TABSMDCalcMethod2.H:31
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
lagrangianWriter.H
Foam::PtrList::set
bool set(const label) const
Is element set.
vtkMesh.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::HashTable< nil, word, string::hash >::empty
bool empty() const
Return true if the hash table is empty.
Definition: HashTableI.H:72
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
passiveParticle.H
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:102
addRegionOption.H
Foam::ZoneMesh< faceZone, polyMesh >
Foam::symmTensor
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:48
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
Foam::DynamicList::shrink
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:258
Foam::fixed
IOstream & fixed(IOstream &io)
Definition: IOstream.H:576
Foam::IOobjectList::lookup
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else NULL.
Definition: IOobjectList.C:128
Foam::FatalError
error FatalError
Foam::HashTable< nil, word, string::hash >::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
createNamedMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
faceZoneMesh.H
Foam::faceZoneMesh.
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
Foam::fvMesh::Sf
const surfaceVectorField & Sf() const
Return cell face area vectors.
Definition: fvMeshGeometry.C:347
Foam::PtrList::clear
void clear()
Clear the PtrList, i.e. set size to zero deleting all the.
Definition: PtrList.C:185
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::zone::name
const word & name() const
Return name.
Definition: zone.H:150
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Foam::SphericalTensor
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor.H:51
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
emptyPolyPatch.H
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::writeSurfFields
void writeSurfFields(const bool binary, const vtkMesh &vMesh, const fileName &fileName, const PtrList< surfaceVectorField > &surfVectorFields)
Definition: writeSurfFields.C:41
Foam::vtkMesh::mesh
const fvMesh & mesh() const
Access either mesh or submesh.
Definition: vtkMesh.H:119
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
volPointInterpolation.H
Foam::chDir
bool chDir(const fileName &dir)
Change the current directory to the one given and return true,.
Definition: POSIX.C:264
Foam::List::setSize
void setSize(const label)
Reset size of List.
setRootCase.H
timeDirs
static instantList timeDirs
Definition: globalFoam.H:44
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::PrimitivePatchInterpolation
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
Definition: PrimitivePatchInterpolation.H:51
Foam::pointSet
A set of point labels.
Definition: pointSet.H:48
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
readFields
void readFields(const boolList &haveMesh, const fvMesh &mesh, const autoPtr< fvMeshSubset > &subsetterPtr, IOobjectList &allObjects, PtrList< GeoField > &fields)
Definition: redistributePar.C:589
Foam::vtkMesh::nFieldPoints
label nFieldPoints() const
Number of field points.
Definition: vtkMesh.H:139
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::PtrList::setSize
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
createTime.H
cloudName
const word cloudName(propsDict.lookup("cloudName"))
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::surfaceMeshWriter
Write faces with fields.
Definition: surfaceMeshWriter.H:58
Foam::vtkMesh::useSubMesh
bool useSubMesh() const
Check if running subMesh.
Definition: vtkMesh.H:103
symmTensorIOField.H
fvCFD.H
stringListOps.H
Operations on lists of strings.
patches
patches[0]
Definition: createSingleCellMesh.H:36
main
int main(int argc, char *argv[])
Definition: foamToVTK.C:228
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
sphericalTensorIOField.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::readDir
fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true)
Read a directory and return the entries as a string list.
Definition: POSIX.C:660
Foam::vtkMesh::readUpdate
polyMesh::readUpdateState readUpdate()
Read mesh.
Definition: vtkMesh.C:62
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
args
Foam::argList args(argc, argv)
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::vtkMesh::nFieldCells
label nFieldCells() const
Number of field cells.
Definition: vtkMesh.H:133
Foam::argList::optionReadIfPresent
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
getSelectedPatches
labelList getSelectedPatches(const polyBoundaryMesh &patches, const List< wordRe > &excludePatches)
Definition: foamToVTK.C:189
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
Foam::volPointInterpolation
Interpolate from cell centres to points (vertices) using inverse distance weighting.
Definition: volPointInterpolation.H:56
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::system
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1155
Foam::rmDir
bool rmDir(const fileName &)
Remove a dirctory and its contents.
Definition: POSIX.C:974
Foam::lagrangianWriter
Write fields (internal).
Definition: lagrangianWriter.H:57
pointMesh.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::writePointSet
void writePointSet(const bool binary, const primitiveMesh &mesh, const topoSet &set, const fileName &fileName)
Write pointSet to vtk polydata file.
labelIOField.H
Foam::argList::optionLookup
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
Definition: argListI.H:114
internalWriter.H
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88