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 "supersonicFreestreamFvPatchVectorField.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "fvPatchFieldMapper.H"
00030 #include "volFields.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037
00038
00039 supersonicFreestreamFvPatchVectorField::supersonicFreestreamFvPatchVectorField
00040 (
00041 const fvPatch& p,
00042 const DimensionedField<vector, volMesh>& iF
00043 )
00044 :
00045 mixedFvPatchVectorField(p, iF),
00046 UInf_(vector::zero),
00047 pInf_(0),
00048 TInf_(0),
00049 gamma_(0)
00050 {
00051 refValue() = patchInternalField();
00052 refGrad() = vector::zero;
00053 valueFraction() = 1;
00054 }
00055
00056
00057 supersonicFreestreamFvPatchVectorField::supersonicFreestreamFvPatchVectorField
00058 (
00059 const supersonicFreestreamFvPatchVectorField& ptf,
00060 const fvPatch& p,
00061 const DimensionedField<vector, volMesh>& iF,
00062 const fvPatchFieldMapper& mapper
00063 )
00064 :
00065 mixedFvPatchVectorField(ptf, p, iF, mapper),
00066 UInf_(ptf.UInf_),
00067 pInf_(ptf.pInf_),
00068 TInf_(ptf.TInf_),
00069 gamma_(ptf.gamma_)
00070 {}
00071
00072
00073 supersonicFreestreamFvPatchVectorField::supersonicFreestreamFvPatchVectorField
00074 (
00075 const fvPatch& p,
00076 const DimensionedField<vector, volMesh>& iF,
00077 const dictionary& dict
00078 )
00079 :
00080 mixedFvPatchVectorField(p, iF),
00081 UInf_(dict.lookup("UInf")),
00082 pInf_(readScalar(dict.lookup("pInf"))),
00083 TInf_(readScalar(dict.lookup("TInf"))),
00084 gamma_(readScalar(dict.lookup("gamma")))
00085 {
00086 if (dict.found("value"))
00087 {
00088 fvPatchField<vector>::operator=
00089 (
00090 vectorField("value", dict, p.size())
00091 );
00092 }
00093 else
00094 {
00095 fvPatchField<vector>::operator=(patchInternalField());
00096 }
00097
00098 refValue() = *this;
00099 refGrad() = vector::zero;
00100 valueFraction() = 1;
00101
00102 if (pInf_ < SMALL)
00103 {
00104 FatalIOErrorIn
00105 (
00106 "supersonicFreestreamFvPatchVectorField::"
00107 "supersonicFreestreamFvPatchVectorField"
00108 "(const fvPatch&, const vectorField&, const dictionary&)",
00109 dict
00110 ) << " unphysical pInf specified (pInf <= 0.0)"
00111 << "\n on patch " << this->patch().name()
00112 << " of field " << this->dimensionedInternalField().name()
00113 << " in file " << this->dimensionedInternalField().objectPath()
00114 << exit(FatalIOError);
00115 }
00116 }
00117
00118
00119 supersonicFreestreamFvPatchVectorField::supersonicFreestreamFvPatchVectorField
00120 (
00121 const supersonicFreestreamFvPatchVectorField& sfspvf
00122 )
00123 :
00124 mixedFvPatchVectorField(sfspvf),
00125 UInf_(sfspvf.UInf_),
00126 pInf_(sfspvf.pInf_),
00127 TInf_(sfspvf.TInf_),
00128 gamma_(sfspvf.gamma_)
00129 {}
00130
00131
00132 supersonicFreestreamFvPatchVectorField::supersonicFreestreamFvPatchVectorField
00133 (
00134 const supersonicFreestreamFvPatchVectorField& sfspvf,
00135 const DimensionedField<vector, volMesh>& iF
00136 )
00137 :
00138 mixedFvPatchVectorField(sfspvf, iF),
00139 UInf_(sfspvf.UInf_),
00140 pInf_(sfspvf.pInf_),
00141 TInf_(sfspvf.TInf_),
00142 gamma_(sfspvf.gamma_)
00143 {}
00144
00145
00146
00147
00148 void supersonicFreestreamFvPatchVectorField::updateCoeffs()
00149 {
00150 if (!size() || updated())
00151 {
00152 return;
00153 }
00154
00155 const fvPatchField<scalar>& pT =
00156 patch().lookupPatchField<volScalarField, scalar>("T");
00157
00158 const fvPatchField<scalar>& pp =
00159 patch().lookupPatchField<volScalarField, scalar>("p");
00160
00161 const fvPatchField<scalar>& ppsi =
00162 patch().lookupPatchField<volScalarField, scalar>("psi");
00163
00164
00165
00166 scalar R = 1.0/(ppsi[0]*pT[0]);
00167
00168 scalar MachInf = mag(UInf_)/sqrt(gamma_*R*TInf_);
00169
00170 if (MachInf < 1.0)
00171 {
00172 FatalErrorIn
00173 (
00174 "supersonicFreestreamFvPatchVectorField::updateCoeffs()"
00175 ) << " MachInf < 1.0, free stream must be supersonic"
00176 << "\n on patch " << this->patch().name()
00177 << " of field " << this->dimensionedInternalField().name()
00178 << " in file " << this->dimensionedInternalField().objectPath()
00179 << exit(FatalError);
00180 }
00181
00182 vectorField& Up = refValue();
00183 valueFraction() = 1;
00184
00185
00186 vectorField U = patchInternalField();
00187
00188
00189
00190
00191
00192
00193 vector UInfHat = UInf_/mag(UInf_);
00194
00195
00196 vectorField nnInfHat = UInfHat ^ patch().nf();
00197
00198
00199
00200
00201
00202
00203
00204
00205 vectorField nHatInf = nnInfHat ^ UInfHat;
00206
00207
00208
00209 vectorField Un = nHatInf*(nHatInf & U);
00210
00211
00212 vectorField Ut = U - Un;
00213
00214
00215 scalar nuMachInf =
00216 sqrt((gamma_ + 1)/(gamma_ - 1))
00217 *atan(sqrt((gamma_ - 1)/(gamma_ + 1)*(sqr(MachInf) - 1)))
00218 - atan(sqr(MachInf) - 1);
00219
00220
00221
00222
00223
00224 forAll(Up, facei)
00225 {
00226 if (pp[facei] >= pInf_)
00227 {
00228
00229
00230
00231 scalar fpp =
00232 sqrt(sqr(MachInf) - 1)
00233 /(gamma_*sqr(MachInf))*mag(Ut[facei])*log(pp[facei]/pInf_);
00234
00235 Up[facei] = Ut[facei] + fpp*nHatInf[facei];
00236
00237
00238 scalar Mach = mag(Up[facei])/sqrt(gamma_/ppsi[facei]);
00239
00240 if (Mach <= 1)
00241 {
00242
00243
00244 Up[facei] = U[facei];
00245 valueFraction()[facei] = 0;
00246 }
00247 }
00248 else
00249 {
00250
00251
00252
00253 scalar Mach =
00254 sqrt
00255 (
00256 (2/(gamma_ - 1))*(1 + ((gamma_ - 1)/2)*sqr(MachInf))
00257 *pow(pp[facei]/pInf_, (1 - gamma_)/gamma_)
00258 - 2/(gamma_ - 1)
00259 );
00260
00261 if (Mach > 1)
00262 {
00263
00264
00265
00266 scalar nuMachf =
00267 sqrt((gamma_ + 1)/(gamma_ - 1))
00268 *atan(sqrt((gamma_ - 1)/(gamma_ + 1)*(sqr(Mach) - 1)))
00269 - atan(sqr(Mach) - 1);
00270
00271 scalar fpp = (nuMachInf - nuMachf)*mag(Ut[facei]);
00272
00273 Up[facei] = Ut[facei] + fpp*nHatInf[facei];
00274 }
00275 else
00276 {
00277 FatalErrorIn
00278 (
00279 "supersonicFreestreamFvPatchVectorField::updateCoeffs()"
00280 ) << "unphysical subsonic inflow has been generated"
00281 << "\n on patch " << this->patch().name()
00282 << " of field " << this->dimensionedInternalField().name()
00283 << " in file "
00284 << this->dimensionedInternalField().objectPath()
00285 << exit(FatalError);
00286 }
00287 }
00288 }
00289
00290 mixedFvPatchVectorField::updateCoeffs();
00291 }
00292
00293
00294 void supersonicFreestreamFvPatchVectorField::write(Ostream& os) const
00295 {
00296 fvPatchVectorField::write(os);
00297 os.writeKeyword("UInf") << UInf_ << token::END_STATEMENT << nl;
00298 os.writeKeyword("pInf") << pInf_ << token::END_STATEMENT << nl;
00299 os.writeKeyword("TInf") << TInf_ << token::END_STATEMENT << nl;
00300 os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
00301 writeEntry("value", os);
00302 }
00303
00304
00305
00306
00307 makePatchTypeField
00308 (
00309 fvPatchVectorField,
00310 supersonicFreestreamFvPatchVectorField
00311 );
00312
00313
00314
00315 }
00316
00317