Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / preProcessing / convertPhi / convertPhi.C
blob86da7d647032bb92cdc52f10f5252120f530fdfa
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     COnvert volumetric to mass flux
27 \*---------------------------------------------------------------------------*/
29 #include "argList.H"
30 #include "fvCFD.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 int main(int argc, char *argv[])
36     argList::validOptions.insert("rhoRef", "scalar");
38 #   include "setRootCase.H"
40     if (!args.options().found("rhoRef"))
41     {
42         FatalErrorIn(args.executable())
43             << "Missing reference density"
44             << endl;
46         FatalError.exit();
47     }
50     dimensionedScalar rhoRef
51     (
52         "rhoRef",
53         dimDensity,
54         readScalar(IStringStream(args.options()["rhoRef"])())
55     );
57     Info<< "Reference density = " << rhoRef.value() << endl;
60 #   include "createTime.H"
61 #   include "createMesh.H"
63     Info<< "Time = " << runTime.value() << endl;
65     Info<< "    Reading p" << endl;
66     volScalarField p
67     (
68         IOobject
69         (
70             "p",
71             runTime.timeName(),
72             mesh,
73             IOobject::MUST_READ,
74             IOobject::NO_WRITE
75         ),
76         mesh
77     );
79     if (p.dimensions() == dimPressure)
80     {
81         Info<< "Pressure " << p.name() << " is a dynamic pressure.  "
82             << "Nothing to do"
83             << endl;
84     }
85     else if (p.dimensions() == dimPressure/dimDensity)
86     {
87         volScalarField rhoP
88         (
89             IOobject
90             (
91                 "rho" + p.name(),
92                 runTime.timeName(),
93                 mesh,
94                 IOobject::NO_READ,
95                 IOobject::NO_WRITE
96             ),
97             rhoRef*p
98         );
100         Info<< "Correcting kinematic pressure " << p.name()
101             << " into dynamic pressure " << rhoP.name()
102             << endl;
104         rhoP.write();
105     }
106     else
107     {
108         Info<< "Cannot recognise dimensions of pressure field " << p.name()
109             << ": " << p.dimensions() << ".  Ignoring" << endl;
111     }
113     Info<< "    Reading phi" << endl;
114     surfaceScalarField phi
115     (
116         IOobject
117         (
118             "phi",
119             runTime.timeName(),
120             mesh,
121             IOobject::MUST_READ,
122             IOobject::NO_WRITE
123         ),
124         mesh
125     );
127     if (phi.dimensions() == dimMass/dimTime)
128     {
129         Info<< "Flux " << phi.name() << " is a mass flux.  Nothing to do"
130             << endl;
131     }
132     else if (phi.dimensions() == dimVolume/dimTime)
133     {
134         surfaceScalarField rhoPhi
135         (
136             IOobject
137             (
138                 "rho" + phi.name(),
139                 runTime.timeName(),
140                 mesh,
141                 IOobject::NO_READ,
142                 IOobject::NO_WRITE
143             ),
144             rhoRef*phi
145         );
147         Info<< "Correcting volume flux " << phi.name()
148             << " into mass flux " << rhoPhi.name()
149             << endl;
151         rhoPhi.write();
152     }
153     else
154     {
155         Info<< "Cannot recognise dimensions of flux field " << phi.name()
156             << ": " << phi.dimensions() << ".  Ignoring" << endl;
157     }
159     Info<< "End\n" << endl;
161     return(0);
165 // ************************************************************************* //