CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Macro existing for calculating a cell surface? (https://www.cfd-online.com/Forums/openfoam-post-processing/77029-macro-existing-calculating-cell-surface.html)

maximeg June 10, 2010 15:50

Macro existing for calculating a cell surface?
 
Hi everyone!

I'm a starter at openFOAM and I'd like to calculate the circulation around a 2D vortex (the simulation is done and I already have the coordinates of the point of maximum vorticity (<=> vortex center)).

To do so, I need to integrate the surface of cells in order to get a disc surrounding the vortex, and then sum up the product of each cell surface by the vorticity to get the final circulation:
"gamma(circulation)=sum(wi(vorticity at cell i) x Ai(surface of cell i))"

Is there a macro already existing allowing you to calculate the surface of each cell? I didn't find anything on the forum concerning that.
I would like to avoid doing something like that:
CellSurface(i)=[y(i+1)-y(i)].[x(i+1)-x(i)]

Thanks in advance for you're help!

Maxime

olesen June 11, 2010 03:32

Quote:

Originally Posted by maximeg (Post 262518)
Hi everyone!

I'm a starter at openFOAM and I'd like to calculate the circulation around a 2D vortex (the simulation is done and I already have the coordinates of the point of maximum vorticity (<=> vortex center)).

To do so, I need to integrate the surface of cells in order to get a disc surrounding the vortex, and then sum up the product of each cell surface by the vorticity to get the final circulation:
"gamma(circulation)=sum(wi(vorticity at cell i) x Ai(surface of cell i))"

Is there a macro already existing allowing you to calculate the surface of each cell? I didn't find anything on the forum concerning that.
I would like to avoid doing something like that:
CellSurface(i)=[y(i+1)-y(i)].[x(i+1)-x(i)]

Thanks in advance for you're help!

Maxime

In the fvMesh class
http://foam.sourceforge.net/doc/Doxy...1_1fvMesh.html

the Sf() and magSf() methods can be used to get the surface vector and the magnitude of the surface vector for the mesh faces, respectively.

the inherited cells() method
http://foam.sourceforge.net/doc/Doxy...h-members.html

allows you to find the faces corresponding to each cell.

maximeg June 14, 2010 11:49

Hi!
Here's the code for the calculation of the circulation, I'm really having a hard time finding out why it doesn't work:

// * * * * * * * * * * * * * * * * * *Circulation calculation (beginning)* * * * * * * * * * * * * * * * * * * * * * * * //

scalar circulation = 0.0;
scalar r = 0.0;
//scalar cell_area = 0.0;
const surfaceScalarField& magSf = mesh.magSf();

forAll(magVorticity, cellI)
{
//cell_area = (mesh.C()[cellI+1].component(0)-mesh.C()[cellI].component(0)).(mesh.C()[cellI+1].component(1)-mesh.C()[cellI].component(1)); // Surface of one cell

if (distance < r[cellI]) // If the radius stays inferior to r_c...
{
// circulation = circulation + magVorticity[cellI].cell_area[cellI]; // ...calculation of the circulation

circulation = circulation + magVorticity[cellI].magSf[cellI];
}

}

// * * * * * * * * * * * * * * * * * *Circulation calculation (end)* * * * * * * * * * * * * * * * * * * * * * * * //

The message given in the terminal is as follows (after I did wmake):

make: Warning: File `linux64GccDPOpt/options' has modification time 6e+02 s in the future
make: warning: Clock skew detected. Your build may be incomplete.
make: Warning: File `Make/linux64GccDPOpt/dontIncludeDeps' has modification time 6e+02 s in the future
Making dependency list for source file MaxVorCirc.C
make: warning: Clock skew detected. Your build may be incomplete.
make: Warning: File `MaxVorCirc.dep' has modification time 6e+02 s in the future
SOURCE=MaxVorCirc.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-40 -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/postProcessing/postCalc -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/finiteVolume/lnInclude -IlnInclude -I. -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/OpenFOAM/lnInclude -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/MaxVorCirc.o
MaxVorCirc.C: In function ‘void Foam::calc(const Foam::argList&, const Foam::Time&, const Foam::fvMesh&)’:
MaxVorCirc.C:86: error: invalid types ‘Foam::scalar[Foam::label]’ for array subscript
MaxVorCirc.C:93: error: request for member ‘magSf’ in ‘magVorticity.Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField <double, Foam::volMesh>::<anonymous>.Foam::Field<double>::< anonymous>.Foam::List<double>::<anonymous>.Foam::U List<T>::operator[] [with T = double](cellI)’, which is of non-class type ‘double’
MaxVorCirc.C:80: warning: unused variable ‘magSf’
make: *** [Make/linux64GccDPOpt/MaxVorCirc.o] Error 1

Any help given would be very appreciated.
Thanking you in advance,
Maxime

maximeg June 14, 2010 15:49

Just to make it a little bit more clear (updated version also):

I have to calculate the circulation in a vortex. My code is as follows:

Code:

#include "calc.H"
#include "fvc.H"

void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{

    volScalarField magVorticity        // Imports the results of the vortex vorticity
    (                   
        IOobject           
        (               
            "magVorticity",       
            runTime.timeName(),       
            mesh,           
            IOobject::MUST_READ,   
            IOobject::AUTO_WRITE   
        ),               
        mesh               
    );     

    scalar circulation = 0.0;
    scalar r = 0.0;
    const volScalarField& magSf = mesh.magSf();

    forAll(magVorticity, cellI)
    {

        if (distance < r[cellI])        // If the radius (distance) stays lower than the critical radius (r)...
        {
            circulation += magSf.magVorticity[cellI];    // ...calculation of the circulation.
        }

    }

}

The error message I get in the terminal is as follows:

Code:

SOURCE=MaxVorCirc.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-40 -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/postProcessing/postCalc -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/finiteVolume/lnInclude -IlnInclude -I. -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/OpenFOAM/lnInclude -I/usr/local/OpenFOAM/OpenFOAM-1.6/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/MaxVorCirc.o
MaxVorCirc.C: In function ‘void Foam::calc(const Foam::argList&, const Foam::Time&, const Foam::fvMesh&)’:
MaxVorCirc.C:89: error: invalid types ‘Foam::scalar[Foam::label]’ for array subscript
MaxVorCirc.C:94: error: ‘magSf’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/MaxVorCirc.o] Error 1

Any help would be very appreciated.

Thank you in advance!

Maxime

olesen June 15, 2010 02:23

Please re-read my previous post. You are, for example, trying to use a surfaceScalarField (which is defined for mesh faces) for cells, and lots of other dubious things.

maximeg June 17, 2010 18:04

Hello,
I'd like to know how I can access/choose the area (of only one of the 6 faces) of a internal cubical finite volume (not near a patch).
I know I have to use the magSf command, but I don't know which face area (or which direction) of the finite volume it gives me.
Thank you.
Maxime

AlterSchwede July 13, 2010 07:37

Hey maximeg,

Have you solved your problem in order to calculate the circulation? In my simulation (flow around around a car) I need to calculate the circulation as well, but here for rectangular "boxes" around the car.

Can you help me out with some advice?

Thanks in advance,

\AlterSchwede

maximeg July 13, 2010 13:30

Quote:

Originally Posted by AlterSchwede (Post 267038)
Hey maximeg,

Have you solved your problem in order to calculate the circulation? In my simulation (flow around around a car) I need to calculate the circulation as well, but here for rectangular "boxes" around the car.

Can you help me out with some advice?

Thanks in advance,

\AlterSchwede

Hi!
No, unfortunately I didn't find what I was looking for. I calculated the surface manually instead (not hard but not general). I don't think you'll be able to do that though (in my case, all the cells have the same size).
If you find anything please let me know.
Maxime


All times are GMT -4. The time now is 20:40.