def u_P1(): """ Plot P1 basis functions and a resulting u to illustrate what it means to use finite elements. """ import matplotlib.pyplot as plt x = [0, 1.5, 2.5, 3.5, 4] phi = [np.zeros(len(x)) for i in range(len(x)-2)] for i in range(len(phi)): phi[i][i+1] = 1 #u = 5*x*np.exp(-0.25*x**2)*(4-x) u = [0, 8, 5, 4, 0] for i in range(len(phi)): plt.plot(x, phi[i], 'r-') #, label=r'$\varphi_%d$' % i) plt.text(x[i+1], 1.2, r'$\varphi_%d$' % i) plt.plot(x, u, 'b-', label='$u$') plt.legend(loc='upper left') plt.axis([0, x[-1], 0, 9]) plt.savefig('tmp_u_P1.png') plt.savefig('tmp_u_P1.pdf') # Mark elements for xi in x[1:-1]: plt.plot([xi, xi], [0, 9], 'm--') # Mark nodes #plt.plot(x, np.zeros(len(x)), 'ro', markersize=4) plt.savefig('tmp_u_P1_welms.png') plt.savefig('tmp_u_P1_welms.pdf') plt.show()
def u_P1(): """ Plot P1 basis functions and a resulting u to illustrate what it means to use finite elements. """ import matplotlib.pyplot as plt x = [0, 1.5, 2.5, 3.5, 4] phi = [np.zeros(len(x)) for i in range(len(x)-2)] for i in range(len(phi)): phi[i][i+1] = 1 #u = 5*x*np.exp(-0.25*x**2)*(4-x) u = [0, 8, 5, 4, 0] for i in range(len(phi)): plt.plot(x, phi[i], 'r-') #, label=r'$\varphi_%d$' % i) plt.text(x[i+1], 1.2, r'$\varphi_%d$' % i) plt.plot(x, u, 'b-', label='$u$') plt.legend(loc='upper left') plt.axis([0, x[-1], 0, 9]) plt.savefig('u_example_P1.png') plt.savefig('u_example_P1.pdf') # Mark elements for xi in x[1:-1]: plt.plot([xi, xi], [0, 9], 'm--') # Mark nodes #plt.plot(x, np.zeros(len(x)), 'ro', markersize=4) plt.savefig('u_example_P1_welms.png') plt.savefig('u_example_P1_welms.pdf') plt.show()
def plot_boundaries(outer_boundary, inner_boundaries=[], marked_points=None): if not isinstance(inner_boundaries, (tuple, list)): inner_boundaries = [inner_boundaries] boundaries = [outer_boundary] boundaries.extend(inner_boundaries) # Find max/min of plotting area plot_area = [ min([b.x.min() for b in boundaries]), max([b.x.max() for b in boundaries]), min([b.y.min() for b in boundaries]), max([b.y.max() for b in boundaries]), ] aspect = (plot_area[3] - plot_area[2]) / (plot_area[1] - plot_area[0]) for b in boundaries: plot(b.x, b.y, daspect=[aspect, 1, 1], daspectratio="manual") hold("on") axis(plot_area) title("Specification of domain with %d boundaries" % len(boundaries)) if marked_points: for pt, name in marked_points: text(pt[0], pt[1], name)
def plot_boundaries(outer_boundary, inner_boundaries=[], marked_points=None): if not isinstance(inner_boundaries, (tuple, list)): inner_boundaries = [inner_boundaries] boundaries = [outer_boundary] boundaries.extend(inner_boundaries) # Find max/min of plotting area plot_area = [ min([b.x.min() for b in boundaries]), max([b.x.max() for b in boundaries]), min([b.y.min() for b in boundaries]), max([b.y.max() for b in boundaries]) ] aspect = (plot_area[3] - plot_area[2]) / (plot_area[1] - plot_area[0]) for b in boundaries: plot(b.x, b.y, daspect=[aspect, 1, 1], daspectratio='manual') hold('on') axis(plot_area) title('Specification of domain with %d boundaries' % len(boundaries)) if marked_points: for pt, name in marked_points: text(pt[0], pt[1], name)