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-2021 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  // Synchronise cloud names
47  Pstream::combineGather(cloudNames, ListOps::uniqueEqOp<word>());
48  Pstream::combineScatter(cloudNames);
49 
50  // Consistent order
51  Foam::sort(cloudNames);
52 
53 
54  for (const word& cloudName : cloudNames)
55  {
56  IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName);
57 
58  bool isCloud = false;
59  if (cloudObjs.erase("coordinates"))
60  {
61  isCloud = true;
62  }
63  if (cloudObjs.erase("positions"))
64  {
65  isCloud = true;
66  }
67 
68  if (!returnReduce(isCloud, orOp<bool>()))
69  {
70  continue;
71  }
72 
73  // Limited to basic IOField types
74  cloudObjs.filterClasses
75  (
76  stringListOps::foundOp<word>(fieldTypes::basic)
77  );
78 
79  // Are there cloud fields (globally)?
80  if (returnReduce(cloudObjs.empty(), andOp<bool>()))
81  {
82  continue;
83  }
84 
85  vtk::lagrangianWriter writer
86  (
87  meshProxy.baseMesh(),
88  cloudName,
89  writeOpts,
90  // Output name for the cloud
91  (
92  outputDir/regionDir/cloud::prefix
93  / cloudName/cloudName + timeDesc
94  ),
95  Pstream::parRun()
96  );
97 
98  Info<< " Lagrangian: "
99  << args.relativePath(writer.output()) << nl;
100 
101  writer.writeTimeValue(mesh.time().value());
102  writer.writeGeometry();
103 
104  // Begin CellData/PointData
105  writer.beginParcelData();
106 
107  writer.writeFields<label>(cloudObjs);
108  writer.writeFields<scalar>(cloudObjs);
109  writer.writeFields<vector>(cloudObjs);
110  writer.writeFields<sphericalTensor>(cloudObjs);
111  writer.writeFields<symmTensor>(cloudObjs);
112  writer.writeFields<tensor>(cloudObjs);
113 
114  fileName outputName(writer.output());
115 
116  writer.close();
117 
118  if (Pstream::master())
119  {
120  // Add to file-series and emit as JSON
121 
122  fileName seriesName(vtk::seriesWriter::base(outputName));
123 
124  vtk::seriesWriter& series = vtkSeries(seriesName);
125 
126  // First time?
127  // Load from file, verify against filesystem,
128  // prune time >= currentTime
129  if (series.empty())
130  {
131  series.load(seriesName, true, timeValue);
132  }
133 
134  series.append(timeValue, outputName);
135  series.write(seriesName);
136  }
137  }
138 }
139 
140 
141 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::sphericalTensor
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
Definition: sphericalTensor.H:54
cloudName
const word cloudName(propsDict.get< word >("cloud"))
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
outputName
word outputName("finiteArea-edges.obj")
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:261
Foam::symmTensor
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:59
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::nl
constexpr char nl
Definition: Ostream.H:404
regionDir
const word & regionDir
Definition: findMeshDefinitionDict.H:34
args
Foam::argList args(argc, argv)
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::readDir
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: MSwindows.C:707
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars, i.e. Tensor<scalar>.
Definition: symmTensor.H:61
Foam::argList::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: argListI.H:94
Foam::fieldTypes::basic
const wordList basic
Standard basic field types (label, scalar, vector, tensor, etc)