OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

ensightCloudField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "ensightCloudField.H"
00028 #include "Time.H"
00029 #include "IOField.H"
00030 #include "OFstream.H"
00031 #include "IOmanip.H"
00032 
00033 using namespace Foam;
00034 
00035 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00036 
00037 template<class Type>
00038 void ensightCloudField
00039 (
00040     const Foam::IOobject& fieldObject,
00041     const Foam::fileName& postProcPath,
00042     const Foam::word& prepend,
00043     const Foam::label timeIndex,
00044     const Foam::word& cloudName,
00045     Foam::Ostream& ensightCaseFile,
00046     const bool dataExists
00047 )
00048 {
00049     if (dataExists)
00050     {
00051         Info<< "Converting cloud " << cloudName
00052             << " field " << fieldObject.name() << endl;
00053     }
00054     else
00055     {
00056         Info<< "Creating empty cloud " << cloudName
00057             << " field "  << fieldObject.name() << endl;
00058     }
00059 
00060     word timeFile = prepend + itoa(timeIndex);
00061 
00062     const Time& runTime = fieldObject.time();
00063 
00064     if (timeIndex == 0 && Pstream::master())
00065     {
00066         ensightCaseFile
00067             << pTraits<Type>::typeName << " per measured node:      1       ";
00068         ensightCaseFile.width(15);
00069         ensightCaseFile.setf(ios_base::left);
00070         ensightCaseFile
00071             << ("c" + fieldObject.name()).c_str()
00072             << (' ' + prepend + "***." + cloudName
00073               + "." + fieldObject.name()).c_str()
00074             << nl;
00075     }
00076 
00077     fileName ensightFileName
00078     (
00079         timeFile + "." + cloudName +"." + fieldObject.name()
00080     );
00081 
00082     OFstream ensightFile
00083     (
00084         postProcPath/ensightFileName,
00085         runTime.writeFormat(),
00086         runTime.writeVersion(),
00087         runTime.writeCompression()
00088     );
00089 
00090     ensightFile<< pTraits<Type>::typeName << " values" << nl;
00091 
00092     if (dataExists)
00093     {
00094         IOField<Type> vf(fieldObject);
00095 
00096         ensightFile.setf(ios_base::scientific, ios_base::floatfield);
00097         ensightFile.precision(5);
00098 
00099         label count = 0;
00100         forAll(vf, i)
00101         {
00102             Type v = vf[i];
00103 
00104             if (mag(v) < 1.0e-90)
00105             {
00106                 v = pTraits<Type>::zero;
00107             }
00108 
00109             for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
00110             {
00111                 ensightFile << setw(12) << component(v, cmpt);
00112                 if (++count % 6 == 0)
00113                 {
00114                     ensightFile << nl;
00115                 }
00116             }
00117         }
00118 
00119         if ((count % 6 != 0) || (count==0))
00120         {
00121             ensightFile << nl;
00122         }
00123     }
00124 }
00125 
00126 
00127 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd