initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToEnsightParts / ensightOutputFunctions.C
blobe62b10064c7ad0a259afa025ec9666409c9fa509
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "ensightOutputFunctions.H"
29 #include "passiveParticle.H"
30 #include "IOField.H"
31 #include "volFields.H"
32 #include "surfaceFields.H"
34 #include "OFstream.H"
35 #include "IOmanip.H"
37 namespace Foam
40 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
42 void ensightCaseEntry
44     OFstream& caseFile,
45     const string& ensightType,
46     const word& fieldName,
47     const fileName& dataMask,
48     const fileName& local,
49     const label cloudNo,
50     const label timeSet
53     caseFile.setf(ios_base::left);
55     fileName dirName(dataMask);
56     if (local.size())
57     {
58         dirName = dirName/local;
59     }
61     if (cloudNo >= 0)
62     {
63         label ts = 1;
64         if (timeSet > ts)
65         {
66             ts = timeSet;
67         }
69         // prefix variables with 'c' (cloud)
70         caseFile
71             << ensightType.c_str()
72             << " per measured node: " << ts << " "
73             << setw(15)
74             << ("c" + Foam::name(cloudNo) + fieldName).c_str()
75             << " "
76             << (dirName/fieldName).c_str()
77             << nl;
78     }
79     else
80     {
81         caseFile
82             << ensightType.c_str()
83             << " per element: "
84             << setw(15) << fieldName
85             << " "
86             << (dirName/fieldName).c_str()
87             << nl;
88     }
92 void ensightParticlePositions
94     const polyMesh& mesh,
95     const fileName& dataDir,
96     const fileName& subDir,
97     const word& cloudName,
98     IOstream::streamFormat format
101     Cloud<passiveParticle> parcels(mesh, cloudName, false);
103     fileName cloudDir = subDir/cloud::prefix/cloudName;
104     fileName postFileName = cloudDir/"positions";
106     // the ITER/lagrangian subdirectory must exist
107     mkDir(dataDir/cloudDir);
108     ensightFile os(dataDir/postFileName, format);
110     // tag binary format (just like geometry files)
111     os.writeBinaryHeader();
112     os.write(postFileName);
113     os.newline();
114     os.write("particle coordinates");
115     os.newline();
116     os.write(parcels.size(), 8);        // unusual width
117     os.newline();
119     // binary write is Ensight6 - first ids, then positions
120     if (format == IOstream::BINARY)
121     {
122         forAll (parcels, i)
123         {
124             os.write(i+1);
125         }
127         forAllIter(Cloud<passiveParticle>, parcels, elmnt)
128         {
129             const vector& p = elmnt().position();
131             os.write(p.x());
132             os.write(p.y());
133             os.write(p.z());
134         }
135     }
136     else
137     {
138         label nParcels = 0;
140         forAllIter(Cloud<passiveParticle>, parcels, elmnt)
141         {
142             const vector& p = elmnt().position();
144             os.write(++nParcels, 8);    // unusual width
145             os.write(p.x());
146             os.write(p.y());
147             os.write(p.z());
148             os.newline();
149         }
150     }
155 template<class Type>
156 void ensightLagrangianField
158     const IOobject& fieldObject,
159     const fileName& dataDir,
160     const fileName& subDir,
161     const word& cloudName,
162     IOstream::streamFormat format
165     Info<< " " << fieldObject.name() << flush;
167     fileName cloudDir = subDir/cloud::prefix/cloudName;
168     fileName postFileName = cloudDir/fieldObject.name();
170     string title =
171         postFileName + " with " + pTraits<Type>::typeName + " values";
173     ensightFile os(dataDir/postFileName, format);
174     os.write(title);
175     os.newline();
177     IOField<Type> field(fieldObject);
179     // 6 values per line
180     label count = 0;
182     forAll(field, i)
183     {
184         Type val = field[i];
186         if (mag(val) < 1.0e-90)
187         {
188             val = pTraits<Type>::zero;
189         }
191         for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; cmpt++)
192         {
193             os.write( component(val, cmpt) );
194         }
196         count += pTraits<Type>::nComponents;
198         if (count % 6 == 0)
199         {
200             os.newline();
201         }
202     }
204     // add final newline if required
205     if (count % 6)
206     {
207         os.newline();
208     }
212 //- write generalized field components
213 template <class Type>
214 void ensightVolField
216     const ensightParts& partsList,
217     const IOobject& fieldObject,
218     const fvMesh& mesh,
219     const fileName& dataDir,
220     const fileName& subDir,
221     IOstream::streamFormat format
224     Info<< " " << fieldObject.name() << flush;
226     fileName postFileName = subDir/fieldObject.name();
228     ensightFile os(dataDir/postFileName, format);
229     os.write(postFileName);
230     os.newline();
232     // ie, volField<Type>
233     partsList.writeField
234     (
235         os,
236         GeometricField<Type, fvPatchField, volMesh>
237         (
238             fieldObject,
239             mesh
240         )
241     );
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 } // namespace Foam
249 // ************************************************************************* //