コード例 #1
0
    def create_geom(**kwargs):
        from pygeoiga.nurb.cad import make_surface_biquadratic
        knots, B = make_surface_biquadratic()

        from pygeoiga.nurb.refinement import knot_insertion
        to_ins = kwargs.get("knot_ins", np.arange(0.1, 1, 0.1))

        knots_ins_0 = [x for x in to_ins if x not in knots[0]]
        B, knots = knot_insertion(B,
                                  degree=(2, 2),
                                  knots=knots,
                                  knots_ins=knots_ins_0,
                                  direction=0)
        knots_ins_1 = [x for x in to_ins if x not in knots[1]]
        B, knots = knot_insertion(B,
                                  degree=(2, 2),
                                  knots=knots,
                                  knots_ins=knots_ins_1,
                                  direction=1)

        geometry = dict()
        geometry["quadrat"] = {
            "B": B,
            "knots": knots,
            "kappa": 4,
            'color': "gray",
            "position": (1, 1),
            "BC": {
                0: "bot_bc",
                2: "top_bc"
            }
        }
        return geometry
コード例 #2
0
ファイル: test_to_gmsh.py プロジェクト: danielsk78/pygeoiga
def test_mesh_biquadratic():
    from pygeoiga.nurb.cad import make_surface_biquadratic
    k, B = make_surface_biquadratic()
    mesh, script, physical_tag_id = convert_single_NURB_to_gmsh(
        B,
        size=0.5,
        save_geo=data_path + "biquadratic.geo",
        save_msh=data_path + "biquadratic.msh")
    print(script)
    plot_mesh(mesh)
コード例 #3
0
ファイル: test_moose.py プロジェクト: danielsk78/pygeoiga
def test_create_script_biquadratic():
    from pygeoiga.FE_solvers.run_moose import create_script
    from pygeoiga.nurb.nrb_to_gmsh import convert_single_NURB_to_gmsh
    from pygeoiga.nurb.cad import make_surface_biquadratic
    k, B = make_surface_biquadratic()
    mesh, script, physical_tag_id = convert_single_NURB_to_gmsh(
        B,
        size=0.5,
        save_geo=datapath + "biquadratic.geo",
        save_msh=datapath + "biquadratic.msh")
    input = datapath + "biquadratic.msh"
    create_script(input,
                  topology_info=physical_tag_id,
                  bot_bc=40,
                  top_bc=10,
                  geometry=None,
                  kappa=4)
コード例 #4
0
ファイル: test_fenics.py プロジェクト: danielsk78/pygeoiga
def test_run_workflow_biquadratic():
    from pygeoiga.FE_solvers.run_fenics import convert_msh_to_xdmf, run_simulation
    from pygeoiga.nurb.nrb_to_gmsh import convert_single_NURB_to_gmsh
    from pygeoiga.nurb.cad import make_surface_biquadratic
    k, B = make_surface_biquadratic()
    mesh, script, physical_tag_id = convert_single_NURB_to_gmsh(
        B,
        size=0.5,
        save_geo=datapath + "biquadratic.geo",
        save_msh=datapath + "biquadratic.msh")
    input = datapath + "biquadratic.msh"
    plt.pause(3)  # needs a bit of time to create the files
    convert_msh_to_xdmf(input)
    run_simulation(input,
                   topology_info=physical_tag_id,
                   bot_bc=40,
                   top_bc=10,
                   geometry=None,
                   kappa=4)
コード例 #5
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()
コード例 #6
0
def test_compare_biquadratic():
    from pygeoiga.nurb.cad import make_surface_biquadratic
    knots, B = make_surface_biquadratic()
    from pygeoiga.nurb.refinement import knot_insertion
    knot_ins = [np.arange(0.05, 1, 0.05), np.arange(0.05, 1, 0.05)]

    knots_ins_0 = [x for x in knot_ins[0] if x not in knots[0]]
    B, knots = knot_insertion(B,
                              degree=(2, 2),
                              knots=knots,
                              knots_ins=knots_ins_0,
                              direction=0)
    knots_ins_1 = [x for x in knot_ins[1] if x not in knots[1]]
    B, knots = knot_insertion(B,
                              degree=(2, 2),
                              knots=knots,
                              knots_ins=knots_ins_1,
                              direction=1)

    geometry = dict()
    geometry["quadrat"] = {
        "B": B,
        "knots": knots,
        "kappa": 4,
        'color': "red",
        "position": (1, 1),
        "BC": {
            0: "bot_bc",
            2: "top_bc"
        }
    }
    T_t = 10
    T_b = 25
    same_IGA_BEZIER(geometry,
                    T_t,
                    T_b,
                    save=True,
                    filename="biquadratic",
                    levels=[12, 14, 17, 20, 22, 24])
コード例 #7
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()
コード例 #8
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)
コード例 #9
0
def test_between_mappings():
    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)

    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.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9]
    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)
    plot(B, knots, "mapping.pdf")
コード例 #10
0
def test_make_NURB_biquadratic():
    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)

    from pygeoiga.nurb.cad import make_surface_biquadratic
    knots, B = make_surface_biquadratic()
    plot(B, knots, "B-spline_biquadratic.pdf")
    from pygeoiga.nurb.refinement import knot_insertion
    knot_ins_1 = [0.3, 0.6]
    knot_ins_0 = [0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9]
    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)
    plot(B, knots, "B-spline_biquadratic_refined.pdf")
コード例 #11
0
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)
コード例 #12
0
def test_image_example():
    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)

    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)
    plot(B, knots, "mapping.pdf")

    knots, B = make_surface_biquadratic()

    from pygeoiga.nurb.refinement import knot_insertion
    knot_ins_1 = [0.3, 0.3, 0.6, 0.6]
    knot_ins_0 = [0.25, 0.25, 0.5, 0.75, 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)
    plot(B, knots, "mapping.pdf")