"extra" value for bodies

Bug #1031703 reported by Christian Jakob
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Yade
Invalid
Wishlist
Unassigned

Bug Description

Hi,

It would be very helpful, if there would be an "extra" value for every body. This value can be set by the user. It must be a very fexible value (bool, int, float, vector, array, etc.).

Example:
I create a clump, which consists of two hardly overlapping spheres and sometimes I need the volume of the clump (which is not the sum of the volumes of the two spheres in this case). So this could be easily managed by this "extra" value. Where i could set either the volume of the clump as extra value to the clump or i could set the volume fractions as extra values to the spheres.

Changed in yade:
importance: Undecided → Wishlist
Revision history for this message
Jan Stránský (honzik) wrote : Re: [Yade-dev] [Bug 1031703] [NEW] "extra" value for bodies

Hello Christian,

sorry if I misunderstood your question, but would you like to achieve this?

Yade [1]: b = utils.sphere((1,1,1),1)

Yade [2]: O.bodies.append(b)
 -> [2]: 0

Yade [3]: b.extra = 4

Yade [4]: b.extra
 -> [4]: 4

Yade [5]: b.extra = Vector3(1,2,3)

Yade [6]: b.extra
 -> [6]: Vector3(1,2,3)

Jan

Revision history for this message
Christian Jakob (jakob-ifgt) wrote :

For further explanation (my first ideas):

We could first make an easy-to-implement feature, later it could be extended.
Lets say we just want to let extra variable be int or float. Also for the start, there is
only one extra value allowed for one body (as said, later we can extend if needed)...
The user has to type in python something like:

var1 = 123
var2 = 1.23

O.bodies[id1].extra(var1,'int') or O.bodies[id2].extra(var2,'float')

Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

The problem is not how to access the extra variables in python but how to implement them in c++.
For storing arbitrary types, I see at least two ways:
1/ void pointers + some typecasting
2/ add template parameters to the class Body

(2) is forbidden in yade as serialization and python wrapping don't seem to like templates.
(1) would be complex to implement but it could work maybe.

Of course, it is possible to add a float and a int to each body, call them extraInt/extraReal, and let the users use them or not. However, it can't be extended since it means a waste of memory as soon as the extra variables are not used.

If the only problem of Jan's suggestion is that the values are not saved, then the simpler thing would be to find a convenient way to save them.

Now, to be honest, I should mention that there are already 7 extra values in each body:
((Vector3r,refPos,Vector3r::Zero(),,"Reference position"))
((Quaternionr,refOri,Quaternionr::Identity(),,"Reference orientation"))

Since they are only used for a very specific type of postprocessing, you can assign any value to them without interfering with the computation. However, it is a short term solution since I would like to remove these parameters one day.

Revision history for this message
Jan Stránský (honzik) wrote : Re: [Yade-dev] [Bug 1031703] Re: "extra" value for bodies

The problem is not how to access the extra variables in python but how to
> implement them in c++.
> For storing arbitrary types, I see at least two ways:
> 1/ void pointers + some typecasting
> 2/ add template parameters to the class Body
>
>
3/ store the string representation of desired variable (as suggested a few
mails above). From my point of view it would be the least effort and for
the same functionality. Example:

Yade [1]: b = utils.sphere((1,2,3),4)

Yade [2]: O.bodies.append(b)
 -> [2]: 0

Yade [3]: a = Vector3(1,2,3)

Yade [4]: b.extra = repr(a)

Yade [5]: b.extra
 -> [5]: 'Vector3(1,2,3)'

Yade [6]: c = eval(b.extra)

Yade [7]: c
 -> [7]: Vector3(1,2,3)

Yade [8]: a + c
 -> [8]: Vector3(2,4,6)

Jan

Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

>3/ store the string representation of desired variable

Yes that one too. I aprooved when I read it but didn't recall it.
Not sure it would be easier than void pointer though, since it would need a lot of typecasting.
Your example is ok in python but the vector3 can't be used in c++ at this point. Getting arbitrary types from a string in c++ is another story.
I guess Christian has in mind to use e.g. clump volume in some c++ algorithm (right?), else there is little interest in adding variables to bodies.

Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

Another option is to keep the data outside bodies in a separate table. Saving a table is no big deal, and it doesn't waste memory when the table is empty.

Revision history for this message
Jan Stránský (honzik) wrote :

2012/8/2 Chareyre <email address hidden>

> >3/ store the string representation of desired variable
>
> Yes that one too. I aprooved when I read it but didn't recall it.
> Not sure it would be easier than void pointer though, since it would need
> a lot of typecasting.
> Your example is ok in python but the vector3 can't be used in c++ at this
> point. Getting arbitrary types from a string in c++ is another story.
> I guess Christian has in mind to use e.g. clump volume in some c++
> algorithm (right?), else there is little interest in adding variables to
> bodies.
>
>
I was just thinking about using it in python, if it is supposed to be used
in c++, then my solution definitely isn't the best one :-)
Jan

Revision history for this message
Christian Jakob (jakob-ifgt) wrote :

> I guess Christian has in mind to use e.g. clump volume in some c++ algorithm (right?), else there is little interest in adding variables to bodies.

No, in my example I need clump volume to calculate porosity. This is done in python code.
But I dont know what other users want to do with their extra values in c++ ...

>Another option is to keep the data outside bodies in a separate table. Saving a table is no big deal, and it doesn't waste memory when the table is empty.

This sounds good. A table, that stores id or pointer of the body and the extra value(s). This is also extendable, e.g. someone needs mor than one extra value per body.

Changed in yade:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.