CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

exp() function not working?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 23, 2014, 22:10
Default exp() function not working?
  #1
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Hello,

For some reason I don't think that exp() is doing anything... can you please tell me what you think is wrong?

I have the following code:
Code:
argf2 = sqr(k_)/(6.0*nu()*epsilon_);
f2 = 1-2/9*Foam::exp(-1.0*sqr(argf2));
I can tell that argf2 is doing what is supposed to.
However, when I bring up f2 in paraview it just shows up as 1 everywhere.

If I define f2 in the following way:
Code:
f2 = 99-2/9*Foam::exp(-1.0*sqr(argf2));
f2 shows up as 99 everywhere.

If I define f2 in the following way:
Code:
f2 = -2/9*Foam::exp(-1.0*sqr(argf2));
Then the field f2 shows up as 0, even if it was initialized as a different value.

I have also tried to not use "Foam::" before exp() and it doesn't make a difference.

Additionally, when I look at the f2 that was output to the time directory it looks like this:
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.2.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0.001";
    object      f2;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 0 0 0 0];

internalField   uniform 1;

boundaryField
{
    plate
    {
        type            calculated;
        value           uniform 1;
    }
    back
    {
        type            empty;
    }
    front
    {
        type            empty;
    }
    inlet
    {
        type            calculated;
        value           uniform 1;
    }
    outlet
    {
        type            calculated;
        value           uniform 1;
    }
    top
    {
        type            calculated;
        value           uniform 1;
    }
    symmetry
    {
        type            symmetryPlane;
    }
}


// ************************************************************************* //
when in reality it should be an internalField nonuniform List<scalar>


Thank you!
CHARLES is offline   Reply With Quote

Old   April 24, 2014, 05:31
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

Code:
1-2/9*Foam::exp(-1.0*sqr(argf2))
2/9 is 0 as it is integer division. So your problem is not with exp but with 2/9 that should be 2.0/9.0 (or if you'd like 2 and 9 then you can write it as 2*Foam::exp(...)/9, in this case nominator will be converted to double due to exp function)
alexeym is offline   Reply With Quote

Old   April 24, 2014, 14:30
Default
  #3
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Thank you Alexey!

Adding the ".0" to each integer made a difference. Instead of f2 being set to 1 everywhere, it is being set to 0.777778 (i.e.: 1.0 - 2.0/9.0). OpenFOAM still doesn't recognize the
Code:
Foam::exp(-1.0*sqr(argf2))
. Even if I try to define f2 as
Code:
f2 = 1-2.0*Foam::exp(-1.0*sqr(argf2))/9.0;
When I open the f2 output in the time directory, I see that it is still shown as
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.2.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0.001";
    object      f2;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 0 0 0 0];

internalField   uniform 1;

boundaryField
{
    plate
    {
        type            calculated;
        value           uniform 0.777778;
    }
    back
    {
        type            empty;
    }
    front
    {
        type            empty;
    }
    inlet
    {
        type            calculated;
        value           uniform 1;
    }
    outlet
    {
        type            calculated;
        value           uniform 1;
    }
    top
    {
        type            calculated;
        value           uniform 1;
    }
    symmetry
    {
        type            symmetryPlane;
    }
}


// ************************************************************************* //
instead of the nonuniform list.

Do you think it may have something to do with the way I have initialized f2 and argf2?

Code:
    argf2
    (
        IOobject
        (
            "argf2",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_,
        dimensionedScalar("argf2", dimless, 0.0)
    ),
    f2
    (
        IOobject
        (
            "f2",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_,
        dimensionedScalar("f2", dimless, 1.0)
    )
Code:
argf2= sqr(k_)/(6.0*nu()*epsilon_);
f2 = 1-2.0/9.0*Foam::exp(-1.0*sqr(argf2));
CHARLES is offline   Reply With Quote

Old   April 24, 2014, 14:56
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi!

Well, as I don't know other values in your problem, I'll try to guess

Code:
argf2= sqr(k_)/(6.0*nu()*epsilon_);
f2 = 1-2.0/9.0*Foam::exp(-1.0*sqr(argf2));
k_ is of order of unity, epsilon_ is almost like k_, nu is around 1e-7, so argf2 should be something around 1e6. And exp(-1e12), I guess it's just 0. At the plate patch argf2 is zero, so f2 there is equal 1 - 2.0/9.0.
alexeym is offline   Reply With Quote

Old   April 29, 2014, 14:07
Default
  #5
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Alexey,

My values for the internal field in the 0 folder are the following:
k=2.16e-3
epsilon=6.27e-4

nu=1.53e-5

which would make argf2=(2.16e-3)^2/(6*1.53e-5*6.27e-4)=81.06 (based on initial conditions)

Based on your argument, I can tell that f2 should in fact approach 0.77778!
exp(-1.0*sqr(argf2)) = 0 -> f2=1.0-2.0/9.0

Thank you.

Now the next question is why does OpenFOAM not create the nonuniform list <scalar>?
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.2.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0.001";
    object      f2;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 0 0 0 0];

internalField   uniform 1;

boundaryField
{
    plate
    {
        type            calculated;
        value           uniform 0.777778;
    }
    back
    {
        type            empty;
    }
    front
    {
        type            empty;
    }
    inlet
    {
        type            calculated;
        value           uniform 1;
    }
    outlet
    {
        type            calculated;
        value           uniform 1;
    }
    top
    {
        type            calculated;
        value           uniform 1;
    }
    symmetry
    {
        type            symmetryPlane;
    }
}


// ************************************************************************* //
CHARLES is offline   Reply With Quote

Old   April 29, 2014, 14:24
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

Quote:
Originally Posted by CHARLES View Post
...
which would make argf2=(2.16e-3)^2/(6*1.53e-5*6.27e-4)=81.06 (based on initial conditions)

Based on your argument, I can tell that f2 should in fact approach 0.77778!
exp(-1.0*sqr(argf2)) = 0 -> f2=1.0-2.0/9.0
No, it should not.

Code:
f2 = 1.0 - 2.0/9.0*exp(-sqr(argf2))
Even if argf2 == 81, exp(-6561) is equal 0, so f2 = 1.0 - 2.0/9.0*0.0 == 1.0.

Quote:
Now the next question is why does OpenFOAM not create the nonuniform list <scalar>?
Guess, cause it's uniform.
alexeym is offline   Reply With Quote

Old   April 29, 2014, 14:50
Default
  #7
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Ooops!
My apologies, I was thinking of the value of argf2 at a solid boundary, which yields argf2=0, leading to f2=1-2.0/9.0.*1.

Thank you for your help Alexey!
CHARLES is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 06:42
Can anybody help me to solve the list errors while compiling Openfoam 15 on Opensuse 103 32bit coompressor OpenFOAM Installation 0 November 12, 2008 20:53
Could you please help me about the VTKFoam liugx212 OpenFOAM Pre-Processing 5 February 13, 2008 12:31
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 07:27
[OpenFOAM] Could you please help me liugx212 ParaView 4 December 22, 2005 17:55


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