View Issue Details

IDProjectCategoryView StatusLast Update
0003102OpenFOAMBugpublic2018-11-14 15:40
ReporterDanielJ Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Fixed in Versiondev 
Summary0003102: Inconsistent behavior of fanFvPatchField
DescriptionfanFvPatchField is derived from uniformJumpFvPatchField and has different specialization for different field types.
For scalars, it computes jump value based on the local(!!!) normal velocity, for all other types the jump is computed based on the current time.
Why is this a problem:
 - very different behavior for different types violates the "principle of least astonishment"
 - for types other than scalar, the behavior of the BC exactly duplicates the behavior of the uniformJumpFvPatchField
 - pressure jump based on the local velocity is not convenient, if at all reasonable, and inconsistent with fanPressure BC which defines fan pressure as a function of the volumetric flow rate
 - "jumpTable" keyword from base class is used to describe the fan characteristics, which is not very domain-related and therefore the semantics of this field is not obvious

Change proposal:
 - de-templatize fanFvPatchField and create only scalar version
 - derive implementation from fixedJumpFvPatchField not uniformJumpFvPatchField
 - add Function1 field, describing pressure as a function of flow rate, with more domain specific name like "fanCurve"
 - deprecate with warning the previous field "jumpTable", but preserve backward compatible behavior
Optional:
 - allow for reversing the "direction" of the pressure jump without the need to change fan curve

I can make the necessary changes if approved.
TagsNo tags attached.

Activities

henry

2018-11-07 14:53

manager   ~0010153

What fields other than pressure are you applying the fanFvPatchField to? My feeling is that it is only applied to pressure in which case the inconsistency in operation does not matter. However, I agree that if it is only ever applied to pressure it need not be templated and might as well be implemented specifically for pressure as say fanPressureJumpFvPatchField

What is wrong with computing the pressure based on the local velocity? While consistency with the fanPressure BC would be sensible removing the current functionality altogether might cause problems for users relying on it.

DanielJ

2018-11-07 16:07

reporter   ~0010155

The fanFvPathField is only used for pressure since for other types the uniformJumpFvPatchField provides identical functionality and its behavior is more.

I agree that removing this functionality is not a good idea, that is why I suggested some sort of backward compatibility mode, either within this BC or as a new one.

As to the local velocity approach, it has a few small issues:
1) It is more common to express pressure as a function of flow rate not velocity.
2) Usually only integral values are known, i.e. "far field" pressure jump as a function of total flow rate
3) Using the local velocity instead of the average velocity would introduce an incorrect amount o energy into the flow for a given total flow rate: A•Δp(Uavg)•Uavg =/= 2•π• integral Δp(U,r??)•U(r)•r•dr
Although this is not a big problem when the velocity profile is fairly uniform.

henry

2018-11-07 16:33

manager   ~0010156

As long as there is optional backward compatibility I don't see a problem with your proposal and think renaming the resulting BC would be sensible.

DanielJ

2018-11-07 16:42

reporter   ~0010157

What about the fact that renaming the BC would break existing cases? Maybe for now just start with modification of the BC?

henry

2018-11-07 16:53

manager   ~0010158

Existing cases would break but it would be VERY easy to fix them by changing the name. However if the actual functionality is removed then they cannot be made to operate in the same manner as before.

fanFvPatchField is not a good name for a pressure-only BC, our convention is to include pressure in the name. However if you plan on updating the BC so it can be used for all fields then the name can stay the same and it would need to be templated.

DanielJ

2018-11-07 17:19

reporter   ~0010159

OK, I prefer the approach with pressure-only BC and a new name.

BTW, just got an idea, that it would be nice to have a case migration utility, would be very similar to changeDict for which specification could be located somewhere in the etc directory.
This would make adding breaking changes essentially painless for the user.

DanielJ

2018-11-08 06:18

reporter  

fanPressureJump.patch (34,778 bytes)   
From 5ed4b3489c93c5ce3c77a9a92c677ef966fb291c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Jasi=C5=84ski?= <daniel.jasinski@gmail.com>
Date: Thu, 8 Nov 2018 07:00:14 +0100
Subject: [PATCH] fanFvPatchField: Renamed to fanPressureJumpFvPatchScalarField
 and added support for defining fan curve.

---
 src/finiteVolume/Make/files                        |   2 +-
 .../fvPatchFields/derived/fan/fanFvPatchField.C    | 135 ------------
 .../fvPatchFields/derived/fan/fanFvPatchField.H    | 219 --------------------
 .../fvPatchFields/derived/fan/fanFvPatchFields.C   |  99 ---------
 .../fvPatchFields/derived/fan/fanFvPatchFields.H   |  49 -----
 .../derived/fan/fanFvPatchFieldsFwd.H              |  50 -----
 .../fanPressureJumpFvPatchScalarField.C            | 228 +++++++++++++++++++++
 .../fanPressureJumpFvPatchScalarField.H            | 212 +++++++++++++++++++
 8 files changed, 441 insertions(+), 553 deletions(-)
 delete mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C
 delete mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H
 delete mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C
 delete mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.H
 delete mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFieldsFwd.H
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.C
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.H

diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files
index c4bb131..8200e8f 100644
--- a/src/finiteVolume/Make/files
+++ b/src/finiteVolume/Make/files
@@ -139,7 +139,7 @@ $(derivedFvPatchFields)/codedFixedValue/codedFixedValueFvPatchFields.C
 $(derivedFvPatchFields)/codedMixed/codedMixedFvPatchFields.C
 $(derivedFvPatchFields)/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C
 $(derivedFvPatchFields)/externalCoupledMixed/externalCoupledMixedFvPatchFields.C
-$(derivedFvPatchFields)/fan/fanFvPatchFields.C
+$(derivedFvPatchFields)/fanPressureJump/fanPressureJumpFvPatchScalarField.C
 $(derivedFvPatchFields)/fanPressure/fanPressureFvPatchScalarField.C
 $(derivedFvPatchFields)/fixedFluxPressure/fixedFluxPressureFvPatchScalarField.C
 $(derivedFvPatchFields)/fixedFluxExtrapolatedPressure/fixedFluxExtrapolatedPressureFvPatchScalarField.C
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C
deleted file mode 100644
index 6498687..0000000
--- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C
+++ /dev/null
@@ -1,135 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#include "fanFvPatchField.H"
-
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-template<class Type>
-void Foam::fanFvPatchField<Type>::calcFanJump()
-{
-    if (this->cyclicPatch().owner())
-    {
-        this->jump_ = this->jumpTable_->value(this->db().time().value());
-    }
-}
-
-
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-template<class Type>
-Foam::fanFvPatchField<Type>::fanFvPatchField
-(
-    const fvPatch& p,
-    const DimensionedField<Type, volMesh>& iF
-)
-:
-    uniformJumpFvPatchField<Type>(p, iF),
-    phiName_("phi"),
-    rhoName_("rho")
-{}
-
-
-template<class Type>
-Foam::fanFvPatchField<Type>::fanFvPatchField
-(
-    const fvPatch& p,
-    const DimensionedField<Type, volMesh>& iF,
-    const dictionary& dict
-)
-:
-    uniformJumpFvPatchField<Type>(p, iF, dict),
-    phiName_(dict.lookupOrDefault<word>("phi", "phi")),
-    rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
-{}
-
-
-template<class Type>
-Foam::fanFvPatchField<Type>::fanFvPatchField
-(
-    const fanFvPatchField<Type>& ptf,
-    const fvPatch& p,
-    const DimensionedField<Type, volMesh>& iF,
-    const fvPatchFieldMapper& mapper
-)
-:
-    uniformJumpFvPatchField<Type>(ptf, p, iF, mapper),
-    phiName_(ptf.phiName_),
-    rhoName_(ptf.rhoName_)
-{}
-
-
-template<class Type>
-Foam::fanFvPatchField<Type>::fanFvPatchField
-(
-    const fanFvPatchField<Type>& ptf
-)
-:
-    uniformJumpFvPatchField<Type>(ptf),
-    phiName_(ptf.phiName_),
-    rhoName_(ptf.rhoName_)
-{}
-
-
-template<class Type>
-Foam::fanFvPatchField<Type>::fanFvPatchField
-(
-    const fanFvPatchField<Type>& ptf,
-    const DimensionedField<Type, volMesh>& iF
-)
-:
-    uniformJumpFvPatchField<Type>(ptf, iF),
-    phiName_(ptf.phiName_),
-    rhoName_(ptf.rhoName_)
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-template<class Type>
-void Foam::fanFvPatchField<Type>::updateCoeffs()
-{
-    if (this->updated())
-    {
-        return;
-    }
-
-    calcFanJump();
-
-    // Call fixedJump variant - uniformJump will overwrite the jump value
-    fixedJumpFvPatchField<Type>::updateCoeffs();
-}
-
-
-template<class Type>
-void Foam::fanFvPatchField<Type>::write(Ostream& os) const
-{
-    uniformJumpFvPatchField<Type>::write(os);
-    this->template writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
-    this->template writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
-}
-
-
-// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H
deleted file mode 100644
index 39c649a..0000000
--- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H
+++ /dev/null
@@ -1,219 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-
-Class
-    Foam::fanFvPatchField
-
-Description
-    This boundary condition provides a jump condition, using the \c cyclic
-    condition as a base.
-
-    The jump is specified as a \c Function1 type, to enable the use of, e.g.
-    constant, polynomial, table values.
-
-Usage
-    \table
-        Property     | Description             | Required    | Default value
-        patchType    | underlying patch type should be \c cyclic| yes |
-        jumpTable    | jump data, e.g. \c csvFile | yes      |
-        phi          | flux field name         | no          | phi
-        rho          | density field name      | no          | none
-    \endtable
-
-    Example of the boundary condition specification:
-    \verbatim
-    <patchName>
-    {
-        type            fan;
-        patchType       cyclic;
-        jumpTable       csvFile;
-        csvFileCoeffs
-        {
-            hasHeaderLine   1;
-            refColumn       0;
-            componentColumns 1(1);
-            separator       ",";
-            file           "$FOAM_CASE/constant/pressureVsU";
-        }
-        value           uniform 0;
-    }
-    \endverbatim
-
-    The above example shows the use of a comma separated (CSV) file to specify
-    the jump condition.
-
-Note
-     The underlying \c patchType should be set to \c cyclic
-
-See also
-    Foam::Function1Types
-
-SourceFiles
-    fanFvPatchField.C
-    fanFvPatchFields.H
-    fanFvPatchFields.C
-    fanFvPatchFieldsFwd.H
-
-\*---------------------------------------------------------------------------*/
-
-#ifndef fanFvPatchField_H
-#define fanFvPatchField_H
-
-#include "uniformJumpFvPatchField.H"
-#include "Function1.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
-
-/*---------------------------------------------------------------------------*\
-                       Class fanFvPatchField Declaration
-\*---------------------------------------------------------------------------*/
-
-template<class Type>
-class fanFvPatchField
-:
-    public uniformJumpFvPatchField<Type>
-{
-    // Private data
-
-        //- Name of the flux transporting the field
-        word phiName_;
-
-        //- Name of the density field used to normalise the mass flux
-        //  if necessary
-        word rhoName_;
-
-
-    // Private Member Functions
-
-        //- Calculate the fan pressure jump
-        void calcFanJump();
-
-
-public:
-
-    //- Runtime type information
-    TypeName("fan");
-
-
-    // Constructors
-
-        //- Construct from patch and internal field
-        fanFvPatchField
-        (
-            const fvPatch&,
-            const DimensionedField<Type, volMesh>&
-        );
-
-        //- Construct from patch, internal field and dictionary
-        fanFvPatchField
-        (
-            const fvPatch&,
-            const DimensionedField<Type, volMesh>&,
-            const dictionary&
-        );
-
-        //- Construct by mapping given fanFvPatchField onto a new patch
-        fanFvPatchField
-        (
-            const fanFvPatchField<Type>&,
-            const fvPatch&,
-            const DimensionedField<Type, volMesh>&,
-            const fvPatchFieldMapper&
-        );
-
-        //- Construct as copy
-        fanFvPatchField
-        (
-            const fanFvPatchField<Type>&
-        );
-
-        //- Construct and return a clone
-        virtual tmp<fvPatchField<Type>> clone() const
-        {
-            return tmp<fvPatchField<Type>>
-            (
-                new fanFvPatchField<Type>(*this)
-            );
-        }
-
-        //- Construct as copy setting internal field reference
-        fanFvPatchField
-        (
-            const fanFvPatchField<Type>&,
-            const DimensionedField<Type, volMesh>&
-        );
-
-        //- Construct and return a clone setting internal field reference
-        virtual tmp<fvPatchField<Type>> clone
-        (
-            const DimensionedField<Type, volMesh>& iF
-        ) const
-        {
-            return tmp<fvPatchField<Type>>
-            (
-                new fanFvPatchField<Type>(*this, iF)
-            );
-        }
-
-
-    // Member functions
-
-        //- Update the coefficients associated with the patch field
-        virtual void updateCoeffs();
-
-        //- Write
-        virtual void write(Ostream&) const;
-};
-
-
-//- Specialisation of the jump-condition for the pressure
-template<>
-void fanFvPatchField<scalar>::calcFanJump();
-
-template<>
-fanFvPatchField<scalar>::fanFvPatchField
-(
-    const fvPatch&,
-    const DimensionedField<scalar, volMesh>&,
-    const dictionary&
-);
-
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#ifdef NoRepository
-    #include "fanFvPatchField.C"
-#endif
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#endif
-
-// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C
deleted file mode 100644
index f5d33b7..0000000
--- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C
+++ /dev/null
@@ -1,99 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#include "fanFvPatchFields.H"
-#include "addToRunTimeSelectionTable.H"
-#include "volFields.H"
-#include "surfaceFields.H"
-#include "Tuple2.H"
-#include "PolynomialEntry.H"
-
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-template<>
-void Foam::fanFvPatchField<Foam::scalar>::calcFanJump()
-{
-    if (this->cyclicPatch().owner())
-    {
-        const surfaceScalarField& phi =
-            db().lookupObject<surfaceScalarField>(phiName_);
-
-        const fvsPatchField<scalar>& phip =
-            patch().patchField<surfaceScalarField, scalar>(phi);
-
-        scalarField Un(max(phip/patch().magSf(), scalar(0)));
-
-        if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
-        {
-            Un /= patch().lookupPatchField<volScalarField, scalar>(rhoName_);
-        }
-
-        this->jump_ = max(this->jumpTable_->value(Un), scalar(0));
-    }
-}
-
-
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-template<>
-Foam::fanFvPatchField<Foam::scalar>::fanFvPatchField
-(
-    const fvPatch& p,
-    const DimensionedField<scalar, volMesh>& iF,
-    const dictionary& dict
-)
-:
-    uniformJumpFvPatchField<scalar>(p, iF),
-    phiName_(dict.lookupOrDefault<word>("phi", "phi")),
-    rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
-{
-    if (this->cyclicPatch().owner())
-    {
-        this->jumpTable_ = Function1<scalar>::New("jumpTable", dict);
-    }
-
-    if (dict.found("value"))
-    {
-        fvPatchScalarField::operator=
-        (
-            scalarField("value", dict, p.size())
-        );
-    }
-    else
-    {
-        this->evaluate(Pstream::commsTypes::blocking);
-    }
-}
-
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
-    makeTemplatePatchTypeField(scalar, fan);
-}
-
-
-// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.H
deleted file mode 100644
index ad86908..0000000
--- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.H
+++ /dev/null
@@ -1,49 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#ifndef fanFvPatchFields_H
-#define fanFvPatchFields_H
-
-#include "fanFvPatchField.H"
-#include "fieldTypes.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-makePatchTypeFieldTypedefs(fan);
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#endif
-
-// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFieldsFwd.H
deleted file mode 100644
index b9775f9..0000000
--- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFieldsFwd.H
+++ /dev/null
@@ -1,50 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#ifndef fanFvPatchFieldsFwd_H
-#define fanFvPatchFieldsFwd_H
-
-#include "fieldTypes.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-template<class Type> class fanFvPatchField;
-
-makePatchTypeFieldTypedefs(fan);
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#endif
-
-// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.C
new file mode 100644
index 0000000..a9314fb
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.C
@@ -0,0 +1,228 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "fanPressureJumpFvPatchScalarField.H"
+#include "addToRunTimeSelectionTable.H"
+#include "volFields.H"
+#include "surfaceFields.H"
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::fanPressureJumpFvPatchScalarField::calcFanJump()
+{
+    const fvsPatchField<scalar>& phip =
+        patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
+
+    const bool massBasedFlux =
+        phip.internalField().dimensions() == dimDensity*dimVelocity*dimArea;
+
+    const scalar dir =  reverse_ ? -1 : 1;
+
+    //- Jump table is defined in backward compatibility mode
+    if(jumpTable_.valid())
+    {
+        //- Patch normal velocity field
+        scalarField Un(max(dir*phip/patch().magSf(), scalar(0)));
+
+        if (massBasedFlux)
+        {
+            const fvPatchField<scalar>& rhop =
+                patch().lookupPatchField<volScalarField, scalar>(rhoName_);
+
+            Un /= rhop;
+        }
+
+        jump_ = dir*max(jumpTable_->value(Un), scalar(0));
+    }
+    else
+    {
+        scalar volFlowRate = 0;
+
+        if (massBasedFlux)
+        {
+            const scalarField& rhop =
+                patch().lookupPatchField<volScalarField, scalar>(rhoName_);
+
+            volFlowRate = gSum(phip/rhop);
+        }
+        else
+        {
+            volFlowRate = gSum(phip);
+        }
+
+
+        jump_ = dir*max(fanCurve_->value(max(dir*volFlowRate, 0)), 0);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::fanPressureJumpFvPatchScalarField::fanPressureJumpFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    fixedJumpFvPatchScalarField(p, iF),
+    fanCurve_(),
+    jumpTable_(),
+    reverse_(false),
+    phiName_("phi"),
+    rhoName_("rho")
+{}
+
+
+Foam::fanPressureJumpFvPatchScalarField::fanPressureJumpFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const dictionary& dict
+)
+:
+    fixedJumpFvPatchScalarField(p, iF),
+    fanCurve_(),
+    jumpTable_(),
+    reverse_(dict.lookupOrDefault<Switch>("reverse", false)),
+    phiName_(dict.lookupOrDefault<word>("phi", "phi")),
+    rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
+{
+    if (cyclicPatch().owner())
+    {
+        if (dict.found("jumpTable"))
+        {
+            //- backward compatibility model
+            jumpTable_ = Function1<scalar>::New("jumpTable", dict);
+        }
+        else
+        {
+            fanCurve_ = Function1<scalar>::New("fanCurve", dict);
+        }
+    }
+
+    if (dict.found("value"))
+    {
+        fvPatchScalarField::operator=
+        (
+            scalarField("value", dict, p.size())
+        );
+    }
+    else
+    {
+        evaluate(Pstream::commsTypes::blocking);
+    }
+}
+
+
+Foam::fanPressureJumpFvPatchScalarField::fanPressureJumpFvPatchScalarField
+(
+    const fanPressureJumpFvPatchScalarField& ptf,
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const fvPatchFieldMapper& mapper
+)
+:
+    fixedJumpFvPatchScalarField(ptf, p, iF, mapper),
+    fanCurve_(ptf.fanCurve_, false),
+    jumpTable_(ptf.jumpTable_, false),
+    reverse_(ptf.reverse_),
+    phiName_(ptf.phiName_),
+    rhoName_(ptf.rhoName_)
+{}
+
+
+Foam::fanPressureJumpFvPatchScalarField::fanPressureJumpFvPatchScalarField
+(
+    const fanPressureJumpFvPatchScalarField& ptf
+)
+:
+    fixedJumpFvPatchScalarField(ptf),
+    fanCurve_(ptf.fanCurve_, false),
+    jumpTable_(ptf.jumpTable_, false),
+    reverse_(ptf.reverse_),
+    phiName_(ptf.phiName_),
+    rhoName_(ptf.rhoName_)
+{}
+
+
+Foam::fanPressureJumpFvPatchScalarField::fanPressureJumpFvPatchScalarField
+(
+    const fanPressureJumpFvPatchScalarField& ptf,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    fixedJumpFvPatchScalarField(ptf, iF),
+    fanCurve_(ptf.fanCurve_, false),
+    jumpTable_(ptf.jumpTable_, false),
+    reverse_(ptf.reverse_),
+    phiName_(ptf.phiName_),
+    rhoName_(ptf.rhoName_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::fanPressureJumpFvPatchScalarField::updateCoeffs()
+{
+    if (updated())
+    {
+        return;
+    }
+
+    if (cyclicPatch().owner())
+    {
+        calcFanJump();
+    }
+
+    fixedJumpFvPatchScalarField::updateCoeffs();
+}
+
+
+void Foam::fanPressureJumpFvPatchScalarField::write(Ostream& os) const
+{
+    fixedJumpFvPatchScalarField::write(os);
+
+    if (jumpTable_.valid()) jumpTable_->writeData(os);
+    if (fanCurve_.valid()) fanCurve_->writeData(os);
+
+    writeEntryIfDifferent<Switch>(os, "reverse", false, reverse_);
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    makePatchTypeField
+    (
+        fvPatchScalarField,
+        fanPressureJumpFvPatchScalarField
+    );
+};
+
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.H
new file mode 100644
index 0000000..e78ac2c
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressureJump/fanPressureJumpFvPatchScalarField.H
@@ -0,0 +1,212 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::fanPressureJumpFvPatchScalarField
+
+Description
+    This boundary condition provides a pressure jump condition, using
+    the \c cyclic condition as a base.
+
+    The jump is specified as a \c Function1 type, to enable the use of, e.g.
+    constant, polynomial, table values. This boundary condition can operate
+    in two modes - standard and backward compatibility.
+    In standard mode, jump is specified as a function of total volumetric
+    flow rate through the patch. In backward compatibility mode, the boundary
+    conditions serves as a direct replacement for the fanFvPatchField, where
+    jump is defined as a function of local velocity.
+
+Usage
+    \table
+        Property     | Description             | Required    | Default value
+        patchType    | underlying patch type should be \c cyclic| yes |
+        fanCurve     | fan curve, e.g. \c csvFile | yes      |
+        jumpTable    | jump data (backward compatibility mode) | no       |
+        reverse      | reverse jump direction  | no | false
+        phi          | flux field name         | no          | phi
+        rho          | density field name      | no          | rho
+    \endtable
+
+    Example of the boundary condition specification:
+    \verbatim
+    <patchName>
+    {
+        type            fan;
+        patchType       cyclic;
+        fanCurve       csvFile;
+        csvFileCoeffs
+        {
+            hasHeaderLine   1;
+            refColumn       0;
+            componentColumns 1(1);
+            separator       ",";
+            file           "$FOAM_CASE/constant/pressureVsQ";
+        }
+        value           uniform 0;
+    }
+    \endverbatim
+
+    The above example shows the use of a comma separated (CSV) file to specify
+    the jump condition.
+
+Note
+     The underlying \c patchType should be set to \c cyclic
+
+See also
+    Foam::Function1Types
+
+SourceFiles
+    fanPressureJumpFvPatchScalarField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef fanPressureJumpFvPatchScalarField_H
+#define fanPressureJumpFvPatchScalarField_H
+
+#include "fixedJumpFvPatchFields.H"
+#include "Function1.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+              Class fanPressureJumpFvPatchScalarField Declaration
+\*---------------------------------------------------------------------------*/
+
+class fanPressureJumpFvPatchScalarField
+:
+    public fixedJumpFvPatchScalarField
+{
+    // Private data
+
+        //- Fan curve
+        autoPtr<Function1<scalar>> fanCurve_;
+
+        //- Jump table (backward compatibility)
+        autoPtr<Function1<scalar>> jumpTable_;
+
+        //- Set true to reverse jump direction
+        Switch reverse_;
+
+        //- Name of the flux transporting the field
+        word phiName_;
+
+        //- Name of the density field used to normalise the mass flux
+        //  if necessary
+        word rhoName_;
+
+
+    // Private Member Functions
+
+        //- Calculate the fan pressure jump
+        void calcFanJump();
+
+
+public:
+
+    //- Runtime type information
+    TypeName("fanPressureJump");
+
+
+    // Constructors
+
+        //- Construct from patch and internal field
+        fanPressureJumpFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct from patch, internal field and dictionary
+        fanPressureJumpFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const dictionary&
+        );
+
+        //- Construct by mapping given patch onto a new patch
+        fanPressureJumpFvPatchScalarField
+        (
+            const fanPressureJumpFvPatchScalarField&,
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const fvPatchFieldMapper&
+        );
+
+        //- Construct as copy
+        fanPressureJumpFvPatchScalarField
+        (
+            const fanPressureJumpFvPatchScalarField&
+        );
+
+        //- Construct and return a clone
+        virtual tmp<fvPatchScalarField> clone() const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new fanPressureJumpFvPatchScalarField(*this)
+            );
+        }
+
+        //- Construct as copy setting internal field reference
+        fanPressureJumpFvPatchScalarField
+        (
+            const fanPressureJumpFvPatchScalarField&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct and return a clone setting internal field reference
+        virtual tmp<fvPatchField<scalar>> clone
+        (
+            const DimensionedField<scalar, volMesh>& iF
+        ) const
+        {
+            return tmp<fvPatchField<scalar>>
+            (
+                new fanPressureJumpFvPatchScalarField(*this, iF)
+            );
+        }
+
+
+    // Member functions
+
+        //- Update the coefficients associated with the patch field
+        virtual void updateCoeffs();
+
+        //- Write
+        virtual void write(Ostream&) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
2.7.4

fanPressureJump.patch (34,778 bytes)   

DanielJ

2018-11-08 06:18

reporter   ~0010166

Here is an implementation of proposed changes.

henry

2018-11-14 15:40

manager   ~0010185

Thanks Daniel

Resolved by commit ae28cb34d258b769da629fa8a1e4c7b757fc40a0

Issue History

Date Modified Username Field Change
2018-11-07 14:31 DanielJ New Issue
2018-11-07 14:53 henry Note Added: 0010153
2018-11-07 16:07 DanielJ Note Added: 0010155
2018-11-07 16:33 henry Note Added: 0010156
2018-11-07 16:42 DanielJ Note Added: 0010157
2018-11-07 16:53 henry Note Added: 0010158
2018-11-07 17:19 DanielJ Note Added: 0010159
2018-11-08 06:18 DanielJ File Added: fanPressureJump.patch
2018-11-08 06:18 DanielJ Note Added: 0010166
2018-11-14 15:40 henry Assigned To => henry
2018-11-14 15:40 henry Status new => resolved
2018-11-14 15:40 henry Resolution open => fixed
2018-11-14 15:40 henry Fixed in Version => dev
2018-11-14 15:40 henry Note Added: 0010185