gaussGrad.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 "gaussGrad.H"
00028 #include "zeroGradientFvPatchField.H"
00029
00030
00031
00032 namespace Foam
00033 {
00034
00035
00036
00037 namespace fv
00038 {
00039
00040
00041
00042 template<class Type>
00043 tmp
00044 <
00045 GeometricField
00046 <
00047 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00048 >
00049 >
00050 gaussGrad<Type>::grad
00051 (
00052 const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
00053 )
00054 {
00055 typedef typename outerProduct<vector, Type>::type GradType;
00056
00057 const fvMesh& mesh = ssf.mesh();
00058
00059 tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
00060 (
00061 new GeometricField<GradType, fvPatchField, volMesh>
00062 (
00063 IOobject
00064 (
00065 "grad("+ssf.name()+')',
00066 ssf.instance(),
00067 mesh,
00068 IOobject::NO_READ,
00069 IOobject::NO_WRITE
00070 ),
00071 mesh,
00072 dimensioned<GradType>
00073 (
00074 "0",
00075 ssf.dimensions()/dimLength,
00076 pTraits<GradType>::zero
00077 ),
00078 zeroGradientFvPatchField<GradType>::typeName
00079 )
00080 );
00081 GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
00082
00083 const unallocLabelList& owner = mesh.owner();
00084 const unallocLabelList& neighbour = mesh.neighbour();
00085 const vectorField& Sf = mesh.Sf();
00086
00087 Field<GradType>& igGrad = gGrad;
00088 const Field<Type>& issf = ssf;
00089
00090 forAll(owner, facei)
00091 {
00092 GradType Sfssf = Sf[facei]*issf[facei];
00093
00094 igGrad[owner[facei]] += Sfssf;
00095 igGrad[neighbour[facei]] -= Sfssf;
00096 }
00097
00098 forAll(mesh.boundary(), patchi)
00099 {
00100 const unallocLabelList& pFaceCells =
00101 mesh.boundary()[patchi].faceCells();
00102
00103 const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
00104
00105 const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
00106
00107 forAll(mesh.boundary()[patchi], facei)
00108 {
00109 igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
00110 }
00111 }
00112
00113 igGrad /= mesh.V();
00114
00115 gGrad.correctBoundaryConditions();
00116
00117 return tgGrad;
00118 }
00119
00120
00121 template<class Type>
00122 tmp
00123 <
00124 GeometricField
00125 <
00126 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00127 >
00128 >
00129 gaussGrad<Type>::grad
00130 (
00131 const GeometricField<Type, fvPatchField, volMesh>& vsf
00132 ) const
00133 {
00134 typedef typename outerProduct<vector, Type>::type GradType;
00135
00136 tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
00137 (
00138 grad(tinterpScheme_().interpolate(vsf))
00139 );
00140 GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
00141
00142 gGrad.rename("grad(" + vsf.name() + ')');
00143 correctBoundaryConditions(vsf, gGrad);
00144
00145 return tgGrad;
00146 }
00147
00148
00149 template<class Type>
00150 void gaussGrad<Type>::correctBoundaryConditions
00151 (
00152 const GeometricField<Type, fvPatchField, volMesh>& vsf,
00153 GeometricField
00154 <
00155 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
00156 >& gGrad
00157 )
00158 {
00159 forAll(vsf.boundaryField(), patchi)
00160 {
00161 if (!vsf.boundaryField()[patchi].coupled())
00162 {
00163 vectorField n =
00164 vsf.mesh().Sf().boundaryField()[patchi]
00165 /vsf.mesh().magSf().boundaryField()[patchi];
00166
00167 gGrad.boundaryField()[patchi] += n *
00168 (
00169 vsf.boundaryField()[patchi].snGrad()
00170 - (n & gGrad.boundaryField()[patchi])
00171 );
00172 }
00173 }
00174 }
00175
00176
00177
00178
00179 }
00180
00181
00182
00183 }
00184
00185
Copyright © 2000-2009 OpenCFD Ltd