yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #16657
[Question #663441]: some modules fail to be loaded when i call a class from a python file
New question #663441 on Yade:
https://answers.launchpad.net/yade/+question/663441
Good evening,
I apologise for this question. I thought i had solved it before, but turns out the problem is still there.
So i have a class in a file called myclass.py that looks like this
from yade.pack import *
from yade import ymport
import sys
from yade import qt
sys.path.append('/home/john/Desktop/yade/workingclass')
from yadeimport import *
import math
class simul():
def __init__(self):
self.g=(0,0,9.81)
def definegravity(self,b):
self.g=b
def run(self):
facets = ymport.stl("maze1lid.stl")
rod1 = O.bodies.append(facets)
# converts facets to gts (see the other question)
s = gts.Surface()
for facet in facets:
vs = [facet.state.pos + facet.state.ori*v for v in facet.shape.vertices]
vs = [gts.Vertex(v[0],v[1],v[2]) for v in vs]
es = [gts.Edge(vs[i],vs[j]) for i,j in ((0,1),(1,2),(2,0))]
f = gts.Face(es[0],es[1],es[2])
s.add(f)
print s.is_closed()
threshold = 1e-3
s.cleanup(threshold)
print s.is_closed()
assert s.is_closed()
# use gts to filter spheres
pred = inGtsSurface(s)
sp=pack.randomDensePack(pack.inAlignedBox((boundaries[0],boundaries[2],boundaries[4]),(boundaries[1],boundaries[3],boundaries[5])),spheresInCell=3000,radius=r,memoizeDb='/tmp/triaxPackCache.sqlite',returnSpherePack=True)
# remove spheres completely inside walls
for c,r in sp:
if pred(c,0):
continue
O.bodies.append(sphere(c,r))
# remove spheres partially inside walls
O.dt = 0
O.step() # interactions are created afterwards
toErase = set()
for i in O.interactions:
b1,b2 = [O.bodies[i] for i in (i.id1,i.id2)]
if any(isinstance(b.shape,Facet) for b in (b1,b2)): # if facet is involved, delete
toErase.add(b1)
toErase.add(b2)
toErase = [b for b in toErase if isinstance(b.shape,Sphere)] # delete just spheres
for b in toErase: # delete the spheres
O.bodies.erase(b.id)
O.bodies.append([
sphere((0,0,4),1),
sphere(center=(0,0,0),radius=.5,fixed=True)
])
O.dt=.5e-4*PWaveTimeStep()
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),
PyRunner(iterPeriod=500,command='simulation.shake()'),
]
O.step()
def shake(self):
NewtonIntegrator(gravity =self.g)
print self.g
def irun(self,num):
print O.time
O.run(num,1)
which i run from a file called run.py that looks like this
import os
import math
import operator
import gts
import sys
sys.path.append('/home/john/Desktop/yade/workingclass')
os.system("ln -s /usr/bin/yade yadeimport.py")
from yadeimport import *
sys.path.append('/home/john/Desktop/yade/workingclass/myclass.py')
from myclass import simul
simulation=simul()
simulation.run()
simulation.irun(500)
simulation.definegravity((0,0,0))
simulation.irun(500)
before i try to input facets and have the particles inside the walls excluded it runs perfectly. When i try to do it however i get the error
Traceback (most recent call last):
File "run.py", line 19, in <module>
simulation.run()
File "/home/john/Desktop/workingclass/myclass.py", line 41, in run
pred = inGtsSurface(s)
NameError: global name 'inGtsSurface' is not defined
I tried yade.pack.inGtsSurface(s) and it still doesnt run
The stl file is this
http://dropmefiles.com/7JEXJ
I again apologize for asking this again.
Any response and aid will be greatly appreciated
Best Regards
John
--
You received this question notification because your team yade-users is
an answer contact for Yade.