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 -------------------------------------------------------------------------------
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  returnReduceOr(currentCloudDirs.found(cloudName));
42 
43  {
44  autoPtr<ensightFile> os = ensCase.newCloud(cloudName);
45 
47  (
48  os.ref(),
49  mesh,
50  cloudName,
51  cloudExists
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  Pstream::reduceOr(fieldExists);
86  }
87 
88  bool wrote = false;
89  do
90  {
91  #undef ensight_WRITE_CLOUD_FIELD
92  #define ensight_WRITE_CLOUD_FIELD(PrimitiveType) \
93  \
94  if (fieldType == IOField<PrimitiveType>::typeName) \
95  { \
96  autoPtr<ensightFile> os = \
97  ensCase.newCloudData<PrimitiveType> \
98  ( \
99  cloudName, \
100  fieldName \
101  ); \
102  \
103  wrote = ensightOutput::readWriteCloudField<PrimitiveType> \
104  ( \
105  os.ref(), \
106  fieldObject, \
107  fieldExists \
108  ); \
109  break; \
110  }
111 
114 
115  #undef ensight_WRITE_CLOUD_FIELD
116  } while (false);
117 
118  if (wrote)
119  {
120  Info<< ' ' << fieldName;
121  if (!fieldExists)
122  {
123  Info<< "{0}"; // report empty field
124  }
125  }
126  }
127  Info<< " )" << nl;
128  }
129 }
130 
131 
132 // ************************************************************************* //
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
List< HashTable< HashTable< word > > > regionCloudFields(meshes.size())
dynamicFvMesh & mesh
const word cloudName(propsDict.get< word >("cloud"))
bool writeCloudPositions(ensightFile &os, const fvMesh &mesh, const word &cloudName, bool exists)
Write cloud positions.
Vector< scalar > vector
Definition: vector.H:57
#define ensight_WRITE_CLOUD_FIELD(PrimitiveType)
OBJstream os(runTime.globalPath()/outputName)
const word & regionDir
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< fileName > fileNameList
List of fileName.
Definition: fileNameList.H:32
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: POSIX.C:963
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
List< wordList > regionCloudNames(meshes.size())