Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToEnsight / ensightCloudField.C
blobad3bff1a7b172087f1f021964a16b2da458b1217
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ensightCloudField.H"
27 #include "foamTime.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 Foam::IOobject& fieldObject,
40     const Foam::fileName& postProcPath,
41     const Foam::word& prepend,
42     const Foam::label timeIndex,
43     const Foam::word& cloudName,
44     Foam::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         ios_base::out|ios_base::trunc,
85         runTime.writeFormat(),
86         runTime.writeVersion(),
87         runTime.writeCompression()
88     );
90     ensightFile<< pTraits<Type>::typeName << " values" << nl;
92     if (dataExists)
93     {
94         IOField<Type> vf(fieldObject);
96         ensightFile.setf(ios_base::scientific, ios_base::floatfield);
97         ensightFile.precision(5);
99         label count = 0;
100         forAll(vf, i)
101         {
102             Type v = vf[i];
104             if (mag(v) < 1.0e-90)
105             {
106                 v = pTraits<Type>::zero;
107             }
109             for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
110             {
111                 ensightFile << setw(12) << component(v, cmpt);
112                 if (++count % 6 == 0)
113                 {
114                     ensightFile << nl;
115                 }
116             }
117         }
119         if ((count % 6 != 0) || (count==0))
120         {
121             ensightFile << nl;
122         }
123     }
127 // ************************************************************************* //