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

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