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

fourthGrad.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "fourthGrad.H"
00028 #include "leastSquaresGrad.H"
00029 #include "gaussGrad.H"
00030 #include "fvMesh.H"
00031 #include "volMesh.H"
00032 #include "surfaceMesh.H"
00033 #include "GeometricField.H"
00034 #include "zeroGradientFvPatchField.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace fv
00044 {
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 template<class Type>
00049 tmp
00050 <
00051     GeometricField
00052     <
00053         typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00054     >
00055 >
00056 fourthGrad<Type>::grad
00057 (
00058     const GeometricField<Type, fvPatchField, volMesh>& vsf
00059 ) const
00060 {
00061     // The fourth-order gradient is calculated in two passes.  First,
00062     // the standard least-square gradient is assembled.  Then, the
00063     // fourth-order correction is added to the second-order accurate
00064     // gradient to complete the accuracy.
00065 
00066     typedef typename outerProduct<vector, Type>::type GradType;
00067 
00068     const fvMesh& mesh = vsf.mesh();
00069 
00070     // Assemble the second-order least-square gradient
00071     // Calculate the second-order least-square gradient
00072     tmp<GeometricField<GradType, fvPatchField, volMesh> > tsecondfGrad
00073         = leastSquaresGrad<Type>(mesh).grad(vsf);
00074     const GeometricField<GradType, fvPatchField, volMesh>& secondfGrad =
00075         tsecondfGrad();
00076 
00077     tmp<GeometricField<GradType, fvPatchField, volMesh> > tfGrad
00078     (
00079         new GeometricField<GradType, fvPatchField, volMesh>
00080         (
00081             IOobject
00082             (
00083                 "grad("+vsf.name()+')',
00084                 vsf.instance(),
00085                 mesh,
00086                 IOobject::NO_READ,
00087                 IOobject::NO_WRITE
00088             ),
00089             secondfGrad
00090         )
00091     );
00092     GeometricField<GradType, fvPatchField, volMesh>& fGrad = tfGrad();
00093 
00094     const vectorField& C = mesh.C();
00095 
00096     const surfaceScalarField& lambda = mesh.weights();
00097 
00098     // Get reference to least square vectors
00099     const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
00100     const surfaceVectorField& ownLs = lsv.pVectors();
00101     const surfaceVectorField& neiLs = lsv.nVectors();
00102 
00103     // owner/neighbour addressing
00104     const unallocLabelList& own = mesh.owner();
00105     const unallocLabelList& nei = mesh.neighbour();
00106 
00107     // Assemble the fourth-order gradient
00108 
00109     // Internal faces
00110     forAll(own, facei)
00111     {
00112         Type dDotGradDelta = 0.5*
00113         (
00114            (C[nei[facei]] - C[own[facei]])
00115          & (secondfGrad[nei[facei]] - secondfGrad[own[facei]])
00116         );
00117 
00118         fGrad[own[facei]] -= lambda[facei]*ownLs[facei]*dDotGradDelta;
00119         fGrad[nei[facei]] -= (1.0 - lambda[facei])*neiLs[facei]*dDotGradDelta;
00120     }
00121 
00122     // Boundary faces
00123     forAll(vsf.boundaryField(), patchi)
00124     {
00125         if (secondfGrad.boundaryField()[patchi].coupled())
00126         {
00127             const fvsPatchVectorField& patchOwnLs =
00128                 ownLs.boundaryField()[patchi];
00129 
00130             const scalarField& lambdap = lambda.boundaryField()[patchi];
00131 
00132             // Build the d-vectors
00133             vectorField pd = 
00134                 mesh.Sf().boundaryField()[patchi]
00135                /(
00136                    mesh.magSf().boundaryField()[patchi]
00137                   *mesh.deltaCoeffs().boundaryField()[patchi]
00138                 );
00139 
00140             if (!mesh.orthogonal())
00141             {
00142                 pd -= mesh.correctionVectors().boundaryField()[patchi]
00143                      /mesh.deltaCoeffs().boundaryField()[patchi];
00144             }
00145 
00146             const unallocLabelList& faceCells =
00147                 fGrad.boundaryField()[patchi].patch().faceCells();
00148 
00149             Field<GradType> neighbourSecondfGrad =
00150                 secondfGrad.boundaryField()[patchi].patchNeighbourField();
00151 
00152             forAll(faceCells, patchFaceI)
00153             {
00154                 fGrad[faceCells[patchFaceI]] -=
00155                     0.5*lambdap[patchFaceI]*patchOwnLs[patchFaceI]
00156                    *(
00157                         pd[patchFaceI]
00158                       & (
00159                             neighbourSecondfGrad[patchFaceI]
00160                           - secondfGrad[faceCells[patchFaceI]]
00161                         )
00162                     );
00163             }
00164         }
00165     }
00166 
00167     fGrad.correctBoundaryConditions();
00168     gaussGrad<Type>::correctBoundaryConditions(vsf, fGrad);
00169 
00170     return tfGrad;
00171 }
00172 
00173 
00174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00175 
00176 } // End namespace fv
00177 
00178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00179 
00180 } // End namespace Foam
00181 
00182 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd