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-------------------------------------------------------------------------------
10License
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
26Description
27 Code chunk for post-processing conversion of cloud(s) to VTK PolyData
28 (.vtp extension).
29
30\*---------------------------------------------------------------------------*/
31
32if (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::combineGather(cloudNames, ListOps::uniqueEqOp<word>());
50 Pstream::broadcast(cloudNames);
51 }
52 // Consistent order
53 Foam::sort(cloudNames);
54
55 for (const word& cloudName : cloudNames)
56 {
57 IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName);
58
59 bool isCloud = false;
60 if (cloudObjs.erase("coordinates"))
61 {
62 isCloud = true;
63 }
64 if (cloudObjs.erase("positions"))
65 {
66 isCloud = true;
67 }
68
69 if (!returnReduce(isCloud, orOp<bool>()))
70 {
71 continue;
72 }
73
74 // Limited to basic IOField types
75 cloudObjs.filterClasses
76 (
77 stringListOps::foundOp<word>(fieldTypes::basic)
78 );
79
80 // Are there cloud fields (globally)?
81 if (returnReduce(cloudObjs.empty(), andOp<bool>()))
82 {
83 continue;
84 }
85
86 vtk::lagrangianWriter writer
87 (
88 meshProxy.baseMesh(),
90 writeOpts,
91 // Output name for the cloud
92 (
93 outputDir/regionDir/cloud::prefix
94 / cloudName/cloudName + timeDesc
95 ),
96 Pstream::parRun()
97 );
98
99 Info<< " Lagrangian: "
100 << args.relativePath(writer.output()) << nl;
101
102 writer.writeTimeValue(mesh.time().value());
103 writer.writeGeometry();
104
105 // Begin CellData/PointData
106 writer.beginParcelData();
107
108 writer.writeFields<label>(cloudObjs);
109 writer.writeFields<scalar>(cloudObjs);
110 writer.writeFields<vector>(cloudObjs);
111 writer.writeFields<sphericalTensor>(cloudObjs);
112 writer.writeFields<symmTensor>(cloudObjs);
113 writer.writeFields<tensor>(cloudObjs);
114
115 fileName outputName(writer.output());
116
117 writer.close();
118
119 if (Pstream::master())
120 {
121 // Add to file-series and emit as JSON
122
123 fileName seriesName(vtk::seriesWriter::base(outputName));
124
125 vtk::seriesWriter& series = vtkSeries(seriesName);
126
127 // First time?
128 // Load from file, verify against filesystem,
129 // prune time >= currentTime
130 if (series.empty())
131 {
132 series.load(seriesName, true, timeValue);
133 }
134
135 series.append(timeValue, outputName);
136 series.write(seriesName);
137 }
138 }
139}
140
141
142// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: argListI.H:94
Tensor of scalars, i.e. Tensor<scalar>.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
dynamicFvMesh & mesh
engineTime & runTime
word outputName("finiteArea-edges.obj")
const word & regionDir
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
Foam::argList args(argc, argv)
const word cloudName(propsDict.get< word >("cloud"))