surfaceInterpolation.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
00028
00029
00030 #include "fvMesh.H"
00031 #include "volFields.H"
00032 #include "surfaceFields.H"
00033 #include "demandDrivenData.H"
00034 #include "coupledFvPatch.H"
00035 #include "mathematicalConstants.H"
00036
00037
00038
00039 namespace Foam
00040 {
00041
00042
00043
00044 defineTypeNameAndDebug(surfaceInterpolation, 0);
00045
00046
00047
00048
00049 void surfaceInterpolation::clearOut()
00050 {
00051 deleteDemandDrivenData(weightingFactors_);
00052 deleteDemandDrivenData(differenceFactors_);
00053 deleteDemandDrivenData(correctionVectors_);
00054 }
00055
00056
00057
00058
00059 surfaceInterpolation::surfaceInterpolation(const fvMesh& fvm)
00060 :
00061 fvSchemes(static_cast<const objectRegistry&>(fvm)),
00062 fvSolution(static_cast<const objectRegistry&>(fvm)),
00063 mesh_(fvm),
00064 weightingFactors_(NULL),
00065 differenceFactors_(NULL),
00066 orthogonal_(false),
00067 correctionVectors_(NULL)
00068 {}
00069
00070
00071
00072
00073 surfaceInterpolation::~surfaceInterpolation()
00074 {
00075 clearOut();
00076 }
00077
00078
00079
00080
00081 const surfaceScalarField& surfaceInterpolation::weights() const
00082 {
00083 if (!weightingFactors_)
00084 {
00085 makeWeights();
00086 }
00087
00088 return (*weightingFactors_);
00089 }
00090
00091
00092 const surfaceScalarField& surfaceInterpolation::deltaCoeffs() const
00093 {
00094 if (!differenceFactors_)
00095 {
00096 makeDeltaCoeffs();
00097 }
00098
00099 return (*differenceFactors_);
00100 }
00101
00102
00103 bool surfaceInterpolation::orthogonal() const
00104 {
00105 if (orthogonal_ == false && !correctionVectors_)
00106 {
00107 makeCorrectionVectors();
00108 }
00109
00110 return orthogonal_;
00111 }
00112
00113
00114 const surfaceVectorField& surfaceInterpolation::correctionVectors() const
00115 {
00116 if (orthogonal())
00117 {
00118 FatalErrorIn("surfaceInterpolation::correctionVectors()")
00119 << "cannot return correctionVectors; mesh is orthogonal"
00120 << abort(FatalError);
00121 }
00122
00123 return (*correctionVectors_);
00124 }
00125
00126
00127
00128 bool surfaceInterpolation::movePoints()
00129 {
00130 deleteDemandDrivenData(weightingFactors_);
00131 deleteDemandDrivenData(differenceFactors_);
00132
00133 orthogonal_ = false;
00134 deleteDemandDrivenData(correctionVectors_);
00135
00136 return true;
00137 }
00138
00139
00140 void surfaceInterpolation::makeWeights() const
00141 {
00142 if (debug)
00143 {
00144 Info<< "surfaceInterpolation::makeWeights() : "
00145 << "Constructing weighting factors for face interpolation"
00146 << endl;
00147 }
00148
00149
00150 weightingFactors_ = new surfaceScalarField
00151 (
00152 IOobject
00153 (
00154 "weightingFactors",
00155 mesh_.pointsInstance(),
00156 mesh_
00157 ),
00158 mesh_,
00159 dimless
00160 );
00161 surfaceScalarField& weightingFactors = *weightingFactors_;
00162
00163
00164
00165
00166
00167
00168 const unallocLabelList& owner = mesh_.owner();
00169 const unallocLabelList& neighbour = mesh_.neighbour();
00170
00171 const vectorField& Cf = mesh_.faceCentres();
00172 const vectorField& C = mesh_.cellCentres();
00173 const vectorField& Sf = mesh_.faceAreas();
00174
00175
00176 scalarField& w = weightingFactors.internalField();
00177
00178 forAll(owner, facei)
00179 {
00180
00181
00182
00183
00184
00185 scalar SfdOwn = mag(Sf[facei] & (Cf[facei] - C[owner[facei]]));
00186 scalar SfdNei = mag(Sf[facei] & (C[neighbour[facei]] - Cf[facei]));
00187 w[facei] = SfdNei/(SfdOwn + SfdNei);
00188 }
00189
00190 forAll(mesh_.boundary(), patchi)
00191 {
00192 mesh_.boundary()[patchi].makeWeights
00193 (
00194 weightingFactors.boundaryField()[patchi]
00195 );
00196 }
00197
00198
00199 if (debug)
00200 {
00201 Info<< "surfaceInterpolation::makeWeights() : "
00202 << "Finished constructing weighting factors for face interpolation"
00203 << endl;
00204 }
00205 }
00206
00207
00208 void surfaceInterpolation::makeDeltaCoeffs() const
00209 {
00210 if (debug)
00211 {
00212 Info<< "surfaceInterpolation::makeDeltaCoeffs() : "
00213 << "Constructing differencing factors array for face gradient"
00214 << endl;
00215 }
00216
00217
00218
00219 weights();
00220
00221 differenceFactors_ = new surfaceScalarField
00222 (
00223 IOobject
00224 (
00225 "differenceFactors_",
00226 mesh_.pointsInstance(),
00227 mesh_
00228 ),
00229 mesh_,
00230 dimless/dimLength
00231 );
00232 surfaceScalarField& DeltaCoeffs = *differenceFactors_;
00233
00234
00235
00236 const volVectorField& C = mesh_.C();
00237 const unallocLabelList& owner = mesh_.owner();
00238 const unallocLabelList& neighbour = mesh_.neighbour();
00239 const surfaceVectorField& Sf = mesh_.Sf();
00240 const surfaceScalarField& magSf = mesh_.magSf();
00241
00242 forAll(owner, facei)
00243 {
00244 vector delta = C[neighbour[facei]] - C[owner[facei]];
00245 vector unitArea = Sf[facei]/magSf[facei];
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 DeltaCoeffs[facei] = 1.0/max(unitArea & delta, 0.05*mag(delta));
00258 }
00259
00260 forAll(DeltaCoeffs.boundaryField(), patchi)
00261 {
00262 mesh_.boundary()[patchi].makeDeltaCoeffs
00263 (
00264 DeltaCoeffs.boundaryField()[patchi]
00265 );
00266 }
00267 }
00268
00269
00270 void surfaceInterpolation::makeCorrectionVectors() const
00271 {
00272 if (debug)
00273 {
00274 Info<< "surfaceInterpolation::makeCorrectionVectors() : "
00275 << "Constructing non-orthogonal correction vectors"
00276 << endl;
00277 }
00278
00279 correctionVectors_ = new surfaceVectorField
00280 (
00281 IOobject
00282 (
00283 "correctionVectors",
00284 mesh_.pointsInstance(),
00285 mesh_
00286 ),
00287 mesh_,
00288 dimless
00289 );
00290 surfaceVectorField& corrVecs = *correctionVectors_;
00291
00292
00293 const volVectorField& C = mesh_.C();
00294 const unallocLabelList& owner = mesh_.owner();
00295 const unallocLabelList& neighbour = mesh_.neighbour();
00296 const surfaceVectorField& Sf = mesh_.Sf();
00297 const surfaceScalarField& magSf = mesh_.magSf();
00298 const surfaceScalarField& DeltaCoeffs = deltaCoeffs();
00299
00300 forAll(owner, facei)
00301 {
00302 vector unitArea = Sf[facei]/magSf[facei];
00303 vector delta = C[neighbour[facei]] - C[owner[facei]];
00304
00305 corrVecs[facei] = unitArea - delta*DeltaCoeffs[facei];
00306 }
00307
00308
00309
00310
00311
00312 forAll(corrVecs.boundaryField(), patchi)
00313 {
00314 fvsPatchVectorField& patchcorrVecs = corrVecs.boundaryField()[patchi];
00315
00316 if (!patchcorrVecs.coupled())
00317 {
00318 patchcorrVecs = vector::zero;
00319 }
00320 else
00321 {
00322 const fvsPatchScalarField& patchDeltaCoeffs
00323 = DeltaCoeffs.boundaryField()[patchi];
00324
00325 const fvPatch& p = patchcorrVecs.patch();
00326
00327 vectorField patchDeltas = mesh_.boundary()[patchi].delta();
00328
00329 forAll(p, patchFacei)
00330 {
00331 vector unitArea =
00332 Sf.boundaryField()[patchi][patchFacei]
00333 /magSf.boundaryField()[patchi][patchFacei];
00334
00335 const vector& delta = patchDeltas[patchFacei];
00336
00337 patchcorrVecs[patchFacei] =
00338 unitArea - delta*patchDeltaCoeffs[patchFacei];
00339 }
00340 }
00341 }
00342
00343 scalar NonOrthogCoeff = 0.0;
00344
00345
00346 if (returnReduce(magSf.size(), sumOp<label>()) > 0)
00347 {
00348 NonOrthogCoeff =
00349 asin
00350 (
00351 min
00352 (
00353 (sum(magSf*mag(corrVecs))/sum(magSf)).value(),
00354 1.0
00355 )
00356 )*180.0/mathematicalConstant::pi;
00357 }
00358
00359 if (debug)
00360 {
00361 Info<< "surfaceInterpolation::makeCorrectionVectors() : "
00362 << "non-orthogonality coefficient = " << NonOrthogCoeff << " deg."
00363 << endl;
00364 }
00365
00366
00367
00368 if (NonOrthogCoeff < 0.1)
00369 {
00370 orthogonal_ = true;
00371 deleteDemandDrivenData(correctionVectors_);
00372 }
00373 else
00374 {
00375 orthogonal_ = false;
00376 }
00377
00378 if (debug)
00379 {
00380 Info<< "surfaceInterpolation::makeCorrectionVectors() : "
00381 << "Finished constructing non-orthogonal correction vectors"
00382 << endl;
00383 }
00384 }
00385
00386
00387
00388
00389 }
00390
00391
Copyright © 2000-2009 OpenCFD Ltd