convertLagrangian.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Code chunk for post-processing conversion of cloud(s) to VTK PolyData
15  (.vtp extension).
16 
17 \*---------------------------------------------------------------------------*/
18 
19 if (doLagrangian)
20 {
21  const fileName cloudPrefix = (regionDir/cloud::prefix);
22 
23  wordList cloudNames = ListOps::create<word>
24  (
25  readDir
26  (
27  mesh.time().path()/mesh.time().timeName()/cloudPrefix,
28  fileName::DIRECTORY
29  ),
30  nameOp<fileName>()
31  );
32 
33  Pstream::combineReduce(cloudNames, ListOps::uniqueEqOp<word>());
34  Foam::sort(cloudNames); // Consistent order
35 
36  for (const word& cloudName : cloudNames)
37  {
38  IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName);
39 
40  bool isCloud = false;
41  if (cloudObjs.erase("coordinates"))
42  {
43  isCloud = true;
44  }
45  if (cloudObjs.erase("positions"))
46  {
47  isCloud = true;
48  }
49 
50  if (!returnReduceOr(isCloud))
51  {
52  continue;
53  }
54 
55  // Limited to basic IOField types
56  cloudObjs.filterClasses
57  (
58  stringListOps::foundOp<word>(fieldTypes::basic)
59  );
60 
61  // Are there cloud fields (globally)?
62  if (returnReduceAnd(cloudObjs.empty()))
63  {
64  continue;
65  }
66 
67  vtk::lagrangianWriter writer
68  (
69  meshProxy.baseMesh(),
70  cloudName,
71  writeOpts,
72  // Output name for the cloud
73  (
74  outputDir/regionDir/cloud::prefix
75  / cloudName/cloudName + timeDesc
76  ),
77  UPstream::parRun()
78  );
79 
80  Info<< " Lagrangian: "
81  << args.relativePath(writer.output()) << nl;
82 
83  writer.writeTimeValue(mesh.time().value());
84  writer.writeGeometry();
85 
86  // Begin CellData/PointData
87  writer.beginParcelData();
88 
89  writer.writeFields<label>(cloudObjs);
90  writer.writeFields<scalar>(cloudObjs);
91  writer.writeFields<vector>(cloudObjs);
92  writer.writeFields<sphericalTensor>(cloudObjs);
93  writer.writeFields<symmTensor>(cloudObjs);
94  writer.writeFields<tensor>(cloudObjs);
95 
96  fileName outputName(writer.output());
97 
98  writer.close();
99 
100  if (UPstream::master())
101  {
102  // Add to file-series and emit as JSON
103 
104  fileName seriesName(vtk::seriesWriter::base(outputName));
105 
106  vtk::seriesWriter& series = vtkSeries(seriesName);
107 
108  // First time?
109  // Load from file, verify against filesystem,
110  // prune time >= currentTime
111  if (series.empty())
112  {
113  series.load(seriesName, true, timeValue);
114  }
115 
116  series.append(timeValue, outputName);
117  series.write(seriesName);
118  }
119  }
120 }
121 
122 
123 // ************************************************************************* //
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void combineReduce(T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Compatibility wrapper for Pstream::combineReduce.
engineTime & runTime
Tensor< scalar > tensor
Definition: symmTensor.H:57
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
word outputName("finiteArea-edges.obj")
dynamicFvMesh & mesh
const word cloudName(propsDict.get< word >("cloud"))
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:55
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
Vector< scalar > vector
Definition: vector.H:57
fileName relativePath(const fileName &input, const bool caseTag=false) const
Return the input relative to the globalPath by stripping off a leading value of the globalPath...
Definition: argListI.H:87
const wordList basic
Standard basic field types (label, scalar, vector, tensor, etc)
List< word > wordList
List of word.
Definition: fileName.H:59
const word & regionDir
messageStream Info
Information stream (stdout output on master, null elsewhere)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: POSIX.C:963
Foam::argList args(argc, argv)
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.