change the k at first grid?
-
Hi guys,
I would like to change the k value in the first grid near wall by the following formulation:
kc=(U\tau)^2/sqrt(Cmu);
I wrote the code, according to epsilonwallfunction, but I met the problem when I compile it.
derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C: In member function 'virtual void Foam::kOngWallFunctionFvPatchScalarField::updateCo effs()': derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C:218:120: error: assignment of read-only location '(& k)->Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam:imensionedField <double, Foam::volMesh>::<anonymous>.Foam::Field<double>::< anonymous>.Foam::List<double>::<anonymous>.Foam::U List<double>:perator[](celli)' ((nutw[facei] + nuw[facei])*magGradUw[facei])*((nutw[facei] + nuw[facei])*magGradUw[facei])/(Cmu25*Cmu2 ); my codes in kwallfunction: const scalarField& y = turbModel.y()[patchi]; const tmp<volScalarField> tk = turbModel.k(); const volScalarField& k = tk(); const tmp<scalarField> tnuw = turbModel.nu(patchi); const scalarField& nuw = tnuw(); const tmp<scalarField> tnutw = turbModel.nut(patchi); const scalarField& nutw = tnutw(); const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi]; const scalarField magGradUw(mag(Uw.snGrad())); forAll(nutw,facei) { label celli = patch().faceCells()[facei]; scalar yPlus = Cmu25*y[facei]*sqrt(k[celli])/nuw[facei]; if (yPlus > yPlusLam_) { k[celli] = ((nutw[facei] + nuw[facei])*magGradUw[facei])*((nutw[facei] + nuw[facei])*magGradUw[facei])/(Cmu25*Cmu25); }
-
@东岳 Hi, dongyue. Thanks a lot. I understood this method but can I use it in a kwallfunction? After I tried the code you suggested, the compiling error is mesh not decalred in this scope. If I would like to update the first grid value in the kwallfunction like epsilonwallfunction did, is it possible?
-
the compiling error is mesh not decalred in this scope
Looks you used that in a Class. Try to include the following code snippet before you use it:
const fvMesh& mesh = k.mesh();
If I would like to update the first grid value in the kwallfunction like epsilonwallfunction did, is it possible?
Everything is possible as long as it is physical.
-
@东岳
derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C: In member function 'virtual void Foam::kOngWallFunctionFvPatchScalarField::updateCoeffs()': derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C:190:40: error: 'class Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >' has no member named 'mesh' const fvMesh& mesh = turbModel.k().mesh();
-
@东岳
derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C: In member function 'virtual void Foam::kOngWallFunctionFvPatchScalarField::updateCoeffs()': derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C:204:22: error: 'p' was not declared in this scope const fvMesh& mesh = p.boundaryMesh().mesh(); ^ derivedFvPatchFields/wallFunctions/kqRWallFunctions/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C:209:28: error: passing 'const volScalarField {aka const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}' as 'this' argument discards qualifiers [-fpermissive] k.boundaryFieldRef()[patchID] = 0;
-
You should highlight you code yourself. Otherwise I need modify it everytime.
The above code runs well if your put it inside the following
template<class Type> Foam::kqRWallFunctionFvPatchField<Type>::kqRWallFunctionFvPatchField ( const kqRWallFunctionFvPatchField& ptf, const fvPatch& p, const DimensionedField<Type, volMesh>& iF, const fvPatchFieldMapper& mapper ) : zeroGradientFvPatchField<Type>(ptf, p, iF, mapper) { const fvMesh& mesh = p.boundaryMesh().mesh(); }
-
Hi Dongyue, I changed the codes as following, but the result dosn't change, k in the first grid is still not calculated by my formulation. I cannot understand.
tmp<volScalarField> tk = turbModel.k(); volScalarField k = tk; const tmp<scalarField> tnuw = turbModel.nu(patchi); const scalarField& nuw = tnuw(); const tmp<scalarField> tnutw = turbModel.nut(patchi); const scalarField& nutw = tnutw(); const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi]; const scalarField magGradUw(mag(Uw.snGrad())); const scalar Cmu25 = pow025(Cmu_); scalarField& kw = *this; forAll(nutw,facei) { label celli = patch().faceCells()[facei]; k[celli] = ((nutw[facei] + nuw[facei])*magGradUw[facei])*((nutw[facei] + nuw[facei])*magGradUw[facei])/(Cmu25*Cmu25); }
-
@东岳 I tried to write these codes in simpleFoam.C,
label patchID = mesh.boundaryMesh().findPatchID("wall"); turbulence->k().boundaryFieldRef()[patchID] = 0; And I got the error: newsimpleFoam.C: In function 'int main(int, char**)': newsimpleFoam.C:77:25: error: 'class Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >' has no member named 'boundaryFieldRef' turbulence->k().boundaryFieldRef()[patchID] = 0;