-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.py
71 lines (47 loc) · 1.86 KB
/
grid.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
#!/usr/bin/env python
# coding: utf-8
# In[15]:
import concurrent.futures
from abc import abstractmethod
import matplotlib.pyplot as plt
import numpy as np
# In[16]:
def mesh(NX, NY, DOMAIN_SIZE_X, DOMAIN_SIZE_Y):
pass
class mesh_grid():
def __init__(self):
pass
#------------------------------------------------#
@abstractmethod
def mesh(NX, NY, DOMAIN_SIZE_X, DOMAIN_SIZE_Y):
#------------------------------------------------#
DX = 2/(NX -1) #element length in x direction
DY = 2/(NY -1) #element length in y direction
element_length = DX
#------------------------------------------------#
x = np.linspace(0, DOMAIN_SIZE_X, NX) #range in xdirection
y = np.linspace(0, DOMAIN_SIZE_Y, NY) #range in ydirection
X, Y = np.meshgrid(x,y) #X, Y are 2d arrays containing same range again and again
#------------------------------------------------#
#Parallelizing "mesh_grid" Using "futures3"
with concurrent.futures.ProcessPoolExecutor() as executor:
executor.map(mesh(NX, NY, DOMAIN_SIZE_X, DOMAIN_SIZE_Y), (x, y))
#------------------------------------------------#
plot_mesh.mesh_plot(X,Y)
return [X, Y, DX, DY]
# In[14]:
class plot_mesh():
def __init__(self):
pass
def mesh_plot(X, Y):
from matplotlib.pyplot import figure
#Plotting the mesh
print('\nOUTPUT: Plotting the mesh in two dimension')
figure(figsize=(6, 5), dpi=80)
plt.plot(X, Y, color = 'g', marker='o',markersize = 4, linestyle='-')
plt.plot(np.transpose(X), np.transpose(Y), color = 'g', linestyle='-')
plt.xlabel('xdirection', fontsize = 12)
plt.ylabel('ydirection', fontsize = 12)
plt.title('Discritized domain in 2d', fontsize = 12)
plt.show()
return None