Bug: Several wall functions use wrong cell-to-wall distance
Summary
I recently updated a larger job from v2212 to v2412, but it no longer worked: Instable after some time steps.
I was able to boil the problem down to the new wall distance calculation (https://develop.openfoam.com/Development/openfoam/-/issues/3215) which Mattijs introduced in v2412. Switching to the old implementation healed the problem apparently.
Digging deeper I saw that the distance calculation is not really the culprit, it is fine. It took me by surprise to realise that the above change only uncovered a very, very old bug: In several wall functions the value used for the distance from the face center to the cell center is wrong, if cells have more than one wall face connected.
Reason:
Several wall functions use "y = turbModel.y()[patchi]" to access the wall distance. This is wrong: It delivers access to the minimum distance from the cell center to the nearest wall face, which is not necessarily the face for which the wall function is being evaluated. This results in the wrong value of y to be used and thus in the instability observed.
Its hard to believe that this sits here at least since 1.6.x.
Steps to reproduce
Recompile v2412 or the latest dev-version with the attached source file in place.
src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkRoughWallFunction/nutkRoughWallFunctionFvPatchScalarField.C nutkRoughWallFunctionFvPatchScalarField.C
Run the supplied example with interFoam. example.zip
Example case
The case uses a very simple anisotropic 3x3x3 grid with dx=dy=1m and dz=0.1 m. Thus, the cell-center-to-wall distance should be 0.5m for the faces of patch ymin and 0.05m for zmin.
What is the current bug behaviour?
The console protocol reports the wall distances as:
Patch: ymin y: 9(0.05 0.5 0.05 0.05 0.5 0.05 0.05 0.5 0.05)
Patch: zmin y: 9(0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05)
This is wrong for ymin. The value should be 0.5 everywhere.
What is the expected correct behavior?
The computed wall distance for ymin should be 0.5 m for faces.
Relevant logs and/or images
See above.
Environment information
OpenFOAM version : all versions since 1.6.x
Possible fixes
Steps:
- Identify all files which are potentially affected:
grep -r "turbModel.y()" $FOAM_SRC| grep derivedFvPatchFields
-
Check the correctness of using the "minimum cell to wall" distance instead of "face to cell center" distance.
-
For affected files, exchange the line
const scalarField& y = turbModel.y()[patchi];
with
scalarField y(1./this->patch().deltaCoeffs());
This can be necessary more than once per file.
I also prepared a merge request for this: !773