From 301e50dfd5d2ee89e826cca7c0e5af3621be5a4c Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 17 Nov 2011 18:13:16 +0000 Subject: [PATCH] ENH: Added variant of pressureInletOutlet BC with slip condition enforced on parallel motion --- ...tOutletParSlipVelocityFvPatchVectorField.C | 204 ++++++++++++++++++ ...tOutletParSlipVelocityFvPatchVectorField.H | 191 ++++++++++++++++ 2 files changed, 395 insertions(+) create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.H diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.C new file mode 100644 index 0000000000..f8002accff --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.C @@ -0,0 +1,204 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 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 . + +\*---------------------------------------------------------------------------*/ + +#include "pressureInletOutletParSlipVelocityFvPatchVectorField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" +#include "surfaceFields.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pressureInletOutletParSlipVelocityFvPatchVectorField:: +pressureInletOutletParSlipVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF +) +: + mixedFvPatchVectorField(p, iF), + phiName_("phi"), + rhoName_("rho") +{ + refValue() = *this; + refGrad() = vector::zero; + valueFraction() = 0.0; +} + + +Foam::pressureInletOutletParSlipVelocityFvPatchVectorField:: +pressureInletOutletParSlipVelocityFvPatchVectorField +( + const pressureInletOutletParSlipVelocityFvPatchVectorField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + mixedFvPatchVectorField(ptf, p, iF, mapper), + phiName_(ptf.phiName_), + rhoName_(ptf.rhoName_) +{} + + +Foam::pressureInletOutletParSlipVelocityFvPatchVectorField:: +pressureInletOutletParSlipVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + mixedFvPatchVectorField(p, iF), + phiName_(dict.lookupOrDefault("phi", "phi")), + rhoName_(dict.lookupOrDefault("rho", "rho")) +{ + fvPatchVectorField::operator=(vectorField("value", dict, p.size())); + refValue() = *this; + refGrad() = vector::zero; + valueFraction() = 0.0; +} + + +Foam::pressureInletOutletParSlipVelocityFvPatchVectorField:: +pressureInletOutletParSlipVelocityFvPatchVectorField +( + const pressureInletOutletParSlipVelocityFvPatchVectorField& pivpvf +) +: + mixedFvPatchVectorField(pivpvf), + phiName_(pivpvf.phiName_), + rhoName_(pivpvf.rhoName_) +{} + + +Foam::pressureInletOutletParSlipVelocityFvPatchVectorField:: +pressureInletOutletParSlipVelocityFvPatchVectorField +( + const pressureInletOutletParSlipVelocityFvPatchVectorField& pivpvf, + const DimensionedField& iF +) +: + mixedFvPatchVectorField(pivpvf, iF), + phiName_(pivpvf.phiName_), + rhoName_(pivpvf.rhoName_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::pressureInletOutletParSlipVelocityFvPatchVectorField::updateCoeffs() +{ + if (updated()) + { + return; + } + + const label patchI = patch().index(); + + const surfaceScalarField& phi = + db().lookupObject(phiName_); + + const fvsPatchField& phip = + patch().patchField(phi); + + tmp n = patch().nf(); + const Field& magS = patch().magSf(); + + const volVectorField& U = db().lookupObject("U"); + + vectorField Uc = U.boundaryField()[patchI].patchInternalField(); + Uc -= n()*(Uc & n()); + + if (phi.dimensions() == dimVelocity*dimArea) + { + refValue() = Uc + n*phip/magS; + } + else if (phi.dimensions() == dimDensity*dimVelocity*dimArea) + { + const fvPatchField& rhop = + patch().lookupPatchField(rhoName_); + + refValue() = Uc + n*phip/(rhop*magS); + } + else + { + FatalErrorIn + ( + "pressureInletOutletParSlipVelocityFvPatchVectorField::" + "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() = 1.0 - pos(phip); + + mixedFvPatchVectorField::updateCoeffs(); +} + + +void Foam::pressureInletOutletParSlipVelocityFvPatchVectorField::write +( + Ostream& os +) const +{ + fvPatchVectorField::write(os); + os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; + os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl; + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +void Foam::pressureInletOutletParSlipVelocityFvPatchVectorField::operator= +( + const fvPatchField& pvf +) +{ + fvPatchField::operator= + ( + valueFraction()*(patch().nf()*(patch().nf() & pvf)) + + (1 - valueFraction())*pvf + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchVectorField, + pressureInletOutletParSlipVelocityFvPatchVectorField + ); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.H new file mode 100644 index 0000000000..afab477fbc --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletParSlipVelocity/pressureInletOutletParSlipVelocityFvPatchVectorField.H @@ -0,0 +1,191 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 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 . + +Class + Foam::pressureInletOutletParSlipVelocityFvPatchVectorField + +Description + Velocity inlet/outlet boundary condition for pressure boundary where the + pressure is specified. zero-gradient is applied for outflow (as defined + by the flux) and for inflow the velocity is obtained from the flux with + the specified `inletDirection'. + + Slip condition applied tangential to the patch. + +SourceFiles + pressureInletOutletParSlipVelocityFvPatchVectorField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef pressureInletOutletParSlipVelocityFvPatchVectorField_H +#define pressureInletOutletParSlipVelocityFvPatchVectorField_H + +#include "fvPatchFields.H" +#include "mixedFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class pressureInletOutletParSlipVelocityFvPatchVectorField Declaration +\*---------------------------------------------------------------------------*/ + +class pressureInletOutletParSlipVelocityFvPatchVectorField +: + public mixedFvPatchVectorField +{ + // Private data + + word phiName_; + word rhoName_; + + +public: + + //- Runtime type information + TypeName("pressureInletOutletParSlipVelocity"); + + + // Constructors + + //- Construct from patch and internal field + pressureInletOutletParSlipVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct by mapping given + // pressureInletOutletParSlipVelocityFvPatchVectorField + // onto a new patch + pressureInletOutletParSlipVelocityFvPatchVectorField + ( + const pressureInletOutletParSlipVelocityFvPatchVectorField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct from patch, internal field and dictionary + pressureInletOutletParSlipVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct as copy + pressureInletOutletParSlipVelocityFvPatchVectorField + ( + const pressureInletOutletParSlipVelocityFvPatchVectorField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new pressureInletOutletParSlipVelocityFvPatchVectorField + ( + *this + ) + ); + } + + //- Construct as copy setting internal field reference + pressureInletOutletParSlipVelocityFvPatchVectorField + ( + const pressureInletOutletParSlipVelocityFvPatchVectorField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new pressureInletOutletParSlipVelocityFvPatchVectorField + ( + *this, + iF + ) + ); + } + + + // Member functions + + // Access + + //- 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 name of phi + const word& phiName() const + { + return phiName_; + } + + //- Return reference to the name of phi to allow adjustment + word& phiName() + { + return phiName_; + } + + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream&) const; + + + // Member operators + + virtual void operator=(const fvPatchField& pvf); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //