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

ensightParticlePositions.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 "ensightParticlePositions.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <lagrangian/passiveParticle.H>
00029 #include <lagrangian/Cloud.H>
00030 #include <OpenFOAM/OFstream.H>
00031 #include <OpenFOAM/IOmanip.H>
00032 #include "itoa.H"
00033 
00034 using namespace Foam;
00035 
00036 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00037 
00038 void ensightParticlePositions
00039 (
00040     const Foam::fvMesh& mesh,
00041     const Foam::fileName& postProcPath,
00042     const Foam::word& timeFile,
00043     const Foam::word& cloudName,
00044     const bool dataExists
00045 )
00046 {
00047     if (dataExists)
00048     {
00049         Info<< "Converting cloud " << cloudName << " positions" <<  endl;
00050     }
00051     else
00052     {
00053         Info<< "Creating empty cloud " << cloudName << " positions" << endl;
00054     }
00055 
00056     const Time& runTime = mesh.time();
00057 
00058     fileName ensightFileName(timeFile + "." + cloudName);
00059     OFstream ensightFile
00060     (
00061         postProcPath/ensightFileName,
00062         runTime.writeFormat(),
00063         runTime.writeVersion(),
00064         runTime.writeCompression()
00065     );
00066 
00067     // Output header
00068     ensightFile
00069         << cloudName.c_str() << nl
00070         << "particle coordinates" << nl;
00071 
00072     if (dataExists)
00073     {
00074         Cloud<passiveParticle> parcels(mesh, cloudName, false);
00075 
00076         // Set Format
00077         ensightFile.setf(ios_base::scientific, ios_base::floatfield);
00078         ensightFile.precision(5);
00079 
00080         ensightFile<< setw(8) << parcels.size() << nl;
00081 
00082         label nParcels = 0;
00083 
00084         // Output positions
00085         forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
00086         {
00087             const vector& p = elmnt().position();
00088 
00089             ensightFile
00090                 << setw(8) << ++nParcels
00091                 << setw(12) << p.x() << setw(12) << p.y() << setw(12) << p.z()
00092                 << nl;
00093         }
00094     }
00095     else
00096     {
00097         label nParcels = 0;
00098         ensightFile<< setw(8) << nParcels << nl;
00099     }
00100 }
00101 
00102 
00103 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines