/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
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 .
\*---------------------------------------------------------------------------*/
#include "turbulentInletFvPatchField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::turbulentInletFvPatchField::turbulentInletFvPatchField
(
const fvPatch& p,
const DimensionedField& iF
)
:
fixedValueFvPatchField(p, iF),
ranGen_(label(0)),
fluctuationScale_(Zero),
referenceField_(p.size()),
alpha_(0.1),
curTimeIndex_(-1)
{}
template
Foam::turbulentInletFvPatchField::turbulentInletFvPatchField
(
const fvPatch& p,
const DimensionedField& iF,
const dictionary& dict
)
:
fixedValueFvPatchField(p, iF, dict, IOobjectOption::NO_READ),
ranGen_(label(0)),
fluctuationScale_(dict.get("fluctuationScale")),
referenceField_("referenceField", dict, p.size()),
alpha_(dict.getOrDefault("alpha", 0.1)),
curTimeIndex_(-1)
{
if (!this->readValueEntry(dict))
{
fvPatchField::operator=(referenceField_);
}
}
template
Foam::turbulentInletFvPatchField::turbulentInletFvPatchField
(
const turbulentInletFvPatchField& ptf,
const fvPatch& p,
const DimensionedField& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchField(ptf, p, iF, mapper),
ranGen_(label(0)),
fluctuationScale_(ptf.fluctuationScale_),
referenceField_(ptf.referenceField_, mapper),
alpha_(ptf.alpha_),
curTimeIndex_(-1)
{}
template
Foam::turbulentInletFvPatchField::turbulentInletFvPatchField
(
const turbulentInletFvPatchField& ptf
)
:
fixedValueFvPatchField(ptf),
ranGen_(ptf.ranGen_),
fluctuationScale_(ptf.fluctuationScale_),
referenceField_(ptf.referenceField_),
alpha_(ptf.alpha_),
curTimeIndex_(-1)
{}
template
Foam::turbulentInletFvPatchField::turbulentInletFvPatchField
(
const turbulentInletFvPatchField& ptf,
const DimensionedField& iF
)
:
fixedValueFvPatchField(ptf, iF),
ranGen_(ptf.ranGen_),
fluctuationScale_(ptf.fluctuationScale_),
referenceField_(ptf.referenceField_),
alpha_(ptf.alpha_),
curTimeIndex_(-1)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
void Foam::turbulentInletFvPatchField::autoMap
(
const fvPatchFieldMapper& m
)
{
fixedValueFvPatchField::autoMap(m);
referenceField_.autoMap(m);
}
template
void Foam::turbulentInletFvPatchField::rmap
(
const fvPatchField& ptf,
const labelList& addr
)
{
fixedValueFvPatchField::rmap(ptf, addr);
const turbulentInletFvPatchField& tiptf =
refCast>(ptf);
referenceField_.rmap(tiptf.referenceField_, addr);
}
template
void Foam::turbulentInletFvPatchField::updateCoeffs()
{
if (this->updated())
{
return;
}
if (curTimeIndex_ != this->db().time().timeIndex())
{
Field& patchField = *this;
Field randomField(this->size());
forAll(patchField, facei)
{
ranGen_.randomise01(randomField[facei]);
}
// Correction-factor to compensate for the loss of RMS fluctuation
// due to the temporal correlation introduced by the alpha parameter.
scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;
patchField =
(1 - alpha_)*patchField
+ alpha_*
(
referenceField_
+ rmsCorr*cmptMultiply
(
randomField - 0.5*pTraits::one,
fluctuationScale_
)*mag(referenceField_)
);
curTimeIndex_ = this->db().time().timeIndex();
}
fixedValueFvPatchField::updateCoeffs();
}
template
void Foam::turbulentInletFvPatchField::write(Ostream& os) const
{
fvPatchField::write(os);
os.writeEntry("fluctuationScale", fluctuationScale_);
referenceField_.writeEntry("referenceField", os);
os.writeEntry("alpha", alpha_);
fvPatchField::writeValueEntry(os);
}
// ************************************************************************* //