BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / utilities / postProcessing / dataConversion / foamToEnsight / ensightCloudField.C
blob091461d13c3bbcc54d4dfbe36f29290c84d73309
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 "ensightCloudField.H"
27 #include "Time.H"
28 #include "IOField.H"
29 #include "OFstream.H"
30 #include "IOmanip.H"
32 using namespace Foam;
34 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
36 template<class Type>
37 void ensightCloudField
39     const IOobject& fieldObject,
40     const fileName& postProcPath,
41     const word& prepend,
42     const label timeIndex,
43     const word& cloudName,
44     Ostream& ensightCaseFile,
45     const bool dataExists
48     if (dataExists)
49     {
50         Info<< "Converting cloud " << cloudName
51             << " field " << fieldObject.name() << endl;
52     }
53     else
54     {
55         Info<< "Creating empty cloud " << cloudName
56             << " field "  << fieldObject.name() << endl;
57     }
59     word timeFile = prepend + itoa(timeIndex);
61     const Time& runTime = fieldObject.time();
63     if (timeIndex == 0 && Pstream::master())
64     {
65         ensightCaseFile
66             << pTraits<Type>::typeName << " per measured node:      1       ";
67         ensightCaseFile.width(15);
68         ensightCaseFile.setf(ios_base::left);
69         ensightCaseFile
70             << ("c" + fieldObject.name()).c_str()
71             << (' ' + prepend + "***." + cloudName
72               + "." + fieldObject.name()).c_str()
73             << nl;
74     }
76     fileName ensightFileName
77     (
78         timeFile + "." + cloudName +"." + fieldObject.name()
79     );
81     OFstream ensightFile
82     (
83         postProcPath/ensightFileName,
84         runTime.writeFormat(),
85         runTime.writeVersion(),
86         runTime.writeCompression()
87     );
89     ensightFile<< pTraits<Type>::typeName << " values" << nl;
91     if (dataExists)
92     {
93         IOField<Type> vf(fieldObject);
95         ensightFile.setf(ios_base::scientific, ios_base::floatfield);
96         ensightFile.precision(5);
98         label count = 0;
99         forAll(vf, i)
100         {
101             Type v = vf[i];
103             if (mag(v) < 1.0e-90)
104             {
105                 v = pTraits<Type>::zero;
106             }
108             for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
109             {
110                 ensightFile << setw(12) << component(v, cmpt);
111                 if (++count % 6 == 0)
112                 {
113                     ensightFile << nl;
114                 }
115             }
116         }
118         if ((count % 6 != 0) || (count==0))
119         {
120             ensightFile << nl;
121         }
122     }
126 // ************************************************************************* //