From 43b9b63ab0f0138f9679b43876bc021166140a30 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Fri, 11 Sep 2020 20:49:41 +0100 Subject: [PATCH] ENH: fanPressureFvPatchScalarField - updated fanCurve to use a Function1 --- .../fanPressureFvPatchScalarField.C | 58 ++++++++++++------- .../fanPressureFvPatchScalarField.H | 12 ++-- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C index 59e729de7a0..c5c2fe3c09b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C @@ -30,6 +30,7 @@ License #include "addToRunTimeSelectionTable.H" #include "volFields.H" #include "surfaceFields.H" +#include "TableFile.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -86,12 +87,28 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField ) : totalPressureFvPatchScalarField(p, iF, dict), - fanCurve_(dict), + fanCurve_(), direction_(fanFlowDirectionNames_.get("direction", dict)), rpm_(0), dm_(0), nonDimensional_(dict.getOrDefault("nonDimensional", false)) { + // Backwards compatibility + if (dict.found("file")) + { + fanCurve_.reset + ( + new Function1Types::TableFile<scalar>("fanCurve", dict) + ); + } + else + { + fanCurve_.reset + ( + Function1<scalar>::New("fanCurve", dict) + ); + } + if (nonDimensional_) { dict.readEntry("rpm", rpm_); @@ -102,30 +119,30 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField ( - const fanPressureFvPatchScalarField& pfopsf + const fanPressureFvPatchScalarField& fppsf ) : - totalPressureFvPatchScalarField(pfopsf), - fanCurve_(pfopsf.fanCurve_), - direction_(pfopsf.direction_), - rpm_(pfopsf.rpm_), - dm_(pfopsf.dm_), - nonDimensional_(pfopsf.nonDimensional_) + totalPressureFvPatchScalarField(fppsf), + fanCurve_(fppsf.fanCurve_.clone()), + direction_(fppsf.direction_), + rpm_(fppsf.rpm_), + dm_(fppsf.dm_), + nonDimensional_(fppsf.nonDimensional_) {} Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField ( - const fanPressureFvPatchScalarField& pfopsf, + const fanPressureFvPatchScalarField& fppsf, const DimensionedField<scalar, volMesh>& iF ) : - totalPressureFvPatchScalarField(pfopsf, iF), - fanCurve_(pfopsf.fanCurve_), - direction_(pfopsf.direction_), - rpm_(pfopsf.rpm_), - dm_(pfopsf.dm_), - nonDimensional_(pfopsf.nonDimensional_) + totalPressureFvPatchScalarField(fppsf, iF), + fanCurve_(fppsf.fanCurve_.clone()), + direction_(fppsf.direction_), + rpm_(fppsf.rpm_), + dm_(fppsf.dm_), + nonDimensional_(fppsf.nonDimensional_) {} @@ -139,11 +156,9 @@ void Foam::fanPressureFvPatchScalarField::updateCoeffs() } // Retrieve flux field - const surfaceScalarField& phi = - db().lookupObject<surfaceScalarField>(phiName()); + const auto& phi = db().lookupObject<surfaceScalarField>(phiName()); - const fvsPatchField<scalar>& phip = - patch().patchField<surfaceScalarField, scalar>(phi); + const auto& phip = patch().patchField<surfaceScalarField, scalar>(phi); int dir = 2*direction_ - 1; @@ -178,7 +193,7 @@ void Foam::fanPressureFvPatchScalarField::updateCoeffs() } // Pressure drop for this flow rate - scalar pdFan = fanCurve_(max(volFlowRate, 0.0)); + scalar pdFan = fanCurve_->value(max(volFlowRate, 0.0)); if (nonDimensional_) { @@ -197,8 +212,9 @@ void Foam::fanPressureFvPatchScalarField::updateCoeffs() void Foam::fanPressureFvPatchScalarField::write(Ostream& os) const { totalPressureFvPatchScalarField::write(os); - fanCurve_.write(os); + fanCurve_->writeData(os); os.writeEntry("direction", fanFlowDirectionNames_[direction_]); + if (nonDimensional_) { os.writeEntry("nonDimensional", "true"); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H index f1ccf048586..5184876d838 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd + Copyright (C) 2017-2020 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,6 +69,7 @@ Usage inlet { type fanPressure; + fanCurve tableFile; file "fanCurve"; outOfBounds clamp; direction in; @@ -79,6 +80,7 @@ Usage outlet { type fanPressure; + fanCurve tableFile; file "fanCurve"; outOfBounds clamp; direction out; @@ -90,7 +92,7 @@ Usage See also Foam::fanFvPatchField Foam::totalPressureFvPatchScalarField - Foam::interpolationTable + Foam::Function1 SourceFiles fanPressureFvPatchScalarField.C @@ -101,7 +103,7 @@ SourceFiles #define fanPressureFvPatchScalarField_H #include "totalPressureFvPatchScalarField.H" -#include "interpolationTable.H" +#include "Function1.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -134,8 +136,8 @@ private: // Private Data - //- Tabulated fan curve - interpolationTable<scalar> fanCurve_; + //- Run-time selectable fan curve + autoPtr<Function1<scalar>> fanCurve_; //- Direction of flow through the fan relative to patch fanFlowDirection direction_; -- GitLab