leastSquaresVectors.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 "leastSquaresVectors.H"
00028 #include "surfaceFields.H"
00029 #include "volFields.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035 defineTypeNameAndDebug(leastSquaresVectors, 0);
00036 }
00037
00038
00039
00040
00041 Foam::leastSquaresVectors::leastSquaresVectors(const fvMesh& mesh)
00042 :
00043 MeshObject<fvMesh, leastSquaresVectors>(mesh),
00044 pVectorsPtr_(NULL),
00045 nVectorsPtr_(NULL)
00046 {}
00047
00048
00049
00050
00051 Foam::leastSquaresVectors::~leastSquaresVectors()
00052 {
00053 deleteDemandDrivenData(pVectorsPtr_);
00054 deleteDemandDrivenData(nVectorsPtr_);
00055 }
00056
00057
00058
00059
00060 void Foam::leastSquaresVectors::makeLeastSquaresVectors() const
00061 {
00062 if (debug)
00063 {
00064 Info<< "leastSquaresVectors::makeLeastSquaresVectors() :"
00065 << "Constructing least square gradient vectors"
00066 << endl;
00067 }
00068
00069 const fvMesh& mesh = mesh_;
00070
00071 pVectorsPtr_ = new surfaceVectorField
00072 (
00073 IOobject
00074 (
00075 "LeastSquaresP",
00076 mesh_.pointsInstance(),
00077 mesh_,
00078 IOobject::NO_READ,
00079 IOobject::NO_WRITE,
00080 false
00081 ),
00082 mesh_,
00083 dimensionedVector("zero", dimless/dimLength, vector::zero)
00084 );
00085 surfaceVectorField& lsP = *pVectorsPtr_;
00086
00087 nVectorsPtr_ = new surfaceVectorField
00088 (
00089 IOobject
00090 (
00091 "LeastSquaresN",
00092 mesh_.pointsInstance(),
00093 mesh_,
00094 IOobject::NO_READ,
00095 IOobject::NO_WRITE,
00096 false
00097 ),
00098 mesh_,
00099 dimensionedVector("zero", dimless/dimLength, vector::zero)
00100 );
00101 surfaceVectorField& lsN = *nVectorsPtr_;
00102
00103
00104 const unallocLabelList& owner = mesh_.owner();
00105 const unallocLabelList& neighbour = mesh_.neighbour();
00106
00107 const volVectorField& C = mesh.C();
00108 const surfaceScalarField& w = mesh.weights();
00109 const surfaceScalarField& magSf = mesh.magSf();
00110
00111
00112
00113 symmTensorField dd(mesh_.nCells(), symmTensor::zero);
00114
00115 forAll(owner, facei)
00116 {
00117 label own = owner[facei];
00118 label nei = neighbour[facei];
00119
00120 vector d = C[nei] - C[own];
00121 symmTensor wdd = (magSf[facei]/magSqr(d))*sqr(d);
00122
00123 dd[own] += (1 - w[facei])*wdd;
00124 dd[nei] += w[facei]*wdd;
00125 }
00126
00127
00128 forAll(lsP.boundaryField(), patchi)
00129 {
00130 const fvsPatchScalarField& pw = w.boundaryField()[patchi];
00131 const fvsPatchScalarField& pMagSf = magSf.boundaryField()[patchi];
00132
00133 const fvPatch& p = pw.patch();
00134 const unallocLabelList& faceCells = p.patch().faceCells();
00135
00136
00137 vectorField pd =
00138 mesh.Sf().boundaryField()[patchi]
00139 /(
00140 mesh.magSf().boundaryField()[patchi]
00141 *mesh.deltaCoeffs().boundaryField()[patchi]
00142 );
00143
00144 if (!mesh.orthogonal())
00145 {
00146 pd -= mesh.correctionVectors().boundaryField()[patchi]
00147 /mesh.deltaCoeffs().boundaryField()[patchi];
00148 }
00149
00150 if (p.coupled())
00151 {
00152 forAll(pd, patchFacei)
00153 {
00154 const vector& d = pd[patchFacei];
00155
00156 dd[faceCells[patchFacei]] +=
00157 ((1 - pw[patchFacei])*pMagSf[patchFacei]/magSqr(d))*sqr(d);
00158 }
00159 }
00160 else
00161 {
00162 forAll(pd, patchFacei)
00163 {
00164 const vector& d = pd[patchFacei];
00165
00166 dd[faceCells[patchFacei]] +=
00167 (pMagSf[patchFacei]/magSqr(d))*sqr(d);
00168 }
00169 }
00170 }
00171
00172
00173
00174 symmTensorField invDd = inv(dd);
00175
00176
00177
00178 forAll(owner, facei)
00179 {
00180 label own = owner[facei];
00181 label nei = neighbour[facei];
00182
00183 vector d = C[nei] - C[own];
00184 scalar magSfByMagSqrd = magSf[facei]/magSqr(d);
00185
00186 lsP[facei] = (1 - w[facei])*magSfByMagSqrd*(invDd[own] & d);
00187 lsN[facei] = -w[facei]*magSfByMagSqrd*(invDd[nei] & d);
00188 }
00189
00190 forAll(lsP.boundaryField(), patchi)
00191 {
00192 fvsPatchVectorField& patchLsP = lsP.boundaryField()[patchi];
00193
00194 const fvsPatchScalarField& pw = w.boundaryField()[patchi];
00195 const fvsPatchScalarField& pMagSf = magSf.boundaryField()[patchi];
00196
00197 const fvPatch& p = pw.patch();
00198 const unallocLabelList& faceCells = p.faceCells();
00199
00200
00201 vectorField pd =
00202 mesh.Sf().boundaryField()[patchi]
00203 /(
00204 mesh.magSf().boundaryField()[patchi]
00205 *mesh.deltaCoeffs().boundaryField()[patchi]
00206 );
00207
00208 if (!mesh.orthogonal())
00209 {
00210 pd -= mesh.correctionVectors().boundaryField()[patchi]
00211 /mesh.deltaCoeffs().boundaryField()[patchi];
00212 }
00213
00214
00215 if (p.coupled())
00216 {
00217 forAll(pd, patchFacei)
00218 {
00219 const vector& d = pd[patchFacei];
00220
00221 patchLsP[patchFacei] =
00222 ((1 - pw[patchFacei])*pMagSf[patchFacei]/magSqr(d))
00223 *(invDd[faceCells[patchFacei]] & d);
00224 }
00225 }
00226 else
00227 {
00228 forAll(pd, patchFacei)
00229 {
00230 const vector& d = pd[patchFacei];
00231
00232 patchLsP[patchFacei] =
00233 pMagSf[patchFacei]*(1.0/magSqr(d))
00234 *(invDd[faceCells[patchFacei]] & d);
00235 }
00236 }
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 if (debug)
00325 {
00326 Info<< "leastSquaresVectors::makeLeastSquaresVectors() :"
00327 << "Finished constructing least square gradient vectors"
00328 << endl;
00329 }
00330 }
00331
00332
00333 const Foam::surfaceVectorField& Foam::leastSquaresVectors::pVectors() const
00334 {
00335 if (!pVectorsPtr_)
00336 {
00337 makeLeastSquaresVectors();
00338 }
00339
00340 return *pVectorsPtr_;
00341 }
00342
00343
00344 const Foam::surfaceVectorField& Foam::leastSquaresVectors::nVectors() const
00345 {
00346 if (!nVectorsPtr_)
00347 {
00348 makeLeastSquaresVectors();
00349 }
00350
00351 return *nVectorsPtr_;
00352 }
00353
00354
00355 bool Foam::leastSquaresVectors::movePoints()
00356 {
00357 deleteDemandDrivenData(pVectorsPtr_);
00358 deleteDemandDrivenData(nVectorsPtr_);
00359
00360 return true;
00361 }
00362
00363
00364
Copyright © 2000-2009 OpenCFD Ltd