def history(): plot.addData( t=O.time, i=O.iter, temp1=axisBodies[0].state.temp, temp2=axisBodies[1].state.temp, temp3=axisBodies[2].state.temp, temp4=axisBodies[3].state.temp, temp5=axisBodies[4].state.temp, temp6=axisBodies[5].state.temp, temp7=axisBodies[6].state.temp, temp8=axisBodies[7].state.temp, temp9=axisBodies[8].state.temp, temp10=axisBodies[9].state.temp, temp11=axisBodies[10].state.temp, AnalyTemp1=analyticalHeatSolution(0, O.time, t0, mx[0], thermalDiff), AnalyTemp2=analyticalHeatSolution(axisBodies[1].state.pos[0], O.time, t0, mx[0], thermalDiff), AnalyTemp3=analyticalHeatSolution( axisBodies[2].state.pos[0] - min(axisTrue), O.time, t0, max(axisTrue) - min(axisTrue), thermalDiff), AnalyTemp4=analyticalHeatSolution( axisBodies[3].state.pos[0] - min(axisTrue), O.time, t0, max(axisTrue) - min(axisTrue), thermalDiff), #bndFlux1 = thermal.thermalBndFlux[0], #bndFlux2 = thermal.thermalBndFlux[1] AnalyTemp5=analyticalHeatSolution(mx[0], O.time, t0, mx[0], thermalDiff)) plot.saveDataTxt( 'txt' + timeStr + identifier + '/conductionAnalyticalComparison.txt', vars=('t', 'i', 'temp1', 'temp2', 'temp3', 'temp4', 'temp5', 'temp6', 'temp7', 'temp8', 'temp9', 'temp10', 'temp11'))
def dataCollector(): R = O.bodies[refPoint] plot.addData(v=R.state.vel[1], p=R.state.pos[1] - p0, iterations=O.iter, t=O.realtime) plot.saveDataTxt(output)
def stopUnloading(): if abs(O.forces.f(plate.id)[2]) < minLoad: # O.tags can be used to retrieve unique identifiers of the simulation # if running in batch, subsequent simulation would overwrite each other's output files otherwise # d (or description) is simulation description (composed of parameter values) # while the id is composed of time and process number plot.saveDataTxt(O.tags['d.id'] + '.txt') O.pause()
def stopUnloading(): if abs(O.forces.f(plate.id)[2])<minLoad: # O.tags can be used to retrieve unique identifiers of the simulation # if running in batch, subsequent simulation would overwrite each other's output files otherwise # d (or description) is simulation description (composed of parameter values) # while the id is composed of time and process number plot.saveDataTxt(O.tags['d.id']+'.txt') O.pause()
def checkUnbalanced(): # define the contact friction setContactFriction(radians(45)) for i in O.interactions: i.phys.tangensOfFrictionAngle = tan(.6) if unbalancedForce() < .05: O.pause() plot.saveDataTxt('bbb.txt.bz2') # plot.saveGnuplot('bbb') is also possible savedata()
def checkDistorsion(): # if the distorsion value is >.3, exit; otherwise do nothing if abs(O.cell.trsf[0,2])>.5: # save data from addData(...) before exiting into file # use O.tags['id'] to distinguish individual runs of the same simulation plot.saveDataTxt(O.tags['id']+'.txt') # exit the program #import sys #sys.exit(0) # no error (0) O.pause()
def checkDistorsion(): # if the distorsion value is >.3, exit; otherwise do nothing if abs(O.cell.trsf[0, 2]) > .5: # save data from addData(...) before exiting into file # use O.tags['id'] to distinguish individual runs of the same simulation plot.saveDataTxt(O.tags['id'] + '.txt') # exit the program #import sys #sys.exit(0) # no error (0) O.pause()
def addSimData(): inter = O.interactions[0, 1] u = inter.geom.penetrationDepth if u > obsCtrlData[-1]: plot.addData(u=u, f=inter.phys.normalForce.norm()) obsCtrlData.pop() if not obsCtrlData: # File name: <simName>_<key>_<param0>_<param1>_..._<paramN>.txt # TODO How to pass argument (simName) from GrainLearning to yade-batch dataName = '2particle_%i_%.10e_%.10e' % (table.key, table.E, table.nu) + '.txt' plot.saveDataTxt(dataName) O.pause()
def history(): plot.addData( ftemp1=flow.getPoreTemperature((0.024,0.023,0.02545)), p=flow.getPorePressure((0.025,0.025,0.025)), t=O.time, i = O.iter, temp1 = axisBodies[0].state.temp, temp2 = axisBodies[1].state.temp, temp3 = axisBodies[2].state.temp, temp4 = axisBodies[3].state.temp, temp5 = axisBodies[4].state.temp, bodyOfIntTemp = O.bodies[bodyOfInterest.id].state.temp ) plot.saveDataTxt('txt'+timeStr+identifier+'/temps'+identifier+'.txt',vars=('t','i','p','ftemp1', 'temp1','temp2','temp3','bodyOfIntTemp'))
def stressStrainHist(): plot.addData(i=O.iter, time=O.time, disp=-O.time * dispVel, P=getPistonForce(), pistonVel=pistonEngine.velocity, PistonDisp=getPistonDisp(), Pblock1=checkBlockEngagement()[0], Pblock2=checkBlockEngagement()[1]) plot.saveDataTxt('txt/data' + identifier + '.txt', vars=('i', 'disp', 'P', 'pistonVel', 'PistonDisp')) momentFile = 'moments_' + identifier + '.txt' AEcount = 0 if os.path.isfile(momentFile): AEcount = sum(1 for line in open(momentFile)) f = open('txt/' + AEfile, 'a') P, pistonDisp = plot.data['P'], plot.data['PistonDisp'] f.write('%g %g %g %g %g\n' % (O.time, O.iter, AEcount, P[-1], pistonDisp[-1])) f.close
def addPlotData(): if debug: print('addPlotData') sig_a = triax.stress[2] sig_r = 0.5 * (triax.stress[0] + triax.stress[1]) C = avgNumInteractions(skipFree=False) CN = avgNumInteractions(skipFree=True) overlap = np.mean( [inter.geom.penetrationDepth for inter in O.interactions]) p = (sig_a + 2 * sig_r) / -3e6 q = (sig_a - sig_r) / -1e6 K0 = sig_r / sig_a n = porosity() e_x, e_y, e_z = -triax.strain e_v = e_x + e_y + e_z plot.addData(p=p, q=q, n=n, e_x=e_x, e_y=e_y, e_z=e_z, C=C, CN=CN, overlap=overlap, K0=K0) if checkWaveSpeed: if abs(e_z - checkStrain[-1]) / checkStrain[-1] < 0.01: O.save(stateDir + testName + '%i_%.5e_%.5f_%.5f_%.5f_%.5f' % (table.key, table.E, mu_i, table.mu, table.kr, table.mu_r) + '_%.5f' % (checkStrain.pop()) + '.yade.gz') if len(checkStrain) == 0: O.pause() exit() if len(loadData) != 0: startLoading() else: dataName = stateDir + testName + '%i_%.5e_%.5f_%.5f_%.5f_%.5f' % ( table.key, table.E, mu_i, table.mu, table.kr, table.mu_r) + '.txt' plot.saveDataTxt(dataName) O.pause()
def recorder(): global ex0, ey0, ez0 crackVolume = crackSurface = 0 for i in O.interactions: if i.phys.isBroken: crackVolume += i.phys.crossSection * i.phys.crackJointAperture crackSurface += i.phys.crossSection yade.plot.addData(t=O.time, i=O.iter, ex=triax.strain[0] - ex0, ey=triax.strain[1] - ey0, ez=triax.strain[2] - ez0, sx=triax.stress(triax.wall_right_id)[0], sy=triax.stress(triax.wall_top_id)[1], sz=triax.stress(triax.wall_front_id)[2], p=flow.getPorePressure( (xinf + X / 2., yinf + Y / 2., zinf + Z / 2.)), tc=interactionLaw.nbTensCracks, sc=interactionLaw.nbShearCracks, p32=crackSurface, p33=crackVolume, unbF=utils.unbalancedForce(), momEnergy=kineticEnergy) plot.saveDataTxt(OUT)
def checkUnbalanced(): if unbalancedForce() < .05: O.pause() plot.saveDataTxt('bbb.txt.bz2') # plot.saveGnuplot('bbb') is also possible savedata()
def checkUnbalanced(): if utils.unbalancedForce() < .05: O.pause() plot.saveDataTxt('bbb.txt.bz2')
def saveData(): plot.saveDataTxt('data/'+O.tags['description']+'.dat',vars=('t','x','y','z','vx','vy','vz','v','wx','wy','wz','w'))
def checkUnbalanced(): if utils.unbalancedForce() < 0.05: O.pause() plot.saveDataTxt("bbb.txt.bz2")
def SavePlot(): global m_savefile, m_simuParams; plot.saveDataTxt(m_savefile,headers=m_simuParams);
def savePlotData(): plot.saveDataTxt(titleText(O.dt, mass, J_rot_value, gaussWidth) + '.txt')
def savePlotData(): plot.saveDataTxt('dt=' + str(O.dt) + '_gaussWidth=' + str(gaussWidth) + '_cols_' + str(potentialColumnX) + '_' + str(potentialColumnVal) + '.txt')
def averageDamageTensor(): topids = set(b.id for b in top) botids = set(b.id for b in bot) ids = set(b.id for b in O.bodies) - topids - botids dmg = sum((damageOfParticle(i) for i in ids), Matrix3.Zero) / len(ids) return dmg for ns, sign in zip(nSteps, signs): calm() vel = Vector3(0, 0, sign * strainRate * size[2]) for b in top: b.state.vel = -vel for b in bot: b.state.vel = vel O.run(ns, True) plot.saveDataTxt(outBase + ".dat") stress = averageStress() stress = [ .5 * (stress[i, j] + stress[j, i]) for i, j in ((0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (0, 1)) ] dmg3, dmg2, dmg1 = sorted(averageDamageTensor().spectralDecomposition()[1]) dmg = (dmg1, dmg2, dmg3) with open("{}_final.dat".format(outBase), "w") as f: for arry in stress, dmg: f.write("{}\n".format(" ".join(str(v) for v in arry)))
# Seed was not used in the end. The rerun will not produce exactly the same results, but should give very similar results import sys from yade import pack, plot utils.readParamsFromTable(noTableOk = True, nums = (50,100,200,400), radius = .1234, seed = 1, ) from yade.params.table import * for num in nums: print num sys.stdout.flush() O.reset() #sp = myRandomPeriPack(radius,num,seed=seed,initSizeFactor=2.4+.0002*num) sp = pack.randomPeriPack(radius,2.4*num**(1/3.)*radius*Vector3.Ones) seed += 1 sp.toSimulation() n = len(O.bodies) v = O.cell.volume f = n*4/3.*pi*pow(radius,3) / v plot.addData( numberOfParticles = n, packingFraction = f, ) plot.saveDataTxt('/tmp/randomPeriPack_packingFraction.dat')
def checkpoint(): if O.iter == nSteps: O.bodies[1].state.vel = (hDspl / (nSteps * O.dt), 0, 0) elif O.iter == 2 * nSteps: O.pause() plot.saveDataTxt('/tmp/shear.dat')
print("\nnormDi= " + str(normDI)) plot.addData(t=O.time, error=ERR, normAn=normAN, normDi=normDI) ## no QT ## plot.liveInterval=2.0 ## no QT ## plot.plot(subPlots=False) #O.dt=80 O.dt = 0.0000001 for i in range(50): O.step() O.dt = 80 #O.save(str(sys.argv[0])+"__t="+str(O.time)+".yade.gz") if (i > 1): plot.saveDataTxt( str(sys.argv[0]) + "__t=" + str(O.time) + "_testDATA.txt") #O.save('/tmp/a.xml.bz2'); #o.run(100000); o.wait(); print o.iter/o.realtime,'iterations/sec' ## noQT ## try: ## noQT ## from yade import qt ## noQT ## qt.Controller() ## noQT ## qt.controller.setWindowTitle("Electron-positron pair in 2D") ## noQT ## qt.Renderer().blinkHighlight=False ## noQT ## qt.View() ## noQT ## qt.controller.setViewAxes(dir=(0,1,0),up=(0,0,1)) ## noQT ## qt.views()[0].center(False,260) # median=False, suggestedRadius = 5 ## noQT ## except ImportError: ## noQT ## pass #O.run(20000)
def checkpoint(): if O.iter==nSteps: O.bodies[1].state.vel = (hDspl/(nSteps*O.dt),0,0) elif O.iter==2*nSteps: O.pause() plot.saveDataTxt('/tmp/shear.dat')
def saveData(): plot.saveDataTxt('data_pullout/'+O.tags['description']+'.dat',vars=('t','i','xtop','ytop','ztop','y','Fnorm','Fx','Fy','Fz','u'))
def saveToFile(): global m_savefile, m_simuParams plot.saveDataTxt(m_savefile, headers=m_simuParams)
def saveData(): plot.saveDataTxt('data/'+O.tags['description']+'.dat',vars=('t','pos','Fnt','Fnb','sigma1','sigma3','unbF','p','q'))
def saveData(): plot.saveDataTxt('data/'+O.tags['description']+'.dat',vars=('y0','y1','y2','y3','y4','Fnorm','Fx','Fy','Fz'))
def saveData(): plot.saveDataTxt(O.tags['description']+'.dat.bz2',vars=('t1','t2','unbF','y1','y2','y3','y4','vy'))
def saveData(): plot.saveDataTxt('data/'+O.tags['description']+'.dat.bz2',vars=('t','pos','displ','Fnt','Fnb','sigmaN','sigmaNb','cui','unbF','p','q','v','p0','sigma0','epsv'))
def saveToFile(): global m_savefile; plot.saveDataTxt(m_savefile);
def saveData(): plot.saveDataTxt('data/'+O.tags['description']+'.dat',vars=('un','eps','Fn','sigma'))
def checkUnbalanced(): if unbalancedForce()<.05: O.pause() plot.saveDataTxt('bbb.txt.bz2')
plot.addData(t=O.time,error=ERR,normAn=normAN,normDi=normDI) ## no QT ## plot.liveInterval=2.0 ## no QT ## plot.plot(subPlots=False) #O.dt=80 O.dt=0.0000001 for i in range(50): O.step() O.dt=80 #O.save(str(sys.argv[0])+"__t="+str(O.time)+".yade.gz") if(i>1): plot.saveDataTxt(str(sys.argv[0])+"__t="+str(O.time)+"_testDATA.txt") #O.save('/tmp/a.xml.bz2'); #o.run(100000); o.wait(); print o.iter/o.realtime,'iterations/sec' ## noQT ## try: ## noQT ## from yade import qt ## noQT ## qt.Controller() ## noQT ## qt.controller.setWindowTitle("Electron-positron pair in 2D") ## noQT ## qt.Renderer().blinkHighlight=False ## noQT ## qt.View() ## noQT ## qt.controller.setViewAxes(dir=(0,1,0),up=(0,0,1)) ## noQT ## qt.views()[0].center(False,260) # median=False, suggestedRadius = 5 ## noQT ## except ImportError: ## noQT ## pass
def plotSaveDataTxt(): plot.saveDataTxt("{}.dat".format(outBase))
def SavePlot(): global m_savefile plot.saveDataTxt(m_savefile)
) if mode == 'tension' else -abs(strainRateCompression) O.step() ss2sc.interactionDetectionFactor = 1. is2aabb.aabbEnlargeFactor = 1. def stopIfDamaged(mode): sigma, eps = plot.data['sigma'], plot.data['eps'] mode = 'tension' if strainer.strainRate > 0 else 'compression' extremum = max(sigma) if mode == 'tension' else min(sigma) minMaxRatio = 0.2 if mode == 'tension' else 0.7 if abs(sigma[-1] / extremum) < minMaxRatio or abs(strainer.strain) > 5e-3: print "Damaged, stopping." return True for mode in ('tension', 'compression'): initTest(mode) while True: O.run(100, True) if stopIfDamaged(mode): break if O.iter > 10000: break sigma = plot.data["sigma"] ft, fc = max(sigma), min(sigma) print 'Strengths fc={}, ft={}, |fc/ft|={}'.format(fc, ft, abs(fc / ft)) plot.saveDataTxt("{}.dat".format(outBase)) print 'Bye.'