def fe_basis_function_figure(d, target_elm=[1], N_e=3, derivative=0, filename='tmp.pdf', labels=False): """ Draw all basis functions (or their derivative), of degree d, associated with element target_elm (may be list of elements). Add a mesh with N_e elements. """ nodes, elements = mesh_uniform(N_e, d) """ x = 1.1 print locate_element_vectorized(x, elements, nodes) print locate_element_scalar(x, elements, nodes) x = 0.1, 0.4, 0.8 print locate_element_vectorized(x, elements, nodes) """ if isinstance(target_elm, int): target_elm = [target_elm] # wrap in list # Draw the basis functions for element 1 colors = ['r-2', 'b-2', 'g-2', 'y-2', 'k-2', 'c-2'] color_counter = 0 phi_drawn = [] # list of already drawn phi functions ymin = ymax = 0 for e in target_elm: for i in elements[e]: if not i in phi_drawn: x, y = phi_glob(i, elements, nodes, derivative=derivative) if x is None and y is None: return # abort ymax = max(ymax, max(y)) ymin = min(ymin, min(y)) plt.plot(x, y, colors[color_counter]) color_counter += 1 if color_counter > len(colors) - 1: color_counter = 0 # restart colors if labels: if derivative == 0: plt.legend(r'\varphi_%d' % i, loc='upper right') else: plt.legend(r"\varphi_%d'(x)" % i, loc='upper right') phi_drawn.append(i) #plt.axis([nodes[0], nodes[-1], ymin-0.1, ymax+0.1]) plot_fe_mesh(nodes, elements, element_marker=[ymin - 0.1, ymax + 0.1]) plt.plot([0, 0], [0, 0], '-') plt.axis([nodes[0], nodes[-1], ymin - 0.1, ymax + 0.1]) #plt.axes.set_aspect('') #plt.daspect([0.2, 1, 1]) #plt.daspactmode('manual') plt.savefig(filename)
def fe_basis_function_figure(d, target_elm=[1], N_e=3, derivative=0, filename='tmp.pdf', labels=False): """ Draw all basis functions (or their derivative), of degree d, associated with element target_elm (may be list of elements). Add a mesh with N_e elements. """ nodes, elements = mesh_uniform(N_e, d) """ x = 1.1 print locate_element_vectorized(x, elements, nodes) print locate_element_scalar(x, elements, nodes) x = 0.1, 0.4, 0.8 print locate_element_vectorized(x, elements, nodes) """ if isinstance(target_elm, int): target_elm = [target_elm] # wrap in list # Draw the basis functions for element 1 phi_drawn = [] # list of already drawn phi functions ymin = ymax = 0 for e in target_elm: for i in elements[e]: if not i in phi_drawn: x, y = phi_glob(i, elements, nodes, derivative=derivative) if x is None and y is None: return # abort ymax = max(ymax, max(y)) ymin = min(ymin, min(y)) plt.plot(x, y, '-') plt.hold('on') if labels: if plt.backend == 'gnuplot': if derivative == 0: plt.legend(r'basis func. %d' % i) else: plt.legend(r'derivative of basis func. %d' % i) elif plt.backend == 'matplotlib': if derivative == 0: plt.legend(r'\varphi_%d' % i) else: plt.legend(r"\varphi_%d'(x)" % i) phi_drawn.append(i) plt.axis([nodes[0], nodes[-1], ymin - 0.1, ymax + 0.1]) plot_fe_mesh(nodes, elements, element_marker=[ymin - 0.1, ymax + 0.1]) plt.hold('off') plt.savefig(filename)
def fe_basis_function_figure(d, target_elm=[1], n_e=3, derivative=0, filename='tmp.pdf', labels=False): """ Draw all basis functions (or their derivative), of degree d, associated with element target_elm (may be list of elements). Add a mesh with n_e elements. """ nodes, elements = mesh_uniform(n_e, d) """ x = 1.1 print locate_element_vectorized(x, elements, nodes) print locate_element_scalar(x, elements, nodes) x = 0.1, 0.4, 0.8 print locate_element_vectorized(x, elements, nodes) """ if isinstance(target_elm, int): target_elm = [target_elm] # wrap in list # Draw the basis functions for element 1 phi_drawn = [] # list of already drawn phi functions ymin = ymax = 0 for e in target_elm: for i in elements[e]: if not i in phi_drawn: x, y = phi_glob(i, elements, nodes, derivative=derivative) if x is None and y is None: return # abort ymax = max(ymax, max(y)) ymin = min(ymin, min(y)) plt.plot(x, y, '-') plt.hold('on') if labels: if plt.backend == 'gnuplot': if derivative == 0: plt.legend(r'basis function no. %d' % i) else: plt.legend(r'derivative of basis function no. %d' % i) elif plt.backend == 'matplotlib': if derivative == 0: plt.legend(r'\varphi_%d' % i) else: plt.legend(r"\varphi_%d'(x)" % i) phi_drawn.append(i) plt.axis([nodes[0], nodes[-1], ymin-0.1, ymax+0.1]) plot_fe_mesh(nodes, elements, element_marker=[ymin-0.1, ymax+0.1]) plt.hold('off') plt.savefig(filename)