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

How to use if statement in openFoam solver?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 24, 2015, 07:53
Default How to use if statement in openFoam solver?
  #1
Senior Member
 
Hesam
Join Date: Feb 2015
Posts: 139
Rep Power: 11
rapierrz is on a distinguished road
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:
rapierrz is offline   Reply With Quote

Old   June 29, 2015, 10:25
Default
  #2
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
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
danny123 is offline   Reply With Quote

Old   July 14, 2015, 09:57
Default
  #3
Member
 
Bruno Blais
Join Date: Sep 2013
Location: Canada
Posts: 64
Rep Power: 13
blais.bruno is on a distinguished road
Quote:
Originally Posted by rapierrz View Post
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...
blais.bruno is offline   Reply With Quote

Old   July 14, 2015, 12:26
Default
  #4
Senior Member
 
Hesam
Join Date: Feb 2015
Posts: 139
Rep Power: 11
rapierrz is on a distinguished road
Quote:
Originally Posted by blais.bruno View Post
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.
rapierrz is offline   Reply With Quote

Old   July 14, 2015, 13:51
Default
  #5
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
You should post more context, i.e. where Re and CD are initialized.
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   August 3, 2015, 13:26
Post how to assign a vlue of a variable to each cell
  #6
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
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
AJAY BHANDARI is offline   Reply With Quote

Old   August 4, 2015, 06:15
Default
  #7
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
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
danny123 is offline   Reply With Quote

Old   August 4, 2015, 06:19
Post
  #8
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
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
AJAY BHANDARI is offline   Reply With Quote

Reply


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
Memory protection in OpenFOAM / combinig with FORTRAN botp OpenFOAM Programming & Development 2 February 15, 2016 13:25
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 01:01
Edit linear solver luckycfd OpenFOAM Programming & Development 32 January 24, 2014 14:28
What openFoam solver for sandstorm? cristina87 OpenFOAM Running, Solving & CFD 4 April 7, 2011 09:57
Working directory via command line Luiz CFX 4 March 6, 2011 21:02


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