From f52a64b083ceed7213cdf032a999649c033341a2 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 8 Feb 2012 14:27:01 +0000 Subject: [PATCH] ENH: fanFvPatchField: generic DataEntry form allowed --- .../derived/fan/fanFvPatchField.C | 44 +++------ .../derived/fan/fanFvPatchField.H | 61 ++++++++++--- .../derived/fan/fanFvPatchFields.C | 90 +++++++++++++++---- 3 files changed, 134 insertions(+), 61 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C index 0261efd54e..477b242b76 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.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-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,7 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "fanFvPatchField.H" -#include "IOmanip.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -36,7 +35,7 @@ Foam::fanFvPatchField::fanFvPatchField ) : fixedJumpFvPatchField(p, iF), - f_(0) + jumpTable_(0) {} @@ -50,7 +49,7 @@ Foam::fanFvPatchField::fanFvPatchField ) : fixedJumpFvPatchField(ptf, p, iF, mapper), - f_(ptf.f_) + jumpTable_(ptf.jumpTable_().clone().ptr()) {} @@ -63,28 +62,8 @@ Foam::fanFvPatchField::fanFvPatchField ) : fixedJumpFvPatchField(p, iF), - f_() -{ - { - Istream& is = dict.lookup("f"); - is.format(IOstream::ASCII); - is >> f_; - - // Check that f_ table is same on both sides.? - } - - if (dict.found("value")) - { - fvPatchField::operator= - ( - Field("value", dict, p.size()) - ); - } - else - { - this->evaluate(Pstream::blocking); - } -} + jumpTable_(DataEntry::New("jumpTable", dict)) +{} template @@ -95,7 +74,7 @@ Foam::fanFvPatchField::fanFvPatchField : cyclicLduInterfaceField(), fixedJumpFvPatchField(ptf), - f_(ptf.f_) + jumpTable_(ptf.jumpTable_().clone().ptr()) {} @@ -107,7 +86,7 @@ Foam::fanFvPatchField::fanFvPatchField ) : fixedJumpFvPatchField(ptf, iF), - f_(ptf.f_) + jumpTable_(ptf.jumpTable_().clone().ptr()) {} @@ -119,11 +98,10 @@ void Foam::fanFvPatchField::write(Ostream& os) const { fixedJumpFvPatchField::write(os); - - IOstream::streamFormat fmt0 = os.format(IOstream::ASCII); - os.writeKeyword("f") << f_ << token::END_STATEMENT << nl; - os.format(fmt0); - + if (this->cyclicPatch().owner()) + { + jumpTable_->writeData(os); + } this->writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H index e93b697977..b3799c2bd9 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H @@ -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-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,43 @@ Class Foam::fanFvPatchField Description - Foam::fanFvPatchField + Jump boundary condition. Operates on cyclic. Jump specified as a DataEntry. + (table, fileTable, csv etc.) + + Example of the boundary condition specification: + \verbatim + fan_half0 + { + type fan; + patchType cyclic; + jump uniform 0; + jumpTable csvFile; + csvFileCoeffs + { + hasHeaderLine 1; + refColumn 0; + componentColumns 1(1); + separator ","; + fileName "$FOAM_CASE/constant/pressureVsU"; + } + value uniform 0; + } + \endverbatim + + + Backwards compatibility: if the 'f' keyword is detected it assumes + it is a power of the flowrate. + + \verbatim + fan_half0 + { + type fan; + patchType cyclic; + jump uniform 0; + f 2(100 -0.1); + value uniform 0; + } + \endverbatim SourceFiles fanFvPatchField.C @@ -36,6 +72,7 @@ SourceFiles #define fanFvPatchField_H #include "fixedJumpFvPatchField.H" +#include "DataEntry.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -53,8 +90,8 @@ class fanFvPatchField { // Private data - //- Fan pressure rise polynomial coefficients - List f_; + //- Interpolation table + autoPtr > jumpTable_; public: @@ -126,15 +163,6 @@ public: // Member functions - // Access - - //- Return the polynomial coefficients - const List& f() const - { - return f_; - } - - // Evaluation functions //- Update the coefficients associated with the patch field @@ -148,6 +176,13 @@ public: //- Specialisation of the jump-condition for the pressure template<> +fanFvPatchField::fanFvPatchField +( + const fvPatch&, + const DimensionedField&, + const dictionary& +); +template<> void fanFvPatchField::updateCoeffs(); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C index b3af1d2245..eacee81a37 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.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-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,8 @@ License #include "addToRunTimeSelectionTable.H" #include "volFields.H" #include "surfaceFields.H" +#include "Tuple2.H" +#include "polynomial.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -41,24 +43,87 @@ makeTemplatePatchTypeField fanFvPatchScalarField ); +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<> +Foam::fanFvPatchField::fanFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedJumpFvPatchField(p, iF), + jumpTable_(new DataEntry("jumpTable")) +{ + if (this->cyclicPatch().owner()) + { + if (dict.found("f")) + { + // Backwards compatibility + Istream& is = dict.lookup("f"); + is.format(IOstream::ASCII); + scalarList f(is); + + label nPows = 0; + forAll(f, powI) + { + if (mag(f[powI]) > VSMALL) + { + nPows++; + } + } + List > coeffs(nPows); + nPows = 0; + forAll(f, powI) + { + if (mag(f[powI]) > VSMALL) + { + coeffs[nPows++] = Tuple2(f[powI], powI); + } + } + + Pout<< "** coeffss:" << coeffs << endl; + + jumpTable_.reset + ( + new polynomial("jumpTable", coeffs) + ); + } + else + { + // Generic input constructed from dictionary + jumpTable_ = DataEntry::New("jumpTable", dict); + } + } + + + if (dict.found("value")) + { + fvPatchScalarField::operator= + ( + scalarField("value", dict, p.size()) + ); + } + else + { + this->evaluate(Pstream::blocking); + } +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // //- Specialisation of the jump-condition for the pressure template<> void Foam::fanFvPatchField::updateCoeffs() { - if (updated()) + if (this->updated()) { return; } - // Note that the neighbour side jump_ data is never actually used; the - // jump() function just calls the owner side jump(). - - // Constant - jump_ = f_[0]; - - if (f_.size() > 1) + if (this->cyclicPatch().owner()) { const surfaceScalarField& phi = db().lookupObject("phi"); @@ -73,12 +138,7 @@ void Foam::fanFvPatchField::updateCoeffs() Un /= patch().lookupPatchField("rho"); } - for (label i=1; ivalue(Un); } fixedJumpFvPatchField::updateCoeffs();