-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelocity_and_distribution_analysis.py
128 lines (119 loc) · 5.07 KB
/
velocity_and_distribution_analysis.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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import pandas as pd
import os
from glob import glob
import configparser
dirname = os.path.dirname(os.path.abspath(__file__))
dirlist = glob(dirname + "/*/")
print("Choose a folder there the results are contained:\nNo | Folder")
for a in range(len(dirlist)):
print("{} | {}\n".format(a,dirlist[a]))
a = int(input("Enter the number of the folder\n"))
res_dir = dirlist[a]
config = configparser.ConfigParser()
config.read(res_dir + 'settings.txt')
dimx = float(config['global']['dimX'].split()[0])
dimy = float(config['global']['dimY'].split()[0])
n_files = int(config['out_files']['out_files'].split()[0])
subspaces = float(input("Enter in how many subspaces the region of calculus will be divided.\nThe \
subspaces should contain particles enough for the statistic.\n"))
print("The velocity and distribution of the particles will be calculated in one direction.\n")
#direction = input("Enter the direction x or y\n")
print('x-direction\n')
direction = 'x'
step = input('Choose step:\n')
while int(step) >= 0:
pos = pd.read_csv(res_dir+"position.csv."+step, header=None, names = ["x","y"])
vel = pd.read_csv(res_dir+"velocity.csv."+step, header=None, names = ["v_x", "v_y"])
n = [x for x in range(len(pos))]
n = pd.DataFrame(n, columns=["n"]) # numero id da partícula
pos_vel = pd.concat([n,pos,vel],axis=1)
pos_vel = pos_vel.sort_values(by=[direction])
pos_vel.reset_index(drop=True, inplace=True)
j = int(0)
concentration_map = np.zeros(int(subspaces))
velocity_map = np.zeros(int(subspaces))
if (direction == 'x'):
aux = dimx/subspaces
for i in range(int(subspaces)):
if (j < len(pos_vel)):
x = pos_vel.loc[j,'x']
while ((i+1)*aux > x and j < len(pos_vel)-1):
concentration_map[i] += 1
velocity_map[i] += np.sqrt(pos_vel.loc[j,'v_x']**2 + pos_vel.loc[j,'v_y']**2)
j += 1
x = pos_vel.loc[j,'x']
mean_Kenergy = (1/2)*velocity_map**2/concentration_map
mean_Kenergy[mean_Kenergy == np.inf] = 0
mean_Kenergy = np.nan_to_num(mean_Kenergy)
fig, ax1 = plt.subplots()
ax1.plot(np.linspace(0,dimx,subspaces),mean_Kenergy,'b')
ax1.set_xlabel("x - direction")
ax1.set_ylabel("Mean kinetic energy", color='b')
ax2 = ax1.twinx()
ax2.plot(np.linspace(0,dimx,subspaces),concentration_map, 'r')
ax2.set_ylabel("Number of density",color='r')
#plt.axis([0,dimx,np.min(mean_Kenergy),np.max(mean_Kenergy)])
fig.tight_layout()
plt.show(block=True)
step = input('Choose step or enter -1 to stop:\n')
#def init():
# concentration_map = [np.nan]*int(subspaces)
# mean_Kenergy = [np.nan]*int(subspaces)
# ax1.plot(np.linspace(0,dimx,subspaces),mean_Kenergy,'b')
# ax1.set_xlabel("x - direction")
# ax1.set_ylabel("Mean kinetic energy", color='b')
#
# ax2.plot(np.linspace(0,dimx,subspaces),concentration_map, 'r')
# ax2.set_ylabel("Number of density",color='r')
# #plt.axis([0,dimx,np.min(mean_Kenergy),np.max(mean_Kenergy)])
# fig.tight_layout()
#
#
#def animate(i):
# pos = pd.read_csv(res_dir+"position.csv."+step, header=None, names = ["x","y"])
# vel = pd.read_csv(res_dir+"velocity.csv."+step, header=None, names = ["v_x", "v_y"])
# n = [x for x in range(len(pos))]
# n = pd.DataFrame(n, columns=["n"]) # numero id da partícula
# pos_vel = pd.concat([n,pos,vel],axis=1)
# pos_vel = pos_vel.sort_values(by=[direction])
# pos_vel.reset_index(drop=True, inplace=True)
#
# j = int(0)
# concentration_map = np.zeros(int(subspaces))
# velocity_map = np.zeros(int(subspaces))
# if (direction == 'x'):
# aux = dimx/subspaces
# for i in range(int(subspaces)):
# if (j < len(pos_vel)):
# x = pos_vel.loc[j,'x']
# while ((i+1)*aux > x and j < len(pos_vel)-1):
# concentration_map[i] += 1
# velocity_map[i] += np.sqrt(pos_vel.loc[j,'v_x']**2 + pos_vel.loc[j,'v_y']**2)
# j += 1
# x = pos_vel.loc[j,'x']
# mean_Kenergy = (1/2)*velocity_map**2/concentration_map
# mean_Kenergy[mean_Kenergy == np.inf] = 0
# mean_Kenergy = np.nan_to_num(mean_Kenergy)
# ax1.plot(np.linspace(0,dimx,subspaces),mean_Kenergy,'b')
# ax1.set_xlabel("x - direction")
# ax1.set_ylabel("Mean kinetic energy", color='b')
#
# ax2.plot(np.linspace(0,dimx,subspaces),concentration_map, 'r')
# ax2.set_ylabel("Number of density",color='r')
# fig.tight_layout()
# #plt.axis([0,dimx,np.min(mean_Kenergy),np.max(mean_Kenergy)])
# return ax1
#
#
#
#animate = input('Make animation?(y/n) ')
#if animate == 'y':
# fig, ax1 = plt.subplots()
# ax2 = ax1.twinx()
# ani = animation.FuncAnimation(fig, animate,frames=n_files, interval=2, save_count=n_files)
# # ani = animation.FuncAnimation(fig, animate,frames=n_files, init_func=init, interval=2, blit=True, save_count=n_files)
#
#plt.show()