Esempio n. 1
0
def plane(cfg):
    import sys,os
    from math import sqrt
    from utilities import geo2utm
    import start as start
    #
    #
    cubit                   = start.start_cubit()
    #
    #
    command = "reset"
    cubit.cmd(command)
    #
    #
    for p in [cfg.x1,cfg.x2,cfg.x3,cfg.x4]:
        x_current,y_current=geo2utm(p[0],p[1],cfg.unit)
        cubitcommand= 'create vertex '+ str( x_current )+ ' ' + str( y_current) +' '+ str( p[2] )
        cubit.cmd(cubitcommand)
    #
    cubitcommand= 'create surface vertex 1 2 3 4'
    cubit.cmd(cubitcommand)
    command = "del vertex all"
    cubit.cmd(command)
    command = "save as 'plane.cub' overwrite"
    cubit.cmd(command)
    #
    #
    #        
    cubit.cmd("set info "+cfg.cubit_info)
    cubit.cmd("set echo "+cfg.echo_info)
    cubit.cmd("set journal "+cfg.jou_info)
Esempio n. 2
0
def process_surfacefiles(iproc, nx, ny, nstep, grdfile, unit, lat_orientation):
    from utilities import geo2utm
    numpy = start.start_numpy()
    elev = numpy.zeros([nx, ny], float)
    coordx = numpy.zeros([nx, ny], float)
    coordy = numpy.zeros([nx, ny], float)
    icoord = 0

    lat_orientation = check_orientation(grdfile)

    try:
        grdfile = open(grdfile, 'r')
        # print 'reading ',grdfile
    except:
        txt = 'error reading: ' + str(grdfile)
        raise Exception(txt)

    if lat_orientation is 'SOUTH2NORTH':
        rangey = range(0, ny)
    else:
        rangey = range(ny - 1, -1, -1)
        lat_orientation = 'NORTH2SOUTH'
    print lat_orientation
    for iy in rangey:
        for ix in range(0, nx):
            txt = grdfile.readline()
            try:
                if len(txt) != 0:
                    x, y, z = map(float, txt.split())
                    if iy % nstep == 0 and ix % nstep == 0:
                        icoord = icoord + 1
                        x_current, y_current = geo2utm(x, y, unit)
                        jx = min(nx - 1, ix / nstep)
                        jy = min(ny - 1, iy / nstep)
                        coordx[jx, jy] = x_current
                        coordy[jx, jy] = y_current
                        elev[jx, jy] = z
            except:
                print 'error reading point ', iy * nx + ix, txt, \
                    grdfile.name, ' proc '
                raise NameError('error reading point')

    if (nx) * (ny) != icoord:
        if iproc == 0:
            print 'error in the surface file ' + grdfile.name
        if iproc == 0:
            print 'x points ' + str(nx) + ' y points ' + str(ny) + \
                ' tot points ' + str((nx) * (ny))
        if iproc == 0:
            print 'points read in ' + grdfile.name + ': ' + str(icoord)
        raise NameError

    grdfile.close()

    return coordx, coordy, elev
Esempio n. 3
0
def process_surfacefiles(iproc, nx, ny, nstep, grdfile, unit, lat_orientation):
    from utilities import geo2utm
    numpy = start.start_numpy()
    elev = numpy.zeros([nx, ny], float)
    coordx = numpy.zeros([nx, ny], float)
    coordy = numpy.zeros([nx, ny], float)
    icoord = 0

    lat_orientation = check_orientation(grdfile)

    try:
        grdfile = open(grdfile, 'r')
        # print 'reading ',grdfile
    except:
        txt = 'error reading: ' + str(grdfile)
        raise Exception(txt)

    if lat_orientation is 'SOUTH2NORTH':
        rangey = range(0, ny)
    else:
        rangey = range(ny - 1, -1, -1)
        lat_orientation = 'NORTH2SOUTH'
    print lat_orientation
    for iy in rangey:
        for ix in range(0, nx):
            txt = grdfile.readline()
            try:
                if len(txt) != 0:
                    x, y, z = map(float, txt.split())
                    if iy % nstep == 0 and ix % nstep == 0:
                        icoord = icoord + 1
                        x_current, y_current = geo2utm(x, y, unit)
                        jx = min(nx - 1, ix / nstep)
                        jy = min(ny - 1, iy / nstep)
                        coordx[jx, jy] = x_current
                        coordy[jx, jy] = y_current
                        elev[jx, jy] = z
            except:
                print 'error reading point ', iy * nx + ix, txt, \
                    grdfile.name, ' proc '
                raise NameError('error reading point')

    if (nx) * (ny) != icoord:
        if iproc == 0:
            print 'error in the surface file ' + grdfile.name
        if iproc == 0:
            print 'x points ' + str(nx) + ' y points ' + str(ny) + \
                ' tot points ' + str((nx) * (ny))
        if iproc == 0:
            print 'points read in ' + grdfile.name + ': ' + str(icoord)
        raise NameError

    grdfile.close()

    return coordx, coordy, elev
Esempio n. 4
0
 def create_line_v(ind,n,n2,step,data,unit):
     last_curve_store=cubit.get_last_id("curve")
     command='create curve spline '
     for i in range(0,n):
         if i%step == 0:
             lon,lat,z=data[n2*i+ind][0],data[n2*i+ind][1],data[n2*i+ind][2]
             x,y=geo2utm(lon,lat,unit)
             txt=' Position ' +   str(x)  +' '+  str(y) +' '+  str(z)
             command=command+txt
             #print command
     cubit.silent_cmd(command)
     last_curve=cubit.get_last_id("curve")
     if last_curve != last_curve_store:
         return last_curve
     else:
         return 0
Esempio n. 5
0
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)
Esempio n. 6
0
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
Esempio n. 7
0
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 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