FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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