Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / velocityField / Co / Co.C
blobc320674f155a0a2860ab26a3dd2cac386f0e326f
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     Co
27 Description
28     Calculates and writes the Co number as a surfaceScalarField obtained
29     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.optionFound("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     }
183     Info<< "\nEnd\n" << endl;
187 // ************************************************************************* //