forked from 541435721/myVTKPythonLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadDynaDeformationGradients.py
46 lines (33 loc) · 1.75 KB
/
readDynaDeformationGradients.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
#coding=utf8
########################################################################
### ###
### Created by Martin Genet, 2012-2016 ###
### ###
### University of California at San Francisco (UCSF), USA ###
### Swiss Federal Institute of Technology (ETH), Zurich, Switzerland ###
### École Polytechnique, Palaiseau, France ###
### ###
########################################################################
import myVTKPythonLibrary as myVTK
########################################################################
def readDynaDeformationGradients(
mesh,
hystory_files_basename,
array_name,
verbose=1):
myVTK.myPrint(verbose, "*** readDynaDeformationGradients ***")
n_cells = mesh.GetNumberOfCells()
history_files_names = [hystory_files_basename + '.history#' + str(num) for num in xrange(11,20)]
F_list = [[0. for k_component in xrange(9)] for k_cell in xrange(n_cells)]
for k_component in xrange(9):
history_file = open(history_files_names[k_component], 'r')
for line in history_file:
if line.startswith('*') or line.startswith('$'): continue
line = line.split()
F_list[int(line[0])-1][k_component] = float(line[1])
history_file.close()
F_array = myVTK.createFloatArray(array_name, 9, n_cells)
for k_cell in xrange(n_cells):
F_array.SetTuple(k_cell, F_list[k_cell])
myVTK.myPrint(verbose-1, "n_tuples = "+str(F_array.GetNumberOfTuples()))
mesh.GetCellData().AddArray(F_array)