/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "nutUSpaldingWallFunctionFvPatchScalarField.H"
#include "turbulenceModel.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::tmp
Foam::nutUSpaldingWallFunctionFvPatchScalarField::calcNut() const
{
const label patchi = patch().index();
const turbulenceModel& turbModel = db().lookupObject
(
IOobject::groupName
(
turbulenceModel::propertiesName,
internalField().group()
)
);
const fvPatchVectorField& Uw = U(turbModel).boundaryField()[patchi];
const scalarField magGradU(mag(Uw.snGrad()));
const tmp tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();
// Calculate new viscosity
tmp tnutw
(
max
(
scalar(0),
sqr(calcUTau(magGradU))/(magGradU + ROOTVSMALL) - nuw
)
);
if (tolerance_ != 0.01)
{
// User-specified tolerance. Find out if current nut already satisfies
// eqns.
// Run ut for one iteration
scalarField err;
tmp UTau(calcUTau(magGradU, 1, err));
// Preserve nutw if the initial error (err) already lower than the
// tolerance.
scalarField& nutw = tnutw.ref();
forAll(err, facei)
{
if (err[facei] < tolerance_)
{
nutw[facei] = this->operator[](facei);
}
}
}
return tnutw;
}
Foam::tmp
Foam::nutUSpaldingWallFunctionFvPatchScalarField::calcUTau
(
const scalarField& magGradU
) const
{
scalarField err;
return calcUTau(magGradU, maxIter_, err);
}
Foam::tmp
Foam::nutUSpaldingWallFunctionFvPatchScalarField::calcUTau
(
const scalarField& magGradU,
const label maxIter,
scalarField& err
) const
{
const label patchi = patch().index();
const turbulenceModel& turbModel = db().lookupObject
(
IOobject::groupName
(
turbulenceModel::propertiesName,
internalField().group()
)
);
const scalarField& y = turbModel.y()[patchi];
const fvPatchVectorField& Uw = U(turbModel).boundaryField()[patchi];
const scalarField magUp(mag(Uw.patchInternalField() - Uw));
const tmp tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();
const scalarField& nutw = *this;
tmp tuTau(new scalarField(patch().size(), Zero));
scalarField& uTau = tuTau.ref();
err.setSize(uTau.size());
err = 0.0;
forAll(uTau, facei)
{
scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);
// Note: for exact restart seed with laminar viscosity only:
//scalar ut = sqrt(nuw[facei]*magGradU[facei]);
if (ROOTVSMALL < ut)
{
int iter = 0;
do
{
scalar kUu = min(kappa_*magUp[facei]/ut, 50);
scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
scalar f =
- ut*y[facei]/nuw[facei]
+ magUp[facei]/ut
+ 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
scalar df =
y[facei]/nuw[facei]
+ magUp[facei]/sqr(ut)
+ 1/E_*kUu*fkUu/ut;
scalar uTauNew = ut + f/df;
err[facei] = mag((ut - uTauNew)/ut);
ut = uTauNew;
//iterations_++;
} while
(
ut > ROOTVSMALL
&& err[facei] > tolerance_
&& ++iter < maxIter
);
uTau[facei] = max(0.0, ut);
//invocations_++;
//if (iter > 1)
//{
// nontrivial_++;
//}
//if (iter >= maxIter_)
//{
// nonconvergence_++;
//}
}
}
return tuTau;
}
void Foam::nutUSpaldingWallFunctionFvPatchScalarField::writeLocalEntries
(
Ostream& os
) const
{
nutWallFunctionFvPatchScalarField::writeLocalEntries(os);
os.writeEntryIfDifferent