CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   create volTensorField from volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/81938-create-voltensorfield-volscalarfield.html)

stevenvanharen November 11, 2010 06:27

create volTensorField from volScalarField
 
Hi does anyone have an idea how to create a volTensorField from volScalarField.

For instance I have volScalarField a and want to create the following volTensorField:

random example:

[a , 0 ,0,
a, 0 ,0,
0, 0, a]

How do I program this?

boger November 12, 2010 10:19

You could always set each value explicitly; e.g.
Code:

    forAll(T,cellI)
    {
      T[cellI].xx() = a[cellI];
    }

but in your case, what about something like this:
Code:

    tensor select(1,0,0,1,0,0,0,0,1);
    T = a*select;

or more directly
Code:

T = a*tensor(1,0,0,1,0,0,0,0,1);
In all cases, a is a volScalarField and T a volTensorField.

stevenvanharen November 15, 2010 03:23

Hi David,

no I solved it like this:

volTensorField T
(
IOobject
(
"Transform",
runTime.timeName(),
mesh
//IOobject::NO_READ
//IOobject::NO_WRITE
),
mesh,
tensor(0,0,0,0,0,0,0,0,0)
);
T=tensor(0,0,0,0,0,0,1,0,0)+(tensor(0,-1,0,0,0,0,0,0,0)*sin(theta))+(tensor(0,0,1,0,0,0,0 ,0,0)*cos(theta))+(tensor(0,0,0,0,-1,0,0,0,0)*cos(theta))+(tensor(0,0,0,0,0,-1,0,0,0)*sin(theta));
T.write();

Where theta is a volScalarField.

So there really is no constructor which can handle volScalarFields as an argument I guess.

P.S. How do I post code like you? Couldn't find how to do it but it looks more nice.

olesen November 16, 2010 02:22

Quote:

Originally Posted by stevenvanharen (Post 283455)
...
P.S. How do I post code like you? Couldn't find how to do it but it looks more nice.

If you are posting with the WYSIWYG forum editor, use the '#' from the toolbar. This wraps "[ CODE ]" ... "[/ CODE ]" tags around the selected text, but of course without the spaces that I've need to add in order to post it.

stevenvanharen November 16, 2010 03:16

Ok, thanks!

Code:

Cool


All times are GMT -4. The time now is 13:41.