From e34b84ec1be63ead2e30e1357ea1020f2bdf8d02 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Tue, 9 Feb 2016 12:24:18 +0000
Subject: [PATCH] fixedMeanFvPatchField: Added support for time-varying
 mean-value

---
 .../derived/fixedMean/fixedMeanFvPatchField.C | 33 ++++++++++---------
 .../derived/fixedMean/fixedMeanFvPatchField.H | 20 +++++------
 2 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C
index e1eebee79c..8f5d8f41ba 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012-2015 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012-2016 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -36,34 +36,34 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
 )
 :
     fixedValueFvPatchField<Type>(p, iF),
-    meanValue_(pTraits<Type>::zero)
+    meanValue_()
 {}
 
 
 template<class Type>
 Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
 (
-    const fixedMeanFvPatchField<Type>& ptf,
     const fvPatch& p,
     const DimensionedField<Type, volMesh>& iF,
-    const fvPatchFieldMapper& mapper
+    const dictionary& dict
 )
 :
-    fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
-    meanValue_(ptf.meanValue_)
+    fixedValueFvPatchField<Type>(p, iF, dict),
+    meanValue_(Function1<Type>::New(dict.lookup("meanValue"), dict))
 {}
 
 
 template<class Type>
 Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
 (
+    const fixedMeanFvPatchField<Type>& ptf,
     const fvPatch& p,
     const DimensionedField<Type, volMesh>& iF,
-    const dictionary& dict
+    const fvPatchFieldMapper& mapper
 )
 :
-    fixedValueFvPatchField<Type>(p, iF, dict),
-    meanValue_(pTraits<Type>(dict.lookup("meanValue")))
+    fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
+    meanValue_(ptf.meanValue_, false)
 {}
 
 
@@ -74,7 +74,7 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
 )
 :
     fixedValueFvPatchField<Type>(ptf),
-    meanValue_(ptf.meanValue_)
+    meanValue_(ptf.meanValue_, false)
 {}
 
 
@@ -86,7 +86,7 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
 )
 :
     fixedValueFvPatchField<Type>(ptf, iF),
-    meanValue_(ptf.meanValue_)
+    meanValue_(ptf.meanValue_, false)
 {}
 
 
@@ -100,19 +100,22 @@ void Foam::fixedMeanFvPatchField<Type>::updateCoeffs()
         return;
     }
 
+    const scalar t = this->db().time().timeOutputValue();
+    Type meanValue = meanValue_->value(t);
+
     Field<Type> newValues(this->patchInternalField());
 
     Type meanValuePsi =
         gSum(this->patch().magSf()*newValues)
        /gSum(this->patch().magSf());
 
-    if (mag(meanValue_) > SMALL && mag(meanValuePsi)/mag(meanValue_) > 0.5)
+    if (mag(meanValue) > SMALL && mag(meanValuePsi)/mag(meanValue) > 0.5)
     {
-        newValues *= mag(meanValue_)/mag(meanValuePsi);
+        newValues *= mag(meanValue)/mag(meanValuePsi);
     }
     else
     {
-        newValues += (meanValue_ - meanValuePsi);
+        newValues += (meanValue - meanValuePsi);
     }
 
     this->operator==(newValues);
@@ -125,7 +128,7 @@ template<class Type>
 void Foam::fixedMeanFvPatchField<Type>::write(Ostream& os) const
 {
     fvPatchField<Type>::write(os);
-    os.writeKeyword("meanValue") << meanValue_ << token::END_STATEMENT << nl;
+    meanValue_->writeData(os);
     this->writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.H
index cddd17d298..757a3aad31 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.H
@@ -29,13 +29,14 @@ Group
 
 Description
     This boundary condition extrapolates field to the patch using the near-cell
-    values and adjusts the distribution to match the specified mean value.
+    values and adjusts the distribution to match the specified, optionally
+    time-varying, mean value.
 
     \heading Patch usage
 
     \table
         Property     | Description             | Required    | Default value
-        meanValue    | mean value              | yes         |
+        meanValue    | mean value Function1    | yes         |
     \endtable
 
     Example of the boundary condition specification:
@@ -49,6 +50,7 @@ Description
 
 SeeAlso
     Foam::fixedValueFvPatchField
+    Foam::Function1Types
 
 SourceFiles
     fixedMeanFvPatchField.C
@@ -59,6 +61,7 @@ SourceFiles
 #define fixedMeanFvPatchField_H
 
 #include "fixedValueFvPatchFields.H"
+#include "Function1.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -74,13 +77,10 @@ class fixedMeanFvPatchField
 :
     public fixedValueFvPatchField<Type>
 {
-
-protected:
-
-    // Protected data
+    // Private data
 
         //- MeanValue value the field is adjusted to maintain
-        Type meanValue_;
+        autoPtr<Function1<Type>> meanValue_;
 
 
 public:
@@ -153,10 +153,8 @@ public:
 
     // Member functions
 
-        // Evaluation functions
-
-            //- Update the coefficients associated with the patch field
-            virtual void updateCoeffs();
+        //- Update the coefficients associated with the patch field
+        virtual void updateCoeffs();
 
         //- Write
         virtual void write(Ostream&) const;
-- 
GitLab