-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_tag_values_final.sh
executable file
·164 lines (130 loc) · 3.96 KB
/
get_tag_values_final.sh
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
#!/usr/bin/python
#get the tag values from the h5m file and print as a list: tag_values
from itaps import iMesh,iBase
import string
datafile = "test_models/test_4.h5m"
mesh = iMesh.Mesh()
mesh.load(datafile)
ents = mesh.getEntities()
print mesh.getEntType(ents)
ents = mesh.getEntities(iBase.Type.all, iMesh.Topology.triangle)
print len(ents)
mesh_set = mesh.getEntSets()
print len(mesh_set)
tag_values=[]
found_all_tags=0
for i in mesh_set:
if found_all_tags == 1:
break
# get all the tags
tags = mesh.getAllTags(i)
#print tags
# loop over the tags checking for name
for t in tags:
# if we find name
if t.name == 'NAME':
# the handle is the tag name
t_handle = mesh.getTagHandle(t.name)
# get the data for the tag, with taghandle in element i
tag = t_handle[i]
a=[]
# since we have a byte type tag loop over the 32 elements
for part in tag:
# if the byte char code is non 0
#print part
if (part != 0 ):
# convert to ascii
a.append(str(unichr(part)))
# join to end string
test=''.join(a)
# the the string we are testing for is not in the list of found
# tag values, add to the list of tag_values
if not any(test in s for s in tag_values):
tag_values.append(test)
#print test
# if the tag is called impl_complement, this is the
# last tag we are done
if any('impl_complement' in s for s in tag_values):
found_all_tags=1
print('------------------------')
#detecting the material name and density and create a list with 'mat="NAME"' as the key and 'rho=-$.$$' as the stored value.
print('tag_values:')
print tag_values
global list
list=[]
materialdensity={}
for l in range(len(tag_values)) :
if '/' in tag_values[l] :
index=tag_values[l].index('/')
#print tag_values[l][0:index]
list.append(tag_values[l][0:index])
a=index+1
materialdensity[tag_values[l][0:index]]=tag_values[l][a:len(tag_values[l])]
#print list
newlist=[]
for w in range(len(list)) :
newlist.append(list[w][4:len(list[w])])
#print len(list)
print materialdensity
# writing the materials provided in a text to mcnp.
from pyne import material
from pyne import mcnp
from pyne.material import Material
global a
global f
a=[]
global materialz
materialz=Material()
matz=Material()
print('materials :')
print newlist
#counting the number of lines in the material text
def flines(n) :
global lines
i=0
f=open('material2.txt','r')
a=f.readlines()
for line in enumerate(a) :
i=i+1
lines = i
print('number of lines in the text is: %i' %lines)
flines(1)
#calling flines needs modification!!
matposition={}
for mat in newlist :
b=open('material2.txt','r')
for k in range(lines) :
while mat in b.readline() :
print mat, (': %i' %k)
matposition[k]=mat
print matposition
print sorted(matposition.keys())
sortedkeys=sorted(matposition.keys())
x=open('material2.txt','r')
for k in sortedkeys :
print k
#f=open('matmcnp.txt','w')
#x=open('material2.txt','r')
for mat in newlist :
if mat == matposition[k] :
p=open('matmcnp.txt','w')
ll=int(k)
if k == int(sortedkeys[len(sortedkeys)-1]) :
ul=lines
else :
ul=int(sortedkeys[sortedkeys.index(k)+1])
#print(type(sortedkeys.index(k)+1))
print ll, ul
for j in range(ll,ul) :
p.write(x.readline())
p.close()
materialz.from_text('matmcnp.txt')
materialz.write_mcnp('txtmcnp.txt',frac_type='mass')
x.close()
'''
issues to consider:
1) materials names in the material text cannot occur more than once!!!
'water' and 'steel and water' caused conflict !!!
2) created mcnp input without numbers!!
3) how to get the tags on the h5m file to match the created mcnp materials!!!
'''