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

if statement for volScalarField

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Bernhard

Reply
 
LinkBack Thread Tools Display Modes
Old   April 28, 2012, 16:37
Question if statement for volScalarField
  #1
New Member
 
reza
Join Date: Apr 2012
Posts: 7
Rep Power: 6
sasookey is on a distinguished road
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.
sasookey is offline   Reply With Quote

Old   April 29, 2012, 04:27
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 13
Bernhard is on a distinguished road
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: Instruction if
sasookey likes this.
Bernhard is offline   Reply With Quote

Old   April 29, 2012, 05:56
Smile
  #3
New Member
 
reza
Join Date: Apr 2012
Posts: 7
Rep Power: 6
sasookey is on a distinguished road
Thanks dear Bernhard, you got me and my problem has been solved.
sasookey is offline   Reply With Quote

Old   June 14, 2016, 14:55
Exclamation
  #4
New Member
 
Rimsha
Join Date: Jan 2016
Posts: 25
Rep Power: 2
block is on a distinguished road
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

ifloop.png

I am getting this error

errorloop.png

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

Kind Regards

Rimsha
block is offline   Reply With Quote

Old   June 15, 2016, 13:40
Default
  #5
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 436
Rep Power: 14
marupio is on a distinguished road
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
}
__________________
~~~
Follow me on twitter @DavidGaden

Last edited by marupio; June 15, 2016 at 13:40. Reason: bad code tags
marupio is offline   Reply With Quote

Old   June 17, 2016, 12:32
Default
  #6
New Member
 
Rimsha
Join Date: Jan 2016
Posts: 25
Rep Power: 2
block is on a distinguished road
Quote:
Originally Posted by marupio View Post
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
DIsetfields.png

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

creatingI.png

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

Last edited by block; June 19, 2016 at 10:42. Reason: adding details
block is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement for volScalarField AnjaMiehe OpenFOAM Programming & Development 2 April 24, 2012 07:01
If Statement Zaktatir CFX 5 June 19, 2010 06:09
Weak statement for Galerkin Method rugabug Main CFD Forum 0 March 26, 2010 20:19
Problem Statement balkrishna Main CFD Forum 0 October 6, 2009 23:55
marking statement in Latex mike Main CFD Forum 0 October 8, 2006 12:01


All times are GMT -4. The time now is 17:47.