Example #1
0
file << u0

# Plot mesh
# 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, 
Example #2
0
# Note: avoid * import from easyviz as DOLFIN and has already
# defined plot, figure, mesh

u2 = u if u.ufl_element().degree() == 1 else \
     interpolate(u, FunctionSpace(mesh, 'Lagrange', 1))
# alternatively: interpolate onto a finer mesh for higher degree elements
u_box = scitools.BoxField.dolfin_function2BoxField(
        u2, 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
start = (0,0.5)
x, uval, y_fixed, snapped = u_box.gridline(start, direction=X)
if snapped:
    print('Line at %s adjusted (snapped) to y=%g' % (start, y_fixed))
ev.figure()
Example #3
0
u2 = u if u.ufl_element().degree() == 1 else \
     interpolate(u, FunctionSpace(mesh, 'Lagrange', 1))
# alternatively: interpolate onto a finer mesh for higher degree elements
u_box = scitools.BoxField.dolfin_function2BoxField(u2,
                                                   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,
Example #4
0
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')
# end draw 2D-field

plt.figure(9)
Example #5
0
# 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))
# 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)

# Default three-dimensional contour plot
plt.figure(4)
plt.contour3(xv, yv, hv, 10)

# 10 contour lines (equally spaced contour levels)
plt.figure(5)
plt.contour(xv, yv, hv, 10)

# 10 black ('k') contour lines
plt.figure(6)
plt.contour(xv, yv, hv, 10, 'k')

# Specify the contour levels explicitly as a list
plt.figure(7)
visual_u.write_png("Image/P%g_u_%gx%g"%(nz,nx,ny))
visual_u1.elevate(-65) #tilt camera -65 degree(latitude dir)
visual_u2.elevate(-65)
visual_u1.write_png("Image/P%g_u1_%gx%g.png"%(nz,nx,ny))
visual_u2.write_png("Image/P%g_u2_%gx%g.png"%(nz,nx,ny))

# Plot exact solution 
visual_ue1 = plot(u_ex[0],title="the exact solution of u1",rescale = True , axes = True, basename = "deflection" ,legend ="u1")
visual_ue2 = plot(u_ex[1],wireframe = True,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"%(nz,nx,ny))
visual_ue2.write_png("Image/P%gu2_exact_%gx%g.png"%(nz,nx,ny))
#interactive()

"""
# Plot with scitools
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))
Example #8
0
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')
# end draw 2D-field

Example #9
0
                 basename="deflection",
                 legend="u1")
visual_u2 = plot(u0[1],
                 wireframe=False,
                 title="the approximation of u2",
                 rescale=True,
                 axes=True,
                 basename="deflection",
                 legend="u2")
visual_mesh.write_png("Image/P%g_mesh_%gx%g.png" % (num, nx, ny))
visual_u.write_png("Image/P%g_u_%gx%g" % (num, nx, ny))
visual_u1.elevate(-65)  #tilt camera -65 degree(latitude dir)
visual_u2.elevate(-65)
visual_u1.write_png("Image/P%g_u1_%gx%g.png" % (num, nx, ny))
visual_u2.write_png("Image/P%g_u2_%gx%g.png" % (num, nx, ny))
"""
X = 0; Y = 1;
u1,u2 = u0.split(deepcopy = True)

us = u0[0] 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'% (num,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'% (num,nx,ny))
ev.figure()
ev.mesh(u_box.grid.coorv[X], u_box.grid.coorv[Y], u_box.values,colorbar='on',shading='interp',
# 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)

# Default three-dimensional contour plot
plt.figure(4)
plt.contour3(xv, yv, hv, 10)

# 10 contour lines (equally spaced contour levels)
plt.figure(5)
plt.contour(xv, yv, hv, 10)

# 10 black ('k') contour lines
plt.figure(6)
plt.contour(xv, yv, hv, 10, 'k')

# Specify the contour levels explicitly as a list
plt.figure(7)