CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to use if statement in openFoam solver? (https://www.cfd-online.com/Forums/openfoam-programming-development/155043-how-use-if-statement-openfoam-solver.html)

rapierrz June 24, 2015 07:53

How to use if statement in openFoam solver?
 
Hi friends,

I want to add if statement to openfoam solver :

if (Re > 1000)
{
CD=24/Re;
}

else
{
CD=0.44;
}

But I can't implement it!!!

error is :

calcVdj.H: In function ‘int main(int, char**)’:
calcVdj.H:30:21: error: no match for ‘operator>’ in ‘Re > 1.0e+3’
calcVdj.H:30:21: note: candidates are:

danny123 June 29, 2015 10:25

This is not very detailed, but maybe you have a type problem. Re must be e.g. of type scalar.

You can add a line upfront:

scalar Ree = Re;

Replace all your Re by Ree. Look at the compilation error. Openfoam will tell of which type Re is (e.g. it has dimensions).

Regards,

Daniel

blais.bruno July 14, 2015 09:57

Quote:

Originally Posted by rapierrz (Post 551906)
Hi friends,

I want to add if statement to openfoam solver :

if (Re > 1000)
{
CD=24/Re;
}

else
{
CD=0.44;
}

But I can't implement it!!!

error is :

calcVdj.H: In function ‘int main(int, char**)’:
calcVdj.H:30:21: error: no match for ‘operator>’ in ‘Re > 1.0e+3’
calcVdj.H:30:21: note: candidates are:


As the variable Re been defined as a scalar (or at least a double?) It is not a per-default variable of the solver so you need to define it. The operator > is defined for the scalar type...

rapierrz July 14, 2015 12:26

Quote:

Originally Posted by blais.bruno (Post 555401)
As the variable Re been defined as a scalar (or at least a double?) It is not a per-default variable of the solver so you need to define it. The operator > is defined for the scalar type...

Hi Bruno.I define Re number as scalar.I want to know how i can use if or while statement.

thank you.

pbachant July 14, 2015 13:51

You should post more context, i.e. where Re and CD are initialized.

AJAY BHANDARI August 3, 2015 13:26

how to assign a vlue of a variable to each cell
 
Hi all,

I am new to open Foam.I have the a problem same as discussed above . i want to use a for loop to assign a variable value to each cell in my mesh . How can i do it??? and where i have to create this loop. any help will be appreciated.

Regards
Ajay

danny123 August 4, 2015 06:15

Here just some code lines, how you can do it. You will find it preat all over the code:

Code:

    forAll(owner, facei)
    {
        ssf[facei] =
            deltaCoeffs[facei]*(vf[neighbour[facei]] - vf[owner[facei]]);
    }

The forAll statement is very useful. It automatically determines the size of the vector (owner), the loop variable (facei). The square bracket assignes the individual row value.

This will not work in some part of the code, e.g. in matrix solvers, but elsewhere it does.

Regards,

Daniel

AJAY BHANDARI August 4, 2015 06:19

Hi danny,

First of all thanks for your quick reply. I will try what u have said. Can u tell me what is meant by this line it will not work in matrix solvers. I am working in porousSimpleFoam and basically i want to assign porosity to each cell in mesh.

Regards
Ajay


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