43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
import sys, array, re, math
|
|
file_in = open(sys.argv[1]+'.ang','r')
|
|
file_out = open(sys.argv[1]+'_material.config_pt1','w')
|
|
file_out.write('<homogenization>\n[SX]\ntype isostrain\nNgrains 1 \n\n<microstructure>\n')
|
|
file_out2 = open(sys.argv[1]+'_material.config_pt2','w')
|
|
file_out2.write('<texture>\n')
|
|
data=array.array('f',[0.0,0.0,0.0])
|
|
resY = 1
|
|
resX = 0
|
|
dimX = 0.0
|
|
dimY = 0.0
|
|
i=0
|
|
for line in file_in:
|
|
if line[0]!='#':
|
|
i = i +1
|
|
data[0] = float(re.findall('\S*',str(line))[0])/2.0/math.pi*360.0
|
|
data[1] = float(re.findall('\S*',str(line))[2])/2.0/math.pi*360.0
|
|
data[2] = float(re.findall('\S*',str(line))[4])/2.0/math.pi*360.0
|
|
phasef = float(re.findall('\S*',str(line))[20])
|
|
if phasef>10000.0:
|
|
phase=1
|
|
else:
|
|
phase=2
|
|
if float(re.findall('\S*',str(line))[6]) < dimX:
|
|
dimX=0.0
|
|
resX=1
|
|
resY= resY + 1
|
|
else:
|
|
resX=resX+1
|
|
dimX = float(re.findall('\S*',str(line))[6])
|
|
file_out.write('[Grain'+str(i)+']\ncrystallite 1\n(constituent)'+\
|
|
' phase '+str(phase)+' texture '+str(i)+' fraction 1.0\n')
|
|
file_out2.write('[Grain'+str(i)+']\n(gauss) phi1 '+str(data[0])+\
|
|
' Phi '+str(data[1])+' phi2 '+str(data[2])+' scatter 0.0 fraction 1.0\n')
|
|
dimY = float(re.findall('\S*',str(line))[8])
|
|
dimZ = min(dimX/resX,dimY/resY)
|
|
file_out3 = open(sys.argv[1]+'.geom','w')
|
|
file_out3.write('resolution a '+str(resX)+' b '+str(resY)+' c 1 \ndimension x '+str(dimX)+' y '+str(dimY)+' z '+str(dimZ)+'\nhomogenization 1\n')
|
|
for x in xrange(resX*resY):
|
|
file_out3.write(str(x+1)+'\n')
|