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

How to delete from a DyanmicList?

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

Like Tree1Likes
  • 1 Post By GPesch

Reply
 
LinkBack Thread Tools Display Modes
Old   April 25, 2013, 05:41
Default How to delete from a DyanmicList?
  #1
New Member
 
Join Date: Apr 2013
Posts: 24
Rep Power: 4
GPesch is on a distinguished road
Hi,

this is probably a very daft question, but I just can't figure it out.
I have already looked into doxygen, but my experience in C++ is too low.

Okay, thats what I have (its taken from dsmcParcel::collisions() from the dsmc library):

Code:
        DynamicList<ParcelType*>& cellParcels(cellOccupancy_[cellI]);

        forAll(cellParcels, i) {
            ParcelType& p = *cellParcels[i];
            const bool allowedToMove = p.allowedToMove();
            if (!allowedToMove)
            {
                cellParcels[i].remove();
                notAllowedToMove++;
            }
        }
As I understand it, I have the the DynamicList cellParcels which is filled with the DsmcParcels which are in the cell CelII.
I want to remove all Parcels from the List in which the parameter allowedToMove is false.
However, I can't figure out how to remove an item from the list. According to doxygen I can remove from a list with DynamicList::remove(), but this is a method without any arguments. So how to tell remove() which item to remove?

Or is remove only used to remove the last item of a list??
cellParcels[i].remove(); doesn't work either.

So in case it is impossible to remove an item from a list I tried a different way by just filling the list manually by iterating over "cellParcels[cellI]" and just adding the elements which are "allowedToMove":

Code:
        DynamicList<ParcelType*>& cellParcels();

        forAll (cellOccupancy_[cellI],i)
        {
            const ParcelType& p = *cellOccupancy_[cellI][i];
            const bool allowedToMove = p.allowedToMove();
            if (allowedToMove)
            {
                cellParcels.append(p);
            }
        }
But then I get an error:

Fehler: Abfrage des Elementes »append« in »Foam::cellParcels<Foam:smcParcel<Foam:article > >«, das vom Nicht-Klassentyp »Foam:ynamicList<Foam:smcParcel<Foam:article >*, 0u, 2u, 1u>&()« ist

That's german and basically translates to that they are not from the same type.

Can somebody help me to sort this out? Either by telling me what I am doing wrong or by giving me a smart way of how to do this?

Thank you so much in advance!

Georg
GPesch is offline   Reply With Quote

Old   April 25, 2013, 09:03
Default
  #2
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 386
Rep Power: 15
deepsterblue will become famous soon enough
Georg,

DynamicList only allows appends and removal to/from the end of the list (think of a stack-like operation). If you're looking to remove from the middle, you'll have to resort to a copy to another list (followed by a List::transfer).

This might boil down to an appropriate choice of container - if you're looking to frequently remove arbitrary items from a list, a linked-list or hash table may be a better option.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   April 25, 2013, 18:40
Default
  #3
New Member
 
Join Date: Apr 2013
Posts: 24
Rep Power: 4
GPesch is on a distinguished road
Hi,

thanks for your reply.
How do I sort a DynamicList? Iterating over all items and using a self-written sort algorithm?
Guess I have to looked at linked-lists in this case, is IDLList the appropriate OpenFOAM class?

Any ideas why the second version I posted doesn't work? I have the feeling it might have something to do with the & and *'s, which are still a little confusing to me. However, I tried billion different combinations to put * and & somewhere but never received working results.
But maybe it doesn't have anything to do with that?

Sorry, I am a little bit lost I somehow hoped there is a simple answer, especially the second version I posted seemed quite reasonable to me and I hope there's just some stupid mistake in there..?!
GPesch is offline   Reply With Quote

Old   April 26, 2013, 09:08
Default
  #4
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 386
Rep Power: 15
deepsterblue will become famous soon enough
I haven't tried it, but you can probably use an STL sort using the List::begin and List::end iterators, since they are largely STL compliant.

cellParcels is a list of pointers to ParcelType, while you are trying to append objects of ParcelType. They need to be consistent.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   April 30, 2013, 05:27
Default
  #5
New Member
 
Join Date: Apr 2013
Posts: 24
Rep Power: 4
GPesch is on a distinguished road
Pointers and References are really breaking my balls.
Sorry that I have to reply again, but I just can't figure it out

To give a little background.
The list cellOccupancy is defined like that:

Code:
List<DynamicList<ParcelType*> > cellOccupancy_;
So it is a list filled with pointers to ParcelType (hence the asterisk in <ParcelType*>, right?)

It is filled like that:
Code:
    forAllIter(typename DsmcCloud<ParcelType>, *this, iter)
    {
        cellOccupancy_[iter().cell()].append(&iter());
    }
Why do I put the (&) before iter()?

So if I fill that list like that (now p should be a pointer because of the asterisk, right?), it still doesn't work:

Code:
        DynamicList<ParcelType*>& cellParcels();

        forAll (cellOccupancy_[cellI],i)
        {
            ParcelType* p
            p=cellOccupancy_[cellI][i];

            const bool allowedToMove = p->allowedToMove();
            if (allowedToMove)
            {
                cellParcels.append(p);
            }
        }
Interestingly, if I initialise the list like that:
Code:
        DynamicList<ParcelType*>& cellParcels(cellOccupancy_[cellI]);
instead of
Code:
        DynamicList<ParcelType*>& cellParcels();
, i can easily append (at least I do not get an error message) objects like this (although I do not have any idea of what I am doing ):
Code:
            ParcelType& p = *cellOccupancy_[cellI][i];

            const bool allowedToMove = p.allowedToMove();
            if (allowedToMove)
            {
                cellParcels.append(&p);
            }
Sorry that's a lot of code - I hope this is not to complicated

Can anyone help to get some light in my dark?
What does this mean?

ParcelType& p = *cellOccupancy_[cellI][i];

I thought I could either initialise a variable without putting anything between the type and the name or a pointer by putting an asterisk between type and variable?
My book teaches me that & points to the memory address of a variable. Why do I use it when I declare the variable? Why is defined with an asterisk before cellOccupancy? Isn't it a list filled with pointers anyway? Isn't the astersik meaning I have a pointer to a pointer (inceptionlike)... ?

Aiaiai... I hope someone still has the nerves to help me!
hua1015 likes this.
GPesch is offline   Reply With Quote

Old   July 19, 2013, 13:44
Default
  #6
Member
 
Join Date: Apr 2010
Posts: 61
Rep Power: 7
alquimista is on a distinguished road
Hello,

I have been also discussing how to remove elements from a dynamic list here . I wrote an simple example inserting and removing values in a HashTable. For now I have a little problem using HashTable in combination with findLower but someone can find it interesting if is looking for this kind of information.

Regards.
alquimista is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set periodic boundary conditions Ganesh FLUENT 13 January 22, 2014 05:11
mesh delete keeper CFX 6 December 17, 2012 11:59
fluent add additional zones for the mesh file SSL FLUENT 2 January 26, 2008 12:55
to delete or not to delete? Wooster CFX 15 November 1, 2007 20:54
Change or delete the materials type: Al Adi FLUENT 4 April 19, 2001 08:08


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