# How to compute a better gradient for sharp fields on unstructured mesh.

 Register Blogs Members List Search Today's Posts Mark Forums Read

Rate this Entry

# How to compute a better gradient for sharp fields on unstructured mesh.

Posted January 31, 2012 at 10:40 by tomislav_maric

In case you are dealing with sharp fields, there are multiple options to choose from. Usually, the literature recommends the "least squares approach", or linear regression. In order to get somewhere with this, the least squares points should pick up the skew cells , not just the normal own-nei surrounding cells in OpenFOAM. Still, there is a workaround that works fine:

#1) IDW interpolation of cell values to mesh points
#2) create a surface*field
#3) average the point values for each face and store this in the surface*field
#4) feed the surface*field to the Gauss with the flavor of interpolation that suits your taste (I used plain linear).

Here's the code:

Code:
```// Node averaging of the point values.
const Time& runTime = alpha1.time();

surfaceScalarField alpha1f
(
IOobject
(
"alpha1f",
runTime.timeName(),
mesh_,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar
(
"0",
alpha1.dimensions(),
0
)
);

// Compute the point averaged face values: internal field.
forAll (owner, I)
{
forAll(meshFaces[I], J)
{
alpha1f[I] += alpha1point[meshFaces[I][J]];
}
alpha1f[I] /= meshFaces[I].size();
}

// TODO: Compute the point averaged face values: boundary field.

// Compute the field gradient from the averaged point valuues using
// standard available schemes.

Please notice the TODO. I'm currently away from the BCs, so I left it like this for the time being.

This may help those that see mesh dependent behaviour of their solvers, if your fields are distributed in a wrong way once the dominated convection/advection direction becomes collinear with the skew direction of the mesh (cell point neighbours), this may help.

A Multi-Dimensional Linear Reconstruction Scheme for Arbitrary Unstructured Grids

on the net. Please comment this if you have some ideas xor you find it useful.
Posted in Uncategorized