CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > 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 Search this Thread Display Modes
Old   April 28, 2012, 17:37
Question if statement for volScalarField
  #1
New Member
 
reza
Join Date: Apr 2012
Posts: 7
Rep Power: 13
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, 05:27
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
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: http://www.cfd-online.com/Forums/ope...uction-if.html
sasookey likes this.
Bernhard is offline   Reply With Quote

Old   April 29, 2012, 06:56
Smile
  #3
New Member
 
reza
Join Date: Apr 2012
Posts: 7
Rep Power: 13
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, 15:55
Exclamation
  #4
New Member
 
Rimsha
Join Date: Jan 2016
Posts: 25
Rep Power: 10
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, 14:40
Default
  #5
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 21
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 14:40. Reason: bad code tags
marupio is offline   Reply With Quote

Old   June 17, 2016, 13:32
Default
  #6
New Member
 
Rimsha
Join Date: Jan 2016
Posts: 25
Rep Power: 10
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 11:42. Reason: adding details
block is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
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 08:01
If Statement Zaktatir CFX 5 June 19, 2010 07:09
Weak statement for Galerkin Method rugabug Main CFD Forum 0 March 26, 2010 20:19
Problem Statement balkrishna Main CFD Forum 0 October 7, 2009 00:55
marking statement in Latex mike Main CFD Forum 0 October 8, 2006 13:01


All times are GMT -4. The time now is 18:55.