# how to do calculation for a variable when solver runs in parallel

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

 May 9, 2022, 14:51 how to do calculation for a variable when solver runs in parallel #1 New Member   Ujjwal Chetan Join Date: Oct 2018 Posts: 2 Rep Power: 0 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

May 10, 2022, 04:52
#2
New Member

Lorenzo
Join Date: Apr 2020
Location: Italy
Posts: 28
Rep Power: 4
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

 Tags collect data, parallel calculation