CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   lift and drag coefficient (https://www.cfd-online.com/Forums/openfoam/81081-lift-drag-coefficient.html)

lift86 October 15, 2010 06:42

lift and drag coefficient
 
Hello, I am new to open foam, I'm trying the tutorial 2d airfoil (simplefoam incompressible). I can not see the values of lift and drag coefficients. I have to put in the contol dict lines you suggested, but I get nothing. How can I do? thanks

functions
{
forces
{
type forces;
functionObjectLibs ( "libforces.so" ); // lib to load
outputControl timeStep;
outputInterval 1;
patches
(
wall // change to your patch name
);
// name of fields
pName p;
UName U;
log true; // dump to file
rhoInf 1025;
CofR ( 0 0 0 );
}
forcesCoeffs
{
type forceCoeffs;
functionObjectLibs ( "libforces.so" ); // lib to load
outputControl timeStep;
outputInterval 1;
patches
(
wall // change to your patch name
);
// name of fields
pName p;
UName U;
log true; // dump to file
rhoInf 1025;
CofR ( 0 0 0 );
liftDir ( 0 1 0 );
dragDir ( 1 0 0 );
pitchAxis ( 0 0 0 );
magUInf 7.30;
lRef 0.305;
Aref 0.001525;
}
}
:mad:

velezisaza October 18, 2010 07:47

The script looks fine, are you placing it in the controlDict? I also had some troubles running it in openfoam 1.7. In 1.6 however it works perfectly. Try it!

If you want moment coefficient you have to change the pitch axis to 0 0 1

vkrastev October 21, 2010 04:02

Have you changed "wall" with the name of the patch (or patches) composing the airfoil?

lift86 October 21, 2010 05:06

I use open foam nn 1.7.1 but nothing happens, even if the procedure is correct. In your opinion, should I download the library "libforces?

velezisaza October 22, 2010 08:46

Check if you have the libforces.so library, its shoulf be in OpenFoam1.7.1/lib/linux64GccDPOpt/libforces.so

My problem with openfoam 1.7.1 is that it says that it cannot locate p and U, so it deactivates "forces". But the same script in 1.6 works perfectly fine. Vesselin, have you tried it yourself in 1.7.0 or 1.7.1?

vkrastev October 22, 2010 09:50

Quote:

Originally Posted by velezisaza (Post 280321)
Check if you have the libforces.so library, its shoulf be in OpenFoam1.7.1/lib/linux64GccDPOpt/libforces.so

My problem with openfoam 1.7.1 is that it says that it cannot locate p and U, so it deactivates "forces". But the same script in 1.6 works perfectly fine. Vesselin, have you tried it yourself in 1.7.0 or 1.7.1?

Unfortunately I do not have much experience with the 1.7.x versions, but I have noticed that there are several different particulars between those versions and the 1.6 one: for instance, the interFoam solver of the latest versions uses a different definition of the pressure, and so on...However, the script I use to calculate the force coefficients (in the 1.6 version) is slightly different from the one posted above: don't know if it makes some difference, but maybe you could try it in the 1.7.x one

Regards

V.

ps-the name of the function is not significant: it simply determines the name of the directory in which the forceCoeffs data will be stored

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application simpleFoam;

startFrom latestTime;

startTime 0;

stopAt endTime;

endTime 5000;

deltaT 1;

writeControl runTime;

writeInterval 500;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression uncompressed;

timeFormat general;

timePrecision 6;

runTimeModifiable yes;

functions
{
totalDrag
{
// rhoInf - reference density
// CofR - Centre of rotation
// dragDir - Direction of drag coefficient
// liftDir - Direction of lift coefficient
// pitchAxis - Pitching moment axis
// magUinf - free stream velocity magnitude
// lRef - reference length
// Aref - reference area
type forceCoeffs;
functionObjectLibs ("libforces.so");
patches ( body );
rhoName rhoInf;
rhoInf 1.184;
CofR (0 0 0);
liftDir (0 1 0);
dragDir (1 0 0);
pitchAxis (0 0 1);
magUInf 40;
lRef 0.288;
Aref 0.0561;

outputControl timeStep;
outputInterval 50;
}

lift86 October 25, 2010 05:56

Hello. I am studying the case of a cylinder.
these are the files that I put:

{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application simpleFoam;

startFrom latestTime;

startTime 0;

stopAt endTime;

endTime 500;

deltaT 1;

writeControl timeStep;

writeInterval 50;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression uncompressed;

timeFormat general;

timePrecision 6;

runTimeModifiable yes;


functions
{
forces
{
type forces;
functionObjectLibs ( "libforces.so" ); // lib to load
outputControl timeStep;
outputInterval 1;
patches
(
wall // change to your patch name
);
// name of fields
pName p;
UName U;
log true; // dump to file
rhoInf 1025;
CofR ( 0 0 0 );
}
forcesCoeffs
{
type forceCoeffs;
functionObjectLibs ( "libforces.so" ); // lib to load
outputControl timeStep;
outputInterval 1;
patches
(
wall // change to your patch name
);
// name of fields
pName p;
UName U;
log true; // dump to file
rhoInf 1025;
CofR ( 0 0 0 );
liftDir ( 0 1 0 );
dragDir ( 1 0 0 );
pitchAxis ( 0 0 0 );
magUInf 7.30;
lRef 0.305;
Aref 0.001525;
}
}

// Definition of terms:
// rhoInf - reference density
// CofR - Centre of rotation
// dragDir - Direction of drag coefficient
// liftDir - Direction of lift coefficient
// pitchAxis - Pitching moment axis
// magUinf - free stream velocity magnitude
// lRef - reference length
// Aref - reference area


FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -2 0 0 0 0];

internalField uniform 101325;

boundaryField
{
inlet
{
type freestreamPressure;
}

outlet
{
type freestreamPressure;
}

wall
{
type zeroGradient;
}

frontAndBack
{
type empty;
}
}


FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (30 0 0);

boundaryField
{
inlet
{
type freestream;
freestreamValue uniform (30 0 0);
}

outlet
{
type freestream;
freestreamValue uniform (30 0 0);
}

wall
{
type fixedValue;
value uniform (0 0 0);
}

frontAndBack
{
type empty;
}
}
how do I get the CD and Cp Cl??

lift86 October 25, 2010 06:12

i have also this error in the terminal(when i start the iteraction):

--> FOAM Warning :
From function void forces::read(const dictionary& dict)
in file forces/forces.C at line 277
Could not find U, p or rho in database.
De-activating forces.

velezisaza October 26, 2010 07:40

I had the same error but now its working fine. As Vesselin used, I removed the pName and uName inputs, and added the rhoName rhoInf.

It works perfect now with 1.7.1

Girolarno, I hope it works for you as well

lift86 October 26, 2010 08:12

Thank you so much you were very kind ...... but you may be able to plot the pressure coefficient on the wall? How do you do for plotting?

velezisaza October 26, 2010 09:49

Pressure coefficient is another story. For that you use the sampling utility. You need the following file in your system directory: sampleDict.

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/

FoamFile
{
version 2.0;
format ascii;
class dictionary;
location system;
object sampleDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Set output format : choice of
// xmgr
// jplot
// gnuplot
// raw
setFormat raw;

// Surface output format. Choice of
// null : suppress output
// foamFile : separate points, faces and values file
// dx : DX scalar or vector format
// vtk : VTK ascii format
// raw : x y z value format for use with e.g. gnuplot 'splot'.
//
// Note:
// other formats such as obj, stl, etc can also be written (by proxy)
// but without any values!
surfaceFormat raw;

// interpolationScheme. choice of
// cell : use cell-centre value only; constant over cells (default)
// cellPoint : use cell-centre and vertex values
// cellPointFace : use cell-centre, vertex and face values.
// 1] vertex values determined from neighbouring cell-centre values
// 2] face values determined using the current face interpolation scheme
// for the field (linear, gamma, etc.)
interpolationScheme cellPoint;

// Fields to sample.
fields
(
p
);


// Set sampling definition: choice of
// uniform evenly distributed points on line
// face one point per face intersection
// midPoint one point per cell, inbetween two face intersections
// midPointAndFace combination of face and midPoint
//
// curve specified points, not nessecary on line, uses
// tracking
// cloud specified points, uses findCell
//
// axis: how to write point coordinate. Choice of
// - x/y/z: x/y/z coordinate only
// - xyz: three columns
// (probably does not make sense for anything but raw)
// - distance: distance from start of sampling line (if uses line) or
// distance from first specified sampling point
//
// type specific:
// uniform, face, midPoint, midPointAndFace : start and end coordinate
// uniform: extra number of sampling points
// curve, cloud: list of coordinates
sets
(

);


// Surface sampling definition: choice of
// plane : values on plane defined by point, normal.
// patch : values on patch.
//
// 1] patches are not triangulated by default
// 2] planes are always triangulated
// 3] iso-surfaces are always triangulated
surfaces
(
airfoil
{
type patch; // always triangulated
patchName Airfoil;
}
slat
{
type patch;
patchName Slat;
}
);


// ************************************************** ********************* //


I got this from a tutorial, I don't remember which one, and its also explained in the user guide.
After running your simulation you run the sample utility. After that you can use matlab or excel to calculate the Cp.

Good luck!

anijdon December 18, 2010 16:22

Hello Alejandro,
excuse me, I have an basically question because I'm not sure.
Is it enough that add mentioned lines to controlDict for calculating drag/lift coefficient in a steady state simulation? or we should copy other specific directories in our own case and use specific command during simulate?
in this way can we use sampleDict to plot these coefficients?
thanks

velezisaza December 19, 2010 04:21

Hi,

To calculate the drag and lift coefficient, the lines inside the controlDict are enough. After running the simulation you should have a directory in your case directory called forceCoeffs or whatever name you give to your function in your controlDict. after that, what I did was import the data in matlab and then plot it, but that depends on you.

This is are the lines I added. I also include the field average in case you need it at a later stage.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.5 |
| \\ / A nd | Web: http://www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application simpleFoam;

startFrom startTime;

startTime 10000;

stopAt endTime;

endTime 20000;

deltaT 1;

writeControl runTime;

writeInterval 2000;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression uncompressed;

timeFormat general;

timePrecision 6;

runTimeModifiable yes;


functions
{
forceCoeffs_combi
{
type forceCoeffs;
functionObjectLibs ("libforces.so");
outputControl timeStep;
enabled true;
outputInterval 1;
patches
(
Slat
Airfoil
);
rhoName rhoInf;
log true;
rhoInf 1.225;
CofR (0 0 0);
liftDir (-0.309 0.95106 0);
dragDir (0.95106 0.309 0);
pitchAxis (0 0 1);
magUInf 51;
lRef 0.3;
Aref 0.0081;
}

forceCoeffs_airfoil
{
type forces;
functionObjectLibs ("libforces.so");
outputControl timeStep;
enabled false;
outputInterval 1;
patches
(
Airfoil
);
log true;
rhoInf 1.225;
CofR (0 0 0);
liftDir (-0.309 0.95106 0);
dragDir (0.95106 0.309 0);
pitchAxis (0 0 1);
magUInf 51;
lRef 0.3;
Aref 0.0075;
}

forceCoeffs_slat
{
type forces;
functionObjectLibs ("libforces.so");
outputControl timeStep;
enabled false;
outputInterval 1;
patches
(
Slat
);
pName p;
UName U;
log true;
rhoInf 1.225;
CofR (0 0 0);
liftDir (-0.309 0.95106 0);
dragDir (0.95106 0.309 0);
pitchAxis (0 0 1);
magUInf 51;
lRef 0.3;
Aref 0.0001566;
}

fieldAverage1
{
type fieldAverage;
functionObjectLibs ("libfieldFunctionObjects.so");
enabled true;
outputControl timeStep;
outputInterval 2000;
fields
(
U
{
mean on;
prime2Mean on;
base time;
}

p
{
mean on;
prime2Mean on;
base time;
}
);
}

}

// ************************************************** *********************** //

anijdon December 19, 2010 10:38

Hello,
I thank you for your helping, but I don't know what's the usage of field average and why we should obtain it?
thanks

inginer December 21, 2010 04:20

forces.dat information
 
Hello,

i have a 2d airfoil and i used simpleFoam to run the case; i have the coefficient lift, drag and momentum. also, i have the forces calculated.
my question is: when i open the forces.dat (were are the forces) file i have on the first line time, forces(pressure, viscous) momentum(pressure, viscous)
and the second line i have 13 colones of numbers, corresponding to time, forces and momentum. but, why do i have 12(+1 the time) and not 9(+1 the time)?

best,
Ovidiu

boger December 22, 2010 08:34

Based on the first line, the 12 columns are the pressure and viscous component of the force, and the pressure and viscous component of the moment. Since each of these 4 items is a vector, you have 12 columns. Plus time.

Eren10 January 7, 2011 10:49

I have put the required function in the controlDict file, but after running there happens nothing. I was just testing an airfoil with icoFoam app. I even copied the functions from an tutorial.

functions
{
forces
{
type forceCoeffs;
functionObjectLibs ( "libforces.so" );
outputControl timeStep;
outputInterval 1;
patches
(
AirFoil // this consists of the lower and the upper camber, defined as a wall in the BC
);
pName p;
UName U;
log true;
rhoInf 1;
CofR ( 0 0 0 );
liftDir (0 1 0);
dragDir (1 0 0);
pitchAxis ( 0 0 1 );
magUInf 25;
lRef 1;
Aref 1;
}
}

boger January 7, 2011 10:54

What if you use parentheses rather than braces for the list of functions and a semicolon at the end?

Code:

functions
(
  forces
  {
  ...
  }
);


Eren10 January 7, 2011 11:00

no still doesn't do anything.

boger January 7, 2011 11:06

I just pasted your entry (with the modifications I already mentioned) into my controlDict and I got the desired output in forces/0/forceCoeffs.dat.

Eren10 January 7, 2011 11:14

Quote:

Originally Posted by boger (Post 289617)
I just pasted your entry (with the modifications I already mentioned) into my controlDict and I got the desired output in forces/0/forceCoeffs.dat.


this is really strange, there happens nothing at mine case ( the case is running well)

this is mine controlDict. ( i am using 1.7.1 version )

FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application icoFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

endTime 0.5;

deltaT 0.0005;

writeControl timeStep;

writeInterval 20;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression uncompressed;

timeFormat general;

timePrecision 6;

runTimeModifiable yes;

functions
(
forces
{
type forceCoeffs;
functionObjectLibs ( "libforces.so" );
outputControl timeStep;
outputInterval 1;
patches
(
AirFoil
);
pName p;
UName U;
log true;
rhoInf 1;
CofR ( 0 0 0 );
liftDir (0 1 0);
dragDir (1 0 0);
pitchAxis ( 0 0 1 );
magUInf 25;
lRef 1;
Aref 1;
}
);

boger January 7, 2011 11:22

I'm using 1.6-ext, so if there's a difference caused by 1.7.x, I'm not familiar with it.

Eren10 January 9, 2011 18:02

how can I see the content of libforces.so (any lib file ) ?

If someone here uses 1.7x version please check for me if the libforces.so works as I have cited here .

boger January 9, 2011 18:39

Content of the library? Do you mean the source code? You can see it here. Go to "classes" and then pick "forces" from the list.

Eren10 January 9, 2011 18:57

Quote:

Originally Posted by boger (Post 289783)
Content of the library? Do you mean the source code? You can see it here. Go to "classes" and then pick "forces" from the list.

Thank you. I am trying to understand how the calculations are programmed and I am looking what the possibilities are. maybe after this I can use the abilities of OpenFOAM much better :)

aerothermal January 27, 2011 16:28

Dear foamers,

the sampleDict sent by velezisaza worked well for me.
i am working to get Cp from a cylinder in a tunnel.
however, the sample tool provided me all data on patch.

How can I extract pressure information in a line, i.e., in the patch intersection with a plane (like normal to Z and at 0,0,0) ? Should I do it by hand? Does openfoam have a tool for this?

regards,

Akuji March 16, 2011 05:00

Hello!

I've got a question about
liftDir (0 1 0);
dragDir (0 0 1);
pitchAxis (0 0 0);

liftDir and dragDir : Lift and Drag direction vectors are specified
. But, if I ser liftDir (0 0.1 0) I have another result of Cd. So, how is right to set lift and drag Dir?


And, what is pitchAxis? I blow on a box, Did I need it?

jms March 16, 2011 11:11

Dear all,

I am using this function that it is needed in controlDict in orer to get the lift, drag and moment coefficients for a computation of the flow around an airfoil. The results I get for the lift and drag coefficients are very good compared to the reference I am using for both lift and drag coefficients but they are very bad for the moment coefficients. I use CofR=0.25*chord.
Any idea why I am getting this bad results?

Thanks,

José

anijdon March 17, 2011 04:40

hello.
I want to figure drag coefficient on walls of a cube which is located in a flat plane in 3D. I put
·rhoInf : the density of fluid.
·MagUinf : uniform velocity in the upstream of cube.
·Aref : the area of each cube's surface
· lref :the length of each cube's edge
· dragDir : flow direction (Uinlet=(1,0,0) in 0 directory)
but this result is not true:confused:. would you tell me my mistakes?
thanks.

Eren10 May 20, 2011 10:59

Hi,

I have only replaced the mesh on the tutorial incom/simplefoam/airfoil2D. I want to check the Cl , Cd values. the airfoil size is the real size on the mesh.

But I get nonsense values. I am using openfoam 1.7.1, with the following function:

functions
{
forceCoeffs
{
type forceCoeffs;
functionObjectLibs ("libforces.so");
patches (UpperCamber LowerCamber TrailingEdge);
log true
pName p;
Uname U;
rhoName rhoInf;
rhoInf 1.225;
magUInf 25;
CofR (0.25 0 0);
liftDir (0 1 0);
dragDir (1 0 0);
pitchAxis (0 0 -1);
lRef 1;
Aref 1;

outputControl timeStep;
outputInterval 1;
}
}


How can I solve this issue :confused:. Because I am using the tutorials I assume that the flow is correct.

Eren10 May 21, 2011 08:13

Can someone please obtain the Cl, Cd, Cm values for the tutorial case , incompressible/simpleFoam/airFoil2D

I am using 1.7.1 version, I can't get the right values. I am almost thinking of a bug :o

Akuji May 21, 2011 12:35

Quote:

Originally Posted by Eren10 (Post 308679)
Can someone please obtain the Cl, Cd, Cm values for the tutorial case , incompressible/simpleFoam/airFoil2D

I am using 1.7.1 version, I can't get the right values. I am almost thinking of a bug :o


Did you try to change patches?

Eren10 May 21, 2011 15:53

Quote:

Originally Posted by Akuji (Post 308696)
Did you try to change patches?

I have tried to get the coefficients for the given mesh in the tutorial (airFoil2D) as well as the mesh that I have drawn, both failed :o

Can someone maybe write here the obtained coefficients of tutorial airFoil2D case ? I will compare it with obtained value of the 1.71 version.

Eren10 May 23, 2011 09:58

can someone help me about this issue ?

Eren10 July 5, 2011 09:34

I have obtained lift and drag from forceCoefficients. I have also calculated lift and the drag using the data of wallShearStress and the pressure distribution.

The results are:


Cd Cl
forceCoeff: 0.0113219 0.339877

calculatedMatlab: 0.009311 0.33927


Cl value is close, but the discrepancy of the Cd value is too big. From the experiments the Cd value should be around 0.00889 (airfoil).
Am I doing something wrong ? or is it the forceCoeffs ??????



*if someone wants to test it I can send mine matlab file.

Eren10 July 5, 2011 11:36

Quote:

Originally Posted by Eren10 (Post 314779)
I have obtained lift and drag from forceCoefficients. I have also calculated lift and the drag using the data of wallShearStress and the pressure distribution.

The results are:


Cd Cl
forceCoeff: 0.0113219 0.339877

calculatedMatlab: 0.009311 0.33927


Cl value is close, but the discrepancy of the Cd value is too big. From the experiments the Cd value should be around 0.00889 (airfoil).
Am I doing something wrong ? or is it the forceCoeffs ??????



*if someone wants to test it I can send mine matlab file.


When I multiply the value of the calculatedMatlab with the density 1.225, I get 0.0114, almost the same value from forceCoeffs.


Can someone please explain why I have to multiply the " skin friction coefficient ( obtained from the wallShearStress" with the density to get the same value ? ( incompressible flow)

Akuji July 5, 2011 14:28

Quote:

Originally Posted by Eren10 (Post 314804)

When I multiply the value of the calculatedMatlab with the density 1.225, I get 0.0114, almost the same value from forceCoeffs.


Can someone please explain why I have to multiply the " skin friction coefficient ( obtained from the wallShearStress" with the density to get the same value ? ( incompressible flow)

Can you send main matlab file? (attach to the post)

Eren10 July 6, 2011 12:34

Quote:

Originally Posted by Akuji (Post 314824)
Can you send main matlab file? (attach to the post)


I get now the same values. Sorry :o

Fransje August 28, 2011 17:56

To all users using version 1.7.*, and having the dreaded:
Quote:

Could not find U, p or rho in database
error, here is a work around to get the test case running.

Simply add, in the function definitions:
Quote:

rhoName rhoInf;
To have something like:
Quote:

functions
{
forces
{
type forceCoeffs;
functionObjectLibs ( "libforces.so" );
outputControl timeStep;
outputInterval 1;
patches
(
wall
);
pName p;
UName U;
log true;
rhoName rhoInf;
rhoInf 1;
CofR ( 0 0 0 );
liftDir ( 0 1 0 );
dragDir ( 1 0 0 );
pitchAxis ( 0 0 1 );
magUInf 30;
lRef 1;
Aref 1;
}
}
Kind regards,

Francois.

hfs October 21, 2012 10:08

Quote:

Originally Posted by aerothermal (Post 292547)
Dear foamers,

the sampleDict sent by velezisaza worked well for me.
i am working to get Cp from a cylinder in a tunnel.
however, the sample tool provided me all data on patch.

How can I extract pressure information in a line, i.e., in the patch intersection with a plane (like normal to Z and at 0,0,0) ? Should I do it by hand? Does openfoam have a tool for this?

regards,


Hello!
Did you figure this out?!

I need the same. I need the Cp values on a point on the patch, i.e., in the patch intersection with a line (with given y, z and parallel to x for example)

Could you please let me know how can I get that?

Thanks!


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