fixedMeanFvPatchField: Added support for time-varying mean-value

This commit is contained in:
Henry Weller 2016-02-09 12:24:18 +00:00
parent 798f13d81b
commit e34b84ec1b
2 changed files with 34 additions and 33 deletions

View file

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -36,7 +36,20 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
) )
: :
fixedValueFvPatchField<Type>(p, iF), fixedValueFvPatchField<Type>(p, iF),
meanValue_(pTraits<Type>::zero) meanValue_()
{}
template<class Type>
Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchField<Type>(p, iF, dict),
meanValue_(Function1<Type>::New(dict.lookup("meanValue"), dict))
{} {}
@ -50,20 +63,7 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
) )
: :
fixedValueFvPatchField<Type>(ptf, p, iF, mapper), fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
meanValue_(ptf.meanValue_) meanValue_(ptf.meanValue_, false)
{}
template<class Type>
Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchField<Type>(p, iF, dict),
meanValue_(pTraits<Type>(dict.lookup("meanValue")))
{} {}
@ -74,7 +74,7 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
) )
: :
fixedValueFvPatchField<Type>(ptf), fixedValueFvPatchField<Type>(ptf),
meanValue_(ptf.meanValue_) meanValue_(ptf.meanValue_, false)
{} {}
@ -86,7 +86,7 @@ Foam::fixedMeanFvPatchField<Type>::fixedMeanFvPatchField
) )
: :
fixedValueFvPatchField<Type>(ptf, iF), fixedValueFvPatchField<Type>(ptf, iF),
meanValue_(ptf.meanValue_) meanValue_(ptf.meanValue_, false)
{} {}
@ -100,19 +100,22 @@ void Foam::fixedMeanFvPatchField<Type>::updateCoeffs()
return; return;
} }
const scalar t = this->db().time().timeOutputValue();
Type meanValue = meanValue_->value(t);
Field<Type> newValues(this->patchInternalField()); Field<Type> newValues(this->patchInternalField());
Type meanValuePsi = Type meanValuePsi =
gSum(this->patch().magSf()*newValues) gSum(this->patch().magSf()*newValues)
/gSum(this->patch().magSf()); /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 else
{ {
newValues += (meanValue_ - meanValuePsi); newValues += (meanValue - meanValuePsi);
} }
this->operator==(newValues); this->operator==(newValues);
@ -125,7 +128,7 @@ template<class Type>
void Foam::fixedMeanFvPatchField<Type>::write(Ostream& os) const void Foam::fixedMeanFvPatchField<Type>::write(Ostream& os) const
{ {
fvPatchField<Type>::write(os); fvPatchField<Type>::write(os);
os.writeKeyword("meanValue") << meanValue_ << token::END_STATEMENT << nl; meanValue_->writeData(os);
this->writeEntry("value", os); this->writeEntry("value", os);
} }

View file

@ -29,13 +29,14 @@ Group
Description Description
This boundary condition extrapolates field to the patch using the near-cell 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 \heading Patch usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default value
meanValue | mean value | yes | meanValue | mean value Function1 | yes |
\endtable \endtable
Example of the boundary condition specification: Example of the boundary condition specification:
@ -49,6 +50,7 @@ Description
SeeAlso SeeAlso
Foam::fixedValueFvPatchField Foam::fixedValueFvPatchField
Foam::Function1Types
SourceFiles SourceFiles
fixedMeanFvPatchField.C fixedMeanFvPatchField.C
@ -59,6 +61,7 @@ SourceFiles
#define fixedMeanFvPatchField_H #define fixedMeanFvPatchField_H
#include "fixedValueFvPatchFields.H" #include "fixedValueFvPatchFields.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -74,13 +77,10 @@ class fixedMeanFvPatchField
: :
public fixedValueFvPatchField<Type> public fixedValueFvPatchField<Type>
{ {
// Private data
protected:
// Protected data
//- MeanValue value the field is adjusted to maintain //- MeanValue value the field is adjusted to maintain
Type meanValue_; autoPtr<Function1<Type>> meanValue_;
public: public:
@ -153,10 +153,8 @@ public:
// Member functions // 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 //- Write
virtual void write(Ostream&) const; virtual void write(Ostream&) const;