From 06b0cd81604dcc9b62ef6e39e1fa1deb614eea06 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 28 Jan 2010 17:31:16 +0000 Subject: [PATCH] timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField: new BC. Velocity inlet boundary condition for patches where the pressure is specified. The inflow velocity is obtained from the flux with the "inletDirection" direction mapped from a time/space-varying table. --- ...essureDirectedInletVelocityFvPatchVectorField.C | 209 +++++++++++++++++++++ ...essureDirectedInletVelocityFvPatchVectorField.H | 201 ++++++++++++++++++++ 2 files changed, 410 insertions(+) create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.H diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.C new file mode 100644 index 00000000..3fb91ab9 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.C @@ -0,0 +1,209 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF +) +: + timeVaryingMappedFixedValueFvPatchVectorField(p, iF), + phiName_("phi"), + rhoName_("rho") +{} + + +Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + timeVaryingMappedFixedValueFvPatchVectorField(p, iF), + phiName_(dict.lookupOrDefault("phi", "phi")), + rhoName_(dict.lookupOrDefault("rho", "rho")) +{ + fvPatchVectorField::operator=(vectorField("value", dict, p.size())); +} + + +Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField +( + const timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + timeVaryingMappedFixedValueFvPatchVectorField(ptf, p, iF, mapper), + phiName_(ptf.phiName_), + rhoName_(ptf.rhoName_) +{} + + +Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField +( + const timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField& + pivpvf +) +: + timeVaryingMappedFixedValueFvPatchVectorField(pivpvf), + phiName_(pivpvf.phiName_), + rhoName_(pivpvf.rhoName_) +{} + + +Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField +( + const timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField& + pivpvf, + const DimensionedField& iF +) +: + timeVaryingMappedFixedValueFvPatchVectorField(pivpvf, iF), + phiName_(pivpvf.phiName_), + rhoName_(pivpvf.rhoName_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +autoMap +( + const fvPatchFieldMapper& m +) +{ + timeVaryingMappedFixedValueFvPatchVectorField::autoMap(m); +} + + +void Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +rmap +( + const fvPatchVectorField& ptf, + const labelList& addr +) +{ + timeVaryingMappedFixedValueFvPatchVectorField::rmap(ptf, addr); +} + + +void Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +updateCoeffs() +{ + if (updated()) + { + return; + } + + // Map the tabulated velocity field onto this field + timeVaryingMappedFixedValueFvPatchVectorField::updateCoeffs(); + vectorField inletDir = *this; + + // Normalise to obtain the flow direction + inletDir /= (mag(inletDir) + SMALL); + + const surfaceScalarField& phi = + db().lookupObject(phiName_); + + const fvsPatchField& phip = + patch().patchField(phi); + + vectorField n = patch().nf(); + scalarField ndmagS = (n & inletDir)*patch().magSf(); + + if (phi.dimensions() == dimVelocity*dimArea) + { + operator==(inletDir*phip/ndmagS); + } + else if (phi.dimensions() == dimDensity*dimVelocity*dimArea) + { + const fvPatchField& rhop = + patch().lookupPatchField(rhoName_); + + operator==(inletDir*phip/(rhop*ndmagS)); + } + else + { + FatalErrorIn + ( + "timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField" + "::updateCoeffs()" + ) << "dimensions of phi are not correct" + << "\n on patch " << this->patch().name() + << " of field " << this->dimensionedInternalField().name() + << " in file " << this->dimensionedInternalField().objectPath() + << exit(FatalError); + } +} + + +void Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField:: +write +( + Ostream& os +) const +{ + if (phiName_ != "phi") + { + os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; + } + if (rhoName_ != "rho") + { + os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl; + } + timeVaryingMappedFixedValueFvPatchVectorField::write(os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchVectorField, + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.H new file mode 100644 index 00000000..a20da7af --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedPressureDirectedInletVelocity/timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.H @@ -0,0 +1,201 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + +Description + Velocity inlet boundary condition for patches where the pressure is + specified. The inflow velocity is obtained from the flux with the + "inletDirection" direction mapped from a time/space-varying table. + +SourceFiles + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField_H +#define timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField_H + +#include "timeVaryingMappedFixedValueFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class timeVaryingMappedPressureDirectedInletVelocityFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +class timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField +: + public timeVaryingMappedFixedValueFvPatchVectorField +{ + // Private data + + word phiName_; + word rhoName_; + + +public: + + //- Runtime type information + TypeName("timeVaryingMappedPressureDirectedInletVelocity"); + + + // Constructors + + //- Construct from patch and internal field + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given + // timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + // onto a new patch + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + const timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + const timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + *this + ) + ); + } + + //- Construct as copy setting internal field reference + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + const timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new + timeVaryingMappedPressureDirectedInletVelocityFvPatchVectorField + ( + *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_; + } + + + // 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; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // -- 2.11.4.GIT