def test_plot_solution_bezier(): knots, B = make_surface_biquadratic() from pygeoiga.nurb.nurb_creation import NURB from pygeoiga.analysis.bezier_FE import analyze_bezier degree, n_xi, n_eta, nel, n, m, ncp, gDof, C, P, W, IEN, K, b, D, B, knots = analyze_bezier(knots, B, refine=10) kappa = 5 K = form_k(K, IEN, P, kappa, nel, degree, W, C) ############## Play with the boundary conditions T_t =None T_l = 5 T_r = 10 T_b = None #lambda x, m: T_l + 10 * np.sin(np.pi * x / m) # [°C] bc, D = boundary_condition(T_t, T_b, T_l, T_r, D, m, n, ncp) D, b = solve(bc, K, b, D) x, y, t = map_bezier_elements(D, degree, P, m,n, ncp, nel, IEN, W, C) from pygeoiga.plot.nrbplotting_mpl import p_knots, p_cpoints fig, ax = plt.subplots() ax = p_cpoints(B, ax=ax, dim=2, color="red", marker=".", markersize=5, point=True, line=False) ax = p_knots(knots, B, ax=ax, dim=2, color="black", linestyle="--", point=False, line=True) ax = p_temperature(x, y, t, levels=100, show=False, colorbar=True, ax=ax, point=True, fill=False) plt.show() fig, ax = plt.subplots() #fig, ax = create_figure() ax = p_cpoints(B, ax=ax, dim=2, color="red", marker=".", markersize=5, point=True, line=False) ax = p_knots(knots, B, ax=ax, dim=2, color="black", linestyle="--", point=False, line=True) ax = p_temperature(x, y, t, levels=100, show=False, colorbar=True, ax = ax, point = True, fill=True) plt.show()
def test_plot_solution_IGA_square(): U, V, B = make_surface_square() knots = (U,V) from pygeoiga.analysis.iga import analyze_IGA degree, n_xi, n_eta, nel, n, m, ncp, gDof, P, W, IEN, K, b, D, knots, B = analyze_IGA(knots, B, refine=10) kappa = 5 K = form_k_IGA(K, IEN, P, kappa, n_xi, n_eta, degree, knots=knots) ############## Play with the boundary conditions T_t = 10 T_b = 40 # lambda x, m: T_t + 10 * np.sin(np.pi * x / m) # [°C] T_l = None T_r = None bc, D = boundary_condition(T_t, T_b, T_l, T_r, D, m, n, ncp) D, b = solve(bc, K, b, D) x, y, t = map_solution_elements(D, degree, P, n_xi, n_eta, n, m, ncp, IEN, W, knots) from pygeoiga.plot.nrbplotting_mpl import p_knots, p_cpoints fig, ax = plt.subplots() ax = p_cpoints(B, ax=ax, dim=2, color="red", marker=".", markersize=5, point=True, line=False) ax = p_knots(knots, B, ax=ax, dim=2, color="black", linestyle="--", point=False, line=True) ax = p_temperature(x, y, t, levels=100, show=False, colorbar=True, ax=ax, point=True, fill=False) plt.show() fig, ax = plt.subplots() # fig, ax = create_figure() ax = p_cpoints(B, ax=ax, dim=2, color="red", marker=".", markersize=5, point=True, line=False) ax = p_knots(knots, B, ax=ax, dim=2, color="black", linestyle="--", point=False, line=True) ax = p_temperature(x, y, t, levels=100, show=False, colorbar=True, ax=ax, point=True, fill=True) plt.show()
def test_make_NURB_quarter_disk(): from pygeoiga.nurb.cad import quarter_disk knots, B = quarter_disk() from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface fig, [ax2, ax] = plt.subplots(1, 2, sharey=True) ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="k") ax = p_surface(knots, B, ax=ax, dim=2, color="blue", border=False, alpha=0.5) ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("x") ax.set_aspect("equal") ax2 = p_cpoints(B, ax=ax2, dim=2, color="blue", linestyle="-", point=False, line=True) ax2 = p_cpoints(B, ax=ax2, dim=2, color="red", marker="o", point=True, line=False) n, m = B.shape[0], B.shape[1] P = np.asarray([(B[x, y, 0], B[x, y, 1]) for y in range(m) for x in range(n)]) for count, point in enumerate(P): ax2.annotate(str(count), point, fontsize=8, xytext=(3, 7), textcoords="offset points") ax2.spines["right"].set_visible(False) ax2.spines["top"].set_visible(False) ax2.set_xlabel("x") ax2.set_ylabel("y") ax2.set_aspect("equal") fig.show() save = False if save or save_all: fig.savefig(fig_folder + "NURBS_surface.pdf", **kwargs_savefig)
def show_plots(): from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots import matplotlib import matplotlib.pyplot as mpl color = None mpl.close("all") figa, axa = mpl.subplots() org = False if org: image = mpl.imread( "/home/danielsk78/GitProjects/master_thesis_IGA-Geothermal-Modeling/IGA/pygeoiga/nurb/data/salt_diapir.png" ) extent = [0, 6000, 0, 3000] axa.imshow(np.flipud(image), extent=extent, origin="lower", aspect="auto") major_ticks_x = np.arange(0, extent[1] + 1, 1000) major_ticks_y = np.arange(0, extent[3] + 1, 1000) minor_ticks_x = np.arange(0, extent[1] + 1, 200) minor_ticks_y = np.arange(0, extent[3] + 1, 200) axa.set_xticks(major_ticks_x) axa.set_xticks(minor_ticks_x, minor=True) axa.set_yticks(major_ticks_y) axa.set_yticks(minor_ticks_y, minor=True) axa.grid(which='both') for i, surf in enumerate(cpoints): col = color[i] if color is not None else np.random.rand(3, ) p_surface(knots[i], surf, ax=axa, dim=2, color=col, alpha=0.5) p_cpoints(surf, ax=axa, line=False, point=True, color=col, dim=2) p_knots(knots[i], surf, ax=axa, dim=2, point=False, color=col) mpl.show() color = [ "red", "red", "red", "blue", "blue", "blue", "brown", "blue", "brown", "yellow", "blue", "yellow", "gray", "blue", "gray", "green", "green", "green" ] figs, axs = mpl.subplots() for i, surf in enumerate(cpoints): col = color[i] if color is not None else np.random.rand(3, ) p_surface(knots[i], surf, ax=axs, dim=2, color=col) #p_cpoints(surf, ax=axs, line=False, point=True, color=col, dim=2) #p_knots(knots[i], surf, ax=axs, dim=2, point=False, color=col) mpl.show()
def plot(geometry, file_name): from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots, create_figure #fig, ax = create_figure("2d") fig, ax = plt.subplots(constrained_layout=True) for patch_id in geometry.keys(): ax = p_cpoints(geometry[patch_id].get("B"), ax=ax, dim=2, color=geometry[patch_id].get("color"), marker="o", linestyle="-", point=True, line=True) P = geometry[patch_id].get("list_cp") glob_num = geometry[patch_id].get("glob_num") for count, point in enumerate(P): ax.annotate(str(glob_num[count]), point, xytext=(8, 5), textcoords="offset points") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect("equal") fig.show() save = False if save or save_all: fig.savefig(fig_folder + file_name, **kwargs_savefig)
def plot_cpoints(self, ax=None, **kwargs_cpoints): if ax is None: fig, ax = create_figure("2d", figsize=(10, 20)) for patch_name in tqdm(self.geometry.keys(), desc="Plotting control points"): ax = p_cpoints(self.geometry[patch_name].get("B"), ax=ax, **kwargs_cpoints) return ax
def plot(geometry, file_name): from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots fig, [ax2, ax] = plt.subplots(1,2,figsize=(10,4),constrained_layout=True) #fig2, ax2 = plt.subplots(constrained_layout=True) for patch_id in geometry.keys(): ax = p_knots(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax, color='k', dim=2, point=False, line=True) print(patch_id, geometry[patch_id].get("knots")) ax = p_surface(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), color=geometry[patch_id].get("color"), dim=2, fill=True, border=False, ax=ax) ax2 = p_cpoints(geometry[patch_id].get("B"), dim=2, ax=ax2, point=True, marker="o", color=geometry[patch_id].get("color"), linestyle="-", line=True) ax.legend(labels=list(geometry.keys()), handles=ax.patches, loc='upper left', bbox_to_anchor=(1., .5), borderaxespad=0) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.set_aspect("equal") ax.set_ylabel(r"$y$") ax.set_xlabel(r"$x$") ax2.spines['right'].set_visible(False) ax2.spines['top'].set_visible(False) ax2.set_aspect("equal") ax2.set_ylabel(r"$y$") ax2.set_xlabel(r"$x$") fig.show() save = False if save or save_all: fig.savefig(fig_folder + file_name, **kwargs_savefig)
def plot(geometry, file_name, c, l): from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots, create_figure #fig, ax = create_figure("2d") fig, [ax, ax2] = plt.subplots(1, 2, figsize=(10, 3)) for patch_id in geometry.keys(): ax2 = p_surface(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax2, dim=2, color=geometry[patch_id].get("color"), alpha=0.5) ax = p_cpoints(geometry[patch_id].get("B"), ax=ax, dim=2, color=geometry[patch_id].get("color"), marker="o", linestyle="-", point=True, line=True) ax2 = p_knots(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax2, dim=2, point=False, line=True, color="k") ax.set_title("Control net") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect("equal") ax2.set_title("Physical space ($x,y$)") ax2.spines["right"].set_visible(False) ax2.spines["top"].set_visible(False) ax2.set_xlabel("$x$") ax2.set_ylabel("$y$") ax2.set_aspect("equal") if c: ax2.annotate("$\Omega_1$", (70, 80), fontsize=20) ax2.annotate("$\Omega_2$", (300, 80), fontsize=20) ax2.annotate("$\Omega_3$", (100, 240), fontsize=20) c = False fig.show() save = False if save or save_all: fig.savefig(fig_folder + file_name, **kwargs_savefig)
def test_plot_solution_mp_fault(): geometry = make_fault_model(refine=True) geometry, gDoF = patch_topology(geometry) K_glob = np.zeros((gDoF, gDoF)) K_glob = form_k_IGA_mp(geometry, K_glob) D = np.zeros(gDoF) b = np.zeros(gDoF) T_t = 10 # [°C] T_b = 40 # [°C] T_l = None T_r = None bc, D = boundary_condition_mp(geometry, D, T_t, T_b, T_l, T_r) bc["gDOF"] = gDoF D, b = solve(bc, K_glob, b, D) geometry = map_MP_elements(geometry, D) from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots, create_figure fig, ax = create_figure("2d") fig_sol, ax_sol = create_figure("2d")# fig_point, ax_point = create_figure("2d") # for patch_id in geometry.keys(): ax = p_surface(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax, dim=2, color=geometry[patch_id].get("color"), alpha=0.5) ax = p_cpoints(geometry[patch_id].get("B"), ax=ax, dim=2, color="black", marker=".", point=True, line=False) ax = p_knots(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax, dim=2, point=False, line=True) #ax_sol = p_cpoints(geometry[patch_id].get("B"), ax=ax_sol, dim=2, color=geometry[patch_id].get("color"), marker=".", point=True, line=False) #ax_sol = p_knots(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), # color = geometry[patch_id].get("color"), ax=ax_sol, dim=2, point=False, line=True) x = geometry[patch_id].get("x_sol") y = geometry[patch_id].get("y_sol") t = geometry[patch_id].get("t_sol") ax_sol = p_temperature(x,y,t, vmin = np.min(D), vmax = np.max(D), levels=50, show=False, colorbar=True, ax=ax_sol, point = False, fill=True, contour=False) ax_point = p_temperature(x, y, t, vmin=np.min(D), vmax=np.max(D), levels=100, show=False, colorbar=True, ax=ax_point, point=True, fill=False) ax_sol = p_surface(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax_sol, dim=2, color="k", alpha=1, fill=False, border=True) fig.show() fig_sol.show() fig_point.show() fig_all, ax_all = create_figure("2d") p_temperature_mp(geometry=geometry, vmin=np.min(D), vmax=np.max(D), levels=200, show=False, colorbar=True, ax=ax_all, point=False, fill=True, contour=False) fig_all.show()
def test_plot_biquadratic(): from pygeoiga.nurb.cad import make_surface_biquadratic from pygeoiga.plot.nrbplotting_mpl import p_knots, create_figure, p_cpoints from pygeoiga.nurb.refinement import knot_insertion knots, cp = make_surface_biquadratic() shape = np.asarray(cp.shape) shape[-1] = cp.shape[-1] + 1 B = np.ones((shape)) B[..., :cp.shape[-1]] = cp fig, ax = create_figure("2d") ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="b") ax.set_axis_off() plt.show() direction = 0 knot_ins = np.asarray([0.2, 0.8]) B_new, knots_new = knot_insertion(B.copy(), (2, 2), knots.copy(), knot_ins, direction=direction) knot_ins = np.asarray([0.3, 0.7]) direction = 1 B_new2, knots_new2 = knot_insertion(B_new, (2, 2), knots_new, knot_ins, direction=direction) fig, ax = create_figure("2d") ax = p_knots(knots_new2, B_new2, ax=ax, dim=2, point=False, line=True, color="b") ax = p_cpoints(B_new2, ax=ax, dim=2, point=True, line=False, color="red") ax.set_axis_off() plt.show() direction = 0 knot_ins = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] B_new, knots_new = knot_insertion(B.copy(), (2, 2), knots.copy(), knot_ins, direction=direction) direction = 1 knot_ins = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] B_new2, knots_new2 = knot_insertion(B_new, (2, 2), knots_new, knot_ins, direction=direction) fig, ax = create_figure("2d") ax = p_knots(knots_new2, B_new2, ax=ax, dim=2, point=False, line=True, color="b") #ax = p_cpoints(geometry[patch_id].get("B"), ax=ax, dim=2, color="black", marker=".", point=True, line=False) ax.set_axis_off() plt.show()
def test_IEN(): from pygeoiga.nurb.cad import make_surface_biquadratic knots, B = make_surface_biquadratic() from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface fig, ax = plt.subplots() ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="k") ax = p_surface(knots, B, ax=ax, dim=2, color="blue", border=False, alpha=0.5) ax = p_cpoints(B, ax=ax, dim=2, color="red", marker="o", point=True, line=False) n, m = B.shape[0], B.shape[1] P = np.asarray([(B[x, y, 0], B[x, y, 1]) for x in range(n) for y in range(m)]) for count, point in enumerate(P): ax.annotate(str(count), point, xytext=(5, 5), textcoords="offset points") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect(0.8) fig.show()
def test_make_NURB_biquadratic(): from pygeoiga.nurb.cad import make_surface_biquadratic knots, B = make_surface_biquadratic() from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface fig, [ax2, ax] = plt.subplots(1, 2, sharey=True, figsize=(7, 3)) ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="k") ax = p_surface(knots, B, ax=ax, dim=2, color="blue", border=False, alpha=0.5) ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("x") #ax.annotate("1", (-1, 1), fontsize=20) #ax.annotate("2", (1.6, 3), fontsize=20) ax.set_aspect(0.8) ax2 = p_cpoints(B, ax=ax2, dim=2, color="blue", linestyle="-", point=False, line=True) ax2 = p_cpoints(B, ax=ax2, dim=2, color="red", marker="s", point=True, line=False) n, m = B.shape[0], B.shape[1] P = np.asarray([(B[x, y, 0], B[x, y, 1]) for x in range(n) for y in range(m)]) for count, point in enumerate(P): ax2.annotate("$P_{%s}$" % str(count), point, fontsize=8, xytext=(3, 7), textcoords="offset points") ax2.spines["right"].set_visible(False) ax2.spines["top"].set_visible(False) ax2.set_xlabel("x") ax2.set_ylabel("y") ax2.set_aspect(0.8) fig.show() from pygeoiga.engine.NURB_engine import basis_function_array_nurbs fig3 = plt.figure(constrained_layout=True) gs = fig3.add_gridspec(2, 2, hspace=0, wspace=0, width_ratios=[0.2, 1], height_ratios=[1, 0.2]) (ax_v, ax3), (no, ax_u) = gs.subplots(sharex=True, sharey=True) no.remove() N_spline_u, _ = basis_function_array_nurbs(knot_vector=knots[0], degree=2, resolution=100) N_spline_v, _ = basis_function_array_nurbs(knot_vector=knots[1], degree=2, resolution=100) resol = np.linspace(0, 1, 100) ax_u.plot(resol, N_spline_u) ax_u.spines["top"].set_visible(False) ax_u.spines["right"].set_visible(False) ax_u.set_xlim(0, 1) ax_u.set_ylim(0, 1) ax_v.plot(N_spline_v, resol) ax_v.spines["top"].set_visible(False) ax_v.spines["right"].set_visible(False) ax_v.set_yticks(knots[2:-2]) ax_v.set_xlim(1, 0) ax_v.set_ylim(0, 1) for i in knots[0]: ax3.vlines(i, 0, 1, 'k') for j in knots[1]: ax3.hlines(j, 0, 1, 'k') ax3.set_xlim(0, 1) ax3.set_ylim(0, 1) ax3.set_axis_off() ax_u.set_xlabel("$u$") ax_v.set_ylabel("$v$") ax_v.set_yticks(knots[1][2:-2]) ax_u.set_xticks(knots[0][2:-2]) for ax in ax_u, ax_v, ax3, no: ax.label_outer() fig3.show() save = True if save or save_all: fig.savefig(fig_folder + "B-spline_biquadratic.pdf", **kwargs_savefig) fig3.savefig(fig_folder + "B-spline_biquadratic_parameter.pdf", **kwargs_savefig)
def test_show_modifysimple_mesh(): from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface cp = np.array([[[0, 0], [1, 0], [2, 0], [3, 0]], [[0, 1], [1, 1], [2, 1], [3, 1]], [[0, 2], [1, 2], [2, 2], [3, 2]]]) kn1 = [0, 0, 0.5, 1, 1] kn2 = [0, 0, 1 / 3, 2 / 3, 1, 1] fig, ax = create_figure("2d") #ax.set_axis_off() ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("x") ax.set_ylabel("y") ax.set_xticks([]) ax.set_yticks([]) ax = p_knots([kn1, kn2], cp, ax=ax, dim=2, point=False, line=True, color="black") ax = p_cpoints(cp, ax=ax, dim=2, color="red", marker="o", point=True, line=False) n, m = cp.shape[0], cp.shape[1] P = np.asarray([(cp[x, y, 0], cp[x, y, 1]) for x in range(n) for y in range(m)]) for count, point in enumerate(P): ax.annotate(str(count), point, xytext=(5, 5), textcoords="offset points") ax.annotate("$\Omega_1$", (0.5, 0.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_2$", (1.5, 0.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_3$", (2.5, 0.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_4$", (0.5, 1.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_5$", (1.5, 1.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_6$", (2.5, 1.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") fig.show() cp_2 = np.array([[[0., 0.], [0.5, 0.], [1., 0.], [1.5, 0.], [2., 0.], [2.5, 0.], [3., 0.]], [[0., 0.5], [0.5, 0.5], [1., 0.5], [1.5, 0.5], [2., 0.5], [2.5, 0.5], [3., 0.5]], [[0., 1.], [0.5, 1.], [1., 1.], [1.5, 1.], [2., 1.], [2.5, 1.], [3., 1.]], [[0., 1.5], [0.5, 1.5], [1., 1.5], [1.5, 1.5], [2., 1.5], [2.5, 1.5], [3., 1.5]], [[0., 2.], [0.5, 2.], [1., 2.], [1.5, 2.], [2., 2.], [2.5, 2.], [3., 2.]]]) knots = (np.array([0., 0., 0., 0.5, 0.5, 1., 1., 1.]), np.array([ 0., 0., 0., 0.33333333, 0.33333333, 0.66666667, 0.66666667, 1., 1., 1. ])) fig2, ax2 = create_figure("2d") #ax2.set_axis_off() ax2.spines["right"].set_visible(False) ax2.spines["top"].set_visible(False) ax2.set_xlabel("x") ax2.set_ylabel("y") ax2.set_xticks([]) ax2.set_yticks([]) ax2 = p_knots(knots, cp_2, ax=ax2, dim=2, point=False, line=True, color="black") ax2 = p_cpoints(cp_2, ax=ax2, dim=2, color="red", marker="o", point=True, line=False) n, m = cp_2.shape[0], cp_2.shape[1] P = np.asarray([(cp_2[x, y, 0], cp_2[x, y, 1]) for x in range(n) for y in range(m)]) for count, point in enumerate(P): ax2.annotate(str(count), point, xytext=(5, 5), textcoords="offset points") disp = (28, 30) ax2.annotate("$\Omega_1$", (0.5, 0.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_2$", (1.5, 0.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_3$", (2.5, 0.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_4$", (0.5, 1.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_5$", (1.5, 1.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_6$", (2.5, 1.5), fontsize=20, xytext=disp, textcoords="offset points") fig2.show() save = True if save or save_all: fig.savefig(fig_folder + "mesh_1degree.pdf", **kwargs_savefig) fig2.savefig(fig_folder + "mesh_2degree.pdf", **kwargs_savefig)
def plot_cpoints(self, ax=None, **kwargs_cpoints): if ax is None: fig, ax = create_figure("2d", figsize=(10, 20)) ax = p_cpoints(self.B, ax=ax, **kwargs_cpoints) return ax
def test_show_simple_mesh_IGA(): from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface cp = np.array([[[0, 0], [3, 0]], [[0, 2], [3, 2]]]) kn1 = [0, 0, 1, 1] kn2 = [0, 0, 1, 1] knots = [kn1, kn2] shape = np.asarray(cp.shape) shape[-1] = 3 # To include the weights in the last term B = np.ones(shape) B[..., :2] = cp from pygeoiga.nurb.refinement import knot_insertion B, knots = knot_insertion(B, [1, 1], knots, [0.5], 0) B, knots = knot_insertion(B, [1, 1], knots, [1 / 3, 2 / 3], 1) fig, ax = create_figure("2d") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("x") ax.set_ylabel("y") ax.set_xticks([]) ax.set_yticks([]) ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="black") ax = p_cpoints(B, ax=ax, dim=2, color="red", marker="o", point=True, line=False) n, m = B.shape[0], B.shape[1] P = np.asarray([(B[x, y, 0], B[x, y, 1]) for x in range(n) for y in range(m)]) for count, point in enumerate(P): ax.annotate(str(count), point, xytext=(5, 5), textcoords="offset points") ax.annotate("$\Omega_1$", (0.5, 0.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_2$", (1.5, 0.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_3$", (2.5, 0.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_4$", (0.5, 1.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_5$", (1.5, 1.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") ax.annotate("$\Omega_6$", (2.5, 1.5), fontsize=20, xytext=(-5, -5), textcoords="offset points") fig.show() knots = [kn1, kn2] shape = np.asarray(cp.shape) shape[-1] = 3 # To include the weights in the last term B = np.ones(shape) B[..., :2] = cp from pygeoiga.nurb.refinement import degree_elevation B, knots = degree_elevation(B, knots, direction=0) B, knots = degree_elevation(B, knots, direction=1) from pygeoiga.nurb.refinement import knot_insertion B, knots = knot_insertion(B, [2, 2], knots, [0.5], 0) B, knots = knot_insertion(B, [2, 2], knots, [1 / 3, 2 / 3], 1) fig2, ax2 = create_figure("2d") # ax2.set_axis_off() ax2.spines["right"].set_visible(False) ax2.spines["top"].set_visible(False) ax2.set_xlabel("x") ax2.set_ylabel("y") ax2.set_xticks([]) ax2.set_yticks([]) ax2 = p_knots(knots, B, ax=ax2, dim=2, point=False, line=True, color="black") ax2 = p_cpoints(B, ax=ax2, dim=2, color="red", marker="o", point=True, line=False) n, m = B.shape[0], B.shape[1] P = np.asarray([(B[x, y, 0], B[x, y, 1]) for x in range(n) for y in range(m)]) for count, point in enumerate(P): ax2.annotate(str(count), point, xytext=(5, 5), textcoords="offset points") disp = (28, 30) ax2.annotate("$\Omega_1$", (0.5, 0.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_2$", (1.5, 0.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_3$", (2.5, 0.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_4$", (0.5, 1.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_5$", (1.5, 1.5), fontsize=20, xytext=disp, textcoords="offset points") ax2.annotate("$\Omega_6$", (2.5, 1.5), fontsize=20, xytext=disp, textcoords="offset points") fig2.show() save = True if save or save_all: fig.savefig(fig_folder + "NURB_mesh_1_degree.pdf", **kwargs_savefig) fig2.savefig(fig_folder + "NURB_mesh_2_degree.pdf", **kwargs_savefig)
def plot(B, knots, file_name): from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface fig, [ax2, ax] = plt.subplots(1, 2, figsize=(10, 5), constrained_layout=True) ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="k") ax = p_surface(knots, B, ax=ax, dim=2, color="blue", border=False, alpha=0.5) ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect(0.8) ax2 = p_cpoints(B, ax=ax2, dim=2, color="blue", linestyle="-", point=False, line=True) ax2 = p_cpoints(B, ax=ax2, dim=2, color="red", marker="o", point=True, line=False) n, m = B.shape[0], B.shape[1] ax2.spines["right"].set_visible(False) ax2.spines["top"].set_visible(False) ax2.set_xlabel("$x$") ax2.set_ylabel("$y$", rotation=90) ax2.set_aspect(0.8) ax.set_title("Physical space ($x,y$)", fontsize=20) ax2.set_title("Control net", fontsize=20) fig.tight_layout(pad=0, h_pad=0, w_pad=0) fig.show() from pygeoiga.engine.NURB_engine import basis_function_array_nurbs fig3 = plt.figure(constrained_layout=True) gs = fig3.add_gridspec(2, 2, hspace=0, wspace=0, width_ratios=[0.2, 1], height_ratios=[1, 0.2]) (ax_v, ax3), (no, ax_u) = gs.subplots(sharex=True, sharey=True) no.remove() N_spline_u, _ = basis_function_array_nurbs(knot_vector=knots[0], degree=2, resolution=100) N_spline_v, _ = basis_function_array_nurbs(knot_vector=knots[1], degree=2, resolution=100) resol = np.linspace(0, 1, 100) ax_u.plot(resol, N_spline_u) ax_u.spines["top"].set_visible(False) ax_u.spines["right"].set_visible(False) ax_u.set_xlim(0, 1) ax_u.set_ylim(0, 1) ax_v.plot(N_spline_v, resol) ax_v.spines["top"].set_visible(False) ax_v.spines["right"].set_visible(False) ax_v.set_yticks(knots[2:-2]) ax_v.set_xlim(1, 0) ax_v.set_ylim(0, 1) for i in knots[0]: ax3.vlines(i, 0, 1, 'k') for j in knots[1]: ax3.hlines(j, 0, 1, 'k') ax3.set_xlim(0, 1) ax3.set_ylim(0, 1) ax3.set_axis_off() ax3.set_title("Parametric space ($u,v$)", fontsize=20) ax_u.set_xlabel("$u$") ax_v.set_ylabel("$v$") ax_v.set_yticks(knots[1][2:-2]) ax_u.set_xticks(knots[0][2:-2]) for ax in ax_u, ax_v, ax3, no: ax.label_outer() fig3.show() save = False if save or save_all: fig.savefig(fig_folder + file_name, **kwargs_savefig) fig3.savefig( fig_folder + file_name.split(".")[0] + "_parameter.pdf", **kwargs_savefig)
def test_explicit_model(): import matplotlib from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface img = matplotlib.image.imread('dike.jpg') fig, ax = plt.subplots() ax.imshow(img, alpha=.8, extent=(0, 300, 0, 178)) ax.set_aspect("equal") ax.set_xlabel("x (m)") ax.set_ylabel("y (m)") ### Big dike cp_1 = np.array([[[223, 0], [145, 60], [108, 90], [71, 149]], [[300, 0], [300, 4.5], [141, 111], [104, 159]]]) kn1_1 = [0, 0, 1, 1] kn1_2 = [0, 0, 0.3, 0.6, 1, 1] knots_1 = [kn1_1, kn1_2] ax = p_cpoints(cp_1, ax=ax, dim=2, color="black", marker="s", point=True, line=False) ax = p_knots(knots_1, cp_1, ax=ax, dim=2, point=True, line=True) ### middle dike cp_2 = np.array([[[0, 40], [92, 86], [197, 154], [300, 178]], [[0, 94], [80, 120], [91, 144], [204, 178]]]) kn2_1 = [0, 0, 1, 1] kn2_2 = [0, 0, 0.3, 0.6, 1, 1] knots_2 = [kn2_1, kn2_2] ax = p_cpoints(cp_2, ax=ax, dim=2, color="black", marker="s", point=True, line=False) ax = p_knots(knots_2, cp_2, ax=ax, dim=2, point=True, line=True) ### Weathered dike cp_3 = np.array([[[0, 94], [90, 100], [91, 144], [204, 178]], [[0, 100], [80, 150], [91, 160], [204, 178]], [[0, 178], [80, 178], [142, 178], [204, 178]]]) kn3_1 = [0, 0, 0, 1, 1, 1] kn3_2 = [0, 0, 0, 0.5, 1, 1, 1] knots_3 = [kn3_1, kn3_2] ax = p_cpoints(cp_3, ax=ax, dim=2, color="black", marker="s", point=True, line=False) ax = p_knots(knots_3, cp_3, ax=ax, dim=2, point=True, line=True) ### Bottom cp_4 = np.array([[[0, 40], [92, 86], [197, 154], [300, 178]], [[0, 0], [92, 0], [197, 0], [300, 0]]]) kn4_1 = [0, 0, 1, 1] kn4_2 = [0, 0, 0.3, 0.6, 1, 1] knots_4 = [kn4_1, kn4_2] ax = p_cpoints(cp_4, ax=ax, dim=2, color="black", marker="s", point=True, line=False) ax = p_knots(knots_4, cp_4, ax=ax, dim=2, point=True, line=True) ax.set_xlim(0, 300) ax.set_ylim(0, 178) fig.show() fig2, ax2 = create_figure("2d") p_surface(knots_4, cp_4, ax=ax2, dim=2, color="red", border=False, label="Dike1") p_surface(knots_2, cp_2, ax=ax2, dim=2, color="blue", border=False, label="Dike2") p_surface(knots_1, cp_1, ax=ax2, dim=2, color="yellow", border=False, label="Dike3") p_surface(knots_3, cp_3, ax=ax2, dim=2, color="gray", border=False, label="Unknown") ax2.set_xlim(0, 300) ax2.set_ylim(0, 178) ax2.set_aspect("equal") ax2.set_xlabel("x (m)") ax2.set_ylabel("y (m)") ax2.legend(loc="center right", facecolor='white', framealpha=0.8) fig2.show() fig3, ax3 = create_figure("2d") ax3.imshow(img, alpha=.8, extent=(0, 300, 0, 178)) #p_surface(knots_4, cp_4, ax=ax3, dim=2, color="red", fill=False, label="Dike1") #p_surface(knots_2, cp_2, ax=ax3, dim=2, color="blue", fill=False, label="Dike2") #p_surface(knots_1, cp_1, ax=ax3, dim=2, color="yellow", fill=False, label="Dike3") #p_surface(knots_3, cp_3, ax=ax3, dim=2, color="gray", fill=False, label="Unknown") ax3.set_xlim(0, 300) ax3.set_ylim(0, 178) ax3.set_aspect("equal") ax3.set_xlabel("x (m)") ax3.set_ylabel("y (m)") #ax3.legend(loc="center right") fig3.show() save = False if save or save_all: fig2.savefig(fig_folder + "model_explicit.pdf", **kwargs_savefig) fig3.savefig(fig_folder + "original_explicit.pdf", **kwargs_savefig)
def test_image_example2(): from pygeoiga.nurb.cad import make_surface_biquadratic knots, B = make_surface_biquadratic() from pygeoiga.nurb.refinement import knot_insertion knot_ins_1 = [0.3, 0.6] knot_ins_0 = [0.25, 0.75] B, knots = knot_insertion(B, (2, 2), knots, knot_ins_0, direction=0) B, knots = knot_insertion(B, (2, 2), knots, knot_ins_1, direction=1) before = B from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface from pygeoiga.engine.NURB_engine import basis_function_array_nurbs fig = plt.figure(constrained_layout=True) gs = fig.add_gridspec(3, 3, hspace=0, wspace=0, width_ratios=[0.2, 0.2, 1], height_ratios=[1, 0.2, 0.2]) (ax_bv, ax_v, ax2), (no1, no2, ax_u), (no3, no4, ax_bu) = gs.subplots(sharex=True, sharey=True) for no in no1, no2, no3, no4: no.remove() N_spline_u, _ = basis_function_array_nurbs(knot_vector=knots[0], degree=2, resolution=100) N_spline_v, _ = basis_function_array_nurbs(knot_vector=knots[1], degree=2, resolution=100) resol = np.linspace(0, 1, 100) ax_u.plot(resol, N_spline_u) ax_u.spines["top"].set_visible(False) ax_u.spines["right"].set_visible(False) ax_u.set_xlim(0, 1) ax_u.set_ylim(0, 1) ax_v.plot(N_spline_v, resol) ax_v.spines["top"].set_visible(False) ax_v.spines["right"].set_visible(False) ax_v.set_yticks(knots[2:-2]) ax_v.set_xlim(0, 1) ax_v.set_ylim(0, 1) ax_u.set_xlabel("$u$") ax_v.set_ylabel("$v$") ax_v.set_xlabel("$N(v)$") ax_u.set_ylabel("$N(u)$") ax_v.set_yticks(knots[1][2:-2]) ax_u.set_xticks(knots[0][2:-2]) for i in knots[0]: ax2.vlines(i, 0, 1, 'k') for j in knots[1]: ax2.hlines(j, 0, 1, 'k') ax2.set_xlim(0, 1) ax2.set_ylim(0, 1) ax2.set_axis_off() fig2, ax = plt.subplots(constrained_layout=True) ax = p_cpoints(B, ax=ax, dim=2, point=False, line=True, color="black", linestyle="-") ax = p_cpoints(B, ax=ax, dim=2, point=True, line=False, color="red") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect(0.8) fig2.tight_layout(pad=0, h_pad=0, w_pad=0) fig2.show() from pygeoiga.nurb.refinement import knot_insertion knot_ins_1 = [0.3, 0.6] knot_ins_0 = [0.25, 0.5, 0.75] B, knots = knot_insertion(B, (2, 2), knots, knot_ins_0, direction=0) B, knots = knot_insertion(B, (2, 2), knots, knot_ins_1, direction=1) new = B N_spline_u, _ = basis_function_array_nurbs(knot_vector=knots[0], degree=2, resolution=100) N_spline_v, _ = basis_function_array_nurbs(knot_vector=knots[1], degree=2, resolution=100) resol = np.linspace(0, 1, 100) ax_bu.plot(resol, N_spline_u) ax_bu.spines["top"].set_visible(False) ax_bu.spines["right"].set_visible(False) ax_bu.set_xlim(0, 1) ax_bu.set_ylim(0, 1) ax_bv.plot(N_spline_v, resol) ax_bv.spines["top"].set_visible(False) ax_bv.spines["right"].set_visible(False) ax_bv.set_yticks(knots[2:-2]) ax_bv.set_xlim(0, 1) ax_bv.set_ylim(0, 1) ax_bu.set_xlabel("$u$") ax_bv.set_ylabel("$v$") ax_bv.set_xlabel("$B(v)$") ax_bu.set_ylabel("$B(u)$") ax_bv.set_yticks(knots[1][2:-2]) ax_bu.set_xticks(knots[0][2:-2]) #for ax in ax_u, ax_v, ax2, no, ax_bu, ax_bv: # ax.label_outer() fig2.show() degree_u = len(np.where(knots[0] == 0.)[0]) - 1 degree_v = len(np.where(knots[1] == 0.)[0]) - 1 n_xi = len(knots[0]) - degree_u - 3 n_eta = len(knots[1]) - degree_v - 3 from pygeoiga.analysis.common import IEN_element_topology, transform_matrix_B IEN = IEN_element_topology(n_xi, n_eta, degree_u) P, W = transform_matrix_B(B) fig3, ax = plt.subplots(constrained_layout=True) for i in range(0, n_xi, 2): pos = IEN[i::n_xi] for e in pos[::2]: # cont = np.hstack([IEN[0][:degree_u+1], IEN[0][degree_u+3], np.flip(IEN[0][-degree_u-1:]), IEN[0][degree_u+1], IEN[0][0]]) cont = np.hstack([ e[:degree_u + 1], e[degree_u + 3], np.flip(e[-degree_u - 1:]), e[degree_u + 1], e[0] ]) ax.plot(P[cont][:, 0], P[cont][:, 1], linestyle="-", color="black", marker=None) ax = p_cpoints(B, ax=ax, dim=2, point=True, line=False, color="red") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect(0.8) fig3.tight_layout(pad=0, h_pad=0, w_pad=0) fig.show() fig2.show() fig3.show() fig_0, ax = plt.subplots(constrained_layout=True) ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="k") ax = p_surface(knots, B, ax=ax, dim=2, fill=True, border=False, color="gray", alpha=0.5) ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect(0.8) fig_0.tight_layout(pad=0, h_pad=0, w_pad=0) fig_0.show() save = False if save or save_all: fig.savefig(fig_folder + "bezier_extraction.pdf", **kwargs_savefig) fig_0.savefig(fig_folder + "curve_original.pdf", **kwargs_savefig) fig2.savefig(fig_folder + "control_original.pdf", **kwargs_savefig) fig3.savefig(fig_folder + "control_bezier.pdf", **kwargs_savefig)
def plot(B, knots, file_name): from pygeoiga.plot.nrbplotting_mpl import create_figure, p_cpoints, p_knots, p_curve, p_surface fig, ax = plt.subplots(constrained_layout=True) ax = p_knots(knots, B, ax=ax, dim=2, point=False, line=True, color="k") ax = p_cpoints(B, ax=ax, dim=2, point=True, line=True, color="red") ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_aspect(0.8) fig.tight_layout(pad=0, h_pad=0, w_pad=0) fig.show() from pygeoiga.engine.NURB_engine import basis_function_array_nurbs fig2 = plt.figure(constrained_layout=True) gs = fig2.add_gridspec(2, 2, hspace=0, wspace=0, width_ratios=[0.2, 1], height_ratios=[1, 0.2]) (ax_v, ax2), (no, ax_u) = gs.subplots(sharex=True, sharey=True) no.remove() N_spline_u, _ = basis_function_array_nurbs(knot_vector=knots[0], degree=2, resolution=100) N_spline_v, _ = basis_function_array_nurbs(knot_vector=knots[1], degree=2, resolution=100) resol = np.linspace(0, 1, 100) ax_u.plot(resol, N_spline_u) ax_u.spines["top"].set_visible(False) ax_u.spines["right"].set_visible(False) ax_u.set_xlim(0, 1) ax_u.set_ylim(0, 1) ax_v.plot(N_spline_v, resol) ax_v.spines["top"].set_visible(False) ax_v.spines["right"].set_visible(False) ax_v.set_yticks(knots[2:-2]) ax_v.set_xlim(1, 0) ax_v.set_ylim(0, 1) for i in knots[0]: ax2.vlines(i, 0, 1, 'k') for j in knots[1]: ax2.hlines(j, 0, 1, 'k') ax2.set_xlim(0, 1) ax2.set_ylim(0, 1) ax2.set_axis_off() ax_u.set_xlabel("$u$") ax_v.set_ylabel("$v$") ax_v.set_yticks(knots[1][2:-2]) ax_u.set_xticks(knots[0][2:-2]) for ax in ax_u, ax_v, ax2, no: ax.label_outer() fig2.show() save = False if save or save_all: fig2.savefig(fig_folder + file_name, **kwargs_savefig)