-
Notifications
You must be signed in to change notification settings - Fork 0
/
Physics.py
144 lines (96 loc) · 3.26 KB
/
Physics.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
# coding: utf-8
# In[9]:
import numpy as np
from boundary_conditions import boundary_update
from test import test_stability
import dask
from dask import delayed
# In[1]:
class homogenous_advection:
@dask.delayed
def advection_temperature(T, u, v, d_T__d_x, d_T__d_y, laplace_T,KINEMATIC_VISCOSITY, TIME_STEP_LENGTH):
T_next = dask.delayed((T + TIME_STEP_LENGTH *
(
-
(
u * d_T__d_x
+
v * d_T__d_y
)
+
KINEMATIC_VISCOSITY * laplace_T
)
))
return T_next
# 000019
@dask.delayed
def advection_velocity_prediction_horizontal(u, v, d_u__d_x, d_u__d_y, laplace__u, KINEMATIC_VISCOSITY, TIME_STEP_LENGTH ):
u_half = dask.delayed((u + TIME_STEP_LENGTH *
(
-
(
u * d_u__d_x
+
v * d_u__d_y
)
+
KINEMATIC_VISCOSITY * laplace__u
)
))
return u_half
@dask.delayed
def advection_velocity_prediction_vertical(v, u, d_v__d_x, d_v__d_y, laplace__v, KINEMATIC_VISCOSITY, TIME_STEP_LENGTH ):
v_half = dask.delayed((v + TIME_STEP_LENGTH *
(
-
(
u * d_v__d_x
+
v * d_v__d_y
)
+
KINEMATIC_VISCOSITY * laplace__v
)
))
return v_half
# In[2]:
class pressure_poisson:
@dask.delayed
def pressure_solver(p, DX, rhs, N_PRESSURE_POISSON_ITERATIONS):
for _ in range(N_PRESSURE_POISSON_ITERATIONS):
p_next = dask.delayed(np.zeros_like(p))
p_next[1:-1, 1:-1] = 1/4 * (
+
p[1:-1, 0:-2]
+
p[0:-2, 1:-1]
+
p[1:-1, 2: ]
+
p[2: , 1:-1]
-
DX**2
*
rhs[1:-1, 1:-1]
)
# Pressure Boundary Conditions: Homogeneous Neumann Boundary
# Conditions everywhere except for the top, where it is a
# homogeneous Dirichlet BC
# if N_PRESSURE_POISSON_ITERATIONS + 1 > N_PRESSURE_POISSON_ITERATIONS:
# test_stability.test_pressure_poisson_convergence(p, p_next)
p = p_next
return p_next
# In[8]:
class advection_velocity_correction:
@dask.delayed
def advection_velocity(u_half, d_p__d_x, DENSITY, TIME_STEP_LENGTH):
u_next = dask.delayed((
u_half
-
TIME_STEP_LENGTH / DENSITY
*
d_p__d_x
))
return u_next
# In[ ]: