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-------------------------------------------------------------------------------
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 Ensight
15
16\*---------------------------------------------------------------------------*/
17
18// Cloud field data output
19if (doLagrangian)
20{
21 // Lagrangian
22 const auto& cloudFields = regionCloudFields[regioni];
23 const auto& cloudNames = regionCloudNames[regioni];
24
25 for (const word& cloudName : cloudNames)
26 {
27 const HashTable<word>& theseCloudFields = cloudFields[cloudName];
29 fileNameList currentCloudDirs
30 (
31 readDir
32 (
33 runTime.timePath()/regionDir/cloud::prefix,
34 fileName::DIRECTORY
35 )
36 );
37
38 Info<< "Cloud " << cloudName << " (";
39
40 const bool cloudExists =
41 returnReduce(currentCloudDirs.found(cloudName), orOp<bool>());
42
43 {
44 autoPtr<ensightFile> os = ensCase.newCloud(cloudName);
45
46 ensightOutput::writeCloudPositions
47 (
48 mesh,
50 cloudExists,
51 os
52 );
53
54 Info<< " positions";
55 if (!cloudExists)
56 {
57 Info<< "{0}"; // report empty field
58 }
59 }
60
61 // Field order may differ on individual processors, so sort by name
62 for (const word& fieldName : theseCloudFields.sortedToc())
63 {
64 const word& fieldType = theseCloudFields[fieldName];
65
66 IOobject fieldObject
67 (
68 fieldName,
69 mesh.time().timeName(),
70 cloud::prefix/cloudName,
71 mesh,
72 IOobject::MUST_READ
73 );
74
75 bool fieldExists = cloudExists; // No field without positions
76 if (cloudExists)
77 {
78 // Want MUST_READ (globally) and valid=false (locally),
79 // but that combination does not work.
80 // So check the header and sync globally
81
82 const bool oldParRun = Pstream::parRun(false);
83 fieldExists = fieldObject.typeHeaderOk<IOField<scalar>>(false);
84 Pstream::parRun(oldParRun); // Restore parallel state
85 reduce(fieldExists, orOp<bool>());
86 }
87
88 bool wrote = false;
89 if (fieldType == scalarIOField::typeName)
90 {
91 autoPtr<ensightFile> os =
92 ensCase.newCloudData<scalar>(cloudName, fieldName);
93
94 wrote = ensightOutput::writeCloudField<scalar>
95 (
96 fieldObject, fieldExists, os
97 );
98 }
99 else if (fieldType == vectorIOField::typeName)
100 {
101 autoPtr<ensightFile> os =
102 ensCase.newCloudData<vector>(cloudName, fieldName);
103
104 wrote = ensightOutput::writeCloudField<vector>
105 (
106 fieldObject, fieldExists, os
107 );
108 }
109
110 if (wrote)
111 {
112 Info<< ' ' << fieldName;
113 if (!fieldExists)
114 {
115 Info<< "{0}"; // report empty field
116 }
117 }
118 }
119 Info<< " )" << nl;
120 }
121}
122
123
124// ************************************************************************* //
reduce(hasMovingMesh, orOp< bool >())
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
dynamicFvMesh & mesh
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
List< wordList > regionCloudNames(meshes.size())
List< HashTable< HashTable< word > > > regionCloudFields(meshes.size())
const word & regionDir
messageStream Info
Information stream (stdout output on master, null elsewhere)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
const word cloudName(propsDict.get< word >("cloud"))