FreeFOAM The Cross-Platform CFD Toolkit
ensightOutputFunctions.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ensightOutputFunctions.H"
27 
29 #include <OpenFOAM/IOField.H>
30 #include <finiteVolume/volFields.H>
32 
33 #include <OpenFOAM/OFstream.H>
34 #include <OpenFOAM/IOmanip.H>
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
40 
42 (
43  OFstream& caseFile,
44  const string& ensightType,
45  const word& fieldName,
46  const fileName& dataMask,
47  const fileName& local,
48  const label cloudNo,
49  const label timeSet
50 )
51 {
52  caseFile.setf(ios_base::left);
53 
54  fileName dirName(dataMask);
55  if (local.size())
56  {
57  dirName = dirName/local;
58  }
59 
60  if (cloudNo >= 0)
61  {
62  label ts = 1;
63  if (timeSet > ts)
64  {
65  ts = timeSet;
66  }
67 
68  // prefix variables with 'c' (cloud)
69  caseFile
70  << ensightType.c_str()
71  << " per measured node: " << ts << " "
72  << setw(15)
73  << ("c" + Foam::name(cloudNo) + fieldName).c_str()
74  << " "
75  << (dirName/fieldName).c_str()
76  << nl;
77  }
78  else
79  {
80  caseFile
81  << ensightType.c_str()
82  << " per element: "
83  << setw(15) << fieldName
84  << " "
85  << (dirName/fieldName).c_str()
86  << nl;
87  }
88 }
89 
90 
92 (
93  const polyMesh& mesh,
94  const fileName& dataDir,
95  const fileName& subDir,
96  const word& cloudName,
98 )
99 {
100  Cloud<passiveParticle> parcels(mesh, cloudName, false);
101 
102  fileName cloudDir = subDir/cloud::prefix/cloudName;
103  fileName postFileName = cloudDir/"positions";
104 
105  // the ITER/lagrangian subdirectory must exist
106  mkDir(dataDir/cloudDir);
107  ensightFile os(dataDir/postFileName, format);
108 
109  // tag binary format (just like geometry files)
110  os.writeBinaryHeader();
111  os.write(postFileName);
112  os.newline();
113  os.write("particle coordinates");
114  os.newline();
115  os.write(parcels.size(), 8); // unusual width
116  os.newline();
117 
118  // binary write is Ensight6 - first ids, then positions
119  if (format == IOstream::BINARY)
120  {
121  forAll (parcels, i)
122  {
123  os.write(i+1);
124  }
125 
126  forAllIter(Cloud<passiveParticle>, parcels, elmnt)
127  {
128  const vector& p = elmnt().position();
129 
130  os.write(p.x());
131  os.write(p.y());
132  os.write(p.z());
133  }
134  }
135  else
136  {
137  label nParcels = 0;
138 
139  forAllIter(Cloud<passiveParticle>, parcels, elmnt)
140  {
141  const vector& p = elmnt().position();
142 
143  os.write(++nParcels, 8); // unusual width
144  os.write(p.x());
145  os.write(p.y());
146  os.write(p.z());
147  os.newline();
148  }
149  }
150 }
151 
152 
153 
154 template<class Type>
156 (
157  const IOobject& fieldObject,
158  const fileName& dataDir,
159  const fileName& subDir,
160  const word& cloudName,
162 )
163 {
164  Info<< " " << fieldObject.name() << flush;
165 
166  fileName cloudDir = subDir/cloud::prefix/cloudName;
167  fileName postFileName = cloudDir/fieldObject.name();
168 
169  string title =
170  postFileName + " with " + pTraits<Type>::typeName + " values";
171 
172  ensightFile os(dataDir/postFileName, format);
173  os.write(title);
174  os.newline();
175 
176  IOField<Type> field(fieldObject);
177 
178  // 6 values per line
179  label count = 0;
180 
181  forAll(field, i)
182  {
183  Type val = field[i];
184 
185  if (mag(val) < 1.0e-90)
186  {
187  val = pTraits<Type>::zero;
188  }
189 
190  for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; cmpt++)
191  {
192  os.write( component(val, cmpt) );
193  }
194 
195  count += pTraits<Type>::nComponents;
196 
197  if (count % 6 == 0)
198  {
199  os.newline();
200  }
201  }
202 
203  // add final newline if required
204  if (count % 6)
205  {
206  os.newline();
207  }
208 }
209 
210 
211 //- write generalized field components
212 template <class Type>
213 void ensightVolField
214 (
215  const ensightParts& partsList,
216  const IOobject& fieldObject,
217  const fvMesh& mesh,
218  const fileName& dataDir,
219  const fileName& subDir,
221 )
222 {
223  Info<< " " << fieldObject.name() << flush;
224 
225  fileName postFileName = subDir/fieldObject.name();
226 
227  ensightFile os(dataDir/postFileName, format);
228  os.write(postFileName);
229  os.newline();
230 
231  // ie, volField<Type>
232  partsList.writeField
233  (
234  os,
235  GeometricField<Type, fvPatchField, volMesh>
236  (
237  fieldObject,
238  mesh
239  )
240  );
241 }
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // namespace Foam
246 
247 
248 // ************************ vim: set sw=4 sts=4 et: ************************ //