|
[Sponsors] |
July 18, 2013, 12:31 |
dynamic list (variable size)
|
#1 | |
Member
Join Date: Apr 2010
Posts: 61
Rep Power: 16 |
Hello,
I have a list of scalars with unknown size at declaration time. During the simulation I want to remove given elements from the list at different times. I know that you can define a DynamicList (DynamicList<scalar> test;) and then add some values (test.append(value)), clear the list (test.clear()) or maybe delete the last introduced value. The thing is if I need to delete some elements from the list It occurs to me to make a temporal copy with the new size or something like that. So my question is... what is the best strategy to declare a list of scalars which is expected to delete some given elements (and then varying the size of the list)? How can I do it effectively? Thank you in advanced. Regards. edit: the post is similar was treated before here and there's an interesting reply: Quote:
|
||
July 18, 2013, 17:59 |
|
#3 |
Member
Join Date: Apr 2010
Posts: 61
Rep Power: 16 |
Hello Laurance.
The list has a size in a range 100-1000 and I need to remove 1 element each time I check a condition. Every timestep It can happen for around 10-70% of the size of the list. (Eg: size 300, 40 elements to remove in a timestep). Thank you for your hints. |
|
July 19, 2013, 04:53 |
|
#4 |
Senior Member
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23 |
That's quite small. I'd either use a HashTable if you have to remove elements individually, or if you can remove them as a block then do this:
Code:
PackedBoolList elemToRemove(l.size()); forAll(l, i) { if (checkCondition) { elemToRemove[i] = true; } } inplaceSubset(elemToRemove, l);
__________________
Laurence R. McGlashan :: Website |
|
July 19, 2013, 07:25 |
|
#5 |
Member
Join Date: Apr 2010
Posts: 61
Rep Power: 16 |
I don't have experience using HashTable, I actually need to remove elements individually from Dynamic and Sortable lists. I'm going to review everything with this new feedback.
Thanks. |
|
July 19, 2013, 13:29 |
|
#6 |
Member
Join Date: Apr 2010
Posts: 61
Rep Power: 16 |
Here is how I did it to have a pairs of labels and scalars defined as a HashTable. With this new method I can efficiently remove an element. There's a strange issue, I'm using the findLower function but the problem comes when I erase a element of the HashTable the findLower still points to the removed index. I have checked that the element was erased correctly (apparently at least debugging) and the the size reduced.
I show an example: Code:
HashTable<scalar, label> testHash_; //- insert values with key 1, 2 and 3 testHash_.insert(1,0.5); testHash_.insert(2,0.7); testHash_.insert(3,0.3); //- print HashTable Info << "testHash: " << testHash_ << nl << endl; //- find value lower than 0.6 label j = findLower(testHash_,0.6); //- erase key j and his value testHash_.erase(j); //- print HashTable Info << "testHash: " << testHash_ << nl << endl; //- find another value lower than 0.6 label k = findLower(testHash_,0.6); //- erase key k and his value testHash_.erase(k); Info << "testHash: " << testHash_ << nl; Code:
testHash: 3 ( 3 0.3 1 0.5 2 0.7 ) testHash: 2 ( 3 0.3 2 0.7 ) --> FOAM FATAL ERROR: 1 not found in table. Valid entries: 2(3 2) The topic of the post has been resolved for me, thank you very much! Still I have that thing but maybe I made a mistake. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 12:41 |
[swak4Foam] funkySetFields compilation error | tayo | OpenFOAM Community Contributions | 39 | December 3, 2012 05:18 |
[Gmsh] discretizer - gmshToFoam | Andyjoe | OpenFOAM Meshing & Mesh Conversion | 13 | March 14, 2012 04:35 |
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found | piprus | OpenFOAM Installation | 22 | February 25, 2010 13:43 |
DxFoam reader update | hjasak | OpenFOAM Post-Processing | 69 | April 24, 2008 01:24 |