#!/usr/bin/env python# *-* coding: utf-8 *-*"""Rotate a given grid clockwiseNote that, at the moment, the grid is always rotated around the origin (0,0)."""fromoptparseimportOptionParserimportnumpyasnpimportcrtomo.gridasCRGridimportmath
[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("-a","--angle",dest="angle_deg",type="float",help="Rotation angle (in degrees, default: 90)",default=90.0)parser.add_option("-o","--output",dest="output",help="Output file (default: elem_rot.dat)",metavar="FILE",default="elem_rot.dat")(options,args)=parser.parse_args()returnoptions
[docs]defrotmat(alpha):"""Rotate around z-axis """R=np.array(((np.cos(alpha),-np.sin(alpha)),(np.sin(alpha),np.cos(alpha))))returnR
[docs]defmain():options=handle_cmd_options()# put in dummy center coordinatesoptions.center_x=0.0options.center_y=0.0grid=CRGrid.crt_grid()grid.load_elem_file(options.elem_file)rotated_nodes=rotate_nodes(grid.nodes['raw'][:,1:3],options.center_x,options.center_y,math.radians(options.angle_deg))grid.nodes['raw'][:,1:3]=rotated_nodesgrid.save_elem_file(options.output)