CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

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

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Lorenzo210

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 9, 2022, 15:51
Arrow 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
lightMyCandle is on a distinguished road
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
lightMyCandle is offline   Reply With Quote

Old   May 10, 2022, 05:52
Default
  #2
Member
 
Lorenzo
Join Date: Apr 2020
Location: Italy
Posts: 46
Rep Power: 6
Lorenzo210 is on a distinguished road
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
francescomarra likes this.
Lorenzo210 is online now   Reply With Quote

Reply

Tags
collect data, parallel calculation


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A function can only be used in serial calculation not parallel calculation chenghui62000 OpenFOAM Programming & Development 1 January 7, 2020 13:18
Error in gradient calculation only while parallel processing Pavithra OpenFOAM Running, Solving & CFD 0 December 23, 2019 05:32
Explicitly filtered LES saeedi Main CFD Forum 16 October 14, 2015 12:58
simpleFoam parallel AndrewMortimer OpenFOAM Running, Solving & CFD 12 August 7, 2015 19:45
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 01:01


All times are GMT -4. The time now is 09:40.