-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation_bdn_penalty.py
73 lines (62 loc) · 2.07 KB
/
simulation_bdn_penalty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import matplotlib.pyplot as plt
import numpy as np
from assembling_lin_sys import AssemblerPenalty
from p1_bubble_fem import P1BubbleFE
from rectangular_grid import RectangularGrid
from reference_element import ReferenceElement
from solution_visualiser import Visualiser
from triangulation import Triangulation
NU = 100
PRESSURE_GRAD = -100
C_CONST = 1 / 2 * 1 / NU * (-PRESSURE_GRAD)
RADIUS = 1
LENGTH = 10
X_DISCRETIZATION = 3
Y_DISCRETIZATION = 3
def g_1(x_1: float, x_2: float) -> float:
if x_1 < 1e-14:
return C_CONST * (RADIUS - x_2) * (x_2 + RADIUS)
else:
return 0
def chi(x_1: float, x_2: float) -> float:
# value_1 = (x_1 - 2) ** 2 + x_2**2
# value_2 = (x_1 - 3.5) ** 2 + (x_2 - RADIUS) ** 2
value_4 = x_1 * (-0.1) + 1
value_5 = x_1 * 0.1 - 1
# value_3 = (x_1 - 4.5) ** 2 + (x_2 + RADIUS) ** 2
if value_4 <= x_2 or value_5 >= x_2: # or value_1 <= RADIUS / 3:
return 1
else:
return 0
return 0
def main():
x_domain = (0, LENGTH)
y_domain = (-RADIUS, RADIUS)
x_discret = X_DISCRETIZATION
y_discret = Y_DISCRETIZATION
meshgrid = RectangularGrid(
x_domain=x_domain,
y_domain=y_domain,
x_discretisation=x_discret,
y_discretisation=y_discret,
)
triangulation = Triangulation(rect_mesh=meshgrid)
p1_bubble_fem = P1BubbleFE(triangulation=triangulation)
triangulation.plot_triangulation(
triangulation.rect_mesh.sorted_mesh_coords,
p1_bubble_fem.discret_points_complete,
)
ref_elem = ReferenceElement()
assembler = AssemblerPenalty(
reference_element=ref_elem, fe_physical=p1_bubble_fem, nu=1, c_const=1
)
# s = assembler.assemble_s_penalty(chi)
s = assembler.assemble_s_penalty(lambda x, y: 0)
rhs = assembler.rhs_penalty(g_boundary_func=g_1)
u_p_sol = np.linalg.solve(s, rhs)
visualizer = Visualiser(u_p_sol, p1_bubble_fem)
# visualizer.plot_simple(bdn_func=g_1, radius=RADIUS, y_disc=Y_DISCRETIZATION)
visualizer.plot_penalty()
visualizer.plot_pressure()
plt.show() # type: ignore
main()