-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDense_A.py
More file actions
86 lines (72 loc) · 2.05 KB
/
Dense_A.py
File metadata and controls
86 lines (72 loc) · 2.05 KB
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
import numpy as np
def Poisson_Solver_Neumann(Nx, Ny):
"""Solves the 2D Poisson equation implicitly on a staggered grid
using Neumann Boundary Conditions
Params:
------
u, v 2D array of float, x and y velocities
Nx, Ny float, Number of segments in x and y
dt float, time step size
T float, current time
X, Y 2D array of float, meshgrid
Returns:
-------
ANeum 2D array of float, A matrix with Neumann conditions
f_RHSn 1D array of float, f(x,y) for Neumann conditions
"""
#Building A
ANeum = np.zeros((Nx*Ny,Nx*Ny),dtype=float)
a = 1.0
b = 1.0
c_int = -4.0
c_edge = -3.0
c_corner = -2.0
d = 1.0
e = 1.0
#Set corner points
ANeum[0,0] = c_edge
ANeum[-1,-1] = c_corner
ANeum[Nx*Ny-Ny,Nx*Ny-Ny] = c_corner
ANeum[Ny-1,Ny-1] = c_corner
#Set edges in first block
for j in range(1,Ny-1):
ANeum[j,j] = c_edge
j +=j
#Set edges in last block
for j in range((Nx*Ny)-Ny,(Nx*Ny)-2):
ANeum[j+1,j+1] = c_edge
j +=j
#Set edges along main diagonal except for first block
for j in range(Nx+1,Ny*Nx):
if j % Nx ==0:
ANeum[j-1,j-1] = c_edge
j +=j
#Set edges on main diagonal except for last block
for j in range(Nx,(Ny*Nx)-Nx):
if j % Nx ==0:
ANeum[j,j] = c_edge
j +=j
#Second diagonal above and below diagonal
for j in range(Ny,Ny*Nx):
ANeum[j,j-Ny] = a
ANeum[j-Nx,j] = e
j +=j
#first diagonal below main diagonal
for j in range(1,Ny*Nx):
if j % Ny ==0:
ANeum[j,j-1] = 0
else:
ANeum[j,j-1] = b
j +=j
#first diagonal above main diagonal
for j in range(0,Ny*Nx):
if j % Nx ==0:
ANeum[j-1,j] = 0
else:
ANeum[j-1,j] = d
j +=j
#Main Diagonal
for j in range(0,Ny*Nx):
if ANeum[j,j] ==0:
ANeum[j,j] = c_int
return ANeum