specify which surface(s) you want to tag

This commit is contained in:
Pratheek Shanthraj 2014-10-21 13:57:17 +00:00
parent 84df61d4a0
commit 975e42b132
1 changed files with 36 additions and 90 deletions

View File

@ -2,10 +2,9 @@
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string import os,sys,string
import numpy as np
from optparse import OptionParser
import damask import damask
import re import re
from optparse import OptionParser
scriptID = '$Id$' scriptID = '$Id$'
scriptName = scriptID.split()[1] scriptName = scriptID.split()[1]
@ -26,30 +25,27 @@ def func(seq):
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
Recognize bounding surfaces and append them as physical sufaces in the geo file. """, version = scriptID) Recognize bounding surfaces and append them as physical sufaces in the geo file. """, version = scriptID)
parser.add_option('-n','--numvol', dest = 'N', \ parser.add_option('-n','--numvol', dest = 'N', \
type='int',\ type='int',\
metavar='int',\ metavar='int',\
help='number of physical volumes' ) help='number of physical volumes' )
(options, filename) = parser.parse_args() parser.add_option('-s','--surfaces', dest = 'surfaces', \
action = 'extend', \
type = 'string', \
metavar = '<string LIST>', \
help = 'surfaces to tag (x, y, and/or z)')
print 'options',options (options, filename) = parser.parse_args()
print 'filename',filename
print options.N, type(options.N)
print filename
my_geofile = filename[0] my_geofile = filename[0]
numVol = options.N numVol = options.N
PointCount = 0 PointCount = 0
LineCount = 0 LineCount = 0
LineLoopCount = 0 LineLoopCount = 0
PlaneSurfaceCount = 0
SurfaceLoopCount = 0
point = [] point = []
line = [] line = []
lineloop = [] lineloop = []
plane = []
surface = []
f = open(my_geofile,'r') f = open(my_geofile,'r')
lines = f.readlines() lines = f.readlines()
@ -63,7 +59,6 @@ for eachline in lines:
a = m.group(1) a = m.group(1)
point.append(list(func(a.split(",")))) point.append(list(func(a.split(","))))
elif eachline.startswith('Line (', 0, 6): elif eachline.startswith('Line (', 0, 6):
LineCount += 1 LineCount += 1
r = re.compile('{(.*?)}') r = re.compile('{(.*?)}')
@ -80,30 +75,13 @@ for eachline in lines:
a = m.group(1) a = m.group(1)
lineloop.append(list(func(a.split(",")))) lineloop.append(list(func(a.split(","))))
elif eachline.startswith('Plane', 0, len(eachline)): x_coord = []; y_coord = []; z_coord = []
PlaneSurfaceCount += 1 xp = []; xm = []
r = re.compile('{(.*?)}') yp = []; ym = []
m = r.search(eachline) zp = []; zm = []
if m: xmin = min([x[0] for x in point]); xmax = max([x[0] for x in point])
a = m.group(1) ymin = min([x[1] for x in point]); ymax = max([x[1] for x in point])
plane.append(list(func(a.split(",")))) zmin = min([x[2] for x in point]); zmax = max([x[2] for x in point])
elif eachline.startswith('Surface', 0,len(eachline)):
SurfaceLoopCount += 1
r = re.compile('{(.*?)}')
m = r.search(eachline)
if m:
a = m.group(1)
surface.append(list(func(a.split(","))))
x_coord = []
y_coord = []
z_coord = []
xp = []
xm = []
yp = []
ym = []
zp = []
zm = []
for i,l in enumerate(lineloop): for i,l in enumerate(lineloop):
for lines in l: for lines in l:
@ -111,69 +89,37 @@ for i,l in enumerate(lineloop):
x_coord.append(point[int(pts)-1][0]) x_coord.append(point[int(pts)-1][0])
y_coord.append(point[int(pts)-1][1]) y_coord.append(point[int(pts)-1][1])
z_coord.append(point[int(pts)-1][2]) z_coord.append(point[int(pts)-1][2])
if all_same(x_coord,xmax) and any([surface == 'x' for surface in options.surfaces]):
if all_same(x_coord,1.):
xp.append(int(i+1)) xp.append(int(i+1))
elif all_same(x_coord,0.): elif all_same(x_coord,xmin) and any([surface == 'x' for surface in options.surfaces]):
xm.append(int(i+1)) xm.append(int(i+1))
elif all_same(y_coord,1.): elif all_same(y_coord,ymax) and any([surface == 'y' for surface in options.surfaces]):
yp.append(int(i+1)) yp.append(int(i+1))
elif all_same(y_coord,0.): elif all_same(y_coord,ymin) and any([surface == 'y' for surface in options.surfaces]):
ym.append(int(i+1)) ym.append(int(i+1))
elif all_same(z_coord,1.): elif all_same(z_coord,zmax) and any([surface == 'z' for surface in options.surfaces]):
zp.append(int(i+1)) zp.append(int(i+1))
elif all_same(z_coord,0.): elif all_same(z_coord,zmin) and any([surface == 'z' for surface in options.surfaces]):
zm.append(int(i+1)) zm.append(int(i+1))
x_coord = [] x_coord = []
y_coord = [] y_coord = []
z_coord = [] z_coord = []
print 'suraces on x + are ', xp
print 'suraces on x - are ', xm
print 'suraces on y + are ', yp
print 'suraces on y - are ', ym
print 'suraces on z + are ', zp
print 'suraces on z - are ', zm
with open(my_geofile,'a') as f: with open(my_geofile,'a') as f:
f.write('Delete Physicals; \n') f.write('Delete Physicals; \n')
f.write('%s%d' %('Physical Surface(1) = {',xp[0])) if any([surface == 'x' for surface in options.surfaces]):
for i in range(len(xp)-1): f.write('%s%s%s\n' %('Physical Surface(1) = {',','.join(map(str, xp)),'};'))
f.write('%s%d' %(',', xp[i+1])) f.write('%s%s%s\n' %('Physical Surface(2) = {',','.join(map(str, xm)),'};'))
f.write('%s\n' %'};')
f.write('%s%d' %('Physical Surface(2) = {',xm[0])) if any([surface == 'y' for surface in options.surfaces]):
for i in range(len(xm)-1): f.write('%s%s%s\n' %('Physical Surface(3) = {',','.join(map(str, yp)),'};'))
f.write('%s%d' %(',', xm[i+1])) f.write('%s%s%s\n' %('Physical Surface(4) = {',','.join(map(str, ym)),'};'))
f.write('%s\n' %'};')
if any([surface == 'z' for surface in options.surfaces]):
f.write('%s%d' %('Physical Surface(3) = {',yp[0])) f.write('%s%s%s\n' %('Physical Surface(5) = {',','.join(map(str, zp)),'};'))
for i in range(len(yp)-1): f.write('%s%s%s\n' %('Physical Surface(6) = {',','.join(map(str, zm)),'};'))
f.write('%s%d' %(',', yp[i+1]))
f.write('%s\n' %'};')
f.write('%s%d' %('Physical Surface(4) = {',ym[0]))
for i in range(len(ym)-1):
f.write('%s%d' %(',', ym[i+1]))
f.write('%s\n' %'};')
f.write('%s%d' %('Physical Surface(5) = {',zp[0]))
for i in range(len(zp)-1):
f.write('%s%d' %(',', zp[i+1]))
f.write('%s\n' %'};')
f.write('%s%d' %('Physical Surface(6) = {',zm[0]))
for i in range(len(zm)-1):
f.write('%s%d' %(',', zm[i+1]))
f.write('%s\n' %'};')
for i in range(numVol): for i in range(numVol):
f.write('%s%d%s%d%s\n' %('Physical Volume (', i+1,') = {',i+1,'};')) f.write('%s%d%s%d%s\n' %('Physical Volume (', i+1,') = {',i+1,'};'))
f.close() f.close()