|
[Sponsors] |
How to include a geometricField value to an if condition |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 19, 2014, 02:11 |
How to include a geometricField value to an if condition
|
#1 |
Member
Join Date: May 2014
Posts: 31
Rep Power: 11 |
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. |
|
August 19, 2014, 04:17 |
|
#2 |
Senior Member
|
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? |
|
August 19, 2014, 23:10 |
if condition
|
#3 |
Member
Join Date: May 2014
Posts: 31
Rep Power: 11 |
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 |
|
August 20, 2014, 01:23 |
if condition
|
#4 |
Member
Join Date: May 2014
Posts: 31
Rep Power: 11 |
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 |
|
August 20, 2014, 02:57 |
|
#5 |
Senior Member
|
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? |
|
|
|
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 |