From 05de25f517475548d294688bf92b4b46d083395e Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 21 Jan 2013 15:56:32 +0000 Subject: [PATCH] ENH: Added new pressureDrop porosity model --- src/finiteVolume/Make/files | 3 +- .../porosityModel/pressureDrop/pressureDrop.C | 144 ++++++++++++ .../porosityModel/pressureDrop/pressureDrop.H | 206 ++++++++++++++++++ .../pressureDrop/pressureDropTemplates.C | 89 ++++++++ 4 files changed, 441 insertions(+), 1 deletion(-) create mode 100644 src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.C create mode 100644 src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.H create mode 100644 src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDropTemplates.C diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 063b6fc04c..578e893fbc 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -381,8 +381,9 @@ $(porosity)/porosityModel/porosityModelNew.C $(porosity)/porosityModel/porosityModelList.C $(porosity)/porosityModel/IOporosityModelList.C $(porosity)/DarcyForchheimer/DarcyForchheimer.C -$(porosity)/powerLaw/powerLaw.C $(porosity)/fixedCoeff/fixedCoeff.C +$(porosity)/powerLaw/powerLaw.C +$(porosity)/pressureDrop/pressureDrop.C MRF = $(general)/MRF $(MRF)/MRFZone.C diff --git a/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.C b/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.C new file mode 100644 index 0000000000..7b0a86e4c8 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.C @@ -0,0 +1,144 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 "addToRunTimeSelectionTable.H" +#include "pressureDrop.H" +#include "fvMatrices.H" +#include "geometricOneField.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + namespace porosityModels + { + defineTypeNameAndDebug(pressureDrop, 0); + addToRunTimeSelectionTable(porosityModel, pressureDrop, mesh); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::porosityModels::pressureDrop::pressureDrop +( + const word& name, + const word& modelType, + const fvMesh& mesh, + const dictionary& dict, + const word& cellZoneName +) +: + porosityModel(name, modelType, mesh, dict, cellZoneName), + coordSys_(coeffs_, mesh), + mDotvsDp_(DataEntry::New("mDotvsDp", coeffs_)), + lRef_(readScalar(coeffs_.lookup("lRef"))), + rhoName_(coeffs_.lookupOrDefault("rho", "rho")) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::porosityModels::pressureDrop::~pressureDrop() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::porosityModels::pressureDrop::correct +( + fvVectorMatrix& UEqn +) const +{ + const vectorField& U = UEqn.psi(); + const scalarField& V = mesh_.V(); + scalarField& Udiag = UEqn.diag(); + vectorField& Usource = UEqn.source(); + + scalar rhoScale = 1.0; + if (UEqn.dimensions() == dimForce) + { + const volScalarField& rho = + mesh_.lookupObject(rhoName_); + + apply(Udiag, Usource, V, rho, U, rhoScale); + } + else + { + coeffs_.lookup("rhoRef") >> rhoScale; + apply(Udiag, Usource, V, geometricOneField(), U, rhoScale); + } + +} + + +void Foam::porosityModels::pressureDrop::correct +( + fvVectorMatrix& UEqn, + const volScalarField& rho, + const volScalarField& +) const +{ + const vectorField& U = UEqn.psi(); + const scalarField& V = mesh_.V(); + scalarField& Udiag = UEqn.diag(); + vectorField& Usource = UEqn.source(); + + apply(Udiag, Usource, V, rho, U, 1.0); +} + + +void Foam::porosityModels::pressureDrop::correct +( + const fvVectorMatrix& UEqn, + volTensorField& AU +) const +{ + const vectorField& U = UEqn.psi(); + + scalar rhoScale = 1.0; + if (UEqn.dimensions() == dimForce) + { + const volScalarField& rho = + mesh_.lookupObject(rhoName_); + + apply(AU, rho, U, rhoScale); + } + else + { + coeffs_.lookup("rhoRef") >> rhoScale; + apply(AU, geometricOneField(), U, rhoScale); + } +} + + +void Foam::porosityModels::pressureDrop::writeData(Ostream& os) const +{ + os << indent << name_ << endl; + dict_.write(os); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.H b/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.H new file mode 100644 index 0000000000..b568a8f7cf --- /dev/null +++ b/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDrop.H @@ -0,0 +1,206 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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::pressureDrop + +Description + Pressure drop porosity model, whereby the user speciefies the pressure + drop per unit length as a function of mass flow rate, over a fixed distance. + + Example usage: + \verbatim + pressureDropCoeffs + { + coordinateSystem + { + e1 (1 0 0); + e2 (0 1 0); + } + + lRef 0.5; + + mDotvsDp table + ( + (0 0) + (0.2 20) + (0.4 40) + (0.6 65) + (0.8 95) + (1.0 125) + (1.5 220) + (2.0 320) + (2.5 435) + (3.0 560) + (3.5 700) + ); + } + \endverbatim + +Note + The mDotvsDp entry is a DataEntry type, able to describe the pressure drop + per unit length as a function mass flow rate. The example above gives the + usage for supplying in-line tabulated data. + +SeeAlso + Foam::DataEntry + +SourceFiles + pressureDrop.C + +\*---------------------------------------------------------------------------*/ + +#ifndef pressureDrop_H +#define pressureDrop_H + +#include "porosityModel.H" +#include "coordinateSystem.H" +#include "autoPtr.H" +#include "DataEntry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace porosityModels +{ + +/*---------------------------------------------------------------------------*\ + Class pressureDrop Declaration +\*---------------------------------------------------------------------------*/ + +class pressureDrop +: + public porosityModel +{ +private: + + // Private data + + //- Local co-ordinate system + coordinateSystem coordSys_; + + //- Pressure drop per unit length [Pa/m] as a function of + // mass flow rate [kg/s] + autoPtr > mDotvsDp_; + + //- Distance over which pressure drop is applied + scalar lRef_; + + //- Name of density field + word rhoName_; + + + // Private Member Functions + + //- Apply + template + void apply + ( + scalarField& Udiag, + vectorField& Usource, + const scalarField& V, + const RhoFieldType& rho, + const vectorField& U, + const scalar rhoScale + ) const; + + //- Apply + template + void apply + ( + tensorField& AU, + const RhoFieldType& rho, + const vectorField& U, + const scalar rhoScale + ) const; + + //- Disallow default bitwise copy construct + pressureDrop(const pressureDrop&); + + //- Disallow default bitwise assignment + void operator=(const pressureDrop&); + + +public: + + //- Runtime type information + TypeName("pressureDrop"); + + //- Constructor + pressureDrop + ( + const word& name, + const word& modelType, + const fvMesh& mesh, + const dictionary& dict, + const word& cellZoneName + ); + + //- Destructor + virtual ~pressureDrop(); + + + // Member Functions + + //- Add resistance + virtual void correct(fvVectorMatrix& UEqn) const; + + //- Add resistance + virtual void correct + ( + fvVectorMatrix& UEqn, + const volScalarField& rho, + const volScalarField& mu + ) const; + + //- Add resistance + virtual void correct + ( + const fvVectorMatrix& UEqn, + volTensorField& AU + ) const; + + + // I-O + + //- Write + void writeData(Ostream& os) const; +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace porosityModels +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "pressureDropTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDropTemplates.C b/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDropTemplates.C new file mode 100644 index 0000000000..0dc6e6e131 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/porosityModel/pressureDrop/pressureDropTemplates.C @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +template +void Foam::porosityModels::pressureDrop::apply +( + scalarField& Udiag, + vectorField& Usource, + const scalarField& V, + const RhoFieldType& rho, + const vectorField& U, + const scalar rhoScale +) const +{ + // local-to-global transformation tensor + const tensor& E = coordSys_.R(); + + forAll(cellZoneIds_, zoneI) + { + const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]]; + + forAll(cells, i) + { + const label cellI = cells[i]; + const scalar magU = mag(U[cellI]); + const scalar mDot = rho[cellI]*magU; + const scalar dp = mDotvsDp_->value(mDot); + const tensor Cd = E*dp/(lRef_*magU*rhoScale + ROOTVSMALL); + const scalar isoCd = tr(Cd); + + Udiag[cellI] += V[cellI]*isoCd; + Usource[cellI] -= V[cellI]*((Cd - I*isoCd) & U[cellI]); + } + } +} + + +template +void Foam::porosityModels::pressureDrop::apply +( + tensorField& AU, + const RhoFieldType& rho, + const vectorField& U, + const scalar rhoScale +) const +{ + // local-to-global transformation tensor + const tensor& E = coordSys_.R(); + + forAll(cellZoneIds_, zoneI) + { + const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]]; + + forAll(cells, i) + { + const label cellI = cells[i]; + const scalar magU = mag(U[cellI]); + const scalar mDot = rho[cellI]*magU; + const scalar dp = mDotvsDp_->value(mDot); + + AU[cellI] += E*dp/(lRef_*magU*rhoScale + ROOTVSMALL); + } + } +} + + +// ************************************************************************* //