← Back to team overview

yade-users team mailing list archive

Re: [Question #235815]: Importing yade to use within python

 

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

Alexander Eulitz [Eugen] posted a new comment:
# -*- coding: utf-8 -*-


import sys
import os
sys.path.append('/home/dummy/Yade/YadePythonImport') #symbolic link to yade-daily
from yadePythonImport import *

os.environ['OMP_NUM_THREADS'] = '32'
from yade import utils
import time


class YadePythonSimulation():
    """
    Enthält alle wichtigen Eigenschaften einer Yade Simulation, die aus Python heraus gesteuert werden kann.
        
    """
    def __init__(self, name="", contactLaw = "HertzMindlin", gui = False):
        """ Arrange all base settings of simulation.
        """

        self.name = name
        self.O = O #get the Omega object from Yade. In this class Omega can be called directly 
        
        print 'Programmstart am ',time.strftime("%d.%m.%Y um %H:%M:%S Uhr") 
        print 'CPU-Zahl:', os.environ['OMP_NUM_THREADS']      
 

        O.engines=[ForceResetter(),
        	   InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
        	   InteractionLoop(
        		  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
        		  [Ip2_FrictMat_FrictMat_MindlinPhys()],
        		  [Law2_ScGeom_MindlinPhys_Mindlin()]       
        	   ),NewtonIntegrator(gravity=(0,0,-9.81), label='newtonIntegrator')
        	]
         
        O.bodies.append(utils.sphere((0,0,0), 1.0, fixed= True))
        for i in xrange(999): O.bodies.append(utils.sphere((0,0,1+i), 0.1))
        O.dt=1*utils.PWaveTimeStep()
        print 'Timestep:',O.dt	

        O.saveTmp()          
     
        
        if gui: #gui doesnt work when calling yade from python
            yade.qt.Controller()


    def run(self):
        timeToRun=10000000 #time in seconds
        iterToRun=int(timeToRun/O.dt)
        print 'running',iterToRun   
        O.run(iterToRun, True) #run endless to watch cpu usage with htop-package      

            
if __name__ == "__main__":
    yaPySi = YadePythonSimulation()
    sim1 = yaPySi.run()

-- 
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.