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, distributed under GPL-3.0-or-later.
12 
13 Description
14  Code chunk for post-processing conversion of cloud(s) to Ensight
15 
16 \*---------------------------------------------------------------------------*/
17 
18 // Cloud field data output
19 if (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];
28 
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 
47  (
48  mesh,
49  cloudName,
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
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::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
reduce
reduce(hasMovingMesh, orOp< bool >())
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::ensightOutput::writeCloudPositions
bool writeCloudPositions(const fvMesh &mesh, const word &cloudName, bool exists, autoPtr< ensightFile > &output)
Write cloud positions.
Definition: ensightOutputCloud.C:79
Foam::fileNameList
List< fileName > fileNameList
A List of fileNames.
Definition: fileNameList.H:58
Foam::nl
constexpr char nl
Definition: Ostream.H:404
regionCloudNames
List< wordList > regionCloudNames(meshes.size())
regionDir
const word & regionDir
Definition: findMeshDefinitionDict.H:34
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
regionCloudFields
List< HashTable< HashTable< word > > > regionCloudFields(meshes.size())