diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C index 8503b83ef70ebcf607b05eef9540fa764e559e52..8c041f374fedc4576f5a77dfbfc1f90dd99eadc5 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,10 +25,10 @@ License #include "pressureInletOutletVelocityFvPatchVectorField.H" #include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" #include "volFields.H" #include "surfaceFields.H" - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::pressureInletOutletVelocityFvPatchVectorField:: @@ -38,12 +38,13 @@ pressureInletOutletVelocityFvPatchVectorField const DimensionedField<vector, volMesh>& iF ) : - directionMixedFvPatchVectorField(p, iF), - phiName_("phi") + mixedFvPatchVectorField(p, iF), + phiName_("phi"), + rhoName_("rho") { - refValue() = vector::zero; + refValue() = *this; refGrad() = vector::zero; - valueFraction() = symmTensor::zero; + valueFraction() = 0.0; } @@ -56,8 +57,9 @@ pressureInletOutletVelocityFvPatchVectorField const fvPatchFieldMapper& mapper ) : - directionMixedFvPatchVectorField(ptf, p, iF, mapper), - phiName_(ptf.phiName_) + mixedFvPatchVectorField(ptf, p, iF, mapper), + phiName_(ptf.phiName_), + rhoName_(ptf.rhoName_) { if (ptf.tangentialVelocity_.size()) { @@ -74,8 +76,9 @@ pressureInletOutletVelocityFvPatchVectorField const dictionary& dict ) : - directionMixedFvPatchVectorField(p, iF), - phiName_(dict.lookupOrDefault<word>("phi", "phi")) + mixedFvPatchVectorField(p, iF), + phiName_(dict.lookupOrDefault<word>("phi", "phi")), + rhoName_(dict.lookupOrDefault<word>("rho", "rho")) { fvPatchVectorField::operator=(vectorField("value", dict, p.size())); @@ -92,7 +95,7 @@ pressureInletOutletVelocityFvPatchVectorField } refGrad() = vector::zero; - valueFraction() = symmTensor::zero; + valueFraction() = 0.0; } @@ -102,8 +105,9 @@ pressureInletOutletVelocityFvPatchVectorField const pressureInletOutletVelocityFvPatchVectorField& pivpvf ) : - directionMixedFvPatchVectorField(pivpvf), + mixedFvPatchVectorField(pivpvf), phiName_(pivpvf.phiName_), + rhoName_(pivpvf.rhoName_), tangentialVelocity_(pivpvf.tangentialVelocity_) {} @@ -115,8 +119,9 @@ pressureInletOutletVelocityFvPatchVectorField const DimensionedField<vector, volMesh>& iF ) : - directionMixedFvPatchVectorField(pivpvf, iF), + mixedFvPatchVectorField(pivpvf, iF), phiName_(pivpvf.phiName_), + rhoName_(pivpvf.rhoName_), tangentialVelocity_(pivpvf.tangentialVelocity_) {} @@ -127,8 +132,8 @@ void Foam::pressureInletOutletVelocityFvPatchVectorField:: setTangentialVelocity(const vectorField& tangentialVelocity) { tangentialVelocity_ = tangentialVelocity; - const vectorField n(patch().nf()); - refValue() = tangentialVelocity_ - n*(n & tangentialVelocity_); + vectorField n(patch().nf()); + tangentialVelocity_ -= n*(n & tangentialVelocity_); } @@ -137,7 +142,7 @@ void Foam::pressureInletOutletVelocityFvPatchVectorField::autoMap const fvPatchFieldMapper& m ) { - directionMixedFvPatchVectorField::autoMap(m); + mixedFvPatchVectorField::autoMap(m); if (tangentialVelocity_.size()) { tangentialVelocity_.autoMap(m); @@ -151,7 +156,7 @@ void Foam::pressureInletOutletVelocityFvPatchVectorField::rmap const labelList& addr ) { - directionMixedFvPatchVectorField::rmap(ptf, addr); + mixedFvPatchVectorField::rmap(ptf, addr); if (tangentialVelocity_.size()) { @@ -170,24 +175,66 @@ void Foam::pressureInletOutletVelocityFvPatchVectorField::updateCoeffs() return; } + const surfaceScalarField& phi = + db().lookupObject<surfaceScalarField>(phiName_); + const fvsPatchField<scalar>& phip = - patch().lookupPatchField<surfaceScalarField, scalar>(phiName_); + patch().patchField<surfaceScalarField, scalar>(phi); + + vectorField n(patch().nf()); + const Field<scalar>& magSf = patch().magSf(); + + if (phi.dimensions() == dimVelocity*dimArea) + { + refValue() = n*phip/magSf; + } + else if (phi.dimensions() == dimDensity*dimVelocity*dimArea) + { + const fvPatchField<scalar>& rhop = + patch().lookupPatchField<volScalarField, scalar>(rhoName_); + + refValue() = n*phip/(rhop*magSf); + } + else + { + FatalErrorIn + ( + "pressureInletOutletVelocityFvPatchVectorField::" + "updateCoeffs()" + ) << "dimensions of phi are not correct" << nl + << " on patch " << this->patch().name() + << " of field " << this->dimensionedInternalField().name() + << " in file " << this->dimensionedInternalField().objectPath() + << exit(FatalError); + } - valueFraction() = neg(phip)*(I - sqr(patch().nf())); + if (tangentialVelocity_.size()) + { + // Adjust the tangential velocity to conserve kinetic energy + // of the entrained fluid + // scalarField magSqrUt(magSqr(tangentialVelocity_)); + // scalarField scale + // ( + // max(sqrt((magSqrUt - magSqr(refValue()))/magSqrUt), scalar(0)) + // ); + // refValue() += scale*tangentialVelocity_; + refValue() += tangentialVelocity_; + } - directionMixedFvPatchVectorField::updateCoeffs(); - directionMixedFvPatchVectorField::evaluate(); + valueFraction() = 1.0 - pos(phip); + + mixedFvPatchVectorField::updateCoeffs(); } void Foam::pressureInletOutletVelocityFvPatchVectorField::write ( Ostream& os -) -const +) const { fvPatchVectorField::write(os); writeEntryIfDifferent<word>(os, "phi", "phi", phiName_); + writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_); if (tangentialVelocity_.size()) { tangentialVelocity_.writeEntry("tangentialVelocity", os); @@ -203,9 +250,7 @@ void Foam::pressureInletOutletVelocityFvPatchVectorField::operator= const fvPatchField<vector>& pvf ) { - tmp<vectorField> normalValue = transform(valueFraction(), refValue()); - tmp<vectorField> transformGradValue = transform(I - valueFraction(), pvf); - fvPatchField<vector>::operator=(normalValue + transformGradValue); + fvPatchField<vector>::operator=(pvf); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.H index 49ebb5d77e8ca16dfd2ba119b0b49cd3cf3fb367..d73e21697db65e75b80564de143b0365f96f2215 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,21 +25,21 @@ Class Foam::pressureInletOutletVelocityFvPatchVectorField Group - grpInletletBoundaryConditions grpOutletBoundaryConditions + grpInletBoundaryConditions grpOutletBoundaryConditions Description This velocity inlet/outlet boundary condition is applied to pressure boundaries where the pressure is specified. A zero-gradient condition is applied for outflow (as defined by the flux); for inflow, the velocity is - obtained from the patch-face normal component of the internal-cell value. - - The tangential patch velocity can be optionally specified. + obtained from the patch-face normal component of the internal-cell value and + the tangential patch velocity can be optionally specified. \heading Patch usage \table Property | Description | Required | Default value phi | flux field name | no | phi + rho | density field name | no | rho tangentialVelocity | tangential velocity field | no | \endtable @@ -49,6 +49,7 @@ Description { type pressureInletOutletVelocity; phi phi; + rho rho; tangentialVelocity uniform (0 0 0); value uniform 0; } @@ -69,7 +70,7 @@ SourceFiles #define pressureInletOutletVelocityFvPatchVectorField_H #include "fvPatchFields.H" -#include "directionMixedFvPatchFields.H" +#include "mixedFvPatchFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -77,18 +78,24 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class pressureInletOutletVelocityFvPatchVectorField Declaration + Class pressureInletOutletVelocityFvPatchVectorField Declaration \*---------------------------------------------------------------------------*/ class pressureInletOutletVelocityFvPatchVectorField : - public directionMixedFvPatchVectorField + public mixedFvPatchVectorField { // Private data //- Flux field name word phiName_; + //- Density field name + word rhoName_; + + +protected: + //- Optional tangential velocity component vectorField tangentialVelocity_; @@ -108,22 +115,23 @@ public: const DimensionedField<vector, volMesh>& ); - //- Construct from patch, internal field and dictionary + //- Construct by mapping given + // pressureInletOutletVelocityFvPatchVectorField + // onto a new patch pressureInletOutletVelocityFvPatchVectorField ( + const pressureInletOutletVelocityFvPatchVectorField&, const fvPatch&, const DimensionedField<vector, volMesh>&, - const dictionary& + const fvPatchFieldMapper& ); - //- Construct by mapping given - // pressureInletOutletVelocityFvPatchVectorField onto a new patch + //- Construct from patch, internal field and dictionary pressureInletOutletVelocityFvPatchVectorField ( - const pressureInletOutletVelocityFvPatchVectorField&, const fvPatch&, const DimensionedField<vector, volMesh>&, - const fvPatchFieldMapper& + const dictionary& ); //- Construct as copy @@ -137,7 +145,10 @@ public: { return tmp<fvPatchVectorField> ( - new pressureInletOutletVelocityFvPatchVectorField(*this) + new pressureInletOutletVelocityFvPatchVectorField + ( + *this + ) ); } @@ -156,7 +167,11 @@ public: { return tmp<fvPatchVectorField> ( - new pressureInletOutletVelocityFvPatchVectorField(*this, iF) + new pressureInletOutletVelocityFvPatchVectorField + ( + *this, + iF + ) ); } @@ -177,6 +192,18 @@ public: return phiName_; } + //- Return the name of rho + const word& rhoName() const + { + return rhoName_; + } + + //- Return reference to the name of rho to allow adjustment + word& rhoName() + { + return rhoName_; + } + //- Return the tangential velocity const vectorField& tangentialVelocity() const { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.C index 830a4b128854dbd5ae61db052e1940fcef2412fa..e7044a5909a7d35a3a90ddd6748d865310a93c54 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,13 +37,11 @@ calcTangentialVelocity() vector om = omega_->value(t); vector axisHat = om/mag(om); - const vectorField tangentialVelocity - ( - (-om) ^ (patch().Cf() - axisHat*(axisHat & patch().Cf())) - ); + tangentialVelocity_ = + (-om) ^ (patch().Cf() - axisHat*(axisHat & patch().Cf())); const vectorField n(patch().nf()); - refValue() = tangentialVelocity - n*(n & tangentialVelocity); + tangentialVelocity_ -= n*(n & tangentialVelocity_); } @@ -87,9 +85,7 @@ rotatingPressureInletOutletVelocityFvPatchVectorField : pressureInletOutletVelocityFvPatchVectorField(p, iF, dict), omega_(DataEntry<vector>::New("omega", dict)) -{ - calcTangentialVelocity(); -} +{} Foam::rotatingPressureInletOutletVelocityFvPatchVectorField:: @@ -100,9 +96,7 @@ rotatingPressureInletOutletVelocityFvPatchVectorField : pressureInletOutletVelocityFvPatchVectorField(rppvf), omega_(rppvf.omega_().clone().ptr()) -{ - calcTangentialVelocity(); -} +{} Foam::rotatingPressureInletOutletVelocityFvPatchVectorField:: @@ -114,12 +108,23 @@ rotatingPressureInletOutletVelocityFvPatchVectorField : pressureInletOutletVelocityFvPatchVectorField(rppvf, iF), omega_(rppvf.omega_().clone().ptr()) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::rotatingPressureInletOutletVelocityFvPatchVectorField::updateCoeffs() { + if (updated()) + { + return; + } + calcTangentialVelocity(); -} + pressureInletOutletVelocityFvPatchVectorField::updateCoeffs(); +} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::rotatingPressureInletOutletVelocityFvPatchVectorField::write ( diff --git a/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.H index cc114d7c6b8110adc0eed599ae2abc17bc646b65..b4b7297692b508825728204c1d600a368769d614 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,7 +39,7 @@ Description Property | Description | Required | Default value phi | flux field name | no | phi tangentialVelocity | tangential velocity field | no | - omega | angular velocty of the frame [rad/s] | yes | + omega | angular velocty of the frame [rad/s] | yes | \endtable Example of the boundary condition specification: @@ -49,7 +49,7 @@ Description type rotatingPressureInletOutletVelocity; phi phi; tangentialVelocity uniform (0 0 0); - omega 100; + omega 100; } \endverbatim @@ -177,6 +177,9 @@ public: // Member functions + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + //- Write virtual void write(Ostream&) const; };