def compute_exact_solution(outdir='./_output', frame=0): #------------------------------------ from scipy.integrate import fixed_quad, quad from pyclaw.plotters.data import ClawPlotData plotdata = ClawPlotData() plotdata.outdir = outdir #Read in the solution dat = plotdata.getframe(frame) ap = ac.AcousticsProblem('setprob.data', 'sharpclaw.data') t = dat.t print t grid = dat.grids[0] xc = dat.center[0] dx = dat.d xe = dat.edge[0] print "Computing exact solution for mx = ", dat.n qq = zeros([2, size(xc)]) for ii in range(size(xc)): qq[0, ii], dummy = fixed_quad(ap.pvec, xe[ii], xe[ii + 1], args=(t, )) qq[1, ii], dummy = fixed_quad(ap.uvec, xe[ii], xe[ii + 1], args=(t, )) #qq[0,ii],dummy= quad(ap.pvec,xe[ii],xe[ii+1],args=(t,),epsabs=1.e-11,epsrel=1.e-11) #qq[1,ii],dummy= quad(ap.uvec,xe[ii],xe[ii+1],args=(t,),epsabs=1.e-11,epsrel=1.e-11) qq /= dx return qq
def compute_exact_solution(outdir='./_output',frame=0): #------------------------------------ from scipy.integrate import fixed_quad, quad from pyclaw.plotters.data import ClawPlotData plotdata = ClawPlotData() plotdata.outdir=outdir #Read in the solution dat = plotdata.getframe(frame) ap=ac.AcousticsProblem('setprob.data','sharpclaw.data') t = dat.t print t grid = dat.grids[0] xc = dat.center[0] dx=dat.d xe = dat.edge[0] print "Computing exact solution for mx = ",dat.n qq=zeros([2,size(xc)]) for ii in range(size(xc)): qq[0,ii],dummy = fixed_quad(ap.pvec,xe[ii],xe[ii+1],args=(t,)) qq[1,ii],dummy = fixed_quad(ap.uvec,xe[ii],xe[ii+1],args=(t,)) #qq[0,ii],dummy= quad(ap.pvec,xe[ii],xe[ii+1],args=(t,),epsabs=1.e-11,epsrel=1.e-11) #qq[1,ii],dummy= quad(ap.uvec,xe[ii],xe[ii+1],args=(t,),epsabs=1.e-11,epsrel=1.e-11) qq/=dx return qq
def timereverse(frame=2,nframes=60): from pyclaw.plotters.data import ClawPlotData plotdata = ClawPlotData() plotdata.outdir='./_output' #"Exact" solution dat0 = plotdata.getframe(frame) u0 = dat0.q[:,0] #Time-reversed solution dat1 = plotdata.getframe(nframes-frame) u1 = dat1.q[:,0] xc = dat0.c_center return u0,u1,xc[0]
def timereverse(frame=2, nframes=60): from pyclaw.plotters.data import ClawPlotData plotdata = ClawPlotData() plotdata.outdir = './_output' #"Exact" solution dat0 = plotdata.getframe(frame) u0 = dat0.q[:, 0] #Time-reversed solution dat1 = plotdata.getframe(nframes - frame) u1 = dat1.q[:, 0] xc = dat0.c_center return u0, u1, xc[0]
def plotframe(frameno, level=1): plotdata = ClawPlotData() plotdata.outdir = "_output" print "Plotting solution from ", plotdata.outdir plotdata = setplot(plotdata) try: frame = plotdata.getframe(frameno) except: print "Unable to get frame" return mlab.figure(1, bgcolor=(1, 1, 1), size=(700, 600)) mlab.clf() for grid in frame.grids: if grid.level <= level: y = grid.c_center[1] x = grid.c_center[0] q = grid.q eta = q[:, :, 3] h = q[:, :, 0] #return x,y,eta #eta = where(q[:,:,0] > 1.,eta,nan) #import pdb; pdb.set_trace() topo = eta - h cutoff = 0.5 #cutoff2 = -500. shift = 0. scale = 10. topo1 = scale * where(topo < cutoff, topo - shift, cutoff - shift) #topo1 = scale*where(topo>cutoff2, topo1, nan) eta1 = scale * where(eta < cutoff, eta - shift, cutoff - shift) water1 = where(h >= 1.e-3, eta1, nan) mlab.mesh(x, y, topo1, colormap='Greens', vmin=-1.0, vmax=0.8) mlab.mesh(x, y, water1, colormap='Blues', vmin=-0.8, vmax=0.8) #mlab.surf(x,y,topo1,colormap='Greens',warp_scale=10,vmin=-0.8,vmax=0.5) #mlab.surf(x,y,water1,colormap='Blues',warp_scale=10,vmin=-0.8,vmax=0.5) V = (150.95115856920216,\ 80.12676623482308,\ 13.359093592227218,\ array([ 2.744 , 1.70099999, -0.04745156])) V = (-108.612973405259,\ 62.96905073871072,\ 13.359093592227456,\ array([ 2.744 , 1.70099999, -0.04745156])) mlab.view(*V) t = frame.t mlab.title('Time = %5.2f' % t, color=(0, 0, 0), height=0.1, size=0.5)
def plotframe(frameno,level=1): plotdata = ClawPlotData() plotdata.outdir = "_output" print "Plotting solution from ",plotdata.outdir plotdata = setplot(plotdata) try: frame = plotdata.getframe(frameno) except: print "Unable to get frame" return mlab.figure(1,bgcolor=(1,1,1),size=(700,600)) mlab.clf() for grid in frame.grids: if grid.level <= level: y = grid.c_center[1] x = grid.c_center[0] q = grid.q eta = q[:,:,3] h = q[:,:,0] #return x,y,eta #eta = where(q[:,:,0] > 1.,eta,nan) #import pdb; pdb.set_trace() topo = eta - h cutoff = 0.5 #cutoff2 = -500. shift = 0. scale = 10. topo1 = scale*where(topo<cutoff, topo-shift, cutoff-shift) #topo1 = scale*where(topo>cutoff2, topo1, nan) eta1 = scale*where(eta<cutoff, eta-shift, cutoff-shift) water1 = where(h>=1.e-3, eta1, nan) mlab.mesh(x,y,topo1,colormap='Greens',vmin=-1.0, vmax=0.8) mlab.mesh(x,y,water1,colormap='Blues',vmin=-0.8, vmax=0.8) #mlab.surf(x,y,topo1,colormap='Greens',warp_scale=10,vmin=-0.8,vmax=0.5) #mlab.surf(x,y,water1,colormap='Blues',warp_scale=10,vmin=-0.8,vmax=0.5) V = (150.95115856920216,\ 80.12676623482308,\ 13.359093592227218,\ array([ 2.744 , 1.70099999, -0.04745156])) V = (-108.612973405259,\ 62.96905073871072,\ 13.359093592227456,\ array([ 2.744 , 1.70099999, -0.04745156])) mlab.view(*V) t = frame.t mlab.title('Time = %5.2f' % t,color=(0,0,0),height=0.1,size=0.5)
def plotframe(frameno,level=1, water_opacity=1.): plotdata = ClawPlotData() plotdata.outdir = outdir print "Plotting solution from ",plotdata.outdir plotdata = setplot(plotdata) try: frame = plotdata.getframe(frameno) except: print "Unable to get frame" return mlab.figure(1,bgcolor=(1,1,1),size=(700,600)) mlab.clf() for grid in frame.grids: if grid.level == level: y = grid.c_center[1] x = grid.c_center[0] q = grid.q eta = q[:,:,3] h = q[:,:,0] topo = eta - h cutoff = 0.5 #cutoff2 = -500. shift = 0. scale = 1. topo1 = scale*where(topo<cutoff, topo-shift, cutoff-shift) #topo1 = scale*where(topo>cutoff2, topo1, nan) eta1 = scale*where(eta<cutoff, eta-shift, cutoff-shift) water1 = where(h>=1.e-3, eta1, nan) scale = 12. #mlab.mesh(x,y,topo1,colormap='Greens',vmin=-1.0, vmax=0.8) #mlab.mesh(x,y,water1,colormap='Blues',vmin=-0.8, vmax=0.8) mlab.surf(x,y,topo1,colormap='YlGn',warp_scale=scale,\ vmin=-0.3,vmax=0.3) mlab.surf(x,y,water1,colormap='Blues',warp_scale=scale,\ vmin=-0.2,vmax=0.3, opacity=water_opacity) # set the view: (Do V = view() to figure out the current view) V = (29.157490879985176,\ 67.560491214404507,\ 79.798910042690324,\ array([ 0. , 1. , -0.07500005])) mlab.view(*V) t = frame.t mlab.title('Time = %5.2f' % t,color=(0,0,0),height=0.1,size=0.5)
def plotframe(frameno,level=1, water_opacity=1.): plotdata = ClawPlotData() plotdata.outdir = outdir print "Plotting solution from ",plotdata.outdir plotdata = setplot(plotdata) try: frame = plotdata.getframe(frameno) except: print "Unable to get frame" return mlab.figure(1,bgcolor=(1,1,1),size=(700,600)) mlab.clf() for grid in frame.grids: if grid.level == level: y = grid.c_center[1] x = grid.c_center[0] q = grid.q eta = q[:,:,3] h = q[:,:,0] topo = eta - h cutoff = 100. #cutoff2 = -500. shift = 0. scale = 1. topo1 = scale*where(topo<cutoff, topo-shift, cutoff-shift) #topo1 = scale*where(topo>cutoff2, topo1, nan) eta1 = scale*where(eta<cutoff, eta-shift, cutoff-shift) water1 = where(h>=1.e-3, eta1, nan) scale = 10. #mlab.mesh(x,y,topo1,colormap='Greens',vmin=-1.0, vmax=0.8) #mlab.mesh(x,y,water1,colormap='Blues',vmin=-0.8, vmax=0.8) if 0: mlab.surf(x,y,topo1,colormap='YlGn',warp_scale=scale,\ vmin=-0.3,vmax=0.3) mlab.surf(x,y,water1,colormap='Blues',warp_scale=scale,\ vmin=-0.2,vmax=0.3, opacity=water_opacity) # set the view: (Do V = view() to figure out the current view) #mlab.view(*V) t = frame.t
def plotframe(frameno): plotdata = ClawPlotData() plotdata.outdir = "_output" plotdata = setplot(plotdata) frame = plotdata.getframe(frameno) x = frame.grids[0].c_center[0] y = frame.grids[0].c_center[1] q = frame.grids[0].q eta = q[:,:,3] eta = where(q[:,:,0] > 1.,eta,nan) #import pdb; pdb.set_trace() mlab.figure(3,bgcolor=(1,1,1)) mlab.clf() #plot_solid_sphere() plot_lat_long_lines() #x = 360 - x X,Y,Z = plot_eta(x,y,eta)
def entropy(nend,nstart=8,outdir='./_output',sigfun='exp'): aux = np.loadtxt('_output/fort.aux') rho = aux[:,0] K = aux[:,1] plotdata = ClawPlotData() plotdata.outdir='./_output' ents=np.zeros([nend-nstart+1,1]) for i in range(nstart,nend+1): dat = plotdata.getframe(i) u = dat.q[:,1] mom=rho*u**2/2. # Change the next line according to the functional form of sigma: # For exponential relation sigma(eps) = e^(K*eps) - 1: # MUST OUTPUT SIGMA! sigma = dat.q[:,0] sigint = (sigma-np.log(sigma+1.))/K # For sigma(eps) = K*eps + 0.5*eps**2: # MUST OUTPUT EPS! #eps = dat.q[:,0] #sigint = K*eps/2. + eps**3/6. ent = (mom+sigint) #pl.clf() #pl.plot(nrg) #pl.axis([0,1800,0,0.015]) #pl.draw() #time.sleep(2.1) ents[i-nstart]=np.sum(mom+sigint)*dat.grid.d[0] print ents[i-nstart] ents=ents/ents[0] pl.clf() pl.plot(ents) pl.draw() return ents
def entropy(nend, nstart=8, outdir='./_output', sigfun='exp'): aux = np.loadtxt('_output/fort.aux') rho = aux[:, 0] K = aux[:, 1] plotdata = ClawPlotData() plotdata.outdir = './_output' ents = np.zeros([nend - nstart + 1, 1]) for i in range(nstart, nend + 1): dat = plotdata.getframe(i) u = dat.q[:, 1] mom = rho * u**2 / 2. # Change the next line according to the functional form of sigma: # For exponential relation sigma(eps) = e^(K*eps) - 1: # MUST OUTPUT SIGMA! sigma = dat.q[:, 0] sigint = (sigma - np.log(sigma + 1.)) / K # For sigma(eps) = K*eps + 0.5*eps**2: # MUST OUTPUT EPS! #eps = dat.q[:,0] #sigint = K*eps/2. + eps**3/6. ent = (mom + sigint) #pl.clf() #pl.plot(nrg) #pl.axis([0,1800,0,0.015]) #pl.draw() #time.sleep(2.1) ents[i - nstart] = np.sum(mom + sigint) * dat.grid.d[0] print ents[i - nstart] ents = ents / ents[0] pl.clf() pl.plot(ents) pl.draw() return ents
rundata.probdata.a=4.0 # 1 for narrow pulse, 4 for wide pulse rundata.clawdata.mx=mx rundata.clawdata.nout=1 rundata.clawdata.tfinal=8 rundata.write() runclaw(xclawcmd='xsclaw',outdir=outdir) #Get the material parameters aux = np.loadtxt(outdir+'/fort.aux') rho = aux[:,0]; K = aux[:,1] plotdata = ClawPlotData() plotdata.outdir=outdir #Read in the solution dat = plotdata.getframe(frame) eps = dat.q[:,0] p = -eps*K u = dat.q[:,1] exact = compute_exact_solution(outdir,frame) error = sum(abs(exact[1,:]-u))*dat.d[0] err.append(error) # xc=dat.center[0] # pl.clf() # pl.plot(xc,exact[1,:],'-k',xc,u,'or') # pl.draw() print error conv=np.zeros(len(err))
rundata.clawdata.mx = mx rundata.clawdata.nout = 1 rundata.clawdata.tfinal = 8 rundata.write() runclaw(xclawcmd='xsclaw', outdir=outdir) #Get the material parameters aux = np.loadtxt(outdir + '/fort.aux') rho = aux[:, 0] K = aux[:, 1] plotdata = ClawPlotData() plotdata.outdir = outdir #Read in the solution dat = plotdata.getframe(frame) eps = dat.q[:, 0] p = -eps * K u = dat.q[:, 1] exact = compute_exact_solution(outdir, frame) error = sum(abs(exact[1, :] - u)) * dat.d[0] err.append(error) # xc=dat.center[0] # pl.clf() # pl.plot(xc,exact[1,:],'-k',xc,u,'or') # pl.draw() print error conv = np.zeros(len(err))