BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / utilities / postProcessing / dataConversion / foamToEnsightParts / ensightOutputFunctions.C
blob2df564e0d0cec528601eaadda55eb3398f247dfd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ensightOutputFunctions.H"
28 #include "passiveParticle.H"
29 #include "IOField.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
33 #include "OFstream.H"
34 #include "IOmanip.H"
37 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
39 void Foam::ensightCaseEntry
41     OFstream& caseFile,
42     const string& ensightType,
43     const word& fieldName,
44     const fileName& dataMask,
45     const fileName& local,
46     const label cloudNo,
47     const label timeSet
50     caseFile.setf(ios_base::left);
52     fileName dirName(dataMask);
53     if (local.size())
54     {
55         dirName = dirName/local;
56     }
58     if (cloudNo >= 0)
59     {
60         label ts = 1;
61         if (timeSet > ts)
62         {
63             ts = timeSet;
64         }
66         // prefix variables with 'c' (cloud)
67         caseFile
68             << ensightType.c_str()
69             << " per measured node: " << ts << " "
70             << setw(15)
71             << ("c" + Foam::name(cloudNo) + fieldName).c_str()
72             << " "
73             << (dirName/fieldName).c_str()
74             << nl;
75     }
76     else
77     {
78         caseFile
79             << ensightType.c_str()
80             << " per element: "
81             << setw(15) << fieldName
82             << " "
83             << (dirName/fieldName).c_str()
84             << nl;
85     }
89 void Foam::ensightParticlePositions
91     const polyMesh& mesh,
92     const fileName& dataDir,
93     const fileName& subDir,
94     const word& cloudName,
95     IOstream::streamFormat format
98     Cloud<passiveParticle> parcels(mesh, cloudName, false);
100     fileName cloudDir = subDir/cloud::prefix/cloudName;
101     fileName postFileName = cloudDir/"positions";
103     // the ITER/lagrangian subdirectory must exist
104     mkDir(dataDir/cloudDir);
105     ensightFile os(dataDir/postFileName, format);
107     // tag binary format (just like geometry files)
108     os.writeBinaryHeader();
109     os.write(postFileName);
110     os.newline();
111     os.write("particle coordinates");
112     os.newline();
113     os.write(parcels.size(), 8);   // unusual width
114     os.newline();
116     // binary write is Ensight6 - first ids, then positions
117     if (format == IOstream::BINARY)
118     {
119         forAll(parcels, i)
120         {
121             os.write(i+1);
122         }
124         forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
125         {
126             const vector& p = elmnt().position();
128             os.write(p.x());
129             os.write(p.y());
130             os.write(p.z());
131         }
132     }
133     else
134     {
135         label nParcels = 0;
137         forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
138         {
139             const vector& p = elmnt().position();
141             os.write(++nParcels, 8);    // unusual width
142             os.write(p.x());
143             os.write(p.y());
144             os.write(p.z());
145             os.newline();
146         }
147     }
152 template<class Type>
153 void Foam::ensightLagrangianField
155     const IOobject& fieldObject,
156     const fileName& dataDir,
157     const fileName& subDir,
158     const word& cloudName,
159     IOstream::streamFormat format
162     Info<< " " << fieldObject.name() << flush;
164     fileName cloudDir = subDir/cloud::prefix/cloudName;
165     fileName postFileName = cloudDir/fieldObject.name();
167     string title =
168         postFileName + " with " + pTraits<Type>::typeName + " values";
170     ensightFile os(dataDir/postFileName, format);
171     os.write(title);
172     os.newline();
174     IOField<Type> field(fieldObject);
176     // 6 values per line
177     label count = 0;
179     forAll(field, i)
180     {
181         Type val = field[i];
183         if (mag(val) < 1.0e-90)
184         {
185             val = pTraits<Type>::zero;
186         }
188         for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; cmpt++)
189         {
190             os.write( component(val, cmpt) );
191         }
193         count += pTraits<Type>::nComponents;
195         if (count % 6 == 0)
196         {
197             os.newline();
198         }
199     }
201     // add final newline if required
202     if (count % 6)
203     {
204         os.newline();
205     }
209 //- write generalized field components
210 template <class Type>
211 void Foam::ensightVolField
213     const ensightParts& partsList,
214     const IOobject& fieldObject,
215     const fvMesh& mesh,
216     const fileName& dataDir,
217     const fileName& subDir,
218     IOstream::streamFormat format
221     Info<< " " << fieldObject.name() << flush;
223     fileName postFileName = subDir/fieldObject.name();
225     ensightFile os(dataDir/postFileName, format);
226     os.write(postFileName);
227     os.newline();
229     // ie, volField<Type>
230     partsList.writeField
231     (
232         os,
233         GeometricField<Type, fvPatchField, volMesh>
234         (
235             fieldObject,
236             mesh
237         )
238     );
242 // ************************************************************************* //