-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_module.py
More file actions
66 lines (56 loc) · 1.88 KB
/
Copy pathpython_module.py
File metadata and controls
66 lines (56 loc) · 1.88 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
print("Within Python Module File")
import os,sys
HERE = os.getcwd()
sys.path.insert(0,HERE)
import numpy as np
import cupy
from cupy.cuda import memory
import matplotlib.pyplot as plt
data_array = cupy.zeros(shape=(2001,258)) # matches the number of timesteps in the main solver
x = np.arange(start=0,stop=2.0*3.1415926,step=2.0*3.1415926/256)
iternum = 0
def collection_func(input_array):
global data_array,iternum
b = cupy.ndarray(
input_array.__array_interface__['shape'][0],
cupy.dtype(input_array.dtype.name),
cupy.cuda.MemoryPointer(cupy.cuda.UnownedMemory(
input_array.__array_interface__['data'][0],
input_array.size,
input_array,
0), 0),
strides=input_array.__array_interface__['strides'])
data_array[iternum,:] = b[:]
iternum+=1
return None
def analyses_plotField():
global data_array, x
plt.figure()
for i in range(0,cupy.shape(data_array)[0],400):
y = cupy.asnumpy(data_array[i,1:-1])
plt.plot(x,y,label='Timestep '+str(i))
plt.legend()
plt.xlabel('x')
plt.xlabel('u')
plt.title('Field evolution')
plt.savefig('Field_evolution.png')
plt.close()
def analyses_SVD():
global data_array, x
# Perform an SVD on device
data_array = data_array[:,1:-1]
print('Performing SVD')
u,s,v = cupy.linalg.svd(data_array,full_matrices=False)
# Plot SVD eigenvectors
vh = cupy.asnumpy(v)
plt.figure()
plt.plot(x, vh[0,:],label='Mode 0')
plt.plot(x, vh[1,:],label='Mode 1')
plt.plot(x, vh[2,:],label='Mode 2')
plt.legend()
plt.title('SVD Eigenvectors')
plt.xlabel('x')
plt.xlabel('u')
plt.savefig('SVD_Eigenvectors.png')
plt.close()
#DONE