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

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