improved Co calculation
[OpenFOAM-1.5.x.git] / applications / utilities / postProcessing / velocityField / Co / Co.C
blob615fac46893f11991abc5b056674e7c3b0e5fa1d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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     Co
28 Description
29     Calculates and writes the Co number as a surfaceScalarField obtained
30     from field phi.
31     The -noWrite option just outputs the max values without writing the
32     field.
34 \*---------------------------------------------------------------------------*/
36 #include "calc.H"
37 #include "fvc.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 namespace Foam
43     tmp<volScalarField> Co(const surfaceScalarField& Cof)
44     {
45         const fvMesh& mesh = Cof.mesh();
47         tmp<volScalarField> tCo
48         (
49             new volScalarField
50             (
51                 IOobject
52                 (
53                     "Co",
54                     mesh.time().timeName(),
55                     mesh
56                 ),
57                 mesh,
58                 dimensionedScalar("0", Cof.dimensions(), 0)
59             )
60         );
62         volScalarField& Co = tCo();
64         // Set local references to mesh data
65         const unallocLabelList& owner = mesh.owner();
66         const unallocLabelList& neighbour = mesh.neighbour();
68         forAll(owner, facei)
69         {
70             label own = owner[facei];
71             label nei = neighbour[facei];
73             Co[own] = max(Co[own], Cof[facei]);
74             Co[nei] = max(Co[nei], Cof[facei]);
75         }
77         forAll(Co.boundaryField(), patchi)
78         {
79             Co.boundaryField()[patchi] = Cof.boundaryField()[patchi];
80         }
82         return tCo;
83     }
87 void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
89     bool writeResults = !args.options().found("noWrite");
91     IOobject phiHeader
92     (
93         "phi",
94         runTime.timeName(),
95         mesh,
96         IOobject::MUST_READ
97     );
99     if (phiHeader.headerOk())
100     {
101         autoPtr<surfaceScalarField> CoPtr;
103         Info<< "    Reading phi" << endl;
104         surfaceScalarField phi(phiHeader, mesh);
105         Info<< "    Calculating Co" << endl;
107         if (phi.dimensions() == dimensionSet(1, 0, -1, 0, 0))
108         {
109             // compressible
110             volScalarField rho
111             (
112                 IOobject
113                 (
114                     "rho",
115                     runTime.timeName(),
116                     mesh,
117                     IOobject::MUST_READ
118                 ),
119                 mesh
120             );
122             CoPtr.set
123             (
124                 new surfaceScalarField
125                 (
126                     IOobject
127                     (
128                         "Cof",
129                         runTime.timeName(),
130                         mesh,
131                         IOobject::NO_READ
132                     ),
133                     (
134                         mesh.surfaceInterpolation::deltaCoeffs()
135                       * (mag(phi)/(fvc::interpolate(rho)*mesh.magSf()))
136                       * runTime.deltaT()
137                     )
138                 )
139             );
140         }
141         else if (phi.dimensions() == dimensionSet(0, 3, -1, 0, 0))
142         {
143             // incompressible
144             CoPtr.set
145             (
146                 new surfaceScalarField
147                 (
148                     IOobject
149                     (
150                         "Cof",
151                         runTime.timeName(),
152                         mesh,
153                         IOobject::NO_READ
154                     ),
155                     (
156                         mesh.surfaceInterpolation::deltaCoeffs()
157                       * (mag(phi)/mesh.magSf())
158                       * runTime.deltaT()
159                     )
160                 )
161             );
162         }
163         else
164         {
165             FatalErrorIn(args.executable())
166                 << "Incorrect dimensions of phi: " << phi.dimensions()
167                     << abort(FatalError);
168         }
170         Info<< "Co max : " << max(CoPtr()).value() << endl;
172         if (writeResults)
173         {
174             CoPtr().write();
175             Co(CoPtr())().write();
176         }
177     }
178     else
179     {
180         Info<< "    No phi" << endl;
181     }
184 // ************************************************************************* //