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/)
-   -   if statement for volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/101181-if-statement-volscalarfield.html)

sasookey April 28, 2012 16:37

if statement for volScalarField
 
hi
i'm a new user of openFoam, i try to do something when a volScalarFied like p is in the specific number like smaller than 1 i tried this in solver.

if ( p < 1)
{
.....
}

when p is volScalarField and i got som error for operator <
thanks to help me.

Bernhard April 29, 2012 04:27

It depends a bit of what you want to do precisely. It is always a good idea to carefully read the errormessages. If you don't understand them, it is still worth to post them in a thread.

See also: http://www.cfd-online.com/Forums/ope...uction-if.html

sasookey April 29, 2012 05:56

Thanks dear Bernhard, you got me and my problem has been solved. :D

block June 14, 2016 14:55

2 Attachment(s)
Hi guys i am trying to implement a if loop in one of the libraries of interFoam where a variable called "kappaf" is depend on the alpha1f value, where i want to impose a condition where kappaf is alpha1f * DI for alpha1f >0.5 or zero if alphaf < 0.5.

I have written the loop

Attachment 48270

I am getting this error

Attachment 48269

I am new to openfoam and C++ coding so not familiar with how to write this.

Kind Regards

Rimsha

marupio June 15, 2016 13:40

You can't put a for loop within a function call like that.
Code:

return tmp<surfaceScalarField>
(
    new surfaceScalarField
    (
        // This is a function call - specifically, a constructor
    )
);

You could create your field first, then modify its values. Also, the if / else if / else syntax is:

Code:

if (condition)
{
    // statements
}
else if (anotherCondition)
{
    // statements
}
else
{
    // statements
}


block June 17, 2016 12:32

2 Attachment(s)
Quote:

Originally Posted by marupio (Post 605048)
You can't put a for loop within a function call like that.
Code:

return tmp<surfaceScalarField>
(
    new surfaceScalarField
    (
        // This is a function call - specifically, a constructor
    )
);

You could create your field first, then modify its values. Also, the if / else if / else syntax is:

Code:

if (condition)
{
    // statements
}
else if (anotherCondition)
{
    // statements
}
else
{
    // statements
}



Thank you so much for helping. I have taken your advice and imposed the for loop just before the equation instead and it works fine.

Below is the procedure i followed.

I imposed the two diffusion coefficients in create fields for the solver
Attachment 48418

wrote this loop before the equation that i imposed in runtime.

Attachment 48419

In the above loop i am trying to switch between diffusion coefficient depending on the cell face value of the alpha (a phase volume fraction in interFoam).


Hope this helps anyone trying to do something similar.

Thanks again.

Rimsha


All times are GMT -4. The time now is 06:25.