예제 #1
0
    def elem_write(self, mesh_name):
        meshfile = open(mesh_name, 'w')
        print('Writing ' + mesh_name + '.....')
        nelem = cubit.get_tet_count()
        print('number of elements:', str(nelem))
        meshfile.write(str(nelem) + '\n')
        num_write = 0
        temp_tet = []
        tetlength = 1
        for block, flag in zip(self.block_mat, self.block_flag):
            tetlength += len(cubit.get_block_tets(block))
        tet_vp = range(tetlength)
        tet_vs = range(tetlength)
        tet_rho = range(tetlength)
        tet_qp = range(tetlength)
        tet_qs = range(tetlength)
        tet_block = range(tetlength)
        for block, flag in zip(self.block_mat, self.block_flag):
            tets = cubit.get_block_tets(block)
            for tet in tets:
                nodes = cubit.get_connectivity('Tet', tet)
                tet_vp[tet] = cubit.get_block_attribute_value(block, 1)
                tet_vs[tet] = cubit.get_block_attribute_value(block, 2)
                tet_rho[tet] = cubit.get_block_attribute_value(block, 3)
                tet_qp[tet] = cubit.get_block_attribute_value(block, 4)
                tet_qs[tet] = cubit.get_block_attribute_value(block, 5)
                tet_block[tet] = block
                temp_tet.append(tet)
#                txt=('%10i ')% tet
#                txt=txt+('%10i %10i %10i %10i\n')% nodes[:]
#                meshfile.write(txt)

        temp_tet.sort()
        for tet in temp_tet:
            nodes = cubit.get_connectivity('Tet', tet)
            txt = ('%10i ') % tet
            txt = txt + ('%10i %10i %10i %10i') % nodes[:]
            txt = txt + (' %9.1f %9.1f %9.1f %5i %5i\n') % (
                tet_vp[tet], tet_vs[tet], tet_rho[tet], tet_qp[tet],
                tet_qs[tet])
            meshfile.write(txt)

        meshfile.close()
        print('Ok')
예제 #2
0
def collect_old(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):
    #
    cubit.cmd('set journal error off')
    cubit.cmd('set verbose error off')
    collecting_merging(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy,cubfiles=cubfiles,ckbound_method1=ckbound_method1,ckbound_method2=ckbound_method2,merge_tolerance=merge_tolerance,decimate=decimate)
    cubit.cmd('set journal error on')
    cubit.cmd('set verbose error on')
    #
    if curverefining:
        block=1001 #topography
        refine_closecurve(block,curverefining,acis=True)
    #
    #
    if add_sea:
        block=1001
        add_sea_layer(block=block)

    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')
    #
    command = "save as '"+outdir2+outfilename+".cub' overwrite"
    cubit.cmd(command)
    #
    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)
예제 #3
0
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)
예제 #4
0
def collect(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):
    #
    cubit.cmd('set journal error off')
    cubit.cmd('set verbose error off')
    collecting_merging(cpuxmin,
                       cpuxmax,
                       cpuymin,
                       cpuymax,
                       cpux,
                       cpuy,
                       cubfiles=cubfiles,
                       ckbound_method1=ckbound_method1,
                       ckbound_method2=ckbound_method2,
                       merge_tolerance=merge_tolerance,
                       decimate=decimate)
    cubit.cmd('set journal error on')
    cubit.cmd('set verbose error on')
    #
    if curverefining:
        block = 1001  #topography
        refine_closecurve(block, curverefining, acis=True)
    #
    #
    if add_sea:
        block = 1001
        add_sea_layer(block=block)

    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')
    #
    command = "save as '" + outdir2 + outfilename + ".cub' overwrite"
    cubit.cmd(command)
    #
    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)
예제 #5
0
    def block_definition(self):
        block_flag=[]
        block_mat=[]
        block_bc=[]
        block_bc_flag=[]
        material={}
        bc={}
        blocks=cubit.get_block_id_list()
        for block in blocks:
            name=cubit.get_exodus_entity_name('block',block)
            ty=cubit.get_block_element_type(block)
            #print block,blocks,ty,self.hex,self.face
            if self.hex in ty:
                flag=None
                vel=None
                vs=None
                rho=None
                q=0
                ani=0
                # material domain id
                if "acoustic" in name :
                  imaterial = 1
                elif "elastic"  in name:
                  imaterial = 2
                elif "poroelastic"  in name:
                  imaterial = 3
                else :
                  imaterial = 0
                #
                nattrib=cubit.get_block_attribute_count(block)
                if nattrib > 1:
                    # material flag:
                    #   positive => material properties,
                    #   negative => interface/tomography domain
                    flag=int(cubit.get_block_attribute_value(block,0))
                    if flag > 0 and nattrib >= 2:
                        # material properties
                        # vp
                        vel=cubit.get_block_attribute_value(block,1)
                        if nattrib >= 3:
                            # vs
                            vs=cubit.get_block_attribute_value(block,2)
                            if nattrib >= 4:
                                # density
                                rho=cubit.get_block_attribute_value(block,3)
                                if nattrib >= 5:
                                  # next: Q_kappa or Q_mu (new/old format style)
                                  q=cubit.get_block_attribute_value(block,4)
                                  if nattrib == 6:
                                    # only 6 parameters given (skipping Q_kappa ), old format style
                                    qmu = q
                                    #Q_kappa is 10 times stronger than Q_mu
                                    qk = q * 10
                                    # last entry is anisotropic flag
                                    ani=cubit.get_block_attribute_value(block,5)
                                  elif nattrib > 6:
                                     #Q_kappa
                                     qk=q
                                     #Q_mu
                                     qmu=cubit.get_block_attribute_value(block,5)
                                     if nattrib == 7:
                                        #anisotropy_flag
                                        ani=cubit.get_block_attribute_value(block,6)
                                  # for q to be valid: it must be positive
                                  if qk < 0 or qmu < 0:
                                    print 'error, Q value invalid:',qk,qmu
                                    break
                    elif flag < 0:
                        # interface/tomography domain
                        # velocity model
                        vel=name
                        attrib=cubit.get_block_attribute_value(block,1)
                        if attrib == 1:
                            kind='interface'
                            flag_down=cubit.get_block_attribute_value(block,2)
                            flag_up=cubit.get_block_attribute_value(block,3)
                        elif attrib == 2:
                            kind='tomography'
                elif  nattrib == 1:
                    flag=cubit.get_block_attribute_value(block,0)
                    #print 'only 1 attribute ', name,block,flag
                    vel,vs,rho,qk,qmu,ani=(0,0,0,9999.,9999.,0)
                else:
                    flag=block
                    vel,vs,rho,qk,qmu,ani=(name,0,0,9999.,9999.,0)
                block_flag.append(int(flag))
                block_mat.append(block)
                if (flag > 0) and nattrib != 1:
                    par=tuple([imaterial,flag,vel,vs,rho,qk,qmu,ani])
                elif flag < 0 and nattrib != 1:
                    if kind=='interface':
                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
                    elif kind=='tomography':
                        par=tuple([imaterial,flag,kind,name])
                elif flag==0 or nattrib == 1:
                    par=tuple([imaterial,flag,name])
                material[block]=par
            elif ty == self.face:
                block_bc_flag.append(4)
                block_bc.append(block)
                bc[block]=4 #face has connectivity = 4
                if name == self.topo or block == 1001:
                    self.topography=block
                if self.freetxt in name:
                    self.free=block
            elif ty == 'SPHERE':
                pass
            else:
                # block elements differ from HEX8/QUAD4/SHELL4
                print '****************************************'
                print 'block not properly defined:'
                print '  name:',name
                print '  type:',type
                print
                print 'please check your block definitions!'
                print
                print 'only supported types are:'
                print '  HEX/HEX8  for volumes'
                print '  QUAD4 for surface'
                print '  SHELL4 for surface'
                print '****************************************'
                continue
                return None, None,None,None,None,None,None,None
        nsets=cubit.get_nodeset_id_list()
        if len(nsets) == 0: self.receivers=None
        for nset in nsets:
            name=cubit.get_exodus_entity_name('nodeset',nset)
            if name == self.rec:
                self.receivers=nset
            else:
                print 'nodeset '+name+' not defined'
                self.receivers=None

        try:
            self.block_mat=block_mat
            self.block_flag=block_flag
            self.block_bc=block_bc
            self.block_bc_flag=block_bc_flag
            self.material=material
            self.bc=bc
            print 'HEX Blocks:'
            for m,f in zip(self.block_mat,self.block_flag):
                print 'block ',m,'material flag ',f
            print 'Absorbing Boundary Conditions:'
            for m,f in zip(self.block_bc,self.block_bc_flag):
                print  'bc ',m,'bc flag ',f
            print 'Topography (free surface)'
            print self.topography
            print 'Free surface'
            print self.free
        except:
            print '****************************************'
            print 'sorry, no blocks or blocks not properly defined'
            print block_mat
            print block_flag
            print block_bc
            print block_bc_flag
            print material
            print bc
            print '****************************************'
예제 #6
0
def savemesh(mpiflag, iproc=0, filename=None):
    import start as start
    cfg = start.start_cfg(filename=filename)
    mpiflag, iproc, numproc, mpi = start.start_mpi()

    def runsave(meshfile, iproc, filename=None):
        import start as start
        cubit = start.start_cubit()
        cfg = start.start_cfg(filename=filename)
        flag = 0
        ner = cubit.get_error_count()
        cubitcommand = 'save as "' + cfg.output_dir + \
            '/' + meshfile + '.cub' + '" overwrite'
        cubit.cmd(cubitcommand)
        ner2 = cubit.get_error_count()
        if ner == ner2:
            cubitcommand = 'export mesh "' + cfg.output_dir + '/' + \
                meshfile + '.e' + '" dimension 3 block all overwrite'
            cubit.cmd(cubitcommand)
            ner2 = cubit.get_error_count()
        if ner == ner2:
            flag = 1
        return flag

    meshfile = 'mesh_vol_' + str(iproc)

    flagsaved = 0
    infosave = (iproc, flagsaved)

    mpi.barrier()
    total_saved = mpi.allgather(flagsaved)
    if isinstance(total_saved, int):
        total_saved = [total_saved]

    ind = 0
    saving = True
    while saving:
        if len(total_saved) != sum(total_saved):
            #
            if not flagsaved:
                flagsaved = runsave(meshfile, iproc, filename=filename)
                if flagsaved:
                    infosave = (iproc, flagsaved)
                    if numproc > 1:
                        f = open('mesh_saved' + str(iproc), 'w')
                        f.close()
            mpi.barrier()
            total_saved = mpi.allgather(flagsaved)
            if isinstance(total_saved, int):
                total_saved = [total_saved]
            ind = ind + 1
        else:
            saving = False
        if ind > len(total_saved) + 10:
            saving = False
        print sum(total_saved), '/', len(total_saved), ' saved'

    info_total_saved = mpi.allgather(infosave)
    if isinstance(info_total_saved, int):
        info_total_saved = [info_total_saved]

    if iproc == 0:
        f = open('mesh_saving.log', 'w')
        f.write('\n'.join(str(x) for x in info_total_saved))
        f.close()

    f = open(cfg.output_dir + '/' + 'blocks_' + str(iproc).zfill(5), '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()

    import quality_log
    f = open(cfg.output_dir + '/' + 'quality_' + str(iproc).zfill(5), 'w')
    max_skewness, min_length = quality_log.quality_log(f)
    f.close()

    count_hex = [cubit.get_hex_count()]
    count_node = [cubit.get_node_count()]
    max_skew = [(iproc, max_skewness)]
    min_l = [(iproc, min_length)]

    mpi.barrier()
    total_min_l = mpi.gather(min_l)
    total_hex = mpi.gather(count_hex)
    total_node = mpi.gather(count_node)
    total_max_skew = mpi.gather(max_skew)

    mpi.barrier()
    if iproc == 0:
        min_total_min_l = min([ms[1] for ms in total_min_l])
        max_total_max_skew = max([ms[1] for ms in total_max_skew])
        sum_total_node = sum(total_node)
        sum_total_hex = sum(total_hex)

        totstat_file = open(cfg.output_dir + '/totstat.log', 'w')
        text = 'hex total number,node total number,max skew, min length\n'
        totstat_file.write(text)

        text = str(sum_total_hex) + ' , ' + str(sum_total_node) + ' , ' + \
            str(max_total_max_skew) + ' , ' + str(min_total_min_l) + '\n'
        totstat_file.write(text)

        totstat_file.write(str(total_max_skew))
        totstat_file.close()

    print 'meshing process end... proc ', iproc
예제 #7
0
 def block_definition(self):
     """ Import blocks features from Cubit """ 
     block_flag = [] # Will contain material id (1 if fluid 2 if solid)
     block_mat = [] # Will contain face block ids
     block_bc = [] # Will contain edge block ids
     block_bc_flag = [] # Will contain edge id -> 2
     abs_boun = [-1] * self.nabs # total 4 sides of absorbing boundaries (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
     #pml_boun = [-1] * 6 # To store pml layers id (for each pml layer : x_acoust, z_acoust, xz_acoust, x_elast, z_elast, xz_elast)
     pml_boun = [[] for _ in range(6)] # To store the block id corresponding to pml layers id (arbitrary number of blocks for each pml layer : x_acoust, z_acoust, xz_acoust, x_elast, z_elast, xz_elast)
     material = {} # Will contain each material name and their properties
     bc = {} # Will contains each boundary name and their connectivity -> 2
     blocks = cubit.get_block_id_list() # Load the blocks list
     for block in blocks: # Loop on the blocks
         name = cubit.get_exodus_entity_name('block',block) # Contains the name of the blocks
         ty = cubit.get_block_element_type(block) # Contains the block element type (QUAD4...)
         if ty == self.face: # If we are dealing with a block containing faces
             nAttributes = cubit.get_block_attribute_count(block)
             if (nAttributes != 1 and nAttributes != 6):
                 print 'Blocks not properly defined, 2d blocks must have one attribute (material id) or 6 attributes'
                 return None,None,None,None,None,None,None,None
             flag=int(cubit.get_block_attribute_value(block,0)) # Fetch the first attribute value (containing material id)
             print "nAttributes : ",nAttributes
             if nAttributes == 6:
                 self.write_nummaterial_velocity_file = True
                 velP = cubit.get_block_attribute_value(block,1)  # Fetch the first attribute value (containing P wave velocity)
                 velS = cubit.get_block_attribute_value(block,2)  # Fetch the second attribute value (containing S wave velocity)
                 rho = cubit.get_block_attribute_value(block,3)  # Fetch the third attribute value (containing material density)
                 qFlag = cubit.get_block_attribute_value(block,4)  # Fetch the first attribute value (containing Qflag)
                 anisotropy_flag = cubit.get_block_attribute_value(block,5)  # Fetch the first attribute value (containing anisotropy_flag) 
                 # Store (material_id,rho,velP,velS,Qflag,anisotropy_flag) in par :
                 par = tuple([flag,rho,velP,velS,qFlag,anisotropy_flag])
                 material[name] = par # associate the name of the block to its id and properties
             block_flag.append(int(flag)) # Append material id to block_flag
             block_mat.append(block)  # Append block id to block_mat
             if name in self.pml_boun_name : # If the block considered refered to one of the pml layer
                 self.abs_mesh=True
                 self.pml_layers=True
                 pml_boun[self.pml_boun_name.index(name)]=block 
                 # -> Put it at the correct position in pml_boun 
                 # (index 0 : pml_x_acoust, index 1 : pml_z_acoust, index 2 : pml_xz_acoust, 
                 #  index 3 : pml_x_elast, index 4 : pml_z_elast, index 5 : pml_xz_elast)
         elif ty == self.edge: # If we are dealing with a block containing edges
             block_bc_flag.append(2) # Append "2" to block_bc_flag
             block_bc.append(block) # Append block id to block_bc
             bc[name] = 2 # Associate the name of the block with its connectivity : an edge has connectivity = 2
             if name == self.topo: 
                 self.topo_mesh=True
                 topography=block # If the block considered refered to topography store its id in "topography"
             if name == self.axisname:
                 self.axisymmetric_mesh = True
                 axisId = block # AXISYM If the block considered refered to the axis store its id in "axisId"
             if name in self.abs_boun_name : # If the block considered refered to one of the boundaries
                 self.abs_mesh = True
                 abs_boun[self.abs_boun_name.index(name)] = block 
                 # -> Put it at the correct position in abs_boun (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
         else:
             print 'Blocks not properly defined', ty
             return None,None,None,None,None,None,None,None
     nsets = cubit.get_nodeset_id_list() # Get the list of all nodeset
     if len(nsets) == 0: self.receivers = None # If this list is empty : put None in self.receivers
     for nset in nsets:
         name = cubit.get_exodus_entity_name('nodeset',nset) # Contains the name of the nodeset
         if name == self.rec: # If the name considered match self.rec (receivers)
             self.receivers = nset # Store the id of the nodeset in self.receivers
         else:
             print 'nodeset '+name+' not defined'
             self.receivers = None
     # Store everything in the object :
     try:
         self.block_mat = block_mat
         self.block_flag = block_flag
         self.block_bc = block_bc
         self.block_bc_flag = block_bc_flag
         self.bc = bc
         if self.write_nummaterial_velocity_file:
             self.material = material
         if self.abs_mesh:
             self.abs_boun = abs_boun
         if self.topo_mesh:
             self.topography = topography
         if self.axisymmetric_mesh:
             self.axisId = axisId
         if self.pml_layers:
             self.pml_boun = pml_boun
     except: 
         print 'Blocks not properly defined'
예제 #8
0
    def block_definition(self):
        block_flag = []
        block_mat = []
        block_bc = []
        block_bc_flag = []
        material = {}
        bc = {}
        blocks = cubit.get_block_id_list()
        for block in blocks:
            name = cubit.get_exodus_entity_name("block", block)
            type = cubit.get_block_element_type(block)
            print block, name, blocks, type, self.hex, self.face
            # block has hexahedral elements (HEX8)
            if type == self.hex:
                flag = None
                vel = None
                vs = None
                rho = None
                q = 0
                ani = 0
                # material domain id
                if name.find("acoustic") >= 0:
                    imaterial = 1
                elif name.find("elastic") >= 0:
                    imaterial = 2
                elif name.find("poroelastic") >= 0:
                    imaterial = 3
                else:
                    imaterial = 0
                    print "block: ", name
                    print "  could not find appropriate material for this block..."
                    print ""
                    break

                nattrib = cubit.get_block_attribute_count(block)
                if nattrib != 0:
                    # material flag:
                    #   positive => material properties,
                    #   negative => interface/tomography domain
                    flag = int(cubit.get_block_attribute_value(block, 0))
                    if flag > 0 and nattrib >= 2:
                        # vp
                        vel = cubit.get_block_attribute_value(block, 1)
                        if nattrib >= 3:
                            # vs
                            vs = cubit.get_block_attribute_value(block, 2)
                            if nattrib >= 4:
                                # density
                                rho = cubit.get_block_attribute_value(block, 3)
                                if nattrib >= 5:
                                    # Q_mu
                                    q = cubit.get_block_attribute_value(block, 4)
                                    # for q to be valid: it must be positive
                                    if q < 0:
                                        print "error, q value invalid:", q
                                        break
                                    if nattrib == 6:
                                        # only 6 parameters given (skipping Q_kappa ), old format style
                                        # Q_kappa is 10 times stronger than Q_mu
                                        q2 = q * 10
                                        # last entry is anisotropic flag
                                        ani = cubit.get_block_attribute_value(block, 5)
                                    elif nattrib > 6:
                                        # Q_kappa
                                        q2 = cubit.get_block_attribute_value(block, 5)
                                        # for q to be valid: it must be positive
                                        if q2 < 0:
                                            print "error, q value invalid:", q2
                                            break
                                        if nattrib == 7:
                                            # anisotropy_flag
                                            ani = cubit.get_block_attribute_value(block, 6)
                    elif flag < 0:
                        # velocity model
                        vel = name
                        attrib = cubit.get_block_attribute_value(block, 1)
                        if attrib == 1:
                            kind = "interface"
                            flag_down = cubit.get_block_attribute_value(block, 2)
                            flag_up = cubit.get_block_attribute_value(block, 3)
                        elif attrib == 2:
                            kind = "tomography"
                else:
                    flag = block
                    vel, vs, rho, q, q2, ani = (name, 0, 0, 0, 0, 0)
                block_flag.append(int(flag))
                block_mat.append(block)
                if flag > 0:
                    par = tuple([imaterial, flag, vel, vs, rho, q, q2, ani])
                elif flag < 0:
                    if kind == "interface":
                        par = tuple([imaterial, flag, kind, name, flag_down, flag_up])
                    elif kind == "tomography":
                        par = tuple([imaterial, flag, kind, name])
                elif flag == 0:
                    par = tuple([imaterial, flag, name])
                material[block] = par
            elif (type == self.face) or (type == self.face2):
                # block has surface elements (QUAD4 or SHELL4)
                block_bc_flag.append(4)
                block_bc.append(block)
                bc[block] = 4  # face has connectivity = 4
                if name == self.topo:
                    topography_face = block
            else:
                # block elements differ from HEX8/QUAD4/SHELL4
                print "****************************************"
                print "block not properly defined:"
                print "  name:", name
                print "  type:", type
                print
                print "please check your block definitions!"
                print
                print "only supported types are:"
                print "  HEX8  for volumes"
                print "  QUAD4 for surface"
                print "  SHELL4 for surface"
                print "****************************************"
                continue

        nsets = cubit.get_nodeset_id_list()
        if len(nsets) == 0:
            self.receivers = None
        for nset in nsets:
            name = cubit.get_exodus_entity_name("nodeset", nset)
            if name == self.rec:
                self.receivers = nset
            else:
                print "nodeset " + name + " not defined"
                self.receivers = None
        try:
            self.block_mat = block_mat
            self.block_flag = block_flag
            self.block_bc = block_bc
            self.block_bc_flag = block_bc_flag
            self.material = material
            self.bc = bc
            self.topography = topography_face
        except:
            print "****************************************"
            print "sorry, no blocks or blocks not properly defined"
            print block_mat
            print block_flag
            print block_bc
            print block_bc_flag
            print material
            print bc
            print topography
            print "****************************************"
    def block_definition(self):
        block_flag = []
        block_mat = []
        block_bc = []
        block_bc_flag = []
        material = {}
        bc = {}
        blocks = cubit.get_block_id_list()
        for block in blocks:
            name = cubit.get_exodus_entity_name('block', block)
            type = cubit.get_block_element_type(block)
            print block, name, blocks, type, self.hex, self.face
            # block has hexahedral elements (HEX8)
            if type == self.hex:
                flag = None
                vel = None
                vs = None
                rho = None
                q = 0
                ani = 0
                # material domain id
                if name.find("acoustic") >= 0:
                    imaterial = 1
                elif name.find("elastic") >= 0:
                    imaterial = 2
                elif name.find("poroelastic") >= 0:
                    imaterial = 3
                else:
                    imaterial = 0
                    print "block: ", name
                    print "  could not find appropriate material for this block..."
                    print ""
                    break

                nattrib = cubit.get_block_attribute_count(block)
                if nattrib != 0:
                    # material flag:
                    #   positive => material properties,
                    #   negative => interface/tomography domain
                    flag = int(cubit.get_block_attribute_value(block, 0))
                    if flag > 0 and nattrib >= 2:
                        # vp
                        vel = cubit.get_block_attribute_value(block, 1)
                        if nattrib >= 3:
                            # vs
                            vs = cubit.get_block_attribute_value(block, 2)
                            if nattrib >= 4:
                                #density
                                rho = cubit.get_block_attribute_value(block, 3)
                                if nattrib >= 5:
                                    #Q_kappa
                                    qkappa = cubit.get_block_attribute_value(
                                        block, 4)
                                    # for q to be valid: it must be positive
                                    if qkappa < 0:
                                        print 'error, qkappa value invalid:', qkappa
                                        break
                                    if nattrib >= 6:
                                        #Q_mu
                                        qmu = cubit.get_block_attribute_value(
                                            block, 5)
                                        # for q to be valid: it must be positive
                                        if qmu < 0:
                                            print 'error, qmu value invalid:', qmu
                                            break
                                        if nattrib == 7:
                                            #anisotropy_flag
                                            ani = cubit.get_block_attribute_value(
                                                block, 5)
                    elif flag < 0:
                        # velocity model
                        vel = name
                        attrib = cubit.get_block_attribute_value(block, 1)
                        if attrib == 1:
                            kind = 'interface'
                            flag_down = cubit.get_block_attribute_value(
                                block, 2)
                            flag_up = cubit.get_block_attribute_value(block, 3)
                        elif attrib == 2:
                            kind = 'tomography'
                else:
                    flag = block
                    vel, vs, rho, qkappa, qmu, ani = (name, 0, 0, 0, 0, 0)
                block_flag.append(int(flag))
                block_mat.append(block)
                if flag > 0:
                    par = tuple(
                        [imaterial, flag, vel, vs, rho, qkappa, qmu, ani])
                elif flag < 0:
                    if kind == 'interface':
                        par = tuple(
                            [imaterial, flag, kind, name, flag_down, flag_up])
                    elif kind == 'tomography':
                        par = tuple([imaterial, flag, kind, name])
                elif flag == 0:
                    par = tuple([imaterial, flag, name])
                material[block] = par
            elif (type == self.face) or (type == self.face2):
                # block has surface elements (QUAD4 or SHELL4)
                block_bc_flag.append(4)
                block_bc.append(block)
                bc[block] = 4  #face has connectivity = 4
                if name == self.topo: topography_face = block
            else:
                # block elements differ from HEX8/QUAD4/SHELL4
                print '****************************************'
                print 'block not properly defined:'
                print '  name:', name
                print '  type:', type
                print
                print 'please check your block definitions!'
                print
                print 'only supported types are:'
                print '  HEX8  for volumes'
                print '  QUAD4 for surface'
                print '  SHELL4 for surface'
                print '****************************************'
                continue

        nsets = cubit.get_nodeset_id_list()
        if len(nsets) == 0: self.receivers = None
        for nset in nsets:
            name = cubit.get_exodus_entity_name('nodeset', nset)
            if name == self.rec:
                self.receivers = nset
            else:
                print 'nodeset ' + name + ' not defined'
                self.receivers = None
        try:
            self.block_mat = block_mat
            self.block_flag = block_flag
            self.block_bc = block_bc
            self.block_bc_flag = block_bc_flag
            self.material = material
            self.bc = bc
            self.topography = topography_face
        except:
            print '****************************************'
            print 'sorry, no blocks or blocks not properly defined'
            print block_mat
            print block_flag
            print block_bc
            print block_bc_flag
            print material
            print bc
            print topography
            print '****************************************'
    def getstats(self):
        ''' Get statistics for differend blocks in the hexmesh '''
    ############################## READ BLOCKS ######################
        try:
            blocks=cubit.get_block_id_list()
        except:
            print('no blocks defined')

        nblocks=len(blocks)
        print('Found ',nblocks,' Blocks')
        # lists of details of all elastic blocks. For each elastic block, append respective values
        name=[]
        typ=[]
        nattrib=[]
        vp=[]
        vs=[]
        rho=[]
        minEdge=[]
        maxEdge=[]
        minEdgeMesh = []
        maxEdgeMesh = []
        # k: counter of all elastic blocks
        k=0
        for block in blocks:
            minEdgeMeshTmp = []
            maxEdgeMeshTmp = []
            blockname=cubit.get_exodus_entity_name('block',block)
            # only apply stats to elastic blocks
            if blockname.find("elastic") >= 0:
                # NOW APPEND VALUES OF THIS ELASTIC BLOCK TO LISTS (defined as empty above)
                name.append(blockname)
                typ.append(cubit.get_block_element_type(block))
                # attribute count
                nattrib.append(cubit.get_block_attribute_count(block))
                # vp
                vp.append(cubit.get_block_attribute_value(block,1))
                # vs
                vs.append(cubit.get_block_attribute_value(block,2))
                # rho
                rho.append(cubit.get_block_attribute_value(block,3))
                hexes=cubit.get_block_hexes(block)
                print(block, k,'name: ',name[k],'#hexes:',len(hexes),'type: ',typ[k],'attribute count: ',nattrib[k],'vp: ',vp[k],'vs: ',vs[k],'rho: ',rho[k])
                
                # minimum/maximum edgelength search for this elastic block
                # initiate  with very large minEdge and very small maxEdge
                minEdge.append(1e9)
                maxEdge.append(1e-9)
                # now search
                for hexa in hexes:
                    nodes=cubit.get_connectivity('Hex',hexa)
                    # get coordinates of nodes of this hexahedron
                    node_coords=[]
                    for node in nodes:
                        node_coords.append(cubit.get_nodal_coordinates(node))

                    minv=self.minEdgeHex(node_coords)
                    minEdgeMeshTmp.append(minv)
                    maxv=self.maxEdgeHex(node_coords)
                    maxEdgeMeshTmp.append(maxv)

                    # is minimum edgelength of this this element smaller than minimum edgelength found before?
                    if minv < minEdge[k]:
                        minEdge[k]=minv

                    # is maximum edgelength of this this element larger than maximum edgelength found before?
                    if maxv > maxEdge[k]:
                        maxEdge[k]=maxv

                minEdgeMesh.append(minEdgeMeshTmp)
                maxEdgeMesh.append(maxEdgeMeshTmp)
                # end of processing of this elastic block. incremet counter
                k=k+1
            # if not "elastic" in this blockname
            else:
                print(blockname, '--no elastic')

        # now calculate maximum frequency for which the mesh is stable
        # and maximal dt

        # first do that for each block
        fmax=[]
        dtmax_05=[]
        for i in range(len(name)):
            fmax.append(self.calcMaxFreq(maxEdge[i],vs[i]))
            dtmax_05.append(self.calcMaxDt(minEdge[i],vp[i],cn=0.5))
            min_dx = minEdge[i]*0.1727
            max_dx = maxEdge[i]*0.3272*sqrt(3.)
            print('Block ', name[i], ' min dx: ',min_dx, ' max dx: ',max_dx, 'max frequency: ',fmax[i],
                  ' maximal dt (C=0.5):',dtmax_05[i])
            vals,bin_edges = histogram(minEdgeMesh[i],10)
            nhexa = sum(vals)
            print('   '+str(nhexa)+' HEXAS IN THIS BLOCK')
            print('   histogram of minimum edge length of hexa of this block:')
            for j,val in enumerate(vals):
                print('       %6.3f %% of hexas have minimum edgelength between %3.3f and %3.3f  ->   dt (C=0.5) is %8.3e'%(100.*val/float(nhexa),bin_edges[j],bin_edges[j+1],self.calcMaxDt(bin_edges[j],vp[i],cn=0.5)))
            vals,bin_edges = histogram(maxEdgeMesh[i],10)
            nhexa = sum(vals)
            print('   '+str(nhexa)+' HEXAS IN THIS BLOCK')
            print('   histogram of maximum edge length of hexa of this block:')
            for j,val in enumerate(vals):
                print('       %6.3f %% of hexas have maximum edgelength between %3.3f and %3.3f  ->   fmax (5 GLL points per wavelength) is %8.3e'%(100.*val/float(nhexa),bin_edges[j],bin_edges[j+1],self.calcMaxFreq(bin_edges[j+1],vs[i])))
        # now compare the values for all the blocks
        dtm_05=sorted(dtmax_05)
        print('The minimum over all blocks of the respective maximal dt for C=0.5 is: ',dtm_05[0])
        fmax_min=sorted(fmax)
        print('The minimum over all blocks of the respective maximal frequency is: ',fmax_min[0])
예제 #11
0
def savemesh(mpiflag, iproc=0, filename=None):
    import start as start
    cfg = start.start_cfg(filename=filename)
    mpiflag, iproc, numproc, mpi = start.start_mpi()

    def runsave(meshfile, iproc, filename=None):
        import start as start
        cubit = start.start_cubit()
        cfg = start.start_cfg(filename=filename)
        flag = 0
        ner = cubit.get_error_count()
        cubitcommand = 'save as "' + cfg.output_dir + '/' + meshfile + '.cub' + '" overwrite'
        cubit.cmd(cubitcommand)
        ner2 = cubit.get_error_count()
        if ner == ner2:
            cubitcommand = 'export mesh "' + cfg.output_dir + '/' + meshfile + '.e' + '" dimension 3 block all overwrite'
            cubit.cmd(cubitcommand)
            ner2 = cubit.get_error_count()
        if ner == ner2:
            flag = 1
        return flag

    meshfile = 'mesh_vol_' + str(iproc)

    flagsaved = 0
    infosave = (iproc, flagsaved)

    mpi.barrier()
    total_saved = mpi.allgather(flagsaved)
    if isinstance(total_saved, int): total_saved = [total_saved]

    ind = 0
    saving = True
    while saving:
        if len(total_saved) != sum(total_saved):
            #
            if not flagsaved:
                flagsaved = runsave(meshfile, iproc, filename=filename)
                if flagsaved:
                    infosave = (iproc, flagsaved)
                    if numproc > 1:
                        f = open('mesh_saved' + str(iproc), 'w')
                        f.close()
            mpi.barrier()
            total_saved = mpi.allgather(flagsaved)
            if isinstance(total_saved, int): total_saved = [total_saved]
            ind = ind + 1
        else:
            saving = False
        if ind > len(total_saved) + 10: saving = False
        print sum(total_saved), '/', len(total_saved), ' saved'

    info_total_saved = mpi.allgather(infosave)
    if isinstance(info_total_saved, int): info_total_saved = [info_total_saved]

    if iproc == 0:
        f = open('mesh_saving.log', 'w')
        f.write('\n'.join(str(x) for x in info_total_saved))
        f.close()

    f = open(cfg.output_dir + '/' + 'blocks_' + str(iproc).zfill(5), '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()

    import quality_log
    f = open(cfg.output_dir + '/' + 'quality_' + str(iproc).zfill(5), 'w')
    max_skewness, min_length = quality_log.quality_log(f)
    f.close()

    count_hex = [cubit.get_hex_count()]
    count_node = [cubit.get_node_count()]
    max_skew = [(iproc, max_skewness)]
    min_l = [(iproc, min_length)]

    mpi.barrier()
    total_min_l = mpi.gather(min_l)
    total_hex = mpi.gather(count_hex)
    total_node = mpi.gather(count_node)
    total_max_skew = mpi.gather(max_skew)

    mpi.barrier()
    if iproc == 0:
        min_total_min_l = min([ms[1] for ms in total_min_l])
        max_total_max_skew = max([ms[1] for ms in total_max_skew])
        sum_total_node = sum(total_node)
        sum_total_hex = sum(total_hex)

        totstat_file = open(cfg.output_dir + '/totstat.log', 'w')
        text = 'hex total number,node total number,max skew, min length\n'
        totstat_file.write(text)

        text = str(sum_total_hex) + ' , ' + str(sum_total_node) + ' , ' + str(
            max_total_max_skew) + ' , ' + str(min_total_min_l) + '\n'
        totstat_file.write(text)

        totstat_file.write(str(total_max_skew))
        totstat_file.close()

    print 'meshing process end... proc ', iproc
    def block_definition(self):
        block_flag=[]
        block_mat=[]
        block_bc=[]
        block_bc_flag=[]
        material={}
        bc={}
        blocks=cubit.get_block_id_list()
        for block in blocks:
            name=cubit.get_exodus_entity_name('block',block)
            type=cubit.get_block_element_type(block)
            print block,name,blocks,type,self.hex,self.face
            # block has hexahedral elements (HEX8)
            if type == self.hex:
                flag=None
                vel=None
                vs=None
                rho=None
                q=0
                ani=0
                # material domain id
                if name.find("acoustic") >= 0 :
                  imaterial = 1
                elif name.find("elastic") >= 0 :
                  imaterial = 2
                elif name.find("poroelastic") >= 0 :
                  imaterial = 3
                else :
                  imaterial = 0
                  print "block: ",name
                  print "  could not find appropriate material for this block..."
                  print ""
                  break

                nattrib=cubit.get_block_attribute_count(block)
                if nattrib != 0:
                    # material flag:
                    #   positive => material properties,
                    #   negative => interface/tomography domain
                    flag=int(cubit.get_block_attribute_value(block,0))
                    if flag > 0 and nattrib >= 2:
                      # vp
                      vel=cubit.get_block_attribute_value(block,1)
                      if nattrib >= 3:
                        # vs
                        vs=cubit.get_block_attribute_value(block,2)
                        if nattrib >= 4:
                          #density
                          rho=cubit.get_block_attribute_value(block,3)
                          if nattrib >= 5:
                            #Q_mu
                            q=cubit.get_block_attribute_value(block,4)
                            # for q to be valid: it must be positive
                            if q < 0 :
                              print 'error, q value invalid:', q
                              break
                            if nattrib == 6:
                              #anisotropy_flag
                              ani=cubit.get_block_attribute_value(block,5)
                    elif flag < 0:
                        # velocity model
                        vel=name
                        attrib=cubit.get_block_attribute_value(block,1)
                        if attrib == 1:
                            kind='interface'
                            flag_down=cubit.get_block_attribute_value(block,2)
                            flag_up=cubit.get_block_attribute_value(block,3)
                        elif attrib == 2:
                            kind='tomography'
                else:
                    flag=block
                    vel,vs,rho,q,ani=(name,0,0,0,0)
                block_flag.append(int(flag))
                block_mat.append(block)
                if flag > 0:
                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
                elif flag < 0:
                    if kind=='interface':
                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
                    elif kind=='tomography':
                        par=tuple([imaterial,flag,kind,name])
                elif flag==0:
                    par=tuple([imaterial,flag,name])
                material[block]=par
            elif (type == self.face) or (type == self.face2) :
                # block has surface elements (QUAD4 or SHELL4)
                block_bc_flag.append(4)
                block_bc.append(block)
                bc[block]=4 #face has connectivity = 4
                if name == self.topo: topography_face=block
            else:
                # block elements differ from HEX8/QUAD4/SHELL4
                print '****************************************'
                print 'block not properly defined:'
                print '  name:',name
                print '  type:',type
                print
                print 'please check your block definitions!'
                print
                print 'only supported types are:'
                print '  HEX8  for volumes'
                print '  QUAD4 for surface'
                print '  SHELL4 for surface'
                print '****************************************'
                continue

        nsets=cubit.get_nodeset_id_list()
        if len(nsets) == 0: self.receivers=None
        for nset in nsets:
            name=cubit.get_exodus_entity_name('nodeset',nset)
            if name == self.rec:
                self.receivers=nset
            else:
                print 'nodeset '+name+' not defined'
                self.receivers=None
        try:
            self.block_mat=block_mat
            self.block_flag=block_flag
            self.block_bc=block_bc
            self.block_bc_flag=block_bc_flag
            self.material=material
            self.bc=bc
            self.topography=topography_face
        except:
            print '****************************************'
            print 'sorry, no blocks or blocks not properly defined'
            print block_mat
            print block_flag
            print block_bc
            print block_bc_flag
            print material
            print bc
            print topography
            print '****************************************'
예제 #13
0
    def block_definition(self):
        block_flag=[]
        block_mat=[]
        block_bc=[]
        block_bc_flag=[]
        material={}
        bc={}
        blocks=cubit.get_block_id_list()
        for block in blocks:
            name=cubit.get_exodus_entity_name('block',block)
            ty=cubit.get_block_element_type(block)
            #print block,blocks,ty,self.hex,self.face
            if self.hex in ty:
                flag=None
                vel=None
                vs=None
                rho=None
                q=0
                ani=0
                # material domain id
                if "acoustic" in name :
                  imaterial = 1
                elif "elastic"  in name:
                  imaterial = 2
                elif "poroelastic"  in name:
                  imaterial = 3
                else :
                  imaterial = 0
                #
                nattrib=cubit.get_block_attribute_count(block)
                if nattrib > 1:
                    # material flag:
                    #   positive => material properties,
                    #   negative => interface/tomography domain
                    flag=int(cubit.get_block_attribute_value(block,0))
                    if flag > 0 and nattrib >= 2:
                        # material properties
                        # vp
                        vel=cubit.get_block_attribute_value(block,1)
                        if nattrib >= 3:
                            # vs
                            vs=cubit.get_block_attribute_value(block,2)
                            if nattrib >= 4:
                                # density
                                rho=cubit.get_block_attribute_value(block,3)
                                if nattrib >= 5:
                                  # next: Q_kappa or Q_mu (new/old format style)
                                  q=cubit.get_block_attribute_value(block,4)
                                  if nattrib == 6:
                                    # only 6 parameters given (skipping Q_kappa ), old format style
                                    qmu = q
                                    #Q_kappa is 10 times stronger than Q_mu
                                    qk = q * 10
                                    # last entry is anisotropic flag
                                    ani=cubit.get_block_attribute_value(block,5)
                                  elif nattrib > 6:
                                     #Q_kappa
                                     qk=q
                                     #Q_mu
                                     qmu=cubit.get_block_attribute_value(block,5)
                                     if nattrib == 7:
                                        #anisotropy_flag
                                        ani=cubit.get_block_attribute_value(block,6)
                                  # for q to be valid: it must be positive
                                  if qk < 0 or qmu < 0:
                                    print 'error, Q value invalid:',qk,qmu
                                    break
                    elif flag < 0:
                        # interface/tomography domain
                        # velocity model
                        vel=name
                        attrib=cubit.get_block_attribute_value(block,1)
                        if attrib == 1:
                            kind='interface'
                            flag_down=cubit.get_block_attribute_value(block,2)
                            flag_up=cubit.get_block_attribute_value(block,3)
                        elif attrib == 2:
                            kind='tomography'
                elif  nattrib == 1:
                    flag=cubit.get_block_attribute_value(block,0)
                    #print 'only 1 attribute ', name,block,flag
                    vel,vs,rho,qk,qmu,ani=(0,0,0,9999.,9999.,0)
                else:
                    flag=block
                    vel,vs,rho,qk,qmu,ani=(name,0,0,9999.,9999.,0)
                block_flag.append(int(flag))
                block_mat.append(block)
                if (flag > 0) and nattrib != 1:
                    par=tuple([imaterial,flag,vel,vs,rho,qk,qmu,ani])
                elif flag < 0 and nattrib != 1:
                    if kind=='interface':
                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
                    elif kind=='tomography':
                        par=tuple([imaterial,flag,kind,name])
                elif flag==0 or nattrib == 1:
                    par=tuple([imaterial,flag,name])
                material[block]=par
            elif ty == self.face:
                block_bc_flag.append(4)
                block_bc.append(block)
                bc[block]=4 #face has connectivity = 4
                if name == self.topo or block == 1001:
                    self.topography=block
                if self.freetxt in name:
                    self.free=block
            elif ty == 'SPHERE':
                pass
            else:
                # block elements differ from HEX8/QUAD4/SHELL4
                print '****************************************'
                print 'block not properly defined:'
                print '  name:',name
                print '  type:',type
                print
                print 'please check your block definitions!'
                print
                print 'only supported types are:'
                print '  HEX/HEX8  for volumes'
                print '  QUAD4 for surface'
                print '  SHELL4 for surface'
                print '****************************************'
                continue
                return None, None,None,None,None,None,None,None
        nsets=cubit.get_nodeset_id_list()
        if len(nsets) == 0: self.receivers=None
        for nset in nsets:
            name=cubit.get_exodus_entity_name('nodeset',nset)
            if name == self.rec:
                self.receivers=nset
            else:
                print 'nodeset '+name+' not defined'
                self.receivers=None

        try:
            self.block_mat=block_mat
            self.block_flag=block_flag
            self.block_bc=block_bc
            self.block_bc_flag=block_bc_flag
            self.material=material
            self.bc=bc
            print 'HEX Blocks:'
            for m,f in zip(self.block_mat,self.block_flag):
                print 'block ',m,'material flag ',f
            print 'Absorbing Boundary Conditions:'
            for m,f in zip(self.block_bc,self.block_bc_flag):
                print  'bc ',m,'bc flag ',f
            print 'Topography (free surface)'
            print self.topography
            print 'Free surface'
            print self.free
        except:
            print '****************************************'
            print 'sorry, no blocks or blocks not properly defined'
            print block_mat
            print block_flag
            print block_bc
            print block_bc_flag
            print material
            print bc
            print '****************************************'
예제 #14
0
 def block_definition(self):
     block_flag=[]
     block_mat=[]
     block_bc=[]
     block_bc_flag=[]
     material={}
     bc={}
     blocks=cubit.get_block_id_list()
     for block in blocks:
         name=cubit.get_exodus_entity_name('block',block)
         ty=cubit.get_block_element_type(block)
         #print block,blocks,ty,self.hex,self.face
         if self.hex in ty:
             nattrib=cubit.get_block_attribute_count(block)
             flag=None
             vel=None
             vs=None
             rho=None
             q=0
             ani=0
             # material domain id
             if "acoustic" in name :
               imaterial = 1
             elif "elastic"  in name:
               imaterial = 2
             elif "poroelastic"  in name:
               imaterial = 3
             else :
               imaterial = 0
             #
             if nattrib > 1:
                 # material flag:
                 #   positive => material properties,
                 #   negative => interface/tomography domain
                 flag=int(cubit.get_block_attribute_value(block,0))
                 if flag > 0 and nattrib >= 2:
                     vel=cubit.get_block_attribute_value(block,1)
                     if nattrib >= 3:
                         vs=cubit.get_block_attribute_value(block,2)
                         if nattrib >= 4:
                             rho=cubit.get_block_attribute_value(block,3)
                             if nattrib >= 5:
                                 q=cubit.get_block_attribute_value(block,4)
                                 # for q to be valid: it must be positive
                                 if q < 0 :
                                   print 'error, q value invalid:', q
                                   break                                                   
                                 if nattrib == 6:
                                     ani=cubit.get_block_attribute_value(block,5)
                 elif flag < 0:
                     vel=name
                     attrib=cubit.get_block_attribute_value(block,1)
                     if attrib == 1: 
                         kind='interface'
                         flag_down=cubit.get_block_attribute_value(block,2)
                         flag_up=cubit.get_block_attribute_value(block,3)
                     elif attrib == 2:
                         kind='tomography'
             elif  nattrib == 1:
                 flag=cubit.get_block_attribute_value(block,0)
                 print 'only 1 attribute ', name,block,flag
                 vel,vs,rho,q,ani=(0,0,0,0,0)
             else:
                 flag=block
                 vel,vs,rho,q,ani=(name,0,0,0,0)
             block_flag.append(int(flag))
             block_mat.append(block)
             if flag > 0 and nattrib != 1:
                 par=tuple([imaterial,flag,vel,vs,rho,q,ani])
             elif flag < 0 and nattrib != 1:
                 if kind=='interface':
                     par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
                 elif kind=='tomography':
                     par=tuple([imaterial,flag,kind,name])
             elif flag==0 or nattrib == 1:
                 par=tuple([imaterial,flag,name])
             material[block]=par
         elif ty == self.face: #Stacey condition, we need hex here for pml
             block_bc_flag.append(4)
             block_bc.append(block)
             bc[block]=4 #face has connectivity = 4
             if name == self.topo or block == 1001: topography_face=block
         elif ty == 'SPHERE':
             pass
         else:
             # block elements differ from HEX8/QUAD4/SHELL4
             print '****************************************'
             print 'block not properly defined:'
             print '  name:',name
             print '  type:',type
             print
             print 'please check your block definitions!'
             print
             print 'only supported types are:'
             print '  HEX/HEX8  for volumes'
             print '  QUAD4 for surface'
             print '  SHELL4 for surface'
             print '****************************************'
             continue
             return None, None,None,None,None,None,None,None
     nsets=cubit.get_nodeset_id_list()
     if len(nsets) == 0: self.receivers=None
     for nset in nsets:
         name=cubit.get_exodus_entity_name('nodeset',nset)
         if name == self.rec:
             self.receivers=nset
         else:
             print 'nodeset '+name+' not defined'
             self.receivers=None
     print block_mat
     print block_flag
     print block_bc
     print block_bc_flag
     print material
     print bc
     print topography_face
     #
     try:
         self.block_mat=block_mat
         self.block_flag=block_flag
         self.block_bc=block_bc
         self.block_bc_flag=block_bc_flag
         self.material=material
         self.bc=bc
         self.topography=topography_face
     except:
         print '****************************************'
         print 'sorry, no blocks or blocks not properly defined'
         print block_mat
         print block_flag
         print block_bc
         print block_bc_flag
         print material
         print bc
         print topography
         print '****************************************'
    def getstats(self):
        ''' Get statistics for differend blocks in the hexmesh '''
        ############################## READ BLOCKS ######################
        try:
            blocks = cubit.get_block_id_list()
        except:
            print('no blocks defined')

        nblocks = len(blocks)
        print('Found ', nblocks, ' Blocks')
        # lists of details of all elastic blocks. For each elastic block, append respective values
        name = []
        typ = []
        nattrib = []
        vp = []
        vs = []
        rho = []
        minEdge = []
        maxEdge = []
        minEdgeMesh = []
        maxEdgeMesh = []
        # k: counter of all elastic blocks
        k = 0
        for block in blocks:
            minEdgeMeshTmp = []
            maxEdgeMeshTmp = []
            blockname = cubit.get_exodus_entity_name('block', block)
            # only apply stats to elastic blocks
            if blockname.find("elastic") >= 0:
                # NOW APPEND VALUES OF THIS ELASTIC BLOCK TO LISTS (defined as empty above)
                name.append(blockname)
                typ.append(cubit.get_block_element_type(block))
                # attribute count
                nattrib.append(cubit.get_block_attribute_count(block))
                # vp
                vp.append(cubit.get_block_attribute_value(block, 1))
                # vs
                vs.append(cubit.get_block_attribute_value(block, 2))
                # rho
                rho.append(cubit.get_block_attribute_value(block, 3))
                hexes = cubit.get_block_hexes(block)
                print(block, k, 'name: ', name[k], '#hexes:', len(hexes),
                      'type: ', typ[k], 'attribute count: ', nattrib[k],
                      'vp: ', vp[k], 'vs: ', vs[k], 'rho: ', rho[k])

                # minimum/maximum edgelength search for this elastic block
                # initiate  with very large minEdge and very small maxEdge
                minEdge.append(1e9)
                maxEdge.append(1e-9)
                # now search
                for hexa in hexes:
                    nodes = cubit.get_connectivity('Hex', hexa)
                    # get coordinates of nodes of this hexahedron
                    node_coords = []
                    for node in nodes:
                        node_coords.append(cubit.get_nodal_coordinates(node))

                    minv = self.minEdgeHex(node_coords)
                    minEdgeMeshTmp.append(minv)
                    maxv = self.maxEdgeHex(node_coords)
                    maxEdgeMeshTmp.append(maxv)

                    # is minimum edgelength of this this element smaller than minimum edgelength found before?
                    if minv < minEdge[k]:
                        minEdge[k] = minv

                    # is maximum edgelength of this this element larger than maximum edgelength found before?
                    if maxv > maxEdge[k]:
                        maxEdge[k] = maxv

                minEdgeMesh.append(minEdgeMeshTmp)
                maxEdgeMesh.append(maxEdgeMeshTmp)
                # end of processing of this elastic block. incremet counter
                k = k + 1
            # if not "elastic" in this blockname
            else:
                print(blockname, '--no elastic')

        # now calculate maximum frequency for which the mesh is stable
        # and maximal dt

        # first do that for each block
        fmax = []
        dtmax_05 = []
        for i in range(len(name)):
            fmax.append(self.calcMaxFreq(maxEdge[i], vs[i]))
            dtmax_05.append(self.calcMaxDt(minEdge[i], vp[i], cn=0.5))
            min_dx = minEdge[i] * 0.1727
            max_dx = maxEdge[i] * 0.3272 * sqrt(3.)
            print('Block ', name[i], ' min dx: ', min_dx, ' max dx: ', max_dx,
                  'max frequency: ', fmax[i], ' maximal dt (C=0.5):',
                  dtmax_05[i])
            vals, bin_edges = histogram(minEdgeMesh[i], 10)
            nhexa = sum(vals)
            print('   ' + str(nhexa) + ' HEXAS IN THIS BLOCK')
            print('   histogram of minimum edge length of hexa of this block:')
            for j, val in enumerate(vals):
                print(
                    '       %6.3f %% of hexas have minimum edgelength between %3.3f and %3.3f  ->   dt (C=0.5) is %8.3e'
                    %
                    (100. * val / float(nhexa), bin_edges[j], bin_edges[j + 1],
                     self.calcMaxDt(bin_edges[j], vp[i], cn=0.5)))
            vals, bin_edges = histogram(maxEdgeMesh[i], 10)
            nhexa = sum(vals)
            print('   ' + str(nhexa) + ' HEXAS IN THIS BLOCK')
            print('   histogram of maximum edge length of hexa of this block:')
            for j, val in enumerate(vals):
                print(
                    '       %6.3f %% of hexas have maximum edgelength between %3.3f and %3.3f  ->   fmax (5 GLL points per wavelength) is %8.3e'
                    %
                    (100. * val / float(nhexa), bin_edges[j], bin_edges[j + 1],
                     self.calcMaxFreq(bin_edges[j + 1], vs[i])))
        # now compare the values for all the blocks
        dtm_05 = sorted(dtmax_05)
        print(
            'The minimum over all blocks of the respective maximal dt for C=0.5 is: ',
            dtm_05[0])
        fmax_min = sorted(fmax)
        print(
            'The minimum over all blocks of the respective maximal frequency is: ',
            fmax_min[0])
예제 #16
0
    def get_block(self):
        ''' extract block information '''
        block_flag = []
        block_mat = []
        block_free = []
        block_absorb = []
        block_pml = []
        material = []
        # number of blocks
        blocks = cubit.get_block_id_list()

        # go through blocks
        for block in blocks:
            name = cubit.get_exodus_entity_name('block', block)
            type = cubit.get_block_element_type(block)
            print block, name, blocks, type

            if type == self.tet:
                # check if elastic
                if name.find('elastic') >= 0:
                    print('found elastic block')
                    imat = 1
                else:
                    print('error, no correct material in block', block)

                # get number of attributes
                nattrib = cubit.get_block_attribute_count(block)
                if nattrib != 0:
                    flag = int(cubit.get_block_attribute_value(block, 0))
                    vp = cubit.get_block_attribute_value(block, 1)
                    vs = cubit.get_block_attribute_value(block, 2)
                    rho = cubit.get_block_attribute_value(block, 3)
                    qp = cubit.get_block_attribute_value(block, 4)
                    qs = cubit.get_block_attribute_value(block, 5)
                    pml = int(cubit.get_block_attribute_value(block, 6))
                else:
                    print('error no attributes in block', block)
                block_flag.append(flag)
                block_mat.append(block)
                block_pml.append(pml)
                material.append([imat, vp, vs, rho, qp, qs])
            elif type == self.tri:
                if name.find('free') >= 0:
                    print('found free surface')
                    block_free.append(block)
                elif name.find('absorb') >= 0:
                    print('found absorb surface')
                    block_absorb.append(block)
                else:
                    print('error in boundaries', block)

#        ns=cubit.get_nodeset_id_list()
#        for n in ns:
#            name=cubit.get_exodus_entity_name('nodeset',n)
#            if name.find('free') >=0:
#                print('found free surface nodes')
#                ns_free.append(n)
#            elif name.find('absorb') >=0:
#                print('found absorb surface nodes')
#                ns_absorb.append(n)
#            else:
#                print('error in boundaries',n)

        print('BLOCKFLAG', block_flag)
        self.block_flag = block_flag
        self.block_mat = block_mat
        self.mat = material
        self.block_free = block_free
        self.block_absorb = block_absorb
        self.block_pml = block_pml