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-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
26 Description
27  Code chunk for post-processing conversion of cloud(s) to Ensight
28 
29 \*---------------------------------------------------------------------------*/
30 
31 // Cloud field data output
32 if (doLagrangian)
33 {
34  for (const word& cloudName : cloudNames)
35  {
36  const HashTable<word>& theseCloudFields = cloudFields[cloudName];
37 
38  fileNameList currentCloudDirs
39  (
40  readDir
41  (
42  runTime.timePath()/regionPrefix/cloud::prefix,
43  fileName::DIRECTORY
44  )
45  );
46 
47  Info<< "Write " << cloudName << " (";
48 
49  const bool cloudExists =
50  returnReduce(currentCloudDirs.found(cloudName), orOp<bool>());
51 
52  {
53  autoPtr<ensightFile> os = ensCase.newCloud(cloudName);
54 
56  (
57  mesh,
58  cloudName,
59  cloudExists,
60  os
61  );
62 
63  Info<< " positions";
64  if (!cloudExists)
65  {
66  Info<< "{0}"; // report empty field
67  }
68  }
69 
70  // Field order may differ on individual processors, so sort by name
71  for (const word& fieldName : theseCloudFields.sortedToc())
72  {
73  const word& fieldType = theseCloudFields[fieldName];
74 
75  IOobject fieldObject
76  (
77  fieldName,
78  mesh.time().timeName(),
79  cloud::prefix/cloudName,
80  mesh,
81  IOobject::MUST_READ
82  );
83 
84  bool fieldExists = cloudExists; // No field without positions
85  if (cloudExists)
86  {
87  // Want MUST_READ (globally) and valid=false (locally),
88  // but that combination does not work.
89  // So check the header and sync globally
90 
91  const bool oldParRun = Pstream::parRun(false);
92  fieldExists = fieldObject.typeHeaderOk<IOField<scalar>>(false);
93  Pstream::parRun(oldParRun); // Restore parallel state
94  reduce(fieldExists, orOp<bool>());
95  }
96 
97  bool wrote = false;
98  if (fieldType == scalarIOField::typeName)
99  {
100  autoPtr<ensightFile> os =
101  ensCase.newCloudData<scalar>(cloudName, fieldName);
102 
103  wrote = ensightOutput::writeCloudField<scalar>
104  (
105  fieldObject, fieldExists, os
106  );
107  }
108  else if (fieldType == vectorIOField::typeName)
109  {
110  autoPtr<ensightFile> os =
111  ensCase.newCloudData<vector>(cloudName, fieldName);
112 
113  wrote = ensightOutput::writeCloudField<vector>
114  (
115  fieldObject, fieldExists, os
116  );
117  }
118 
119  if (wrote)
120  {
121  Info<< ' ' << fieldName;
122  if (!fieldExists)
123  {
124  Info<< "{0}"; // report empty field
125  }
126  }
127  }
128  Info<< " )" << nl;
129  }
130 }
131 
132 
133 // ************************************************************************* //
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::ensightOutput::writeCloudPositions
bool writeCloudPositions(const fvMesh &mesh, const word &cloudName, bool exists, autoPtr< ensightFile > &output, Pstream::commsTypes comm=Pstream::commsTypes::blocking)
Write cloud positions.
Definition: ensightOutputCloud.C:79
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
reduce
reduce(hasMovingMesh, orOp< bool >())
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
cloudNames
const wordList cloudNames(cloudFields.sortedToc())
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::fileNameList
List< fileName > fileNameList
A List of fileNames.
Definition: fileNameList.H:58
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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
cloudFields
HashTable< HashTable< word > > cloudFields
Definition: findCloudFields.H:4