Exemple #1
0
def test_plot_field_iga_salt():
    geometry = make_salt_dome(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 = 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.analysis.MultiPatch import point_solution_mp
    x = np.arange(0, 6000, 200)
    y = np.arange(0, 3000, 200)
    x = x[1:-1]
    y = y[1:-1]
    xx, yy = np.meshgrid(x,y)
    tt = np.empty(xx.shape)
    for i in range(len(x)):
        for j in range(len(y)):
            tt[i,j] = point_solution_mp(xx[i,j], yy[i,j], geometry)
    #tt = point_solution_mp(xx,yy,geometry)
    plt.imshow(tt, cmap="viridis", origin="lower")
    plt.colorbar()
    plt.show()
def test_plot_solution_salt_dome():
    from pygeoiga.nurb.cad import make_salt_dome
    geometry = make_salt_dome(refine=True,
                              knot_ins=[
                                  np.arange(0.2, 1, 0.2),
                                  np.arange(0.2, 1, 0.2)
                              ])  #refine=np.arange(0.05,1,0.05))
    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
    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)
    from pygeoiga.analysis.MultiPatch import map_MP_elements

    geometry = map_MP_elements(geometry, D)
    plot_pvista(geometry)
Exemple #3
0
def test_global_stifffness_matrix():
    from pygeoiga.nurb.cad import make_L_shape
    from pygeoiga.analysis.MultiPatch import patch_topology

    geometry = make_L_shape(refine=True,
                            knot_ins=([0.3, 0.5, 0.7], [0.4, 0.6]))
    geometry, gDoF = patch_topology(geometry)
    print(gDoF)
    from pygeoiga.analysis.MultiPatch import form_k_IGA_mp
    K_glob = np.zeros((gDoF, gDoF))
    K_glob = form_k_IGA_mp(geometry, K_glob)

    fig, ax = plt.subplots(1, 3, sharey=True, figsize=(10, 3))
    for count, patch_id in enumerate(geometry):
        K = geometry[patch_id].get("K")
        print(K.shape)
        ax[count].spy(K)
    ax[0].set_xlabel("$K$ for $\Omega_1$", fontsize=15)
    ax[1].set_xlabel("$K$ for $\Omega_2$", fontsize=15)
    ax[2].set_xlabel("$K$ for $\Omega_3$", fontsize=15)
    fig.show()

    fig2, ax2 = plt.subplots()
    ax2.spy(K_glob)
    ax2.set_xlabel("Global $K$ for $\Omega$", fontsize=15)
    fig2.show()

    save = False
    if save or save_all:
        fig.savefig(fig_folder + "K_single_patch.pdf", **kwargs_savefig)
        fig2.savefig(fig_folder + "K_multi_patch.pdf", **kwargs_savefig)
Exemple #4
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()
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()
Exemple #6
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()
def do_IGA(function, T_t, T_b, knot_ins):
    geometry = function(refine=True, knot_ins=knot_ins)
    from pygeoiga.analysis.MultiPatch import patch_topology, form_k_IGA_mp
    geometry, gDoF = patch_topology(geometry)
    K_glob_IGA = np.zeros((gDoF, gDoF))
    F_IGA = np.zeros(gDoF)
    a_IGA = np.zeros(gDoF)
    K_glob_IGA = form_k_IGA_mp(geometry, K_glob_IGA)
    from pygeoiga.analysis.MultiPatch import boundary_condition_mp
    bc_IGA, a_IGA = boundary_condition_mp(geometry, a_IGA, T_t, T_b, None,
                                          None)
    bc_IGA["gDOF"] = gDoF
    from pygeoiga.analysis.common import solve
    a_IGA, F_IGA = solve(bc_IGA, K_glob_IGA, F_IGA, a_IGA)
    from pygeoiga.analysis.MultiPatch import map_MP_elements
    geometry = map_MP_elements(geometry, a_IGA)
    return geometry, gDoF
def test_plot_solution_3_layer_mp():
    from pygeoiga.nurb.cad import make_3_layer_patches
    geometry = make_3_layer_patches(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 = 25  # [°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)
    plot_pvista(geometry)
def test_plot_solution_mp_fault():
    from pygeoiga.nurb.cad import make_fault_model
    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)
    from pygeoiga.analysis.MultiPatch import map_MP_elements

    geometry = map_MP_elements(geometry, D)
    plot_pvista(geometry)
def same_IGA_BEZIER(geometry,
                    T_t,
                    T_b,
                    save=False,
                    filename="temp",
                    levels=None):
    from pygeoiga.analysis.MultiPatch import patch_topology, bezier_extraction_mp, form_k_IGA_mp, form_k_bezier_mp
    geometry, gDoF = patch_topology(geometry)

    import copy
    bezier_geometry = copy.deepcopy(geometry)
    bezier_geometry = bezier_extraction_mp(bezier_geometry)

    K_glob_IGA = np.zeros((gDoF, gDoF))
    F_IGA = np.zeros(gDoF)
    a_IGA = np.zeros(gDoF)
    K_glob_be = np.zeros((gDoF, gDoF))
    F_be = np.zeros(gDoF)
    a_be = np.zeros(gDoF)

    K_glob_IGA = form_k_IGA_mp(geometry, K_glob_IGA)
    K_glob_be = form_k_bezier_mp(bezier_geometry, K_glob_be)

    from pygeoiga.analysis.MultiPatch import boundary_condition_mp
    bc_IGA, a_IGA = boundary_condition_mp(geometry, a_IGA, T_t, T_b, None,
                                          None)
    bc_IGA["gDOF"] = gDoF
    bc_be, a_be = boundary_condition_mp(bezier_geometry, a_be, T_t, T_b, None,
                                        None)
    bc_be["gDOF"] = gDoF
    from pygeoiga.analysis.common import solve

    a_IGA, F_IGA = solve(bc_IGA, K_glob_IGA, F_IGA, a_IGA)
    a_be, F_be = solve(bc_be, K_glob_be, F_be, a_be)

    from pygeoiga.analysis.MultiPatch import map_MP_elements

    geometry = map_MP_elements(geometry, a_IGA)
    bezier_geometry = map_MP_elements(bezier_geometry, a_be)
    figsize = (6, 5)
    #plot_IGA(geometry, a_IGA, gDoF, name="IGA")
    plot_field(geometry,
               a_IGA,
               gDoF,
               file_name=filename + "_IGA.pdf",
               name="IGA",
               figsize=figsize,
               save=save,
               levels=levels)
    #plot_IGA(bezier_geometry, a_be, gDoF, name ="Bezier")
    plot_field(bezier_geometry,
               a_be,
               gDoF,
               file_name=filename + "_bezier.pdf",
               name="Bezier",
               figsize=figsize,
               save=save,
               levels=levels)
    fig, ax = plt.subplots(figsize=figsize)
    min_p = None
    max_p = None
    cmap = plt.get_cmap("RdBu")
    xmin = 0
    xmax = 0
    ymin = 0
    ymax = 0
    cbar = True

    for patch_id in geometry.keys():
        err = geometry[patch_id].get("t_sol") - bezier_geometry[patch_id].get(
            "t_sol")
        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_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
        if min_p is None or min_p > err.min():
            min_p = err.min()
        if max_p is None or max_p < err.max():
            max_p = err.max()

    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 patch_id in geometry.keys():
        err = geometry[patch_id].get("t_sol") - bezier_geometry[patch_id].get(
            "t_sol")
        x = geometry[patch_id].get("x_sol")
        y = geometry[patch_id].get("y_sol")
        ax.contourf(x, y, err, vmin=min_p, vmax=max_p, cmap=cmap)

    import matplotlib
    from mpl_toolkits.axes_grid1 import make_axes_locatable
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad="2%")
    norm = matplotlib.colors.TwoSlopeNorm(vmin=min_p, vcenter=0, vmax=max_p)
    #norm = matplotlib.colors.Normalize(vmin=min_p, vmax=max_p, v)
    mappeable = matplotlib.cm.ScalarMappable(norm=norm, cmap=cmap)
    cbar = ax.figure.colorbar(mappeable,
                              cax=cax,
                              ax=ax,
                              label="Difference (IGA-Bezier)")

    fig.show()
    if save or save_all:
        fig.savefig(fig_folder + filename + "_difference.pdf",
                    **kwargs_savefig)
def test_comparison_efficiency():
    from time import process_time
    levels = [15, 20, 30, 40, 50, 60, 70, 80, 85]
    T_t = 10
    T_b = 90
    T_l = None
    T_r = None
    from pygeoiga.nurb.cad import make_salt_dome

    start_model = process_time()
    geometry = make_salt_dome(refine=True)
    finish_model = process_time()

    start_FEM = process_time()
    geometry, gDoF = patch_topology(geometry)
    geometry = bezier_extraction_mp(geometry)

    K_glob = np.zeros((gDoF, gDoF))
    s_k_FEM = process_time()
    K_glob = form_k_bezier_mp(geometry, K_glob)
    e_k_FEM = process_time()

    D = np.zeros(gDoF)
    b = np.zeros(gDoF)

    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)
    finish_FEM = process_time()

    from pygeoiga.analysis.MultiPatch import form_k_IGA_mp

    geometry = make_salt_dome(refine=True)  # refine=np.arange(0.05,1,0.05))

    start_IGA = process_time()
    geometry, gDoF = patch_topology(geometry)
    K_glob = np.zeros((gDoF, gDoF))
    s_k_IGA = process_time()
    K_glob = form_k_IGA_mp(geometry, K_glob)
    e_k_IGA = process_time()
    D = np.zeros(gDoF)
    b = np.zeros(gDoF)

    T_t = 10  # [°C]
    T_b = 90  # [°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)
    finish_IGA = process_time()

    time_FEM = finish_FEM - start_FEM
    time_k_fem = e_k_FEM - s_k_FEM
    time_IGA = finish_IGA - start_IGA
    time_k_iga = e_k_IGA - s_k_IGA
    time_model_refinement = finish_model - start_model

    print("gDoF: ", gDoF)
    print("FEM: ", time_FEM)  # FEM:  241.05022452400001
    print("K_FEM; ", time_k_fem)  # K_FEM;  172.537146357
    print("IGA: ", time_IGA)  # IGA: 372.34105559899996
    print("K_IGA; ", time_k_iga)  # K_IGA;  316.763859975
    print("Refinement: ",
          time_model_refinement)  # Refinement:  0.06600132199999997