FreeStream.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 "FreeStream.H"
00028
00029
00030
00031 template <class CloudType>
00032 Foam::FreeStream<CloudType>::FreeStream
00033 (
00034 const dictionary& dict,
00035 CloudType& cloud
00036 )
00037 :
00038 InflowBoundaryModel<CloudType>(dict, cloud, typeName),
00039 patches_(),
00040 moleculeTypeIds_(),
00041 numberDensities_(),
00042 particleFluxAccumulators_()
00043 {
00044
00045
00046 DynamicList<label> patches;
00047
00048 forAll(cloud.mesh().boundaryMesh(), p)
00049 {
00050 const polyPatch& patch = cloud.mesh().boundaryMesh()[p];
00051
00052 if (patch.type() == polyPatch::typeName)
00053 {
00054 patches.append(p);
00055 }
00056 }
00057
00058 patches_.transfer(patches);
00059
00060 const dictionary& numberDensitiesDict
00061 (
00062 this->coeffDict().subDict("numberDensities")
00063 );
00064
00065 List<word> molecules(numberDensitiesDict.toc());
00066
00067
00068 particleFluxAccumulators_.setSize(patches_.size());
00069
00070 forAll(patches_, p)
00071 {
00072 const polyPatch& patch = cloud.mesh().boundaryMesh()[patches_[p]];
00073
00074 particleFluxAccumulators_[p] = List<Field<scalar> >
00075 (
00076 molecules.size(),
00077 Field<scalar>(patch.size(), 0.0)
00078 );
00079 }
00080
00081 moleculeTypeIds_.setSize(molecules.size());
00082
00083 numberDensities_.setSize(molecules.size());
00084
00085 forAll(molecules, i)
00086 {
00087 numberDensities_[i] = readScalar
00088 (
00089 numberDensitiesDict.lookup(molecules[i])
00090 );
00091
00092 moleculeTypeIds_[i] = findIndex(cloud.typeIdList(), molecules[i]);
00093
00094 if (moleculeTypeIds_[i] == -1)
00095 {
00096 FatalErrorIn
00097 (
00098 "Foam::FreeStream<CloudType>::FreeStream"
00099 "("
00100 "const dictionary&, "
00101 "CloudType&"
00102 ")"
00103 ) << "typeId " << molecules[i] << "not defined in cloud." << nl
00104 << abort(FatalError);
00105 }
00106 }
00107
00108 numberDensities_ /= cloud.nParticle();
00109 }
00110
00111
00112
00113
00114
00115 template <class CloudType>
00116 Foam::FreeStream<CloudType>::~FreeStream()
00117 {}
00118
00119
00120
00121
00122 template <class CloudType>
00123 void Foam::FreeStream<CloudType>::inflow()
00124 {
00125 CloudType& cloud(this->owner());
00126
00127 const polyMesh& mesh(cloud.mesh());
00128
00129 const scalar deltaT = cloud.cachedDeltaT();
00130
00131 Random& rndGen(cloud.rndGen());
00132
00133 scalar sqrtPi = sqrt(mathematicalConstant::pi);
00134
00135 label particlesInserted = 0;
00136
00137 const volScalarField::GeometricBoundaryField& boundaryT
00138 (
00139 cloud.T().boundaryField()
00140 );
00141
00142 const volVectorField::GeometricBoundaryField& boundaryU
00143 (
00144 cloud.U().boundaryField()
00145 );
00146
00147 forAll(patches_, p)
00148 {
00149 label patchI = patches_[p];
00150
00151 const polyPatch& patch = mesh.boundaryMesh()[patchI];
00152
00153
00154
00155
00156
00157 List<Field<scalar> >& pFA = particleFluxAccumulators_[p];
00158
00159 forAll(pFA, i)
00160 {
00161 label typeId = moleculeTypeIds_[i];
00162
00163 scalar mass = cloud.constProps(typeId).mass();
00164
00165 if (min(boundaryT[patchI]) < SMALL)
00166 {
00167 FatalErrorIn ("Foam::FreeStream<CloudType>::inflow()")
00168 << "Zero boundary temperature detected, check boundaryT condition." << nl
00169 << nl << abort(FatalError);
00170 }
00171
00172 scalarField mostProbableSpeed
00173 (
00174 cloud.maxwellianMostProbableSpeed
00175 (
00176 boundaryT[patchI],
00177 mass
00178 )
00179 );
00180
00181
00182
00183
00184
00185 scalarField sCosTheta =
00186 boundaryU[patchI]
00187 & -patch.faceAreas()/mag(patch.faceAreas())
00188 /mostProbableSpeed;
00189
00190
00191
00192 pFA[i] +=
00193 mag(patch.faceAreas())*numberDensities_[i]*deltaT
00194 *mostProbableSpeed
00195 *(
00196 exp(-sqr(sCosTheta)) + sqrtPi*sCosTheta*(1 + erf(sCosTheta))
00197 )
00198 /(2.0*sqrtPi);
00199 }
00200
00201 forAll(patch, f)
00202 {
00203
00204
00205
00206 labelList faceVertices = patch[f];
00207
00208 label nVertices = faceVertices.size();
00209
00210 label globalFaceIndex = f + patch.start();
00211
00212 label cell = mesh.faceOwner()[globalFaceIndex];
00213
00214 const vector& fC = patch.faceCentres()[f];
00215
00216 scalar fA = mag(patch.faceAreas()[f]);
00217
00218
00219 List<scalar> cTriAFracs(nVertices);
00220
00221 for (label v = 0; v < nVertices - 1; v++)
00222 {
00223 const point& vA = mesh.points()[faceVertices[v]];
00224
00225 const point& vB = mesh.points()[faceVertices[(v + 1)]];
00226
00227 cTriAFracs[v] =
00228 0.5*mag((vA - fC)^(vB - fC))/fA
00229 + cTriAFracs[max((v - 1), 0)];
00230 }
00231
00232
00233
00234 cTriAFracs[nVertices - 1] = 1.0;
00235
00236
00237
00238 vector n = patch.faceAreas()[f];
00239 n /= -mag(n);
00240
00241
00242
00243 vector t1 = fC - (mesh.points()[faceVertices[0]]);
00244 t1 /= mag(t1);
00245
00246
00247
00248 vector t2 = n^t1;
00249 t2 /= mag(t2);
00250
00251 scalar faceTemperature = boundaryT[patchI][f];
00252
00253 const vector& faceVelocity = boundaryU[patchI][f];
00254
00255 forAll(pFA, i)
00256 {
00257 scalar& faceAccumulator = pFA[i][f];
00258
00259
00260 label nI = max(label(faceAccumulator), 0);
00261
00262
00263
00264 if ((faceAccumulator - nI) > rndGen.scalar01())
00265 {
00266 nI++;
00267 }
00268
00269 faceAccumulator -= nI;
00270
00271 label typeId = moleculeTypeIds_[i];
00272
00273 scalar mass = cloud.constProps(typeId).mass();
00274
00275 for (label i = 0; i < nI; i++)
00276 {
00277
00278
00279
00280 scalar triSelection = rndGen.scalar01();
00281
00282
00283 label sTri = -1;
00284
00285 forAll(cTriAFracs, tri)
00286 {
00287 sTri = tri;
00288
00289 if (cTriAFracs[tri] >= triSelection)
00290 {
00291 break;
00292 }
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302 const point& A = fC;
00303 const point& B = mesh.points()[faceVertices[sTri]];
00304 const point& C =
00305 mesh.points()[faceVertices[(sTri + 1) % nVertices]];
00306
00307 scalar s = rndGen.scalar01();
00308 scalar t = sqrt(rndGen.scalar01());
00309
00310 point p = (1 - t)*A + (1 - s)*t*B + s*t*C;
00311
00312
00313
00314 scalar mostProbableSpeed
00315 (
00316 cloud.maxwellianMostProbableSpeed
00317 (
00318 faceTemperature,
00319 mass
00320 )
00321 );
00322
00323 scalar sCosTheta = (faceVelocity & n)/mostProbableSpeed;
00324
00325
00326 scalar uNormProbCoeffA =
00327 sCosTheta + sqrt(sqr(sCosTheta) + 2.0);
00328
00329 scalar uNormProbCoeffB =
00330 0.5*
00331 (
00332 1.0
00333 + sCosTheta*(sCosTheta - sqrt(sqr(sCosTheta) + 2.0))
00334 );
00335
00336
00337 scalar randomScaling = 3.0;
00338
00339 if (sCosTheta < -3)
00340 {
00341 randomScaling = mag(sCosTheta) + 1;
00342 }
00343
00344 scalar P = -1;
00345
00346
00347
00348 scalar uNormal;
00349 scalar uNormalThermal;
00350
00351
00352 do
00353 {
00354 uNormalThermal =
00355 randomScaling*(2.0*rndGen.scalar01() - 1);
00356
00357 uNormal = uNormalThermal + sCosTheta;
00358
00359 if (uNormal < 0.0)
00360 {
00361 P = -1;
00362 }
00363 else
00364 {
00365 P = 2.0*uNormal/uNormProbCoeffA
00366 *exp(uNormProbCoeffB - sqr(uNormalThermal));
00367 }
00368
00369 } while (P < rndGen.scalar01());
00370
00371 vector U =
00372 sqrt(CloudType::kb*faceTemperature/mass)
00373 *(
00374 rndGen.GaussNormal()*t1
00375 + rndGen.GaussNormal()*t2
00376 )
00377 + (t1 & faceVelocity)*t1
00378 + (t2 & faceVelocity)*t2
00379 + mostProbableSpeed*uNormal*n;
00380
00381 scalar Ei = cloud.equipartitionInternalEnergy
00382 (
00383 faceTemperature,
00384 cloud.constProps(typeId).internalDegreesOfFreedom()
00385 );
00386
00387 cloud.addNewParcel
00388 (
00389 p,
00390 U,
00391 Ei,
00392 cell,
00393 typeId
00394 );
00395
00396 particlesInserted++;
00397 }
00398 }
00399 }
00400 }
00401
00402 reduce(particlesInserted, sumOp<label>());
00403
00404 Info<< " Particles inserted = "
00405 << particlesInserted << endl;
00406
00407 }
00408
00409
00410
Copyright © 2000-2009 OpenCFD Ltd