I've noticed a lot of people are asking how to add source terms of diffusion of UDSs to either UDS eqns or maybe other eqns.

The source is d/dx( T d(phi)/dx)) where phi is a UDS scalar and T = T(x,y,z) is a vector for the directional diffusivity.

Find below my code for calculating this. Its not complete (some helper functions are missing) and I'm not going to explain it in detail. But it should give you guys some idea.

The basic principle is to go back to the finite volume conservation of fluxes for the entire volume. Fluxes thus depend on the gradient across faces times face properties - which are calculated as the average of the neighbour cells. If you don't understand please read the book by Patankar - Nuemrical heat Transfer 1980.

One other thing about this code - I know it works, but since I wrote is for FLUENT 5.x the udf documentation has imprved a lot and you might be able to make it more efficient by using internal FLUENT Macros etc.

For example, there are FLUENT macros for the vector routines, which I have written (not shown) and called.

Also it may be useful to rewrite it using the _RG gradients suggested by Kim (below). This will speed up tinsg alot, since the astute reader will notice for neighbour cells my routine re-calculates the gradient on each side of the face for each cell. Thus the computations are much greater than they need be if these are stored. Anyway if you make improvements, please post them so I can use them too!!!