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

Reverse sort of a list in parallel

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 11, 2020, 06:55
Default Reverse sort of a list in parallel
  #1
New Member
 
Pietro Tavazzi
Join Date: Aug 2019
Location: Milan, Italy
Posts: 8
Rep Power: 7
elden is on a distinguished road
Hi everyone,

I'm working on adaptive mesh refinement with dynamicRefineFvMesh class
I'm stuck at the definition of a list of scalars that need to be sorted from the highest to the lowest value. The use of SortableList::reverseSort() member function holds until mpirun is used.

Let me explain a little bit more: in dynamicRefineFvMesh the scalarField named cellError is evaluated. I need to sort these scalars, thus I pass them to a sortableList and then I use the reverseSort() function. This solution works just fine only with one processor.

Should I exploit the ListListOps::combine function? Or should I exploit the ParSortableList implementing a new member function to handle a "reverse sort"?

I'm sure I'm getting lost in a glass of water but I'm wasting a lot of time with this issue.
Attached Images
File Type: png reverseSort.png (89.4 KB, 47 views)
elden is offline   Reply With Quote

Old   January 20, 2022, 05:05
Default
  #2
New Member
 
Pietro Tavazzi
Join Date: Aug 2019
Location: Milan, Italy
Posts: 8
Rep Power: 7
elden is on a distinguished road
Well, I totally forgot about this post. I'll try to give it a closure.

I was dealing with the following problem related to Adaptive Mesh Refinement in OpenFOAM:

the code in dynamicRefineFvMesh was implemented in such a way that, when the user specifies a maximum number of cells for the simulation, there is no guarantee the code will comply with it. This is because each cell candidate has the same importance as any other candidate.

Solution to the problem:

We want to give higher importance to those cells with higher cellError; we want to consider andidates from the its highest value to the lowest. This requires the sorting of the scalarField from the maximum to the minimum value, giving us the ordered indices of the cells. Once we have the proper ordering of cells indexing, we start marking cells for refinement until the maxCells limit is
reached.

The only problem is the sorting of a list during parallel computing.

Code definition:

The first thing to do is to collect all the cellError values from each processor. We can do that by simply transfer all the list of scalars in a list of list of scalars; we gather those lists (Pstream::gatherList) and re-distribute the result among all processors (Pstream::scatterList). Now each processor combines all cell values in a SortableList (ListListOps::combine) and sorts from the maximum value to the minimum one (SortableList::reverseSort). This way each processors sees the global indices of the cells in a specific order. We start considering the candidate cells for refinemente from the highest value of cellError; we take the cell global index, we find the processor in which this cell is defined and look for the associated local index and mark the corresponding cell if it satisfies all requirements.

Code:

Here below can be found the changes applied to the dynamicRefineFvMesh.C file. Those changes are for the the functions selectRefineCandidates, selectRefineCells and update. (Awareness of a possible inaccuracies source is mentioned in the update function image)
selectRefineCandidates.png

selectRefineCells.jpg

update.png
elden is offline   Reply With Quote

Reply

Tags
dynamicrefinefvmesh, reversesort, sort


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
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 04:30
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 10:07
simpleFoam parallel AndrewMortimer OpenFOAM Running, Solving & CFD 12 August 7, 2015 19:45
simpleFoam in parallel issue plucas OpenFOAM Running, Solving & CFD 3 July 17, 2013 12:30
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24


All times are GMT -4. The time now is 17:18.