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 "polyMesh.H"
00028
00029
00030
00031 namespace Foam
00032 {
00033
00034
00035
00036 template<class particleType>
00037 inline scalar particle<particleType>::lambda
00038 (
00039 const vector& from,
00040 const vector& to,
00041 const label facei,
00042 const scalar stepFraction
00043 )
00044 {
00045 const polyMesh& mesh = cloud_.polyMesh_;
00046 bool movingMesh = mesh.moving();
00047
00048 if (movingMesh)
00049 {
00050 vector Sf = mesh.faceAreas()[facei];
00051 Sf /= mag(Sf);
00052 vector Cf = mesh.faceCentres()[facei];
00053
00054
00055 if (!cloud_.internalFace(facei))
00056 {
00057 const vector& C = mesh.cellCentres()[celli_];
00058 scalar CCf = mag((C - Cf) & Sf);
00059
00060
00061 if
00062 (
00063 CCf
00064 > static_cast<const particleType&>(*this).wallImpactDistance(Sf)
00065 )
00066 {
00067 Cf -= static_cast<const particleType&>(*this)
00068 .wallImpactDistance(Sf)*Sf;
00069 }
00070 }
00071
00072
00073
00074
00075
00076 const vectorField& oldPoints = mesh.oldPoints();
00077
00078 vector Cf00 = mesh.faces()[facei].centre(oldPoints);
00079 vector Cf0 = Cf00 + stepFraction*(Cf - Cf00);
00080
00081 vector Sf00 = mesh.faces()[facei].normal(oldPoints);
00082
00083
00084 if (mag(Sf00) > SMALL)
00085 {
00086 Sf00 /= mag(Sf00);
00087 }
00088 else
00089 {
00090 Sf00 = Sf;
00091 }
00092
00093 scalar magSfDiff = mag(Sf - Sf00);
00094
00095
00096 if (magSfDiff > SMALL)
00097 {
00098 vector Sf0 = Sf00 + stepFraction*(Sf - Sf00);
00099
00100
00101 vector omega = Sf0 ^ Sf;
00102 scalar magOmega = mag(omega);
00103 omega /= magOmega+SMALL;
00104 vector n0 = omega ^ Sf0;
00105 scalar lam = ((Cf - Cf0) & Sf)/(n0 & Sf);
00106 vector r0 = Cf0 + lam*n0;
00107
00108
00109
00110
00111
00112
00113 vector alpha = from - r0;
00114 vector beta = to - from;
00115 scalar a = beta & (Sf - Sf0);
00116 scalar b = (alpha & (Sf - Sf0)) + (beta & Sf0);
00117 scalar c = alpha & Sf0;
00118
00119 if (mag(a) > SMALL)
00120 {
00121
00122 scalar ap = b/a;
00123 scalar bp = c/a;
00124 scalar cp = ap*ap - 4.0*bp;
00125
00126 if (cp < 0.0)
00127 {
00128
00129 return GREAT;
00130 }
00131 else
00132 {
00133 scalar l1 = -0.5*(ap - ::sqrt(cp));
00134 scalar l2 = -0.5*(ap + ::sqrt(cp));
00135
00136
00137
00138 if (mag(l1) < mag(l2))
00139 {
00140 return l1;
00141 }
00142 else
00143 {
00144 return l2;
00145 }
00146 }
00147 }
00148 else
00149 {
00150
00151 return (-c/b);
00152 }
00153 }
00154 else
00155 {
00156 vector alpha = from - Cf0;
00157 vector beta = to - from - (Cf - Cf0);
00158 scalar lambdaNominator = alpha & Sf;
00159 scalar lambdaDenominator = beta & Sf;
00160
00161
00162 if (mag(lambdaDenominator) < SMALL)
00163 {
00164 if (lambdaDenominator < 0.0)
00165 {
00166 lambdaDenominator = -SMALL;
00167 }
00168 else
00169 {
00170 lambdaDenominator = SMALL;
00171 }
00172 }
00173
00174 return (-lambdaNominator/lambdaDenominator);
00175 }
00176 }
00177 else
00178 {
00179
00180 return lambda(from, to, facei);
00181 }
00182 }
00183
00184
00185 template<class particleType>
00186 inline scalar particle<particleType>::lambda
00187 (
00188 const vector& from,
00189 const vector& to,
00190 const label facei
00191 )
00192 {
00193 const polyMesh& mesh = cloud_.polyMesh_;
00194
00195 vector Sf = mesh.faceAreas()[facei];
00196 Sf /= mag(Sf);
00197 vector Cf = mesh.faceCentres()[facei];
00198
00199
00200 if (!cloud_.internalFace(facei))
00201 {
00202 const vector& C = mesh.cellCentres()[celli_];
00203 scalar CCf = mag((C - Cf) & Sf);
00204
00205
00206 if
00207 (
00208 CCf
00209 > static_cast<const particleType&>(*this).wallImpactDistance(Sf)
00210 )
00211 {
00212 Cf -= static_cast<const particleType&>(*this)
00213 .wallImpactDistance(Sf)*Sf;
00214 }
00215 }
00216
00217 scalar lambdaNominator = (Cf - from) & Sf;
00218 scalar lambdaDenominator = (to - from) & Sf;
00219
00220
00221 if (mag(lambdaDenominator) < SMALL)
00222 {
00223 if (lambdaDenominator < 0.0)
00224 {
00225 lambdaDenominator = -SMALL;
00226 }
00227 else
00228 {
00229 lambdaDenominator = SMALL;
00230 }
00231 }
00232
00233 return lambdaNominator/lambdaDenominator;
00234 }
00235
00236
00237 template<class particleType>
00238 inline bool particle<particleType>::inCell()
00239 {
00240 labelList faces = findFaces(position_);
00241
00242 return (!faces.size());
00243 }
00244
00245
00246 template<class particleType>
00247 inline bool particle<particleType>::inCell
00248 (
00249 const vector& position,
00250 const label celli,
00251 const scalar stepFraction
00252 )
00253 {
00254 labelList faces = findFaces(position, celli, stepFraction);
00255
00256 return (!faces.size());
00257 }
00258
00259
00260
00261
00262
00263 template<class particleType>
00264 inline const Cloud<particleType>& particle<particleType>::cloud() const
00265 {
00266 return cloud_;
00267 }
00268
00269
00270 template<class particleType>
00271 inline const vector& particle<particleType>::position() const
00272 {
00273 return position_;
00274 }
00275
00276
00277 template<class particleType>
00278 inline label particle<particleType>::cell() const
00279 {
00280 return celli_;
00281 }
00282
00283
00284 template<class particleType>
00285 inline label particle<particleType>::face() const
00286 {
00287 return facei_;
00288 }
00289
00290
00291
00292 template<class particleType>
00293 inline bool particle<particleType>::onBoundary() const
00294 {
00295 return facei_ != -1 && facei_ >= cloud_.pMesh().nInternalFaces();
00296 }
00297
00298
00299 template<class particleType>
00300 inline scalar& particle<particleType>::stepFraction()
00301 {
00302 return stepFraction_;
00303 }
00304
00305
00306 template<class particleType>
00307 inline scalar particle<particleType>::stepFraction() const
00308 {
00309 return stepFraction_;
00310 }
00311
00312
00313 template<class particleType>
00314 inline bool particle<particleType>::softImpact() const
00315 {
00316 return false;
00317 }
00318
00319
00320 template<class particleType>
00321 inline label particle<particleType>::patch(const label facei) const
00322 {
00323 return cloud_.facePatch(facei);
00324 }
00325
00326
00327 template<class particleType>
00328 inline label particle<particleType>::patchFace
00329 (
00330 const label patchi,
00331 const label facei
00332 ) const
00333 {
00334 return cloud_.patchFace(patchi, facei);
00335 }
00336
00337
00338 template<class particleType>
00339 inline scalar particle<particleType>::wallImpactDistance(const vector&) const
00340 {
00341 return 0.0;
00342 }
00343
00344
00345
00346
00347 }
00348
00349
Copyright © 2000-2007 OpenCFD Ltd