FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "ensightCloudField.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/IOField.H>
00029 #include <OpenFOAM/OFstream.H>
00030 #include <OpenFOAM/IOmanip.H>
00031 
00032 using namespace Foam;
00033 
00034 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00035 
00036 template<class Type>
00037 void ensightCloudField
00038 (
00039     const Foam::IOobject& fieldObject,
00040     const Foam::fileName& postProcPath,
00041     const Foam::word& prepend,
00042     const Foam::label timeIndex,
00043     const Foam::word& cloudName,
00044     Foam::Ostream& ensightCaseFile,
00045     const bool dataExists
00046 )
00047 {
00048     if (dataExists)
00049     {
00050         Info<< "Converting cloud " << cloudName
00051             << " field " << fieldObject.name() << endl;
00052     }
00053     else
00054     {
00055         Info<< "Creating empty cloud " << cloudName
00056             << " field "  << fieldObject.name() << endl;
00057     }
00058 
00059     word timeFile = prepend + itoa(timeIndex);
00060 
00061     const Time& runTime = fieldObject.time();
00062 
00063     if (timeIndex == 0 && Pstream::master())
00064     {
00065         ensightCaseFile
00066             << pTraits<Type>::typeName << " per measured node:      1       ";
00067         ensightCaseFile.width(15);
00068         ensightCaseFile.setf(ios_base::left);
00069         ensightCaseFile
00070             << ("c" + fieldObject.name()).c_str()
00071             << (' ' + prepend + "***." + cloudName
00072               + "." + fieldObject.name()).c_str()
00073             << nl;
00074     }
00075 
00076     fileName ensightFileName
00077     (
00078         timeFile + "." + cloudName +"." + fieldObject.name()
00079     );
00080 
00081     OFstream ensightFile
00082     (
00083         postProcPath/ensightFileName,
00084         runTime.writeFormat(),
00085         runTime.writeVersion(),
00086         runTime.writeCompression()
00087     );
00088 
00089     ensightFile<< pTraits<Type>::typeName << " values" << nl;
00090 
00091     if (dataExists)
00092     {
00093         IOField<Type> vf(fieldObject);
00094 
00095         ensightFile.setf(ios_base::scientific, ios_base::floatfield);
00096         ensightFile.precision(5);
00097 
00098         label count = 0;
00099         forAll(vf, i)
00100         {
00101             Type v = vf[i];
00102 
00103             if (mag(v) < 1.0e-90)
00104             {
00105                 v = pTraits<Type>::zero;
00106             }
00107 
00108             for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
00109             {
00110                 ensightFile << setw(12) << component(v, cmpt);
00111                 if (++count % 6 == 0)
00112                 {
00113                     ensightFile << nl;
00114                 }
00115             }
00116         }
00117 
00118         if ((count % 6 != 0) || (count==0))
00119         {
00120             ensightFile << nl;
00121         }
00122     }
00123 }
00124 
00125 
00126 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines