CFD Online URL
[Sponsors]
Home > Forums > OpenFOAM

if-loop, volScalarField comparison

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

Like Tree3Likes
  • 1 Post By volker
  • 1 Post By alberto
  • 1 Post By alberto

Reply
 
LinkBack Thread Tools Display Modes
Old   April 19, 2010, 12:29
Default if-loop, volScalarField comparison
  #1
New Member
 
Volker Tritschler
Join Date: Jan 2010
Posts: 20
Rep Power: 6
volker is on a distinguished road
Hi all,

I have a problem with a task, which seemed to be straight-forward to solve at first.
I need to program an if-loop in order to compare one volScalarField (P1) to another one (P2), and for each grid point, where P1 >= P2, a certain value (d) has to be written to another volScalarField (N) at exactly the same grid point.
I wrote something like:
(a, b, c, d are placeholder for arbitrary volScalarFields)
Code:
volScalarField P1 = a;
volScalarField P2 = b;
volScalarField N = c;

    if (P1 >= P2)
    {
    N = d;
    }
    else
    {
    N = -d;
    }
The problem is that the code in the actual version does not compare the values for every single grid point and hence does not write the value (d) to (N) for all the grid points where the logical expression is true (P1 >= P2).
It's more that it just compares just one (the first?!) point of P1 with P2.
Right now, I don't have any idea how to get rid of that problem, though it seems to be a very silly one.
Thanks for any idea.

greets, volker
neeraj likes this.
volker is offline   Reply With Quote

Old   April 22, 2010, 01:30
Default
  #2
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,890
Rep Power: 25
alberto will become famous soon enoughalberto will become famous soon enough
Hi,

you have to loop over your cells to compare information in each point:

Code:
forAll(P1, cellI)
{
  if (P1[cellI] > P2[cellI])
  {
    N[cellI] = ...
  }
  else
  {
    ...
  }
}
Best,
neeraj likes this.
__________________
Alberto

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
GeekoCFD 32bit - The 32bit edition of GeekoCFD.
GeekoCFD text mode - A smaller version of GeekoCFD, text-mode only, with only OpenFOAM. Available in a variety of virtual formats.
alberto is offline   Reply With Quote

Old   April 22, 2010, 04:42
Default
  #3
New Member
 
Volker Tritschler
Join Date: Jan 2010
Posts: 20
Rep Power: 6
volker is on a distinguished road
hi alberto,

so many thanks for your help!!! It worked great.
I wasn't aware of that class 'cell'.

Do you know if there is a way to loop over the boundary patches as well?

best
volker
volker is offline   Reply With Quote

Old   April 22, 2010, 11:11
Default
  #4
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,890
Rep Power: 25
alberto will become famous soon enoughalberto will become famous soon enough
Quote:
Originally Posted by volker View Post
hi alberto,
so many thanks for your help!!! It worked great.
I wasn't aware of that class 'cell'.
It's not a class, it's just an index created locally by the forAll loop

Quote:
Do you know if there is a way to loop over the boundary patches as well?
Yes, let's assume you want to loop over the boundaries of a field p:

Code:
forAll(p.boundaryField(), patchi)
    {
        // Check if it's zeroGradient (optional, depending on your case)
        if (isA<zeroGradientFvPatchScalarField>(p.boundaryField()[patchi]))
        {
            otherFieldA.boundaryField()[patchi] = 0.0;
            otherFieldB.boundaryField()[patchi] = 0.0;
        }
    }
Best,
neeraj likes this.
__________________
Alberto

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
GeekoCFD 32bit - The 32bit edition of GeekoCFD.
GeekoCFD text mode - A smaller version of GeekoCFD, text-mode only, with only OpenFOAM. Available in a variety of virtual formats.
alberto is offline   Reply With Quote

Old   April 23, 2010, 14:02
Default
  #5
New Member
 
Volker Tritschler
Join Date: Jan 2010
Posts: 20
Rep Power: 6
volker is on a distinguished road
perfect, big thanks to you!
volker is offline   Reply With Quote

Old   April 23, 2010, 15:18
Default
  #6
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,890
Rep Power: 25
alberto will become famous soon enoughalberto will become famous soon enough
You're welcome
__________________
Alberto

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
GeekoCFD 32bit - The 32bit edition of GeekoCFD.
GeekoCFD text mode - A smaller version of GeekoCFD, text-mode only, with only OpenFOAM. Available in a variety of virtual formats.
alberto 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
ForAll loop and vector comparison juho OpenFOAM Running, Solving & CFD 4 June 17, 2011 10:51
my stl surface is seen as just a line rcastilla OpenFOAM Meshing & Mesh Conversion 2 January 6, 2010 02:30
Problem with Gmsh nishant_hull Open Source Meshers: Gmsh, Netgen, CGNS, ... 17 December 7, 2007 02:33
for loop inside a cell_loop? MHDWill FLUENT 0 September 26, 2007 22:24
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 16:57


All times are GMT -4. The time now is 20:02.