CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   lift and drag coefficient (http://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 17: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 05: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 11: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 05: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 09: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 11: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 11: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 12:00

no still doesn't do anything.

boger January 7, 2011 12: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.


All times are GMT -4. The time now is 04:05.