""" with open(fname, 'r') as f: n = int(f.readline()) tri = int32([int32(L.split()) for L in f.readlines()]) return tri def delaunay(X, fout='delaunayOut.tmp'): """ compute the delaunay triangulation of X taking as the dimension X.shape[0] """ fname, idx = delaunayInput(X) fin = os.path.join(tmpPath, fname) comm = os.path.join(delaunayPath, 'qdelaunay') + ' Qt i ' ret = os.system(comm + 'TI ' + fin + '> ' + os.path.join(tmpPath, fout)) assert ret == 0, 'delaunay did not return 0! check delaunayPath...currently is ' + delaunayPath tri = delaunayOutput(os.path.join(tmpPath, fout)) Y = X[(slice(None), ) + idx] return (tri, idx, Y) if __name__ == '__main__': X = rand(3, 10, 10) tri, idx, Y = delaunay(X) f = mlm.fig('the points') mlm.ml.points3d(X[0], X[1], X[2], figure=f) mlm.ml.triangular_mesh(Y[0], Y[1], Y[2], tri[:, :3], figure=f) mlm.ml.show()
os.path.split(dirname)[1] + '.pkl'), 'rb') as f: z, r, t, X = pkl.load(f) if dumpMean: n = (300, 200) nCut = (60, 40) Y = mean(X, axis=0) Yreg = zeros((Y.shape[0], ) + n) for i in range(Yreg.shape[0]): zReg, rReg, Yreg[i] = regularize2d(z, r, Y[i], n, nCut) if i < 3: mlm.surf3(x=zReg, y=rReg, z=Yreg[i], axeLab=['axial, cm', 'radial, cm', labs[i]], f=mlm.fig(labs[i])) dumplist = [Yreg[i] for i in range(5)] + [Yreg[5] + Yreg[6]] with open('e:\\labcode\\pyrticle\\lavaJet.pkl', 'wb') as f: pkl.dump( dict( zip(['radialCoord', 'axialCoord'] + labs[:5] + ['airMols'], [cookDist(rReg), cookDist(zReg)] + dumplist)), f, -1) Tcl = ndimage.gaussian_filter(squeeze(X[:, 0, :, 0, ...]), 1) Vcl = ndimage.gaussian_filter(squeeze(X[:, 1, :, 0, ...]), 1) # # ONratio =squeeze(X[:, 6,...]/X[:,5,...]) # ONratio[logical_or(isinf(ONratio), isnan(ONratio))] = .25 # ONratio[ONratio>.5] = .5 # ONratio[ONratio<.05] = .05 #
label='electron temperature/ heavy temperature)') legend() G = mgrid[amin(x[0]):amax(x[0]):200j, amin(x[1]):amax(x[1]):200j] R = sum(G**2, axis=0)**.5 T = Rbf(x[0], x[1], Tbar, function='cubic')(G[0], G[1]) T[R > amax(r)] = mean(Tbar[r == amax(r)]) U = Rbf(x[0], x[1], Ubar, function='cubic')(G[0], G[1]) U[R > amax(r)] = mean(Ubar[r == amax(r)]) Te = Rbf(x[0], x[1], Tbar * thetaBar, function='cubic')(G[0], G[1]) Te[R > amax(r)] = mean((Tbar * thetaBar)[r == amax(r)]) eps = 1e-3 dT = (gradient(T)[0]**2 + gradient(T)[1]**2)**.5 dT[R > (amax(r) - eps)] = 0 dU = (gradient(U)[0]**2 + gradient(U)[1]**2)**.5 dU[R > (amax(r) - eps)] = 0 figure() contourf(dT, 30, cmap=cm.copper) colorbar() contour(dU, 10, cmap=cm.cool) colorbar() mlm.surf3(G[0], G[1], U, f=mlm.fig('axial velocity')) mlm.surf3(G[0], G[1], T, f=mlm.fig('temperature')) mlm.surf3(G[0], G[1], Te, f=mlm.fig('electron temperature')) show()
fig() plot(QT.xi, QT.yi, 'k', linewidth = 2, label = 'mapping') xlab('heat input, J/kg') ylab('Temperature, K') tit('Mapping from Heat Input to Temperature') plot(q[idx], pq[idx]*.5*np.max(QT.yi)/np.max(pq[idx]), 'r', linewidth = 1.5, label = 'heat pdf') plot(pt[idx]*.5*np.max(QT.xi)/np.max(pt[idx]), t[idx], 'g', linewidth = 1.5, label = 'temperature pdf') legend() axisFontSize() sf('heat-temp_distributionMap') with open('heat-temp.csv', 'w') as f: f.write('heat, pHeat, temp, pTemp\n') for i in range(t[idx].shape[0]): f.write(str(q[idx][i])+ ', ') f.write(str(pq[idx][i])+ ', ') f.write(str(t[idx][i])+ ', ') f.write(str(pt[idx][i])+ ', ') f.write('\n') f = mlm.fig('Transformation of Unimodal Heat Distribution to Bimodal Temperature Distribution') ml.mesh(mlm.sc(t), tile(expand_dims(mlm.sc(mu),1), (1, t.shape[1])), log(mlm.sc(pt)), extent = mlm.ex, figure = f) mlm.axe(['Temperature', 'mean heat input', 'p(T)'], mlm.rgs(t, mu, pt), f) mlm.out()
ylab('final vertical location, m') tit('Spread of Trajectories for Different Size Particles\ndiameters in microns ' ) legend() sf('proposal_spreadFig1') figure(3) axisFontSize() xlab('final vertical location, m') ylab('probability density') tit('Posterior Distributions of Final Locations \nfor Particles of Increasing Diameter' ) legend(loc='upper left') sf('proposal_spreadFig2') fig(4) contourf(G[1] * 1e6, G[0], mi, 30) axisFontSize() xlab('d, microns') ylab('v0, m/s') tit('ratio of final to initial mass') mlm.surf3(G[1] * 1e6, G[0], T[..., -1], f=mlm.fig('final surface temperature')) D = dict(zip(['v0', 'd', 'G', 'T'], [v0, d, G, T])) f = open( 'T_v0' + str(v0[0]) + '-' + str(v0[-1]) + '_d' + str(d[0] * 1e6) + '-' + str(d[-1] * 1e6) + '.pkl', 'wb') pkl.dump(D, f, -1) f.close()
def bel2tri(el, bel, bface): #pdb.set_trace() f = array([el[bel[i]][TH.faces[bface[i]]] for i in range(bel.shape[0])]) tri = r_['0', f[:, :3], f[:, [0, 2, 3]]] return tri tri = bel2tri(el, bels, belFace) sly = slice(0, None, 10) # xend = x[:-1, bx[-2]] * 1e3 mend = Vh[0, bx[-2]] otri, idx, yend = qh.delaunay(xend) ft = mlm.fig('Outlet Mode 0') ml.triangular_mesh(mlm.sc(xend[0]), mlm.sc(xend[1]), mlm.sc(mend), otri, extent=mlm.ex, figure=ft) ml.axes(figure=ft, ranges=[ np.min(xend[0]), np.max(xend[0]), np.min(xend[1]), np.max(xend[1]), -1, 1 ], extent=mlm.ex, nb_labels=5,
# g = meshgrid(rReg, zReg) n = (300, 200) nCut = (60, 40) Treg = zeros((T.shape[0], ) + n) showAll = False for i in range(T.shape[0]): #Treg[i] = pol(array([0.,0.]),array([z[-1],r[-1]]), cookList[i](T[i]))(r_['0,3', g[1], g[0]]) zReg, rReg, Treg[i] = regularize2d(z, r, cookList[i](T[i]), n, nCut) if showAll: # mlm.surf3(x = z, y = r, z = T[i],axeLab = ['radial, cm','axial, cm',labs[i]], f = mlm.fig(labs[i])) mlm.surf3(x=zReg, y=rReg, z=Treg[i], axeLab=['radial, cm', 'axial, cm', labs[i]], f=mlm.fig(labs[i]), clf=False) elif not showAll and i < 3: # mlm.surf3(x = z, y = r, z = T[i],axeLab = ['radial, cm','axial, cm',labs[i]], f = mlm.fig(labs[i])) mlm.surf3(x=zReg, y=rReg, z=Treg[i], axeLab=['radial, cm', 'axial, cm', labs[i]], f=mlm.fig(labs[i]), clf=False) cut = 6 dumplist = [Treg[i] for i in range(5)] + [Treg[5] + Treg[6]] with open('e:\\labcode\\pyrticle\\lavaJet.pkl', 'wb') as f: pkl.dump( dict(
else: theFile = open('particleConvergenceSplit.pkl', 'rb') D = pkl.load(theFile) theFile.close() cf = lambda x_: contourf(D['kinematicTimestep'], D['thermalTimestep'], x_, linspace(np.min(x_), np.max(x_), 30)) fig = lambda: figure(figsize=(20, 22)) mf = lambda x_, zLab_, fName_: mlm.mesh3( D['thermalTimestep'], D['kinematicTimestep'], x_, f=mlm.fig(fName_), axeLab=['thermal timestep, s', 'kinematic timestep, s', zLab_]) mf(D['ex'], 'error, m', 'error in axial location') mf(D['ey'], 'error, m', 'error in vertical location') mf(D['et'], 'error, K', 'error in final mean temperature') mf(D['eh'], 'pct error', 'error in final total enthalpy') mf(log2(D['elapsed'] / np.min(D['elapsed'])), 'log2(runtime/min(runtime))', 'simulation runtime, fastest run = ' + str(np.min(D['elapsed']))) mf(D['ratio'], 'runtime, s', 'timestep ratio') # fig() # cf(D['ex']) # colorbar() # title('error in x(t)') # xlabel('kinematic timestep, s')
JmaxIn[j] = np.max(P[0]) #compute velocity proxy numerator vProxyIn = PE.diameter()**2 * PE.temperature()**2 vProxyOut = IS.diameter()**2 * IS.temperature()**4 ###################################################################### #//////////////////////////// SUMMARY AND FRAME PLOTTING ///////////////////////////////////// # mlm.scat(r_['0,4,-1', squeeze(PE.temperature()), squeeze(1e6*PE.diameter()),squeeze(PE.lateralPosition())], axeLab = ['T', 'D', 'z'], f = mlm.fig('input mesh') ) # mlm.scat(r_['0,4,-1', squeeze(IS.temperature()), squeeze(1e6*IS.diameter()),squeeze(PE.lateralPosition())], axeLab = ['T', 'D', 'z'], f = mlm.fig('output mesh') ) # mlm.scat(r_['0,4,-1', squeeze(PE.temperature()), squeeze(1e6*PE.diameter()),squeeze(PE.lateralPosition()), 1e6*squeeze(IS.diameter()-PE.diameter())], axeLab = ['T', 'D', 'z'], f = mlm.fig('diameter error') ) mlm.surf3(1e6 * PE.diameter()[:, 0, :, 0], PE.lateralPosition()[:, 0, :, 0], 1e6 * (IS.diameter()[:, 0, :, 0] - PE.diameter()[:, 0, :, 0]), axeLab=['D', 'z', 'error'], f=mlm.fig('error in diameter')) #:::::::::::::::::::::::::::::::::::::: HISTOGRAMS :::::::::::::::::::::::::::::::::: ############ TEMP, DIAMETER####################### figure(figsize=(20, 20)) subplot(1, 2, 1) #temprature #vvvvvvvvvvvvvvvvvvvvvv inHist(IS.temperature().ravel() - PE.temperature().ravel()) #^^^^^^^^^^^^^^^^^^^ xlab('error in temperature, K') legend() axisFontSize() tit(simTag)
def summary(self, plotOn=True): """ make a bunch of surface plots if appropriate, and display ensemble statistics """ pv = self.parameterVectors pk = self.modelArray.flatten()[0].parameterKeys() if self.modelArray.ndim == 2: #assume we meshed outer diameter and injection velocity g = r_['0,3', squeeze(1e6 * pv[..., nonzero(pk == 'outerDiameter')[0]]), squeeze(-pv[..., nonzero(pk == 'injVelY')[0]])] axlab = ['diameter, microns', 'injection velocity, m/s'] arrs = [ 'surfaceTemperature', 'centerTemperature', 'meanTemperature', 'volumeFraction', 'diameterFraction', 'finalVelocity', 'enthalpy', 'surfaceEnthalpy', 'moltenFraction', 'moltenVolume', 'momentum', 'verticalPosition', 'axialPosition', ] units = [ 'K', 'K', 'K', '', '', 'm/s', r'$\mu$J', 'J/kg', '', r'$\mu$$m^3$', 'mg m/s', 'mm', 'mm' ] A = zeros((len(arrs), ) + self.modelArray.shape) for i, M in ndenumerate(self.modelArray): A[3][i] = sum(M.PS.p.mesh.nodeVolume) / sum( M.PS.p.meshHistory[0].nodeVolume) A[4][i] = M.PS.p.diameter() / (2 * M.PS.p.meshHistory[0].xInt[-1]) A[1][i] = copy(M.PS.p.T[0]) A[2][i] = sum(M.PS.p.mesh.nodeVolume * M.PS.p.T / sum(M.PS.p.mesh.nodeVolume)) A[0][i] = copy(M.PS.p.surfaceTemperature) A[8][i] = M.PS.p.moltenFraction() A[9][i] = M.PS.p.moltenVolume() * 1e18 A[6][i] = sum(M.PS.p.enthalpy() * M.PS.p.mass * 1e6) A[7][i] = M.PS.p.enthalpy()[-1] A[5][i] = sqrt(sum(M.PS.p.velocity()**2)) A[10][i] = A[5][i] * M.PS.p.totalMass * 1e6 A[11][i] = M.PS.p.verticalPosition() * 1e3 A[12][i] = M.PS.p.axialPosition() * 1e3 A[12][i] = M.PS.p.axialPosition() * 1e3 A[2][logical_or(isinf(A[2]), isnan(A[2]))] = 0 if plotOn: F = [mlm.fig(a) for a in arrs] for i in range(len(arrs)): try: mlm.surf3(g[0], g[1], A[i], axeLab=axlab + [arrs[i] + ', ' + units[i]], f=F[i]) except ValueError: print 'nans! check ' + arrs[i] return dict( zip(['diameter', 'injectionVelocity'] + arrs + ['units'], [g[0], g[1]] + [A[i] for i in range(A.shape[0])] + [dict(zip(arrs, units))]))