def cubit_command_check(iproc, command, stop=True): """ Run a cubit command, checking if it performs correctly. If the command fails, it writes the result on a file "error_[processor number]" and stop the meshing process iproc = process number command = cubit command stop = if command fails, stop the meshing process (Default: True) return status variable (0 ok, -1 fail) """ er = cubit.get_error_count() cubit.cmd(command) ner = cubit.get_error_count() flag = 0 if ner > er: text = '"Proc: ' + str(iproc) + ' ERROR ' + str( command) + ' number of error ' + str(er) + '/' + str(ner) + '"' cubitcommand = 'comment ' + text cubit.cmd(cubitcommand) f = open('error_' + str(iproc) + '.log', 'a') f.write("CUBIT ERROR: \n" + text) f.close() if stop: raise Exception("CUBIT ERROR: " + text) flag = -1 return flag
def cubit_command_check(iproc, command, stop=True): """ Run a cubit command, checking if it performs correctly. If the command fails, it writes the result on a file "error_[processor number]" and stop the meshing process iproc = process number command = cubit command stop = if command fails, stop the meshing process (Default: True) return status variable (0 ok, -1 fail) """ flag = True er = cubit.get_error_count() cubit.cmd(command) print command ner = cubit.get_error_count() if ner > er: text = '"Proc: ' + str(iproc) + ' ERROR ' + str(command) + \ ' number of error ' + str(er) + '/' + str(ner) + '"' cubitcommand = 'comment ' + text cubit.cmd(cubitcommand) f = open('error_' + str(iproc) + '.log', 'a') f.write("CUBIT ERROR: \n" + text) f.close() if stop: raise Exception("CUBIT ERROR: " + text) flag = False return flag
def runsave(geometryfile,iproc,filename=None): import start as start cubit = start.start_cubit() cfg = start.start_cfg(filename=filename) flag=[0] ner=cubit.get_error_count() cubitcommand= 'save as "'+ cfg.output_dir+'/'+geometryfile+ '" overwrite' cubit.cmd(cubitcommand) ner2=cubit.get_error_count() if ner == ner2: flag=[1] return flag
def runsave(geometryfile, iproc, filename=None): import start as start cubit = start.start_cubit() cfg = start.start_cfg(filename=filename) flag = [0] ner = cubit.get_error_count() cubitcommand = 'save as "' + cfg.output_dir + '/' + geometryfile + '" overwrite' cubit.cmd(cubitcommand) ner2 = cubit.get_error_count() if ner == ner2: flag = [1] return flag
def runsave(meshfile,iproc,filename=None): import start as start cubit = start.start_cubit() cfg = start.start_cfg(filename=filename) flag=0 ner=cubit.get_error_count() cubitcommand= 'save as "'+ cfg.output_dir+'/'+meshfile+'.cub'+ '" overwrite' cubit.cmd(cubitcommand) ner2=cubit.get_error_count() if ner == ner2: cubitcommand= 'export mesh "'+ cfg.output_dir+'/'+meshfile+'.e'+ '" dimension 3 block all overwrite' cubit.cmd(cubitcommand) ner2=cubit.get_error_count() if ner == ner2: flag=1 return flag
def runsave(meshfile, iproc, filename=None): import start as start cubit = start.start_cubit() cfg = start.start_cfg(filename=filename) flag = 0 ner = cubit.get_error_count() cubitcommand = 'save as "' + cfg.output_dir + '/' + meshfile + '.cub' + '" overwrite' cubit.cmd(cubitcommand) ner2 = cubit.get_error_count() if ner == ner2: cubitcommand = 'export mesh "' + cfg.output_dir + '/' + meshfile + '.e' + '" dimension 3 block all overwrite' cubit.cmd(cubitcommand) ner2 = cubit.get_error_count() if ner == ner2: flag = 1 return flag
def cubit_error_stop(iproc,command,ner): """obsolete""" er=cubit.get_error_count() if er > ner: text='"Proc: '+str(iproc)+' ERROR '+str(command)+' number of error '+str(er)+'/'+str(ner)+'"' cubitcommand = 'comment '+text cubit.cmd(cubitcommand) raise NameError, text
def cubit_error_continue(iproc,command,n_er): """obsolete""" er=cubit.get_error_count() if er >= n_er: text='"Proc: '+str(iproc)+' ERROR continue '+str(command)+' number of error '+str(er)+' '+str(n_er)+'"' cubit.cmd('comment '+ text) print 'error: ',text return er
def cubit_error_stop(iproc, command, ner): """obsolete""" er = cubit.get_error_count() if er > ner: text = '"Proc: ' + str(iproc) + ' ERROR ' + str( command) + ' number of error ' + str(er) + '/' + str(ner) + '"' cubitcommand = 'comment ' + text cubit.cmd(cubitcommand) raise NameError, text
def cubit_error_continue(iproc, command, n_er): """obsolete""" er = cubit.get_error_count() if er >= n_er: text = '"Proc: ' + str(iproc) + ' ERROR continue ' + str( command) + ' number of error ' + str(er) + ' ' + str(n_er) + '"' cubit.cmd('comment ' + text) print 'error: ', text return er
def layercake_volume_ascii_regulargrid_mpiregularmap(filename=None,verticalsandwich=False,onlysurface=False): import sys import start as start # mpiflag,iproc,numproc,mpi = start.start_mpi() # numpy = start.start_numpy() cfg = start.start_cfg(filename=filename) from utilities import geo2utm, savegeometry,savesurf,cubit_command_check from math import sqrt # try: mpi.barrier() except: pass # # command = "comment '"+"PROC: "+str(iproc)+"/"+str(numproc)+" '" cubit_command_check(iproc,command,stop=True) if verticalsandwich: cubit.cmd("comment 'Starting Vertical Sandwich'") # #get icpuy,icpux values if mpiflag: icpux = iproc % cfg.nproc_xi icpuy = int(iproc / cfg.nproc_xi) else: icpuy=int(cfg.id_proc/cfg.nproc_xi) icpux=cfg.id_proc%cfg.nproc_xi # if cfg.geometry_format == 'ascii': #for the original surfaces #number of points in the files that describe the topography import local_volume if cfg.localdir_is_globaldir: if iproc == 0 or not mpiflag: coordx_0,coordy_0,elev_0,nx_0,ny_0=local_volume.read_grid(filename) print 'end of reading grd files '+str(nx_0*ny_0)+ ' points' else: pass if iproc == 0 or not mpiflag: coordx=mpi.bcast(coordx_0) else: coordx=mpi.bcast() if iproc == 0 or not mpiflag: coordy=mpi.bcast(coordy_0) else: coordy=mpi.bcast() if iproc == 0 or not mpiflag: elev=mpi.bcast(elev_0) else: elev=mpi.bcast() if iproc == 0 or not mpiflag: nx=mpi.bcast(nx_0) else: nx=mpi.bcast() if iproc == 0 or not mpiflag: ny=mpi.bcast(ny_0) else: ny=mpi.bcast() else: coordx,coordy,elev,nx,ny=local_volume.read_grid(filename) print str(iproc)+ ' end of receving grd files ' nx_segment=int(nx/cfg.nproc_xi)+1 ny_segment=int(ny/cfg.nproc_eta)+1 elif cfg.geometry_format=='regmesh': # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if cfg.depth_bottom != cfg.zdepth[0]: if iproc == 0: print 'the bottom of the block is at different depth than depth[0] in the configuration file' nx= cfg.nproc_xi+1 ny= cfg.nproc_eta+1 nx_segment=2 ny_segment=2 #if iproc == 0: print nx,ny,cfg.cpux,cfg.cpuy xp=(cfg.xmax-cfg.xmin)/float((nx-1)) yp=(cfg.ymax-cfg.ymin)/float((ny-1)) # elev=numpy.zeros([nx,ny,cfg.nz],float) coordx=numpy.zeros([nx,ny],float) coordy=numpy.zeros([nx,ny],float) # # xlength=(cfg.xmax-cfg.xmin)/float(cfg.nproc_xi) #length of x slide for chunk ylength=(cfg.ymax-cfg.ymin)/float(cfg.nproc_eta) #length of y slide for chunk nelem_chunk_x=1 nelem_chunk_y=1 ivxtot=nelem_chunk_x+1 ivytot=nelem_chunk_y+1 xstep=xlength #distance between vertex on x ystep=ylength for i in range(0,cfg.nz): elev[:,:,i] = cfg.zdepth[i] icoord=0 for iy in range(0,ny): for ix in range(0,nx): icoord=icoord+1 coordx[ix,iy]=cfg.xmin+xlength*(ix) coordy[ix,iy]=cfg.ymin+ylength*(iy) #print coordx,coordy,nx,ny # print 'end of building grid '+str(iproc) print 'number of point: ', len(coordx)*len(coordy) # #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #for each processor # nxmin_cpu=(nx_segment-1)*(icpux) nymin_cpu=(ny_segment-1)*(icpuy) nxmax_cpu=min(nx-1,(nx_segment-1)*(icpux+1)) nymax_cpu=min(ny-1,(ny_segment-1)*(icpuy+1)) #if iproc == 0: # print nx_segment,ny_segment,nx,ny # print icpux,icpuy,nxmin_cpu,nxmax_cpu # print icpux,icpuy,nymin_cpu,nymax_cpu # print coordx[0,0],coordx[nx-1,ny-1] # print coordy[0,0],coordy[nx-1,ny-1] # # icurve=0 isurf=0 ivertex=0 # #create vertex for inz in range(0,cfg.nz): if cfg.sea and inz==cfg.nz-1: #sea layer sealevel=True bathymetry=False elif cfg.sea and inz==cfg.nz-2: #bathymetry layer sealevel=False bathymetry=True else: sealevel=False bathymetry=False print sealevel,bathymetry if cfg.bottomflat and inz == 0: #bottom layer # if cfg.geometry_format == 'ascii': lv=cubit.get_last_id("vertex") x_current,y_current=(coordx[nxmin_cpu,nymin_cpu],coordy[nxmin_cpu,nymin_cpu]) cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # x_current,y_current=(coordx[nxmin_cpu,nymax_cpu],coordy[nxmin_cpu,nymax_cpu]) cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # x_current,y_current=(coordx[nxmax_cpu,nymax_cpu],coordy[nxmax_cpu,nymax_cpu]) cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # x_current,y_current=(coordx[nxmax_cpu,nymin_cpu],coordy[nxmax_cpu,nymin_cpu]) cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # lv2=cubit.get_last_id("vertex") cubitcommand= 'create surface vertex '+str(lv+1)+' to '+str(lv2) cubit.cmd(cubitcommand) # isurf = isurf + 1 else: lv=cubit.get_last_id("vertex") x_current,y_current=geo2utm(coordx[nxmin_cpu,nymin_cpu],coordy[nxmin_cpu,nymin_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # x_current,y_current=geo2utm(coordx[nxmin_cpu,nymax_cpu],coordy[nxmin_cpu,nymax_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # x_current,y_current=geo2utm(coordx[nxmax_cpu,nymax_cpu],coordy[nxmax_cpu,nymax_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # x_current,y_current=geo2utm(coordx[nxmax_cpu,nymin_cpu],coordy[nxmax_cpu,nymin_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( cfg.depth_bottom ) cubit.cmd(cubitcommand) # lv2=cubit.get_last_id("vertex") cubitcommand= 'create surface vertex '+str(lv+1)+' to '+str(lv2) cubit.cmd(cubitcommand) # isurf = isurf + 1 else: if cfg.geometry_format == 'regmesh': zvertex=cfg.zdepth[inz] lv=cubit.get_last_id("vertex") x_current,y_current=geo2utm(coordx[nxmin_cpu,nymin_cpu],coordy[nxmin_cpu,nymin_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( zvertex ) cubit.cmd(cubitcommand) # x_current,y_current=geo2utm(coordx[nxmin_cpu,nymax_cpu],coordy[nxmin_cpu,nymax_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( zvertex ) cubit.cmd(cubitcommand) # x_current,y_current=geo2utm(coordx[nxmax_cpu,nymax_cpu],coordy[nxmax_cpu,nymax_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( zvertex ) cubit.cmd(cubitcommand) # x_current,y_current=geo2utm(coordx[nxmax_cpu,nymin_cpu],coordy[nxmax_cpu,nymin_cpu],'utm') cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( zvertex ) cubit.cmd(cubitcommand) # cubitcommand= 'create surface vertex '+str(lv+1)+' '+str(lv+2)+' '+str(lv+3)+' '+str(lv+4) cubit.cmd(cubitcommand) # isurf = isurf + 1 elif cfg.geometry_format == 'ascii': vertex=[] for iy in range(nymin_cpu,nymax_cpu+1): ivx=0 for ix in range(nxmin_cpu,nxmax_cpu+1): zvertex=elev[ix,iy,inz] #zvertex=adjust_sea_layers(zvertex,sealevel,bathymetry,cfg) x_current,y_current=(coordx[ix,iy],coordy[ix,iy]) # vertex.append(' Position '+ str( x_current ) +' '+ str( y_current )+' '+ str( zvertex ) ) # print 'proc',iproc, 'vertex list created....',len(vertex) n=max(nx,ny) uline=[] vline=[] iv=0 cubit.cmd("set info off") cubit.cmd("set echo off") cubit.cmd("set journal off") for iy in range(0,nymax_cpu-nymin_cpu+1): positionx='' for ix in range(0,nxmax_cpu-nxmin_cpu+1): positionx=positionx+vertex[iv] iv=iv+1 command='create curve spline '+positionx cubit.cmd(command) #print command uline.append( cubit.get_last_id("curve") ) for ix in range(0,nxmax_cpu-nxmin_cpu+1): positiony='' for iy in range(0,nymax_cpu-nymin_cpu+1): positiony=positiony+vertex[ix+iy*(nxmax_cpu-nxmin_cpu+1)] command='create curve spline '+positiony cubit.cmd(command) #print command vline.append( cubit.get_last_id("curve") ) # cubit.cmd("set info "+cfg.cubit_info) cubit.cmd("set echo "+cfg.echo_info) cubit.cmd("set journal "+cfg.jou_info) # # print 'proc',iproc, 'lines created....',len(uline),'*',len(vline) umax=max(uline) umin=min(uline) vmax=max(vline) vmin=min(vline) ner=cubit.get_error_count() cubitcommand= 'create surface net u curve '+ str( umin )+' to '+str( umax )+ ' v curve '+ str( vmin )+ ' to '+str( vmax )+' heal' cubit.cmd(cubitcommand) ner2=cubit.get_error_count() if ner == ner2: command = "del curve all" cubit.cmd(command) isurf=isurf+1 # else: raise NameError, 'error, check geometry_format, it should be ascii or regmesh' # # cubitcommand= 'del vertex all' cubit.cmd(cubitcommand) if cfg.save_surface_cubit: savegeometry(iproc=iproc,surf=True,filename=filename) # # #!create volume if not onlysurface: if cfg.nz == 1: nsurface=2 else: nsurface=cfg.nz for inz in range(1,nsurface): ner=cubit.get_error_count() create_volume(inz,inz+1,method=cfg.volumecreation_method) ner2=cubit.get_error_count() if ner == ner2 and not cfg.debug_geometry: #cubitcommand= 'del surface 1 to '+ str( cfg.nz ) cubitcommand= 'del surface all' cubit.cmd(cubitcommand) list_vol=cubit.parse_cubit_list("volume","all") if len(list_vol) > 1: cubitcommand= 'imprint volume all' cubit.cmd(cubitcommand) cubitcommand= 'merge all' cubit.cmd(cubitcommand) #ner=cubit.get_error_count() #cubitcommand= 'composite create curve in vol all' #cubit.cmd(cubitcommand) savegeometry(iproc,filename=filename) #if cfg.geological_imprint: # curvesname=[cfg.outlinebasin_curve,cfg.transition_curve,cfg.faulttrace_curve] # outdir=cfg.working_dir # imprint_topography_with_geological_outline(curvesname,outdir) # # cubit.cmd("set info "+cfg.cubit_info) cubit.cmd("set echo "+cfg.echo_info) cubit.cmd("set journal "+cfg.jou_info)
def layercake_volume_fromacis_mpiregularmap(filename=None): import sys import start as start # mpiflag,iproc,numproc,mpi = start.start_mpi() # cfg = start.start_cfg(filename=filename) # from utilities import geo2utm, savegeometry # from math import sqrt # try: mpi.barrier() except: pass # # command = "comment '"+"PROC: "+str(iproc)+"/"+str(numproc)+" '" cubit.cmd(command) # #get the limit of the volume considering the cpu def xwebcut(x): command='create planar surface with plane xplane offset '+str(x) cubit.cmd(command) last_surface=cubit.get_last_id("surface") command="webcut volume all tool volume in surf "+str(last_surface) cubit.cmd(command) command="del surf "+str(last_surface) cubit.cmd(command) def ywebcut(x): command='create planar surface with plane yplane offset '+str(x) cubit.cmd(command) last_surface=cubit.get_last_id("surface") command="webcut volume all tool volume in surf "+str(last_surface) cubit.cmd(command) command="del surf "+str(last_surface) cubit.cmd(command) def translate2zero(): ss=cubit.parse_cubit_list('surface','all') box = cubit.get_total_bounding_box("surface", ss) xmin=box[0] ymin=box[3] cubit.cmd('move surface all x '+str(-1*xmin)+' y '+str(-1*ymin)) return xmin,ymin def translate2original(xmin,ymin): cubit.cmd('move surface all x '+str(xmin)+' y '+str(ymin)) if mpiflag: icpux = iproc % cfg.nproc_xi icpuy = int(iproc / cfg.nproc_xi) else: icpuy=int(cfg.id_proc/cfg.nproc_xi) icpux=cfg.id_proc%cfg.nproc_xi # ner=cubit.get_error_count() # icurve=0 isurf=0 ivertex=0 # xlength=(cfg.xmax-cfg.xmin)/float(cfg.cpux) #length of x slide for chunk ylength=(cfg.ymax-cfg.ymin)/float(cfg.cpuy) #length of y slide for chunk xmin_cpu=cfg.xmin+(xlength*(icpux)) ymin_cpu=cfg.ymin+(ylength*(icpuy)) xmax_cpu=xmin_cpu+xlength ymax_cpu=ymin_cpu+ylength # #importing the surfaces for inz in range(cfg.nz-2,-2,-1): if cfg.bottomflat and inz==-1: command = "create planar surface with plane zplane offset "+str(cfg.depth_bottom) cubit.cmd(command) else: command = "import cubit '"+cfg.filename[inz]+"'" cubit.cmd(command) #translate xmin,ymin=translate2zero() print 'translate ...', -xmin,-ymin xmin_cpu=xmin_cpu-xmin ymin_cpu=ymin_cpu-ymin xmax_cpu=xmax_cpu-xmin ymax_cpu=ymax_cpu-ymin ss=cubit.parse_cubit_list('surface','all') box = cubit.get_total_bounding_box("surface", ss) print 'dimension... ', box #cutting the surfaces xwebcut(xmin_cpu) xwebcut(xmax_cpu) ywebcut(ymin_cpu) ywebcut(ymax_cpu) # list_surface_all=cubit.parse_cubit_list("surface","all") #condisidering only the surfaces inside the boundaries dict_surf={} for isurf in list_surface_all: p=cubit.get_center_point("surface",isurf) if p[0] < xmin_cpu or p[0] > xmax_cpu or p[1] > ymax_cpu or p[1] < ymin_cpu: command = "del surf "+str(isurf) cubit.cmd(command) else: dict_surf[str(isurf)]=p[2] z=dict_surf.values() z.sort() list_surf=[] for val in z: isurf=[k for k, v in dict_surf.iteritems() if v == val][0] list_surf.append(int(isurf)) # #lofting the volume for i,j in zip(list_surf,list_surf[1:]): ner=cubit.get_error_count() create_volume(i,j,method=cfg.volumecreation_method) #cubitcommand= 'create volume loft surface '+ str(i)+' '+str(j) #cubit.cmd(cubitcommand) ner2=cubit.get_error_count() # translate2original(xmin,ymin) if ner == ner2: cubitcommand= 'del surface all' cubit.cmd(cubitcommand) # # #cubitcommand= 'composite create curve in vol all' #cubit.cmd(cubitcommand) list_vol=cubit.parse_cubit_list("volume","all") if len(list_vol) > 1: cubitcommand= 'imprint volume all' cubit.cmd(cubitcommand) #cubit_error_stop(iproc,cubitcommand,ner) # cubitcommand= 'merge all' cubit.cmd(cubitcommand) # savegeometry(iproc,filename=filename)
# name element blocks for master earth... blockCount = 1 cubit.cmd ('block ' + str (blockCount) + ' volume with name "masters*"') cubit.cmd ('block ' + str (blockCount) + ' name "master"') # and nodesets... cubit.cmd ('Nodeset ' + str (blockCount) + ' volume with name "masters*"') cubit.cmd ('Nodeset ' + str (blockCount) + ' name "master"') # now go through and group the rest of the regions into blocks and nodesets blockCount = 2 for region in names: cubit.cmd ('block ' + str (blockCount) + ' volume with name "' + region + '*"') cubit.cmd ('block ' + str (blockCount) + ' name "' + region + '"') cubit.cmd ('Nodeset ' + str (blockCount) + ' volume with name "' + region + '*"') cubit.cmd ('Nodeset ' + str (blockCount) + ' name "' + region + '"') blockCount = blockCount + 1 cubit.cmd ('Surface all scheme trimesh') # write and reset for next file. cubit.cmd ('save as "' + geomPath + 'regions/' + file + '" overwrite') cubit.cmd ('reset') if cubit.get_error_count () != 0: print "Unfortunately, I found some errors"
def layercake_volume_ascii_regulargrid_mpiregularmap(filename=None, verticalsandwich=False, onlysurface=False): import sys import start as start # mpiflag, iproc, numproc, mpi = start.start_mpi() # numpy = start.start_numpy() cfg = start.start_cfg(filename=filename) from utilities import geo2utm, savegeometry, savesurf, cubit_command_check from math import sqrt # try: mpi.barrier() except: pass # # command = "comment '" + "PROC: " + str(iproc) + "/" + str(numproc) + " '" cubit_command_check(iproc, command, stop=True) if verticalsandwich: cubit.cmd("comment 'Starting Vertical Sandwich'") # #get icpuy,icpux values if mpiflag: icpux = iproc % cfg.nproc_xi icpuy = int(iproc / cfg.nproc_xi) else: icpuy = int(cfg.id_proc / cfg.nproc_xi) icpux = cfg.id_proc % cfg.nproc_xi # if cfg.geometry_format == 'ascii': #for the original surfaces #number of points in the files that describe the topography import local_volume if cfg.localdir_is_globaldir: if iproc == 0 or not mpiflag: coordx_0, coordy_0, elev_0, nx_0, ny_0 = local_volume.read_grid( filename) print 'end of reading grd files ' + str( nx_0 * ny_0) + ' points' else: pass if iproc == 0 or not mpiflag: coordx = mpi.bcast(coordx_0) else: coordx = mpi.bcast() if iproc == 0 or not mpiflag: coordy = mpi.bcast(coordy_0) else: coordy = mpi.bcast() if iproc == 0 or not mpiflag: elev = mpi.bcast(elev_0) else: elev = mpi.bcast() if iproc == 0 or not mpiflag: nx = mpi.bcast(nx_0) else: nx = mpi.bcast() if iproc == 0 or not mpiflag: ny = mpi.bcast(ny_0) else: ny = mpi.bcast() else: coordx, coordy, elev, nx, ny = local_volume.read_grid(filename) print str(iproc) + ' end of receving grd files ' nx_segment = int(nx / cfg.nproc_xi) + 1 ny_segment = int(ny / cfg.nproc_eta) + 1 elif cfg.geometry_format == 'regmesh': # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if cfg.depth_bottom != cfg.zdepth[0]: if iproc == 0: print 'the bottom of the block is at different depth than depth[0] in the configuration file' nx = cfg.nproc_xi + 1 ny = cfg.nproc_eta + 1 nx_segment = 2 ny_segment = 2 #if iproc == 0: print nx,ny,cfg.cpux,cfg.cpuy xp = (cfg.xmax - cfg.xmin) / float((nx - 1)) yp = (cfg.ymax - cfg.ymin) / float((ny - 1)) # elev = numpy.zeros([nx, ny, cfg.nz], float) coordx = numpy.zeros([nx, ny], float) coordy = numpy.zeros([nx, ny], float) # # xlength = (cfg.xmax - cfg.xmin) / float( cfg.nproc_xi) #length of x slide for chunk ylength = (cfg.ymax - cfg.ymin) / float( cfg.nproc_eta) #length of y slide for chunk nelem_chunk_x = 1 nelem_chunk_y = 1 ivxtot = nelem_chunk_x + 1 ivytot = nelem_chunk_y + 1 xstep = xlength #distance between vertex on x ystep = ylength for i in range(0, cfg.nz): elev[:, :, i] = cfg.zdepth[i] icoord = 0 for iy in range(0, ny): for ix in range(0, nx): icoord = icoord + 1 coordx[ix, iy] = cfg.xmin + xlength * (ix) coordy[ix, iy] = cfg.ymin + ylength * (iy) #print coordx,coordy,nx,ny # print 'end of building grid ' + str(iproc) print 'number of point: ', len(coordx) * len(coordy) # #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #for each processor # nxmin_cpu = (nx_segment - 1) * (icpux) nymin_cpu = (ny_segment - 1) * (icpuy) nxmax_cpu = min(nx - 1, (nx_segment - 1) * (icpux + 1)) nymax_cpu = min(ny - 1, (ny_segment - 1) * (icpuy + 1)) #if iproc == 0: # print nx_segment,ny_segment,nx,ny # print icpux,icpuy,nxmin_cpu,nxmax_cpu # print icpux,icpuy,nymin_cpu,nymax_cpu # print coordx[0,0],coordx[nx-1,ny-1] # print coordy[0,0],coordy[nx-1,ny-1] # # icurve = 0 isurf = 0 ivertex = 0 # #create vertex for inz in range(0, cfg.nz): if cfg.sea and inz == cfg.nz - 1: #sea layer sealevel = True bathymetry = False elif cfg.sea and inz == cfg.nz - 2: #bathymetry layer sealevel = False bathymetry = True else: sealevel = False bathymetry = False print sealevel, bathymetry if cfg.bottomflat and inz == 0: #bottom layer # if cfg.geometry_format == 'ascii': lv = cubit.get_last_id("vertex") x_current, y_current = (coordx[nxmin_cpu, nymin_cpu], coordy[nxmin_cpu, nymin_cpu]) cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # x_current, y_current = (coordx[nxmin_cpu, nymax_cpu], coordy[nxmin_cpu, nymax_cpu]) cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # x_current, y_current = (coordx[nxmax_cpu, nymax_cpu], coordy[nxmax_cpu, nymax_cpu]) cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # x_current, y_current = (coordx[nxmax_cpu, nymin_cpu], coordy[nxmax_cpu, nymin_cpu]) cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # lv2 = cubit.get_last_id("vertex") cubitcommand = 'create surface vertex ' + str( lv + 1) + ' to ' + str(lv2) cubit.cmd(cubitcommand) # isurf = isurf + 1 else: lv = cubit.get_last_id("vertex") x_current, y_current = geo2utm(coordx[nxmin_cpu, nymin_cpu], coordy[nxmin_cpu, nymin_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # x_current, y_current = geo2utm(coordx[nxmin_cpu, nymax_cpu], coordy[nxmin_cpu, nymax_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # x_current, y_current = geo2utm(coordx[nxmax_cpu, nymax_cpu], coordy[nxmax_cpu, nymax_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # x_current, y_current = geo2utm(coordx[nxmax_cpu, nymin_cpu], coordy[nxmax_cpu, nymin_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(cfg.depth_bottom) cubit.cmd(cubitcommand) # lv2 = cubit.get_last_id("vertex") cubitcommand = 'create surface vertex ' + str( lv + 1) + ' to ' + str(lv2) cubit.cmd(cubitcommand) # isurf = isurf + 1 else: if cfg.geometry_format == 'regmesh': zvertex = cfg.zdepth[inz] lv = cubit.get_last_id("vertex") x_current, y_current = geo2utm(coordx[nxmin_cpu, nymin_cpu], coordy[nxmin_cpu, nymin_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(zvertex) cubit.cmd(cubitcommand) # x_current, y_current = geo2utm(coordx[nxmin_cpu, nymax_cpu], coordy[nxmin_cpu, nymax_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(zvertex) cubit.cmd(cubitcommand) # x_current, y_current = geo2utm(coordx[nxmax_cpu, nymax_cpu], coordy[nxmax_cpu, nymax_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(zvertex) cubit.cmd(cubitcommand) # x_current, y_current = geo2utm(coordx[nxmax_cpu, nymin_cpu], coordy[nxmax_cpu, nymin_cpu], 'utm') cubitcommand = 'create vertex ' + str(x_current) + ' ' + str( y_current) + ' ' + str(zvertex) cubit.cmd(cubitcommand) # cubitcommand = 'create surface vertex ' + str( lv + 1) + ' ' + str(lv + 2) + ' ' + str(lv + 3) + ' ' + str(lv + 4) cubit.cmd(cubitcommand) # isurf = isurf + 1 elif cfg.geometry_format == 'ascii': vertex = [] for iy in range(nymin_cpu, nymax_cpu + 1): ivx = 0 for ix in range(nxmin_cpu, nxmax_cpu + 1): zvertex = elev[ix, iy, inz] #zvertex=adjust_sea_layers(zvertex,sealevel,bathymetry,cfg) x_current, y_current = (coordx[ix, iy], coordy[ix, iy]) # vertex.append(' Position ' + str(x_current) + ' ' + str(y_current) + ' ' + str(zvertex)) # print 'proc', iproc, 'vertex list created....', len(vertex) n = max(nx, ny) uline = [] vline = [] iv = 0 cubit.cmd("set info off") cubit.cmd("set echo off") cubit.cmd("set journal off") for iy in range(0, nymax_cpu - nymin_cpu + 1): positionx = '' for ix in range(0, nxmax_cpu - nxmin_cpu + 1): positionx = positionx + vertex[iv] iv = iv + 1 command = 'create curve spline ' + positionx cubit.cmd(command) #print command uline.append(cubit.get_last_id("curve")) for ix in range(0, nxmax_cpu - nxmin_cpu + 1): positiony = '' for iy in range(0, nymax_cpu - nymin_cpu + 1): positiony = positiony + vertex[ ix + iy * (nxmax_cpu - nxmin_cpu + 1)] command = 'create curve spline ' + positiony cubit.cmd(command) #print command vline.append(cubit.get_last_id("curve")) # cubit.cmd("set info " + cfg.cubit_info) cubit.cmd("set echo " + cfg.echo_info) cubit.cmd("set journal " + cfg.jou_info) # # print 'proc', iproc, 'lines created....', len(uline), '*', len( vline) umax = max(uline) umin = min(uline) vmax = max(vline) vmin = min(vline) ner = cubit.get_error_count() cubitcommand = 'create surface net u curve ' + str( umin) + ' to ' + str(umax) + ' v curve ' + str( vmin) + ' to ' + str(vmax) + ' heal' cubit.cmd(cubitcommand) ner2 = cubit.get_error_count() if ner == ner2: command = "del curve all" cubit.cmd(command) isurf = isurf + 1 # else: raise NameError, 'error, check geometry_format, it should be ascii or regmesh' # # cubitcommand = 'del vertex all' cubit.cmd(cubitcommand) if cfg.save_surface_cubit: savegeometry(iproc=iproc, surf=True, filename=filename) # # #!create volume if not onlysurface: if cfg.nz == 1: nsurface = 2 else: nsurface = cfg.nz for inz in range(1, nsurface): ner = cubit.get_error_count() create_volume(inz, inz + 1, method=cfg.volumecreation_method) ner2 = cubit.get_error_count() if ner == ner2 and not cfg.debug_geometry: #cubitcommand= 'del surface 1 to '+ str( cfg.nz ) cubitcommand = 'del surface all' cubit.cmd(cubitcommand) list_vol = cubit.parse_cubit_list("volume", "all") if len(list_vol) > 1: cubitcommand = 'imprint volume all' cubit.cmd(cubitcommand) cubitcommand = 'merge all' cubit.cmd(cubitcommand) #ner=cubit.get_error_count() #cubitcommand= 'composite create curve in vol all' #cubit.cmd(cubitcommand) savegeometry(iproc, filename=filename) #if cfg.geological_imprint: # curvesname=[cfg.outlinebasin_curve,cfg.transition_curve,cfg.faulttrace_curve] # outdir=cfg.working_dir # imprint_topography_with_geological_outline(curvesname,outdir) # # cubit.cmd("set info " + cfg.cubit_info) cubit.cmd("set echo " + cfg.echo_info) cubit.cmd("set journal " + cfg.jou_info)
def layercake_volume_fromacis_mpiregularmap(filename=None): import sys import start as start # mpiflag, iproc, numproc, mpi = start.start_mpi() # cfg = start.start_cfg(filename=filename) # from utilities import geo2utm, savegeometry # from math import sqrt # try: mpi.barrier() except: pass # # command = "comment '" + "PROC: " + str(iproc) + "/" + str(numproc) + " '" cubit.cmd(command) # #get the limit of the volume considering the cpu def xwebcut(x): command = 'create planar surface with plane xplane offset ' + str(x) cubit.cmd(command) last_surface = cubit.get_last_id("surface") command = "webcut volume all tool volume in surf " + str(last_surface) cubit.cmd(command) command = "del surf " + str(last_surface) cubit.cmd(command) def ywebcut(x): command = 'create planar surface with plane yplane offset ' + str(x) cubit.cmd(command) last_surface = cubit.get_last_id("surface") command = "webcut volume all tool volume in surf " + str(last_surface) cubit.cmd(command) command = "del surf " + str(last_surface) cubit.cmd(command) def translate2zero(): ss = cubit.parse_cubit_list('surface', 'all') box = cubit.get_total_bounding_box("surface", ss) xmin = box[0] ymin = box[3] cubit.cmd('move surface all x ' + str(-1 * xmin) + ' y ' + str(-1 * ymin)) return xmin, ymin def translate2original(xmin, ymin): cubit.cmd('move surface all x ' + str(xmin) + ' y ' + str(ymin)) if mpiflag: icpux = iproc % cfg.nproc_xi icpuy = int(iproc / cfg.nproc_xi) else: icpuy = int(cfg.id_proc / cfg.nproc_xi) icpux = cfg.id_proc % cfg.nproc_xi # ner = cubit.get_error_count() # icurve = 0 isurf = 0 ivertex = 0 # xlength = (cfg.xmax - cfg.xmin) / float( cfg.cpux) #length of x slide for chunk ylength = (cfg.ymax - cfg.ymin) / float( cfg.cpuy) #length of y slide for chunk xmin_cpu = cfg.xmin + (xlength * (icpux)) ymin_cpu = cfg.ymin + (ylength * (icpuy)) xmax_cpu = xmin_cpu + xlength ymax_cpu = ymin_cpu + ylength # #importing the surfaces for inz in range(cfg.nz - 2, -2, -1): if cfg.bottomflat and inz == -1: command = "create planar surface with plane zplane offset " + str( cfg.depth_bottom) cubit.cmd(command) else: command = "import cubit '" + cfg.filename[inz] + "'" cubit.cmd(command) #translate xmin, ymin = translate2zero() print 'translate ...', -xmin, -ymin xmin_cpu = xmin_cpu - xmin ymin_cpu = ymin_cpu - ymin xmax_cpu = xmax_cpu - xmin ymax_cpu = ymax_cpu - ymin ss = cubit.parse_cubit_list('surface', 'all') box = cubit.get_total_bounding_box("surface", ss) print 'dimension... ', box #cutting the surfaces xwebcut(xmin_cpu) xwebcut(xmax_cpu) ywebcut(ymin_cpu) ywebcut(ymax_cpu) # list_surface_all = cubit.parse_cubit_list("surface", "all") #condisidering only the surfaces inside the boundaries dict_surf = {} for isurf in list_surface_all: p = cubit.get_center_point("surface", isurf) if p[0] < xmin_cpu or p[0] > xmax_cpu or p[1] > ymax_cpu or p[ 1] < ymin_cpu: command = "del surf " + str(isurf) cubit.cmd(command) else: dict_surf[str(isurf)] = p[2] z = dict_surf.values() z.sort() list_surf = [] for val in z: isurf = [k for k, v in dict_surf.iteritems() if v == val][0] list_surf.append(int(isurf)) # #lofting the volume for i, j in zip(list_surf, list_surf[1:]): ner = cubit.get_error_count() create_volume(i, j, method=cfg.volumecreation_method) #cubitcommand= 'create volume loft surface '+ str(i)+' '+str(j) #cubit.cmd(cubitcommand) ner2 = cubit.get_error_count() # translate2original(xmin, ymin) if ner == ner2: cubitcommand = 'del surface all' cubit.cmd(cubitcommand) # # #cubitcommand= 'composite create curve in vol all' #cubit.cmd(cubitcommand) list_vol = cubit.parse_cubit_list("volume", "all") if len(list_vol) > 1: cubitcommand = 'imprint volume all' cubit.cmd(cubitcommand) #cubit_error_stop(iproc,cubitcommand,ner) # cubitcommand = 'merge all' cubit.cmd(cubitcommand) # savegeometry(iproc, filename=filename)
'xpositive ypositive zpositive' ) fSub = '.rad' + str(rad-abs(dis)).zfill(4) + '-' + str(rad).zfill(4) + \ '.000.cub" overwrite journal' cubit.cmd ( 'vol 1 name "masters"' ) cubit.cmd ( "group 'Masters' equals Volume all\n" ) cubit.cmd ( fNameBase + 'col000-090.lon000-090' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( fNameBase + 'col000-090.lon090-180' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( fNameBase + 'col000-090.lon180-270' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( fNameBase + 'col000-090.lon270-360' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( 'volume all reflect Z\n' ) cubit.cmd ( fNameBase + 'col090-180.lon000-090' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( fNameBase + 'col090-180.lon090-180' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( fNameBase + 'col090-180.lon180-270' + fSub + '\n' ) cubit.cmd ( 'rotate volume all angle 90 about z include_merged\n' ) cubit.cmd ( fNameBase + 'col090-180.lon270-360' + fSub + '\n' ) cubit.cmd ( 'reset' ) if ( cubit.get_error_count () != 0 ): print "I'm so sorry, but I've detected errors. Check." cubit.cmd ( 'quit' )