Skip to content

Commit

Permalink
extrai rFup
Browse files Browse the repository at this point in the history
  • Loading branch information
g7fernandes committed Aug 7, 2019
1 parent 5ff8bb4 commit d48e277
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 115 deletions.
38 changes: 27 additions & 11 deletions csv2vtk_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
import csv, os, shutil
import configparser
from zipfile import ZipFile
try:
import progressbar
pbar = True
Expand All @@ -28,13 +29,14 @@
folder = 'result'
i = 1


while aux:
try:
os.mkdir(folder)
aux = False
except FileExistsError:
print('Folder {} exists'.format(folder))
opt = input('Overwrite? [y/n]')
opt = input('Overwrite? [y/n] ')
if opt == 'y' or 'opt' == 'Y':
aux =False
else:
Expand All @@ -54,6 +56,7 @@
N = int(config['global']['N'].split()[0])
nimpre = int(config['global']['nimpre'].split()[0])
ntype = int(config['global']['Ntype'].split()[0])
print_TC = int(config['global']['print_TC'].split()[0])
quant = []
rs = [] # raio sólido
sigma = []
Expand Down Expand Up @@ -82,11 +85,6 @@
rsol[j+k] = rs[i]
k = sum(quant[0:i+1])


# a = input("a")
# for i in range(len(rsol)):
# print("{} {}".format(i,rsol[i]))

# Ler os arquivos e colocá-los em vetores

x = np.zeros(N)
Expand All @@ -103,9 +101,12 @@

nID = np.linspace(1,N,N)

zip_positions = ZipFile(via+'/'+folder+'/positions.zip','w')
zip_velocities = ZipFile(via+'/'+folder+'/velocities.zip','w')

print('Converting...')
if pbar:
bar = progressbar.ProgressBar(max_value=nimpre)
bar = progressbar.ProgressBar(max_value=nimpre+1)
for fnum in range(0,nimpre+1):
with open('temp/position.csv.'+str(fnum),encoding='utf-8') as file_locus:
csv_lector = csv.reader(file_locus,delimiter = ',')
Expand All @@ -114,8 +115,8 @@
x[i] = linea[0]
y[i] = linea[1]
i = i+1
shutil.move(via+'/temp/position.csv.'+str(fnum),via+'/'+folder+'/position.csv.'+str(fnum))

zip_positions.write(via+'/temp/position.csv.'+str(fnum), 'position.csv.'+str(fnum))
# shutil.move(via+'/temp/position.csv.'+str(fnum),via+'/'+folder+'/position.csv.'+str(fnum))
with open('temp/velocity.csv.'+str(fnum),encoding='utf-8') as file_velocitas:
csv_lector = csv.reader(file_velocitas,delimiter = ',')
i = 0
Expand All @@ -124,7 +125,8 @@
vy[i] = linea[1]

i = i+1
shutil.move(via+'/temp/velocity.csv.'+str(fnum),via+'/'+folder+'/velocity.csv.'+str(fnum))
zip_velocities.write(via+'/temp/velocity.csv.'+str(fnum),'velocity.csv.'+str(fnum))
# shutil.move(via+'/temp/velocity.csv.'+str(fnum),via+'/'+folder+'/velocity.csv.'+str(fnum))

fin = 0
grupo = 0
Expand All @@ -144,8 +146,21 @@

if pbar:
bar.update(fnum)


zip_positions.close()
zip_velocities.close()

shutil.rmtree('temp')


if print_TC == 1:
a = os.listdir('temp2')
zip_rFup = ZipFile(via+'/'+folder+'/rFuP.zip','w')
for f in a:
zip_rFup.write(via+'/temp2/'+f,f)
# shutil.move(via+'/temp2/'+f,via+'/'+folder + '/' + f)
zip_rFup.close()
shutil.rmtree('temp2')

with open("settings.txt","a") as settingstxt:
settingstxt.write("[out_files]\n")
Expand All @@ -168,6 +183,7 @@
with open('.gitignore','a+') as file:
file.write(folder+'\n')


#with open('cell.csv.'+str(fnum),encoding='utf-8') as file_velocitas:
#csv_lector = csv.reader(file_velocitas,delimiter = ',')
#i = 0
Expand Down
208 changes: 128 additions & 80 deletions lennard.f90

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Defining variables
objects = m_config.o linkedlist.o mod1.o saida.o lennard.o data.o mod0.o matprint.o randnormal.o
f90comp = mpiifort
switch = -O3
switch = -O3 -assume protect_parens,minus0 -prec-div -prec-sqrt
# Makefile
execname: $(objects)
$(f90comp) -o lennard.out $(switch) $(objects)
$(f90comp) -o lennard $(switch) $(objects)
randnormal.mod: randnormal.o randnormal.f90
$(f90comp) -c $(switch) randnormal.f90
mod1.mod: mod1.o mod1.f90
Expand Down
2 changes: 2 additions & 0 deletions part_gen_pequeno.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
p1[cont,:] = [i*spac+refe[0],j*spac+refe[1]]
cont = cont+1

# np.random.shuffle(p1)

with open(arquivo1,'w') as file:
for i in range(N):
file.write('{},{}\n'.format(p1[i,0],p1[i,1]))
Expand Down
39 changes: 29 additions & 10 deletions pos_e_vel_inicial_usando_sim_anterior.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from glob import glob
import os, shutil
import configparser
from zipfile import ZipFile

dirname = os.getcwd() #os.path.dirname(os.path.abspath(__file__))
dirlist = glob(dirname + "/*/")
Expand All @@ -16,8 +17,11 @@
a = int(input("Enter the number of the folder\n"))
res_dir = dirlist[a]

zip_positions = ZipFile(res_dir+'/positions.zip','r')
zip_velocities = ZipFile(res_dir+'/velocities.zip','r')

config = configparser.ConfigParser()
list_files = os.listdir(res_dir)
len_list_files = len(zip_positions.namelist()+zip_velocities.namelist())

if os.path.isfile(res_dir + 'settings.txt'):
config.read(res_dir + 'settings.txt')
Expand All @@ -26,7 +30,7 @@
print('The still not converted to vtk. Probable incomplete simulation.\n'+\
'settings.ini will be used.\n')
config.read(dirname + '/settings.ini')
nimpre = len(list_files)/2
nimpre = len(len_list_files)/2


N = int(config['global']['N'].split()[0])
Expand All @@ -39,27 +43,42 @@
quant.append(int(config['par_'+str(i)]['quantidade'].split()[0]))
x_files.append(config['par_'+str(i)]['x'].split()[0])
x_files[-1] = x_files[-1][1:len(x_files[-1])-1]
v_files.append(config['par_'+str(i)]['v_file'].split()[0])
v_files[-1] = v_files[-1][1:len(v_files[-1])-1]
try:
v_files.append(config['par_'+str(i)]['v_file'].split()[0])
v_files[-1] = v_files[-1][1:len(v_files[-1])-1]
except:
print("no velocity file used")
v_files.append('v_file_'+str(i))
pass

step = input('Extract step no. (max {}) '.format(nimpre-1))

positions = []
with open(res_dir + 'position.csv.'+step) as file:
with zip_positions.open('position.csv.'+step) as file:
for line in file:
positions.append(line)
velocities = []
with open(res_dir + 'velocity.csv.'+step) as file:
with zip_velocities.open('velocity.csv.'+step) as file:
for line in file:
velocities.append(line)


# positions = []
# with open(res_dir + 'position.csv.'+step) as file:
# for line in file:
# positions.append(line)
# velocities = []
# with open(res_dir + 'velocity.csv.'+step) as file:
# for line in file:
# velocities.append(line)

# verificar se não é desejavel fazer backup de arquivos de posição e velocidade
a == 'n'
i = 0
for f in x_files + v_files:
if os.path.isfile(f) and a == 'n':
a = input('Old positions files exist. Backup? y/n')
if a != 'n' or a != 'N':
a = input('Old positions files exist. Backup? y/n ')
if a != 'n' or a != 'N':
try:
if i == 0:
bkp = 'bkp'
Expand All @@ -80,14 +99,14 @@

k = 0
for i in range(ntype):
with open(x_files[i],'w') as file:
with open(x_files[i],'wb') as file:
for j in range(quant[i]):
file.write(positions[k])
k += 1

k = 0
for i in range(ntype):
with open(v_files[i],'w') as file:
with open(v_files[i],'wb') as file:
for j in range(quant[i]):
file.write(velocities[k])
k += 1
Expand Down
15 changes: 13 additions & 2 deletions saida.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ subroutine vec2csv(v,n,d,prop,step,t,nimpre,start)
character(4) :: extensao = '.csv', passo
real(dp) :: time
real(dp), save :: timep, etc, dtimepp
character(LEN=*),parameter :: fmt5 = '(f32.16, ", ",f32.16, ", ",f32.16, ", ",f32.16, ", ",f32.16 )'
character(LEN=*),parameter :: fmt6 = '(f5.0, ", ",f32.16, ", ",f32.16, ", ",f32.16, ", ",f32.16, ", ",f32.16 )'

write(passo,'(i0)') step
open(10,file='temp/'//prop//extensao//'.'//trim(passo),status="replace")
if (d <= 3) then
open(10,file='temp/'//prop//extensao//'.'//trim(passo),status="replace")
else
open(10,file='temp2/'//prop//extensao//'.'//trim(passo),status="replace")
end if
if (d == 1) then
do i = 1,n
write(10,*) v(i,1)
Expand All @@ -33,9 +39,14 @@ subroutine vec2csv(v,n,d,prop,step,t,nimpre,start)
end do
else if (d == 5) then
do i = 1,n
write(10,*) v(i,1),',',v(i,2),',',v(i,3),',',v(i,4),',',v(i,5)
write(10,fmt5) v(i,1),v(i,2),v(i,3),v(i,4),v(i,5)
end do
else if (d == 6) then
do i = 1,n
write(10,fmt6) v(i,1),v(i,2),v(i,3),v(i,4),v(i,5),v(i,6)
end do
end if

close(10)

if (prop == "position") then
Expand Down
10 changes: 5 additions & 5 deletions settings.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# PARAMETROS GLOBAIS
[global]
nimpre = 5000 # quntidade de saidas
N = 1089 # número de partículas
nimpre = 50 # quntidade de saidas
N = 108 #9 # número de partículas
Ntype = 1 # número de tipos de partícula
t_fim = 50 # tempo de execução
t_fim = 5 # tempo de execução
nimpre_init = 0 # começa a simular a partir no tempo referente ao snapshot (nimpre).
dt = 0.0001 # passo de tempo
dimX = 410 # Dimensões da região de cálculo
Expand All @@ -20,7 +20,7 @@
vd = 2 2 # velocidade distribuida com Maxwell Boltzmann
NMPT = 100 # Número máximo de partículas que poderá mudar de process. Se não souber estimar, usar -1 ou o valor de N.
GField = 0 0 # Campo de força gravitacional que afeta todas as partículas
print_TC = 0 # imprimir dados para calcular coeficiente de transporte
print_TC = 1 # imprimir dados para calcular coeficiente de transporte
# PARTICLE PROPERTIES
# v é velocidade global, entrar dois número correspondentes ao vetor vx vy que serão aplicadas em todas as partículas
# se v_file é dada, então ela será usada para dar a velocidade às partículas. Deve ser arquivo .csv. Deixar "%" se não usar.
Expand All @@ -32,7 +32,7 @@
nome = 'g1'
sigma = 2 # Lennard Jones
epsilon = 1 # Lennard Jones
quantidade = 1089
quantidade = 108 #9
x_lockdelay = 0 # só vai poder mudar de posição a partir de t = x_lockdelay
rs = 0 # raio sólido. Posição de partículas na superfície de um sólido de raio rs
fric_term = 0 # fricção artifical
Expand Down
22 changes: 17 additions & 5 deletions teste.f90
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
program teste
use mod1
! use mod1

call system('mkdir temp')
open(10,file='temp/test.txt',status="replace")
write(10,*) 'lalalala'
print*,'a'
! call system('mkdir temp')
! open(10,file='temp/test.txt',status="replace")
! write(10,*) 'lalalala'
! print*,'a'

implicit none
real :: a,b,c,d
character(LEN=*), parameter :: fmt = '(f16.0, ", ",f32.16, ", ",f32.16, ", ",f32.16, ", ",f32.16 )'
character(170) :: out

a = 12.0
b = 1.2
c = sqrt(2.0)
d = -sqrt(3.0)
write(out,fmt) a,b,c,d,d
out = trim(out)
write(*,*) out



Expand Down

0 comments on commit d48e277

Please sign in to comment.