CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Looping over all cells in parallel (https://www.cfd-online.com/Forums/openfoam-programming-development/88280-looping-over-all-cells-parallel.html)

skabilan May 12, 2011 13:55

Looping over all cells in parallel
 
Hi Foamers,

The following code works good on a single processor but not on multiple processors...

forAll( mesh.C(), celli)
{
.
.
.
}

How can I make this work on multiple processors?

Thanks
Senthil

olesen May 13, 2011 03:07

Quote:

Originally Posted by skabilan (Post 307402)
Hi Foamers,

The following code works good on a single processor but not on multiple processors...

forAll( mesh.C(), celli)
{
.
.
.
}

How can I make this work on multiple processors?

This should work fine on every processor. Where is the issue?

gschaider May 13, 2011 05:31

Quote:

Originally Posted by olesen (Post 307462)
This should work fine on every processor. Where is the issue?

I guess his problem is what's in the loop. The answer to his problem will probably contain "reduce" or "correctBoundaryConditions" ;)

skabilan May 13, 2011 11:57

Thanks for the response...Actually, I figured out what was missing...I had to use a "reduce" call to sum over all the processors and not just one processor. Like

reduce(U_flux, sumOp<scalar>());

Senthil

Zato_Ichi May 15, 2011 16:29

Hello everyone.

I have a problem with forAll loop in parallel too. There is a piece of my code, and i don't know how to extend it for parallel calculations. It calculates mass flux deltaM through cell faces.

Code:


scalarField& deltaMi = deltaM.internalField();   
deltaMi = 0 ;

    forAll(owner, faceI)
    {
       
        label P = owner[faceI] ;
        label N = neighbour[faceI] ;

        dir = (Ui[P]+ Ui[N]) & mesh.Sf()[faceI] ;

        if (dir >= 0)
        {
            deltaMi[faceI] = (0.5*rho[P]*(deltaT.value())*(U[P] + U[N])) & mesh.Sf()[faceI] ;
        }
        else
        {
              deltaMi[faceI] = (0.5*rho[N]*(deltaT.value())*(U[P] + U[N])) & mesh.Sf()[faceI] ;
        }
   
       
        if (mag(deltaMi[faceI]) < 1e-20)
           
            deltaMi[faceI] = 0 ;

    } ;

    forAll(mesh.boundary(),patchI)
    {
        fvsPatchScalarField& pfdeltaM = deltaM.boundaryField()[patchI] ;
        const fvPatchVectorField& pfU = U.boundaryField()[patchI] ;
        const fvPatchScalarField& pfp = p.boundaryField()[patchI] ;
        const fvPatchScalarField& pfrho = rho.boundaryField()[patchI] ;
        const unallocLabelList& faceCells = mesh.boundary()[patchI].faceCells();
        const vectorField& pSf = mesh.Sf().boundaryField()[patchI];
       
        forAll(mesh.boundary()[patchI], faceI)
        {

        dir = (pfU[faceI] + U[faceCells[faceI]]) & pSf[faceI] ;

        if (dir >= 0)
        {
            pfdeltaM[faceI] = (rho[faceCells[faceI]]*deltaT.value()*(pfU[faceI])) & pSf[faceI] ;
        }
        else
        {
            pfdeltaM[faceI] = (pfrho[faceI]*deltaT.value()*(pfU[faceI])) & pSf[faceI] ;
        }
        } ;

    };

Any tips ?


All times are GMT -4. The time now is 13:50.