-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviscosity_allen.py
176 lines (150 loc) · 5.61 KB
/
viscosity_allen.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import numpy as np
import pandas as pd
import os
import configparser
import matplotlib.pyplot as plt
from glob import glob
import time
import curses # para progressbar
def integral(F,i,j,dt):
# sh = np.shape(F)
I = np.trapz(F[i,j,:],dx=dt)
# I = np.zeros((sh[0],sh[1]))
# xi = [-np.sqrt(3/5), 0, np.sqrt(3/5)]
#xp = np.linspace(0, dt*sh[2], sh[2])
#w = [5/9, 8/9, 5/9]
# for i in range(sh[0]):
# for j in range(sh[1]):
# for s in range(sh[2]-1):
# I[i,j] += 0.5*(dt)*( \
# w[0]*np.interp( dt*xi[0]/2 + ((s+1)*dt+s*dt)/2 , xp, F[i,j,:]) + \
# w[1]*np.interp( dt*xi[0]/2 + ((s+1)*dt+s*dt)/2 , xp, F[i,j,:]) + \
# w[2]*np.interp( dt*xi[0]/2 + ((s+1)*dt+s*dt)/2 , xp, F[i,j,:]) \
# )
return I
def progressbar(step,total,message, stdscr):
# usar import curses
# inicializar uma strig vazia fora do loop para stdcr
if step == 0:
stdscr = curses.initscr()
stdscr.addstr(0, 0, message + "|" + " "*20 + "| {} %".format(0))
stdscr.refresh()
return stdscr
elif step < total-1:
a = int(20*step/total)
b = 20-a
stdscr.addstr(0, 0, message + "|" + "#"*a + " "*b + "| {} %".format(5*a))
stdscr.refresh()
return stdscr
#print("#",end='')
else:
a = int(20*step/total)
b = 20-a
stdscr.addstr(0, 0, message + "|" + "#"*a + " "*b + "| {} %".format(5*a))
curses.endwin()
print("\n")
return "0"
dirname = os.getcwd() #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')
N = int(config['global']['N'].split()[0])
dimx = float(config['global']['dimX'].split()[0])
dimy = float(config['global']['dimY'].split()[0])
n_files = int(config['out_files']['out_files'].split()[0])
ntype = int(config['global']['Ntype'].split()[0])
t_fim = float(config['global']['t_fim'].split()[0])
dt = float(config['global']['dt'].split()[0])
F = np.array([0,0])
quant = []
sigma = []
epsilon = []
rs = [] # raio sólido
mass = []
tipo = [0]*N
dt = t_fim/n_files
a = input("Enter the subdomains mesh dimensions.\n")
a = a.split()
mesh = np.array([int(a[0]), int(a[1])])
a = input("Enter a location. xmin xmax ymin ymax\n")
if a == '':
region = [0, mesh[0], 0, mesh[1]]
else:
region = [int(x) for x in a.split()]
Vol = (dimx/mesh[0])*(dimy/mesh[1]) # volume dos elementos da malha
for i in range(ntype):
quant.append(int(config['par_'+str(i)]['quantidade'].split()[0]))
rs.append(float(config['par_'+str(i)]['rs'].split()[0]))
sigma.append(float(config['par_'+str(i)]['sigma'].split()[0]))
epsilon.append(float(config['par_'+str(i)]['epsilon'].split()[0]))
mass.append(float(config['par_'+str(i)]['m'].split()[0]))
j,k = 0,0
for i in range(len(quant)):
for j in range(quant[i]):
tipo[j+k] = i
k = sum(quant[0:i+1])
tipo = pd.DataFrame(tipo, columns=["tipo"]) # numero id da partícula
hx = dimx/mesh[0]
hy = dimy/mesh[1]
nsteps = n_files # int(input('Enter the number of steps:\n'))
density_map = np.zeros((mesh[0],mesh[1], nsteps+1))
r = np.zeros((mesh[0],mesh[1],nsteps+1))
dQm = np.zeros(nsteps)
eta = np.zeros(nsteps)
step = 0
n1,n2 = 0,0
stdscr = 's' #para barra de progresso
sample_list = []
r0 = []
p0 = []
Qxy = np.zeros((nsteps,1))
Qyx = np.zeros((nsteps,1))
#eta = np.zeros((nsteps,1))
while step <= nsteps:
particle_map = [[[] for _ in range(mesh[1])] for _ in range(mesh[0])]
#stdscr = progressbar(step,nsteps,'Computing:',stdscr)
print(step)
pos = pd.read_csv(res_dir+"position.csv."+str(step), header=None, names = ["x","y"])
vel = pd.read_csv(res_dir+"velocity.csv."+str(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,tipo],axis=1)
for nn in range(len(pos_vel)):
xp = int(pos_vel.loc[nn,'x']//hx)
yp = int(pos_vel.loc[nn,'y']//hy)
if xp == mesh[0]:
xp = xp - 1
if yp == mesh[1]:
yp = yp - 1
particle_map[xp][yp].append( pos_vel.loc[nn,'n'] )
density_map[xp,yp,step] += 1
if (step == 0):
for i in range(region[0],region[1]):
for j in range(region[2],region[3]):
for nn in range(len(particle_map[i][j])):
sample_list.append(particle_map[i][j][nn])
n1 = particle_map[i][j][nn]
r0.append([pos_vel.loc[n1,'x'], pos_vel.loc[n1,'y']])
m = mass[pos_vel.loc[n1,'tipo']]
p0.append([pos_vel.loc[n1,'v_x']*m, pos_vel.loc[n1,'v_y']*m])
r0 = np.array(r0)
r1 = np.zeros( (len(sample_list),2) )
p0 = np.array(p0)
p1 = np.zeros( (len(sample_list),2) )
else:
for nn in range(len(sample_list)):
n1 = sample_list[nn]
r1[nn,:] = [pos_vel.loc[n1,'x'], pos_vel.loc[n1,'y']]
m = mass[pos_vel.loc[n1,'tipo']]
p1[nn,:] = [pos_vel.loc[n1,'v_x']*m, pos_vel.loc[n1,'v_y']*m]
Qxy[step-1] = np.sum(r1[:,0]*p1[:,1], axis=0)/Vol
Qyx[step-1] = np.sum(r1[:,1]*p1[:,0], axis=0)/Vol
step += 1
eta = (Qxy - np.sum(r0[:,0]*p0[:,1]))/len(sample_list) #completar
plt.plot(eta)
plt.show()