← Back to team overview

yade-users team mailing list archive

Re: Updating Engines in Python

 

> I have some problems while updating my engines during a simulation
> with python.
> 
> For example I declare in the beginning:
> O.engines=[
> ...
> GravityEngine(gravity=(0,0,-9.81))
> ...
> ]
> 
> then i later want to update the gravity during the simulation, for
> example
> gravity=(0,0,-9810)
> 
> How should I do that?

You get the engine object and update the attribute.

1. The simplest is to assign label to engine, which will create
automagically variable of that name:

O.engines=[
	# ...
	GravityEngine(gravity=(0,0,-9.81),label='gravitator'),
	# ...
]

# do things here, such as running simulation etc
gravitator.gravity=(0,0,0)

2. If you don't want to use label for some reason, you can find the
engine by its type (class name) utils.typedEngine('GravityEngine'), e.g.

gravitator=utils.typedEngine('GravityEngine').

3. Finally, you can get it simply by its index, such as
O.engines[4].gravity=(0,0,0), but this it ugly, since the index might
change as you add another engines later.

HTH, Vaclav






References