leastSquaresGrad.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "leastSquaresGrad.H"
00028 #include "leastSquaresVectors.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 leastSquaresGrad<Type>::grad
00057 (
00058 const GeometricField<Type, fvPatchField, volMesh>& vsf
00059 ) const
00060 {
00061 typedef typename outerProduct<vector, Type>::type GradType;
00062
00063 const fvMesh& mesh = vsf.mesh();
00064
00065 tmp<GeometricField<GradType, fvPatchField, volMesh> > tlsGrad
00066 (
00067 new GeometricField<GradType, fvPatchField, volMesh>
00068 (
00069 IOobject
00070 (
00071 "grad("+vsf.name()+')',
00072 vsf.instance(),
00073 mesh,
00074 IOobject::NO_READ,
00075 IOobject::NO_WRITE
00076 ),
00077 mesh,
00078 dimensioned<GradType>
00079 (
00080 "zero",
00081 vsf.dimensions()/dimLength,
00082 pTraits<GradType>::zero
00083 ),
00084 zeroGradientFvPatchField<GradType>::typeName
00085 )
00086 );
00087 GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad();
00088
00089
00090 const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
00091
00092 const surfaceVectorField& ownLs = lsv.pVectors();
00093 const surfaceVectorField& neiLs = lsv.nVectors();
00094
00095 const unallocLabelList& own = mesh.owner();
00096 const unallocLabelList& nei = mesh.neighbour();
00097
00098 forAll(own, facei)
00099 {
00100 register label ownFaceI = own[facei];
00101 register label neiFaceI = nei[facei];
00102
00103 Type deltaVsf = vsf[neiFaceI] - vsf[ownFaceI];
00104
00105 lsGrad[ownFaceI] += ownLs[facei]*deltaVsf;
00106 lsGrad[neiFaceI] -= neiLs[facei]*deltaVsf;
00107 }
00108
00109
00110 forAll(vsf.boundaryField(), patchi)
00111 {
00112 const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi];
00113
00114 const unallocLabelList& faceCells =
00115 lsGrad.boundaryField()[patchi].patch().faceCells();
00116
00117 if (vsf.boundaryField()[patchi].coupled())
00118 {
00119 Field<Type> neiVsf =
00120 vsf.boundaryField()[patchi].patchNeighbourField();
00121
00122 forAll(neiVsf, patchFaceI)
00123 {
00124 lsGrad[faceCells[patchFaceI]] +=
00125 patchOwnLs[patchFaceI]
00126 *(neiVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
00127 }
00128 }
00129 else
00130 {
00131 const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi];
00132
00133 forAll(patchVsf, patchFaceI)
00134 {
00135 lsGrad[faceCells[patchFaceI]] +=
00136 patchOwnLs[patchFaceI]
00137 *(patchVsf[patchFaceI] - vsf[faceCells[patchFaceI]]);
00138 }
00139 }
00140 }
00141
00142
00143 lsGrad.correctBoundaryConditions();
00144 gaussGrad<Type>::correctBoundaryConditions(vsf, lsGrad);
00145
00146 return tlsGrad;
00147 }
00148
00149
00150
00151
00152 }
00153
00154
00155
00156 }
00157
00158
Copyright © 2000-2009 OpenCFD Ltd