Question #704311 on Yade changed:
https://answers.launchpad.net/yade/+question/704311

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,

First of all, always try to provide a MWE [1], such that we know how
exactly the code is used and in which context.

> O.engines=O.engines+[...]

**My** recommendation is not to use this this king of structure unless 
necessary.
Better approach is to set everything while creating O.engines, i.e.
###
O.engines = [
... # all engines here
]
###

> However, the variable "rad_vel" is not changed during the simulation.

Surely the variable "rad_vel" is changed, just print it:
###
def cal_wall_rot():
       global rad_vel
       rad_vel = "function of sine(O.time)"
       print(rad_vel) # should print current value
###

That it has no effect on the RotationEngine is another point.
rad_vel is a value. If you pass it to 
RotationEngine(...,angularVelocity=rad_vel), and then you change rad_vel, it 
has no effect on angularVelocity, because the angularVelocity value is just 
copy of passed rad_vel at the time of creation.
You need to modify the attribute of the RotationEngine instance, not a global 
variable rad_vel.

> Anyway, I have found another way to change the velocity of the facet using 
> b.state.
> Is this the only way to control the motion of bodies with time?

yes and no (depending on definition of "the only way")
Modifying directly state is one option.
Using RotationEngine (or other similar engine, like HelixEngine) is another 
option. However, internally they just modify state.. (hence the dependency on 
definition)

===============
Solution:
modify attribute of RotationEngine instance, not an independent rad_vel 
variable.

First, you need to access to the instance. A few options:

-  using instance directly
###
rot = RotationEngine(...)
O.engines = [
   ...,
   rot,
]
###

- using label
### 
O.engines = [
    ...,
    RotationEngine(...,label="rot"),
]

- using O.engines[index]:
###
rot = O.engines[indexOfRotationEngine]
###

Once having "rot" instance, you can do whatever you like with it, in your case 
most likely something like:
###
def cal_wall_rot():
       rot.angularVelocity = "function of sine(O.time)"
###

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

_______________________________________________
Mailing list: https://launchpad.net/~yade-users
Post to     : yade-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp

Reply via email to