CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Creating a symmTensorField from a scalarField (

maninthemail September 29, 2011 11:51

Creating a symmTensorField from a scalarField

I'm implementing a boundary condition for a symmTensor variable. I calculate a scalarField, and then want to apply it to the diagonal components of the symmTensorField. The fields are turbulent intensity and reynolds stress, though that really isn't important. The relevant (updateCoeffs) part of the code is as follows...


if (updated()) return;

// boundary velocity
const fvPatchVectorField& Up = patch().lookupPatchField<volVectorField, vector>(UName_);

// "value" is one third of the turbulent intensity
scalarField value = 0.5*sqr(intensity_)*magSqr(Up);

// "stress" is a symmetric tensor field with diagonal elements equal to "value"
symmTensorField stress;

// I don't know how to set the values in the tensor
 *          / value  0.0  0.0  \
 * stress = |  0.0  value  0.0  |
 *          \  0.0  0.0  value /



As you can see, it is transferring the scalarField values to the symmTensorField which I can't work out how to do. There are no existing derived tensor boundary conditions to copy off, so I'm stuck for ideas. If anyone could help, I'd be eternally grateful.

Many thanks, and apologies for reposting this. No-one replied to the last post I made, and I've had some time to re-formulate the question, hopefully a little more clearly.

Bernhard September 29, 2011 14:11

Did you already try something like this:

symmTensorField stress(value,0,0,value,0,value);
I am not sure if it works like this, but otherwise you may want to try:

symmTensor I(1,0,0,1,0,1);
symmTensorField stress=value*I;

However, for both I am not sure if it works, but it may give you some directions, good luck!

maninthemail September 30, 2011 04:13

The second of those works. Thank you very much.

All times are GMT -4. The time now is 17:22.