initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / errorEstimation / icoMomentError / icoMomentError.C
blob67551e1eeccc631b48d02a815307f9f52e309748
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     icoMomentError
28 Description
29     Estimates error for the incompressible laminar CFD application icoFoam.
31 \*---------------------------------------------------------------------------*/
33 #include "fvCFD.H"
34 #include "linear.H"
35 #include "gaussConvectionScheme.H"
36 #include "gaussLaplacianScheme.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 int main(int argc, char *argv[])
42     timeSelector::addOptions();
44 #   include "setRootCase.H"
45 #   include "createTime.H"
47     instantList timeDirs = timeSelector::select0(runTime, args);
49 #   include "createMesh.H"
51     Info<< "\nEstimating error in the incompressible momentum equation\n"
52         << "Reading transportProperties\n" << endl;
54     IOdictionary transportProperties
55     (
56         IOobject
57         (
58             "transportProperties",
59             runTime.constant(),
60             mesh,
61             IOobject::MUST_READ,
62             IOobject::NO_WRITE
63         )
64     );
66     dimensionedScalar nu
67     (
68         transportProperties.lookup("nu")
69     );
71     forAll(timeDirs, timeI)
72     {
73         runTime.setTime(timeDirs[timeI], timeI);
75         Info<< "Time = " << runTime.timeName() << endl;
77         mesh.readUpdate();
79         IOobject pHeader
80         (
81             "p",
82             runTime.timeName(),
83             mesh,
84             IOobject::MUST_READ
85         );
87         IOobject Uheader
88         (
89             "U",
90             runTime.timeName(),
91             mesh,
92             IOobject::MUST_READ
93         );
95         if (pHeader.headerOk() && Uheader.headerOk())
96         {
97             Info << "Reading p" << endl;
98             volScalarField p(pHeader, mesh);
100             Info << "Reading U" << endl;
101             volVectorField U(Uheader, mesh);
103 #           include "createPhi.H"
105             volScalarField ek = 0.5*magSqr(U);
106             volTensorField gradU = fvc::grad(U);
108             // Divergence of the error in U squared
110             volScalarField L
111             (
112                 IOobject
113                 (
114                     "L",
115                     mesh.time().timeName(),
116                     mesh,
117                     IOobject::NO_READ,
118                     IOobject::NO_WRITE
119                 ),
120                 mesh,
121                 dimensionedScalar("one", dimLength, 1.0)
122             );
124             L.internalField() =
125                 mesh.V()/fvc::surfaceSum(mesh.magSf())().internalField();
127             // Warning: 4th row of this equation specially modified
128             // for the momentum equation. The "real" formulation would
129             // have diffusivity*(gradV && gradV)
130             volScalarField momError
131             (
132                 IOobject
133                 (
134                     "momErrorL" + U.name(),
135                     mesh.time().timeName(),
136                     mesh,
137                     IOobject::NO_READ,
138                     IOobject::NO_WRITE
139                 ),
140                 sqrt
141                 (
142                     2.0*mag
143                     (
144                         (
145                             fv::gaussConvectionScheme<scalar>
146                             (
147                                 mesh,
148                                 phi,
149                                 tmp<surfaceInterpolationScheme<scalar> >
150                                 (
151                                     new linear<scalar>(mesh)
152                                 )
153                             ).fvcDiv(phi, ek)
155                           - nu*
156                             fv::gaussLaplacianScheme<scalar, scalar>(mesh)
157                            .fvcLaplacian
158                             (
159                                 ek
160                             )
161                           - (U & fvc::grad(p))
162 //                        + nu*(gradU && gradU)
163                           + 0.5*nu*
164                             (
165                                 gradU && (gradU + gradU.T())
166                             )
167                         )*L/(mag(U) + nu/L)
168                     )
169                 )
170             );
172             momError.boundaryField() = 0.0;
173             momError.write();
174         }
175         else
176         {
177             Info<< "    No p or U" << endl;
178         }
180         Info<< endl;
181     }
183     Info<< "End\n" << endl;
185     return 0;
189 // ************************************************************************* //