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()
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)
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)
def test_mesh_mp_salt_dome(): from pygeoiga.nurb.cad import make_salt_dome geometry = make_salt_dome(refine=False) mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh( geometry, size=100, save_geo=data_path + "salt_dome_model.geo", save_msh=data_path + "salt_dome_model.msh", mesh_file_type="msh2") print(script, physical_tag_id) plot_mesh(mesh)
def test_plot_local_solution_salt(): from pygeoiga.nurb.cad import make_salt_dome from pygeoiga.nurb.nrb_to_gmsh import convert_geometry_mp_to_gmsh geometry = make_salt_dome(refine=False) mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh( geometry, size=100, save_geo=datapath + "salt_dome_model.geo", save_msh=datapath + "salt_dome_model.msh") from pygeoiga.FE_solvers.run_fenics import convert_msh_to_xdmf, run_simulation, p_temperature_fenics input = datapath + "salt_dome_model.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, show=False) from pygeoiga.plot.solution_mpl import p_temperature fig, ax = plt.subplots() ax.set_aspect("equal") ax = p_temperature(nodal_coordinates[:, 0], nodal_coordinates[:, 1], temperature_nodes, vmin=temperature_nodes.min(), vmax=temperature_nodes.max(), ax=ax, point=False, fill=True, contour=False, colorbar=True, levels=100) ax = p_temperature(nodal_coordinates[:, 0], nodal_coordinates[:, 1], temperature_nodes, vmin=temperature_nodes.min(), vmax=temperature_nodes.max(), ax=ax, point=False, fill=False, contour=True, colorbar=False, levels=10) fig.show() print(len(temperature_nodes)) #695 200 #2381 100 fig.savefig(datapath + "salt_dome_model_100.png")
def test_create_script_salt_dome(): from pygeoiga.nurb.cad import make_salt_dome from pygeoiga.nurb.nrb_to_gmsh import convert_geometry_mp_to_gmsh geometry = make_salt_dome(refine=False) mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh( geometry, size=100, save_geo=datapath + "salt_dome_model.geo", save_msh=datapath + "salt_dome_model.msh") from pygeoiga.FE_solvers.run_moose import create_script input = datapath + "salt_dome_model.msh" create_script(input, topology_info=physical_tag_id, top_bc=10, bot_bc=40, geometry=geometry)
def test_run_workflow_salt_dome(): from pygeoiga.nurb.cad import make_salt_dome from pygeoiga.nurb.nrb_to_gmsh import convert_geometry_mp_to_gmsh geometry = make_salt_dome(refine=False) mesh, script, physical_tag_id = convert_geometry_mp_to_gmsh( geometry, size=200, save_geo=datapath + "salt_dome_model.geo", save_msh=datapath + "salt_dome_model.msh") from pygeoiga.FE_solvers.run_fenics import convert_msh_to_xdmf, run_simulation input = datapath + "salt_dome_model.msh" convert_msh_to_xdmf(input) nodal_coordinates, temperature_nodes = run_simulation( input, topology_info=physical_tag_id, top_bc=10, bot_bc=90, geometry=geometry)
def test_solve_salt_dome(): 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 = 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)
def test_same_dome(): from pygeoiga.nurb.cad import make_salt_dome #geometry = make_salt_dome(refine=False) #knot_ins = [np.arange(0.1, 1, 0.1), np.arange(0.1, 1, 0.1)] #for patch_id in geometry.keys(): # knots = geometry[patch_id].get("knots") # knot_ins[0] = [x for x in knot_ins[0] if x not in knots[0]] # knot_ins[1] = [x for x in knot_ins[1] if x not in knots[1]] knot_ins = [[ 0.1, 0.2, 0.3, 0.6, 0.7, ], [0.1, 0.2, 0.3, 0.6, 0.7]] geometry = make_salt_dome(refine=True, knot_ins=knot_ins) same_IGA_BEZIER(geometry, 10, 90, save=True, filename="fault", levels=[15, 20, 30, 40, 50, 60, 70, 80, 85])
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