3
from optparse import OptionParser
9
#####################################################################
11
optparser=OptionParser(usage='usage: %prog transformation mesh',
13
description="""Applies a coordinate transformation to the given mesh.""")
16
"usage: %prog <transformation> <mesh>\n\n"+
17
"<transformation> is a python expression giving the coordinate transformation.\n"+
18
"<mesh> is the name of the triangle mesh files. You need a mesh.node, mesh.face and mesh.ele file.\n"+
21
"To rescale the z-dimension by a factor of 1000,\n"
22
"%prog '(x,y,1000*z)' mesh.\n"
25
(options, argv) = optparser.parse_args()
28
optparser.print_help()
31
transformation=argv[0]
34
# make all definitions of the math module available in
35
# the transformation expression.
38
f=file(mesh_name+'.node','r')
39
newf=file(mesh_name+'.node.tmp','w')
41
nodes=int(header.split(' ')[0])
42
dim=int(header.split(' ')[1])
46
# remove spaces leading and trailing spaces and the end of line character:
47
line=line.lstrip().rstrip()
48
if line.startswith('#'):
52
globals['x']=float(cols[1])
53
globals['y']=float(cols[2])
55
globals['z']=float(cols[3])
56
xyz=eval(transformation, globals)
58
newf.write(`index`+' '+`xyz[0]`+' '+`xyz[1]`+'\n')
60
newf.write(`index`+' '+`xyz[0]`+' '+`xyz[1]`+' '+`xyz[2]`+'\n')
65
shutil.move(mesh_name+'.node', mesh_name+'.node.bak')
66
shutil.move(mesh_name+'.node.tmp', mesh_name+'.node')
b'\\ No newline at end of file'