@LevMckinney/

# Fluid_Simulation_For_Dummies

## No description

Files
• main.py
main.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
```
```import numpy

class FluidCube:
def __init__(self, size, diffusion, viscosity, dt) :
self.size = size
self.dt = dt
self.diff = diffusion
self.visc = viscosity

self.s = numpy.zeros((size,size,size))
self.density = numpy.zeros((size,size,size))

self.Vx = numpy.zeros((size,size,size))
self.Vy = numpy.zeros((size,size,size))
self.Vz = numpy.zeros((size,size,size))

self.Vx0 = numpy.zeros((size,size,size))
self.Vy0 = numpy.zeros((size,size,size))
self.Vz0 = numpy.zeros((size,size,size))

def AddDensity(self, x,  y, z, anmount) :
self.density[x,y,z] += anmount

def AddVelocity(self, x, y, z, dY, dX, dZ) :
self.Vx[x,y,z] += dX
self.Vy[x,y,z] += dY
self.Vz[x,y,z] += dZ

def set_bnd(self, b, x) :

N = self.size

for j in range(1, N - 1) :
for i in range(1, N - 1) :
x[i, j, 0] = -x[i, j, 1] if b == 3 else x[i, j, 1]
x[i,j, N - 1] = -x[i, j, N-2] if b == 3 else x[i, j, N-2]

for k in range(1, N - 1) :
for i in range(1, N - 1) :
x[i, 0  , k] =  -x[i, 1  , k] if b == 2 else x[i, 1  , k]
x[i, N-1, k] =  -x[i, N-2, k] if b == 2 else x[i, N-2, k]

for k in range(1, N - 1) :
for j in range(1, N - 1) :
x[0  , j, k] =  -x[1  , j, k] if b == 1 else x[1  , j, k]
x[N-1, j, k] =  -x[N-2, j, k] if b == 1 else x[N-2, j, k]

#Corners

x[0, 0, 0] = 0.33 * (x[1, 0, 0] + x[0, 1, 0] + x[0, 0, 1])

x[0, N-1, 0] = 0.33 * (x[1, N-1, 0] + x[0, N-2, 0] + x[0, N-1, 1])

x[0, 0, N-1] = 0.33 * (x[1, 0, N-1] + x[0, 1, N-1] + x[0, 0, N]);

x[0, N-1, N-1] = 0.33 * (x[1, N-1, N-1] + x[0, N-2, N-1] + x[0, N-1, N-2])

x[N-1, 0, 0] = 0.33 * (x[N-2, 0, 0] + x[N-1, 1, 0] + x[N-1, 0, 1])

x[N-1, N-1, 0] = 0.33 * (x[N-2, N-1, 0] + x[N-1, N-2, 0] + x[N-1, N-1, 1])

x[N-1, 0, N-1] = 0.33 * (x[N-2, 0, N-1] + x[N-1, 1, N-1] + x[N-1, 0, N-2])

x[N-1, N-1, N-1] = 0.33 * (x[N-2, N-1, N-1] + x[N-1, N-2, N-1] + x[N-1, N-1, N-2])

```