def stopIfDamaged(): global mode if O.iter<2 or not plot.data.has_key('sigma'): return # do nothing at the very beginning sigma,eps=plot.data['sigma'],plot.data['eps'] extremum=max(sigma) if (strainer.strainRate>0) else min(sigma) minMaxRatio=0.5 if mode=='tension' else 0.5 if extremum==0: return # uncomment to get graph for the very first time stopIfDamaged() is called #eudoxos.estimatePoissonYoung(principalAxis=axis,stress=strainer.avgStress,plot=True,cutoff=0.3) print O.tags['id'],mode,strainer.strain,sigma[-1] import sys; sys.stdout.flush() if abs(sigma[-1]/extremum)<minMaxRatio or abs(strainer.strain)>(5e-3 if isoPrestress==0 else 5e-2): if mode=='tension' and doModes & 2: # only if compression is enabled mode='compression' O.save('/tmp/uniax-tension.yade.gz') print "Saved /tmp/uniax-tension.yade.gz (for use with interaction-histogram.py and uniax-post.py)" print "Damaged, switching to compression... "; O.pause() # important! initTest must be launched in a separate thread; # otherwise O.load would wait for the iteration to finish, # but it would wait for initTest to return and deadlock would result import thread; thread.start_new_thread(initTest,()) return else: print "Damaged, stopping." ft,fc=max(sigma),min(sigma) print 'Strengths fc=%g, ft=%g, |fc/ft|=%g'%(fc,ft,abs(fc/ft)) title=O.tags['description'] if 'description' in O.tags.keys() else O.tags['params'] print 'gnuplot',plot.saveGnuplot(O.tags['id'],title=title) print 'Bye.' #O.pause() sys.exit(0)
def breakControl(): if (len(O.bodies) > 7): sigmaResT = maxFT[2]/(sizeB*sizeB)*factorR uT = startPos - O.bodies[topmesh[0]].state.pos[2] print ("STOP!!!!!!!!!!!!!!!!") print ('maxFT = %g;'%(sigmaResT)) plot.saveGnuplot(descriptionIn + 'plot') if (not(os.path.isfile('./resFile'))): fWT = open('./resFile','w') fWT.write('m\tV0\tP\tSCz\tSCd\todt\tSRES\tfactorR\tU\n') fWT.close() fW = open('./resFile','a'); fW.write(('%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n' % (Wei_m, Wei_V0, Wei_P, sigmaCZ, sigmaCD, odt, sigmaResT, factorR, uT))) fW.close() O.pause()
def stopIfDamaged(): global mode if O.iter<2 or 'sigma' not in plot.data: return # do nothing at the very beginning sigma,eps=plot.data['sigma'],plot.data['eps'] extremum=max(sigma) if (strainer.strainRate>0) else min(sigma) minMaxRatio=0.5 if mode=='tension' else 0.5 if extremum==0: return import sys; sys.stdout.flush() if abs(sigma[-1]/extremum)<minMaxRatio or abs(strainer.strain)>(5e-3 if isoPrestress==0 else 5e-2): if mode=='tension' and doModes & 2: # only if compression is enabled mode='compression' O.save('/tmp/uniax-tension.yade.gz') print("Saved /tmp/uniax-tension.yade.gz (for use with interaction-histogram.py and uniax-post.py)") print("Damaged, switching to compression... "); O.pause() # important! initTest must be launched in a separate thread; # otherwise O.load would wait for the iteration to finish, # but it would wait for initTest to return and deadlock would result import _thread; _thread.start_new_thread(initTest,()) return else: print("Damaged, stopping.") ft,fc=max(sigma),min(sigma) if doModes==3: print('Strengths fc=%g, ft=%g, |fc/ft|=%g'%(fc,ft,abs(fc/ft))) if doModes==2: print('Compressive strength fc=%g'%(abs(fc))) if doModes==1: print('Tensile strength ft=%g'%(abs(ft))) title=O.tags['description'] if 'description' in list(O.tags.keys()) else O.tags['params'] print('gnuplot',plot.saveGnuplot(O.tags['id'],title=title)) print('Bye.') O.pause()
def stopIfDamaged(): global mode if O.iter<2 or not plot.data.has_key('sigma'): return # do nothing at the very beginning sigma,eps=plot.data['sigma'],plot.data['eps'] extremum=max(sigma) if (strainer.maxStrainRate>0) else min(sigma) # FIXME: only temporary, should be .5 minMaxRatio=0.5 if mode=='tension' else 0.5 if extremum==0: return print O.tags['id'],mode,strainer.strain[axis],sigma[-1] #print 'strain',strainer['strain'],'stress',strainer['stress'] import sys; sys.stdout.flush() if abs(sigma[-1]/extremum)<minMaxRatio or abs(strainer.strain[axis])>6e-3: if mode=='tension' and doModes & 2: # only if compression is enabled mode='compression' #O.save('/tmp/uniax-tension.xml.bz2') print "Damaged, switching to compression... "; O.pause() # important! initTest must be launched in a separate thread; # otherwise O.load would wait for the iteration to finish, # but it would wait for initTest to return and deadlock would result import thread; thread.start_new_thread(initTest,()) return else: print "Damaged, stopping." ft,fc=max(sigma),min(sigma) print 'Strengths fc=%g, ft=%g, |fc/ft|=%g'%(fc,ft,abs(fc/ft)) title=O.tags['description'] if 'description' in O.tags.keys() else O.tags['params'] print 'gnuplot',plot.saveGnuplot(O.tags['id'],title=title) print 'Bye.' # O.pause() sys.exit(0)
def stopIfDamaged(): global mode if O.iter < 2 or not plot.data.has_key('sigma'): return # do nothing at the very beginning sigma, eps = plot.data['sigma'], plot.data['eps'] extremum = max(sigma) if (strainer.strainRate > 0) else min(sigma) minMaxRatio = 0.5 if mode == 'tension' else 0.5 if extremum == 0: return # uncomment to get graph for the very first time stopIfDamaged() is called #eudoxos.estimatePoissonYoung(principalAxis=axis,stress=strainer.avgStress,plot=True,cutoff=0.3) import sys sys.stdout.flush() if abs(sigma[-1] / extremum) < minMaxRatio or abs( strainer.strain) > (5e-3 if isoPrestress == 0 else 5e-2): if mode == 'tension' and doModes & 2: # only if compression is enabled mode = 'compression' O.save('/tmp/uniax-tension.yade.gz') print "Saved /tmp/uniax-tension.yade.gz (for use with interaction-histogram.py and uniax-post.py)" print "Damaged, switching to compression... " O.pause() # important! initTest must be launched in a separate thread; # otherwise O.load would wait for the iteration to finish, # but it would wait for initTest to return and deadlock would result import thread thread.start_new_thread(initTest, ()) return else: print "Damaged, stopping." ft, fc = max(sigma), min(sigma) print 'Strengths fc=%g, ft=%g, |fc/ft|=%g' % (fc, ft, abs(fc / ft)) title = O.tags['description'] if 'description' in O.tags.keys( ) else O.tags['params'] print 'gnuplot', plot.saveGnuplot(O.tags['id'], title=title) print 'Bye.' O.pause()
def breakControl(): if (len(O.bodies) > 7): sigmaResT = maxFT[2] / (sizeB * sizeB) * factorR uT = startPos - O.bodies[topmesh[0]].state.pos[2] print("STOP!!!!!!!!!!!!!!!!") print('maxFT = %g;' % (sigmaResT)) plot.saveGnuplot(descriptionIn + 'plot') if (not (os.path.isfile('./resFile'))): fWT = open('./resFile', 'w') fWT.write('m\tV0\tP\tSCz\tSCd\todt\tSRES\tfactorR\tU\n') fWT.close() fW = open('./resFile', 'a') fW.write(('%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n' % (Wei_m, Wei_V0, Wei_P, sigmaCZ, sigmaCD, odt, sigmaResT, factorR, uT))) fW.close() O.pause()
def stopIfDamaged(maxEps=5e-3): extremum = max(abs(s) for s in plot.data['s']) s = abs(plot.data['s'][-1]) e = abs(plot.data['e'][-1]) if O.iter < 1000 or s > .5*extremum and e < maxEps: return f = os.path.join(exportDir,fileName) print 'gnuplot',plot.saveGnuplot(f,term='png') if runGnuplot: import subprocess os.chdir(exportDir) subprocess.Popen(['gnuplot',f+'.gnuplot']).wait() print 'Simulation finished' O.pause()
def stopIfDamaged(maxEps=5e-3): extremum = max(abs(s) for s in plot.data['s']) s = abs(plot.data['s'][-1]) e = abs(plot.data['e'][-1]) if O.iter < 1000 or s > .5 * extremum and e < maxEps: return f = os.path.join(exportDir, fileName) print 'gnuplot', plot.saveGnuplot(f, term='png') if runGnuplot: import subprocess os.chdir(exportDir) subprocess.Popen(['gnuplot', f + '.gnuplot']).wait() print 'Simulation finished' O.pause()
def stopIfDamaged(): global mode if O.iter < 2 or not plot.data.has_key('sigma'): return # do nothing at the very beginning sigma, eps = plot.data['sigma'], plot.data['eps'] extremum = max(sigma) if (strainer.maxStrainRate > 0) else min(sigma) # FIXME: only temporary, should be .5 minMaxRatio = 0.5 if mode == 'tension' else 0.5 if extremum == 0: return print O.tags['id'], mode, strainer.strain[axis], sigma[-1] #print 'strain',strainer['strain'],'stress',strainer['stress'] import sys sys.stdout.flush() if abs(sigma[-1] / extremum) < minMaxRatio or abs( strainer.strain[axis]) > 6e-3: if mode == 'tension' and doModes & 2: # only if compression is enabled mode = 'compression' #O.save('/tmp/uniax-tension.xml.bz2') print "Damaged, switching to compression... " O.pause() # important! initTest must be launched in a separate thread; # otherwise O.load would wait for the iteration to finish, # but it would wait for initTest to return and deadlock would result import thread thread.start_new_thread(initTest, ()) return else: print "Damaged, stopping." ft, fc = max(sigma), min(sigma) print 'Strengths fc=%g, ft=%g, |fc/ft|=%g' % (fc, ft, abs(fc / ft)) title = O.tags['description'] if 'description' in O.tags.keys( ) else O.tags['params'] print 'gnuplot', plot.saveGnuplot(O.tags['id'], title=title) print 'Bye.' # O.pause() sys.exit(0)
r2) s3 = (O.bodies[id32].state.pos[2] - O.bodies[id31].state.pos[2]) - (r1 + r2) s4 = (O.bodies[id42].state.pos[2] - O.bodies[id41].state.pos[2]) - (r1 + r2) plot.addData(fc1=f1[2], sc1=-s1, fc2=f2[2], sc2=-s2, fc3=f3[2], sc3=-s3, fc4=f4[2], sc4=-s4) plot.plots = { 'sc1': ('fc1'), 'sc2': ('fc2'), 'sc3': ('fc3'), 'sc4': ('fc4') } plot.plot() from yade import qt qt.View() O.run(320000) O.wait() plot.saveGnuplot('sim-data_LudigPM')
[Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys(),], [Law2_ScGeom_FrictPhys_CundallStrack(),] ), PyRunner(iterPeriod=100,command='myAddPlotData()',label='plotDataCollector'), NewtonIntegrator(damping=0.4,gravity=(0,0,gravity))## here we use the 'gravity' parameter ] O.bodies.append([ box([0,50,0],extents=[1,50,1],fixed=True,color=[1,0,0]), sphere([0,0,10],1,color=[0,1,0]) ]) O.bodies[1].state.vel=(0,initialSpeed,0) ## assign initial velocity O.dt=.8*PWaveTimeStep() ## o.saveTmp('initial') def myAddPlotData(): s=O.bodies[1] plot.addData({'t':O.time,'y_sph':s.state.pos[1],'z_sph':s.state.pos[2]}) plot.plots={'y_sph':('z_sph',)} # run 30000 iterations O.run(20000,True) # write some results to a common file # (we rely on the fact that 2 processes will not write results at exactly the same time) # 'a' means to open for appending #file('multi.out','a').write('%s %g %g %g %g\n'%(O.tags['description'],gravity,density,initialSpeed,O.bodies[1].state.pos[1])) file('multi.out','a').write('%g %g %g %g\n'%(gravity,density,initialSpeed,O.bodies[1].state.pos[1])) print('gnuplot',plot.saveGnuplot(O.tags['id']))
]) O.bodies[1].state.vel = (0, initialSpeed, 0) ## assign initial velocity O.dt = .8 * utils.PWaveTimeStep() ## o.saveTmp('initial') def myAddPlotData(): s = O.bodies[1] plot.addData({ 't': O.time, 'y_sph': s.state.pos[1], 'z_sph': s.state.pos[2] }) plot.plots = {'y_sph': ('z_sph', )} # run 30000 iterations O.run(20000, True) # write some results to a common file # (we rely on the fact that 2 processes will not write results at exactly the same time) # 'a' means to open for appending #file('multi.out','a').write('%s %g %g %g %g\n'%(O.tags['description'],gravity,density,initialSpeed,O.bodies[1].state.pos[1])) file('multi.out', 'a').write('%g %g %g %g\n' % (gravity, density, initialSpeed, O.bodies[1].state.pos[1])) print 'gnuplot', plot.saveGnuplot(O.tags['id'])
global iterN if (O.bodies[id2].state.vel[2]<0.0): O.bodies[id2].state.vel*=-1.0 cDir.iterPeriod = int(iterN/10000.0) elif (O.bodies[id2].state.pos[2]-O.bodies[id1].state.pos[2])-(r1 + r2) > 0.0: iterN = int(iterN*1.2) O.bodies[id2].state.vel[2]*=-1.0 cDir.iterPeriod = iterN def addPlotData(): f = [0,0,0] sc = 0 try: f=O.forces.f(id2) except: f = [0,0,0] s1 = (O.bodies[id2].state.pos[2]-O.bodies[id1].state.pos[2])-(r1 + r2) fc1 = f[2] sc1 = -s1/r1 plot.addData(fc1=fc1, sc=sc1) plot.plots={'sc':('fc1')}; plot.plot() from yade import qt qt.View() plot.saveGnuplot('sim-data_LudigPM')