CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)

 lentschi March 3, 2011 08:44

Defining additionally variables of U in OF 1.6

Hello,

I am an OF Newbie and want to set up a case of a pump turbine in OF 1.6.
Therefor I have to integrate some additionally variables of the Velocity in 3 different local coordinate systems, such as:

U_new1=Ux*cos(10°)+Uy*sin(10°)
U_new2=Ux*cos(12°)+Uy*sin(12°)
U_new3=Ux*cos(30°)+Uy*sin(30°)

Can anyone tell me, where I have to define this 3 velocities and in which Script I have to perform this Integration?
Or do you think it's better to output the standard Velocity U and transform it later during post?

Regards Markus

 gwierink March 5, 2011 08:51

Hi Markus,

The x-component of a field, here U, is U.component(0). The y- and z-components would be U.component(1) and U.component(2), respectively. Now, the way you have written it gives a volScalarField, not a volVectorField (like U itself). For instance, you could plug the following in the solver after U is solved:
Code:

```scalar angle1 = mathematicalConstant::pi/6.0; volScalarField Unew =     U.component(0) * Foam::cos(angle1)  + U.component(1) * Foam::sin(angle1);```
This calculates a field of scalars that consist of Ux*cos(pi/6) + Uy*sin(pi/6), where cos and sin use rad. But the field is not written every time step. For that you need to put
Code:

```Info << "Reading field Unew\n" << endl; volScalarField Unew (     IOobject     (         "Unew",         runTime.timeName(),         mesh,         IOobject::MUST_READ,         IOobject::AUTO_WRITE     ),     mesh );```
in createFields.H. Then, you don't need to specify the type of Unew in the code, i.e. leave out "volScalarField" in the code that calculates Unew. If you use "MUST_READ" in createFields.H you need to make a file in the 0 folder of the case, where the initial and boundary conditions of Unew are specified.

If you'd like to write every time step, function objects are handy. In your case probably the turboPerformance function objects. Hope this helps you on your way a bit!

 lentschi March 7, 2011 09:56

Hy Gijsbert,

thank you very much for your instruction!Now, I have to think about if it's necessary to perfom the transformation during solving - in my opinion this may rise the calculation time?!
For this reason I think it's much easier to output only the velocity U and to create a script in python during post,which transform it to local coordinate systems.

Regards Markus

 gwierink March 7, 2011 10:10

Hi Markus,

Sure, the calculation, although small, will take some time. You could use the U file in the time step directories. This, however, only gives you data at write time. If you need data at every time step I suggest to either use a function object or put the above code in and write out the data in an info statement to a log file. For that simply add
Code:

`Info << "Unew = " << Unew << endl;`
to the solver, run the solver with
Code:

`somethingFoam > log &`
and grep Unew from the log file.

 All times are GMT -4. The time now is 15:35.