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.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Description
27  Code chunk for post-processing conversion of cloud(s) to VTK PolyData
28  (.vtp extension).
29 
30 \*---------------------------------------------------------------------------*/
31 
32 if (doLagrangian)
33 {
34  const fileName cloudPrefix = (regionDir/cloud::prefix);
35 
36  wordList cloudNames = ListOps::create<word>
37  (
38  readDir
39  (
40  mesh.time().path()/mesh.time().timeName()/cloudPrefix,
41  fileName::DIRECTORY
42  ),
43  nameOp<fileName>()
44  );
45 
46  if (Pstream::parRun())
47  {
48  // Synchronise cloud names
49  Pstream::combineReduce(cloudNames, ListOps::uniqueEqOp<word>());
50  }
51  Foam::sort(cloudNames); // Consistent order
52 
53  for (const word& cloudName : cloudNames)
54  {
55  IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName);
56 
57  bool isCloud = false;
58  if (cloudObjs.erase("coordinates"))
59  {
60  isCloud = true;
61  }
62  if (cloudObjs.erase("positions"))
63  {
64  isCloud = true;
65  }
66 
67  if (!returnReduceOr(isCloud))
68  {
69  continue;
70  }
71 
72  // Limited to basic IOField types
73  cloudObjs.filterClasses
74  (
75  stringListOps::foundOp<word>(fieldTypes::basic)
76  );
77 
78  // Are there cloud fields (globally)?
79  if (returnReduceAnd(cloudObjs.empty()))
80  {
81  continue;
82  }
83 
84  vtk::lagrangianWriter writer
85  (
86  meshProxy.baseMesh(),
87  cloudName,
88  writeOpts,
89  // Output name for the cloud
90  (
91  outputDir/regionDir/cloud::prefix
92  / cloudName/cloudName + timeDesc
93  ),
94  Pstream::parRun()
95  );
96 
97  Info<< " Lagrangian: "
98  << args.relativePath(writer.output()) << nl;
99 
100  writer.writeTimeValue(mesh.time().value());
101  writer.writeGeometry();
102 
103  // Begin CellData/PointData
104  writer.beginParcelData();
105 
106  writer.writeFields<label>(cloudObjs);
107  writer.writeFields<scalar>(cloudObjs);
108  writer.writeFields<vector>(cloudObjs);
109  writer.writeFields<sphericalTensor>(cloudObjs);
110  writer.writeFields<symmTensor>(cloudObjs);
111  writer.writeFields<tensor>(cloudObjs);
112 
113  fileName outputName(writer.output());
114 
115  writer.close();
116 
117  if (Pstream::master())
118  {
119  // Add to file-series and emit as JSON
120 
121  fileName seriesName(vtk::seriesWriter::base(outputName));
122 
123  vtk::seriesWriter& series = vtkSeries(seriesName);
124 
125  // First time?
126  // Load from file, verify against filesystem,
127  // prune time >= currentTime
128  if (series.empty())
129  {
130  series.load(seriesName, true, timeValue);
131  }
132 
133  series.append(timeValue, outputName);
134  series.write(seriesName);
135  }
136  }
137 }
138 
139 
140 // ************************************************************************* //
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:334
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)
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
List< word > wordList
A List of words.
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:916
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.