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  if (UPstream::parRun())
34  {
35  // Synchronise cloud names
36  Pstream::combineReduce(cloudNames, ListOps::uniqueEqOp<word>());
37  }
38  Foam::sort(cloudNames); // Consistent order
39 
40  for (const word& cloudName : cloudNames)
41  {
42  IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName);
43 
44  bool isCloud = false;
45  if (cloudObjs.erase("coordinates"))
46  {
47  isCloud = true;
48  }
49  if (cloudObjs.erase("positions"))
50  {
51  isCloud = true;
52  }
53 
54  if (!returnReduceOr(isCloud))
55  {
56  continue;
57  }
58 
59  // Limited to basic IOField types
60  cloudObjs.filterClasses
61  (
62  stringListOps::foundOp<word>(fieldTypes::basic)
63  );
64 
65  // Are there cloud fields (globally)?
66  if (returnReduceAnd(cloudObjs.empty()))
67  {
68  continue;
69  }
70 
71  vtk::lagrangianWriter writer
72  (
73  meshProxy.baseMesh(),
74  cloudName,
75  writeOpts,
76  // Output name for the cloud
77  (
78  outputDir/regionDir/cloud::prefix
79  / cloudName/cloudName + timeDesc
80  ),
81  UPstream::parRun()
82  );
83 
84  Info<< " Lagrangian: "
85  << args.relativePath(writer.output()) << nl;
86 
87  writer.writeTimeValue(mesh.time().value());
88  writer.writeGeometry();
89 
90  // Begin CellData/PointData
91  writer.beginParcelData();
92 
93  writer.writeFields<label>(cloudObjs);
94  writer.writeFields<scalar>(cloudObjs);
95  writer.writeFields<vector>(cloudObjs);
96  writer.writeFields<sphericalTensor>(cloudObjs);
97  writer.writeFields<symmTensor>(cloudObjs);
98  writer.writeFields<tensor>(cloudObjs);
99 
100  fileName outputName(writer.output());
101 
102  writer.close();
103 
104  if (UPstream::master())
105  {
106  // Add to file-series and emit as JSON
107 
108  fileName seriesName(vtk::seriesWriter::base(outputName));
109 
110  vtk::seriesWriter& series = vtkSeries(seriesName);
111 
112  // First time?
113  // Load from file, verify against filesystem,
114  // prune time >= currentTime
115  if (series.empty())
116  {
117  series.load(seriesName, true, timeValue);
118  }
119 
120  series.append(timeValue, outputName);
121  series.write(seriesName);
122  }
123  }
124 }
125 
126 
127 // ************************************************************************* //
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:49
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:348
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:58
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.