Skip to content

Commit

Permalink
primeiro cometimento
Browse files Browse the repository at this point in the history
  • Loading branch information
g7fernandes committed May 28, 2019
0 parents commit 72556f1
Show file tree
Hide file tree
Showing 18 changed files with 7,239 additions and 0 deletions.
121 changes: 121 additions & 0 deletions csv2vtk_particles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 9 13:03:06 2019
Este programa lê arquivos CSV onde cada arquivo é um passo de tempo e cada
linha é uma partícula e exporta em vtk o reultado.
@author: gabriel
"""

from evtk.hl import pointsToVTK
import numpy as np
import csv, os, shutil
import configparser

via = os.getcwd()

aux = True
folder = 'result'
i = 1

while aux:
try:
os.mkdir(folder)
aux = False
except FileExistsError:
print('Folder {} exists'.format(folder))
opt = input('Overwrite? [y/n]')
if opt == 'y' or 'opt' == 'Y':
aux =False
else:
folder = input('Enter new folder name:\n')
if len(folder) == 0:
folder = 'result' + '_' + str(i)
aux = True
i = i+1

print('The results will be saved at {}'.format(folder))

#Ler a quantidade de arquivos de settings.

config = configparser.ConfigParser()
config.read('settings.ini')

N = int(config['global']['N'].split()[0])
nimpre = int(config['global']['nimpre'].split()[0])
ntype = int(config['global']['Ntype'].split()[0])
quant = []

for i in range(ntype):
quant.append(int(config['par_'+str(i)]['quantidade'].split()[0]))

a = os.listdir('temp')
if len(a)/2 < nimpre:
print("Propable incomplete execution. Processing {} files\n.".format(len(a)/2))
nimpre = int(len(a)/2)-1

tipo = np.zeros(N)
j,k = 0,0
for i in range(len(quant)):
for j in range(quant[i]):
tipo[j+k] = i
k = quant[i]

# Ler os arquivos e colocá-los em vetores

x = np.zeros(N)
y = np.zeros(N)
z = np.zeros(N)

vx = np.zeros(N)
vy = np.zeros(N)
vz = np.zeros(N)

cx = np.zeros(N)
cy = np.zeros(N)
cz = np.zeros(N)

try:
shutil.move(via+'/settings.txt',via+'/'+folder+'/settings.txt')
except:
print('No settings file found!\n')

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 = ',')
i = 0
for linea in csv_lector:
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))

with open('temp/velocity.csv.'+str(fnum),encoding='utf-8') as file_velocitas:
csv_lector = csv.reader(file_velocitas,delimiter = ',')
i = 0
for linea in csv_lector:
vx[i] = linea[0]
vy[i] = linea[1]

i = i+1

shutil.move(via+'/temp/velocity.csv.'+str(fnum),via+'/'+folder+'/velocity.csv.'+str(fnum))

#with open('cell.csv.'+str(fnum),encoding='utf-8') as file_velocitas:
#csv_lector = csv.reader(file_velocitas,delimiter = ',')
#i = 0
#for linea in csv_lector:
#cx[i] = int(float(linea[0]))
#cy[i] = int(float(linea[1]))

#i = i+1

#shutil.move(via+'/cell.csv.'+str(fnum),via+'/'+folder+'/cell.csv.'+str(fnum))

pointsToVTK(via+'/'+folder +'/result_'+str(fnum), x, y, z, data = {"Vx" : vx, "Vy" : vy, "Tipo" : tipo}) #, "Cellx" : cx, "Celly" : cy

shutil.rmtree('temp')


31 changes: 31 additions & 0 deletions data.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module data
use mod1
use linkedlist

private
public :: data_t
public :: data_ptr

! Data is stored in data_t
type :: data_t
real(dp),dimension(2) :: x !posição
real(dp),dimension(2) :: v !velocidade
real(dp),dimension(2) :: F !força nela
integer :: grupo !grupo que a partícula pertence
integer :: n !numero da partícula
logical :: flag ! bandeira auxiliar
end type data_t

! A trick to allow us to store pointers in the list
type :: data_ptr
type(data_t), pointer :: p
end type data_ptr



! pra fazer vetor de ponteiro
! type :: container
! type(list_t), pointer :: list => null()
! end type container

end module data
Loading

0 comments on commit 72556f1

Please sign in to comment.