Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
14 Code chunk for post-processing conversion of cloud(s) to VTK PolyData
15 (.vtp extension).
16
17\*---------------------------------------------------------------------------*/
18
19if (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(Foam::fieldTypes::is_basic);
57
58 // Are there cloud fields (globally)?
59 if (returnReduceAnd(cloudObjs.empty()))
60 {
61 continue;
62 }
63
64 vtk::lagrangianWriter writer
65 (
66 meshProxy.baseMesh(),
68 writeOpts,
69 // Output name for the cloud
70 (
71 outputDir/regionDir/cloud::prefix
72 / cloudName/cloudName + timeDesc
73 ),
74 UPstream::parRun()
75 );
76
77 Info<< " Lagrangian: "
78 << args.relativePath(writer.output()) << nl;
79
80 writer.writeTimeValue(mesh.time().value());
81 writer.writeGeometry();
82
83 // Begin CellData/PointData
84 writer.beginParcelData();
85
86 writer.writeFields<label>(cloudObjs);
87 writer.writeFields<scalar>(cloudObjs);
88 writer.writeFields<vector>(cloudObjs);
89 writer.writeFields<sphericalTensor>(cloudObjs);
90 writer.writeFields<symmTensor>(cloudObjs);
91 writer.writeFields<tensor>(cloudObjs);
92
93 fileName outputName(writer.output());
94
95 writer.close();
96
97 if (UPstream::master())
98 {
99 // Add to file-series and emit as JSON
100
101 fileName seriesName(vtk::seriesWriter::base(outputName));
102
103 vtk::seriesWriter& series = vtkSeries(seriesName);
104
105 // First time?
106 // Load from file, verify against filesystem,
107 // prune time >= currentTime
108 if (series.empty())
109 {
110 series.load(seriesName, true, timeValue);
111 }
112
113 series.append(timeValue, outputName);
114 series.write(seriesName);
115 }
116 }
117}
118
119
120// ************************************************************************* //
const word cloudName(propsDict.get< word >("cloud"))
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
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
bool is_basic(const word &clsName)
Test if the class name appears to be a basic field.
Definition fieldTypes.C:73
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
messageStream Info
Information stream (stdout output on master, null elsewhere).
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
void sort(UList< T > &list)
Sort the list.
Definition UList.C:283
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)