#!/usr/bin/env python# *-* coding:utf-8 *-*"""Translate a given grid using the user-supplied offsets dx, dzExamples-------- grid_translate.py -e original/elem.dat -z 600 -o elem.dat"""fromoptparseimportOptionParserimportnumpyasnpimportcrtomo.gridasCRGrid
[docs]defhandle_cmd_options():parser=OptionParser()parser.add_option('-e',"--elem",dest="elem_file",type="string",help="elem.dat file (default: elem.dat)",default="elem.dat")# parser.add_option("-x", "--center_x", dest="center_x", type="float",# help="Center around which to rotate (X-coordiante)",# default=0.0)# parser.add_option("-y", "--center_y", dest="center_y", type="float",# help="Center around which to rotate (Y-coordiante)",# default=0.0)parser.add_option("-x","--dx",dest="dx",type="float",help="Offset on x-axis (default: 0)",default=0.0)parser.add_option("-z","--dz",dest="dz",type="float",help="Offset on z-axis (default: 0)",default=0.0)parser.add_option("-o","--output",dest="output",help="Output file (default: elem_trans.dat)",metavar="FILE",default="elem_rot.dat")(options,args)=parser.parse_args()returnoptions
[docs]defmain():options=handle_cmd_options()# put in dummy center coordinatesoptions.center_x=0.0options.center_y=0.0grid=CRGrid.crt_grid(elem_file=options.elem_file,elec_file='elec.dat')# grid.load_elem_file(options.elem_file)rotated_nodes=translate_nodes(grid.nodes['raw'][:,1:3],options.dx,options.dz)grid.nodes['raw'][:,1:3]=rotated_nodesgrid.save_elem_file(options.output)