def velocities_upper(state, dim, t, auxbc, num_ghost): """ Set the velocities for the ghost cells outside the outer radius of the annulus. """ from mapc2p import mapc2p grid = state.grid mx = grid.num_cells[0] my = grid.num_cells[1] dxc = grid.delta[0] dyc = grid.delta[1] if dim == grid.dimensions[0]: xc1d = grid.lower[0] + dxc * ( np.arange(mx + num_ghost, mx + 2 * num_ghost + 1) - num_ghost) yc1d = grid.lower[1] + dyc * (np.arange(my + 2 * num_ghost + 1) - num_ghost) yc, xc = np.meshgrid(yc1d, xc1d) xp, yp = mapc2p(xc, yc) auxbc[:, -num_ghost:, :] = velocities_capa(xp, yp, dxc, dyc) else: raise Exception('Custum BC for this boundary is not appropriate!')
def q_vs_radius(current_data): from numpy import sqrt xc = current_data.x yc = current_data.y x, y = mapc2p(xc, yc) r = sqrt(x**2 + y**2) q = current_data.q[:, :, 0] return r, q
def q_vs_radius(current_data): from numpy import sqrt xc = current_data.x yc = current_data.y x, y = mapc2p(xc, yc) r = sqrt(x ** 2 + y ** 2) q = current_data.q[:, :, 0] return r, q
def plotq2_cart(outputdir, nframe, m, meth1, meqn, time, points_per_dir, LegVals, xlow, xhigh, ylow, yhigh, mx, my, dx, dy, mx_old, my_old, dx_old, dy_old, xc, yc, xl, yl, qaug): import matplotlib.pyplot as plt import numpy as np import mapc2p as mp data = np.loadtxt('mapped.txt') xp = data[:, 0] yp = data[:, 1] xpl, ypl = mp.mapc2p(xl, yl) n4 = xpl.shape[0] m4 = xpl.shape[1] print n4, m4, xp.shape xp = np.reshape(xp, (n4, m4)) yp = np.reshape(yp, (n4, m4)) plt.figure(1) plt.clf() plt.gca().set_aspect('equal') plt.gca().set_xlim(xl[0, 0], xl[mx, 0]) plt.gca().set_ylim(yl[0, 0], yl[0, my]) im = plt.pcolor(xp, yp, qaug[:, :, m], cmap='OrRd') for i1 in range(mx): for j1 in range(my): #print [xpl[i1,j1],xpl[i1+1,j1]] print i1, j1 if xp[i1, j1] != xp[i1 + 1, j1]: plt.plot([xp[i1, j1], xp[i1 + 1, j1]], [yp[i1, j1], yp[i1 + 1, j1]], 'k') if xp[i1, j1] != xp[i1, j1 + 1]: plt.plot([xp[i1, j1], xp[i1, j1 + 1]], [yp[i1, j1], yp[i1, j1 + 1]], 'k') if yp[i1, j1] != yp[i1 + 1, j1]: plt.plot([xp[i1, j1], xp[i1 + 1, j1]], [yp[i1, j1], yp[i1 + 1, j1]], 'k') if yp[i1, j1] != yp[i1, j1 + 1]: plt.plot([xp[i1, j1], xp[i1, j1 + 1]], [yp[i1, j1], yp[i1, j1 + 1]], 'k') plt.colorbar(im, use_gridspec=True) tmp1 = "".join(("q(", str(m + 1), ") at t = ")) tmp2 = "".join((tmp1, str(time))) title = "".join((tmp2, " [DoGPack]")) plt.title(title) plt.draw() plt.tight_layout() plt.savefig('plots/figure_%s.pdf' % nframe)
def ghost_velocities_lower(state,dim,t,auxbc,num_ghost): """ Set the velocities for the ghost cells outside the inner radius of the annulus. In the computational domain, these are the cells at the bottom of the grid. """ from mapc2p import mapc2p grid=state.grid if dim == grid.dimensions[0]: dx, dy = grid.delta X_edges, Y_edges = grid.c_edges_with_ghost(num_ghost=2) R_edges,Theta_edges = mapc2p(X_edges,Y_edges) auxbc[:,0:num_ghost,:] = edge_velocities_and_area(R_edges[0:num_ghost+1,:],Theta_edges[0:num_ghost+1,:],dx,dy) else: raise Exception('Custom BC for this boundary is not appropriate!')
def ghost_velocities_upper(state,dim,t,auxbc,num_ghost): """ Set the velocities for the ghost cells outside the outer radius of the annulus. In the computational domain, these are the cells at the top of the grid. """ from mapc2p import mapc2p grid=state.grid if dim == grid.dimensions[0]: dx, dy = grid.delta X_edges, Y_edges = grid.c_edges_with_ghost(num_ghost=2) R_edges,Theta_edges = mapc2p(X_edges,Y_edges) # Compute edge coordinates in physical domain auxbc[:,-num_ghost:,:] = edge_velocities_and_area(R_edges[-num_ghost-1:,:],Theta_edges[-num_ghost-1:,:],dx,dy) else: raise Exception('Custom BC for this boundary is not appropriate!')
def plotq2_cart(outputdir, nframe, m, meth1, meqn, time, points_per_dir, LegVals, xlow, xhigh, ylow, yhigh, mx, my, dx, dy, mx_old, my_old, dx_old, dy_old, xc, yc, xl, yl, qsoln): import matplotlib.pyplot as plt import numpy as np import mapc2p as mp plt.figure(1) plt.clf() #xp=xl #yp=yl xpl, ypl = mp.mapc2p(xl, yl) n4 = xpl.shape[0] m4 = xpl.shape[1] data = np.loadtxt('mapped.txt') xp = data[:, 0] yp = data[:, 1] print xp.shape, yp.shape, n4, m4 xp = np.reshape(xpl, (n4, m4)) yp = np.reshape(ypl, (n4, m4)) #plt.gca().set_aspect('equal') #plt.gca().set_xlim(xl[0,0],xl[mx,0]) #plt.gca().set_ylim(yl[0,0],yl[0,my]) plt.pcolor(xp, yp, qsoln[:, :, m]) """ plt.plot(xp,yp,'ko') for i1 in range(mx): for j1 in range(my): #print [xpl[i1,j1],xpl[i1+1,j1]] if yp[i1,j1]!=yp[i1+1,j1]: plt.plot([xp[i1,j1], xp[i1+1,j1]],[yp[i1,j1], yp[i1+1,j1]],'k') if yp[i1,j1]!=yp[i1,j1+1]: plt.plot([xp[i1,j1], xp[i1,j1+1]],[yp[i1,j1], yp[i1,j1+1]],'k') """ plt.colorbar() tmp1 = "".join(("q(", str(m + 1), ") at t = ")) tmp2 = "".join((tmp1, str(time))) title = "".join((tmp2, " [DoGPack]")) plt.title(title) plt.draw()
def velocities_lower(state,dim,t,auxbc,mbc): """ Set the velocities for the ghost cells outside the inner radius of the annulus. """ from mapc2p import mapc2p grid=state.grid my = grid.ng[1] dxc = grid.d[0] dyc = grid.d[1] if dim == grid.dimensions[0]: xc1d = grid.lower[0]+dxc*(np.arange(mbc+1)-mbc) yc1d = grid.lower[1]+dyc*(np.arange(my+2*mbc+1)-mbc) yc,xc = np.meshgrid(yc1d,xc1d) xp,yp = mapc2p(xc,yc) auxbc[:,0:mbc,:] = velocities_capa(xp,yp,dxc,dyc) else: raise Exception('Custum BC for this boundary is not appropriate!')
def velocities_upper(state,dim,t,auxbc,num_ghost): """ Set the velocities for the ghost cells outside the outer radius of the annulus. """ from mapc2p import mapc2p grid=state.grid mx = grid.num_cells[0] my = grid.num_cells[1] dxc = grid.delta[0] dyc = grid.delta[1] if dim == grid.dimensions[0]: xc1d = grid.lower[0]+dxc*(np.arange(mx+num_ghost,mx+2*num_ghost+1)-num_ghost) yc1d = grid.lower[1]+dyc*(np.arange(my+2*num_ghost+1)-num_ghost) yc,xc = np.meshgrid(yc1d,xc1d) xp,yp = mapc2p(xc,yc) auxbc[:,-num_ghost:,:] = velocities_capa(xp,yp,dxc,dyc) else: raise Exception('Custum BC for this boundary is not appropriate!')
import numpy as np from mapc2p import mapc2p dispersion = True # Include Boussinesq terms? B_param = 1.0 / 15.0 # Parameter for the Boussinesq eqns sw_depth0 = 20. # Use pure SWE if depth less than sw_depth0 sw_depth1 = 20. # Use pure Bous if depth greater than sw_depth1 radial = True # Include radial source terms? grid = np.loadtxt('grid.data', skiprows=1) print('Read grid from grid.data, %i grid values' % grid.shape[0]) mx = grid.shape[0] - 1 dxc = 1. / mx xc = np.linspace(dxc / 2., 1 - dxc / 2., mx) xp = mapc2p(xc) #------------------------------ def setrun(claw_pkg='geoclaw'): #------------------------------ """ Define the parameters used for running Clawpack. INPUT: claw_pkg expected to be "geoclaw" for this setrun. OUTPUT: rundata - object of class ClawRunData """
def plotdog2(points_per_dir_in="1",outputdir="output",point_type_in="1"): """ Generic code for plotting DoGPack output in matplotlib. """ """ Execute via $ python $DOGPACK/viz/python/plotdog2.py from an application directory. For help type $ python $DOGPACK/viz/python/plotdog2.py -h to see a list of options. Usage: plotdog2( points_per_dir_in="1", outputdir="output", point_type_in="1") points_per_dir = points per direction (spatial dimension) outputdir = location of output directory point_type = 1: uniform points on each element = 2: Gauss-Legendre points on each element """ def phi(xin,yin,x1,y1,dx1,dy1,a): c0=0.0 c1=0.0 c2=0.0 c3=0.0 c4=0.0 c5=0.0 x=2.0*(xin-x1)/dx1-1.0; y=2.0*(yin-y1)/dy1-1.0; if(a==1): c0=-1.0/6.0; c1=-1.0/6.0; c2=-1.0/6.0; c3=1.0/3.0; c4=1.0/6.0; c5=1.0/3.0; if(a==2): c0=1.0; c1=0.0; c2=-1.0/3.0; c3=0.0; c4=-2.0/3.0; c5=-2.0/3.0; if(a==3): c0=-1.0/6.0; c1=1.0/6.0; c2=-1.0/6.0; c3=-1.0/3.0; c4=1.0/6.0; c5=1.0/3.0; if(a==4): c0=1.0/6.0; c1=1.0/3.0; c2=1.0/6.0; c3=1.0/3.0; c4=1.0/3.0; c5=-1.0/3.0; if(a==5): c0=0.0; c1=0.0; c2=1.0/3.0; c3=0.0; c4=-1.0/3.0; c5=2.0/3.0; if(a==6): c0=1.0/6.0; c1=-1.0/3.0; c2=1.0/6.0; c3=-1.0/3.0; c4=1.0/3.0; c5=-1.0/3.0; phi1=c0+c1*x+c2*y+c3*x*y+c4*x*x+c5*y*y; return phi1; import os import sys from math import sqrt import matplotlib.pyplot as plt from helpermap2 import get_grid_type from helpermap2 import read_params from helpermap2 import get_kmax from helpermap2 import GetCart2Legendre from helpermap2 import read_qfile from helpermap2 import sample_state2_cart_mod_map,sample_state2_cart_mod from helpermap2 import read_mesh_params from helpermap2 import read_node from helpermap2 import read_tnode from helpermap2 import GetMonomialToLegendre from helpermap2 import GetUnstLegendre from helpermap2 import set_tcounter from helpermap2 import set_soln_at_node_values from helpermap2 import sample_state2_unst from helpermap2 import DivideUnstMesh import numpy as np try: from mapc2p import mapc2p # Import DNSPython except ImportError: def mapc2p(xc,yc): """ Specifies the mapping to curvilinear coordinates -- should be consistent with mapc2p.f """ return xc,yc points_per_dir = int(points_per_dir_in) point_type = int(point_type_in) TF = os.path.exists(outputdir) if TF==False: print "" print " Directory not found, outputdir =",outputdir print "" return -1 else: print "found outputdir = ", outputdir if (point_type!=1 and point_type!=2): point_type = 1 if (point_type==2 and points_per_dir>5): print 'setting points_per_dir = 5 instead of requested %d' % points_per_dir points_per_dir = 5 GridType = get_grid_type(outputdir) if (GridType=="Cartesian"): params = np.zeros(11, float) read_params(outputdir,params) meqn = int(params[0]) maux = int(params[1]) nplot = int(params[2]) meth1 = int(params[3]) mx = int(params[5]) my = int(params[6]) xlow = params[7] xhigh = params[8] ylow = params[9] yhigh = params[10] datafmt = int(params[4]) elif (GridType=="Unstructured"): params = np.zeros(4, int) read_params(outputdir,params) meqn = params[0] maux = params[1] nplot = params[2] meth1 = params[3] kmax = get_kmax(meth1,2) print "" print " GridType = ",GridType print " points_per_dir = ",points_per_dir print " point_type = ",point_type print " outputdir = ",outputdir print "" curr_dir = os.path.abspath("./") sys.path.append(curr_dir) if (GridType=="Cartesian"): plotq2_file = os.path.abspath("plotq2_cart.py") local_plotq2 = os.path.exists(plotq2_file) if local_plotq2==False: from plotq2_cart_default import plotq2_cart else: from plotq2_cart import plotq2_cart # Grid information mx_old = mx my_old = my dx_old = (xhigh-xlow)/mx_old dy_old = (yhigh-ylow)/my_old mx = mx*points_per_dir my = my*points_per_dir dx = (xhigh-xlow)/mx dy = (yhigh-ylow)/my print "mx=",mx,"my=",my if (point_type==1): xl = np.zeros((mx+1,my+1),float) yl = np.zeros((mx+1,my+1),float) phil=np.zeros((mx,my,points_per_dir,kmax),float) xc = np.zeros((mx,my),float) yc = np.zeros((mx,my),float) for j in range(0,my+1): xl[:,j] = xlow + dx*np.arange(mx+1)[:] for i in range(0,mx+1): yl[i,:] = ylow + dy*np.arange(my+1)[:] for j in range(0,my): xc[:,j] = (xlow+0.5*dx) + dx*np.arange(mx)[:] for i in range(0,mx): yc[i,:] = (ylow+0.5*dy) + dy*np.arange(my)[:] xpl,ypl=mapc2p(xl,yl) for i in range(0,mx): for j in range(0,my): xp1 = xpl[i,j]; yp1= ypl[i,j]; xp2 = xpl[i+1,j]; yp2= ypl[i+1,j]; xp3 = xpl[i+1,j+1]; yp3= ypl[i+1,j+1]; xp4 = xpl[i,j+1]; yp4= ypl[i,j+1]; xmax=max(max(xp1,xp2),max(xp3,xp4));xmin=min(min(xp1,xp2),min(xp3,xp4)); ymax=max(max(yp1,yp2),max(yp3,yp4));ymin=min(min(yp1,yp2),min(yp3,yp4)); dx1=xmax-xmin;dy1=ymax-ymin; xin=0.5*(xmax+xmin); yin=0.5*(ymax+ymin); for l in range(0,kmax): phil[i,j,0,l]=phi(xin,yin,xmin,ymin,dx1,dy1,l+1) ##################################################### # 1D points dxi = 1.0/float(points_per_dir) s1d = -1 + dxi + 2*dxi * np.arange(points_per_dir) kk=-1; s2d = np.zeros((points_per_dir*points_per_dir,2),float) for jj in range(0,points_per_dir): for ii in range(0,points_per_dir): kk = kk+1 s2d[kk,0] = s1d[ii] s2d[kk,1] = s1d[jj] else: sq3 = sqrt(3.0) sq5 = sqrt(5.0) sq7 = sqrt(7.0) # 1D quadrature points s1d = np.zeros(points_per_dir,float) if (points_per_dir==1): s1d[0] = 0.0 elif (points_per_dir==2): s1d[0] = -1.0/sq3 s1d[1] = 1.0/sq3 elif (points_per_dir==3): s1d[0] = -sq3/sq5 s1d[1] = 0.0 s1d[2] = sq3/sq5 elif (points_per_dir==4): s1d[0] = -sqrt(3.0+sqrt(4.8))/sq7 s1d[1] = -sqrt(3.0-sqrt(4.8))/sq7 s1d[2] = sqrt(3.0-sqrt(4.8))/sq7 s1d[3] = sqrt(3.0+sqrt(4.8))/sq7 elif (points_per_dir==5): s1d[0] = -sqrt(5.0 + sqrt(40.0/7.0))/3.0 s1d[1] = -sqrt(5.0 - sqrt(40.0/7.0))/3.0 s1d[2] = 0.0 s1d[3] = sqrt(5.0 - sqrt(40.0/7.0))/3.0 s1d[4] = sqrt(5.0 + sqrt(40.0/7.0))/3.0 kk=-1; s2d = np.zeros((points_per_dir*points_per_dir,2),float) for jj in range(0,points_per_dir): for ii in range(0,points_per_dir): kk = kk+1 s2d[kk,0] = s1d[ii] s2d[kk,1] = s1d[jj] xx = np.zeros(mx,float) yy = np.zeros(my,float) kk=0 xtmp = xlow-0.5*dx_old for i in range(0,mx_old): xtmp = xtmp + dx_old for m in range(0,points_per_dir): xx[kk+m] = xtmp + 0.5*dx_old*s1d[m] kk = kk + points_per_dir kk=0 ytmp = ylow-0.5*dy_old for j in range(0,my_old): ytmp = ytmp + dy_old for m in range(0,points_per_dir): yy[kk+m] = ytmp + 0.5*dy_old*s1d[m] kk = kk + points_per_dir xc = np.zeros((mx,my),float) yc = np.zeros((mx,my),float) for i in range(0,mx): for j in range(0,my): xc[i,j] = xx[i] yc[i,j] = yy[j] xxx = np.zeros(mx+1,float) yyy = np.zeros(my+1,float) xxx[0] = xlow for i in range(1,mx): xxx[i] = 0.5*(xx[i]+xx[i-1]) xxx[mx] = xhigh yyy[0] = ylow for j in range(1,my): yyy[j] = 0.5*(yy[j]+yy[j-1]) yyy[my] = yhigh xl = np.zeros((mx+1,my+1),float) yl = np.zeros((mx+1,my+1),float) for i in range(0,mx+1): for j in range(0,my+1): xl[i,j] = xxx[i] yl[i,j] = yyy[j] # Sample Legendre polynomial on the midpoint of each sub-element p2 = points_per_dir*points_per_dir LegVals = np.zeros((kmax,p2),float) GetCart2Legendre(meth1,points_per_dir,s2d,LegVals) q=-1; tmp1 = "".join((" Which component of q do you want to plot ( 1 - ",str(meqn))) tmp2 = "".join((tmp1," ) ? ")) m = raw_input(tmp2) print "herro?",m if (not m): m = 1 else: m = int(m) if m<1: print "" print " Error, need m > 1, m = ",m print "" return -1 elif m>meqn: print "" print " Error, need m <=",meqn,", m = ",m print "" return -1 kn = 0; n = 0; nf = 0; n1 = -1; plt.ion() #while (nf!=-1): for n1 in range(nplot+1): """ tmp1 = "".join((" Plot which frame ( 0 - ",str(nplot))) tmp2 = "".join((tmp1," ) [type -1 or q to quit] ? ")) nf = raw_input(tmp2) if (not nf): n1 = n1 + 1 nf = 0 elif nf=="q": nf = -1 else: nf = int(nf) n1 = nf """ if n1>nplot: print "" print " End of plots " print "" n1 = nplot if (nf!=-1): # Solution -- q # solution should be found in file # outputdir/q[n1].dat qfile_tmp_tmp = "".join((str(n1+10000),".dat")) qfile_tmp = "q" + qfile_tmp_tmp[1:] qfile = "".join(("".join((outputdir,"/")),qfile_tmp)) mtmp = mx_old*my_old*meqn*kmax qtmp = np.zeros(mtmp,float) time = read_qfile(mtmp,qfile,qtmp) qcoeffs = np.reshape(qtmp,(kmax,meqn,my_old,mx_old)) qsoln = np.zeros((mx*my,meqn),float) sample_state2_cart_mod(mx_old,my_old,points_per_dir,meqn,kmax,qcoeffs,phil,qsoln) qsoln = np.reshape(qsoln,(mx,my,meqn),'F') # USER SUPPLIED FUNCTION print xc.shape,xl.shape #plotq2_cart(m-1,meth1,meqn,mx,my,time,xc,yc,xl,yl,qsoln) plotq2_cart(outputdir,n1, m-1,meth1,meqn,time, points_per_dir,LegVals, xlow,xhigh,ylow,yhigh, mx,my,dx,dy, mx_old,my_old,dx_old,dy_old, xc,yc,xl,yl,qsoln); plt.ioff() print "" elif (GridType=="Unstructured"): plotq2_file = os.path.abspath("plotq2_unst.py") local_plotq2 = os.path.exists(plotq2_file) if local_plotq2==False: from plotq2_unst_default import plotq2_unst else: from plotq2_unst import plotq2_unst print " Creating mesh ... " # READ-IN MESH INFO meshdir = "".join((outputdir,"/mesh_output")) TF = os.path.exists(meshdir) if TF==False: print "" print " Directory not found, meshdir =",meshdir print "" return -1 mesh_params = np.zeros(7,int) read_mesh_params(meshdir,mesh_params) NumElems = mesh_params[0] NumPhysElems = mesh_params[1] NumGhostElems = mesh_params[2] NumNodes = mesh_params[3] NumPhysNodes = mesh_params[4] NumBndNodes = mesh_params[5] NumEdges = mesh_params[6] tnode = np.zeros((NumPhysElems,3),int) x = np.zeros(NumPhysNodes,float) y = np.zeros(NumPhysNodes,float) read_node(meshdir,NumPhysNodes,x,y) read_tnode(meshdir,NumPhysElems,tnode) xlow = min(x) ylow = min(y) xhigh = max(x) yhigh = max(y) tcounter = np.zeros(NumPhysNodes,int) set_tcounter(NumPhysElems,tnode,tcounter) # Add extra points and elements if points_per_dir>1 p2 = points_per_dir*points_per_dir points_per_elem = ((points_per_dir+1)*(points_per_dir+2))/2 zx = np.zeros(p2,float) zy = np.zeros(p2,float) if (points_per_dir>1): x_tmp = np.zeros(NumPhysElems*points_per_elem,float) y_tmp = np.zeros(NumPhysElems*points_per_elem,float) tnode_new = np.zeros((NumPhysElems*p2,3),int) NumPhysElems_new = 0 NumPhysNodes_new = 0 newsizes = np.zeros(2,int) DivideUnstMesh(points_per_dir,NumPhysElems,x,y,tnode, x_tmp,y_tmp,tnode_new,zx,zy,newsizes) NumPhysElems_new = newsizes[0] NumPhysNodes_new = newsizes[1] x_new = np.zeros(NumPhysNodes_new,float) y_new = np.zeros(NumPhysNodes_new,float) for ijk in range(0,NumPhysNodes_new): x_new[ijk] = x_tmp[ijk] y_new[ijk] = y_tmp[ijk] tcounter_new = np.zeros(NumPhysNodes_new,int) set_tcounter(NumPhysElems_new,tnode_new,tcounter_new) else: NumPhysElems_new = NumPhysElems NumPhysNodes_new = NumPhysNodes x_new = x y_new = y tnode_new = tnode tcounter_new = tcounter # Get physical midpoints of each element xmid = np.zeros(NumPhysElems_new,float) ymid = np.zeros(NumPhysElems_new,float) onethird = 1.0/3.0 for i in range(0,NumPhysElems_new): xmid[i] = onethird*(x_new[tnode_new[i,0]]+x_new[tnode_new[i,1]]+x_new[tnode_new[i,2]]) ymid[i] = onethird*(y_new[tnode_new[i,0]]+y_new[tnode_new[i,1]]+y_new[tnode_new[i,2]]) # Sample Legendre polynomial on the midpoint of each element Mon2Leg = np.zeros((kmax,kmax),float) GetMonomialToLegendre(kmax,Mon2Leg) MonVals = np.zeros((kmax,p2),float) LegVals = np.zeros((kmax,p2),float) GetUnstLegendre(meth1,kmax,points_per_dir,zx,zy,Mon2Leg,MonVals,LegVals) print " Finished creating mesh. " print "" q=-1; tmp1 = "".join((" Which component of q do you want to plot ( 1 - ",str(meqn))) tmp2 = "".join((tmp1," ) ? ")) m = raw_input(tmp2) print "" if (not m): m = 1 else: m = int(m) if m<1: print "" print " Error, need m > 1, m = ",m print "" return -1 elif m>meqn: print "" print " Error, need m <=",meqn,", m = ",m print "" return -1 kn = 0; n = 0; nf = 0; n1 = -1; plt.ion() while (nf!=-1): tmp1 = "".join((" Plot which frame ( 0 - ",str(nplot))) tmp2 = "".join((tmp1," ) [type -1 or q to quit] ? ")) nf = raw_input(tmp2) if (not nf): n1 = n1 + 1 nf = 0 elif nf=="q": nf = -1 else: nf = int(nf) n1 = nf if n1>nplot: print "" print " End of plots " print "" n1 = nplot if (nf!=-1): # Solution -- q # solution should be found in file # outputdir/q[n1].dat qfile_tmp_tmp = "".join((str(n1+10000),".dat")) qfile_tmp = "q" + qfile_tmp_tmp[1:] qfile = "".join(("".join((outputdir,"/")),qfile_tmp)) mtmp = NumElems*meqn*kmax qtmp = np.zeros(mtmp,float) time = read_qfile(mtmp,qfile,qtmp) qcoeffs_tmp = np.reshape(qtmp,(NumElems,meqn,kmax),'fortran') qcoeffs = qcoeffs_tmp[0:NumPhysElems,:,:] # Solution -- q qsoln_elem = np.zeros((NumPhysElems_new,meqn),float) qsoln = np.zeros((NumPhysNodes_new,meqn),float) sample_state2_unst(NumPhysElems,p2,meqn,kmax,LegVals,qcoeffs,qsoln_elem) set_soln_at_node_values(NumPhysElems_new,NumPhysNodes_new, meqn,tcounter_new,tnode_new,qsoln_elem,qsoln) # USER SUPPLIED FUNCTION: Plotting function plotq2_unst(m-1,meqn,NumPhysElems_new,NumPhysNodes_new, xlow,xhigh,ylow,yhigh,time,x_new,y_new,tnode_new, qsoln,xmid,ymid,qsoln_elem) plt.ioff() print "" else: print "" print " Error in plotdog2.py: GridType = ",GridType," is not supported." print "" return -1
def main(): '''Write some help documentation here ''' err1 = [] nnn1 = [] err2 = [] nnn2 = [] err3 = [] nnn3 = [] my_dictionary = {} old_err = l = 0 old_err = 1.0 new_err1 = 1.0 new_err2 = 1.0 new_err3 = 1.0 old_n = 1.0 new_n = 1.0 ###FRAME TO TEST n1 = 10 while (1): directory_num = my_dictionary['dir_num'] = l folder = 'output_00%s' % l if (not os.path.exists(folder)): break my_dictionary['curr_folder'] = folder # we want to do: # data = open('dogpack.data','w') # print >> data, dogpack_data_template % { 'mx': mx_now, 'ts_method': ts_method} # data.close() # and we avoid the .close() (even in case of exception) with 'with': directory_num = l try: qpre = np.loadtxt(folder + "/q0010.dat")[1:] except IOError: print "Could not find data in folder %s" % folder return print directory_num, folder ############################################### params = np.zeros(11, float) read_params(folder, params) meqn = int(params[0]) maux = int(params[1]) nplot = int(params[2]) meth1 = int(params[3]) mx = int(params[5]) my = int(params[6]) xlow = params[7] xhigh = params[8] ylow = params[9] yhigh = params[10] # Grid information mx_old = mx my_old = my dx_old = (xhigh - xlow) / mx_old dy_old = (yhigh - ylow) / my_old point_type = 2 points_per_dir = 5 mx = mx * points_per_dir my = my * points_per_dir dx = (xhigh - xlow) / mx dy = (yhigh - ylow) / my kmax = int((meth1 * (meth1 + 1) / 2)) phil = np.zeros((mx, my, points_per_dir, kmax), float) #print 'mx=',mx,'my=',my,'xlow=',xlow,'xhigh=',xhigh,'dx=',dx,params xc = np.zeros((mx, my), float) yc = np.zeros((mx, my), float) xol = np.zeros((mx, my), float) yol = np.zeros((mx, my), float) xor = np.zeros((mx, my), float) yor = np.zeros((mx, my), float) sxc = np.zeros((mx, my), float) syc = np.zeros((mx, my), float) if (point_type == 1): xl = np.zeros((mx + 1, my + 1), float) yl = np.zeros((mx + 1, my + 1), float) for j in range(0, my + 1): xl[:, j] = xlow + dx * np.arange(mx + 1)[:] for i in range(0, mx + 1): yl[i, :] = ylow + dy * np.arange(my + 1)[:] for j in range(0, my): xc[:, j] = (xlow + 0.5 * dx) + dx * np.arange(mx)[:] for i in range(0, mx): yc[i, :] = (ylow + 0.5 * dy) + dy * np.arange(my)[:] ##################################################### # 1D points dxi = 1.0 / float(points_per_dir) s1d = -1 + dxi + 2 * dxi * np.arange(points_per_dir) kk = -1 s2d = np.zeros((points_per_dir * points_per_dir, 2), float) for jj in range(0, points_per_dir): for ii in range(0, points_per_dir): kk = kk + 1 s2d[kk, 0] = s1d[ii] s2d[kk, 1] = s1d[jj] else: sq3 = np.sqrt(3.0) sq5 = np.sqrt(5.0) sq7 = np.sqrt(7.0) # 1D quadrature points s1d = np.zeros(points_per_dir, float) if (points_per_dir == 1): s1d[0] = -1.0 elif (points_per_dir == 2): s1d[0] = -1.0 / sq3 s1d[1] = 1.0 / sq3 elif (points_per_dir == 3): s1d[0] = -sq3 / sq5 s1d[1] = 0.0 s1d[2] = sq3 / sq5 elif (points_per_dir == 4): s1d[0] = -np.sqrt(3.0 + np.sqrt(4.8)) / sq7 s1d[1] = -np.sqrt(3.0 - np.sqrt(4.8)) / sq7 s1d[2] = np.sqrt(3.0 - np.sqrt(4.8)) / sq7 s1d[3] = np.sqrt(3.0 + np.sqrt(4.8)) / sq7 elif (points_per_dir == 5): s1d[0] = -np.sqrt(5.0 + np.sqrt(40.0 / 7.0)) / 3.0 s1d[1] = -np.sqrt(5.0 - np.sqrt(40.0 / 7.0)) / 3.0 s1d[2] = 0.0 s1d[3] = np.sqrt(5.0 - np.sqrt(40.0 / 7.0)) / 3.0 s1d[4] = np.sqrt(5.0 + np.sqrt(40.0 / 7.0)) / 3.0 kk = -1 s2d = np.zeros((points_per_dir * points_per_dir, 2), float) for jj in range(0, points_per_dir): for ii in range(0, points_per_dir): kk = kk + 1 s2d[kk, 0] = s1d[ii] s2d[kk, 1] = s1d[jj] xx = np.zeros(mx, float) yy = np.zeros(my, float) sx = np.zeros(mx, float) sy = np.zeros(my, float) xor1 = np.zeros(mx + points_per_dir, float) yor1 = np.zeros(my + points_per_dir, float) kk = 0 xtmp = xlow - 0.5 * dx_old xtmp1 = xlow - dx_old for i in range(0, mx_old): xtmp = xtmp + dx_old xtmp1 = xtmp1 + dx_old for m in range(0, points_per_dir): xx[kk + m] = xtmp + 0.5 * dx_old * s1d[m] sx[kk + m] = s1d[m] xor1[kk + m] = xtmp1 kk = kk + points_per_dir xor1[mx:mx + points_per_dir] = xtmp1 + dx_old kk = 0 ytmp = ylow - 0.5 * dy_old ytmp1 = ylow - dy_old for j in range(0, my_old): ytmp = ytmp + dy_old ytmp1 = ytmp1 + dy_old for m in range(0, points_per_dir): yy[kk + m] = ytmp + 0.5 * dy_old * s1d[m] sy[kk + m] = s1d[m] yor1[kk + m] = ytmp1 kk = kk + points_per_dir yor1[my:my + points_per_dir] = ytmp1 + dy_old for i in range(0, mx): for j in range(0, my): xc[i, j] = xx[i] yc[i, j] = yy[j] sxc[i, j] = sx[i] syc[i, j] = sy[j] ix = -1 for i in range(0, mx_old): for l1 in range(points_per_dir): ix = ix + 1 iy = -1 for j in range(0, my_old): for l2 in range(points_per_dir): iy = iy + 1 xol[ix, iy] = xor1[points_per_dir * (i)] yol[ix, iy] = yor1[points_per_dir * (j)] ix = -1 for i in range(0, mx_old): for l1 in range(points_per_dir): ix = ix + 1 iy = -1 for j in range(0, my_old): for l2 in range(points_per_dir): iy = iy + 1 xor[ix, iy] = xor1[points_per_dir * (i) + points_per_dir] yor[ix, iy] = yor1[points_per_dir * (j) + points_per_dir] xxx = np.zeros(mx + 1, float) yyy = np.zeros(my + 1, float) xxx[0] = xlow for i in range(1, mx): xxx[i] = 0.5 * (xx[i] + xx[i - 1]) xxx[mx] = xhigh yyy[0] = ylow for j in range(1, my): yyy[j] = 0.5 * (yy[j] + yy[j - 1]) yyy[my] = yhigh xl = np.zeros((mx + 1, my + 1), float) yl = np.zeros((mx + 1, my + 1), float) for i in range(0, mx + 1): for j in range(0, my + 1): xl[i, j] = xxx[i] yl[i, j] = yyy[j] # Sample Legendre polynomial on the midpoint of each sub-element p2 = points_per_dir * points_per_dir LegVals = np.zeros((kmax, p2), float) GetCart2Legendre(meth1, points_per_dir, s2d, LegVals) qfile_tmp_tmp = "".join((str(0 + 10000), ".dat")) qfile_tmp = "q" + qfile_tmp_tmp[1:] qfile = "".join(("".join((folder, "/")), qfile_tmp)) mtmp = mx_old * my_old * meqn * kmax qtmp = np.zeros(mtmp, float) time = read_qfile(mtmp, qfile, qtmp) qcoeffsold = np.reshape(qtmp, (kmax, meqn, my_old, mx_old)) qfile_tmp_tmp = "".join((str(n1 + 10000), ".dat")) qfile_tmp = "q" + qfile_tmp_tmp[1:] qfile = "".join(("".join((folder, "/")), qfile_tmp)) mtmp = mx_old * my_old * meqn * kmax qtmp = np.zeros(mtmp, float) time = read_qfile(mtmp, qfile, qtmp) qcoeffs = np.reshape(qtmp, (kmax, meqn, my_old, mx_old)) #qdiff=abs(qcoeffs-qcoeffsold) qsoln = np.zeros((mx * my, meqn), float) xc1 = np.reshape(xc, (mx * my)) yc1 = np.reshape(yc, (mx * my)) xleg = np.array(xc1) yleg = np.array(yc1) xp1, yp1 = mp.mapc2p(xc1, yc1) xpl, ypl = mp.mapc2p(xl, yl) xpllo, ypllo = mp.mapc2p(xol, yol) xplro, yplro = mp.mapc2p(xol, yor) xprlo, yprlo = mp.mapc2p(xor, yol) xprro, yprro = mp.mapc2p(xor, yor) xpy = np.array(xc) ypy = np.array(yc) xpy1 = np.array(xc) ypy1 = np.array(yc) coeff = np.array(xc) mcoeff = 0.0 for i in range(0, mx): for j in range(0, my): xpp1 = xpllo[i, j] ypp1 = ypllo[i, j] xpp2 = xprlo[i, j] ypp2 = yprlo[i, j] xpp3 = xprro[i, j] ypp3 = yprro[i, j] xpp4 = xplro[i, j] ypp4 = yplro[i, j] xmax = max(max(xpp1, xpp2), max(xpp3, xpp4)) xmin = min(min(xpp1, xpp2), min(xpp3, xpp4)) ymax = max(max(ypp1, ypp2), max(ypp3, ypp4)) ymin = min(min(ypp1, ypp2), min(ypp3, ypp4)) dx1 = xmax - xmin dy1 = ymax - ymin xin = xp1[ i * my + j] #xmin+dx1/2*(1+1)#xp1[i*my+j]#xmin+dx1/2*(1-0)#xp1[i*my+j]; yin = yp1[ i * my + j] #ymin+dy1/2*(1-0.5)#yp1[i*my+j]#ymin+dy1/2*(1-0)#yp1[i*my+j]; xo, yo = mp.squaremap(sxc[i, j], syc[i, j], xpp1, xpp2, xpp3, xpp4, ypp1, ypp2, ypp3, ypp4) #print sxc[i,j],syc[i,j],xo,yo,xpp1,xpp2,xpp3,xpp4,ypp1,ypp2,ypp3,ypp4 #adsf xpy[i, j] = xo ypy[i, j] = yo xpy1[i, j] = xmin ypy1[i, j] = ymin #mn=qdiff[:,0,j,i] #coeff[i,j]=max(mn) #mcoeff=max(mcoeff,coeff[i,j]) #for l1 in range(0,kmax): # phil[i,j,0,l1]=phi(xin,yin,xmin,ymin,dx1,dy1,l1+1) sample_state2_cart_mod(mx_old, my_old, points_per_dir, meqn, kmax, qcoeffs, LegVals, qsoln) qsoln = np.reshape(qsoln, (mx, my, meqn), 'F') qex1 = interface(np.reshape(xpy, (mx * my)), np.reshape(ypy, (mx * my))) #(xp1,yp1) qex = np.reshape(qex1, (mx, my)) plt.figure(1) plt.clf() xc2 = xpy #xpl[0:mx,0:my]#np.reshape(xp1,(mx,my)) yc2 = ypy #ypl[0:mx,0:my]#np.reshape(yp1,(mx,my)) #plt.gca().set_aspect('equal') #plt.gca().set_xlim(xl[0,0],xl[mx,0]) #plt.gca().set_ylim(yl[0,0],yl[0,my]) # qex[yc<0.2]=0.0 # qsoln[:,:,0][yc<0.2]=0.0 #plt.pcolor(xl,yl,qex) #plt.show() #plt.pcolor(xpl,ypl,qex) #print qcoeffs[0,0,:,6],xpy1[6,:] #plt.colorbar(); #plt.figure(2) #plt.clf() #plt.pcolor(xpl,ypl,qsoln[:,:,0]) #plt.colorbar(); #plt.figure(3) #plt.clf() #plt.pcolor(xpl,ypl,qex-qsoln[:,:,0]) #for i1 in range(mx): # for j1 in range(my): # #print [xpl[i1,j1],xpl[i1+1,j1]] # plt.plot([xpl[i1,j1], xpl[i1+1,j1]],[ypl[i1,j1], ypl[i1+1,j1]],'k') # plt.plot([xpl[i1,j1], xpl[i1,j1+1]],[ypl[i1,j1], ypl[i1,j1+1]],'k') #plt.colorbar(); #plt.show() #################################### diff = np.reshape((qsoln[:, :, 0] - qex), mx * my) h = dx_old old_n = new_n new_n = mx_old old_err1 = new_err1 old_err2 = new_err2 old_err3 = new_err3 #print "h=",h,mx,my new_err1 = max(abs( diff)) #h**2*np.linalg.norm(diff,1) #np.linalg.norm(diff,np.inf)# new_err2 = h**2 * np.linalg.norm(diff, 1) new_err3 = h * np.linalg.norm(diff, 2) """ if( old_err > 0 and new_err > 0 ): result = r1 + folder + ' log2(ratio) = %(rat).3f' % \ {'rat' : log( (old_err/new_err), float(new_n)/float(old_n)) } errors['rat'] = log( ( old_err/new_err), float(new_n)/float(old_n) ) else: result = r1 + folder + ' log2(ratio) = %(rat).3f' % \ {'old' : old_err, 'new' : new_err, 'rat' : (old_err/new_err) } errors['rat'] = old_err/new_err """ #print 'ratio=',old_err/new_err,log(old_err/new_err)/log(new_n/old_n) rat1 = np.log(old_err1 / new_err1) / np.log( float(new_n) / float(old_n)) rat2 = np.log(old_err2 / new_err2) / np.log( float(new_n) / float(old_n)) rat3 = np.log(old_err3 / new_err3) / np.log( float(new_n) / float(old_n)) #print 'old error',old_err,'old n',old_n,old_err/new_err,float(new_n)/float(old_n) print " Error = %s; Order = %s " % (new_err1, rat1) print " Error = %s; Order = %s " % (new_err2, rat2) print " Error = %s; Order = %s " % (new_err3, rat3) err1 = err1 + [new_err1] nnn1 = nnn1 + [new_n] err2 = err2 + [new_err2] nnn2 = nnn2 + [new_n] err3 = err3 + [new_err3] nnn3 = nnn3 + [new_n] l = l + 1 print "here! ", l print nnn1, err1 plt.loglog(nnn1, err1) plt.show()
def main(): my_dictionary = {} old_err = l = 0 old_err = 1.0 new_err1 = 1.0 new_err2 = 1.0 new_err3 = 1.0 old_n = 1.0 new_n = 1.0 ###FRAME TO TEST n1 = 0 while (1): directory_num = my_dictionary['dir_num'] = l folder = 'output' if (not os.path.exists(folder)): break my_dictionary['curr_folder'] = folder # we want to do: # data = open('dogpack.data','w') # print >> data, dogpack_data_template % { 'mx': mx_now, 'ts_method': ts_method} # data.close() # and we avoid the .close() (even in case of exception) with 'with': directory_num = l try: qpre = np.loadtxt(folder + "/q0010.dat")[1:] except IOError: print "Could not find data in folder %s" % folder return print directory_num, folder ############################################### params = np.zeros(11, float) read_params(folder, params) meqn = int(params[0]) maux = int(params[1]) nplot = int(params[2]) meth1 = int(params[3]) mx = int(params[5]) my = int(params[6]) xlow = params[7] xhigh = params[8] ylow = params[9] yhigh = params[10] print params, my, mx, xlow # Grid information mx_old = mx my_old = my dx_old = (xhigh - xlow) / mx_old dy_old = (yhigh - ylow) / my_old point_type = 1 points_per_dir = 1 mx = mx * points_per_dir my = my * points_per_dir dx = (xhigh - xlow) / mx dy = (yhigh - ylow) / my kmax = int((meth1 * (meth1 + 1) / 2)) phil = np.zeros((mx, my, points_per_dir, kmax), float) if (point_type == 1): xl = np.zeros((mx + 1, my + 1), float) yl = np.zeros((mx + 1, my + 1), float) xc = np.zeros((mx, my), float) yc = np.zeros((mx, my), float) for j in range(0, my + 1): xl[:, j] = xlow + dx * np.arange(mx + 1)[:] for i in range(0, mx + 1): yl[i, :] = ylow + dy * np.arange(my + 1)[:] for j in range(0, my): xc[:, j] = (xlow + 0.5 * dx) + dx * np.arange(mx)[:] for i in range(0, mx): yc[i, :] = (ylow + 0.5 * dy) + dy * np.arange(my)[:] ##################################################### # 1D points dxi = 1.0 / float(points_per_dir) s1d = -1 + dxi + 2 * dxi * np.arange(points_per_dir) kk = -1 s2d = np.zeros((points_per_dir * points_per_dir, 2), float) for jj in range(0, points_per_dir): for ii in range(0, points_per_dir): kk = kk + 1 s2d[kk, 0] = s1d[ii] s2d[kk, 1] = s1d[jj] else: sq3 = np.sqrt(3.0) sq5 = np.sqrt(5.0) sq7 = np.sqrt(7.0) # 1D quadrature points s1d = np.zeros(points_per_dir, float) if (points_per_dir == 1): s1d[0] = -1.0 elif (points_per_dir == 2): s1d[0] = -1.0 / sq3 s1d[1] = 1.0 / sq3 elif (points_per_dir == 3): s1d[0] = -sq3 / sq5 s1d[1] = 0.0 s1d[2] = sq3 / sq5 elif (points_per_dir == 4): s1d[0] = -np.sqrt(3.0 + np.sqrt(4.8)) / sq7 s1d[1] = -np.sqrt(3.0 - np.sqrt(4.8)) / sq7 s1d[2] = np.sqrt(3.0 - np.sqrt(4.8)) / sq7 s1d[3] = np.sqrt(3.0 + np.sqrt(4.8)) / sq7 elif (points_per_dir == 5): s1d[0] = -np.sqrt(5.0 + np.sqrt(40.0 / 7.0)) / 3.0 s1d[1] = -np.sqrt(5.0 - np.sqrt(40.0 / 7.0)) / 3.0 s1d[2] = 0.0 s1d[3] = np.sqrt(5.0 - np.sqrt(40.0 / 7.0)) / 3.0 s1d[4] = np.sqrt(5.0 + np.sqrt(40.0 / 7.0)) / 3.0 kk = -1 s2d = np.zeros((points_per_dir * points_per_dir, 2), float) for jj in range(0, points_per_dir): for ii in range(0, points_per_dir): kk = kk + 1 s2d[kk, 0] = s1d[ii] s2d[kk, 1] = s1d[jj] xx = np.zeros(mx, float) yy = np.zeros(my, float) kk = 0 xtmp = xlow - 0.5 * dx_old for i in range(0, mx_old): xtmp = xtmp + dx_old for m in range(0, points_per_dir): xx[kk + m] = xtmp + 0.5 * dx_old * s1d[m] kk = kk + points_per_dir kk = 0 ytmp = ylow - 0.5 * dy_old for j in range(0, my_old): ytmp = ytmp + dy_old for m in range(0, points_per_dir): yy[kk + m] = ytmp + 0.5 * dy_old * s1d[m] kk = kk + points_per_dir xc = np.zeros((mx, my), float) yc = np.zeros((mx, my), float) for i in range(0, mx): for j in range(0, my): xc[i, j] = xx[i] yc[i, j] = yy[j] xxx = np.zeros(mx + 1, float) yyy = np.zeros(my + 1, float) xxx[0] = xlow for i in range(1, mx): xxx[i] = 0.5 * (xx[i] + xx[i - 1]) xxx[mx] = xhigh yyy[0] = ylow for j in range(1, my): yyy[j] = 0.5 * (yy[j] + yy[j - 1]) yyy[my] = yhigh xl = np.zeros((mx + 1, my + 1), float) yl = np.zeros((mx + 1, my + 1), float) for i in range(0, mx + 1): for j in range(0, my + 1): xl[i, j] = xxx[i] yl[i, j] = yyy[j] # Sample Legendre polynomial on the midpoint of each sub-element p2 = points_per_dir * points_per_dir LegVals = np.zeros((kmax, p2), float) GetCart2Legendre(meth1, points_per_dir, s2d, LegVals) qfile_tmp_tmp = "".join((str(0 + 10000), ".dat")) qfile_tmp = "q" + qfile_tmp_tmp[1:] qfile = "".join(("".join((folder, "/")), qfile_tmp)) mtmp = mx_old * my_old * meqn * kmax qtmp = np.zeros(mtmp, float) time = read_qfile(mtmp, qfile, qtmp) qcoeffsold = np.reshape(qtmp, (kmax, meqn, my_old, mx_old)) qfile_tmp_tmp = "".join((str(n1 + 10005), ".dat")) qfile_tmp = "q" + qfile_tmp_tmp[1:] qfile = "".join(("".join((folder, "/")), qfile_tmp)) mtmp = mx_old * my_old * meqn * kmax qtmp = np.zeros(mtmp, float) print qfile time = read_qfile(mtmp, qfile, qtmp) qcoeffs = np.reshape(qtmp, (kmax, meqn, my_old, mx_old)) qdiff = abs(qcoeffs - qcoeffsold) #print qcoeffs.shape,dx qsoln = np.zeros((mx * my, meqn), float) xc1 = np.reshape(xc, (mx * my)) yc1 = np.reshape(yc, (mx * my)) xp1, yp1 = mp.mapc2p(xc1, yc1) xpl, ypl = mp.mapc2p(xl, yl) xpy = np.array(xc) ypy = np.array(yc) xpy1 = np.array(xc) ypy1 = np.array(yc) coeff = np.array(xc) mcoeff = 0.0 mesh = meshobject() yplot = 0.201 xplot = np.linspace(1.0 / 2. * dx, 1.0 - 1. / 2. * dx, 180) qplot = np.zeros(xplot.shape) qmax = 0.0 #for i in range(0,mx): # for j in range(0,my): i = 0 for l in range(xplot.shape[0]): x1 = xplot[l] y1 = yplot check = 0 j = 0 while (j < my): #print 'l=',l,'i=',i,'j=',j xpp1 = xpl[i, j] ypp1 = ypl[i, j] xpp2 = xpl[i + 1, j] ypp2 = ypl[i + 1, j] xpp3 = xpl[i + 1, j + 1] ypp3 = ypl[i + 1, j + 1] xpp4 = xpl[i, j + 1] ypp4 = ypl[i, j + 1] #print xpp1,xpp2,xpp3,xpp4,ypp1,ypp2,ypp3,ypp4 xmax = max(max(xpp1, xpp2), max(xpp3, xpp4)) xmin = min(min(xpp1, xpp2), min(xpp3, xpp4)) ymax = max(max(ypp1, ypp2), max(ypp3, ypp4)) ymin = min(min(ypp1, ypp2), min(ypp3, ypp4)) boundary = 0 if (x1 == xpp1 or x1 == xpp2 or x1 == xpp3 or x1 == xpp4): if (ymax >= y1 and ymin <= y1): boundary = 1 if (y1 == ypp1 or y1 == ypp2 or y1 == ypp3 or y1 == ypp4): if (xmax >= x1 and xmin <= x1): boundary = 1 dx1 = xmax - xmin dy1 = ymax - ymin xpy1[i, j] = xmin ypy1[i, j] = ymin mn = qdiff[:, 0, j, i] coeff[i, j] = max(mn) mcoeff = max(mcoeff, coeff[i, j]) x = [xpp1, xpp2, xpp3, xpp4] y = [ypp1, ypp2, ypp3, ypp4] order = meth1 mesh.setcell(i, j, order, x, y, qcoeffs[:, 0, i, j]) poly = [(xpp1, ypp1), (xpp2, ypp2), (xpp3, ypp3), (xpp4, ypp4)] if (point_inside_polygon(x1, y1, poly) or boundary): qmax = max(qmax, max(qcoeffs[:, 0, i, j])) xin = x1 #xmin+dx1/2*(1+1)#xp1[i*my+j]#xmin+dx1/2*(1-0)#xp1[i*my+j]; yin = y1 #ymin+dy1/2*(1-0.5)#yp1[i*my+j]#ymin+dy1/2*(1-0)#yp1[i*my+j]; q = 0.0 for l11 in range(0, kmax): phil[i, j, 0, l11] = phi(xin, yin, xmin, ymin, dx1, dy1, l11 + 1) q = q + phil[i, j, 0, l11] * qcoeffs[l11, 0, j, i] #print 'q=',qcoeffs[:,0,i,j],q qplot[l] = q check = 1 #print 'l=',l,'check=1','i=',i,'j=',j,q j = my elif (j == (my - 1) and i < mx - 1 and check == 0): #print 'here' i = i + 1 j = 0 j = j + 1 if (check == 0): print 'l=', l, 'nowork' a = qplot print 'xplot', xplot[qplot == 0], a[a < 1.0] plt.plot(xplot, a) #plt.ylim(-1.5,0.0) # plt.plot(xplot,xplot,'ko') plt.show()