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/)
-   -   how to do calculation for a variable when solver runs in parallel (https://www.cfd-online.com/Forums/openfoam-programming-development/242754-how-do-calculation-variable-when-solver-runs-parallel.html)

lightMyCandle May 9, 2022 14:51

how to do calculation for a variable when solver runs in parallel
 
Hello Foamers,

I wanted to get the volume integral of y-component of vorticity and print it on the terminal at run time. The code for the same is as follows;

Code:

//vorticity calculation ----------------------------------------------------

volVectorField omega = fvc::curl(U);

// volume integrals calculation ---------------------------------------

scalar vort_volume_integral = 0;
forAll(omega, cellI)
{
vort_volume_integral += omega[cellI][1]*mesh.V()[cellI];
}

// printing data to the terminal at runtime -------------------------

Info<< "\nvorticity_y_component_volume_integral = " << vort_volume_integral << nl << endl;

When I do this calculation on single core for icoFoam solver, it accurately prints the vorticity-volume integral. But when I run the same in parallel (more than one cores at a time), I get the wrong output. I got the reason after comparing the calculation in paraview that it is calculating the variable only in certain regions of the domain as the domain is divided among multiple processors.

So, my question is, how to reassemble vorticity-volume-integral data from all the processors and add it up to print in the terminal.

Thanks

Lorenzo210 May 10, 2022 04:52

Hi,

You should add a code that collects the variable calculated by every single processor and sum it.

In fact,
Quote:

forAll(omega, cellI)
{
vort_volume_integral += omega[cellI][1]*mesh.V()[cellI];
}
this will make every processor do a certain operation on "vort_volume_integral" inside every part of the domain, but this variable is not communicated among the processors. So, it is actually normal that it works only in serial.
There are many snippets that you can find in your OpenFOAM directory regarding coding for simulations in parallel, for example in v2112 you can find them in "applications/test", just look for parallel, parallel communicators etc.

In order to collect the overall vorticity, you should add something like:

Code:

reduce(vort_volume_integral, sumOp<scalar>());
This will sum every vort_volume_integral.

Hope this helps.
Regards,

Lorenzo


All times are GMT -4. The time now is 06:36.