← Back to team overview

yade-users team mailing list archive

Re: [Question #661017]: call a class from yade

 

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

    Status: Open => Answered

Deepak proposed the following answer:
Hi,

If I understand correctly, you intend to run yade under a ''pure python''
environment?  If that's the case you could have a look at these notes in
[1].  You might also want to look at how to instantiate an instance of your
class (having __init()__ method)[2].

An example of python script importing yade as a module is here [3] (this
script is based on one of the example scripts) [4]

[1]
https://yade-dem.org/doc/user.html#importing-yade-in-other-python-applications
[2]https://docs.python.org/2/tutorial/classes.html
[3]https://pastebin.com/J5FsRWQe
[4]
https://github.com/yade/trunk/blob/e4e757f2e98a620e3177b7a36a1d10f69f6a6a28/examples/concrete/triax.py


On Wed, Nov 22, 2017 at 6:08 PM, JOHN <question661017@xxxxxxxxxxxxxxxxxxxxx>
wrote:

> New question #661017 on Yade:
> https://answers.launchpad.net/yade/+question/661017
>
> Good evening,
> What i am trying to do is bundle the yade simulation in  a class which
> works
>
> from yade.pack import *
> from yade import ymport
> import math
> class simul():
>         def run(self):
>                 O.bodies.append([
>                         sphere((0,0,4),1),
>                         sphere(center=(0,0,0),radius=.5,fixed=True)
>                         ])
>
>                 O.engines=[
>                         ForceResetter(),
>                         InsertionSortCollider([Bo1_Sphere_Aabb()]),
>                         InteractionLoop(
>                                 [Ig2_Sphere_Sphere_ScGeom()],
>                                 [Ip2_FrictMat_FrictMat_FrictPhys()],
>                                 [Law2_ScGeom_FrictPhys_CundallStrack()]
>                         ),
>                 NewtonIntegrator(gravity=(0,0,-9.81),damping=0.1),
>                 ]
>                 O.dt=.5e-4*PWaveTimeStep()
>
>
>
> #simulation=simul()
> #simulation.run()
>
>
>
>
> and call it from another file
>
>
>
>
>
> import math
> import operator
> import gts
> from yade.pack import *
> from yade import ymport
>
>
> from myclass import simul
> simulation=simul()
> simulation.run()
>
>
>
> i get this
>
> yade run.py
>
> Welcome to Yade 1.20.0
> TCP python prompt on localhost:9000, auth cookie `ucsdsy'
> XMLRPC info provider on http://localhost:21000
> Running script run.py
> Traceback (most recent call last):
>   File "/usr/bin/yade", line 182, in runScript
>     execfile(script,globals())
>   File "run.py", line 10, in <module>
>     from myclass import simul
> ImportError: No module named myclass
> [[ ^L clears screen, ^U kills line. F12 controller, F11 3d view (use h-key
> for showing help), F10 both, F9 generator, F8 plot. ]]
> [0;34mYade [[1;34m1[0;34m]: [0m
>
>
> Thank you for the help
> (PS, amazing community)
>
>
>
> --
> 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@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-users
> More help   : https://help.launchpad.net/ListHelp
>

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