CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Programming issues (http://www.cfd-online.com/Forums/openfoam/79449-programming-issues.html)

vkrastev August 24, 2010 09:10

Programming issues
 
Hi everybody, I have some compiling problems which are very probably due to my lack of knowledge in programming inside the OpenFOAM/C++ frame...however, I'm trying to compile a .C source file which contains the following piece of code:

tmp<volScalarField> kOmegaSI::kiKappa() const
{
return (1/(pow(omega_,3.0)))*((fvc::grad(k_))&(fvc::grad(ome ga_)));
}

tmp<volScalarField> kOmegaSI::fBetaStar() const
{
{
if (kiKappa() > scalar(0.0)) {
return ((scalar(680.0)+sqr(kiKappa()))/(scalar(400.0)+sqr(kiKappa())));
}
else {
return scalar(1.0);
}
}
}

and this is the error message after runninng the wmake utility

kOmegaSI/kOmegaSI.C:56: error: no match for ‘operator>’ in ‘Foam::incompressible::RASModels::kOmegaSI::kiKapp a() const() > 0.0’
kOmegaSI/kOmegaSI.C:60: error: conversion from ‘double’ to non-scalar type ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ requested

Line 56 is:

if (kiKappa() > scalar(0.0)) {

Line 60 is:

return scalar(1.0);

Can someone please give me some help about it? Thank you in advance

PS - What I'm trying to do is to implement the revised version of Wilcox's k-omega turbulence model. For the definition of the correction-functions of the closure coefficients (such as fBetaStar) I've took some inspiration from the Launder-Sharma Low-Re k-epsilon model source code.

vkrastev August 24, 2010 11:41

Any replies? I could post more information if necessary...

niklas August 24, 2010 11:50

kiKappa seems to be a tmp<volScalarField>

so what does it mean when you write kiKappa() > 0?
Thats what it tells you on the line:
kOmegaSI/kOmegaSI.C:56: error: no match for ‘operator>’ in ‘Foam::incompressible::RASModels::kOmegaSI::kiKapp a() const() > 0.0’

Does it mean that every element of kiKappa should be larger than zero?
what about the ones that are not?

you cant compare fields to a scalar, its like you have a vector a=(1, 2, 3)
and you write
a > 0.
What does that mean?...nothing.

You have to rethink your code there.

vkrastev August 24, 2010 12:36

Quote:

Originally Posted by niklas (Post 272532)
kiKappa seems to be a tmp<volScalarField>

so what does it mean when you write kiKappa() > 0?
Thats what it tells you on the line:
kOmegaSI/kOmegaSI.C:56: error: no match for ‘operator>’ in ‘Foam::incompressible::RASModels::kOmegaSI::kiKapp a() const() > 0.0’

Does it mean that every element of kiKappa should be larger than zero?
what about the ones that are not?

you cant compare fields to a scalar, its like you have a vector a=(1, 2, 3)
and you write
a > 0.
What does that mean?...nothing.

You have to rethink your code there.

First of all thanks for your reply. I can say that my original goal was: 1) to calculate kiKappa as a field of scalar values; 2) to search inside this field for positive and negative values (that's the reason for posing the if....else condition); 3) depending of the kiKappa's sign, to impose a value (which can depend on kiKappa or not) for the next field of scalar values (namely, the fBetaStar parameter).
As you have noticed, I've made some conceptual mistakes, so I will really appreciate if you could give me some advices about how to correct the code...anyway, thank you once again

hk318i August 24, 2010 20:21

try kiKappa.value() > 0.

I am not sure it will work or not

niklas August 25, 2010 02:34

I havent compiled this, so it probably wont work, but you have to do it
something like this.
you probably dont have access to runTime and mesh, so you need to replace runTime_ and mesh_ with
the appropriate equivalents and set the correct dimension in dimensionSet
Code:


    tmp<volScalarField> kOmegaSI::fBetaStar() const
    {
        tmp<volScalarField> tBeta
        (
            new volScalarField
            (
                IOobject
                (
                    "fBetaStar",
                    runTime_.timeName(),
                    mesh_,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh_,
                dimensionedScalar("one", dimensionSet(0, 0, 0, 0, 0), 1.0)
            )
        );

    forAll(tBeta(), i)
    {
        if (kiKappa()[i] > 0)
        {
            tBeta()[i] = ....
        }
    }

    return tBeta;
}


vkrastev August 25, 2010 04:56

Quote:

Originally Posted by hk318i (Post 272605)
try kiKappa.value() > 0.

I am not sure it will work or not

Thank you, but I've already tried it and it doesn't work (I mean not simply like this, maybe with some other modifications it will be different)

vkrastev August 25, 2010 04:57

Quote:

Originally Posted by niklas (Post 272614)
I havent compiled this, so it probably wont work, but you have to do it
something like this.
you probably dont have access to runTime and mesh, so you need to replace runTime_ and mesh_ with
the appropriate equivalents and set the correct dimension in dimensionSet
Code:


    tmp<volScalarField> kOmegaSI::fBetaStar() const
    {
        tmp<volScalarField> tBeta
        (
            new volScalarField
            (
                IOobject
                (
                    "fBetaStar",
                    runTime_.timeName(),
                    mesh_,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh_,
                dimensionedScalar("one", dimensionSet(0, 0, 0, 0, 0), 1.0)
            )
        );

    forAll(tBeta(), i)
    {
        if (kiKappa()[i] > 0)
        {
            tBeta()[i] = ....
        }
    }

    return tBeta;
}


Ok, I'll try to modify the source code and then I'll let you know if it works. Thanks a lot


All times are GMT -4. The time now is 07:37.