Ejemplo n.º 1
0
def test_plot_solution_salt_dome_bezier():
    from pygeoiga.nurb.cad import make_salt_dome
    from pygeoiga.analysis.MultiPatch import bezier_extraction_mp
    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)
    geometry = bezier_extraction_mp(geometry)
    K_glob = np.zeros((gDoF, gDoF))

    from pygeoiga.analysis.MultiPatch import form_k_bezier_mp
    K_glob = form_k_bezier_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)
Ejemplo n.º 2
0
def test_plot_solution_salt_dome_mp():

    from pygeoiga.nurb.cad import make_salt_dome
    levels = [15, 20, 30, 40, 50, 60, 70, 80, 85]
    T_t = 10
    T_b = 90
    T_l = None
    T_r = None

    geometry = make_salt_dome(refine=True)
    geometry, gDoF = patch_topology(geometry)
    geometry = bezier_extraction_mp(geometry)

    K_glob = np.zeros((gDoF, gDoF))
    K_glob = form_k_bezier_mp(geometry, K_glob)

    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)

    geometry = map_MP_elements(geometry, D)
    plot_mp_FEM(geometry, D, gDoF, levels=levels)
Ejemplo n.º 3
0
def test_form_k():
    from pygeoiga.nurb.cad import make_3_layer_patches

    geometry = make_3_layer_patches(refine=True)
    geometry, gDoF = patch_topology(geometry)
    geometry = bezier_extraction_mp(geometry)

    K_glob = np.zeros((gDoF, gDoF))
    K_glob = form_k_bezier_mp(geometry, K_glob)

    plt.spy(K_glob)
    plt.show()
def do_Bezier(function, T_t, T_b, knot_ins):
    bezier_geometry = function(refine=True, knot_ins=knot_ins)
    from pygeoiga.analysis.MultiPatch import patch_topology, bezier_extraction_mp, form_k_IGA_mp, form_k_bezier_mp
    bezier_geometry, gDoF = patch_topology(bezier_geometry)
    bezier_geometry = bezier_extraction_mp(bezier_geometry)
    K_glob_be = np.zeros((gDoF, gDoF))
    F_be = np.zeros(gDoF)
    a_be = np.zeros(gDoF)
    K_glob_be = form_k_bezier_mp(bezier_geometry, K_glob_be)
    from pygeoiga.analysis.MultiPatch import boundary_condition_mp
    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_be, F_be = solve(bc_be, K_glob_be, F_be, a_be)
    from pygeoiga.analysis.MultiPatch import map_MP_elements
    bezier_geometry = map_MP_elements(bezier_geometry, a_be)
    return bezier_geometry, gDoF
Ejemplo n.º 5
0
def test_3_layers():
    from pygeoiga.nurb.cad import make_3_layer_patches

    geometry = make_3_layer_patches(refine=True)
    geometry, gDoF = patch_topology(geometry)
    geometry = bezier_extraction_mp(geometry)

    K_glob = np.zeros((gDoF, gDoF))
    K_glob = form_k_bezier_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_mp_FEM(geometry, D, gDoF, levels=[12, 14, 17, 20, 22, 24])
Ejemplo n.º 6
0
def test_plot_solution_fault_model_mp():
    from pygeoiga.nurb.cad import make_fault_model
    levels = [12, 16, 20, 24, 28, 32, 36]
    T_t = 10
    T_b = 40
    T_l = None
    T_r = None

    geometry = make_fault_model(refine=True)
    geometry, gDoF = patch_topology(geometry)
    geometry = bezier_extraction_mp(geometry)

    K_glob = np.zeros((gDoF, gDoF))
    K_glob = form_k_bezier_mp(geometry, K_glob)

    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)

    geometry = map_MP_elements(geometry, D)
    plot_mp_FEM(geometry, D, gDoF, levels=levels)
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)
Ejemplo n.º 8
0
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