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

momentScalarError.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     momentScalarError
00027 
00028 Description
00029     Estimates the error in the solution for a scalar transport equation in the
00030     standard form
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #include "fvCFD.H"
00035 #include "linear.H"
00036 #include "gaussConvectionScheme.H"
00037 #include "gaussLaplacianScheme.H"
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 int main(int argc, char *argv[])
00042 {
00043     timeSelector::addOptions();
00044 
00045 #   include "setRootCase.H"
00046 #   include "createTime.H"
00047 
00048     instantList timeDirs = timeSelector::select0(runTime, args);
00049 
00050 #   include "createMesh.H"
00051 
00052     Info<< "\nEstimating error in scalar transport equation\n"
00053         << "Reading transportProperties\n" << endl;
00054 
00055     IOdictionary transportProperties
00056     (
00057         IOobject
00058         (
00059             "transportProperties",
00060             runTime.constant(),
00061             mesh,
00062             IOobject::MUST_READ,
00063             IOobject::NO_WRITE
00064         )
00065     );
00066 
00067 
00068     Info<< "Reading diffusivity DT\n" << endl;
00069 
00070     dimensionedScalar DT
00071     (
00072         transportProperties.lookup("DT")
00073     );
00074 
00075 
00076     forAll(timeDirs, timeI)
00077     {
00078         runTime.setTime(timeDirs[timeI], timeI);
00079 
00080         Info<< "Time = " << runTime.timeName() << endl;
00081 
00082         mesh.readUpdate();
00083 
00084         IOobject THeader
00085         (
00086             "T",
00087             runTime.timeName(),
00088             mesh,
00089             IOobject::MUST_READ
00090         );
00091 
00092         IOobject Uheader
00093         (
00094             "U",
00095             runTime.timeName(),
00096             mesh,
00097             IOobject::MUST_READ
00098         );
00099 
00100         if (THeader.headerOk() && Uheader.headerOk())
00101         {
00102             Info << "Reading T" << endl;
00103             volScalarField T(THeader, mesh);
00104 
00105             Info << "Reading U" << endl;
00106             volVectorField U(Uheader, mesh);
00107 
00108 #           include "createPhi.H"
00109 
00110             volVectorField gradT = fvc::grad(T);
00111 
00112             volScalarField TE = 0.5*sqr(T);
00113 
00114             volScalarField L
00115             (
00116                 IOobject
00117                 (
00118                     "L",
00119                     mesh.time().timeName(),
00120                     mesh,
00121                     IOobject::NO_READ,
00122                     IOobject::NO_WRITE
00123                 ),
00124                 mesh,
00125                 dimensionedScalar("one", dimLength, 1.0)
00126             );
00127 
00128             L.internalField() =
00129                 mesh.V()/fvc::surfaceSum(mesh.magSf())().internalField();
00130 
00131             // Divergence of the error in the T squared
00132             volScalarField momError
00133             (
00134                 IOobject
00135                 (
00136                     "momErrorL" + T.name(),
00137                     mesh.time().timeName(),
00138                     mesh,
00139                     IOobject::NO_READ,
00140                     IOobject::NO_WRITE
00141                 ),
00142                 sqrt
00143                 (
00144                     2.0*mag
00145                     (
00146                         (
00147                             fv::gaussConvectionScheme<scalar>
00148                             (
00149                                 mesh,
00150                                 phi,
00151                                 tmp<surfaceInterpolationScheme<scalar> >
00152                                 (
00153                                     new linear<scalar>(mesh)
00154                                 )
00155                             ).fvcDiv(phi, TE)
00156 
00157                           - DT*
00158                             fv::gaussLaplacianScheme<scalar, scalar>(mesh)
00159                            .fvcLaplacian
00160                             (
00161                                 TE
00162                             )
00163                           + DT*(gradT & gradT)
00164                         )*L/(mag(U) + DT/L)
00165                     )
00166                 )
00167             );
00168 
00169             momError.boundaryField() = 0.0;
00170             momError.write();
00171         }
00172         else
00173         {
00174             Info<< "    No T or U" << endl;
00175         }
00176 
00177         Info<< endl;
00178     }
00179 
00180     Info<< "End\n" << endl;
00181 
00182     return 0;
00183 }
00184 
00185 
00186 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd