"calm function" inside source code

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

Bug Description

Hi,

I need a "calm function" for my generation process. In python code it looks like this:

def calm():
 for b in O.bodies:
  if isinstance(b.shape,Sphere) or b.isClump:
   b.state.vel = Vector3(0,0,0)
   b.state.angVel = Vector3(0,0,0)
   b.state.angMom = Vector3(0,0,0)

I detected, that it is very slow in the case it is called by PyRunner for e.g. every 2 steps.

O.engines=O.engines+[PyRunner(iterPeriod=2,command='calm()')]

Would it be faster, when it is implemented inside C++ source code?
If yes, where can I implement it (which file)?

Regards,

Christian

Revision history for this message
Anton Gladky (gladky-anton) wrote : Re: [Bug 1026073] [NEW] "calm function" inside source code

Hi,

pkg/dem/Shop.cpp should probably be the right place.
As an example, you can have a look, how "Shop::getSpheresMass" [1] and [2]
was implemented, it can be also useful to keep "mask" parameter for more
flexibility.

Do not forget to add a python-wrapper for this function into
py/_utils.cpp [3] and [4].

Have a luck!

Anton

[1] https://github.com/yade/trunk/blob/master/pkg/dem/Shop.hpp#L59
[2] https://github.com/yade/trunk/blob/master/pkg/dem/Shop.cpp#L295
[3] https://github.com/yade/trunk/blob/master/py/_utils.cpp#L404
[4] https://github.com/yade/trunk/blob/master/py/_utils.cpp#L456

Revision history for this message
Jan Stránský (honzik) wrote : Re: [Yade-dev] [Bug 1026073] [NEW] "calm function" inside source code

Hello Christian,

I would say it will be faster in c++ (as almost anything :-). Esepcially
here you can save a lot of time by changing allocation of new Vector3r
object for each particle to just rewriting doubles.

As the place I would use Shop.*pp file for c++ code and utils module for
python interface (if nobody else disagree).

regards
Jan

2012/7/18 Christian Jakob <email address hidden>

> Public bug reported:
>
> Hi,
>
> I need a "calm function" for my generation process. In python code it
> looks like this:
>
> def calm():
> for b in O.bodies:
> if isinstance(b.shape,Sphere) or b.isClump:
> b.state.vel = Vector3(0,0,0)
> b.state.angVel = Vector3(0,0,0)
> b.state.angMom = Vector3(0,0,0)
>
> I detected, that it is very slow in the case it is called by PyRunner
> for e.g. every 2 steps.
>
> O.engines=O.engines+[PyRunner(iterPeriod=2,command='calm()')]
>
> Would it be faster, when it is implemented inside C++ source code?
> If yes, where can I implement it (which file)?
>
> Regards,
>
> Christian
>
> ** Affects: yade
> Importance: Wishlist
> Status: New
>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/1026073
>
> Title:
> "calm function" inside source code
>
> Status in Yet Another Dynamic Engine:
> New
>
> Bug description:
> Hi,
>
> I need a "calm function" for my generation process. In python code it
> looks like this:
>
> def calm():
> for b in O.bodies:
> if isinstance(b.shape,Sphere) or b.isClump:
> b.state.vel = Vector3(0,0,0)
> b.state.angVel = Vector3(0,0,0)
> b.state.angMom = Vector3(0,0,0)
>
> I detected, that it is very slow in the case it is called by PyRunner
> for e.g. every 2 steps.
>
> O.engines=O.engines+[PyRunner(iterPeriod=2,command='calm()')]
>
> Would it be faster, when it is implemented inside C++ source code?
> If yes, where can I implement it (which file)?
>
> Regards,
>
> Christian
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/1026073/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp
>

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

Thank you for your help.

I think I did it, but there is a compilation warning:

/home/me/YADE/trunk/pkg/dem/Shop.cpp: In static member function ‘static Real Shop::calm(const boost::shared_ptr<Scene>&, int)’:
/home/me/YADE/trunk/pkg/dem/Shop.cpp:838: warning: no return statement in function returning non-void

Shall I say "return 0;" at the end of the function?

Revision history for this message
Anton Gladky (gladky-anton) wrote : Re: [Bug 1026073] Re: "calm function" inside source code

2012/7/18 Christian Jakob <email address hidden>:
> I think I did it, but there is a compilation warning:
>
> /home/me/YADE/trunk/pkg/dem/Shop.cpp: In static member function ‘static Real Shop::calm(const boost::shared_ptr<Scene>&, int)’:
> /home/me/YADE/trunk/pkg/dem/Shop.cpp:838: warning: no return statement in function returning non-void
>
> Shall I say "return 0;" at the end of the function?

Why not to declare it as "void", if you are not going to return any value?

Anton

Revision history for this message
Jan Stránský (honzik) wrote : Re: [Yade-dev] [Bug 1026073] Re: "calm function" inside source code

>
> Shall I say "return 0;" at the end of the function?
>

It is one option, or just change

static Real Shop::calm(const boost::shared_ptr<Scene>&, int)

to

static void Shop::calm(const boost::shared_ptr<Scene>&, int)

Jan

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

Jan and Anton, are you twins?

... you are giving same answer at the same time ^^

Revision history for this message
Anton Gladky (gladky-anton) wrote : Re: [Bug 1026073] Re: "calm function" inside source code

Something is wrong with Launchpad. It resends mails too late.

Anton

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

calm function is not working yet (see attachment)
it seems it does not set velocities to zero, I can see no effect at all ... ?!

Revision history for this message
Jan Stránský (honzik) wrote : Re: [Yade-dev] [Bug 1026073] Re: "calm function" inside source code

Hello Christian,

in PyRunner, instead of command='calm', try:

command='calm()'

with braces.

Jan

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

Ah, ok. Works fine with braces ;)

Changed in yade:
status: New → Fix Released
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.