Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / errorEstimation / simpleFoamResidual / simpleFoamResidual.C
blob8dfeb8fbebb24b155b0941ed60add8f9e84f7a66
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 Application
25     simpleFoamResidual
27 Author
28     Hrvoje Jasak, Wikki Ltd.  All rights reserved.
30 Description
31     Calculate and write residual for a simpleFoam momentum equation
33 \*---------------------------------------------------------------------------*/
35 #include "fvCFD.H"
36 #include "singlePhaseTransportModel.H"
37 #include "RASModel.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 int main(int argc, char *argv[])
44     timeSelector::addOptions();
46 #   include "setRootCase.H"
47 #   include "createTime.H"
49     instantList timeDirs = timeSelector::select0(runTime, args);
51 #   include "createMesh.H"
53     forAll(timeDirs, timeI)
54     {
55         runTime.setTime(timeDirs[timeI], timeI);
57         Info<< "Time = " << runTime.timeName() << endl;
59         IOobject Uheader
60         (
61             "U",
62             runTime.timeName(),
63             mesh,
64             IOobject::MUST_READ
65         );
67         IOobject pHeader
68         (
69             "p",
70             runTime.timeName(),
71             mesh,
72             IOobject::MUST_READ
73         );
75         // Check U exists
76         if (Uheader.headerOk() && pHeader.headerOk())
77         {
78             mesh.readUpdate();
80             Info<< "    Reading U" << endl;
81             volVectorField U(Uheader, mesh);
83             Info<< "    Reading p" << endl;
84             volScalarField p(pHeader, mesh);
86 #           include "createPhi.H"
88             singlePhaseTransportModel laminarTransport(U, phi);
90             autoPtr<incompressible::RASModel> turbulence
91             (
92                 incompressible::RASModel::New(U, phi, laminarTransport)
93             );
95             Info<< "    Calculating uResidual" << endl;
96             volScalarField uResidual
97             (
98                 IOobject
99                 (
100                     "uResidual",
101                     runTime.timeName(),
102                     mesh,
103                     IOobject::NO_READ
104                 ),
105                 mag
106                 (
107                     fvc::div(phi, U)
108                   + fvc::div(turbulence->R())
109                   + fvc::grad(p)
110                 )
111             );
113             Info<< "uResidual max: " << max(uResidual.internalField())
114                 << " mean: "
115                 << sum(uResidual.internalField()*mesh.V())/
116                        sum(mesh.V()).value()
117                 << endl;
119             uResidual.write();
120         }
121         else
122         {
123             Info<< "    No U or p" << endl;
124         }
126         Info<< endl;
127     }
129     Info<< "End\n" << endl;
131     return(0);
135 // ************************************************************************* //