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

ptot.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 Application
00026     ptot
00027 
00028 Description
00029     For each time: calculate the total pressure.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "fvCFD.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 int main(int argc, char *argv[])
00038 {
00039     timeSelector::addOptions();
00040 
00041 #   include "setRootCase.H"
00042 #   include "createTime.H"
00043 
00044     instantList timeDirs = timeSelector::select0(runTime, args);
00045 
00046 #   include "createMesh.H"
00047 
00048     forAll(timeDirs, timeI)
00049     {
00050         runTime.setTime(timeDirs[timeI], timeI);
00051 
00052         Info<< "Time = " << runTime.timeName() << endl;
00053 
00054         IOobject pheader
00055         (
00056             "p",
00057             runTime.timeName(),
00058             mesh,
00059             IOobject::MUST_READ
00060         );
00061 
00062         IOobject Uheader
00063         (
00064             "U",
00065             runTime.timeName(),
00066             mesh,
00067             IOobject::MUST_READ
00068         );
00069 
00070 
00071         // Check p and U exist
00072         if (pheader.headerOk() && Uheader.headerOk())
00073         {
00074             mesh.readUpdate();
00075 
00076             Info<< "    Reading p" << endl;
00077             volScalarField p(pheader, mesh);
00078 
00079             Info<< "    Reading U" << endl;
00080             volVectorField U(Uheader, mesh);
00081 
00082             Info<< "    Calculating ptot" << endl;
00083             if (p.dimensions() == dimensionSet(0, 2, -2, 0, 0))
00084             {
00085                 volScalarField ptot
00086                 (
00087                     IOobject
00088                     (
00089                         "ptot",
00090                         runTime.timeName(),
00091                         mesh,
00092                         IOobject::NO_READ
00093                     ),
00094                     p + 0.5*magSqr(U)
00095                 );
00096                 ptot.write();
00097             }
00098             else
00099             {
00100                 IOobject rhoheader
00101                 (
00102                     "rho",
00103                     runTime.timeName(),
00104                     mesh,
00105                     IOobject::MUST_READ
00106                 );
00107 
00108                 // Check rho exists
00109                 if (rhoheader.headerOk())
00110                 {
00111                     Info<< "    Reading rho" << endl;
00112                     volScalarField rho(rhoheader, mesh);
00113 
00114                     volScalarField ptot
00115                     (
00116                         IOobject
00117                         (
00118                             "ptot",
00119                             runTime.timeName(),
00120                             mesh,
00121                             IOobject::NO_READ
00122                         ),
00123                         p + 0.5*rho*magSqr(U)
00124                     );
00125                     ptot.write();
00126                 }
00127                 else
00128                 {
00129                     Info<< "    No rho" << endl;
00130                 }
00131             }
00132         }
00133         else
00134         {
00135             Info<< "    No p or U" << endl;
00136         }
00137 
00138         Info<< endl;
00139     }
00140 
00141     return 0;
00142 }
00143 
00144 
00145 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd