예제 #1
0
def plot(x, y, f, title, plt=None):
    if plt is None:
        #import matplotlib.pylab as plt
        import scitools.easyviz as plt
    plt.figure()
    plt.plot(x, y, x, f)
    plt.legend(["approximation", "exact"])
    plt.title(title)
    return plt
예제 #2
0
def plot(x, y, f, title, plt=None):
    if plt is None:
        # import matplotlib.pylab as plt
        import scitools.easyviz as plt
    plt.figure()
    plt.plot(x, y, x, f)
    plt.legend(["approximation", "exact"])
    plt.title(title)
    return plt
예제 #3
0
파일: tools.py 프로젝트: SpuqTeam/spuq
 def plotConvergence(cls, scale, error4scale, title, legend, regression = False):
     p.figure()
     p.loglog(scale, error4scale, "k-d", xlabel = "samples", ylabel = "error",)  # semilogy
     p.title(title)
     p.legend(legend)
     if regression and len(error4scale) > 1:
         p.hold('on')
         lineSpace = np.array((scale[0], scale[-1]))
         slope, intercept, r_value, p_value, std_err = stats.linregress(scale, np.log10(error4scale))
         line = np.power(10, slope * lineSpace + intercept)
         p.plot(lineSpace, line, "k:", legend = "{slope:.2}x + c" \
                .format(slope = slope))
     p.hardcopy(cls.folder + title + "  " + t.strftime('%Y-%m-%d_%H-%M') + ".pdf")
예제 #4
0
파일: tools.py 프로젝트: SpuqTeam/spuq
    def plotConvergenceMean(cls, approx, exact, regression = False):
        nApprox = approx.shape[0]
        errorMean = np.empty(nApprox)
        for curSampleN in range(0, nApprox):
            errorMean[curSampleN] = cls.computeError(np.mean(approx[:curSampleN + 1], 0), exact)

        p.figure()
        # lSpace = p.linspace(0, errorMean.size, errorMean.size)
        lSpace = list(i * (len(exact) ** 2) for i in range(nApprox))
        p.loglog(lSpace, errorMean, "k-", xlabel = "samples", ylabel = "error",
                   legend = "E[(Q_M - E[Q])^2]^{1/2}")
        print("CompCost: {compCost:5.2e}\t Error: {error:5.4e}"
              .format(compCost = lSpace[-1], error = errorMean[-1]))
        if regression:
            p.hold('on')
            lineSpace = np.array((lSpace[0], lSpace[-1]))
            slope, intercept, r_value, p_value, std_err = stats.linregress(lSpace, np.log10(errorMean))
            line = np.power(10, slope * lineSpace + intercept)
            p.plot(lineSpace, line, "k:", legend = "{slope:.2}x + c" \
                   .format(slope = slope))
예제 #5
0
# visual_mesh = plot(mesh,title = "Mesh")
# visual_mesh.write_png("Image/mesh_%gx%g.png"%(nx,ny))

# Plot solution
X = 0; Y = 1;
u1,u2 = u0.split(deepcopy = True)

us = u1 if u1.ufl_element().degree() == 1 else \
     interpolate(u1, FunctionSpace(mesh, 'Lagrange', 1))
u_box = scitools.BoxField.dolfin_function2BoxField(us, mesh, (nx,ny), uniform_mesh=True)


ev.contour(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, 20, 
           savefig='Image/Contour of u1_P%g(mesh:%g-%g).png'% (nz,nx,ny), title='Contour plot of u1', colorbar='on')

ev.figure()
ev.surf(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, shading='interp', colorbar='on', title='surf plot of u1', savefig='Image/Surf of u1_P%g(mesh:%g-%g).png'% (nz,nx,ny))

#ev.figure()
#ev.mesh(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values,colorbar='on',shading='interp', title='mesh plot of u1', savefig='Image/Mesh of u1_P%g(mesh:%g-%g).png'% (nz,nx,ny))

# Plot exact solution
u1_ex,u2_ex = u_ex.split(deepcopy = True)
u1_ex = u1_ex if u1_ex.ufl_element().degree() == 1 else \
     interpolate(u1_ex, FunctionSpace(mesh, 'Lagrange', 1))
u_box = scitools.BoxField.dolfin_function2BoxField(u1_ex, mesh, (nx,ny), uniform_mesh=True)

ev.figure()
ev.contour(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, 20, 
           savefig='Image/Contour of exact solution u1_P%g(mesh:%g-%g).png'% (nz,nx,ny), title='Contour plot of exact u1',colorbar='on')
예제 #6
0
                                                   mesh, (nx, ny),
                                                   uniform_mesh=True)

# Write out u at mesh point (i,j)
i = nx
j = ny
print 'u(%g,%g)=%g' % (u_box.grid.coor[X][i], u_box.grid.coor[Y][j],
                       u_box.values[i, j])
ev.contour(u_box.grid.coorv[X],
           u_box.grid.coorv[Y],
           u_box.values,
           14,
           savefig='tmp0.eps',
           title='Contour plot of u',
           clabels='on')
ev.figure()
ev.surf(u_box.grid.coorv[X],
        u_box.grid.coorv[Y],
        u_box.values,
        shading='interp',
        colorbar='on',
        title='surf plot of u',
        savefig='tmp3.eps')
ev.figure()
ev.mesh(u_box.grid.coorv[X],
        u_box.grid.coorv[Y],
        u_box.values,
        title='mesh plot of u',
        savefig='tmp4.eps')

# Extract and plot u along the line y=0.5
예제 #7
0
#from scitools.easyviz.gnuplot_ import *

h0 = 2277.  # Height of the top of the mountain (m)
R = 4.  # The radius of the mountain (km)

x = y = np.linspace(-10., 10., 41)
xv, yv = plt.ndgrid(x, y)  # Grid for x, y values (km)
hv = h0 / (1 + (xv**2 + yv**2) / (R**2))  # Compute height (m)

x = y = np.linspace(-10., 10., 11)
x2v, y2v = plt.ndgrid(x, y)  # Define a coarser grid for the vector field
h2v = h0 / (1 + (x2v**2 + y2v**2) / (R**2))  # Compute height for new grid
dhdx, dhdy = np.gradient(h2v)  # Compute the gradient vector (dh/dx,dh/dy)

# Draw contours and gradient field of h
plt.figure(9)
plt.quiver(x2v, y2v, dhdx, dhdy, 0, 'r')
plt.hold('on')
plt.contour(xv, yv, hv)
plt.axis('equal')
# end draw contours and gradient field of h

x = y = np.linspace(-5, 5, 11)
xv, yv = plt.ndgrid(x, y)
u = xv**2 + 2 * yv - .5 * xv * yv
v = -3 * yv

# Draw 2D-field
plt.figure(10)
plt.quiver(xv, yv, u, v, 200, 'b')
plt.axis('equal')
import scitools.easyviz as plt

h0 = 2277.  # Height of the top of the mountain (m)
R = 4.     # The radius of the mountain (km)

x = y = np.linspace(-10., 10., 41)
xv, yv = plt.ndgrid(x, y)
hv = h0/(1+(xv**2+yv**2)/(R**2))

s = np.linspace(0, 2*np.pi, 100)
curve_x = 10*(1 - s/(2*np.pi))*np.cos(s)
curve_y = 10*(1 - s/(2*np.pi))*np.sin(s)
curve_z = h0/(1 + 100*(1 - s/(2*np.pi))**2/(R**2))

# Simple plot of mountain
plt.figure(1)
plt.mesh(xv, yv, hv)

# Simple plot of mountain and parametric curve
plt.figure(2)
plt.surf(xv, yv, hv)
plt.hold('on')

# add the parametric curve. Last parameter controls color of the curve
plt.plot3(curve_x, curve_y, curve_z, 'b-')
# endsimpleplots

# Default two-dimensional contour plot
plt.figure(3)
plt.contour(xv, yv, hv)
"""
# Define a higher-order approximation to the exact solution
t3 = time.time()
Ue=VectorFunctionSpace(mesh,"Lagrange",degree= 3)
u_ex = interpolate(u_exact,Ue)
t4 = time.time()
# Plot exact solution

visual_ue1 = plot(u_ex[0],wireframe = False,title="the exact solution of u1",rescale = True , axes = True, basename = "deflection" ,legend ="u1")
visual_ue2 = plot(u_ex[1],wireframe = False,title="the exact solution of u2",rescale = True , axes = True, basename = "deflection" ,legend ="u2")
visual_ue1.elevate(-65) #tilt camera -65 degree(latitude dir)
visual_ue2.elevate(-65) #tilt camera -65 degree(latitude dir)
visual_ue1.write_png("Image/P%gu1_exact_%gx%g.png"%(num,nx,ny))
visual_ue2.write_png("Image/P%gu2_exact_%gx%g.png"%(num,nx,ny))
interactive()
"""
u1_ex,u2_ex = u_ex.split(deepcopy = True)
u1_ex = u1_ex if u1_ex.ufl_element().degree() == 1 else \
     interpolate(u1_ex, FunctionSpace(mesh, 'Lagrange', 1))
u_box = scitools.BoxField.dolfin_function2BoxField(u1_ex, mesh, (nx,ny), uniform_mesh=True)

ev.figure()
ev.contour(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, 20, 
           savefig='Image/Contour of exact solution u1_P%g(mesh:%g-%g).png'% (num,nx,ny), title='Contour plot of exact u1',colorbar='on')
ev.figure()
ev.surf(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, shading='interp', colorbar='on', 
        title='surf plot of exact u1', savefig='Image/Surf of exact solution u1_P%g(mesh:%g-%g).png'% (num,nx,ny))
ev.figure()
ev.mesh(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, colorbar="on",
        title='mesh plot of exact u1', savefig='Image/Mesh of exact solution u1_P%g(mesh:%g-%g).png'% (num,nx,ny))
"""
예제 #10
0

h0 = 2277.  # Height of the top of the mountain (m)
R = 4.     # The radius of the mountain (km)

x = y = np.linspace(-10., 10., 41)
xv, yv = plt.ndgrid(x, y)             # Grid for x, y values (km)
hv = h0/(1+(xv**2+yv**2)/(R**2)) # Compute height (m)

x = y = np.linspace(-10.,10.,11)
x2v, y2v = plt.ndgrid(x, y)      # Define a coarser grid for the vector field
h2v = h0/(1+(x2v**2+y2v**2)/(R**2)) # Compute height for new grid
dhdx, dhdy = np.gradient(h2v)         # Compute the gradient vector (dh/dx,dh/dy)

# Draw contours and gradient field of h
plt.figure(9)
plt.quiver(x2v, y2v, dhdx, dhdy, 0, 'r')
plt.hold('on')
plt.contour(xv, yv, hv)
plt.axis('equal')
# end draw contours and gradient field of h

x = y = np.linspace(-5, 5, 11)
xv, yv = plt.ndgrid(x, y)
u = xv**2 + 2*yv - .5*xv*yv
v = -3*yv

# Draw 2D-field
plt.figure(10)
plt.quiver(xv, yv, u, v, 200, 'b')
plt.axis('equal')
예제 #11
0
                  axes=True,
                  basename="deflection",
                  legend="u1")
visual_ue2 = plot(u_ex[1],
                  wireframe=False,
                  title="the exact solution of u2",
                  rescale=True,
                  axes=True,
                  basename="deflection",
                  legend="u2")
visual_ue1.elevate(-65)  #tilt camera -65 degree(latitude dir)
visual_ue2.elevate(-65)  #tilt camera -65 degree(latitude dir)
visual_ue1.write_png("Image/P%gu1_exact_%gx%g.png" % (num, nx, ny))
visual_ue2.write_png("Image/P%gu2_exact_%gx%g.png" % (num, nx, ny))
interactive()
"""
u1_ex,u2_ex = u_ex.split(deepcopy = True)
u1_ex = u1_ex if u1_ex.ufl_element().degree() == 1 else \
     interpolate(u1_ex, FunctionSpace(mesh, 'Lagrange', 1))
u_box = scitools.BoxField.dolfin_function2BoxField(u1_ex, mesh, (nx,ny), uniform_mesh=True)

ev.figure()
ev.contour(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, 20, 
           savefig='Image/Contour of exact solution u1_P%g(mesh:%g-%g).png'% (num,nx,ny), title='Contour plot of exact u1',colorbar='on')
ev.figure()
ev.surf(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, shading='interp', colorbar='on', 
        title='surf plot of exact u1', savefig='Image/Surf of exact solution u1_P%g(mesh:%g-%g).png'% (num,nx,ny))
ev.figure()
ev.mesh(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values, colorbar="on",
        title='mesh plot of exact u1', savefig='Image/Mesh of exact solution u1_P%g(mesh:%g-%g).png'% (num,nx,ny))
"""
import scitools.easyviz as plt

h0 = 2277.  # Height of the top of the mountain (m)
R = 4.  # The radius of the mountain (km)

x = y = np.linspace(-10., 10., 41)
xv, yv = plt.ndgrid(x, y)
hv = h0 / (1 + (xv**2 + yv**2) / (R**2))

s = np.linspace(0, 2 * np.pi, 100)
curve_x = 10 * (1 - s / (2 * np.pi)) * np.cos(s)
curve_y = 10 * (1 - s / (2 * np.pi)) * np.sin(s)
curve_z = h0 / (1 + 100 * (1 - s / (2 * np.pi))**2 / (R**2))

# Simple plot of mountain
plt.figure(1)
plt.mesh(xv, yv, hv)

# Simple plot of mountain and parametric curve
plt.figure(2)
plt.surf(xv, yv, hv)
plt.hold('on')

# add the parametric curve. Last parameter controls color of the curve
plt.plot3(curve_x, curve_y, curve_z, 'b-')
# endsimpleplots

# Default two-dimensional contour plot
plt.figure(3)
plt.contour(xv, yv, hv)