def start_cubit(init=False): """ start cubit, it return the cubit object init argument set the monitotr files """ import sys,os try: cubit.silent_cmd('comment') except: try: import cubit import utilities cubit.init([""]) except: print 'error importing cubit' sys.exit() try: if init: from start import start_cfg,start_mpi cfg=start_cfg() mpiflag,iproc,numproc,mpi = start_mpi() cubit.cmd('set logging on file "'+cfg.working_dir+'/cubit_proc_'+str(iproc)+'.log"') cubit.cmd("set echo off") cubit.cmd("set info off") if iproc == cfg.monitored_cpu: cubit.cmd("record '"+cfg.working_dir+"/monitor_"+str(cfg.monitored_cpu)+".jou'") cubit.cmd("set journal on") cubit.cmd("journal error on") d=cfg.__dict__ ks=d.keys() ks.sort() for k in ks: if '__' not in k and '<' not in str(d[k]) and d[k] is not None: txt=str(k)+' -----> '+str(d[k]) txt=txt.replace("'","").replace('"','') cubit.cmd('comment "'+txt+'"') else: cubit.cmd("set journal "+cfg.jou_info) cubit.cmd("journal error "+cfg.jer_info) d=cfg.__dict__ ks=d.keys() ks.sort() for k in ks: if '__' not in k and '<' not in str(d[k]) and d[k] is not None: txt=str(k)+' -----> '+str(d[k]) txt=txt.replace("'","").replace('"','') cubit.cmd('comment "'+txt+'"') cubit.cmd("set echo "+cfg.echo_info) cubit.cmd("set info "+cfg.cubit_info) version_cubit=utilities.get_cubit_version() if version_cubit > 13 and version_cubit < 15: print 'VERSION CUBIT ',version_cubit print 'VERSIONs of CUBIT > 13 have bugs with merge node commands and equivalence' print 'the merge option is not operative with this version, please download CUBIT 13' else: print 'VERSION CUBIT ',version_cubit except: print 'error start cubit' sys.exit() return cubit
def build_block(vol_list, name, id_0=1, top_surf=None, optionsea=False): # from sets import Set if optionsea: sea = optionsea['sea'] seaup = optionsea['seaup'] sealevel = optionsea['sealevel'] seathres = optionsea['seathres'] else: sea = False seaup = False sealevel = False seathres = False # block_list = cubit.get_block_id_list() if len(block_list) > 0: id_block = max(max(block_list), 2) + id_0 else: id_block = 2 + id_0 for v, n in zip(vol_list, name): id_block += 1 v_other = Set(vol_list) - Set([v]) if sea and v == vol_list[-1]: cubit.cmd('set duplicate block elements off') tsurf_string = " ".join(str(x) for x in top_surf) # sea command = 'block ' + str(id_block) + ' hex in node in surf ' + \ tsurf_string + ' with Z_coord < ' + str(seathres) cubit.cmd(command) command = "block " + str(id_block) + " name 'sea" + n + "'" cubit.cmd(command) if not seaup: id_block += 1 command = 'block ' + str(id_block) + ' hex in node in surf ' +\ tsurf_string + ' with (Z_coord > ' + str(seathres) +\ ' and Z_coord < ' + str(sealevel) cubit.cmd(command) command = "block " + str(id_block) + " name 'shwater" + n + "'" cubit.cmd(command) id_block += 1 command = 'block ' + str(id_block) + ' hex in node in surf ' + \ tsurf_string + ' with Z_coord >= ' + str(sealevel) cubit.cmd(command) command = "block " + str(id_block) + " name 'continent" + n + "'" cubit.cmd(command) else: version_cubit = get_cubit_version() if version_cubit >= 15: command = 'block ' + str(id_block) + ' hex in vol ' + \ str(v) else: command = 'block ' + str(id_block) + ' hex in vol ' + \ str(v) + ' except hex in vol ' + str(list(v_other)) print command command = command.replace("[", " ").replace("]", " ") cubit.cmd(command) command = "block " + str(id_block) + " name '" + n + "'" cubit.cmd(command)
def __init__(self, hex27=False, cpml=False, cpml_size=False, top_absorbing=False): super(mesh, self).__init__() self.mesh_name = 'mesh_file' self.nodecoord_name = 'nodes_coords_file' self.material_name = 'materials_file' self.nummaterial_name = 'nummaterial_velocity_file' self.absname = 'absorbing_surface_file' self.cpmlname = 'absorbing_cpml_file' self.freename = 'free_or_absorbing_surface_file_zmax' self.recname = 'STATIONS' version_cubit = get_cubit_version() if version_cubit >= 12: self.face = 'SHELL4' else: self.face = 'QUAD4' self.hex = 'HEX' if version_cubit <= 13: if hex27: print "ATTENTION **********************\n\nCubit <= 12.2 doesn't support HEX27\nassuming HEX8 .....\n\n" self.hex27 = False else: self.hex27 = hex27 self.edge = 'BAR2' self.topo = 'face_topo' self.topography = None self.free = None self.freetxt = 'free' self.rec = 'receivers' self.cpml = cpml if cpml: if cpml_size: self.size = cpml_size else: print 'please specify cmpl size if you want to use cpml' self.top_absorbing = top_absorbing if hex27: cubit.cmd( 'block all except block 1001 1002 1003 1004 1005 1006 element type hex27' ) self.block_definition() self.ngll = 5 self.percent_gll = 0.172 self.point_wavelength = 5 self.xmin = False self.ymin = False self.zmin = False self.xmax = False self.ymax = False self.zmax = False cubit.cmd('compress all')
def __init__(self,hex27=False,cpml=False,cpml_size=False,top_absorbing=False): super(mesh, self).__init__() self.mesh_name='mesh_file' self.nodecoord_name='nodes_coords_file' self.material_name='materials_file' self.nummaterial_name='nummaterial_velocity_file' self.absname='absorbing_surface_file' self.cpmlname='absorbing_cpml_file' self.freename='free_or_absorbing_surface_file_zmax' self.recname='STATIONS' version_cubit=get_cubit_version() if version_cubit >= 15: self.face='SHELL' elif version_cubit >= 12: self.face='SHELL4' else: self.face='QUAD4' self.hex='HEX' if version_cubit <= 13: if hex27: print "ATTENTION **********************\n\nCubit <= 12.2 doesn't support HEX27\nassuming HEX8 .....\n\n" self.hex27=False else: self.hex27=hex27 self.edge='BAR2' self.topo='face_topo' self.topography=None self.free=None self.freetxt='free' self.rec='receivers' self.cpml=cpml if cpml: if cpml_size: self.size=cpml_size else: print 'please specify cmpl size if you want to use cpml' self.top_absorbing=top_absorbing if hex27: cubit.cmd('block all except block 1001 1002 1003 1004 1005 1006 element type hex27') self.block_definition() self.ngll=5 self.percent_gll=0.172 self.point_wavelength=5 self.xmin=False self.ymin=False self.zmin=False self.xmax=False self.ymax=False self.zmax=False cubit.cmd('compress all')
def start_cubit(init=False): """ start cubit, it return the cubit object init argument set the monitotr files """ import sys try: cubit.silent_cmd('comment') except: try: import cubit import utilities cubit.init([""]) except: print('error importing cubit') sys.exit() try: if init: from start import start_cfg, start_mpi cfg = start_cfg() mpiflag, iproc, numproc, mpi = start_mpi() version_cubit = utilities.get_cubit_version() cubit.cmd('set logging on file "' + cfg.working_dir + '/cubit_proc_' + str(iproc) + '.log"') cubit.cmd("set echo off") cubit.cmd("set info off") if iproc == cfg.monitored_cpu: cubit.cmd("record '" + cfg.working_dir + "/monitor_" + str(cfg.monitored_cpu) + ".jou'") cubit.cmd("set journal on") if version_cubit < 16: cubit.cmd("journal error on") d = cfg.__dict__ ks = d.keys() ks.sort() for k in ks: if '__' not in k and '<' not in str(d[k]): if d[k] is not None: txt = str(k) + ' -----> ' + str(d[k]) txt = txt.replace("'", "").replace('"', '') cubit.cmd('comment "' + txt + '"') else: cubit.cmd("set journal " + cfg.jou_info) if version_cubit < 16: cubit.cmd("journal error " + cfg.jer_info) d = cfg.__dict__ ks = d.keys() ks.sort() for k in ks: if '__' not in k and '<' not in str(d[k]): if d[k] is not None: txt = str(k) + ' -----> ' + str(d[k]) txt = txt.replace("'", "").replace('"', '') cubit.cmd('comment "' + txt + '"') cubit.cmd("set echo " + cfg.echo_info) cubit.cmd("set info " + cfg.cubit_info) if version_cubit > 13 and version_cubit < 15: print('VERSION CUBIT ', version_cubit) print('VERSIONs of CUBIT > 13 have bugs with merge node') print('the merge option is not operative with this version') print('please download CUBIT 15+') else: print('VERSION CUBIT ', version_cubit) except: print('error start cubit') sys.exit() return cubit
def collect_new(cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,ckbound_method1=False,ckbound_method2=False,merge_tolerance=None,curverefining=False,outfilename='totalmesh_merged',qlog=False,export2SPECFEM3D=False,listblock=None,listflag=None,outdir='.',add_sea=False,decimate=False,cpml=False,cpml_size=False,top_absorbing=False,hex27=False,save_cubfile=True,check_merging=False): # cubit.cmd('set info off') cubit.cmd('set echo off') cubit.cmd('set journal off') #cubit.cmd('set error off') version_cubit=get_cubit_version() if decimate: if version_cubit >= 14.0: raise VersionException('check cubit version, decimate capability has been tested only with cubit <= 12.2') if version_cubit <= 12.2: collecting_merging(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy,cubfiles=cubfiles,ckbound_method1=ckbound_method1,ckbound_method2=ckbound_method2,merge_tolerance=merge_tolerance,decimate=decimate) elif version_cubit >= 14: collecting_merging_new(cpuxmin,cpuxmax+1,cpuymin,cpuymax+1,cpux,cpuy,cubfiles=cubfiles,check_merging=check_merging) else: raise VersionException('check cubit version, parallel capability of geocubit is working with cubit/trelis 14+ (or cubit 12.2)') cubit.cmd('set info on') cubit.cmd('set echo on') cubit.cmd('set journal on') #cubit.cmd('set error on') # if curverefining: if version_cubit <= 12.2: block=1001 #topography refine_closecurve(block,curverefining,acis=True) else: raise VersionException('check cubit version, refine curve capability has been tested only with cubit <= 12.2') # # if add_sea: if version_cubit <= 12.2: block=1001 add_sea_layer(block=block) else: raise VersionException('check cubit version, sea capability has been tested only with cubit <= 12.2') outdir2='/'.join(x for x in outfilename.split('/')[:-1]) if outdir2 == '': outdir2=outdir+'/' else: outdir2=outdir+'/'+outdir2+'/' import os try: os.makedirs(outdir2) except OSError: pass cubit.cmd('compress all') command="export mesh '"+outdir2+outfilename+".e' block all overwrite xml '"+outdir2+outfilename+".xml'" cubit.cmd(command) f=open(outdir2+'blocks.dat','w') blocks=cubit.get_block_id_list() # for block in blocks: name=cubit.get_exodus_entity_name('block',block) element_count = cubit.get_exodus_element_count(block, "block") nattrib=cubit.get_block_attribute_count(block) attr=[cubit.get_block_attribute_value(block,x) for x in range(0,nattrib)] ty=cubit.get_block_element_type(block) f.write(str(block)+' ; '+name+' ; nattr '+str(nattrib)+' ; '+' '.join(str(x) for x in attr)+' ; '+ty+' '+str(element_count)+'\n') f.close() # # cubit.cmd('set info echo journ off') cmd='del group all' cubit.silent_cmd(cmd) cubit.cmd('set info echo journ on') # # print 'end meshing' # # if qlog: print '\n\nQUALITY CHECK.... ***************\n\n' import quality_log tq=open(outdir2+outfilename+'.quality','w') max_skewness,min_length=quality_log.quality_log(tq) # # # if export2SPECFEM3D: e2SEM(files=False,listblock=listblock,listflag=listflag,outdir=outdir,cpml=cpml,cpml_size=cpml_size,top_absorbing=top_absorbing,hex27=hex27) if save_cubfile: vol_blocks=[x for x in blocks if x <=1000] cubit.cmd("create mesh geometry block "+' '.join(str(x) for x in vol_blocks)+" feature_angle 135.0") command = "save as '"+outdir2+outfilename+".cub' overwrite" print command cubit.cmd(command)
cpuymax = None curverefining = False add_sea = False decimate = False cpml = False cpml_size = False top_absorbing = False qlog = False hex27 = False check_merging = False save_cubfile = False cubit_version = get_cubit_version() if opts: for o, value in opts: if o in ('--starting_tolerance'): starting_tolerance = float(value) # print o, value if o in ('--save_cubfile'): save_cubfile = True if o in ('--step_tolerance'): step_tolerance = float(value) if o in ('--hex27'): hex27 = True if o in ('--cpml'):
cpuymax = None curverefining = False add_sea = False decimate = False cpml = False cpml_size = False top_absorbing = False qlog = False hex27 = False check_merging = False save_cubfile = False cubit_version = get_cubit_version() if opts: for o, value in opts: if o in ('--starting_tolerance'): starting_tolerance = float(value) # print o, value if o in ('--save_cubfile'): save_cubfile = True if o in ('--step_tolerance'): step_tolerance = float(value) if o in ('--hex27'): hex27 = True if o in ('--cpml'): cpml = True
def build_block(vol_list, name, id_0=1, top_surf=None, optionsea=False): # from sets import Set if optionsea: sea = optionsea['sea'] seaup = optionsea['seaup'] sealevel = optionsea['sealevel'] seathres = optionsea['seathres'] else: sea = False seaup = False sealevel = False seathres = False # print 'build blocks' block_list = cubit.get_block_id_list() print block_list, vol_list if len(block_list) > 0: id_block = max(max(block_list), 2) + id_0 else: # id_block = 2 + id_0 id_block = 0 for v, n in zip(vol_list, name): id_block += 1 v_other = Set(vol_list) - Set([v]) if sea and v == vol_list[-1]: cubit.cmd('set duplicate block elements off') tsurf_string = " ".join(str(x) for x in top_surf) # sea command = 'block ' + str(id_block) + ' hex in node in surf ' + \ tsurf_string + ' with Z_coord < ' + str(seathres) cubit.cmd(command) command = "block " + str(id_block) + " name 'sea" + n + "'" cubit.cmd(command) if not seaup: id_block += 1 command = 'block ' + str(id_block) + ' hex in node in surf ' +\ tsurf_string + ' with (Z_coord > ' + str(seathres) +\ ' and Z_coord < ' + str(sealevel) cubit.cmd(command) command = "block " + str(id_block) + " name 'shwater" + n + "'" cubit.cmd(command) id_block += 1 command = 'block ' + str(id_block) + ' hex in node in surf ' + \ tsurf_string + ' with Z_coord >= ' + str(sealevel) cubit.cmd(command) command = "block " + str(id_block) + " name 'continent" + n + "'" cubit.cmd(command) else: version_cubit = get_cubit_version() if version_cubit >= 15: command = 'block ' + str(id_block) + ' hex in vol ' + \ str(v) print command else: command = 'block ' + str(id_block) + ' hex in vol ' + \ str(v) + ' except hex in vol ' + str(list(v_other)) print command command = command.replace("[", " ").replace("]", " ") cubit.cmd(command) command = "block " + str(id_block) + " name '" + n + "'" cubit.cmd(command)
def mesh_layercake_regularmap(filename=None): import start as start mpiflag, iproc, numproc, mpi = start.start_mpi() from utilities import importgeometry, savemesh, get_v_h_list from utilities import cubit_command_check, get_cubit_version # # numpy = start.start_numpy() cfg = start.start_cfg(filename=filename) # from math import sqrt from sets import Set version_cubit = get_cubit_version() list_vol = cubit.parse_cubit_list("volume", "all") if len(list_vol) != 0: pass else: geometryfile = 'geometry_vol_' + str(iproc) + '.cub' importgeometry(geometryfile, iproc=iproc) command = 'composite create curve all' cubit.cmd(command) print('###"No valid composites can be created from the specified curves." \ is NOT a critical ERROR.') # command = "compress all" cubit.cmd(command) list_vol = cubit.parse_cubit_list("volume", "all") nvol = len(list_vol) vol = [] for id_vol in list_vol: p = cubit.get_center_point("volume", id_vol) vol.append(cubitvolume(id_vol, 1, p[2], 0)) vol.sort(by_z) # for id_vol in range(0, nvol): vol[id_vol].intervalv = cfg.iv_interval[id_vol] # # surf_vertical = [] surf_or = [] # top_surface = 0 # top_surface_add = '' # bottom_surface = 0 # # # zmin_box = cubit.get_total_bounding_box("volume", list_vol)[6] # xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] # xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] # ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] # ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] # # # interval assignement surf_or, surf_vertical, list_curve_or, list_curve_vertical, \ bottom, top = get_v_h_list(list_vol, chktop=cfg.chktop) print('vertical surfaces: ', surf_vertical) for k in surf_vertical: command = "surface " + str(k) + " scheme submap" cubit.cmd(command) for k in surf_or: command = "surface " + str(k) + " scheme " + cfg.or_mesh_scheme cubit.cmd(command) # ucurve, vcurve = get_uv_curve(list_curve_or) schemepave = False # ucurve_interval = {} for k in ucurve: length = cubit.get_curve_length(k) interval = int(2 * round(.5 * length / cfg.size, 0)) ucurve_interval[k] = interval command = "curve " + str(k) + " interval " + str(interval) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) if max(ucurve_interval.values()) != min(ucurve_interval.values()): schemepave = True print('mesh scheme is set to pave') for sk in surf_or: command = "surface " + str(sk) + " scheme pave" cubit.cmd(command) # vcurve_interval = {} for k in vcurve: length = cubit.get_curve_length(k) interval = int(2 * round(.5 * length / cfg.size, 0)) vcurve_interval[k] = interval command = "curve " + str(k) + " interval " + str(interval) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) if max(vcurve_interval.values()) != min(vcurve_interval.values()): print('mesh scheme is set to pave') schemepave = True for sk in surf_or: command = "surface " + str(sk) + " scheme pave" cubit.cmd(command) # for s in surf_vertical: lcurve = cubit.get_relatives("surface", s, "curve") interval_store = [] for k in lcurve: interval_curve = cubit.get_mesh_intervals('curve', k) if k in list_curve_vertical: volume_id = cubit.get_owning_volume("curve", k) for idv in range(0, nvol): if vol[idv].ID == volume_id: int_v = vol[idv].intervalv command = "curve " + str(k) + " interval " + str(int_v) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) else: interval_store.append((k, interval_curve)) if len(interval_store) != 0: interval_min = min([iv[1] for iv in interval_store]) str_interval = [str(iv[0]) for iv in interval_store] cmd = "curve " + ' '.join(str_interval) + \ " interval " + str(interval_min) cubit.cmd(cmd) command = "curve " + \ ' '.join(str(iv[0]) for iv in interval_store) + " scheme equal" cubit.cmd(command) command = "surface " + str(s) + " scheme submap" cubit.cmd(command) # meshing if cfg.or_mesh_scheme == 'pave' or schemepave: command = 'mesh surf ' + ' '.join(str(t) for t in top) status = cubit_command_check(iproc, command, stop=True) # cubit.cmd(command) elif cfg.or_mesh_scheme == 'map': command = 'mesh surf ' + ' '.join(str(t) for t in bottom) status = cubit_command_check(iproc, command, stop=True) # cubit.cmd(command) for id_volume in range(nvol - 1, -1, -1): command = "mesh vol " + str(vol[id_volume].ID) status = cubit_command_check(iproc, command, stop=False) if not status: for s in surf_vertical: command_surf = "mesh surf " + str(s) cubit.cmd(command_surf) if version_cubit < 16: command_set_meshvol = '''volume all redistribute nodes on volume all autosmooth target off volume all scheme Sweep Vector 0 0 -1 volume all sweep smooth Auto ''' else: command_set_meshvol = '''volume all redistribute nodes on volume all autosmooth target off volume all scheme Sweep Vector 0 0 -1 ''' status2 = cubit_command_check( iproc, command_set_meshvol, stop=False) status2 = cubit_command_check(iproc, command, stop=False) if not status2: _surf = cubit.get_relatives( 'volume', vol[id_volume].ID, 'surface') local_o_surf = [x for x in _surf if x in surf_or] cubit.cmd('volume ' + str(vol[id_volume].ID) + ' redistribute nodes off') cubit.cmd('volume ' + str(vol[id_volume].ID) + ' scheme Sweep source surface ' + ' '.join(str(x) for x in local_o_surf[0:-1]) + ' target surface ' + str(local_o_surf[-1])) cubit.cmd('volume ' + str(vol[id_volume].ID) + ' autosmooth_target off') status = cubit_command_check(iproc, command, stop=True) # # smoothing print(iproc, 'untangling...') cmd = "volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd = "smooth volume all" cubit.cmd(cmd) if cfg.smoothing: print('smoothing .... ' + str(cfg.smoothing)) cubitcommand = 'surf all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand = 'smooth surf all' cubit.cmd(cubitcommand) # cubitcommand = 'vol all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand = 'smooth vol all' cubit.cmd(cubitcommand) # # # vertical refinement # for nvol = 3 ## # ___________________________ interface 4 ## # vol 2 # ___________________________ interface 3 ## # vol 1 # ___________________________ interface 2 ## # vol 0 # ___________________________ interface 1 ## refinement(nvol, vol, filename=filename) # # top layer vertical coarsening print('coarsening top layer... ', cfg.coarsening_top_layer) if cfg.coarsening_top_layer: cubitcommand = 'del mesh vol ' + str(vol[-1].ID) + ' propagate' cubit.cmd(cubitcommand) s1 = Set(list_curve_vertical) command = "group 'list_curve_tmp' add curve " + \ "in vol " + str(vol[-1].ID) cubit.cmd(command) group = cubit.get_id_from_name("list_curve_tmp") list_curve_tmp = cubit.get_group_curves(group) command = "delete group " + str(group) cubit.cmd(command) s2 = Set(list_curve_tmp) lc = list(s1 & s2) # cubitcommand = 'curve ' + \ ' '.join(str(x) for x in lc) + ' interval ' + \ str(cfg.actual_vertical_interval_top_layer) cubit.cmd(cubitcommand) cubitcommand = 'mesh vol ' + str(vol[-1].ID) cubit.cmd(cubitcommand) # n = cubit.get_sideset_id_list() if len(n) != 0: command = "del sideset all" cubit.cmd(command) n = cubit.get_block_id_list() if len(n) != 0: command = "del block all" cubit.cmd(command) # import boundary_definition entities = ['face'] print(iproc, 'hex block definition...') boundary_definition.define_bc(entities, parallel=True, cpux=cfg.cpux, cpuy=cfg.cpuy, cpuxmin=0, cpuymin=0, optionsea=False) # save mesh print(iproc, 'untangling...') cmd = "volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd = "smooth volume all" cubit.cmd(cmd) print(iproc, 'saving...') savemesh(mpiflag, iproc=iproc, filename=filename)
def readcfg(filename=None,importmenu=False,mpiflag=False): """ read the configuration file, filename is defined in the command line arguments (see menu.py) """ if importmenu: import menu as menu cfgname=menu.cfg_name id_proc=menu.id_proc create_plane=menu.create_plane menusurface=menu.surface single=menu.single elif filename: cfgname=filename id_proc=0 menu=False create_plane=False menusurface=False single=False else: print 'error: no configuration file' import sys sys.exit() # from utilities import geo2utm,get_cubit_version #here I can use pyproj but I prefere to include a function in pure python in order to avoid an additional installation # # import ConfigParser config = ConfigParser.ConfigParser() # # def converter(s): if s == 'True': value=True elif s == 'False': value=False elif s == 'None': value= None else: if s.count(',') != 0: value=s.split(',') while value.count(''): value.remove('') else: value=s try: if type(value).__name__ == 'str': if str(value).count('.') != 0: value=float(value) else: value=int(value) else: if str(value).count('.') != 0: value=map(float,value) else: value=map(int,value) except: pass return value # def section_dict(section): dict_o = {} options = config.options(section) for option in options: try: value=converter(config.get(section, option)) dict_o[option] = value except: dict_o[option] = None return dict_o class attrdict(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__dict__ = self def __str__(self): names=[] values=[] for name,value in self.items(): names.append(name) values.append(value) print names,values a=zip(names,values) a.sort() arc='' for o in a: if o[0][0] != arc: print print o[0],' -> ',o[1] arc=o[0][0] return '____' # dcfg={} # #CONSTANTS dcfg['osystem'] = 'linux' dcfg['debug_cfg']=False dcfg['version_cubit']=get_cubit_version() dcfg['checkbound']=False dcfg['top_partitioner'] = 10000 dcfg['tres']=0.3 #if n is the vertical component of the normal at a surface pointing horizontally, when -tres < n < tres then the surface is vertical dcfg['precision'] =0.02 #precision for the boundary check (0.02 m) # #INIT dcfg['debug']=True dcfg['cubit_info']="on" dcfg['echo_info']="on" dcfg['jou_info']="on" dcfg['jer_info']="on" dcfg['monitored_cpu']=0 dcfg['parallel_import']=True dcfg['save_geometry_cubit']=True dcfg['save_surface_cubit']=False dcfg['save_geometry_paraview'] = False #not implemented dcfg['save_geometry_ACIS'] = False #not implemented dcfg['export_exodus_mesh']=False dcfg['manual_adj'] =False dcfg['play_adj'] =False dcfg['no_adj'] =False dcfg['nx']=False dcfg['ny']=False dcfg['nstep']=False dcfg['localdir_is_globaldir']=True dcfg['refinement_depth']=[] dcfg['scratchdir']=None dcfg['map_meshing_type']='regularmap' dcfg['4sideparallel']=True dcfg["outlinebasin_curve"]=False dcfg["transition_curve"]=False dcfg["faulttrace_curve"]=False dcfg['geological_imprint']=False dcfg['number_processor_xi']=1 dcfg['number_processor_eta']=1 dcfg['filename']=None dcfg['actual_vertical_interval_top_layer']=1 dcfg['coarsening_top_layer']=False dcfg['refineinsidevol']=False dcfg['sea']=False dcfg['seaup']=False dcfg['sea_level']=False dcfg['sea_threshold']=False dcfg['subduction']=True dcfg['subduction_thres']=500 dcfg['debugsurface']=False #if true it creates only the surface not the lofted volumes dcfg['lat_orientation']=False dcfg['irregulargridded_surf']=False dcfg['chktop']=False dcfg['smoothing']=False dcfg['ntripl']=0 dcfg['debug_geometry']=False if float(dcfg['version_cubit']) >= 13.1: dcfg['volumecreation_method']=None else: dcfg['volumecreation_method']='loft' dcfg['nsurf'] = None if cfgname: config.read(cfgname) sections=['cubit.options','simulation.cpu_parameters','geometry.surfaces','geometry.volumes','geometry.volumes.layercake','geometry.volumes.flatcake','geometry.volumes.partitioner','geometry.partitioner','meshing'] for section in sections: try: d=section_dict(section) dcfg.update(d) except: pass if dcfg['nsurf']: surface_name=[] num_x=[] num_y=[] xstep=[] ystep=[] step=[] directionx=[] directiony=[] unit2=[] surf_type=[] delimiter=[] nsurf=int(dcfg['nsurf']) for i in range(1,nsurf+1): section='surface'+str(i)+'.parameters' d=section_dict(section) surface_name.append(d['name']) surf_type.append(d['surf_type']) unit2.append(d['unit_surf']) if d['surf_type'] == 'regular_grid': xstep.append(d['step_along_x']) ystep.append(d['step_along_y']) num_x.append(d['number_point_along_x']) num_y.append(d['number_point_along_y']) elif d['surf_type'] == 'skin': step.append(d['step']) try: delimiter.append(d['delimiter']) except: pass directionx.append(d['directionx']) directiony.append(d['directiony']) dcfg['surface_name']=surface_name dcfg['num_x']=num_x dcfg['num_y']=num_y dcfg['xstep']=xstep dcfg['ystep']=ystep dcfg['step']=step dcfg['directionx']=directionx dcfg['directiony']=directiony dcfg['unit2']=unit2 dcfg['surf_type']=surf_type dcfg['delimiter']=delimiter try: tres=0 xmin,ymin=geo2utm(dcfg['longitude_min'],dcfg['latitude_min'],dcfg['unit']) xmax,ymax=geo2utm(dcfg['longitude_max'],dcfg['latitude_max'],dcfg['unit']) dcfg['xmin']=xmin dcfg['ymin']=ymin dcfg['xmax']=xmax dcfg['ymax']=ymax x1,y1=geo2utm(dcfg['longitude_min'],dcfg['latitude_min'],dcfg['unit']) x2,y2=geo2utm(dcfg['longitude_max'],dcfg['latitude_min'],dcfg['unit']) x3,y3=geo2utm(dcfg['longitude_max'],dcfg['latitude_max'],dcfg['unit']) x4,y4=geo2utm(dcfg['longitude_min'],dcfg['latitude_max'],dcfg['unit']) dcfg['x1_box']=x1 dcfg['y1_box']=y1 dcfg['x2_box']=x2 dcfg['y2_box']=y2 dcfg['x3_box']=x3 dcfg['y3_box']=y3 dcfg['x4_box']=x4 dcfg['y4_box']=y4 dcfg['tres_boundarydetection']=tres except: pass if dcfg['sea']: if not dcfg['sea_level']: dcfg['sea_level']=0 if not dcfg['sea_threshold']: dcfg['sea_threshold']=-200 dcfg['actual_vertical_interval_top_layer']=1 dcfg['coarsening_top_layer']=True dcfg['optionsea']={'sea':dcfg['sea'],'seaup':dcfg['seaup'],'sealevel':dcfg['sea_level'],'seathres':dcfg['sea_threshold']} cfg=attrdict(dcfg) if menu: try: if cfg.working_dir[-1] == '/': cfg.working_dir=cfg.working_dir[:-1] if cfg.working_dir[0] != '/': cfg.working_dir='./'+cfg.working_dir except: cfg.working_dir=os.getcwd() try: if cfg.output_dir[-1] == '/': cfg.output_dir=cfg.output_dir[:-1] if cfg.output_dir[0] != '/': cfg.output_dir='./'+cfg.output_dir except: cfg.output_dir=os.getcwd() try: if cfg.SPECFEM3D_output_dir[-1] == '/': cfg.SPECFEM3D_output_dir=cfg.SPECFEM3D_output_dir[:-1] if cfg.SPECFEM3D_output_dir[0] != '/': cfg.SPECFEM3D_output_dir='./'+cfg.SPECFEM3D_output_dir except: cfg.SPECFEM3D_output_dir=os.getcwd() cfg.single=single if menusurface: cfg.nsurf=1 cfg.name=[menu.surface_name] cfg.num_x=[menu.num_x] cfg.num_y=[menu.num_x] cfg.unit=[menu.unit] cfg.surf_type=[menu.surf_type] try: cfg.delimiter=[menu.delimiter] except: cfg.delimiter=[' '] cfg.directionx=[menu.directionx] cfg.directiony=[menu.directiony] else: cfg.SPECFEM3D_output_dir=os.getcwd() if not cfg.number_processor_eta and cfg.nodes: cfg.number_processor_xi,cfg.number_processor_eta=split(cfg.nodes) if isinstance(cfg.filename,str): cfg.filename=[cfg.filename] try: cfg.nproc_eta=cfg.number_processor_eta cfg.nproc_xi=cfg.number_processor_xi cfg.cpuy=cfg.number_processor_eta cfg.cpux=cfg.number_processor_xi except: pass if create_plane: cfg.x1=map(float,menu.x1.split(',')) cfg.x2=map(float,menu.x2.split(',')) cfg.x3=map(float,menu.x3.split(',')) cfg.x4=map(float,menu.x4.split(',')) cfg.unit=menu.unit # if menu: cfg.id_proc=menu.id_proc else: cfg.id_proc=id_proc # try: if isinstance(cfg.tripl,int): cfg.tripl=[cfg.tripl] except: pass try: if isinstance(cfg.iv_interval,int): cfg.iv_interval=[cfg.iv_interval] except: pass try: if isinstance(cfg.refinement_depth,int): cfg.refinement_depth=[cfg.refinement_depth] except: pass return cfg
def mesh_layercake_regularmap(filename=None): import start as start mpiflag, iproc, numproc, mpi = start.start_mpi() from utilities import importgeometry, savemesh, get_v_h_list from utilities import cubit_command_check, get_cubit_version # # numpy = start.start_numpy() cfg = start.start_cfg(filename=filename) # from math import sqrt from sets import Set version_cubit = get_cubit_version() list_vol = cubit.parse_cubit_list("volume", "all") if len(list_vol) != 0: pass else: geometryfile = 'geometry_vol_' + str(iproc) + '.cub' importgeometry(geometryfile, iproc=iproc) command = 'composite create curve all' cubit.cmd(command) print '###"No valid composites can be created from the specified curves." \ is NOT a critical ERROR.' # command = "compress all" cubit.cmd(command) list_vol = cubit.parse_cubit_list("volume", "all") nvol = len(list_vol) vol = [] for id_vol in list_vol: p = cubit.get_center_point("volume", id_vol) vol.append(cubitvolume(id_vol, 1, p[2], 0)) vol.sort(by_z) # for id_vol in range(0, nvol): vol[id_vol].intervalv = cfg.iv_interval[id_vol] # # surf_vertical = [] surf_or = [] # top_surface = 0 # top_surface_add = '' # bottom_surface = 0 # # # zmin_box = cubit.get_total_bounding_box("volume", list_vol)[6] # xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] # xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] # ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] # ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] # # # interval assignement surf_or, surf_vertical, list_curve_or, list_curve_vertical, \ bottom, top = get_v_h_list(list_vol, chktop=cfg.chktop) print 'vertical surfaces: ', surf_vertical for k in surf_vertical: command = "surface " + str(k) + " scheme submap" cubit.cmd(command) for k in surf_or: command = "surface " + str(k) + " scheme " + cfg.or_mesh_scheme cubit.cmd(command) # ucurve, vcurve = get_uv_curve(list_curve_or) schemepave = False # ucurve_interval = {} for k in ucurve: length = cubit.get_curve_length(k) interval = int(2 * round(.5 * length / cfg.size, 0)) ucurve_interval[k] = interval command = "curve " + str(k) + " interval " + str(interval) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) if max(ucurve_interval.values()) != min(ucurve_interval.values()): schemepave = True print 'mesh scheme is set to pave' for sk in surf_or: command = "surface " + str(sk) + " scheme pave" cubit.cmd(command) # vcurve_interval = {} for k in vcurve: length = cubit.get_curve_length(k) interval = int(2 * round(.5 * length / cfg.size, 0)) vcurve_interval[k] = interval command = "curve " + str(k) + " interval " + str(interval) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) if max(vcurve_interval.values()) != min(vcurve_interval.values()): print 'mesh scheme is set to pave' schemepave = True for sk in surf_or: command = "surface " + str(sk) + " scheme pave" cubit.cmd(command) # for s in surf_vertical: lcurve = cubit.get_relatives("surface", s, "curve") interval_store = [] for k in lcurve: interval_curve = cubit.get_mesh_intervals('curve', k) if k in list_curve_vertical: volume_id = cubit.get_owning_volume("curve", k) for idv in range(0, nvol): if vol[idv].ID == volume_id: int_v = vol[idv].intervalv command = "curve " + str(k) + " interval " + str(int_v) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) else: interval_store.append((k, interval_curve)) if len(interval_store) != 0: interval_min = min([iv[1] for iv in interval_store]) str_interval = [str(iv[0]) for iv in interval_store] cmd = "curve " + ' '.join(str_interval) + \ " interval " + str(interval_min) cubit.cmd(cmd) command = "curve " + \ ' '.join(str(iv[0]) for iv in interval_store) + " scheme equal" cubit.cmd(command) command = "surface " + str(s) + " scheme submap" cubit.cmd(command) # meshing if cfg.or_mesh_scheme == 'pave' or schemepave: command = 'mesh surf ' + ' '.join(str(t) for t in top) status = cubit_command_check(iproc, command, stop=True) # cubit.cmd(command) elif cfg.or_mesh_scheme == 'map': command = 'mesh surf ' + ' '.join(str(t) for t in bottom) status = cubit_command_check(iproc, command, stop=True) # cubit.cmd(command) for id_volume in range(nvol - 1, -1, -1): command = "mesh vol " + str(vol[id_volume].ID) status = cubit_command_check(iproc, command, stop=False) if not status: for s in surf_vertical: command_surf = "mesh surf " + str(s) cubit.cmd(command_surf) if version_cubit < 16: command_set_meshvol = '''volume all redistribute nodes on volume all autosmooth target off volume all scheme Sweep Vector 0 0 -1 volume all sweep smooth Auto ''' else: command_set_meshvol = '''volume all redistribute nodes on volume all autosmooth target off volume all scheme Sweep Vector 0 0 -1 ''' status2 = cubit_command_check( iproc, command_set_meshvol, stop=False) status2 = cubit_command_check(iproc, command, stop=False) if not status2: _surf = cubit.get_relatives( 'volume', vol[id_volume].ID, 'surface') local_o_surf = [x for x in _surf if x in surf_or] cubit.cmd('volume ' + str(vol[id_volume].ID) + ' redistribute nodes off') cubit.cmd('volume ' + str(vol[id_volume].ID) + ' scheme Sweep source surface ' + ' '.join(str(x) for x in local_o_surf[0:-1]) + ' target surface ' + str(local_o_surf[-1])) cubit.cmd('volume ' + str(vol[id_volume].ID) + ' autosmooth_target off') status = cubit_command_check(iproc, command, stop=True) # # smoothing print iproc, 'untangling...' cmd = "volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd = "smooth volume all" cubit.cmd(cmd) if cfg.smoothing: print 'smoothing .... ' + str(cfg.smoothing) cubitcommand = 'surf all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand = 'smooth surf all' cubit.cmd(cubitcommand) # cubitcommand = 'vol all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand = 'smooth vol all' cubit.cmd(cubitcommand) # # # vertical refinement # for nvol = 3 ## # ___________________________ interface 4 ## # vol 2 # ___________________________ interface 3 ## # vol 1 # ___________________________ interface 2 ## # vol 0 # ___________________________ interface 1 ## refinement(nvol, vol, filename=filename) # # top layer vertical coarsening print 'coarsening top layer... ', cfg.coarsening_top_layer if cfg.coarsening_top_layer: cubitcommand = 'del mesh vol ' + str(vol[-1].ID) + ' propagate' cubit.cmd(cubitcommand) s1 = Set(list_curve_vertical) command = "group 'list_curve_tmp' add curve " + \ "in vol " + str(vol[-1].ID) cubit.cmd(command) group = cubit.get_id_from_name("list_curve_tmp") list_curve_tmp = cubit.get_group_curves(group) command = "delete group " + str(group) cubit.cmd(command) s2 = Set(list_curve_tmp) lc = list(s1 & s2) # cubitcommand = 'curve ' + \ ' '.join(str(x) for x in lc) + ' interval ' + \ str(cfg.actual_vertical_interval_top_layer) cubit.cmd(cubitcommand) cubitcommand = 'mesh vol ' + str(vol[-1].ID) cubit.cmd(cubitcommand) # n = cubit.get_sideset_id_list() if len(n) != 0: command = "del sideset all" cubit.cmd(command) n = cubit.get_block_id_list() if len(n) != 0: command = "del block all" cubit.cmd(command) # import boundary_definition entities = ['face'] print iproc, 'hex block definition...' boundary_definition.define_bc(entities, parallel=True, cpux=cfg.cpux, cpuy=cfg.cpuy, cpuxmin=0, cpuymin=0, optionsea=False) # save mesh print iproc, 'untangling...' cmd = "volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd = "smooth volume all" cubit.cmd(cmd) print iproc, 'saving...' savemesh(mpiflag, iproc=iproc, filename=filename)
def readcfg(filename=None, importmenu=False, mpiflag=False): """ read the configuration file, filename is defined in the command line arguments (see menu.py) """ if importmenu: import menu as menu cfgname = menu.cfg_name id_proc = menu.id_proc create_plane = menu.create_plane menusurface = menu.surface single = menu.single elif filename: cfgname = filename id_proc = 0 menu = False create_plane = False menusurface = False single = False else: print "error: no configuration file" import sys sys.exit() # from utilities import ( geo2utm, get_cubit_version, ) # here I can use pyproj but I prefere to include a function in pure python in order to avoid an additional installation # # import ConfigParser config = ConfigParser.ConfigParser() # # def converter(s): if s == "True": value = True elif s == "False": value = False elif s == "None": value = None else: if s.count(",") != 0: value = s.split(",") while value.count(""): value.remove("") else: value = s try: if type(value).__name__ == "str": if str(value).count(".") != 0: value = float(value) else: value = int(value) else: if str(value).count(".") != 0: value = map(float, value) else: value = map(int, value) except: pass return value # def section_dict(section): dict_o = {} options = config.options(section) for option in options: try: value = converter(config.get(section, option)) dict_o[option] = value except: dict_o[option] = None return dict_o class attrdict(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__dict__ = self def __str__(self): names = [] values = [] for name, value in self.items(): names.append(name) values.append(value) print names, values a = zip(names, values) a.sort() arc = "" for o in a: if o[0][0] != arc: print print o[0], " -> ", o[1] arc = o[0][0] print __name__ return "____" # dcfg = {} # # CONSTANTS dcfg["osystem"] = "linux" dcfg["debug_cfg"] = False dcfg["version_cubit"] = get_cubit_version() dcfg["checkbound"] = False dcfg["top_partitioner"] = 10000 dcfg[ "tres" ] = ( 0.3 ) # if n is the vertical component of the normal at a surface pointing horizontally, when -tres < n < tres then the surface is vertical dcfg["precision"] = 0.02 # precision for the boundary check (0.02 m) # # INIT dcfg["debug"] = True dcfg["cubit_info"] = "on" dcfg["echo_info"] = "on" dcfg["jou_info"] = "on" dcfg["jer_info"] = "on" dcfg["monitored_cpu"] = 0 dcfg["parallel_import"] = True dcfg["save_geometry_cubit"] = True dcfg["save_surface_cubit"] = False dcfg["save_geometry_paraview"] = False # not implemented dcfg["save_geometry_ACIS"] = False # not implemented dcfg["export_exodus_mesh"] = False dcfg["manual_adj"] = False dcfg["play_adj"] = False dcfg["no_adj"] = False dcfg["nx"] = False dcfg["ny"] = False dcfg["nstep"] = False dcfg["localdir_is_globaldir"] = True dcfg["refinement_depth"] = [] dcfg["scratchdir"] = None dcfg["map_meshing_type"] = "regularmap" dcfg["4sideparallel"] = True dcfg["outlinebasin_curve"] = False dcfg["transition_curve"] = False dcfg["faulttrace_curve"] = False dcfg["geological_imprint"] = False dcfg["number_processor_xi"] = 1 dcfg["number_processor_eta"] = 1 dcfg["filename"] = None dcfg["actual_vertical_interval_top_layer"] = 1 dcfg["coarsening_top_layer"] = False dcfg["refineinsidevol"] = False dcfg["sea"] = False dcfg["seaup"] = False dcfg["sea_level"] = False dcfg["sea_threshold"] = False dcfg["subduction"] = False dcfg["subduction_thres"] = 500 dcfg["debugsurface"] = False # if true it creates only the surface not the lofted volumes dcfg["lat_orientation"] = False dcfg["irregulargridded_surf"] = False dcfg["chktop"] = False dcfg["smoothing"] = False dcfg["ntripl"] = 0 dcfg["debug_geometry"] = False dcfg["topflat"] = False if float(dcfg["version_cubit"]) >= 13.1: dcfg["volumecreation_method"] = None else: dcfg["volumecreation_method"] = "loft" dcfg["nsurf"] = None if cfgname: config.read(cfgname) sections = [ "cubit.options", "simulation.cpu_parameters", "geometry.surfaces", "geometry.volumes", "geometry.volumes.layercake", "geometry.volumes.flatcake", "geometry.volumes.partitioner", "geometry.partitioner", "meshing", ] for section in sections: try: d = section_dict(section) dcfg.update(d) except: pass # print dcfg if dcfg["nsurf"]: surface_name = [] num_x = [] num_y = [] xstep = [] ystep = [] step = [] directionx = [] directiony = [] unit2 = [] surf_type = [] delimiter = [] nsurf = int(dcfg["nsurf"]) for i in range(1, nsurf + 1): section = "surface" + str(i) + ".parameters" d = section_dict(section) surface_name.append(d["name"]) surf_type.append(d["surf_type"]) unit2.append(d["unit_surf"]) if d["surf_type"] == "regular_grid": xstep.append(d["step_along_x"]) ystep.append(d["step_along_y"]) num_x.append(d["number_point_along_x"]) num_y.append(d["number_point_along_y"]) elif d["surf_type"] == "skin": step.append(d["step"]) try: delimiter.append(d["delimiter"]) except: pass directionx.append(d["directionx"]) directiony.append(d["directiony"]) dcfg["surface_name"] = surface_name dcfg["num_x"] = num_x dcfg["num_y"] = num_y dcfg["xstep"] = xstep dcfg["ystep"] = ystep dcfg["step"] = step dcfg["directionx"] = directionx dcfg["directiony"] = directiony dcfg["unit2"] = unit2 dcfg["surf_type"] = surf_type dcfg["delimiter"] = delimiter try: tres = 0 xmin, ymin = geo2utm(dcfg["longitude_min"], dcfg["latitude_min"], dcfg["unit"]) xmax, ymax = geo2utm(dcfg["longitude_max"], dcfg["latitude_max"], dcfg["unit"]) dcfg["xmin"] = xmin dcfg["ymin"] = ymin dcfg["xmax"] = xmax dcfg["ymax"] = ymax x1, y1 = geo2utm(dcfg["longitude_min"], dcfg["latitude_min"], dcfg["unit"]) x2, y2 = geo2utm(dcfg["longitude_max"], dcfg["latitude_min"], dcfg["unit"]) x3, y3 = geo2utm(dcfg["longitude_max"], dcfg["latitude_max"], dcfg["unit"]) x4, y4 = geo2utm(dcfg["longitude_min"], dcfg["latitude_max"], dcfg["unit"]) dcfg["x1_box"] = x1 dcfg["y1_box"] = y1 dcfg["x2_box"] = x2 dcfg["y2_box"] = y2 dcfg["x3_box"] = x3 dcfg["y3_box"] = y3 dcfg["x4_box"] = x4 dcfg["y4_box"] = y4 dcfg["tres_boundarydetection"] = tres except: pass if dcfg["irregulargridded_surf"]: print "test" dcfg["xmin"] = dcfg["longitude_min"] dcfg["ymin"] = dcfg["latitude_min"] dcfg["xmax"] = dcfg["longitude_max"] dcfg["ymax"] = dcfg["latitude_max"] if dcfg["sea"]: if not dcfg["sea_level"]: dcfg["sea_level"] = 0 if not dcfg["sea_threshold"]: dcfg["sea_threshold"] = -200 dcfg["actual_vertical_interval_top_layer"] = 1 dcfg["coarsening_top_layer"] = True dcfg["optionsea"] = { "sea": dcfg["sea"], "seaup": dcfg["seaup"], "sealevel": dcfg["sea_level"], "seathres": dcfg["sea_threshold"], } cfg = attrdict(dcfg) if menu: try: if cfg.working_dir[-1] == "/": cfg.working_dir = cfg.working_dir[:-1] if cfg.working_dir[0] != "/": cfg.working_dir = "./" + cfg.working_dir except: cfg.working_dir = os.getcwd() try: if cfg.output_dir[-1] == "/": cfg.output_dir = cfg.output_dir[:-1] if cfg.output_dir[0] != "/": cfg.output_dir = "./" + cfg.output_dir except: cfg.output_dir = os.getcwd() try: if cfg.SPECFEM3D_output_dir[-1] == "/": cfg.SPECFEM3D_output_dir = cfg.SPECFEM3D_output_dir[:-1] if cfg.SPECFEM3D_output_dir[0] != "/": cfg.SPECFEM3D_output_dir = "./" + cfg.SPECFEM3D_output_dir except: cfg.SPECFEM3D_output_dir = os.getcwd() cfg.single = single if menusurface: cfg.nsurf = 1 cfg.name = [menu.surface_name] cfg.num_x = [menu.num_x] cfg.num_y = [menu.num_x] cfg.unit = [menu.unit] cfg.surf_type = [menu.surf_type] try: cfg.delimiter = [menu.delimiter] except: cfg.delimiter = [" "] cfg.directionx = [menu.directionx] cfg.directiony = [menu.directiony] else: cfg.SPECFEM3D_output_dir = os.getcwd() if not cfg.number_processor_eta and cfg.nodes: cfg.number_processor_xi, cfg.number_processor_eta = split(cfg.nodes) if isinstance(cfg.filename, str): cfg.filename = [cfg.filename] try: cfg.nproc_eta = cfg.number_processor_eta cfg.nproc_xi = cfg.number_processor_xi cfg.cpuy = cfg.number_processor_eta cfg.cpux = cfg.number_processor_xi except: pass if create_plane: cfg.x1 = map(float, menu.x1.split(",")) cfg.x2 = map(float, menu.x2.split(",")) cfg.x3 = map(float, menu.x3.split(",")) cfg.x4 = map(float, menu.x4.split(",")) cfg.unit = menu.unit # if menu: cfg.id_proc = menu.id_proc else: cfg.id_proc = id_proc # try: if isinstance(cfg.tripl, int): cfg.tripl = [cfg.tripl] except: pass try: if isinstance(cfg.iv_interval, int): cfg.iv_interval = [cfg.iv_interval] except: pass try: if isinstance(cfg.refinement_depth, int): cfg.refinement_depth = [cfg.refinement_depth] except: pass return cfg