freestreamPressure, freestreamVelocity: New blended boundary conditions for the freestream

These BCs blend between typical inflow and outflow conditions based on the
velocity orientation.

airFoil2D tutorial updated to demonstrate these new BCs.
This commit is contained in:
Henry Weller
2018-02-23 12:23:06 +00:00
parent c7a5f740d8
commit fb15be492c
10 changed files with 388 additions and 83 deletions

View File

@ -151,6 +151,7 @@ $(derivedFvPatchFields)/flowRateInletVelocity/flowRateInletVelocityFvPatchVector
$(derivedFvPatchFields)/flowRateOutletVelocity/flowRateOutletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/flowRateOutletVelocity/flowRateOutletVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/fluxCorrectedVelocity/fluxCorrectedVelocityFvPatchVectorField.C $(derivedFvPatchFields)/fluxCorrectedVelocity/fluxCorrectedVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/freestream/freestreamFvPatchFields.C $(derivedFvPatchFields)/freestream/freestreamFvPatchFields.C
$(derivedFvPatchFields)/freestreamVelocity/freestreamVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/freestreamPressure/freestreamPressureFvPatchScalarField.C $(derivedFvPatchFields)/freestreamPressure/freestreamPressureFvPatchScalarField.C
$(derivedFvPatchFields)/inletOutlet/inletOutletFvPatchFields.C $(derivedFvPatchFields)/inletOutlet/inletOutletFvPatchFields.C
$(derivedFvPatchFields)/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C $(derivedFvPatchFields)/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -45,7 +45,7 @@ Usage
<patchName> <patchName>
{ {
type freestream; type freestream;
phi phi; freestreamValue uniform (300 0 0);
} }
\endverbatim \endverbatim

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,10 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "freestreamPressureFvPatchScalarField.H" #include "freestreamPressureFvPatchScalarField.H"
#include "freestreamFvPatchFields.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -39,10 +36,8 @@ freestreamPressureFvPatchScalarField
const DimensionedField<scalar, volMesh>& iF const DimensionedField<scalar, volMesh>& iF
) )
: :
zeroGradientFvPatchScalarField(p, iF), mixedFvPatchScalarField(p, iF),
UName_("U"), UName_("U")
phiName_("phi"),
rhoName_("rho")
{} {}
@ -54,11 +49,26 @@ freestreamPressureFvPatchScalarField
const dictionary& dict const dictionary& dict
) )
: :
zeroGradientFvPatchScalarField(p, iF, dict), mixedFvPatchScalarField(p, iF),
UName_(dict.lookupOrDefault<word>("U", "U")), UName_(dict.lookupOrDefault<word>("U", "U"))
phiName_(dict.lookupOrDefault<word>("phi", "phi")), {
rhoName_(dict.lookupOrDefault<word>("rho", "rho")) freestreamValue() = scalarField("freestreamValue", dict, p.size());
{}
if (dict.found("value"))
{
fvPatchScalarField::operator=
(
scalarField("value", dict, p.size())
);
}
else
{
fvPatchScalarField::operator=(freestreamValue());
}
refGrad() = Zero;
valueFraction() = 0;
}
Foam::freestreamPressureFvPatchScalarField:: Foam::freestreamPressureFvPatchScalarField::
@ -70,10 +80,8 @@ freestreamPressureFvPatchScalarField
const fvPatchFieldMapper& mapper const fvPatchFieldMapper& mapper
) )
: :
zeroGradientFvPatchScalarField(ptf, p, iF, mapper), mixedFvPatchScalarField(ptf, p, iF, mapper),
UName_(ptf.UName_), UName_(ptf.UName_)
phiName_(ptf.phiName_),
rhoName_(ptf.rhoName_)
{} {}
@ -83,10 +91,8 @@ freestreamPressureFvPatchScalarField
const freestreamPressureFvPatchScalarField& wbppsf const freestreamPressureFvPatchScalarField& wbppsf
) )
: :
zeroGradientFvPatchScalarField(wbppsf), mixedFvPatchScalarField(wbppsf),
UName_(wbppsf.UName_), UName_(wbppsf.UName_)
phiName_(wbppsf.phiName_),
rhoName_(wbppsf.rhoName_)
{} {}
@ -97,10 +103,8 @@ freestreamPressureFvPatchScalarField
const DimensionedField<scalar, volMesh>& iF const DimensionedField<scalar, volMesh>& iF
) )
: :
zeroGradientFvPatchScalarField(wbppsf, iF), mixedFvPatchScalarField(wbppsf, iF),
UName_(wbppsf.UName_), UName_(wbppsf.UName_)
phiName_(wbppsf.phiName_),
rhoName_(wbppsf.rhoName_)
{} {}
@ -113,40 +117,15 @@ void Foam::freestreamPressureFvPatchScalarField::updateCoeffs()
return; return;
} }
const freestreamFvPatchVectorField& Up = const Field<vector>& Up =
refCast<const freestreamFvPatchVectorField> patch().template lookupPatchField<volVectorField, vector>
( (
patch().lookupPatchField<volVectorField, vector>(UName_) UName_
); );
surfaceScalarField& phi = valueFraction() = 0.5 + 0.5*(Up & patch().nf())/mag(Up);
db().lookupObjectRef<surfaceScalarField>(phiName_);
fvsPatchField<scalar>& phip = mixedFvPatchField<scalar>::updateCoeffs();
patch().patchField<surfaceScalarField, scalar>(phi);
if (phi.dimensions() == dimVelocity*dimArea)
{
phip = patch().Sf() & Up.freestreamValue();
}
else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
{
const fvPatchField<scalar>& rhop =
patch().lookupPatchField<volScalarField, scalar>(rhoName_);
phip = rhop*(patch().Sf() & Up.freestreamValue());
}
else
{
FatalErrorInFunction
<< "dimensions of phi are not correct"
<< "\n on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< exit(FatalError);
}
zeroGradientFvPatchScalarField::updateCoeffs();
} }
@ -154,8 +133,7 @@ void Foam::freestreamPressureFvPatchScalarField::write(Ostream& os) const
{ {
fvPatchScalarField::write(os); fvPatchScalarField::write(os);
writeEntryIfDifferent<word>(os, "U", "U", UName_); writeEntryIfDifferent<word>(os, "U", "U", UName_);
writeEntryIfDifferent<word>(os, "phi", "phi", phiName_); freestreamValue().writeEntry("freestreamValue", os);
writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
writeEntry("value", os); writeEntry("value", os);
} }

View File

@ -29,15 +29,16 @@ Group
Description Description
This boundary condition provides a free-stream condition for pressure. This boundary condition provides a free-stream condition for pressure.
It is a zero-gradient condition that constrains the flux across the patch
based on the free-stream velocity. It is an outlet-inlet condition that uses the velocity orientation to
continuously blend between zero gradient for normal inlet and fixed value
for normal outlet flow.
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default value
U | velocity field name | no | U U | velocity field name | no | U
phi | flux field name | no | phi freestreamValue | freestream pressure | yes |
rho | density field name | no | none
\endtable \endtable
Example of the boundary condition specification: Example of the boundary condition specification:
@ -45,14 +46,15 @@ Usage
<patchName> <patchName>
{ {
type freestreamPressure; type freestreamPressure;
freestreamValue uniform 1e5;
} }
\endverbatim \endverbatim
Note Note
This condition is designed to operate with a freestream velocity condition This condition is designed to operate with a freestreamVelocity condition
See also See also
Foam::zeroGradientFvPatchField Foam::mixedFvPatchField
Foam::freestreamFvPatchField Foam::freestreamFvPatchField
SourceFiles SourceFiles
@ -64,7 +66,7 @@ SourceFiles
#define freestreamPressureFvPatchScalarField_H #define freestreamPressureFvPatchScalarField_H
#include "fvPatchFields.H" #include "fvPatchFields.H"
#include "zeroGradientFvPatchFields.H" #include "mixedFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -77,20 +79,13 @@ namespace Foam
class freestreamPressureFvPatchScalarField class freestreamPressureFvPatchScalarField
: :
public zeroGradientFvPatchScalarField public mixedFvPatchScalarField
{ {
// Private data // Private data
//- Name of the velocity field //- Name of the velocity field
word UName_; word UName_;
//- Name of the flux transporting the field
word phiName_;
//- Name of the density field used to normalise the mass flux
// if necessary
word rhoName_;
public: public:
@ -162,6 +157,17 @@ public:
// Member functions // Member functions
const scalarField& freestreamValue() const
{
return refValue();
}
scalarField& freestreamValue()
{
return refValue();
}
// Evaluation functions // Evaluation functions
//- Update the coefficients associated with the patch field //- Update the coefficients associated with the patch field

View File

@ -0,0 +1,136 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "freestreamVelocityFvPatchVectorField.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::freestreamVelocityFvPatchVectorField::freestreamVelocityFvPatchVectorField
(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF
)
:
mixedFvPatchVectorField(p, iF)
{}
Foam::freestreamVelocityFvPatchVectorField::freestreamVelocityFvPatchVectorField
(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const dictionary& dict
)
:
mixedFvPatchVectorField(p, iF)
{
freestreamValue() = vectorField("freestreamValue", dict, p.size());
if (dict.found("value"))
{
fvPatchVectorField::operator=
(
vectorField("value", dict, p.size())
);
}
else
{
fvPatchVectorField::operator=(freestreamValue());
}
refGrad() = Zero;
valueFraction() = 1;
}
Foam::freestreamVelocityFvPatchVectorField::freestreamVelocityFvPatchVectorField
(
const freestreamVelocityFvPatchVectorField& ptf,
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
mixedFvPatchVectorField(ptf, p, iF, mapper)
{}
Foam::freestreamVelocityFvPatchVectorField::freestreamVelocityFvPatchVectorField
(
const freestreamVelocityFvPatchVectorField& wbppsf
)
:
mixedFvPatchVectorField(wbppsf)
{}
Foam::freestreamVelocityFvPatchVectorField::freestreamVelocityFvPatchVectorField
(
const freestreamVelocityFvPatchVectorField& wbppsf,
const DimensionedField<vector, volMesh>& iF
)
:
mixedFvPatchVectorField(wbppsf, iF)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::freestreamVelocityFvPatchVectorField::updateCoeffs()
{
if (updated())
{
return;
}
const Field<vector>& Up = *this;
valueFraction() = 0.5 - 0.5*(Up & patch().nf())/mag(Up);
mixedFvPatchField<vector>::updateCoeffs();
}
void Foam::freestreamVelocityFvPatchVectorField::write(Ostream& os) const
{
fvPatchVectorField::write(os);
freestreamValue().writeEntry("freestreamValue", os);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchVectorField,
freestreamVelocityFvPatchVectorField
);
}
// ************************************************************************* //

View File

@ -0,0 +1,184 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::freestreamVelocityFvPatchVectorField
Group
grpInletBoundaryConditions grpOutletBoundaryConditions
Description
This boundary condition provides a free-stream condition for velocity.
It is an inlet-outlet condition that uses the velocity orientation to
continuously blend between fixed value for normal inlet and zero gradient
for normal outlet flow.
Usage
\table
Property | Description | Required | Default value
freestreamValue | freestream velocity | yes |
\endtable
Example of the boundary condition specification:
\verbatim
<patchName>
{
type freestreamVelocity;
freestreamValue uniform (300 0 0);
}
\endverbatim
Note
This condition is designed to operate with the freestreamPressure condition
See also
Foam::mixedFvPatchField
Foam::freestreamFvPatchField
SourceFiles
freestreamVelocityFvPatchVectorField.C
\*---------------------------------------------------------------------------*/
#ifndef freestreamVelocityFvPatchVectorField_H
#define freestreamVelocityFvPatchVectorField_H
#include "fvPatchFields.H"
#include "mixedFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class freestreamVelocityFvPatchVectorField Declaration
\*---------------------------------------------------------------------------*/
class freestreamVelocityFvPatchVectorField
:
public mixedFvPatchVectorField
{
public:
//- Runtime type information
TypeName("freestreamVelocity");
// Constructors
//- Construct from patch and internal field
freestreamVelocityFvPatchVectorField
(
const fvPatch&,
const DimensionedField<vector, volMesh>&
);
//- Construct from patch, internal field and dictionary
freestreamVelocityFvPatchVectorField
(
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const dictionary&
);
//- Construct by mapping given freestreamVelocityFvPatchVectorField onto
// a new patch
freestreamVelocityFvPatchVectorField
(
const freestreamVelocityFvPatchVectorField&,
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
freestreamVelocityFvPatchVectorField
(
const freestreamVelocityFvPatchVectorField&
);
//- Construct and return a clone
virtual tmp<fvPatchVectorField> clone() const
{
return tmp<fvPatchVectorField>
(
new freestreamVelocityFvPatchVectorField(*this)
);
}
//- Construct as copy setting internal field reference
freestreamVelocityFvPatchVectorField
(
const freestreamVelocityFvPatchVectorField&,
const DimensionedField<vector, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchVectorField> clone
(
const DimensionedField<vector, volMesh>& iF
) const
{
return tmp<fvPatchVectorField>
(
new freestreamVelocityFvPatchVectorField(*this, iF)
);
}
// Member functions
const vectorField& freestreamValue() const
{
return refValue();
}
vectorField& freestreamValue()
{
return refValue();
}
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -22,14 +22,14 @@ boundaryField
{ {
inlet inlet
{ {
type freestream; type freestreamVelocity;
freestreamValue uniform (25.75 3.62 0); freestreamValue $internalField;
} }
outlet outlet
{ {
type freestream; type freestreamVelocity;
freestreamValue uniform (25.75 3.62 0); freestreamValue $internalField;
} }
walls walls

View File

@ -23,11 +23,13 @@ boundaryField
inlet inlet
{ {
type freestreamPressure; type freestreamPressure;
freestreamValue $internalField;
} }
outlet outlet
{ {
type freestreamPressure; type freestreamPressure;
freestreamValue $internalField;
} }
walls walls

View File

@ -17,7 +17,7 @@ FoamFile
application simpleFoam; application simpleFoam;
startFrom latestTime; startFrom startTime;
startTime 0; startTime 0;

View File

@ -47,8 +47,6 @@ solvers
SIMPLE SIMPLE
{ {
nNonOrthogonalCorrectors 0; nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
residualControl residualControl
{ {