Example #1
0
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()
Example #2
0
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()
Example #3
0
def test_plot_solution_salt_dome():
    from pygeoiga.nurb.cad import make_salt_dome
    from pygeoiga.analysis.MultiPatch import patch_topology, form_k_IGA_mp, boundary_condition_mp
    from pygeoiga.analysis.common import solve
    from pygeoiga.plot.solution_mpl import p_temperature, p_temperature_mp
    from pygeoiga.analysis.MultiPatch import map_MP_elements
    geometry = make_salt_dome(refine=True, knot_ins= [np.arange(0.2,1,0.2), np.arange(0.2,1,0.2)])
    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 = 90  # [°C]
    T_l = None#10
    T_r = None#40
    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")
    #ax.view_init(azim=270, elev=90)
    fig_sol, ax_sol = create_figure("2d")
    geometrypatch = make_salt_dome(refine=False)
    figpatch, axpatch = 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)

        axpatch = p_surface(geometrypatch[patch_id].get("knots"), geometrypatch[patch_id].get("B"), ax=axpatch, dim=2,
                       color=geometrypatch[patch_id].get("color"), alpha=0.5)
        #axpatch = p_cpoints(geometry[patch_id].get("B"), ax=axpatch, dim=2, color="black", marker=".", point=True, line=False)
        axpatch = p_knots(geometrypatch[patch_id].get("knots"), geometrypatch[patch_id].get("B"), ax=axpatch, 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_surface(geometry[patch_id].get("knots"), geometry[patch_id].get("B"), ax=ax_sol, dim=2,
                       color="k", fill=False)
        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)#, color = "k")

    fig.show()
    fig_sol.show()
    figpatch.show()

    fig_all, ax_all = create_figure("2d")
    p_temperature_mp(geometry=geometry, vmin=np.min(D), vmax=np.max(D), levels=50, show=False, colorbar=True,
                     ax=ax_all, point=False, fill=True, contour=False)
    plt.show()
Example #4
0
        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()
Example #5
0
def test_plot_solution_mp_3d():
    import matplotlib
    matplotlib.use('Qt5Agg')
    geometry = make_3_layer_patches()
    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 = lambda x, m: T_t + 10 * np.sin(np.pi * x / m)  # [°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_knots, create_figure
    fig, ax = create_figure()
    for patch_id in geometry.keys():
        ax = p_knots(geometry[patch_id].get("knots"), geometry[patch_id].get("B"),
                         color = geometry[patch_id].get("color"), ax=ax, 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 = p_temperature(x,y,t, vmin = np.min(D), vmax = np.max(D), levels=50, show=False, colorbar=True, ax=ax,
                               point = True, fill=True, color = "k")

    plt.show()
Example #6
0
    def plot_knots(self, ax=None, **kwargs_knots):
        if ax is None:
            fig, ax = create_figure("2d", figsize=(10, 20))

        ax = p_knots(self.knots,
                     self.B,
                     weight=self.weight,
                     ax=ax,
                     **kwargs_knots)
        return ax
Example #7
0
 def plot_knots(self, ax=None, **kwargs_knots):
     if ax is None:
         fig, ax = create_figure("2d", figsize=(10, 20))
     for patch_name in tqdm(self.geometry.keys(), desc="Plotting knots"):
         ax = p_knots(self.geometry[patch_name].get("knots"),
                      self.geometry[patch_name].get("B"),
                      weight=self.geometry[patch_name].get("weight"),
                      ax=ax,
                      **kwargs_knots)
     return ax
Example #8
0
    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)
Example #9
0
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)
Example #10
0
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()
Example #11
0
    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)
Example #12
0
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()
Example #13
0
def make_plot(control, knot, basis_fun, resol, positions):
    from  pygeoiga.plot.nrbplotting_mpl import p_knots
    dpi=200
    figsize=(5,6)
    fig, (cp, kn, bas) = plt.subplots(3, 1, dpi=dpi, figsize=figsize)
    bas.plot(resol, basis_fun)
    bas.spines["top"].set_visible(False)
    bas.spines["right"].set_visible(False)
    bas.set_xticks([])
    bas.set_xlim(0,1)
    bas.set_ylim(0,1)
    # bas.set_xticklabels([])
    bas.set_yticks([])
    bas.set_aspect(0.2)

    cp.plot(positions[..., 0], positions[..., 1], 'b')
    cp.plot(control[..., 0], control[..., 1], color='red', marker='s',
            linestyle='--')
    #ax.set_ylim(top=1)
    cp.axis('off')
    #cp.set_aspect(1.2)
    cp.spines["top"].set_visible(False)
    cp.spines["right"].set_visible(False)
    #for i in range(len(control)):
    #    cp.annotate("$P_{%i}$" % i, xy=(control[i, 0], control[i, 1]), xytext=(5, 0),
    #                textcoords="offset points", fontsize=15)

    kn.plot(positions[..., 0], positions[..., 1], 'b')
    kn = p_knots(knot, control[:, :3], ax=kn, point=True, line=False, dim=2, color="red")

    kn.axis('off')
    #kn.set_aspect(1.2)
    kn.spines["top"].set_visible(False)
    kn.spines["right"].set_visible(False)
    cp.set_xlim(-0.2, 5.2)
    cp.set_ylim(-0.2, 2.2)
    kn.set_xlim(-0.2, 5.2)
    kn.set_ylim(-0.2, 2.2)
    fig.subplots_adjust(wspace=0, hspace=0)
    fig.tight_layout()
    fig.show()
    return fig
Example #14
0
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 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)
Example #16
0
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)
Example #17
0
    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.spines["right"].set_visible(False)
        ax.spines["top"].set_visible(False)
        ax.set_xlabel("$x$")
        ax.set_ylabel("$y$")
        ax.set_aspect(0.8)
        ax.plot(0.7, 3, "r*", markersize=10)
        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()
        ax2.plot(0.65, 0.45, "r*", markersize=10)

        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()

        fig3, ax3 = plt.subplots()
        ax3.vlines(-1, -1, 1, 'k')
        ax3.vlines(1, -1, 1, 'k')
        ax3.hlines(-1, -1, 1, 'k')
        ax3.hlines(1, -1, 1, 'k')
        ax3.spines['left'].set_position('center')
        ax3.spines['bottom'].set_position('center')

        # Eliminate upper and right axes
        ax3.spines['right'].set_visible(False)
        ax3.spines['top'].set_visible(False)

        # Show ticks in the left and lower axes only
        ax3.xaxis.set_ticks_position('bottom')
        ax3.yaxis.set_ticks_position('left')
        ax3.set_xlabel(r"$\xi $", fontsize=15)
        ax3.set_ylabel(r"$\eta$", rotation=0, fontsize=15)
        ax3.xaxis.set_label_coords(1.05, 0.475)
        ax3.yaxis.set_label_coords(0.475, 1.05)
        ax3.set_yticks([-1, -0.5, 0.5, 1])
        ax3.set_xticks([-1, -0.5, 0.5, 1])
        ax3.set_aspect("equal")
        fig3.show()
        save = True
        if save or save_all:
            fig.savefig(fig_folder + file_name, **kwargs_savefig)
            fig2.savefig(
                fig_folder + file_name.split(".")[0] + "_parameter.pdf",
                **kwargs_savefig)
            fig3.savefig(fig_folder + file_name.split(".")[0] + "_element.pdf",
                         **kwargs_savefig)
Example #18
0
    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)
Example #19
0
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 plot_mp_FEM(geometry, a, gDoF, levels=None):
    fig_sol, [ax2, ax3] = plt.subplots(1, 2, figsize=(10, 5), sharey=True)
    xmin = 0
    xmax = 0
    ymin = 0
    ymax = 0
    cbar = True
    for patch_id in geometry.keys():
        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_sol")
        t = geometry[patch_id].get("t_sol")

        xmin = x.min() if x.min() < xmin else xmin
        xmax = x.max() if x.max() > xmax else xmax
        ymin = y.min() if y.min() < ymin else ymin
        ymax = y.max() if y.max() > ymax else ymax

        ax2 = p_temperature(x,
                            y,
                            t,
                            vmin=np.min(a),
                            vmax=np.max(a),
                            show=False,
                            colorbar=False,
                            ax=ax2,
                            point=True,
                            fill=False,
                            markersize=25)

        ax2 = p_knots(geometry[patch_id].get("knots"),
                      geometry[patch_id].get("B"),
                      ax=ax2,
                      color='k',
                      dim=2,
                      point=False,
                      line=True,
                      linestyle="--",
                      linewidth=0.2)

        ax3 = p_temperature(x,
                            y,
                            t,
                            vmin=np.min(a),
                            vmax=np.max(a),
                            levels=200,
                            show=False,
                            colorbar=cbar,
                            ax=ax3,
                            point=False,
                            fill=True,
                            contour=False)
        cbar = False

    ax2.set_title("%s DoF" % gDoF)

    for ax in ax2, ax3:
        ax.set_aspect("equal")
        ax.set_ylabel(r"$y$")
        ax.set_xlabel(r"$x$")
        ax.set_xlim(xmin, xmax)
        ax.set_ylim(ymin, ymax)

    for c in ax3.collections:
        c.set_edgecolor("face")

    for patch_id in geometry.keys():
        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_sol")
        t = geometry[patch_id].get("t_sol")

        ax3 = p_temperature(x,
                            y,
                            t,
                            vmin=np.min(a),
                            vmax=np.max(a),
                            levels=levels,
                            show=False,
                            colorbar=False,
                            colors=["black"],
                            ax=ax3,
                            point=False,
                            fill=False,
                            contour=True,
                            cmap=None,
                            linewidths=0.5)

    plt.tight_layout()
    fig_sol.show()
Example #21
0
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 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_IGA(geometry,
             a,
             gDoF,
             figsize=(5, 5),
             file_name="temp.pdf",
             save=False,
             levels=None,
             name="_"):
    from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots
    from pygeoiga.plot.solution_mpl import p_temperature, p_triangular_mesh, p_temperature_mp

    figsize = (figsize[0] * 2, figsize[1])
    fig_sol, [ax2, ax3] = plt.subplots(1, 2, figsize=figsize, sharey=True)

    xmin = 0
    xmax = 0
    ymin = 0
    ymax = 0
    cbar = True
    for patch_id in geometry.keys():
        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_sol")
        t = geometry[patch_id].get("t_sol")

        xmin = x.min() if x.min() < xmin else xmin
        xmax = x.max() if x.max() > xmax else xmax
        ymin = y.min() if y.min() < ymin else ymin
        ymax = y.max() if y.max() > ymax else ymax

        ax2 = p_temperature(x,
                            y,
                            t,
                            vmin=np.min(a),
                            vmax=np.max(a),
                            show=False,
                            colorbar=False,
                            ax=ax2,
                            point=True,
                            fill=False,
                            markersize=25)

        ax2 = p_knots(geometry[patch_id].get("knots"),
                      geometry[patch_id].get("B"),
                      ax=ax2,
                      color='k',
                      dim=2,
                      point=False,
                      line=True,
                      linestyle="--",
                      linewidth=0.2)

        ax3 = p_temperature(x,
                            y,
                            t,
                            vmin=np.min(a),
                            vmax=np.max(a),
                            levels=200,
                            show=False,
                            colorbar=cbar,
                            ax=ax3,
                            point=False,
                            fill=True,
                            contour=False)
        cbar = False

    ax2.set_title("%s DoF_%s" % (gDoF, name))

    for ax in ax2, ax3:
        ax.set_aspect("equal")
        ax.set_ylabel(r"$y$")
        ax.set_xlabel(r"$x$")
        ax.set_xlim(xmin, xmax)
        ax.set_ylim(ymin, ymax)

    for c in ax3.collections:
        c.set_edgecolor("face")

    for patch_id in geometry.keys():
        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_sol")
        t = geometry[patch_id].get("t_sol")

        ax3 = p_temperature(x,
                            y,
                            t,
                            vmin=np.min(a),
                            vmax=np.max(a),
                            levels=levels,
                            show=False,
                            colorbar=False,
                            colors=["black"],
                            ax=ax3,
                            point=False,
                            fill=False,
                            contour=True,
                            cmap=None,
                            linewidths=0.5)
    #ax3 = p_temperature_mp(geometry, vmin=np.min(a), vmax=np.max(a), levels=levels,
    #                                         show=False, colorbar=False, colors=["black"], ax=ax3,
    #                                            point=False, fill=False, contour=True, cmap=None,
    #                                            linewidths=0.5)

    plt.tight_layout()
    fig_sol.show()

    if save or save_all:
        fig_sol.savefig(fig_folder + file_name, **kwargs_savefig)
Example #24
0
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)
Example #25
0
def test_listings():
    import numpy as np
    from collections import OrderedDict

    def create_three_layer_model():
        # Lower layer control points
        bottom_c = np.array([[[0., 0., 1.], [0., 50., 1.], [0., 100., 1.]],
                             [[250., 0., 1.], [250., 180., 1.], [250., 250., 1.]],
                             [[500., 0., 1.], [500., 50., 1.], [500., 100., 1.]]])
        knot_b = ([0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1])  # knot vector (U, V)

        # Middle layer control points
        middle_c = np.array([[[0., 100., 1.], [0., 200., 1.], [0., 300., 1.]],
                             [[250., 250., 1.], [250., 380., 1.], [250., 400., 1.]],
                             [[500., 100., 1.], [500., 200., 1.], [500., 300., 1.]]])
        knot_m = ([0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1])  # knot vector (U, V)

        # Upper layer control points
        upper_c = np.array([[[0., 300., 1.], [0., 400., 1.], [0., 500., 1.]],
                            [[250., 400., 1.], [250., 450., 1.], [250., 500., 1.]],
                            [[500., 300., 1.], [500., 400., 1.], [500., 500., 1.]]])
        knot_u = ([0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1])  # knot vector (U, V)

        cpoints = [bottom_c, middle_c, upper_c]
        knots = [knot_b, knot_m, knot_u]

        geometry = OrderedDict({})
        name = ["Granite", "Mudstone", "Sandstone"]  # type of litholgy

        for i, lith in enumerate(name):
            geometry[lith] = {"B": cpoints[i], "knots": knots[i]}

        return geometry

    def assign_properties(geometry: dict):

        color = ["red", "blue", "green"]  # Assign a fixed color to the NURBS. Useful for visualization
        kappa = [3.1, 0.9, 3]  # Thermal conductivity of the layer [W/mK]
        position = [(1, 1), (2, 1), (3, 1)]  # Position of the patch in a global grid (Row and colum)
        for i, patch_name in enumerate(geometry.keys()):
            geometry[patch_name]["kappa"] = kappa[i]
            geometry[patch_name]["color"] = color[i]
            geometry[patch_name]["position"] = position[i]

        # Topology of patches -BOUNDARIES - faces of the patch in contact
        # 0: down; 1: right; 2: up; 3: left
        # Granite is in contact to mudstone in the "up" face
        geometry["Granite"]["patch_faces"] = {2: "Mudstone"}
        # Mudstone is in contact to granite in the "down" face and to sandstone in the "up" face
        geometry["Mudstone"]["patch_faces"] = {0: "Granite", 2: "Sandstone"}
        # Sandstone is in contact to mudstone in the "down" face
        geometry["Sandstone"]["patch_faces"] = {0: "Mudstone"}

        # Specify the face that have a boundary condition
        #geometry["granite"]["BC"] = {0: "bot_bc"}
        #geometry["sandstone"]["BC"] = {2: "top_bc"}

        return geometry

    def refinement(geometry: dict):
        # Knot insertion following the computational procedure of Piegl and Tille (1997)
        from pygeoiga.nurb.refinement import knot_insertion

        knot_ins_0 = np.arange(0.1, 1, 0.1)
        knot_ins_1 = np.arange(0.1, 1, 0.1)

        for count, patch_name in enumerate(geometry.keys()):
            B = geometry[patch_name].get("B")
            knots = geometry[patch_name].get("knots")

            B, knots = knot_insertion(B, degree=(2, 2), knots=knots,
                                      knots_ins=knot_ins_0, direction=0)  # U refinement
            B, knots = knot_insertion(B, degree=(2, 2), knots=knots,
                                      knots_ins=knot_ins_1, direction=1)  # V refinement

            geometry[patch_name]["B"] = B
            geometry[patch_name]["knots"] = knots

        return geometry

    def form_k_IGA(K_glb: np.ndarray,
                   IEN: np.ndarray,
                   P: list,
                   kappa: float,
                   nx: int,
                   ny: int,
                   degree: int,
                   knots: float):
        """
           Function to form the stiffness matrix
           Args:
               K_glb: empty stiffness matrix
               IEN: element topology = numbering of control points
               P: coordinates of NURBS control points x, y, z in single matrix (:,3)
               kappa: Thermal conductivity
               nx: number of elements in u direction
               ny: number of elments in v direction
               degree: polynomial order
               knots: knot vector (U, V)
           Returns:
               K -> Stiffness matrix
           """

        from pygeoiga.analysis.common import gauss_points
        from pygeoiga.analysis.iga import nurb_basis_IGA, jacobian_IGA
        # Gauss quadrature for performing numerical integration. Gauss points and weights
        G, W = gauss_points(degree)

        # Assign a value of thermal conductivity to each control point and calculate the element thermal conductivity
        #kappa_element = kappa_domain(kappa, IEN)

        # Knot vector from each parametric direction
        U = knots[0][degree:-degree]
        V = knots[1][degree:-degree]

        e = 0
        for i in range(ny):
            for j in range(nx):
                IEN_e = IEN[e]  # Element topology of current element
                eDOF = IEN_e  # Element degrees of freedom
                #kappa_e = kappa_element[e] #
                k = 0
                for g in range(len(G)):
                    # Obtain gauss points from reference element
                    xi = G[g, 0]  # Gauss point in xi direction
                    eta = G[g, 1]  # Gauss point in eta direction
                    w = W[g]  # weight of Gauss point

                    # Map Gauss points to parameter space
                    u = U[j] + (xi + 1) * (U[j + 1] - U[j]) / 2
                    v = V[i] + (eta + 1) * (V[i + 1] - V[i]) / 2

                    # Evaluate basis functions and derivatives
                    N_u, dN_u, N_v, dN_v = nurb_basis_IGA(u, v, knots=knots, degree=degree)

                    # Map of derivatives from parameter space to reference element
                    dN_xi = dN_u / 2
                    dN_eta = dN_v / 2

                    # Collect the basis functions and derivatives which support the element
                    N_u = N_u[j:j + degree + 1]
                    dN_xi = dN_xi[j:j + degree + 1]
                    N_v = N_v[i:i + degree + 1]
                    dN_eta = dN_eta[i:i + degree + 1]

                    # Calculate the Jacobian to map from the reference element to physical space
                    J, dxy = jacobian_IGA(N_u, dN_xi, N_v, dN_eta, P, IEN_e, degree)

                    # add contributions to local stiffness matrix
                    k = k + (dxy.T @ dxy) * np.linalg.det(J) * w * kappa#kappa_e
                # Add local stiffness matrix to global stiffness matrix
                K_glb[np.ix_(eDOF, eDOF)] = K_glb[np.ix_(eDOF, eDOF)] + k
                e += 1
        return K_glb

    geometry = create_three_layer_model()
    geometry = assign_properties(geometry)
    geometry = refinement(geometry)

    from pygeoiga.analysis.MultiPatch import patch_topology
    # Extract the information from each patch and create a global numbering of the multi-patch geometry.
    # The total amount of non-repeated control points will be global degrees of freedom
    geometry, gDoF = patch_topology(geometry)
    print(gDoF)

    #from pygeoiga.analysis.iga import form_k_IGA

    def assemble_stiffness_matrix(geometry: dict, gDoF: int):
        """
        Args:
            geometry: NURBS multipatch
            gDoF: Global degrees of freedom
        Return:
            K_glob: Global stiffnes matrix
        """
        # Set empty the stiffness matrix according to the global degrees of freedom
        K_glob = np.zeros((gDoF, gDoF))

        # iterate over the patches
        for patch_id in geometry.keys():
            pDof = geometry[patch_id].get("patch_DOF")  # Degrees of freedom per patch
            K = np.zeros((pDof, pDof))  # Initialize empty patch stiffness matrix

            nx, ny = geometry[patch_id].get("n_element")  # number of elements in u and v parametric coordinates
            U, V = geometry[patch_id].get("knots")  # knot vectors
            degree = geometry[patch_id].get("degree")  # degree of NURBS patch
            # Currently support only the same degree for both parametric directions
            assert degree[0] == degree[1]
            degree = degree[0]

            P = geometry[patch_id].get("list_cp")  # Get list with location of control points
            IEN = geometry[patch_id].get("IEN")  # connectivity array (element topology)
            kappa = geometry[patch_id].get("kappa")  # Patch thermal conductivity

            # create patch stiffness matrix
            K = form_k_IGA(K, IEN, P, kappa, nx, ny, degree, knots=(U, V))

            # Assemble global stiffness matrix according to global indexing
            patch_glob_num = geometry[patch_id].get("glob_num")
            K_glob[np.ix_(patch_glob_num,
                          patch_glob_num)] = K_glob[np.ix_(patch_glob_num,
                                                           patch_glob_num)] + K

        return K_glob

    K_glob = assemble_stiffness_matrix(geometry, gDoF)
    fig, ax = plt.subplots(constrained_layout=True)
    ax.spy(K_glob)
    ax.set_xlabel("Global $K$ of Anticline multi-patch geometry")
    fig.show()
    save = False
    if save or save_all:
        fig.savefig(fig_folder+"stiffnes_matrix.pdf", **kwargs_savefig)

    from pygeoiga.analysis.MultiPatch import boundary_condition_mp
    a = np.zeros(gDoF)

    T_top = 10; T_bottom = 25; T_left = None; T_right = None
    # Also possible to pass a function as
    #T_bottom = lambda x, m: 10 * np.sin(np.pi * x / m)
    # with x the position of the node and m the total number of nodes
    bc, a = boundary_condition_mp(geometry, a, T_top, T_bottom, T_left, T_right)
    bc["gDOF"] = gDoF

    from scipy.sparse.linalg import cg

    # Empty Force vector
    F = np.zeros(gDoF)

    def solve(bc: dict, K: np.ndarray, F: np.ndarray, a: np.ndarray):
        prDOF = bc.get("prDOF")  # list of indexes for control points with boundary condition
        gDOF = bc.get("gDOF")  # Degrees of freedom for the system

        # Find the active control points
        acDOF = np.setxor1d(np.arange(0, gDOF), prDOF).astype('int')

        # Reduced stiffness matrix using only active control points
        Kfs = K[np.ix_(acDOF, prDOF)]
        f = F[acDOF]
        bf_n = f - Kfs @ a[prDOF]

        # Solve for the system of equations for displacement vector
        a[acDOF], _ = cg(A=K[np.ix_(acDOF, acDOF)], b=bf_n)

        # Calculate Force vector
        F = K @ a

        return a, F

    a, F = solve(bc, K_glob, F, a)

    from pygeoiga.analysis.iga import map_solution_elements

    def map_MP_elements(geometry, a):
        for patch_id in geometry.keys():
            degree, _ = geometry[patch_id].get("degree")  # Degree of NURBS patch
            P = geometry[patch_id].get("list_cp")  # List of control points associated to the patch
            nx, ny = geometry[patch_id].get("n_element")  # number of elements in u and v diection
            n, m = geometry[patch_id].get("n_basis")  # number of basis functions in u and v direction
            ncp = n * m  # Total amount of control points
            W = geometry[patch_id].get("list_weight")  # List of weights
            knots = geometry[patch_id].get("knots")  # knot vectors in u and v
            glob_num = geometry[patch_id].get("glob_num")  # global index numbering

            a_patch = a[glob_num]  # Extract from the displacement vector the values corresponding to the patch control points
            IEN = geometry[patch_id].get("IEN")  # Connectivity array (element topology)

            # Procedure to obtain the coordinate x and y of the temperature value t
            x_temp, y_temp, t_temp = map_solution_elements(a_patch, degree, P, nx, ny, n, m, ncp, IEN, W, knots)

            geometry[patch_id]["x_sol"] = x_temp
            geometry[patch_id]["y_sol"] = y_temp
            geometry[patch_id]["t_sol"] = t_temp

        return geometry

    geometry = map_MP_elements(geometry, a)

    fig_sol, [ax1, ax2, ax3] = plt.subplots(1, 3, figsize=(15,5), sharey=True)
    from pygeoiga.plot.nrbplotting_mpl import p_surface, p_cpoints, p_knots, np
    from pygeoiga.plot.solution_mpl import  p_temperature

    for patch_id in geometry.keys():
        ax1 = 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=ax1)

        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_sol")
        t = geometry[patch_id].get("t_sol")

        ax2 = p_temperature(x, y, t, vmin=np.min(a), vmax=np.max(a), levels=100, show=False, colorbar=False,
                                 ax=ax2, point=True, fill=False, markersize=50)

        ax2 = p_knots(geometry[patch_id].get("knots"),
                     geometry[patch_id].get("B"),
                     ax=ax2,
                     color='k',
                     dim=2,
                     point=False,
                     line=True,
                      linestyle="--",
                      linewidth=0.2)
        #ax2 = p_cpoints(geometry[patch_id].get("B"), dim=2, ax=ax2, point=True, line=False)
        ax3 = p_temperature(x, y, t, vmin=np.min(a), vmax=np.max(a), levels=200, show=False, colorbar=True, ax=ax3,
                               point=False, fill=True, contour=False)

    ax1.legend(labels=list(geometry.keys()),
              handles=ax1.patches,
              loc='upper left',
            bbox_to_anchor=(0.05, .9),
             borderaxespad=0)
    ax1.set_ylabel(r"$y$")
    for ax in ax1, ax2, ax3:
        ax.set_aspect("equal")
        ax.set_xlabel(r"$x$")
        ax.set_xlim(0,500)
        ax.set_ylim(0,500)

    for c in ax3.collections:
        c.set_edgecolor("face")

    plt.tight_layout()
    fig_sol.show()

    save = False
    if save or save_all:
        fig_sol.savefig(fig_folder + "solution_anticline.pdf", **kwargs_savefig)