OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

Co.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     Co
00027 
00028 Description
00029     Calculates and writes the Co number as a surfaceScalarField obtained
00030     from field phi.
00031 
00032     The -noWrite option just outputs the max values without writing the
00033     field.
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #include "calc.H"
00038 #include "fvc.H"
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace Foam
00043 {
00044     tmp<volScalarField> Co(const surfaceScalarField& Cof)
00045     {
00046         const fvMesh& mesh = Cof.mesh();
00047 
00048         tmp<volScalarField> tCo
00049         (
00050             new volScalarField
00051             (
00052                 IOobject
00053                 (
00054                     "Co",
00055                     mesh.time().timeName(),
00056                     mesh
00057                 ),
00058                 mesh,
00059                 dimensionedScalar("0", Cof.dimensions(), 0)
00060             )
00061         );
00062 
00063         volScalarField& Co = tCo();
00064 
00065         // Set local references to mesh data
00066         const unallocLabelList& owner = mesh.owner();
00067         const unallocLabelList& neighbour = mesh.neighbour();
00068 
00069         forAll(owner, facei)
00070         {
00071             label own = owner[facei];
00072             label nei = neighbour[facei];
00073 
00074             Co[own] = max(Co[own], Cof[facei]);
00075             Co[nei] = max(Co[nei], Cof[facei]);
00076         }
00077 
00078         forAll(Co.boundaryField(), patchi)
00079         {
00080             Co.boundaryField()[patchi] = Cof.boundaryField()[patchi];
00081         }
00082 
00083         return tCo;
00084     }
00085 }
00086 
00087 
00088 void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
00089 {
00090     bool writeResults = !args.optionFound("noWrite");
00091 
00092     IOobject phiHeader
00093     (
00094         "phi",
00095         runTime.timeName(),
00096         mesh,
00097         IOobject::MUST_READ
00098     );
00099 
00100     if (phiHeader.headerOk())
00101     {
00102         autoPtr<surfaceScalarField> CoPtr;
00103 
00104         Info<< "    Reading phi" << endl;
00105         surfaceScalarField phi(phiHeader, mesh);
00106         Info<< "    Calculating Co" << endl;
00107 
00108         if (phi.dimensions() == dimensionSet(1, 0, -1, 0, 0))
00109         {
00110             // compressible
00111             volScalarField rho
00112             (
00113                 IOobject
00114                 (
00115                     "rho",
00116                     runTime.timeName(),
00117                     mesh,
00118                     IOobject::MUST_READ
00119                 ),
00120                 mesh
00121             );
00122 
00123             CoPtr.set
00124             (
00125                 new surfaceScalarField
00126                 (
00127                     IOobject
00128                     (
00129                         "Cof",
00130                         runTime.timeName(),
00131                         mesh,
00132                         IOobject::NO_READ
00133                     ),
00134                     (
00135                         mesh.surfaceInterpolation::deltaCoeffs()
00136                       * (mag(phi)/(fvc::interpolate(rho)*mesh.magSf()))
00137                       * runTime.deltaT()
00138                     )
00139                 )
00140             );
00141         }
00142         else if (phi.dimensions() == dimensionSet(0, 3, -1, 0, 0))
00143         {
00144             // incompressible
00145             CoPtr.set
00146             (
00147                 new surfaceScalarField
00148                 (
00149                     IOobject
00150                     (
00151                         "Cof",
00152                         runTime.timeName(),
00153                         mesh,
00154                         IOobject::NO_READ
00155                     ),
00156                     (
00157                         mesh.surfaceInterpolation::deltaCoeffs()
00158                       * (mag(phi)/mesh.magSf())
00159                       * runTime.deltaT()
00160                     )
00161                 )
00162             );
00163         }
00164         else
00165         {
00166             FatalErrorIn(args.executable())
00167                 << "Incorrect dimensions of phi: " << phi.dimensions()
00168                     << abort(FatalError);
00169         }
00170 
00171         Info<< "Co max : " << max(CoPtr()).value() << endl;
00172 
00173         if (writeResults)
00174         {
00175             CoPtr().write();
00176             Co(CoPtr())().write();
00177         }
00178     }
00179     else
00180     {
00181         Info<< "    No phi" << endl;
00182     }
00183 
00184     Info<< "\nEnd\n" << endl;
00185 }
00186 
00187 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd