initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / miscellaneous / ptot / ptot.C
blob26d66de83e85c048d5cc96fca511ab896d873c53
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     ptot
28 Description
29     For each time: calculate the total pressure.
31 \*---------------------------------------------------------------------------*/
33 #include "fvCFD.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 int main(int argc, char *argv[])
39     timeSelector::addOptions();
41 #   include "setRootCase.H"
42 #   include "createTime.H"
44     instantList timeDirs = timeSelector::select0(runTime, args);
46 #   include "createMesh.H"
48     forAll(timeDirs, timeI)
49     {
50         runTime.setTime(timeDirs[timeI], timeI);
52         Info<< "Time = " << runTime.timeName() << endl;
54         IOobject pheader
55         (
56             "p",
57             runTime.timeName(),
58             mesh,
59             IOobject::MUST_READ
60         );
62         IOobject Uheader
63         (
64             "U",
65             runTime.timeName(),
66             mesh,
67             IOobject::MUST_READ
68         );
71         // Check p and U exist
72         if (pheader.headerOk() && Uheader.headerOk())
73         {
74             mesh.readUpdate();
76             Info<< "    Reading p" << endl;
77             volScalarField p(pheader, mesh);
79             Info<< "    Reading U" << endl;
80             volVectorField U(Uheader, mesh);
82             Info<< "    Calculating ptot" << endl;
83             if (p.dimensions() == dimensionSet(0, 2, -2, 0, 0))
84             {
85                 volScalarField ptot
86                 (
87                     IOobject
88                     (
89                         "ptot",
90                         runTime.timeName(),
91                         mesh,
92                         IOobject::NO_READ
93                     ),
94                     p + 0.5*magSqr(U)
95                 );
96                 ptot.write();
97             }
98             else
99             {
100                 IOobject rhoheader
101                 (
102                     "rho",
103                     runTime.timeName(),
104                     mesh,
105                     IOobject::MUST_READ
106                 );
108                 // Check rho exists
109                 if (rhoheader.headerOk())
110                 {
111                     Info<< "    Reading rho" << endl;
112                     volScalarField rho(rhoheader, mesh);
114                     volScalarField ptot
115                     (
116                         IOobject
117                         (
118                             "ptot",
119                             runTime.timeName(),
120                             mesh,
121                             IOobject::NO_READ
122                         ),
123                         p + 0.5*rho*magSqr(U)
124                     );
125                     ptot.write();
126                 }
127                 else
128                 {
129                     Info<< "    No rho" << endl;
130                 }
131             }
132         }
133         else
134         {
135             Info<< "    No p or U" << endl;
136         }
138         Info<< endl;
139     }
141     return 0;
145 // ************************************************************************* //