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 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  forAll(cloudNames, cloudNo)
35  {
36  const word& cloudName = cloudNames[cloudNo];
37  const HashTable<word>& theseCloudFields = cloudFields[cloudName];
38 
39  fileNameList currentCloudDirs
40  (
41  readDir
42  (
43  runTime.timePath()/regionPrefix/cloud::prefix,
44  fileName::DIRECTORY
45  )
46  );
47 
48  Info<< "Write " << cloudName << " (";
49 
50  const bool cloudExists =
52  (
53  currentCloudDirs.found(cloudName),
54  orOp<bool>()
55  );
56 
57 
58  {
59  autoPtr<ensightFile> os = ensCase.newCloud(cloudName);
60 
62  (
63  mesh,
64  cloudName,
65  cloudExists,
66  os
67  );
68 
69  Info<< " positions";
70  if (!cloudExists)
71  {
72  Info<< "{0}"; // report empty field
73  }
74  }
75 
76  forAllConstIters(theseCloudFields, fieldIter)
77  {
78  const word& fieldName = fieldIter.key();
79  const word& fieldType = fieldIter.val();
80 
81  IOobject fieldObject
82  (
83  fieldName,
84  mesh.time().timeName(),
85  cloud::prefix/cloudName,
86  mesh,
87  IOobject::MUST_READ
88  );
89 
90  bool fieldExists = cloudExists; // No field without positions
91  if (cloudExists)
92  {
93  // Want MUST_READ (globally) and valid=false (locally),
94  // but that combination does not work.
95  // So check the header and sync globally
96 
97  fieldExists =
98  fieldObject.typeHeaderOk<IOField<scalar>>(false);
99 
100  reduce(fieldExists, orOp<bool>());
101  }
102 
103  bool wrote = false;
104  if (fieldType == scalarIOField::typeName)
105  {
106  autoPtr<ensightFile> os =
107  ensCase.newCloudData<scalar>(cloudName, fieldName);
108 
109  wrote = ensightOutput::writeCloudField<scalar>
110  (
111  fieldObject, fieldExists, os
112  );
113  }
114  else if (fieldType == vectorIOField::typeName)
115  {
116  autoPtr<ensightFile> os =
117  ensCase.newCloudData<vector>(cloudName, fieldName);
118 
119  wrote = ensightOutput::writeCloudField<vector>
120  (
121  fieldObject, fieldExists, os
122  );
123  }
124 
125  if (wrote)
126  {
127  Info<< ' ' << fieldName;
128  if (!fieldExists)
129  {
130  Info<< "{0}"; // report empty field
131  }
132  }
133  }
134  Info<< " )" << nl;
135  }
136 }
137 
138 
139 // ************************************************************************* //
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:372
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
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