interpolationCellPointFace.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 #include "interpolationCellPointFace.H"
00030 #include "volFields.H"
00031 #include "polyMesh.H"
00032 #include "volPointInterpolation.H"
00033 #include "linear.H"
00034 #include "findCellPointFaceTet.H"
00035 #include "findCellPointFaceTriangle.H"
00036
00037
00038
00039 namespace Foam
00040 {
00041
00042
00043
00044 template<class Type>
00045 interpolationCellPointFace<Type>::interpolationCellPointFace
00046 (
00047 const GeometricField<Type, fvPatchField, volMesh>& psi
00048 )
00049 :
00050 interpolation<Type>(psi),
00051 psip_(volPointInterpolation::New(psi.mesh()).interpolate(psi)),
00052 psis_(linearInterpolate(psi))
00053 {}
00054
00055
00056
00057
00058 template<class Type>
00059 Type interpolationCellPointFace<Type>::interpolate
00060 (
00061 const vector& position,
00062 const label nCell,
00063 const label facei
00064 ) const
00065 {
00066 Type ts[4];
00067 vector tetPoints[4];
00068 scalar phi[4], phiCandidate[4];
00069 label tetLabelCandidate[2], tetPointLabels[2];
00070
00071 Type t = pTraits<Type>::zero;
00072
00073
00074 if (facei < 0)
00075 {
00076 const vector& cellCentre = this->pMesh_.cellCentres()[nCell];
00077 const labelList& cellFaces = this->pMesh_.cells()[nCell];
00078
00079 vector projection = position - cellCentre;
00080 tetPoints[3] = cellCentre;
00081
00082
00083
00084
00085
00086
00087 bool foundTet = false;
00088 label closestFace = -1;
00089 scalar minDistance = GREAT;
00090
00091 forAll(cellFaces, facei)
00092 {
00093 label nFace = cellFaces[facei];
00094
00095 vector normal = this->pMeshFaceAreas_[nFace];
00096 normal /= mag(normal);
00097
00098 const vector& faceCentreTmp = this->pMeshFaceCentres_[nFace];
00099
00100 scalar multiplierNumerator = (faceCentreTmp - cellCentre) & normal;
00101 scalar multiplierDenominator = projection & normal;
00102
00103
00104 if (mag(multiplierDenominator) > SMALL)
00105 {
00106 scalar multiplier = multiplierNumerator/multiplierDenominator;
00107 vector iPoint = cellCentre + multiplier*projection;
00108 scalar dist = mag(position - iPoint);
00109
00110 if (dist < minDistance)
00111 {
00112 closestFace = nFace;
00113 minDistance = dist;
00114 }
00115 }
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 minDistance = GREAT;
00125 if (closestFace != -1)
00126 {
00127 label nFace = closestFace;
00128 foundTet = findTet
00129 (
00130 position,
00131 nFace,
00132 tetPoints,
00133 tetLabelCandidate,
00134 tetPointLabels,
00135 phi,
00136 phiCandidate,
00137 closestFace,
00138 minDistance
00139 );
00140 }
00141
00142 if (!foundTet)
00143 {
00144
00145 if (minDistance < 1.0e-5)
00146 {
00147 foundTet = true;
00148 for (label i=0; i<4; i++)
00149 {
00150 phi[i] = phiCandidate[i];
00151 }
00152 tetPointLabels[0] = tetLabelCandidate[0];
00153 tetPointLabels[1] = tetLabelCandidate[1];
00154 }
00155 }
00156
00157
00158
00159
00160
00161 if (!foundTet)
00162 {
00163 minDistance = GREAT;
00164
00165 label facei = 0;
00166 while (facei < cellFaces.size() && !foundTet)
00167 {
00168 label nFace = cellFaces[facei];
00169 if (nFace < this->pMeshFaceAreas_.size())
00170 {
00171 foundTet = findTet
00172 (
00173 position,
00174 nFace,
00175 tetPoints,
00176 tetLabelCandidate,
00177 tetPointLabels,
00178 phi,
00179 phiCandidate,
00180 closestFace,
00181 minDistance
00182 );
00183 }
00184 facei++;
00185 }
00186 }
00187
00188 if (!foundTet)
00189 {
00190
00191
00192 if (minDistance < 1.0e-3)
00193 {
00194 foundTet = true;
00195 for (label i=0; i<4; i++)
00196 {
00197 phi[i] = phiCandidate[i];
00198 }
00199 tetPointLabels[0] = tetLabelCandidate[0];
00200 tetPointLabels[1] = tetLabelCandidate[1];
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209 if (foundTet)
00210 {
00211 for (label i=0; i<2; i++)
00212 {
00213 ts[i] = psip_[tetPointLabels[i]];
00214 }
00215
00216 if (closestFace < psis_.size())
00217 {
00218 ts[2] = psis_[closestFace];
00219 }
00220 else
00221 {
00222 label patchi = this->pMesh_.boundaryMesh().whichPatch(closestFace);
00223
00224
00225
00226 if (this->psi_.boundaryField()[patchi].size())
00227 {
00228 ts[2] = this->psi_.boundaryField()[patchi]
00229 [this->pMesh_.boundaryMesh()[patchi].whichFace(closestFace)];
00230 }
00231 else
00232 {
00233 ts[2] = this->psi_[nCell];
00234 }
00235 }
00236
00237 ts[3] = this->psi_[nCell];
00238
00239 for (label n=0; n<4; n++)
00240 {
00241 phi[n] = min(1.0, phi[n]);
00242 phi[n] = max(0.0, phi[n]);
00243
00244 t += phi[n]*ts[n];
00245 }
00246 }
00247 else
00248 {
00249 Info<< "interpolationCellPointFace<Type>::interpolate"
00250 << "(const vector&, const label nCell) const : "
00251 << "search failed; using closest cellFace value" << endl
00252 << "cell number " << nCell << tab
00253 << "position " << position << endl;
00254
00255 if (closestFace < psis_.size())
00256 {
00257 t = psis_[closestFace];
00258 }
00259 else
00260 {
00261 label patchi = this->pMesh_.boundaryMesh().whichPatch(closestFace);
00262
00263
00264
00265 if (this->psi_.boundaryField()[patchi].size())
00266 {
00267 t = this->psi_.boundaryField()[patchi]
00268 [this->pMesh_.boundaryMesh()[patchi].whichFace(closestFace)];
00269 }
00270 else
00271 {
00272 t = this->psi_[nCell];
00273 }
00274 }
00275 }
00276 }
00277 else
00278 {
00279 bool foundTriangle = findTriangle
00280 (
00281 position,
00282 facei,
00283 tetPointLabels,
00284 phi
00285 );
00286
00287 if (foundTriangle)
00288 {
00289
00290 for (label i=0; i<2; i++)
00291 {
00292 Type vel = psip_[tetPointLabels[i]];
00293 t += phi[i]*vel;
00294 }
00295
00296
00297 if (facei < psis_.size())
00298 {
00299 t += phi[2]*psis_[facei];
00300 }
00301 else
00302 {
00303 label patchi = this->pMesh_.boundaryMesh().whichPatch(facei);
00304
00305
00306
00307 if (this->psi_.boundaryField()[patchi].size())
00308 {
00309 t += phi[2]*this->psi_.boundaryField()[patchi]
00310 [this->pMesh_.boundaryMesh()[patchi].whichFace(facei)];
00311 }
00312 else
00313 {
00314 t += phi[2]*this->psi_[nCell];
00315 }
00316 }
00317 }
00318 else
00319 {
00320
00321 if (facei < psis_.size())
00322 {
00323 t = psis_[facei];
00324 }
00325 else
00326 {
00327 label patchi = this->pMesh_.boundaryMesh().whichPatch(facei);
00328
00329
00330
00331 if (this->psi_.boundaryField()[patchi].size())
00332 {
00333 t = this->psi_.boundaryField()[patchi]
00334 [this->pMesh_.boundaryMesh()[patchi].whichFace(facei)];
00335 }
00336 else
00337 {
00338 t = this->psi_[nCell];
00339 }
00340 }
00341 }
00342 }
00343
00344 return t;
00345 }
00346
00347
00348
00349
00350 }
00351
00352
Copyright © 2000-2009 OpenCFD Ltd