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

How to include a geometricField value to an if condition

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 19, 2014, 02:11
Default How to include a geometricField value to an if condition
  #1
kcn
Member
 
Join Date: May 2014
Posts: 31
Rep Power: 11
kcn is on a distinguished road
Hello,

I am developing a solver for temperature transport in a region where some places have porous structure. I need to solve a different transport equation in porous regions and another in ordinary regions. I plan to do this using an if condition as indicated below.

if (porosity == 1)
{ solve Equation A;}
else
{solve Equation B;}

I have defined porosity as a geometricField.

When I try to compile the code it does not recognize the condition " porosity == 1"

Can someone please tell me how to include the value of a geometricField in an if condition in OpenFOAM.
kcn is offline   Reply With Quote

Old   August 19, 2014, 04:17
Default
  #2
Senior Member
 
Jens Höpken
Join Date: Apr 2009
Location: Duisburg, Germany
Posts: 159
Rep Power: 17
jhoepken is on a distinguished road
Send a message via Skype™ to jhoepken
Hi,

if you do that, you have to check in each cell and this in turn involves a manual loop over all cells. This is slow as hell. Or even slower.

Why don't you use a blending field, which is 1 where equation 1 should be solved and 0 where equation 2 should be solved. This blending field - basically like the VoF rule of mixture approach - is then multiplied with the particular equations.

Otherwise, as I said, you have to loop over all cells and check locally using

Code:
forAll(porosity, pI)
{
    if(porosity[pI] == 1)
....
}
__________________
Blog: sourceflux.de/blog
"The OpenFOAM Technology Primer": sourceflux.de/book
Twitter: @sourceflux_de
Interested in courses on OpenFOAM?
jhoepken is offline   Reply With Quote

Old   August 19, 2014, 23:10
Default if condition
  #3
kcn
Member
 
Join Date: May 2014
Posts: 31
Rep Power: 11
kcn is on a distinguished road
Dear jhoepken,

Thanks a lot for your help. I'm bit new to openfoam. Can you please explain a little bit about using a blending field for this purpose. Actually, its the first time I heard about it. Are there any built in solvers that uses blending fields so that I can have a look at code?

Thanks
kcn
kcn is offline   Reply With Quote

Old   August 20, 2014, 01:23
Default if condition
  #4
kcn
Member
 
Join Date: May 2014
Posts: 31
Rep Power: 11
kcn is on a distinguished road
Dear jhoepken,

I managed to solve the problem using your idea. I used a scalarfield of 1 and 0 as you said and multiplied some terms in my equations with that field. Now it easily calculates using different equations in different zones.

I also tried the for loop method using the code you provided. As you said it took a long time to run even in a coarse mesh.

Thanks a really lot.

kcn
kcn is offline   Reply With Quote

Old   August 20, 2014, 02:57
Default
  #5
Senior Member
 
Jens Höpken
Join Date: Apr 2009
Location: Duisburg, Germany
Posts: 159
Rep Power: 17
jhoepken is on a distinguished road
Send a message via Skype™ to jhoepken
Hi kcn,

great that you've figured it out. As a general rule of thumb, you should avoid looping over cells and accessing field values wherever possible.
__________________
Blog: sourceflux.de/blog
"The OpenFOAM Technology Primer": sourceflux.de/book
Twitter: @sourceflux_de
Interested in courses on OpenFOAM?
jhoepken 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
Cht tutorial in 15 braennstroem OpenFOAM Running, Solving & CFD 197 June 10, 2015 03:02
conjugate boundary condition Daniel_Khazaei OpenFOAM Programming & Development 0 December 31, 2013 13:11
Flow simulation in wind tunnel mukut OpenFOAM 15 September 11, 2013 22:43
vorticity boundary condition bearcharge Main CFD Forum 0 May 14, 2010 11:32
Slip boundary condition what is inside normunds OpenFOAM Running, Solving & CFD 2 June 4, 2007 06:45


All times are GMT -4. The time now is 22:14.