CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Diagonal elements of a volTensorField (

CpCaniggia September 22, 2010 05:47

Diagonal elements of a volTensorField
Dear All,

I need to compute the diagonal elements of a volTensorField. The tensor field has the form,

volTensorField tmp ("tmp", fvc::grad(U));

It seems OpenFoam 1.6 doesn't have a function like diag(tmp). Does OpenFoam 1.7 have such kinds of function? Do any people know how to compute the diagonal elements?

Many thanks,
Y. J.

eugene September 23, 2010 11:06

If you want the sum of the diagonal elements then:

volScalarField trTmp = tr(tmp);

If you just want the diagonal components, then


will provide the individual fields.

All times are GMT -4. The time now is 01:50.