diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalInletOutletVelocity/fixedNormalInletOutletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalInletOutletVelocity/fixedNormalInletOutletVelocityFvPatchVectorField.C new file mode 100644 index 0000000000..f45f9893c1 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalInletOutletVelocity/fixedNormalInletOutletVelocityFvPatchVectorField.C @@ -0,0 +1,218 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2014 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 "fixedNormalInletOutletVelocityFvPatchVectorField.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" +#include "surfaceFields.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fixedNormalInletOutletVelocityFvPatchVectorField:: +fixedNormalInletOutletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF +) +: + directionMixedFvPatchVectorField(p, iF), + phiName_("phi"), + fixTangentialInflow_(true), + normalVelocity_ + ( + fvPatchVectorField::New("fixedValue", p, iF) + ) +{ + refValue() = vector::zero; + refGrad() = vector::zero; + valueFraction() = symmTensor::zero; +} + + +Foam::fixedNormalInletOutletVelocityFvPatchVectorField:: +fixedNormalInletOutletVelocityFvPatchVectorField +( + const fixedNormalInletOutletVelocityFvPatchVectorField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + directionMixedFvPatchVectorField(ptf, p, iF, mapper), + phiName_(ptf.phiName_), + fixTangentialInflow_(ptf.fixTangentialInflow_), + normalVelocity_ + ( + fvPatchVectorField::New(ptf.normalVelocity(), p, iF, mapper) + ) +{} + + +Foam::fixedNormalInletOutletVelocityFvPatchVectorField:: +fixedNormalInletOutletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + directionMixedFvPatchVectorField(p, iF), + phiName_(dict.lookupOrDefault("phi", "phi")), + fixTangentialInflow_(dict.lookup("fixTangentialInflow")), + normalVelocity_ + ( + fvPatchVectorField::New(p, iF, dict.subDict("normalVelocity")) + ) +{ + fvPatchVectorField::operator=(vectorField("value", dict, p.size())); + refValue() = normalVelocity(); + refGrad() = vector::zero; + valueFraction() = symmTensor::zero; +} + + +Foam::fixedNormalInletOutletVelocityFvPatchVectorField:: +fixedNormalInletOutletVelocityFvPatchVectorField +( + const fixedNormalInletOutletVelocityFvPatchVectorField& pivpvf +) +: + directionMixedFvPatchVectorField(pivpvf), + phiName_(pivpvf.phiName_), + fixTangentialInflow_(pivpvf.fixTangentialInflow_), + normalVelocity_(pivpvf.normalVelocity().clone()) +{} + + +Foam::fixedNormalInletOutletVelocityFvPatchVectorField:: +fixedNormalInletOutletVelocityFvPatchVectorField +( + const fixedNormalInletOutletVelocityFvPatchVectorField& pivpvf, + const DimensionedField& iF +) +: + directionMixedFvPatchVectorField(pivpvf, iF), + phiName_(pivpvf.phiName_), + fixTangentialInflow_(pivpvf.fixTangentialInflow_), + normalVelocity_(pivpvf.normalVelocity().clone()) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fixedNormalInletOutletVelocityFvPatchVectorField::autoMap +( + const fvPatchFieldMapper& m +) +{ + directionMixedFvPatchVectorField::autoMap(m); + normalVelocity_->autoMap(m); +} + + +void Foam::fixedNormalInletOutletVelocityFvPatchVectorField::rmap +( + const fvPatchVectorField& ptf, + const labelList& addr +) +{ + directionMixedFvPatchVectorField::rmap(ptf, addr); + + const fixedNormalInletOutletVelocityFvPatchVectorField& fniovptf = + refCast(ptf); + + normalVelocity_->rmap(fniovptf.normalVelocity(), addr); +} + + +void Foam::fixedNormalInletOutletVelocityFvPatchVectorField::updateCoeffs() +{ + if (updated()) + { + return; + } + + normalVelocity_->evaluate(); + refValue() = normalVelocity(); + + valueFraction() = sqr(patch().nf()); + + if (fixTangentialInflow_) + { + const fvsPatchField& phip = + patch().lookupPatchField(phiName_); + + valueFraction() += neg(phip)*(I - valueFraction()); + } + + directionMixedFvPatchVectorField::updateCoeffs(); + directionMixedFvPatchVectorField::evaluate(); +} + + +void Foam::fixedNormalInletOutletVelocityFvPatchVectorField::write +( + Ostream& os +) +const +{ + fvPatchVectorField::write(os); + writeEntryIfDifferent(os, "phi", "phi", phiName_); + os.writeKeyword("fixTangentialInflow") + << fixTangentialInflow_ << token::END_STATEMENT << nl; + os.writeKeyword("normalVelocity") + << nl << indent << token::BEGIN_BLOCK << nl << incrIndent; + normalVelocity_->write(os); + os << decrIndent << indent << token::END_BLOCK << endl; + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +void Foam::fixedNormalInletOutletVelocityFvPatchVectorField::operator= +( + const fvPatchField& pvf +) +{ + tmp normalValue = transform(valueFraction(), refValue()); + tmp transformGradValue = transform(I - valueFraction(), pvf); + fvPatchField::operator=(normalValue + transformGradValue); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchVectorField, + fixedNormalInletOutletVelocityFvPatchVectorField + ); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalInletOutletVelocity/fixedNormalInletOutletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalInletOutletVelocity/fixedNormalInletOutletVelocityFvPatchVectorField.H new file mode 100644 index 0000000000..6d6bb2e736 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalInletOutletVelocity/fixedNormalInletOutletVelocityFvPatchVectorField.H @@ -0,0 +1,248 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2014 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::fixedNormalInletOutletVelocityFvPatchVectorField + +Group + grpInletletBoundaryConditions grpOutletBoundaryConditions + +Description + + This velocity inlet/outlet boundary condition combines a fixed normal + component obtained from the "normalVelocity" patchField supplied with a + fixed or zero-gradiented tangential component depending on the direction + of the flow and the setting of "fixTangentialInflow": + - Outflow: apply zero-gradient condition to tangential components + - Inflow: + - fixTangentialInflow is true + apply value provided by the normalVelocity patchField to the + tangential components + - fixTangentialInflow is false + apply zero-gradient condition to tangential components. + + \heading Patch usage + + \table + Property | Description | Required | Default value + phi | flux field name | no | phi + fixTangentialInflow | If true fix the tangential component for inflow | yes | + normalVelocity | patchField providing the normal velocity field | yes | + \endtable + + Example of the boundary condition specification: + \verbatim + myPatch + { + type fixedNormalInletOutletVelocity; + + fixTangentialInflow false; + normalVelocity + { + type oscillatingFixedValue; + refValue uniform (0 1 0); + offset (0 -1 0); + amplitude table + ( + ( 0 0) + ( 2 0.088) + ( 8 0.088) + ); + frequency constant 1; + } + + value uniform (0 0 0); + } + \endverbatim + +SourceFiles + fixedNormalInletOutletVelocityFvPatchVectorField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fixedNormalInletOutletVelocityFvPatchVectorField_H +#define fixedNormalInletOutletVelocityFvPatchVectorField_H + +#include "fvPatchFields.H" +#include "directionMixedFvPatchFields.H" +#include "Switch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class fixedNormalInletOutletVelocityFvPatchVectorField Declaration +\*---------------------------------------------------------------------------*/ + +class fixedNormalInletOutletVelocityFvPatchVectorField +: + public directionMixedFvPatchVectorField +{ + // Private data + + //- Flux field name + word phiName_; + + //- Set true to fix the tangential component for inflow + Switch fixTangentialInflow_; + + //- BC which provided the normal component of the velocity + tmp normalVelocity_; + + +public: + + //- Runtime type information + TypeName("fixedNormalInletOutletVelocity"); + + + // Constructors + + //- Construct from patch and internal field + fixedNormalInletOutletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + fixedNormalInletOutletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given + // fixedNormalInletOutletVelocityFvPatchVectorField onto a new patch + fixedNormalInletOutletVelocityFvPatchVectorField + ( + const fixedNormalInletOutletVelocityFvPatchVectorField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + fixedNormalInletOutletVelocityFvPatchVectorField + ( + const fixedNormalInletOutletVelocityFvPatchVectorField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new fixedNormalInletOutletVelocityFvPatchVectorField(*this) + ); + } + + //- Construct as copy setting internal field reference + fixedNormalInletOutletVelocityFvPatchVectorField + ( + const fixedNormalInletOutletVelocityFvPatchVectorField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new fixedNormalInletOutletVelocityFvPatchVectorField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- 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_; + } + + Switch fixTangentialInflow() const + { + return fixTangentialInflow_; + } + + //- Return the BC which provides the normal component of velocity + const fvPatchVectorField& normalVelocity() const + { + return normalVelocity_(); + } + + + // Mapping functions + + //- Map (and resize as needed) from self given a mapping object + virtual void autoMap + ( + const fvPatchFieldMapper& + ); + + //- Reverse map the given fvPatchField onto this fvPatchField + virtual void rmap + ( + const fvPatchVectorField&, + const labelList& + ); + + + //- 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 + +// ************************************************************************* //