How to merge two labellist?
Hello,
I have two labellist and they share some labels, so I want to merge them. Thanks! Wei |
Does anyone have any idea on this, thanks in advance!
|
Quote:
Be careful with the following example: STL set and unique deliver proper results, but in case of std::unique, you have to understand the invalidation that happens to the list iterator. When OpenFOAM algorithm "uniqueSorted" is used from ListOps.H (btw, this is the file you need to investigate to find available List operations in OF), all repeated values are removed from the result. If you have small lists with repeating indices, consider using sets. I think there is even a native OF set (HashTable<label, label>, or HashSet<label>), but you should make sure that the set is really - a set : has unique elements. Do this by unit testing the class. Here is the code: Code:
#include "fvCFD.H" Code:
5(1 2 3 3 5) |
Quote:
Many thanks for the example codes. I have a question in your codes. You defined a label list by labelList l1 (5,0), what does the 0 in (5,0) mean? Best, Wei |
Quote:
Code:
labelList l1(5,0) Edit: Hint, my advice is a tricky advice, labelList class is instantiation of the List<T> template, where T = label. So check out List<T> source. |
Dear Tomislav,
I have a labelListList, contains some duplicated value like this : Info<< tmpMyLists[cellI]; -> 7 (44 44 55 66 77 88 99). to remove the extra '44' when i use this : Foam::uniqueOrder(tmpMyLists[cellI],MyLists[cellI]); the output is some value like this ->5 ( 4 3 0 6 ...)//completely different of the expected list. (using std::unique: std::unique(tmpMyLists[cellI].begin(),tmpMyLists[cellI].end() ) does not do anything, the output would be again -> 7(44 44 55 66 ... ) Is there anything i would miss? How can i get this -> 6 (44 55 66 77 88 99) ? |
@ooo
Can you post the code that you programmed? If you post a working example it's easier for me + anyone else to see what you did and find the problem. |
sure :
Code:
List<DynamicList<label>> tmpCellCells(mesh.cells().size()); So: Code:
forAll(mesh.cells(),cellI) { |
and these are some sample outputs :
forAll(mesh.cells(),cellI) { //before the try to remove duplications: Info << tmpCellCells[cellI] -> 41 ( 500 800 500 600 300 ....) //After using uniqueOrder(sorted) : Info << cellCells[cellI] -> 30 ( 0 2 4 5 ... 40) ! //After using std::unique: Info << tmpCellCells[cellI] -> 41 ( 500 800 500 600 300 ....) } What i want -> xx ( 500 800 600 300 ... ) //removing the extra 500... |
I'll just answer for the Foam algorithms. The STL I've commented in my answer below - please re-read it , you invalidate iterators with std::unique and need to be careful what you do afterwards.
Here is a working small code example: Code:
typedef List<DynamicList<label> > listDynamicLabelList; Code:
tmpCellCells = 1(5(500 500 600 300 700)) Code:
//- Generate (sorted) indices corresponding to unique list values Hope this helps.. :) |
All times are GMT -4. The time now is 05:13. |