CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   for loop, not working in parallel (http://www.cfd-online.com/Forums/openfoam-programming-development/99385-loop-not-working-parallel.html)

xisto April 2, 2012 10:19

for loop, not working in parallel
 
Hello everyone,

Maybe this is not a new question, but for some reason this piece of code does not work in parallel, just in serial.

Any advice?

Code:

for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)  //internalFACES

{


 if(mag(M_R[faceI]) >= scalar(1.0)) //rigth face values
    {
        M_4_neg[faceI] = M_1_neg[faceI]; //rigth side face function
        P_5_neg[faceI] = M_1_neg[faceI]/M_R[faceI];
    }   

  if(mag(M_L[faceI]) >= scalar(1.0)) //left face values
      {
        M_4_pos[faceI] = M_1_pos[faceI]; //left side face functions
        P_5_pos[faceI] = M_1_pos[faceI]/M_L[faceI]; 
      } 
     
 
}


xisto April 3, 2012 05:20

This is the Bernhard answer to my email:

>Anyway: one of your problems might be that faces that were internal in
>the serial case are now boundary faces (on a processor patch). From
>what I see in your code you don't treat them at all. You'll have to do
>that treatment separately for these patches.

Thanks Bernhard

xisto April 3, 2012 08:32

So I have added the boundaryField. But is still not working.

Any ideas?

Code:

for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)  //internalFACES
  {
 if(mag(M_R[faceI]) >= scalar(1.0)) //rigth face values (for ox)
    {
        M_4_neg[faceI] = M_1_neg[faceI]; //rigth side face function
        P_5_neg[faceI] = M_1_neg[faceI]/M_R[faceI];
    }   
       
  if(mag(M_L[faceI]) >= scalar(1.0)) //left face values (for ox)
      {
        M_4_pos[faceI] = M_1_pos[faceI]; //left side face functions
        P_5_pos[faceI] = M_1_pos[faceI]/M_L[faceI]; 
      } 
  }


  forAll(mesh.boundaryMesh(), patchi)
    {
 if(mag(M_R[patchi]) >= scalar(1.0)) //rigth face values (for ox)
    {
        M_4_neg[patchi] = M_1_neg[patchi]; //rigth side face function
        P_5_neg[patchi] = M_1_neg[patchi]/M_R[patchi];
    }   
       
  if(mag(M_L[patchi]) >= scalar(1.0)) //left face values (for ox)
      {
        M_4_pos[patchi] = M_1_pos[patchi]; //left side face functions
        P_5_pos[patchi] = M_1_pos[patchi]/M_L[patchi]; 
      } 
    }


gschaider April 3, 2012 14:42

Quote:

Originally Posted by xisto (Post 352894)
So I have added the boundaryField. But is still not working.

Any ideas?

Code:

for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)  //internalFACES
  {
 if(mag(M_R[faceI]) >= scalar(1.0)) //rigth face values (for ox)
    {
        M_4_neg[faceI] = M_1_neg[faceI]; //rigth side face function
        P_5_neg[faceI] = M_1_neg[faceI]/M_R[faceI];
    }   
       
  if(mag(M_L[faceI]) >= scalar(1.0)) //left face values (for ox)
      {
        M_4_pos[faceI] = M_1_pos[faceI]; //left side face functions
        P_5_pos[faceI] = M_1_pos[faceI]/M_L[faceI]; 
      } 
  }


  forAll(mesh.boundaryMesh(), patchi)
    {
 if(mag(M_R[patchi]) >= scalar(1.0)) //rigth face values (for ox)
    {
        M_4_neg[patchi] = M_1_neg[patchi]; //rigth side face function
        P_5_neg[patchi] = M_1_neg[patchi]/M_R[patchi];
    }   
       
  if(mag(M_L[patchi]) >= scalar(1.0)) //left face values (for ox)
      {
        M_4_pos[patchi] = M_1_pos[patchi]; //left side face functions
        P_5_pos[patchi] = M_1_pos[patchi]/M_L[patchi]; 
      } 
    }


Your on the right track. But

a) you'll have to loop over the individual faces in each patch (just like you did for the internal field)
b) you'll want to be sure that you do this only on processor patches. Use "isA" to find out

Have a look at $FOAM_SRC/finiteVolume/lnInclude/adjustPhi.C for inspiration

xisto April 3, 2012 17:45

I was doing this in the wrong way, now I see that. But I can use a different and ingenious approach (without loops) for this particular case (see bellow).

Once more, thanks Bernhard you were very helpful and I think that I need to use your suggestion for another loop problem.



Following the solution of Alberto Passalacqua.

The best way in this case is to forget about the loops and treat everything as a surface scalar.

Quote:

the for loop is not required anymore because the operation is done using the surface field, and not accessing to each face. The "pos" and "neg" methods return a surfaceScalarField with values of 1 on the faces where the argument is positive (pos) or negative (neg), and zero elsewhere. So, say you have your field magMR = mag(M_R), if you do M_4_neg = pos(magMR - 1.0)*(operations...) + neg(magMR - 1.0)*(operations...); you should end up with the final result you want without looping.
and I did just that..

It was necessary to use Foam::pos(magMR -1.0), dont know why.

Many thanks Alberto and Bernhard

You guys are the best.

Carlos


All times are GMT -4. The time now is 05:12.