OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

supersonicFreestreamFvPatchVectorField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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     // Need R of the free-stream flow.  Assume R is independent of location
00165     // along patch so use face 0
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     // get the near patch internal cell values
00186     vectorField U = patchInternalField();
00187 
00188 
00189     // Find the component of U normal to the free-stream flow and in the
00190     // plane of the free-stream flow and the patch normal
00191 
00192     // Direction of the free-stream flow
00193     vector UInfHat = UInf_/mag(UInf_);
00194 
00195     // Normal to the plane defined by the free-stream and the patch normal
00196     vectorField nnInfHat = UInfHat ^ patch().nf();
00197 
00198     //vectorField UnInf = U - nnInfHat*(nnInfHat & U);
00199     //vectorField Un = UnInf - UInfHat*(UInfHat & UnInf);
00200     //vectorField nHatInf =
00201     //    (Un/(mag(Un) + SMALL)) * sign(patch().nf() & Un);
00202 
00203     // Normal to the free-stream in the plane defined by the free-stream
00204     // and the patch normal
00205     vectorField nHatInf = nnInfHat ^ UInfHat;
00206 
00207     // Component of U normal to the free-stream in the plane defined by the
00208     // free-stream and the patch normal
00209     vectorField Un = nHatInf*(nHatInf & U);
00210 
00211     // The tangential component is
00212     vectorField Ut = U - Un;
00213 
00214     // Calculate the Prandtl-Meyer function of the free-stream
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     // Set the patch boundary condition based on the Mach number and direction
00222     // of the flow dictated by the boundary/free-stream pressure difference
00223 
00224     forAll(Up, facei)
00225     {
00226         if (pp[facei] >= pInf_) // If outflow
00227         {
00228             // Assume supersonic outflow and calculate the boundary velocity
00229             // according to ???
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             // Calculate the Mach number of the boundary velocity
00238             scalar Mach = mag(Up[facei])/sqrt(gamma_/ppsi[facei]);
00239 
00240             if (Mach <= 1) // If subsonic
00241             {
00242                 // Zero-gradient subsonic outflow
00243 
00244                 Up[facei] = U[facei];
00245                 valueFraction()[facei] = 0;
00246             }
00247         }
00248         else // if inflow
00249         {
00250             // Calculate the Mach number of the boundary velocity
00251             // from the boundary pressure assuming constant total pressure
00252             // expansion from the free-stream
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) // If supersonic
00262             {
00263                 // Supersonic inflow is assumed to occur according to the
00264                 // Prandtl-Meyer expansion process
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 // If subsonic
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 } // End namespace Foam
00316 
00317 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd