Esempio n. 1
0
def test_plot_solution_3_layer_mp():
    from pygeoiga.nurb.cad import make_3_layer_patches
    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_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 = 40  # [°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_3_layer_patches(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()
Esempio n. 2
0
def test_form_k():
    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)
    plt.spy(K_glob)
    plt.show()
def test_same_anticline():
    from pygeoiga.nurb.cad import make_3_layer_patches
    geometry = make_3_layer_patches(refine=True)
    same_IGA_BEZIER(geometry,
                    10,
                    25,
                    save=True,
                    filename="anticline",
                    levels=[11, 12, 14, 17, 20, 22, 23, 24])
Esempio n. 4
0
def test_boundary_condition():
    geometry = make_3_layer_patches()
    geometry, gDoF = patch_topology(geometry)

    D = np.zeros(gDoF)
    T_t = 10  # [°C]
    T_b = 40  # [°C]
    T_l = None
    T_r = None
    prDOF, D = boundary_condition_mp(geometry, D, T_t, T_b, T_l, T_r)
    print(prDOF, D)
Esempio n. 5
0
def test_mesh_mp_3_layer():
    from pygeoiga.nurb.cad import make_3_layer_patches
    geometry = make_3_layer_patches()
    mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh(
        geometry,
        size=50,
        save_geo=data_path + "3_layer_anticline.geo",
        save_msh=data_path + "3_layer_anticline.msh",
        mesh_file_type="msh2")
    print(script, physical_tag_id)
    plot_mesh(mesh)
Esempio n. 6
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()
Esempio n. 7
0
def test_visualize_patches():
    geometry = make_3_layer_patches()
    resolution = 20
    fig = plt.figure("first")
    ax = fig.add_subplot(111, projection='3d')

    for patch_id in geometry.keys():
        B = geometry[patch_id].get("B")
        knots = geometry[patch_id].get("knots")
        nurb = NURB(B, knots, resolution=resolution, engine="python")
        ax.plot(nurb.model[:, 0], nurb.model[:, 1], nurb.model[:, 2], linestyle='None', marker='.')#, color='blue')
        ax.plot_wireframe(nurb.cpoints[..., 0], nurb.cpoints[..., 1], nurb.cpoints[..., 2])#, color='red')
    fig.show()
Esempio n. 8
0
def test_create_script_3_layer():
    from pygeoiga.nurb.cad import make_3_layer_patches
    from pygeoiga.nurb.nrb_to_gmsh import convert_geometry_mp_to_gmsh
    geometry = make_3_layer_patches(refine=False)
    mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh(
        geometry,
        size=10,
        save_geo=datapath + "3_layer_anticline.geo",
        save_msh=datapath + "3_layer_anticline.msh")
    from pygeoiga.FE_solvers.run_moose import create_script
    input = datapath + "3_layer_anticline.msh"
    create_script(input,
                  topology_info=physical_tag_id,
                  bot_bc=10,
                  top_bc=40,
                  geometry=geometry)
Esempio n. 9
0
def test_stiffness_matrix():
    geometry = make_3_layer_patches()
    geometry, gDoF = patch_topology(geometry)

    K_glob = np.zeros((gDoF, gDoF))
    npatches = len(geometry)
    #form the stiffness matrix
    for patch_id in geometry.keys():
        B = geometry[patch_id].get("B")
        U, V = geometry[patch_id].get("knots")

        ### For the moment we will not make a refinement

        degree_u = len(np.where(U == 0.)[0]) - 1
        degree_v = len(np.where(V == 0.)[0]) - 1

        # n_xi and n_eta are the number of elements
        n_xi = B.shape[0] - degree_u
        n_eta = B.shape[1] - degree_v
        nel = n_xi * n_eta  # total number of elements
        n = n_xi + degree_u  # Number of basis functions/ control points in xi direction
        m = n_eta + degree_v  # Number of basis functions/ control points in eta direction
        ncp = n * m  # Total number of control points
        pDof = ncp  # patch degrees of freedom - Temperature

        K = np.zeros((pDof, pDof))  # stiffness matrix size
        degree = degree_u

        P = geometry[patch_id].get("list_cp")
        W = geometry[patch_id].get("list_weight")

        # Element topology
        IEN = IEN_element_topology(n_xi, n_eta, degree)

        b = np.zeros(pDof)  # load vector size
        D = np.zeros(pDof)
        kappa = np.ones((n, m)) * geometry[patch_id].get("kappa")
        K = form_k_IGA(K, IEN, P, kappa, n_xi, n_eta, degree)

        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 #[np.ix_(patch_DOF, patch_DOF)]


    plt.spy(K_glob)
    plt.show()
Esempio n. 10
0
def test_run_workflow_3_layer_patch():
    from pygeoiga.nurb.cad import make_3_layer_patches
    from pygeoiga.nurb.nrb_to_gmsh import convert_geometry_mp_to_gmsh
    geometry = make_3_layer_patches(refine=False)
    mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh(
        geometry,
        size=10,
        save_geo=datapath + "3_layer_anticline.geo",
        save_msh=datapath + "3_layer_anticline.msh")
    from pygeoiga.FE_solvers.run_fenics import convert_msh_to_xdmf, run_simulation
    input = datapath + "3_layer_anticline.msh"
    convert_msh_to_xdmf(input)
    nodal_coordinates, temperature_nodes = run_simulation(
        input,
        topology_info=physical_tag_id,
        top_bc=10,
        bot_bc=40,
        geometry=geometry)
Esempio n. 11
0
def test_solve_mp():
    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 = 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)
    plt.spy(K_glob)
    plt.show()
    print(D)
Esempio n. 12
0
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)
Esempio n. 13
0
def test_get_point_solution_mp():
    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 = 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.analysis.MultiPatch import point_solution_mp

    t = point_solution_mp(0, 0, geometry, tolerance=1e-9, itera =1000)
    print(t) # knots (0.5548848818987607, 0.7526260007172824),
Esempio n. 14
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])
Esempio n. 15
0
def test_create_geometry():

    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)

    from pygeoiga.nurb.cad import make_3_layer_patches

    geometry = make_3_layer_patches()
    plot(geometry, "anticline.pdf")
    geometry2 = make_3_layer_patches(refine=True, knot_ins=[np.arange(0.25,1,0.25), np.arange(0.25,1,0.25)])
    plot(geometry2, "anticline_refined_2.pdf")
    geometry3 = make_3_layer_patches(refine=True, knot_ins=[np.arange(0.1,1,0.1), np.arange(0.1,1,0.1)])
    plot(geometry3, "anticline_refined_3.pdf")
def test_listings():
    from pygeoiga.nurb.cad import make_3_layer_patches

    geometry = make_3_layer_patches(refine=True)

    from pygeoiga.analysis.MultiPatch import patch_topology

    geometry, gDoF = patch_topology(geometry)

    def bezier_extraction(geometry):
        from pygeoiga.analysis.bezier_extraction import bezier_extraction_operator_bivariate, bezier_extraction_operator

        for patch_id in geometry.keys():
            U, V = geometry[patch_id].get("knots")
            degree = geometry[patch_id].get("degree")
            n_u, n_v = geometry[patch_id].get("n_element")
            assert degree[0] == degree[
                1], "Degree of the geometry is not the same"
            degree = degree[0]

            C_u = bezier_extraction_operator(U, degree)
            C_v = bezier_extraction_operator(V, degree)
            C = bezier_extraction_operator_bivariate(C_u, C_v, n_u, n_v,
                                                     degree)

            geometry[patch_id]["bezier_extraction"] = C

        return geometry

    geometry = bezier_extraction(geometry)

    from pygeoiga.analysis.bezier_FE import form_k

    def assemble_stiffness_matrix_bezier(geometry: dict, gDoF: int):
        # Set empty the stiffness matrix according to the global degrees of freedom
        K_glob = np.zeros((gDoF, gDoF))
        for patch_id in geometry.keys():
            pDof = geometry[patch_id].get(
                "patch_DOF")  # Degrees of freedom per patch
            nx, ny = geometry[patch_id].get(
                "n_element")  # number of elements in parametric space
            nel = nx * ny  # total number of elements
            K = np.zeros(
                (pDof, pDof))  # Initialize empty patch stiffness matrix

            P = geometry[patch_id].get(
                "list_cp")  # Get list with location of control points
            W = geometry[patch_id].get("list_weight")  # Get list of weights
            # Support only the same degree for both parametric directions
            degree = geometry[patch_id].get("degree")[0]

            # Bezier exatractor operator of the patch
            C = geometry[patch_id].get("bezier_extraction")

            kappa = geometry[patch_id].get(
                "kappa")  # Get thermal conductivity of patch

            IEN = geometry[patch_id].get(
                "IEN")  # Global connectivity array (Element topology)

            K = form_k(K, IEN, P, kappa, nel, degree, W, C)
            geometry[patch_id]["K"] = K
            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_bezier(geometry, gDoF)
    plt.spy(K_glob)
    plt.show()
Esempio n. 17
0
def test_conectivity_arrays():
    geometry = make_3_layer_patches()
    geometry, _ = patch_topology(geometry)
    for patch_id in geometry.keys():
        print(patch_id, " have: ", geometry[patch_id]["patch_topology"])
Esempio n. 18
0
def test_fill_info():
    geometry = make_3_layer_patches()
    geometry, _ = patch_topology(geometry)
    for patch_id in geometry.keys():
        print(patch_id, " have: ", geometry[patch_id]["patch_DOF"])
        print(patch_id, " have: ", geometry[patch_id]["n_element"])
Esempio n. 19
0
def test_multi_patch_bezier_extraction():
    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)
Esempio n. 20
0
def test_get_common_cp():
    geometry = make_3_layer_patches()
    geometry, _ = patch_topology(geometry)
    for patch_id in geometry.keys():
        print(patch_id, " have: ", geometry[patch_id]["cp_repeated"])
Esempio n. 21
0
def test_glob_num():
    geometry = make_3_layer_patches()
    geometry, global_degrees_freedom = patch_topology(geometry)
    print("Geometry have a total of: ", global_degrees_freedom, " DOF")
    for patch_id in geometry.keys():
        print(patch_id, " have glob_num: ", geometry[patch_id]["glob_num"])