NameError: global name 'inGtsSurface' is not defined

Asked by JOHN

Good evening all,
So, i tried to wrap my code in a python class and call it from somewhere else.
However, when i run it i get the following terminal output

Traceback (most recent call last):
  File "run.py", line 17, in <module>
    simulation.run()
  File "/home/john/Desktop/yade/experimentsworkingclass/myclass.py", line 44, in run
    pred = inGtsSurface(s)
NameError: global name 'inGtsSurface' is not defined

Specifically, the code is

from yade.pack import *
from yade import ymport
import sys
from yade import qt
import gts

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):

  from yade import ymport
  import sys
  from yade import qt

  facets = ymport.stl('maze4lid.stl')
  rod1 = O.bodies.append(facets)

  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()
  a=(0,9.81,0)
  # use gts to filter spheres
  pred = inGtsSurface(s)

  O.engines=[

     ForceResetter(),
     InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
     InteractionLoop(
  # handle sphere+sphere and facet+sphere collisions
        [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
        [Ip2_FrictMat_FrictMat_FrictPhys()],
        [Law2_ScGeom_FrictPhys_CundallStrack()]
     ),
     NewtonIntegrator(gravity=(0,-9.81,0),damping=0.4, label='newtonInt'),
       PyRunner(command='if O.time<5:shake()',iterPeriod=1),

  ]

  sp=pack.SpherePack()
  sp.makeCloud((10,40,3),(30,60,12),rMean=0.5)

  # 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.dt=.5*PWaveTimeStep()

 def shake(self):
  NewtonIntegrator(gravity =self.g)
  print self.g

 def irun(self,num):
  print O.time
  O.run(num,1)

and the python file calling it is

import os
import math
import operator
import gts
import sys
sys.path.append('/home/john/Desktop/yade/experimentsworkingclass')
os.system("ln -s /usr/bin/yade yadeimport.py")
from yadeimport import *

from myclass import simul

simulation=simul()
simulation.run()
simulation.irun(500)
simulation.definegravity((0,0,0))
simulation.irun(500)

#os.system("yade inafunc.py")

Thank you very much for any help
John

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
JOHN (washingmachine) said :
#1

http://dropmefiles.com/z0xlX

this is the stl file by the way

Revision history for this message
Best Jan Stránský (honzik) said :
#2

would

from yade import pack
pack.inGtsSurface

or

import yade
yade.pack.inGtsSurface

help?
Jan

Revision history for this message
JOHN (washingmachine) said :
#3

Hello,
thank you for the reply
unfortunately it didnt help.

i am calling the class code from a python file by using python run.py if this makes any difference

John

Revision history for this message
Jan Stránský (honzik) said :
#4

For the answer, see [1]

@John: please do not ask the same question twice

[1] https://answers.launchpad.net/yade/+question/661286

Revision history for this message
JOHN (washingmachine) said :
#5

Thanks Jan Stránský, that solved my question.