I created a wall function for nuTilda.
It calculates nuTilda on wall patch faces from mut calculated by mutWallFunction by following equation (the red part of nuTildaWallFunctionFvPatchScalarField.C).
nuTildaWallFunctionFvPatchScalarField.H
\*---------------------------------------------------------------------------*/
#ifndef compressiblenuTildaWallFunctionFvPatchScalarField_H
#define compressiblenuTildaWallFunctionFvPatchScalarField_H
#include "fixedValueFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
class turbulenceModel;
/*---------------------------------------------------------------------------*\
Class nuTildaWallFunctionFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class nuTildaWallFunctionFvPatchScalarField
:
public fixedValueFvPatchField<scalar>
{
protected:
// Protected data
// Protected Member Functions
//- Check the type of the patch
virtual void checkType();
//- Main driver to calculate the turbulence fields
virtual tmp<scalarField> calcNuTilda() const;
public:
//- Runtime type information
TypeName("compressible::nuTildaWallFunction");
// Constructors
//- Construct from patch and internal field
nuTildaWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
nuTildaWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given
// nuTildaWallFunctionFvPatchScalarField
// onto a new patch
nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField&
);
//- Construct and return a clone
virtual tmp<fvPatchScalarField> clone() const
{
return tmp<fvPatchScalarField>
(
new nuTildaWallFunctionFvPatchScalarField(*this)
);
}
//- Construct as copy setting internal field reference
nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchScalarField> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchScalarField>
(
new nuTildaWallFunctionFvPatchScalarField(*this, iF)
);
}
//- Destructor
virtual ~nuTildaWallFunctionFvPatchScalarField()
{}
// Member functions
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace compressible
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
It calculates nuTilda on wall patch faces from mut calculated by mutWallFunction by following equation (the red part of nuTildaWallFunctionFvPatchScalarField.C).
nuTildaWallFunctionFvPatchScalarField.H
\*---------------------------------------------------------------------------*/
#ifndef compressiblenuTildaWallFunctionFvPatchScalarField_H
#define compressiblenuTildaWallFunctionFvPatchScalarField_H
#include "fixedValueFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
class turbulenceModel;
/*---------------------------------------------------------------------------*\
Class nuTildaWallFunctionFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class nuTildaWallFunctionFvPatchScalarField
:
public fixedValueFvPatchField<scalar>
{
protected:
// Protected data
// Protected Member Functions
//- Check the type of the patch
virtual void checkType();
//- Main driver to calculate the turbulence fields
virtual tmp<scalarField> calcNuTilda() const;
public:
//- Runtime type information
TypeName("compressible::nuTildaWallFunction");
// Constructors
//- Construct from patch and internal field
nuTildaWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
nuTildaWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given
// nuTildaWallFunctionFvPatchScalarField
// onto a new patch
nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField&
);
//- Construct and return a clone
virtual tmp<fvPatchScalarField> clone() const
{
return tmp<fvPatchScalarField>
(
new nuTildaWallFunctionFvPatchScalarField(*this)
);
}
//- Construct as copy setting internal field reference
nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchScalarField> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchScalarField>
(
new nuTildaWallFunctionFvPatchScalarField(*this, iF)
);
}
//- Destructor
virtual ~nuTildaWallFunctionFvPatchScalarField()
{}
// Member functions
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace compressible
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
nuTildaWallFunctionFvPatchScalarField.C
\*---------------------------------------------------------------------------*/
#include "nuTildaWallFunctionFvPatchScalarField.H"
#include "compressible/turbulenceModel/turbulenceModel.H"
#include "fvPatchFieldMapper.H"
#include "fvMatrix.H"
#include "volFields.H"
#include "wallFvPatch.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//defineTypeNameAndDebug(nuTildaWallFunctionFvPatchScalarField, 0);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void nuTildaWallFunctionFvPatchScalarField::checkType()
{
if (!isA<wallFvPatch>(patch()))
{
FatalErrorIn("nuTildaWallFunctionFvPatchScalarField::checkType()")
<< "Invalid wall function specification" << nl
<< " Patch type for patch " << patch().name()
<< " must be wall" << nl
<< " Current patch type is " << patch().type() << nl << endl
<< abort(FatalError);
}
}
tmp<scalarField> nuTildaWallFunctionFvPatchScalarField::calcNuTilda() const
{
const label patchi = patch().index();
const turbulenceModel& turbModel =
db().lookupObject<turbulenceModel>("turbulenceModel");
const fvPatchScalarField& muw = turbModel.mu().boundaryField()[patchi];
const volScalarField& mut = db().lookupObject<volScalarField>("mut");
const fvPatchScalarField& mutw = mut.boundaryField()[patchi];
const fvPatchScalarField& rhow = turbModel.rho().boundaryField()[patchi];
tmp<scalarField> tnuTildaw(new scalarField(patch().size(), 0.0));
scalarField& nuTildaw = tnuTildaw();
forAll(mutw, faceI)
{
scalar nu = muw[faceI]/rhow[faceI];
scalar nut = mutw[faceI]/rhow[faceI];
scalar nT = nut;
int iter = 0;
scalar nuTildaLast = 0.0;
do
{
nuTildaLast = nT;
nT = pow(pow3(nu)*(pow3(nT/nu) + pow3(7.1))*nut, 0.25);
} while (mag((nT - nuTildaLast)/max(nT, 1.0e-10)) > 0.01 && ++iter < 100);
nuTildaw[faceI] = max(0.0, nT);
}
return tnuTildaw;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
nuTildaWallFunctionFvPatchScalarField::nuTildaWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchField<scalar>(p, iF)
{
checkType();
}
nuTildaWallFunctionFvPatchScalarField::nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper)
{
checkType();
}
nuTildaWallFunctionFvPatchScalarField::nuTildaWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchField<scalar>(p, iF, dict)
{
checkType();
}
nuTildaWallFunctionFvPatchScalarField::nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField& wfpsf
)
:
fixedValueFvPatchField<scalar>(wfpsf)
{
checkType();
}
nuTildaWallFunctionFvPatchScalarField::nuTildaWallFunctionFvPatchScalarField
(
const nuTildaWallFunctionFvPatchScalarField& wfpsf,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchField<scalar>(wfpsf, iF)
{
checkType();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void nuTildaWallFunctionFvPatchScalarField::updateCoeffs()
{
if (updated())
{
return;
}
operator==(calcNuTilda());
fixedValueFvPatchField<scalar>::updateCoeffs();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField
(
fvPatchScalarField,
nuTildaWallFunctionFvPatchScalarField
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace compressible
} // End namespace Foam
// ************************************************************************* //
Comments
Post a Comment