import paraBEM from paraBEM.pan2d import doublet_2_0, source_2_0, doublet_2_0_v, source_2_0_v, doublet_2_1, doublet_2_1_v from paraBEM.vtk_export import VtkWriter import numpy as np from paraBEM.utils import check_path v1 = paraBEM.PanelVector2(-2, 0) v2 = paraBEM.PanelVector2(2, 0) panel = paraBEM.Panel2([v1, v2]) n = 500 space = np.linspace(-5, 5, n) grid = [paraBEM.Vector2([x, y]) for y in space for x in space] dub_vals = [doublet_2_0(target, panel) for target in grid] dub_vals_lin_1 = [doublet_2_1(target, panel, True) for target in grid] dub_vals_lin_2 = [doublet_2_1(target, panel, False) for target in grid] src_vals = [source_2_0(target, panel) for target in grid] dublinv1_vals = [doublet_2_1_v(target, panel, True) for target in grid] dublinv2_vals = [doublet_2_1_v(target, panel, False) for target in grid] dubv_vals = [doublet_2_0_v(target, panel) for target in grid] srcv_vals = [source_2_0_v(target, panel) for target in grid] writer = VtkWriter() with open(check_path("results/element_2.vtk"), "w") as _file: writer.structed_grid(_file, "element_2", [n, n, 1]) writer.points(_file, grid) writer.data(_file, dub_vals, name="doublet", _type="SCALARS", data_type="POINT_DATA") writer.data(_file, dub_vals_lin_1, name="doublet_lin_1", _type="SCALARS", data_type="POINT_DATA") writer.data(_file, dub_vals_lin_2, name="doublet_lin_2", _type="SCALARS", data_type="POINT_DATA")
import numpy as np import paraBEM from paraBEM.pan2d import doublet_2_0, doublet_2_0_v v1 = paraBEM.PanelVector2(-1, 0) v2 = paraBEM.PanelVector2(1, 0) p = paraBEM.Panel2([v1, v2]) v = paraBEM.Vector2(0, 0) print("doublet influence on panel center:") print(doublet_2_0_v(v, p).y) print("") y = 3 pos = [[x, y] for x in np.linspace(-2, 2, 100)] _pos = map(paraBEM.Vector2, pos) vals = [doublet_2_0(i, p) for i in _pos] print("x, y, doublet_value") print("==============================\n") print(np.array([[pos[0], pos[1], vals[i]] for i, pos in enumerate(pos)]))
# | | # col|+ +| # | | # x -1 1 # T 0 1 # R 1 1 # l 1 # panel1: temp-formulation T1 = 0 T2 = 1 R1 = 0 R2 = 0 l = 1 mat[0, 0] = source_2_0(pan1.center, pan1) mat[0, 1] = source_2_0(pan1.center, pan2) mat[0, 0] -= doublet_2_0(pan1.center, pan1) * l * R1 mat[0, 1] -= doublet_2_0(pan1.center, pan2) * l * R2 rhs[0] += T1 # panel3: temp-formulation mat[1, 0] = source_2_0(pan2.center, pan1) mat[1, 1] = source_2_0(pan2.center, pan2) mat[1, 0] -= doublet_2_0(pan2.center, pan1) * l * R1 mat[1, 1] -= doublet_2_0(pan2.center, pan2) * l * R2 rhs[1] += T2 sol = np.linalg.solve(mat, rhs) print(mat) print(rhs) print(sol)
points = [paraBEM.PanelVector2(*point) for point in points] panels = [ [1, 0], [2, 1], [3, 2], [0, 3], [4, 5], [5, 6], [6, 7], [7, 4] ] panels = [paraBEM.Panel2([points[i] for i in panel]) for panel in panels] T_boundary = [0, 0, 0, 0, 1, 1, 1, 1] mat = np.zeros([8, 8]) rhs = np.zeros([8]) for i, panel_i in enumerate(panels): rhs[i] = T_boundary[i] for j, panel_j in enumerate(panels): mat[i, j] = - source_2_0(panel_i.center, panel_j) mat[i, j] += doublet_2_0(panel_i.center, panel_j) * R sol = np.linalg.solve(mat, rhs) nx = 300 ny = 300 x_grid = np.linspace(-3, 3, nx) y_grid = np.linspace(-3, 3, ny) grid = [paraBEM.Vector2(x, y) for y in y_grid for x in x_grid] t_list = [] for point in grid: t = 0 for i, panel_i in enumerate(panels): t -= source_2_0(point, panel_i) * sol[i] t += doublet_2_0(point, panel_i) * sol[i] * R
points = [[-2, -2], [2, -2], [2, 2], [-2, 2], [-1, -1], [1, -1], [1, 1], [-1, 1]] points = [paraBEM.PanelVector2(*point) for point in points] panels = [[1, 0], [2, 1], [3, 2], [0, 3], [4, 5], [5, 6], [6, 7], [7, 4]] panels = [paraBEM.Panel2([points[i] for i in panel]) for panel in panels] T_boundary = [0, 0, 0, 0, 1, 1, 1, 1] mat = np.zeros([8, 8]) rhs = np.zeros([8]) for i, panel_i in enumerate(panels): rhs[i] = T_boundary[i] for j, panel_j in enumerate(panels): mat[i, j] = -source_2_0(panel_i.center, panel_j) mat[i, j] += doublet_2_0(panel_i.center, panel_j) * R sol = np.linalg.solve(mat, rhs) nx = 300 ny = 300 x_grid = np.linspace(-3, 3, nx) y_grid = np.linspace(-3, 3, ny) grid = [paraBEM.Vector2(x, y) for y in y_grid for x in x_grid] t_list = [] for point in grid: t = 0 for i, panel_i in enumerate(panels): t -= source_2_0(point, panel_i) * sol[i] t += doublet_2_0(point, panel_i) * sol[i] * R t_list.append(t)
source = paraBEM.Panel2([pnt1, pnt2]) y = np.linspace(-3, 3, 100) val = [source_2_0(paraBEM.Vector2(yi, 8), source) for yi in y] plt.plot(y, val) val = [source_2_0(paraBEM.Vector2(yi, 0.01), source) for yi in y] plt.plot(y, val) val = [source_2_0(paraBEM.Vector2(yi, 0.0), source) for yi in y] plt.plot(y, val) val = [source_2_0(paraBEM.Vector2(yi, 3), source) for yi in y] plt.plot(y, val) plt.savefig(check_path("results/2d/source.png")) plt.close() y = np.linspace(-3, 3, 100) val = [doublet_2_0(paraBEM.Vector2(yi, 7), source) for yi in y] plt.plot(y, val) val = [doublet_2_0(paraBEM.Vector2(yi, 0.01), source) for yi in y] plt.plot(y, val) val = [doublet_2_0(paraBEM.Vector2(yi, 0.0), source) for yi in y] plt.plot(y, val) val = [doublet_2_0(paraBEM.Vector2(yi, 3), source) for yi in y] plt.plot(y, val) plt.savefig(check_path("results/2d/doublet.png")) plt.close() y = np.linspace(-3, 3, 100) val = [doublet_2_0_v(paraBEM.Vector2(yi, 7), source).x for yi in y] plt.plot(y, val) val = [doublet_2_0_v(paraBEM.Vector2(yi, 0.2), source).x for yi in y] plt.plot(y, val)
# | | | # col|+ +| +| # | | | # x -1 0 1 # T 0 ? 1 # l 1 2 # panel1: temp-formulation T1 = -10 T2 = 10 l1 = 1 l2 = 2 mat[0, 0] = source_2_0(panels[0].center, panels[0]) mat[0, 1] = source_2_0(panels[0].center, panels[1]) * (1 - l2 / l1) mat[0, 2] = source_2_0(panels[0].center, panels[2]) rhs[0] += doublet_2_0(panels[0].center, panels[0]) * T1 rhs[0] += doublet_2_0(panels[0].center, panels[2]) * T2 rhs[0] += T1 # panel2: velocity formulation mat[1, 0] = source_2_0_v(panels[1].center, panels[0]).dot(panels[1].n) mat[1, 1] = source_2_0_v(panels[1].center, panels[1]).dot(panels[1].n) * (1 - l2 / l1) - 1 mat[1, 2] = source_2_0_v(panels[1].center, panels[2]).dot(panels[1].n) rhs[1] += doublet_2_0_v(panels[1].center, panels[0]).dot(panels[1].n) * T1 rhs[1] += doublet_2_0_v(panels[1].center, panels[2]).dot(panels[1].n) * T2 # panel3: temp-formulation mat[2, 0] = source_2_0(panels[2].center, panels[0]) mat[2, 1] = source_2_0(panels[2].center, panels[1]) * (1 - l2 / l1) mat[2, 2] = source_2_0(panels[2].center, panels[2]) rhs[2] += doublet_2_0(panels[2].center, panels[0]) * T1