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

Mach.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     Mach
00027 
00028 Description
00029     Calculates and optionally writes the local Mach number from the velocity
00030     field U at each time.
00031 
00032     The -nowrite option just outputs the max value without writing the field.
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #include "calc.H"
00037 #include "basicPsiThermo.H"
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
00041 {
00042     bool writeResults = !args.optionFound("noWrite");
00043 
00044     IOobject Uheader
00045     (
00046         "U",
00047         runTime.timeName(),
00048         mesh,
00049         IOobject::MUST_READ
00050     );
00051 
00052     IOobject Theader
00053     (
00054         "T",
00055         runTime.timeName(),
00056         mesh,
00057         IOobject::MUST_READ
00058     );
00059 
00060     // Check U and T exists
00061     if (Uheader.headerOk() && Theader.headerOk())
00062     {
00063         autoPtr<volScalarField> MachPtr;
00064 
00065         volVectorField U(Uheader, mesh);
00066 
00067         if (isFile(runTime.constantPath()/"thermophysicalProperties"))
00068         {
00069             // thermophysical Mach
00070             autoPtr<basicPsiThermo> thermo
00071             (
00072                 basicPsiThermo::New(mesh)
00073             );
00074 
00075             volScalarField Cp = thermo->Cp();
00076             volScalarField Cv = thermo->Cv();
00077 
00078             MachPtr.set
00079             (
00080                 new volScalarField
00081                 (
00082                     IOobject
00083                     (
00084                         "Ma",
00085                         runTime.timeName(),
00086                         mesh
00087                     ),
00088                     mag(U)/(sqrt((Cp/Cv)*(Cp - Cv)*thermo->T()))
00089                 )
00090             );
00091         }
00092         else
00093         {
00094             // thermodynamic Mach
00095             IOdictionary thermoProps
00096             (
00097                 IOobject
00098                 (
00099                     "thermodynamicProperties",
00100                     runTime.constant(),
00101                     mesh,
00102                     IOobject::MUST_READ,
00103                     IOobject::NO_WRITE
00104                 )
00105             );
00106 
00107             dimensionedScalar R(thermoProps.lookup("R"));
00108             dimensionedScalar Cv(thermoProps.lookup("Cv"));
00109 
00110             volScalarField T(Theader, mesh);
00111 
00112             MachPtr.set
00113             (
00114                 new volScalarField
00115                 (
00116                     IOobject
00117                     (
00118                         "Ma",
00119                         runTime.timeName(),
00120                         mesh
00121                     ),
00122                     mag(U)/(sqrt(((Cv + R)/Cv)*R*T))
00123                 )
00124             );
00125         }
00126 
00127         Info<< "Mach max : " << max(MachPtr()).value() << endl;
00128 
00129         if (writeResults)
00130         {
00131             MachPtr().write();
00132         }
00133     }
00134     else
00135     {
00136         Info<< "    Missing U or T" << endl;
00137     }
00138 
00139     Info<< "\nEnd\n" << endl;
00140 }
00141 
00142 
00143 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd