def save_elements_nodes(name,quads_fault_u,quads_fault_d):
   fault_file = open(name,'w')
   txt =''
   list_hex=cubit.parse_cubit_list('hex','all')
   txt='%10i %10i\n' % (len(quads_fault_u),len(quads_fault_d))
   fault_file.write(txt)
   
   dic_quads_fault_u = dict(zip(quads_fault_u,quads_fault_u)) 
   dic_quads_fault_d = dict(zip(quads_fault_d,quads_fault_d)) 
   
   # FAULT SIDE DOWN
   for h in list_hex: 
       faces = cubit.get_sub_elements('hex',h,2)  
       for f in faces:
           if dic_quads_fault_d.has_key(f): 
              nodes=cubit.get_connectivity('Face',f)
   #           print 'h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3]
              txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                nodes[1],nodes[2],nodes[3])
              fault_file.write(txt)

   # FAULT SIDE UP
   for h in list_hex: 
       faces = cubit.get_sub_elements('hex',h,2)  
       for f in faces:
           if dic_quads_fault_u.has_key(f): 
              nodes=cubit.get_connectivity('Face',f)
   #           print 'h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3]
              txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                nodes[1],nodes[2],nodes[3])
              fault_file.write(txt)

   fault_file.close()
Exemplo n.º 2
0
def save_elements_nodes(name, quads_fault_u, quads_fault_d):
    fault_file = open(name, 'w')
    txt = ''
    list_hex = cubit.parse_cubit_list('hex', 'all')
    txt = '%10i %10i\n' % (len(quads_fault_u), len(quads_fault_d))
    fault_file.write(txt)

    dic_quads_fault_u = dict(zip(quads_fault_u, quads_fault_u))
    dic_quads_fault_d = dict(zip(quads_fault_d, quads_fault_d))

    # FAULT SIDE DOWN
    for h in list_hex:
        faces = cubit.get_sub_elements('hex', h, 2)
        for f in faces:
            if dic_quads_fault_d.has_key(f):
                nodes = cubit.get_connectivity('Face', f)
                #           print 'h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3]
                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                  nodes[1],nodes[2],nodes[3])
                fault_file.write(txt)

    # FAULT SIDE UP
    for h in list_hex:
        faces = cubit.get_sub_elements('hex', h, 2)
        for f in faces:
            if dic_quads_fault_u.has_key(f):
                nodes = cubit.get_connectivity('Face', f)
                #           print 'h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3]
                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                  nodes[1],nodes[2],nodes[3])
                fault_file.write(txt)

    fault_file.close()
Exemplo n.º 3
0
 def free_write(self, freename=None):
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     normal = (0, 0, 1)
     if not freename: freename = self.freename
     freehex = open(freename, 'w')
     print 'Writing ' + freename + '.....'
     #
     #
     for block, flag in zip(self.block_bc, self.block_bc_flag):
         if block == self.topography:
             name = cubit.get_exodus_entity_name('block', block)
             print 'free surface (topography) block name:', name, 'id:', block
             quads_all = cubit.get_block_faces(block)
             print '  number of faces = ', len(quads_all)
             dic_quads_all = dict(zip(quads_all, quads_all))
             freehex.write('%10i\n' % len(quads_all))
             list_hex = cubit.parse_cubit_list('hex', 'all')
             for h in list_hex:
                 faces = cubit.get_sub_elements('hex', h, 2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         #print f
                         txt = self.create_facenode_string(h,
                                                           f,
                                                           normal,
                                                           cknormal=True)
                         freehex.write(txt)
             freehex.close()
         elif block == self.free:
             name = cubit.get_exodus_entity_name('block', block)
             print 'free surface block name:', name, 'id:', block
             quads_all = cubit.get_block_faces(block)
             print '  number of faces = ', len(quads_all)
             dic_quads_all = dict(zip(quads_all, quads_all))
             freehex.write('%10i\n' % len(quads_all))
             list_hex = cubit.parse_cubit_list('hex', 'all')
             for h in list_hex:
                 faces = cubit.get_sub_elements('hex', h, 2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         txt = self.create_facenode_string(h,
                                                           f,
                                                           normal,
                                                           cknormal=False)
                         freehex.write(txt)
             freehex.close()
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
Exemplo n.º 4
0
 def free_write(self,freename=None):
     # free surface
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     normal=(0,0,1)
     if not freename: freename=self.freename
     # writes free surface file
     print 'Writing '+freename+'.....'
     freehex=open(freename,'w')
     #
     # searches block definition with name face_topo
     for block,flag in zip(self.block_bc,self.block_bc_flag):
         if block == self.topography:
             name=cubit.get_exodus_entity_name('block',block)
             print 'free surface (topography) block name:',name,'id:',block
             quads_all=cubit.get_block_faces(block)
             print '  number of faces = ',len(quads_all)
             dic_quads_all=dict(zip(quads_all,quads_all))
             freehex.write('%10i\n' % len(quads_all))
             list_hex=cubit.parse_cubit_list('hex','all')
             for h in list_hex:
                 faces=cubit.get_sub_elements('hex',h,2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         #print f
                         txt=self.create_facenode_string(h,f,normal,cknormal=True)
                         freehex.write(txt)
             freehex.close()
         elif block == self.free:
             name=cubit.get_exodus_entity_name('block',block)
             print 'free surface block name:',name,'id:',block
             quads_all=cubit.get_block_faces(block)
             print '  number of faces = ',len(quads_all)
             dic_quads_all=dict(zip(quads_all,quads_all))
             freehex.write('%10i\n' % len(quads_all))
             list_hex=cubit.parse_cubit_list('hex','all')
             for h in list_hex:
                 faces=cubit.get_sub_elements('hex',h,2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         txt=self.create_facenode_string(h,f,normal,cknormal=False)
                         freehex.write(txt)
             freehex.close()
     print 'Ok'
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
 def free_write(self,freename=None):
     # free surface
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     normal=(0,0,1)
     if not freename: freename=self.freename
     # writes free surface file
     print 'Writing '+freename+'.....'
     freehex=open(freename,'w')
     # searches block definition with name face_topo
     for block,flag in zip(self.block_bc,self.block_bc_flag):
         if block == self.topography:
             name=cubit.get_exodus_entity_name('block',block)
             print '  block name:',name,'id:',block
             quads_all=cubit.get_block_faces(block)
             print '  number of faces = ',len(quads_all)
             dic_quads_all=dict(zip(quads_all,quads_all))
             freehex.write('%10i\n' % len(quads_all))
             list_hex=cubit.parse_cubit_list('hex','all')
             for h in list_hex:
                 faces=cubit.get_sub_elements('hex',h,2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         #print f
                         nodes=cubit.get_connectivity('Face',f)
                         nodes_ok=self.normal_check(nodes,normal)
                         txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
                                      nodes_ok[1],nodes_ok[2],nodes_ok[3])
                         freehex.write(txt)
     freehex.close()
     print 'Ok'
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
 def free_write(self, freename=None):
     # free surface
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     normal = (0, 0, 1)
     if not freename: freename = self.freename
     # writes free surface file
     print 'Writing ' + freename + '.....'
     freehex = open(freename, 'w')
     # searches block definition with name face_topo
     for block, flag in zip(self.block_bc, self.block_bc_flag):
         if block == self.topography:
             name = cubit.get_exodus_entity_name('block', block)
             print '  block name:', name, 'id:', block
             quads_all = cubit.get_block_faces(block)
             print '  number of faces = ', len(quads_all)
             dic_quads_all = dict(zip(quads_all, quads_all))
             freehex.write('%10i\n' % len(quads_all))
             list_hex = cubit.parse_cubit_list('hex', 'all')
             for h in list_hex:
                 faces = cubit.get_sub_elements('hex', h, 2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         #print f
                         nodes = cubit.get_connectivity('Face', f)
                         nodes_ok = self.normal_check(nodes, normal)
                         txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
                                      nodes_ok[1],nodes_ok[2],nodes_ok[3])
                         freehex.write(txt)
     freehex.close()
     print 'Ok'
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
Exemplo n.º 7
0
    def free_write(self, free_name):
        freefile = open(free_name, 'w')
        print('writing ' + free_name)

        list_tet = cubit.parse_cubit_list('tet', 'all')

        if (self.block_free != []):
            for n in self.block_free:
                elems_free = cubit.get_block_tris(n)
                dic_free = dict(zip(elems_free, elems_free))
                nfree = len(elems_free)
                freefile.write(str(nfree) + '\n')
                print('Number of free elements ', nfree)

            for tet in list_tet:
                tris = cubit.get_sub_elements('tet', tet, 2)
                for tri in tris:
                    if dic_free.has_key(tri):
                        nodes = cubit.get_connectivity('Tri', tri)
                        txt = ('%10i ') % tet
                        txt = txt + ('%10i %10i %10i') % nodes[:]
                        freefile.write(str(txt) + '\n')
        else:
            freefile.write(str(0) + '\n')
            print('Number of free elements ', 0)
Exemplo n.º 8
0
    def absorb_write(self, absorb_name):
        absorbfile = open(absorb_name, 'w')
        print('writing ' + absorb_name)

        #        for n in self.ns_absorb:
        #            nodes_absorb=cubit.get_nodeset_nodes(n)
        #        nabs=len(nodes_absorb)
        #        absorbfile.write(str(nabs)+'\n')
        #        print('Number of absorbing nodes ',nabs)

        #        for node in nodes_absorb:
        #            absorbfile.write(str(node)+'\n')
        ###
        list_tet = cubit.parse_cubit_list('tet', 'all')

        if (self.block_absorb != []):
            for n in self.block_absorb:
                elems_absorb = cubit.get_block_tris(n)
                dic_absorb = dict(zip(elems_absorb, elems_absorb))
                nabs = len(elems_absorb)
                absorbfile.write(str(nabs) + '\n')
                print('Number of absorbing elements ', nabs)

            for tet in list_tet:
                tris = cubit.get_sub_elements('tet', tet, 2)
                for tri in tris:
                    if dic_absorb.has_key(tri):
                        nodes = cubit.get_connectivity('Tri', tri)
                        txt = ('%10i ') % tet
                        txt = txt + ('%10i %10i %10i') % nodes[:]
                        absorbfile.write(str(txt) + '\n')
        else:
            absorbfile.write(str(0) + '\n')
            print('Number of absorbing elements ', 0)
 def free_write(self, freename):  #freename = None):
     """ Write free surface on file : freename """
     cubit.cmd(
         'set info off')  # Turn off return messages from Cubit commands
     cubit.cmd('set echo off')  # Turn off echo of Cubit commands
     cubit.cmd('set journal off')  # Do not save journal file
     from sets import Set
     # if not freename: freename = self.freename
     freeedge = open(freename, 'w')
     print 'Writing ' + freename + '.....'
     if self.topo_mesh:
         for block, flag in zip(self.block_bc,
                                self.block_bc_flag):  # For each 1D block
             if block == self.topography:  # If the block correspond to topography
                 edges_all = Set(cubit.get_block_edges(
                     block))  # Import all topo edges id as a Set
         freeedge.write('%10i\n' % len(edges_all)
                        )  # Print the number of edges on the free surface
         print 'Number of edges in free surface :', len(edges_all)
         id_element = 0
         for block, flag in zip(self.block_mat,
                                self.block_flag):  # For each 2D block
             quads = cubit.get_block_faces(block)  # Import quads id
             for quad in quads:  # For each quad
                 id_element = id_element + 1  # id of this quad
                 edges = Set(
                     cubit.get_sub_elements("face", quad, 1)
                 )  # Get the lower dimension entities associated with a higher dimension entities.
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
                 intersection = edges & edges_all  # Contains the edges of the considered quad that is on the free surface
                 if len(intersection
                        ) != 0:  # If this quad touch the free surface
                     nodes = cubit.get_expanded_connectivity(
                         'face',
                         quad)  # Import the nodes describing the quad
                     nodes = self.jac_check(
                         list(nodes))  # Check the jacobian of the quad
                     for e in intersection:  # For each edge on the free surface
                         node_edge = cubit.get_connectivity(
                             'edge',
                             e)  # Import the nodes describing the edge
                         nodes_ok = []
                         for i in nodes:  # ??? TODO nodes_ok == node_edge ???
                             if i in node_edge:
                                 nodes_ok.append(i)
                         txt = '%10i %10i %10i %10i\n' % (
                             id_element, 2, nodes_ok[0], nodes_ok[1])
                         # Write the id of the quad, 2 (number of nodes describing a free surface elements), and the nodes
                         freeedge.write(txt)
     else:
         freeedge.write(
             '0'
         )  # Even without any free surface specfem2d need a file with a 0 in first line
     freeedge.close()
     print 'Ok'
     cubit.cmd('set info on')  # Turn on return messages from Cubit commands
     cubit.cmd('set echo on')  # Turn on echo of Cubit commands
Exemplo n.º 10
0
 def forcing_write(self,forcname):
     """ Write forcing surfaces on file : forcname """
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     cubit.cmd('set journal off') # Do not save journal file
     from sets import Set
     forceedge = open(forcname,'w')
     print 'Writing '+forcname+'.....'
     edges_forc = [Set()]*self.nforc # edges_forc[0] will be a Set containing the nodes describing the forcing boundary
     # (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
     nedges_all = 0 # To count the total number of forcing edges
     for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block
         for iforc in range(0, self.nforc): # iforc = 0,1,2,3 : for each forcing boundaries
             if block == self.forcing_boun[iforc]: # If the block considered correspond to the boundary
                 edges_forc[iforc] = Set(cubit.get_block_edges(block)) # Store each edge on edges_forc
                 nedges_all = nedges_all+len(edges_forc[iforc]) # add the number of edges to nedges_all
     toWritetoFile = [""]*(nedges_all+1)
     toWritetoFile[0] = '%10i\n' % nedges_all # Write the total number of forcing edges to the first line of file
     #forceedge.write('%10i\n' % nedges_all) # Write the total number of forcing edges to the first line of file
     print 'Number of edges', nedges_all
     #id_element = 0
     indexFile = 1
     for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
             quads = cubit.get_block_faces(block) # Import quads id
             for quad in quads: # For each quad
                 #id_element = id_element+1 # id of this quad
                 edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities.
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
                 for iforc in range(0,self.nforc): # iforc = 0,1,2,3 : for each forcing boundaries
                     intersection = edges & edges_forc[iforc]  # Contains the edges of the considered quad that is on the forcing boundary considered
                     if len(intersection) != 0: # If this quad touch the forcing boundary considered
                         nodes = cubit.get_connectivity('face',quad) # Import the nodes describing the quad
                         nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                         for e in intersection: # For each edge on the forcing boundary considered
                             node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge
                             nodes_ok = []
                             for i in nodes: # Loop on the nodes of the quad
                                 if i in node_edge: # If this node is belonging to forcing surface
                                     nodes_ok.append(i) # add it to nodes_ok
                             # forcname contains 1/ element number, 2/ number of nodes that form the acoustic forcing edge
                             # (which currently must always be equal to two, see comment below),
                             # 3/ first node on the acforcing surface, 4/ second node on the acforcing surface
                             # 5/ 1 = IBOTTOME, 2 = IRIGHT, 3 = ITOP, 4 = ILEFT
                             #txt = '%10i %10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1],iforc+1)
                             txt = '%10i %10i %10i %10i %10i\n' % (quad,2,nodes_ok[0],nodes_ok[1],iforc+1)
                             # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes and the type of boundary
                             #print indexFile
                             toWritetoFile[indexFile] = txt
                             indexFile = indexFile + 1
                             #forceedge.write(txt)
     forceedge.writelines(toWritetoFile)
     forceedge.close()
     print 'Ok'
     cubit.cmd('set info on') # Turn on return messages from Cubit commands
     cubit.cmd('set echo on') # Turn on echo of Cubit commands
Exemplo n.º 11
0
 def axis_write(self, axis_name):
     """ Write axis on file """
     cubit.cmd(
         'set info off')  # Turn off return messages from Cubit commands
     cubit.cmd('set echo off')  # Turn off echo of Cubit commands
     cubit.cmd('set journal off')  # Do not save journal file
     from sets import Set
     axisedge = open(axis_name, 'w')
     print 'Writing ' + axis_name + '.....'
     for block, flag in zip(self.block_bc,
                            self.block_bc_flag):  # For each 1D block
         if block == self.axisId:  # If the block correspond to the axis
             edges_all = Set(cubit.get_block_edges(
                 block))  # Import all axis edges id as a Set
     toWritetoFile = [""] * (len(edges_all) + 1)
     toWritetoFile[0] = '%10i\n' % len(
         edges_all)  # Write the number of edges on the axis
     #axisedge.write('%10i\n' % len(edges_all)) # Write the number of edges on the axis
     print 'Number of edges on the axis :', len(edges_all)
     #id_element = 0
     indexFile = 1
     for block, flag in zip(self.block_mat,
                            self.block_flag):  # For each 2D block
         quads = cubit.get_block_faces(block)  # Import quads id
         for quad in quads:  # For each quad
             #id_element = id_element+1 # id of this quad
             edges = Set(
                 cubit.get_sub_elements("face", quad, 1)
             )  # Get the lower dimension entities associated with a higher dimension entities.
             # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
             intersection = edges & edges_all  # Contains the edges of the considered quad that are on the axis
             if len(intersection) != 0:  # If this quad touch the axis
                 nodes = cubit.get_connectivity(
                     'face', quad)  # Import the nodes describing the quad
                 nodes = self.jac_check(
                     list(nodes))  # Check the jacobian of the quad
                 for e in intersection:  # For each edge on the axis
                     node_edge = cubit.get_connectivity(
                         'edge', e)  # Import the nodes describing the edge
                     nodes_ok = []
                     for i in nodes:  # Loop on the nodes of the quad
                         if i in node_edge:  # If this node is belonging to the axis
                             nodes_ok.append(i)  # Add it to nodes_ok
                     txt = '%10i %10i %10i %10i\n' % (quad, 2, nodes_ok[0],
                                                      nodes_ok[1])
                     #txt = '%10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1])
                     # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes
                     toWritetoFile[indexFile] = txt
                     indexFile = indexFile + 1
                     #axisedge.write(txt)
     axisedge.writelines(toWritetoFile)
     axisedge.close()
     print 'Ok'
     cubit.cmd('set info on')  # Turn on return messages from Cubit commands
     cubit.cmd('set echo on')  # Turn on echo of Cubit commands
    def mesh_analysis(self, frequency):
        from sets import Set
        cubit.cmd('set info off')
        cubit.cmd('set echo off')
        cubit.cmd('set journal off')
        bins_d = [0.0001] + range(0, int(frequency) + 1) + [1000]
        bins_u = bins_d[1:]
        dt = []
        ed_dt = []
        r = []
        ed_r = []
        nstart = cubit.get_next_sideset_id()
        command = "del sideset all"
        cubit.cmd(command)
        for bin_d, bin_u in zip(bins_d, bins_u):
            nsideset = cubit.get_next_sideset_id()
            command = 'create sideset ' + str(nsideset)
            cubit.cmd(command)
            command = "sideset " + str(nsideset) + " name " + "'ratio-[" + str(
                bin_d) + "_" + str(bin_u) + "['"
            cubit.cmd(command)
        nend = cubit.get_next_sideset_id()
        sidelist = range(nstart, nend)
        for block in self.block_mat:
            name = cubit.get_exodus_entity_name('block', block)
            velocity = self.material[name][1]
            if velocity > 0:
                faces = cubit.get_block_faces(block)
                edges = []
                for face in faces:
                    es = cubit.get_sub_elements("face", face, 1)
                    edges = edges + list(es)
                edges = Set(edges)
                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
                                                              velocity,bins_d,bins_u,sidelist)
                dt.append(dtstore)
                ed_dt.append(edgedtstore)
                r.append(ratiostore)
                ed_r.append(edgeratiostore)
        self.ddt = zip(ed_dt, dt)
        self.dr = zip(ed_r, r)

        def sorter(x, y):
            return cmp(x[1], y[1])

        self.ddt.sort(sorter)
        self.dr.sort(sorter)
        print self.ddt, self.dr
        print 'Deltat minimum => edge:' + str(self.ddt[0][0]) + ' dt: ' + str(
            self.ddt[0][1])
        print 'minimum frequency resolved => edge:' + str(
            self.dr[0][0]) + ' frequency: ' + str(self.dr[0][1])
        return self.ddt[0], self.dr[0]
Exemplo n.º 13
0
    def mesh_analysis(self, frequency):
        from sets import Set

        cubit.cmd("set info off")
        cubit.cmd("set echo off")
        cubit.cmd("set journal off")
        bins_d = [0.0001] + range(0, int(frequency) + 1) + [1000]
        bins_u = bins_d[1:]
        dt = []
        ed_dt = []
        r = []
        ed_r = []
        nstart = cubit.get_next_sideset_id()
        command = "del sideset all"
        cubit.cmd(command)
        for bin_d, bin_u in zip(bins_d, bins_u):
            nsideset = cubit.get_next_sideset_id()
            command = "create sideset " + str(nsideset)
            cubit.cmd(command)
            command = "sideset " + str(nsideset) + " name " + "'ratio-[" + str(bin_d) + "_" + str(bin_u) + "['"
            cubit.cmd(command)
        nend = cubit.get_next_sideset_id()
        sidelist = range(nstart, nend)
        for block in self.block_mat:
            name = cubit.get_exodus_entity_name("block", block)
            velocity = self.material[name][1]
            if velocity > 0:
                faces = cubit.get_block_faces(block)
                edges = []
                for face in faces:
                    es = cubit.get_sub_elements("face", face, 1)
                    edges = edges + list(es)
                edges = Set(edges)
                dtstore, edgedtstore, ratiostore, edgeratiostore = self.seismic_resolution(
                    edges, velocity, bins_d, bins_u, sidelist
                )
                dt.append(dtstore)
                ed_dt.append(edgedtstore)
                r.append(ratiostore)
                ed_r.append(edgeratiostore)
        self.ddt = zip(ed_dt, dt)
        self.dr = zip(ed_r, r)

        def sorter(x, y):
            return cmp(x[1], y[1])

        self.ddt.sort(sorter)
        self.dr.sort(sorter)
        print self.ddt, self.dr
        print "Deltat minimum => edge:" + str(self.ddt[0][0]) + " dt: " + str(self.ddt[0][1])
        print "minimum frequency resolved => edge:" + str(self.dr[0][0]) + " frequency: " + str(self.dr[0][1])
        return self.ddt[0], self.dr[0]
Exemplo n.º 14
0
 def abs_write(self,absname):
     """ Write absorbing surfaces on file : absname """
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     cubit.cmd('set journal off') # Do not save journal file.
     from sets import Set
     # if not absname: absname = self.absname
     absedge = open(absname,'w')
     print 'Writing '+absname+'.....'
     edges_abs = [Set()]*self.nabs # edges_abs[0] will be a Set containing the nodes describing bottom adsorbing boundary
     # (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
     nedges_all = 0 # To count the total number of absorbing edges
     for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block
         for iabs in range(0, self.nabs): # iabs = 0,1,2,3 : for each absorbing boundaries
             if block == self.abs_boun[iabs]: # If the block considered correspond to the boundary
                 edges_abs[iabs] = Set(cubit.get_block_edges(block)) # Store each edge on edges_abs
                 nedges_all = nedges_all+len(edges_abs[iabs]); # add the number of edges to nedges_all
     toWritetoFile = [""]*(nedges_all+1)
     toWritetoFile[0] = '%10i\n' % nedges_all # Write the total number of absorbing edges to the first line of file
     #absedge.write('%10i\n' % nedges_all) # Write the total number of absorbing edges to the first line of file
     print 'Number of edges', nedges_all
     #id_element = 0
     indexFile = 1
     for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
             quads = cubit.get_block_faces(block) # Import quads id
             for quad in quads: # For each quad
                 #id_element = id_element+1 # id of this quad
                 edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities.
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
                 for iabs in range(0,self.nabs): # iabs = 0,1,2,3 : for each absorbing boundaries
                     intersection = edges & edges_abs[iabs]  # Contains the edges of the considered quad that is on the absorbing boundary considered
                     if len(intersection) != 0: # If this quad touch the absorbing boundary considered
                         nodes = cubit.get_connectivity('face',quad) # Import the nodes describing the quad
                         nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                         for e in intersection: # For each edge on the absorbing boundary considered
                             node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge
                             nodes_ok = []
                             for i in nodes: # Loop on the nodes of the quad
                                 if i in node_edge: # If this node is belonging to absorbing surface
                                     nodes_ok.append(i) # Add it to nodes_ok
                             #txt = '%10i %10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1],iabs+1)
                             txt = '%10i %10i %10i %10i %10i\n' % (quad,2,nodes_ok[0],nodes_ok[1],iabs+1)
                             # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes and the type of boundary
                             toWritetoFile[indexFile] = txt
                             indexFile = indexFile + 1
                             #absedge.write(txt)
     absedge.writelines(toWritetoFile)
     absedge.close()
     print 'Ok'
     cubit.cmd('set info on') # Turn on return messages from Cubit commands
     cubit.cmd('set echo on') # Turn on echo of Cubit commands
Exemplo n.º 15
0
 def free_write(self,freename): #freename = None):
     """ Write free surface on file : freename """
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     cubit.cmd('set journal off') # Do not save journal file
     from sets import Set
     # if not freename: freename = self.freename
     freeedge = open(freename,'w')
     print 'Writing '+freename+'.....'
     if self.topo_mesh:
         for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block
             if block == self.topography: # If the block correspond to topography
                 edges_all = Set(cubit.get_block_edges(block)) # Import all topo edges id as a Set
         toWritetoFile = [] #[""]*(len(edges_all)+1)
         toWritetoFile.append('%10i\n' % len(edges_all)) # Print the number of edges on the free surface
         for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
             print block,flag
             quads = cubit.get_block_faces(block) # Import quads id
             for quad in quads: # For each quad
                 edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities.
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
                 intersection = edges & edges_all # Contains the edges of the considered quad that is on the free surface
                 if len(intersection) != 0: # If this quad touch the free surface
                     #print "  ",quad," -> this quad touch the free surface!"
                     nodes = cubit.get_connectivity('face',quad) # Import the nodes describing the quad
                     #print "    it is described by nodes:",nodes," and edges :",edges
                     #print "      edges:",intersection," is/are on the free surface"
                     nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                     for e in intersection: # For each edge on the free surface
                         node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge
                         #print "      edge",e,"is composed of nodes",node_edge
                         nodes_ok = []
                         for i in nodes: # Loop on the nodes of the quad
                             if i in node_edge: # If this node is belonging to the free surface
                                 nodes_ok.append(i) # Put it in nodes_ok
                         #print "    nodes:",nodes_ok,"belong to free surface"
                         txt = '%10i %10i %10i %10i\n' % (quad,2,nodes_ok[0],nodes_ok[1])
                         toWritetoFile.append(txt)
                         # Write the id of the quad, 2 (number of nodes describing a free surface elements), and the nodes
         freeedge.writelines(toWritetoFile)
     else:
         freeedge.write('0') # Even without any free surface specfem2d need a file with a 0 in first line
     freeedge.close()
     print 'Ok'
     cubit.cmd('set info on') # Turn on return messages from Cubit commands
     cubit.cmd('set echo on') # Turn on echo of Cubit commands
Exemplo n.º 16
0
    def surface_write(self, pathdir=None):
        # optional surfaces, e.g. moho_surface
        # should be created like e.g.:
        #  > block 10 face in surface 2
        #  > block 10 name 'moho_surface'
        import re
        from sets import Set

        for block in self.block_bc:
            if block != self.topography:
                name = cubit.get_exodus_entity_name("block", block)
                # skips block names like face_abs**, face_topo**
                if re.search("abs", name):
                    continue
                elif re.search("topo", name):
                    continue
                elif re.search("surface", name):
                    filename = pathdir + name + "_file"
                else:
                    continue
                # gets face elements
                print "  surface block name: ", name, "id: ", block
                quads_all = cubit.get_block_faces(block)
                print "  face = ", len(quads_all)
                if len(quads_all) == 0:
                    continue
                # writes out surface infos to file
                print "Writing " + filename + "....."
                surfhex_local = open(filename, "w")
                dic_quads_all = dict(zip(quads_all, quads_all))
                # writes number of surface elements
                surfhex_local.write("%10i\n" % len(quads_all))
                # writes out element node ids
                list_hex = cubit.parse_cubit_list("hex", "all")
                for h in list_hex:
                    faces = cubit.get_sub_elements("hex", h, 2)
                    for f in faces:
                        if dic_quads_all.has_key(f):
                            nodes = cubit.get_connectivity("Face", f)
                            txt = "%10i %10i %10i %10i %10i\n" % (h, nodes[0], nodes[1], nodes[2], nodes[3])
                            surfhex_local.write(txt)
                # closes file
                surfhex_local.close()
        print "Ok"
 def surface_write(self,pathdir=None):
     # optional surfaces, e.g. moho_surface
     # should be created like e.g.:
     #  > block 10 face in surface 2
     #  > block 10 name 'moho_surface'
     import re
     from sets import Set
     for block in self.block_bc :
         if block != self.topography:
             name=cubit.get_exodus_entity_name('block',block)
             # skips block names like face_abs**, face_topo**
             if re.search('abs',name):
               continue
             elif re.search('topo',name):
               continue
             elif re.search('surface',name):
               filename=pathdir+name+'_file'
             else:
               continue
             # gets face elements
             print '  surface block name: ',name,'id: ',block
             quads_all=cubit.get_block_faces(block)
             print '  face = ',len(quads_all)
             if len(quads_all) == 0 :
               continue
             # writes out surface infos to file
             print 'Writing '+filename+'.....'
             surfhex_local=open(filename,'w')
             dic_quads_all=dict(zip(quads_all,quads_all))
             # writes number of surface elements
             surfhex_local.write('%10i\n' % len(quads_all))
             # writes out element node ids
             list_hex=cubit.parse_cubit_list('hex','all')
             for h in list_hex:
                 faces=cubit.get_sub_elements('hex',h,2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         nodes=cubit.get_connectivity('Face',f)
                         txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                          nodes[1],nodes[2],nodes[3])
                         surfhex_local.write(txt)
             # closes file
             surfhex_local.close()
     print 'Ok'
Exemplo n.º 18
0
 def axis_write(self,axis_name):
     """ Write axis on file """
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     cubit.cmd('set journal off') # Do not save journal file
     from sets import Set
     axisedge = open(axis_name,'w')
     print 'Writing '+axis_name+'.....'
     for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block
         if block == self.axisId: # If the block correspond to the axis
             edges_all = Set(cubit.get_block_edges(block)) # Import all axis edges id as a Set
     toWritetoFile = [""]*(len(edges_all)+1)
     toWritetoFile[0] = '%10i\n' % len(edges_all) # Write the number of edges on the axis
     #axisedge.write('%10i\n' % len(edges_all)) # Write the number of edges on the axis
     print 'Number of edges on the axis :',len(edges_all)
     #id_element = 0
     indexFile = 1
     for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
             quads = cubit.get_block_faces(block) # Import quads id
             for quad in quads: # For each quad
                 #id_element = id_element+1 # id of this quad
                 edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities.
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
                 intersection = edges & edges_all # Contains the edges of the considered quad that are on the axis
                 if len(intersection) != 0: # If this quad touch the axis
                     nodes = cubit.get_connectivity('face',quad) # Import the nodes describing the quad
                     nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                     for e in intersection: # For each edge on the axis
                         node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge
                         nodes_ok = []
                         for i in nodes: # Loop on the nodes of the quad
                             if i in node_edge: # If this node is belonging to the axis
                                 nodes_ok.append(i) # Add it to nodes_ok
                         txt = '%10i %10i %10i %10i\n' % (quad,2,nodes_ok[0],nodes_ok[1])
                         #txt = '%10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1])
                         # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes
                         toWritetoFile[indexFile] = txt
                         indexFile = indexFile + 1
                         #axisedge.write(txt)
     axisedge.writelines(toWritetoFile)
     axisedge.close()
     print 'Ok'
     cubit.cmd('set info on') # Turn on return messages from Cubit commands
     cubit.cmd('set echo on') # Turn on echo of Cubit commands
Exemplo n.º 19
0
 def abs_write(self,absname): #absname=None):
     """ Write absorbing surfaces on file : absname """ 
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     cubit.cmd('set journal off') # Do not save journal file
     from sets import Set
     # if not absname: absname = self.absname
     absedge = open(absname,'w')
     print 'Writing '+absname+'.....'
     edges_abs = [Set()]*self.nabs # edges_abs[0] will be a Set containing the nodes describing bottom adsorbing boundary 
     # (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
     nedges_all = 0 # To count the total number of absorbing edges 
     for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block
         for iabs in range(0, self.nabs): # iabs = 0,1,2,3 : for each absorbing boundaries
             if block == self.abs_boun[iabs]: # If the block considered correspond to the boundary
                 edges_abs[iabs] = Set(cubit.get_block_edges(block)) # Store each edge on edges_abs
                 nedges_all = nedges_all+len(edges_abs[iabs]); # add the number of edges to nedges_all
     absedge.write('%10i\n' % nedges_all) # Write the total number of absorbing edges to the first line of file
     print 'Number of edges', nedges_all
     id_element  = 0
     for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
             quads = cubit.get_block_faces(block) # Import quads id
             for quad in quads: # For each quad
                 id_element = id_element+1 # id of this quad
                 edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities. 
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set 
                 for iabs in range(0,self.nabs): # iabs = 0,1,2,3 : for each absorbing boundaries
                     intersection = edges & edges_abs[iabs]  # Contains the edges of the considered quad that is on the absorbing boundary considered
                     if len(intersection) != 0: # If this quad touch the absorbing boundary considered
                         nodes = cubit.get_expanded_connectivity('face',quad) # Import the nodes describing the quad
                         nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                         for e in intersection: # For each edge on the absorbing boundary considered
                             node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge
                             nodes_ok = []
                             for i in nodes: # Loop on the nodes of the quad
                                 if i in node_edge: # If this node is belonging to absorbing surface
                                     nodes_ok.append(i) # Add it to nodes_ok
                             txt = '%10i %10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1],iabs+1)
                             # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes and the type of boundary 
                             absedge.write(txt)
     absedge.close()
     print 'Ok'
     cubit.cmd('set info on') # Turn on return messages from Cubit commands
     cubit.cmd('set echo on') # Turn on echo of Cubit commands
 def surface_write(self, pathdir=None):
     # optional surfaces, e.g. moho_surface
     # should be created like e.g.:
     #  > block 10 face in surface 2
     #  > block 10 name 'moho_surface'
     import re
     from sets import Set
     for block in self.block_bc:
         if block != self.topography:
             name = cubit.get_exodus_entity_name('block', block)
             # skips block names like face_abs**, face_topo**
             if re.search('abs', name):
                 continue
             elif re.search('topo', name):
                 continue
             elif re.search('surface', name):
                 filename = pathdir + name + '_file'
             else:
                 continue
             # gets face elements
             print '  surface block name: ', name, 'id: ', block
             quads_all = cubit.get_block_faces(block)
             print '  face = ', len(quads_all)
             if len(quads_all) == 0:
                 continue
             # writes out surface infos to file
             print 'Writing ' + filename + '.....'
             surfhex_local = open(filename, 'w')
             dic_quads_all = dict(zip(quads_all, quads_all))
             # writes number of surface elements
             surfhex_local.write('%10i\n' % len(quads_all))
             # writes out element node ids
             list_hex = cubit.parse_cubit_list('hex', 'all')
             for h in list_hex:
                 faces = cubit.get_sub_elements('hex', h, 2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         nodes = cubit.get_connectivity('Face', f)
                         txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                          nodes[1],nodes[2],nodes[3])
                         surfhex_local.write(txt)
             # closes file
             surfhex_local.close()
     print 'Ok'
 def free_write(self,freename): #freename = None):
     """ Write free surface on file : freename """ 
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     cubit.cmd('set journal off') # Do not save journal file
     from sets import Set
     # if not freename: freename = self.freename
     freeedge = open(freename,'w')
     print 'Writing '+freename+'.....'
     if self.topo_mesh:
         for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block
             if block == self.topography: # If the block correspond to topography
                 edges_all = Set(cubit.get_block_edges(block)) # Import all topo edges id as a Set
         freeedge.write('%10i\n' % len(edges_all)) # Print the number of edges on the free surface
         print 'Number of edges in free surface :',len(edges_all)
         id_element=0
         for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
                 quads = cubit.get_block_faces(block) # Import quads id
                 for quad in quads: # For each quad
                     id_element = id_element+1 # id of this quad
                     edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities. 
                     # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set 
                     intersection = edges & edges_all # Contains the edges of the considered quad that is on the free surface
                     if len(intersection) != 0: # If this quad touch the free surface
                         nodes = cubit.get_expanded_connectivity('face',quad) # Import the nodes describing the quad
                         nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                         for e in intersection: # For each edge on the free surface
                             node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge
                             nodes_ok = []
                             for i in nodes: # ??? TODO nodes_ok == node_edge ???
                                 if i in node_edge:
                                     nodes_ok.append(i)
                             txt='%10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1]) 
                             # Write the id of the quad, 2 (number of nodes describing a free surface elements), and the nodes
                             freeedge.write(txt)
     else:
         freeedge.write('0') # Even without any free surface specfem2d need a file with a 0 in first line
     freeedge.close()
     print 'Ok'
     cubit.cmd('set info on') # Turn on return messages from Cubit commands
     cubit.cmd('set echo on') # Turn on echo of Cubit commands
Exemplo n.º 22
0
    def free_write(self, freename=None):
        # free surface
        cubit.cmd("set info off")
        cubit.cmd("set echo off")
        cubit.cmd("set journal off")
        from sets import Set

        normal = (0, 0, 1)
        if not freename:
            freename = self.freename
        # writes free surface file
        print "Writing " + freename + "....."
        freehex = open(freename, "w")
        # searches block definition with name face_topo
        for block, flag in zip(self.block_bc, self.block_bc_flag):
            if block == self.topography:
                name = cubit.get_exodus_entity_name("block", block)
                print "  block name:", name, "id:", block
                quads_all = cubit.get_block_faces(block)
                print "  number of faces = ", len(quads_all)
                dic_quads_all = dict(zip(quads_all, quads_all))
                freehex.write("%10i\n" % len(quads_all))
                list_hex = cubit.parse_cubit_list("hex", "all")
                for h in list_hex:
                    faces = cubit.get_sub_elements("hex", h, 2)
                    for f in faces:
                        if dic_quads_all.has_key(f):
                            # print f
                            nodes = cubit.get_connectivity("Face", f)
                            nodes_ok = self.normal_check(nodes, normal)
                            txt = "%10i %10i %10i %10i %10i\n" % (h, nodes_ok[0], nodes_ok[1], nodes_ok[2], nodes_ok[3])
                            freehex.write(txt)
        freehex.close()
        print "Ok"
        cubit.cmd("set info on")
        cubit.cmd("set echo on")
Exemplo n.º 23
0
    def abs_write(self, absname=None):
        # absorbing boundaries
        import re

        cubit.cmd("set info off")
        cubit.cmd("set echo off")
        cubit.cmd("set journal off")
        from sets import Set

        if not absname:
            absname = self.absname
        #
        # loops through all block definitions
        list_hex = cubit.parse_cubit_list("hex", "all")
        for block, flag in zip(self.block_bc, self.block_bc_flag):
            if block != self.topography:
                name = cubit.get_exodus_entity_name("block", block)
                print name, block
                absflag = False
                if re.search("xmin", name):
                    filename = absname + "_xmin"
                    normal = (-1, 0, 0)
                elif re.search("xmax", name):
                    filename = absname + "_xmax"
                    normal = (1, 0, 0)
                elif re.search("ymin", name):
                    filename = absname + "_ymin"
                    normal = (0, -1, 0)
                elif re.search("ymax", name):
                    filename = absname + "_ymax"
                    normal = (0, 1, 0)
                elif re.search("bottom", name):
                    filename = absname + "_bottom"
                    normal = (0, 0, -1)
                elif re.search("abs", name):
                    # print "  ...face_abs - not used so far..."
                    filename = absname + "_all"
                    absflag = True
                else:
                    continue
                # opens file
                print "Writing " + filename + "....."
                abshex_local = open(filename, "w")
                # gets face elements
                quads_all = cubit.get_block_faces(block)
                dic_quads_all = dict(zip(quads_all, quads_all))
                print "  number of faces = ", len(quads_all)
                abshex_local.write("%10i\n" % len(quads_all))
                # command = "group 'list_hex' add hex in face "+str(quads_all)
                # command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
                # cubit.cmd(command)
                # group=cubit.get_id_from_name("list_hex")
                # list_hex=cubit.get_group_hexes(group)
                # command = "delete group "+ str(group)
                # cubit.cmd(command)
                for h in list_hex:
                    faces = cubit.get_sub_elements("hex", h, 2)
                    for f in faces:
                        if dic_quads_all.has_key(f):
                            nodes = cubit.get_connectivity("Face", f)
                            if not absflag:
                                # checks with specified normal
                                nodes_ok = self.normal_check(nodes, normal)
                                txt = "%10i %10i %10i %10i %10i\n" % (
                                    h,
                                    nodes_ok[0],
                                    nodes_ok[1],
                                    nodes_ok[2],
                                    nodes_ok[3],
                                )
                            else:
                                txt = "%10i %10i %10i %10i %10i\n" % (h, nodes[0], nodes[1], nodes[2], nodes[3])
                            abshex_local.write(txt)
                # closes file
                abshex_local.close()
        print "Ok"
        cubit.cmd("set info on")
        cubit.cmd("set echo on")
Exemplo n.º 24
0
def save_elements_nodes(name, quads_fault_u, quads_fault_d):
    print('')
    print('## save fault nodes elements: file = ', name)
    print('##')
    fault_file = open(name, 'w')
    txt = ''
    list_hex = cubit.parse_cubit_list('hex', 'all')

    # number of fault elements up/down
    txt = '%10i %10i\n' % (len(quads_fault_u), len(quads_fault_d))
    fault_file.write(txt)

    dic_quads_fault_u = dict(zip(quads_fault_u, quads_fault_u))
    dic_quads_fault_d = dict(zip(quads_fault_d, quads_fault_d))

    #cubit.cmd('set info off')
    #cubit.cmd('set echo off')

    # FAULT SIDE DOWN
    # fault_file.write('upsurface')
    for h in list_hex:
        faces = cubit.get_sub_elements('hex', h, 2)
        for f in faces:
            if f in dic_quads_fault_d.keys():
                cubit.silent_cmd('group "nf" add Node in face ' + str(f))

        group1 = cubit.get_id_from_name("nf")
        nodes = []
        if not group1 == 0:
            nodes = cubit.get_group_nodes(group1)
            cubit.silent_cmd('del group ' + str(group1))
            #debug
            #print('#fault down nodes: ',nodes,len(nodes),group1)

        #debug
        #nodes=cubit.get_connectivity('Face',f)
        #print('h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3])

        if len(nodes) > 0:
            ngnod2d = len(nodes)
            if ngnod2d == 9:
                #kangchen added
                #txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],nodes[1],nodes[2],nodes[3])
                txt = '%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                      nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
            else:
                txt = '%10i %10i %10i %10i %10i \n' % (h, nodes[0], nodes[1],
                                                       nodes[2], nodes[3])

            fault_file.write(txt)

    # FAULT SIDE UP
    #  fault_file.write('downsurface')
    for h in list_hex:
        faces = cubit.get_sub_elements('hex', h, 2)
        for f in faces:
            if f in dic_quads_fault_u.keys():
                cubit.silent_cmd('group "nf" add Node in face ' + str(f))

        group1 = cubit.get_id_from_name("nf")
        nodes = []
        if not group1 == 0:
            nodes = cubit.get_group_nodes(group1)
            cubit.silent_cmd('del group ' + str(group1))
            #debug
            #print('#fault up   nodes: ',nodes,len(nodes),group1)

        #debug
        #nodes=cubit.get_connectivity('Face',f)
        #print('h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3])

        if len(nodes) > 0:
            ngnod2d = len(nodes)
            if ngnod2d == 9:
                #kangchen added
                #txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],nodes[1],nodes[2],nodes[3])
                txt = '%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                      nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
            else:
                txt = '%10i %10i %10i %10i %10i \n' % (h, nodes[0], nodes[1],
                                                       nodes[2], nodes[3])

            fault_file.write(txt)

    fault_file.close()

    #cubit.cmd('set info on')
    #cubit.cmd('set echo on')

    print('## done fault file: ', name)
    print('')
Exemplo n.º 25
0
    def abs_write(self,absname=None):
        # absorbing boundaries
        import re
        cubit.cmd('set info off')
        cubit.cmd('set echo off')
        cubit.cmd('set journal off')
        from sets import Set
        if not absname: absname=self.absname

        if self.cpml:
            if not absname: absname=self.cpmlname
            print 'Writing cpml'+absname+'.....'
            list_cpml=self.select_cpml()
            if list_cpml is False:
                print 'error writing cpml files'
                return
            else:
                abshex_cpml=open(absname,'w')
                hexcount=sum(map(len,list_cpml))
                abshex_cpml.write(('%10i\n') % (hexcount))
                for icpml,lcpml in enumerate(list_cpml):
                    for hexa in lcpml:
                        abshex_cpml.write(('%10i %10i\n') % (hexa,icpml))


        stacey_absorb=True
        if stacey_absorb:
            #
            #
            if not absname: absname=self.absname
            # loops through all block definitions
            list_hex=cubit.parse_cubit_list('hex','all')
            for block,flag in zip(self.block_bc,self.block_bc_flag):
                if block != self.topography:
                    name=cubit.get_exodus_entity_name('block',block)
                    print '  block name:',name,'id:',block
                    cknormal=True
                    abshex_local=False
                    # opens file
                    if re.search('xmin',name):
                        print 'xmin'
                        abshex_local=open(absname+'_xmin','w')
                        normal=(-1,0,0)
                    elif re.search('xmax',name):
                        print "xmax"
                        abshex_local=open(absname+'_xmax','w')
                        normal=(1,0,0)
                    elif re.search('ymin',name):
                        print "ymin"
                        abshex_local=open(absname+'_ymin','w')
                        normal=(0,-1,0)
                    elif re.search('ymax',name):
                        print "ymax"
                        abshex_local=open(absname+'_ymax','w')
                        normal=(0,1,0)
                    elif re.search('bottom',name):
                        print "bottom"
                        abshex_local=open(absname+'_bottom','w')
                        normal=(0,0,-1)
                    elif re.search('abs',name):
                        print "abs all - experimental, check the output"
                        cknormal=False
                        abshex_local=open(absname,'w')
                    else:
                        if block == 1003:
                            print 'xmin'
                            abshex_local=open(absname+'_xmin','w')
                            normal=(-1,0,0)
                        elif block == 1004:
                            print "ymin"
                            abshex_local=open(absname+'_ymin','w')
                            normal=(0,-1,0)
                        elif block == 1005:
                            print "xmax"
                            abshex_local=open(absname+'_xmax','w')
                            normal=(1,0,0)
                        elif block == 1006:
                            print "ymax"
                            abshex_local=open(absname+'_ymax','w')
                            normal=(0,1,0)
                        elif block == 1002:
                            print "bottom"
                            abshex_local=open(absname+'_bottom','w')
                            normal=(0,0,-1)
                        elif block == 1000:
                            print "custumized"
                            abshex_local=open(absname,'w')
                            cknormal=False
                            normal=None
                    #
                    #
                    if abshex_local:
                        # gets face elements
                        quads_all=cubit.get_block_faces(block)
                        dic_quads_all=dict(zip(quads_all,quads_all))
                        print '  number of faces = ',len(quads_all)
                        abshex_local.write('%10i\n' % len(quads_all))
                        #command = "group 'list_hex' add hex in face "+str(quads_all)
                        #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
                        #cubit.cmd(command)
                        #group=cubit.get_id_from_name("list_hex")
                        #list_hex=cubit.get_group_hexes(group)
                        #command = "delete group "+ str(group)
                        #cubit.cmd(command)
                        for h in list_hex:
                            faces=cubit.get_sub_elements('hex',h,2)
                            for f in faces:
                                if dic_quads_all.has_key(f):
                                    txt=self.create_facenode_string(h,f,normal=normal,cknormal=cknormal)
                                    abshex_local.write(txt)
                        abshex_local.close()
                        print 'Ok'
            cubit.cmd('set info on')
            cubit.cmd('set echo on')
def save_elements_nodes(name,quads_fault_u,quads_fault_d):
   fault_file = open(name,'w')
   txt =''
   list_hex=cubit.parse_cubit_list('hex','all')
   txt='%10i %10i\n' % (len(quads_fault_u),len(quads_fault_d))
   fault_file.write(txt)

   dic_quads_fault_u = dict(zip(quads_fault_u,quads_fault_u))
   dic_quads_fault_d = dict(zip(quads_fault_d,quads_fault_d))

   # FAULT SIDE DOWN
  # fault_file.write('upsurface')
   for h in list_hex:
       faces = cubit.get_sub_elements('hex',h,2)
       for f in faces:
           if dic_quads_fault_d.has_key(f):
	      cubit.silent_cmd('group "nf" add Node in face '+str(f))
	      group1 = cubit.get_id_from_name("nf")
	      nodes = cubit.get_group_nodes(group1)
	      cubit.silent_cmd('del group '+ str(group1))
#              nodes=cubit.get_connectivity('Face',f)
#              print 'h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3]
#              txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
#                                                nodes[1],nodes[2],nodes[3])
              ngnod2d = len(nodes)
	      if ngnod2d == 9:
#kangchen added               txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
#                                                nodes[1],nodes[2],nodes[3])
                      txt='%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
	      else:
		      txt='%10i %10i %10i %10i %10i \n' % (h,nodes[0],\
				                                                      nodes[1],nodes[2],nodes[3])




              fault_file.write(txt)

   # FAULT SIDE UP
 #  fault_file.write('downsurface')
   for h in list_hex:
       faces = cubit.get_sub_elements('hex',h,2)
       for f in faces:
           if dic_quads_fault_u.has_key(f):
       	      cubit.silent_cmd('group "nf" add Node in face '+str(f))
	      group1 = cubit.get_id_from_name("nf")
	      nodes = cubit.get_group_nodes(group1)
	      cubit.cmd('del group '+ str(group1))
	      ngnod2d=len(nodes)
	      if ngnod2d == 9:
#	      nodes=cubit.get_connectivity('Face',f)
#             print 'h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3]
#kangchen added               txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
#                                                nodes[1],nodes[2],nodes[3])
                      txt='%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
	      else:
		      txt='%10i %10i %10i %10i %10i \n' % (h,nodes[0],\
				                                                      nodes[1],nodes[2],nodes[3])



              fault_file.write(txt)

   fault_file.close()
Exemplo n.º 27
0
 def abs_write(self,absname=None):
     import re
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     if not absname: absname=self.absname
     #
     #
     list_hex=cubit.parse_cubit_list('hex','all')
     for block,flag in zip(self.block_bc,self.block_bc_flag):
         if block != self.topography:
             name=cubit.get_exodus_entity_name('block',block)
             print '  block name:',name,'id:',block
             cknormal=True
             if re.search('xmin',name):
                 print 'xmin'
                 abshex_local=open(absname+'_xmin','w')
                 normal=(-1,0,0)
             elif re.search('xmax',name):
                 print "xmax"
                 abshex_local=open(absname+'_xmax','w')
                 normal=(1,0,0)
             elif re.search('ymin',name):
                 print "ymin"
                 abshex_local=open(absname+'_ymin','w')
                 normal=(0,-1,0)
             elif re.search('ymax',name):
                 print "ymax"
                 abshex_local=open(absname+'_ymax','w')
                 normal=(0,1,0)
             elif re.search('bottom',name):
                 print "bottom"
                 abshex_local=open(absname+'_bottom','w')
                 normal=(0,0,-1)
             elif re.search('abs',name):
                 print "abs all - no implemented yet"
                 cknormal=False
                 abshex_local=open(absname,'w')
             else:
                 if block == 1003:
                     print 'xmin'
                     abshex_local=open(absname+'_xmin','w')
                     normal=(-1,0,0)
                 elif block == 1004:
                     print "ymin"
                     abshex_local=open(absname+'_ymin','w')
                     normal=(0,-1,0)
                 elif block == 1005:
                     print "xmax"
                     abshex_local=open(absname+'_xmax','w')
                     normal=(1,0,0)
                 elif block == 1006:
                     print "ymax"
                     abshex_local=open(absname+'_ymax','w')
                     normal=(0,1,0)
                 elif block == 1002:
                     print "bottom"
                     abshex_local=open(absname+'_bottom','w')
                     normal=(0,0,-1)
             #
             #
             quads_all=cubit.get_block_faces(block)
             dic_quads_all=dict(zip(quads_all,quads_all))
             print '  number of faces = ',len(quads_all)
             abshex_local.write('%10i\n' % len(quads_all))
             #command = "group 'list_hex' add hex in face "+str(quads_all)
             #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
             #cubit.cmd(command)
             #group=cubit.get_id_from_name("list_hex")
             #list_hex=cubit.get_group_hexes(group)
             #command = "delete group "+ str(group)
             #cubit.cmd(command)
             for h in list_hex:
                 faces=cubit.get_sub_elements('hex',h,2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         txt=self.create_facenode_string(h,f,normal=normal,cknormal=True)
                         abshex_local.write(txt)
             abshex_local.close()   
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
Exemplo n.º 28
0
    def abs_write(self,absname=None):
        # absorbing boundaries
        import re
        cubit.cmd('set info off')
        cubit.cmd('set echo off')
        cubit.cmd('set journal off')
        from sets import Set
        if not absname: absname=self.absname

        if self.cpml:
            if not absname: absname=self.cpmlname
            print 'Writing cpml'+absname+'.....'
            list_cpml=self.select_cpml()
            if list_cpml is False:
                print 'error writing cpml files'
                return
            else:
                abshex_cpml=open(absname,'w')
                hexcount=sum(map(len,list_cpml))
                abshex_cpml.write(('%10i\n') % (hexcount))
                for icpml,lcpml in enumerate(list_cpml):
                    for hexa in lcpml:
                        abshex_cpml.write(('%10i %10i\n') % (hexa,icpml))


        stacey_absorb=True
        if stacey_absorb:
            #
            #
            if not absname: absname=self.absname
            # loops through all block definitions
            list_hex=cubit.parse_cubit_list('hex','all')
            for block,flag in zip(self.block_bc,self.block_bc_flag):
                if block != self.topography:
                    name=cubit.get_exodus_entity_name('block',block)
                    print '  block name:',name,'id:',block
                    cknormal=True
                    abshex_local=False
                    # opens file
                    if re.search('xmin',name):
                        print 'xmin'
                        abshex_local=open(absname+'_xmin','w')
                        normal=(-1,0,0)
                    elif re.search('xmax',name):
                        print "xmax"
                        abshex_local=open(absname+'_xmax','w')
                        normal=(1,0,0)
                    elif re.search('ymin',name):
                        print "ymin"
                        abshex_local=open(absname+'_ymin','w')
                        normal=(0,-1,0)
                    elif re.search('ymax',name):
                        print "ymax"
                        abshex_local=open(absname+'_ymax','w')
                        normal=(0,1,0)
                    elif re.search('bottom',name):
                        print "bottom"
                        abshex_local=open(absname+'_bottom','w')
                        normal=(0,0,-1)
                    elif re.search('abs',name):
                        print "abs all - experimental, check the output"
                        cknormal=False
                        abshex_local=open(absname,'w')
                    else:
                        if block == 1003:
                            print 'xmin'
                            abshex_local=open(absname+'_xmin','w')
                            normal=(-1,0,0)
                        elif block == 1004:
                            print "ymin"
                            abshex_local=open(absname+'_ymin','w')
                            normal=(0,-1,0)
                        elif block == 1005:
                            print "xmax"
                            abshex_local=open(absname+'_xmax','w')
                            normal=(1,0,0)
                        elif block == 1006:
                            print "ymax"
                            abshex_local=open(absname+'_ymax','w')
                            normal=(0,1,0)
                        elif block == 1002:
                            print "bottom"
                            abshex_local=open(absname+'_bottom','w')
                            normal=(0,0,-1)
                        elif block == 1000:
                            print "custumized"
                            abshex_local=open(absname,'w')
                            cknormal=False
                            normal=None
                    #
                    #
                    if abshex_local:
                        # gets face elements
                        quads_all=cubit.get_block_faces(block)
                        dic_quads_all=dict(zip(quads_all,quads_all))
                        print '  number of faces = ',len(quads_all)
                        abshex_local.write('%10i\n' % len(quads_all))
                        #command = "group 'list_hex' add hex in face "+str(quads_all)
                        #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
                        #cubit.cmd(command)
                        #group=cubit.get_id_from_name("list_hex")
                        #list_hex=cubit.get_group_hexes(group)
                        #command = "delete group "+ str(group)
                        #cubit.cmd(command)
                        for h in list_hex:
                            faces=cubit.get_sub_elements('hex',h,2)
                            for f in faces:
                                if dic_quads_all.has_key(f):
                                    txt=self.create_facenode_string(h,f,normal=normal,cknormal=cknormal)
                                    abshex_local.write(txt)
                        abshex_local.close()
                        print 'Ok'
            cubit.cmd('set info on')
            cubit.cmd('set echo on')
 def abs_write(self,absname=None):
     # absorbing boundaries
     import re
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     if not absname: absname=self.absname
     #
     # loops through all block definitions
     list_hex=cubit.parse_cubit_list('hex','all')
     for block,flag in zip(self.block_bc,self.block_bc_flag):
         if block != self.topography:
             name=cubit.get_exodus_entity_name('block',block)
             print name,block
             absflag=False
             if re.search('xmin',name):
                 filename=absname+'_xmin'
                 normal=(-1,0,0)
             elif re.search('xmax',name):
                 filename=absname+'_xmax'
                 normal=(1,0,0)
             elif re.search('ymin',name):
                 filename=absname+'_ymin'
                 normal=(0,-1,0)
             elif re.search('ymax',name):
                 filename=absname+'_ymax'
                 normal=(0,1,0)
             elif re.search('bottom',name):
                 filename=absname+'_bottom'
                 normal=(0,0,-1)
             elif re.search('abs',name):
                 print "  ...face_abs - not used so far..."
                 continue
             else:
                 continue
             # opens file
             print 'Writing '+filename+'.....'
             abshex_local=open(filename,'w')
             # gets face elements
             quads_all=cubit.get_block_faces(block)
             dic_quads_all=dict(zip(quads_all,quads_all))
             print '  number of faces = ',len(quads_all)
             abshex_local.write('%10i\n' % len(quads_all))
             #command = "group 'list_hex' add hex in face "+str(quads_all)
             #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
             #cubit.cmd(command)
             #group=cubit.get_id_from_name("list_hex")
             #list_hex=cubit.get_group_hexes(group)
             #command = "delete group "+ str(group)
             #cubit.cmd(command)
             for h in list_hex:
                 faces=cubit.get_sub_elements('hex',h,2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         nodes=cubit.get_connectivity('Face',f)
                         if not absflag:
                             # checks with specified normal
                             nodes_ok=self.normal_check(nodes,normal)
                             txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
                                          nodes_ok[1],nodes_ok[2],nodes_ok[3])
                         else:
                             txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                          nodes[1],nodes[2],nodes[3])
                         abshex_local.write(txt)
             # closes file
             abshex_local.close()
     print 'Ok'
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
Exemplo n.º 30
0
 def free_write(self, freename):  #freename = None):
     """ Write free surface on file : freename """
     cubit.cmd(
         'set info off')  # Turn off return messages from Cubit commands
     cubit.cmd('set echo off')  # Turn off echo of Cubit commands
     cubit.cmd('set journal off')  # Do not save journal file
     from sets import Set
     # if not freename: freename = self.freename
     freeedge = open(freename, 'w')
     print 'Writing ' + freename + '.....'
     if self.topo_mesh:
         for block, flag in zip(self.block_bc,
                                self.block_bc_flag):  # For each 1D block
             if block == self.topography:  # If the block correspond to topography
                 edges_all = Set(cubit.get_block_edges(
                     block))  # Import all topo edges id as a Set
         toWritetoFile = []  #[""]*(len(edges_all)+1)
         toWritetoFile.append(
             '%10i\n' % len(edges_all)
         )  # Print the number of edges on the free surface
         for block, flag in zip(self.block_mat,
                                self.block_flag):  # For each 2D block
             print block, flag
             quads = cubit.get_block_faces(block)  # Import quads id
             for quad in quads:  # For each quad
                 edges = Set(
                     cubit.get_sub_elements("face", quad, 1)
                 )  # Get the lower dimension entities associated with a higher dimension entities.
                 # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
                 intersection = edges & edges_all  # Contains the edges of the considered quad that is on the free surface
                 if len(intersection
                        ) != 0:  # If this quad touch the free surface
                     #print "  ",quad," -> this quad touch the free surface!"
                     nodes = cubit.get_connectivity(
                         'face',
                         quad)  # Import the nodes describing the quad
                     #print "    it is described by nodes:",nodes," and edges :",edges
                     #print "      edges:",intersection," is/are on the free surface"
                     nodes = self.jac_check(
                         list(nodes))  # Check the jacobian of the quad
                     for e in intersection:  # For each edge on the free surface
                         node_edge = cubit.get_connectivity(
                             'edge',
                             e)  # Import the nodes describing the edge
                         #print "      edge",e,"is composed of nodes",node_edge
                         nodes_ok = []
                         for i in nodes:  # Loop on the nodes of the quad
                             if i in node_edge:  # If this node is belonging to the free surface
                                 nodes_ok.append(i)  # Put it in nodes_ok
                         #print "    nodes:",nodes_ok,"belong to free surface"
                         txt = '%10i %10i %10i %10i\n' % (
                             quad, 2, nodes_ok[0], nodes_ok[1])
                         toWritetoFile.append(txt)
                         # Write the id of the quad, 2 (number of nodes describing a free surface elements), and the nodes
         freeedge.writelines(toWritetoFile)
     else:
         freeedge.write(
             '0'
         )  # Even without any free surface specfem2d need a file with a 0 in first line
     freeedge.close()
     print 'Ok'
     cubit.cmd('set info on')  # Turn on return messages from Cubit commands
     cubit.cmd('set echo on')  # Turn on echo of Cubit commands
Exemplo n.º 31
0
 def forcing_write(self, forcname):
     """ Write forcing surfaces on file : forcname """
     cubit.cmd(
         'set info off')  # Turn off return messages from Cubit commands
     cubit.cmd('set echo off')  # Turn off echo of Cubit commands
     cubit.cmd('set journal off')  # Do not save journal file
     from sets import Set
     forceedge = open(forcname, 'w')
     print 'Writing ' + forcname + '.....'
     edges_forc = [
         Set()
     ] * self.nforc  # edges_forc[0] will be a Set containing the nodes describing the forcing boundary
     # (index 0 : bottom, index 1 : right, index 2 : top, index 3 : left)
     nedges_all = 0  # To count the total number of forcing edges
     for block, flag in zip(self.block_bc,
                            self.block_bc_flag):  # For each 1D block
         for iforc in range(
                 0, self.nforc
         ):  # iforc = 0,1,2,3 : for each forcing boundaries
             if block == self.forcing_boun[
                     iforc]:  # If the block considered correspond to the boundary
                 edges_forc[iforc] = Set(cubit.get_block_edges(
                     block))  # Store each edge on edges_forc
                 nedges_all = nedges_all + len(
                     edges_forc[iforc]
                 )  # add the number of edges to nedges_all
     toWritetoFile = [""] * (nedges_all + 1)
     toWritetoFile[
         0] = '%10i\n' % nedges_all  # Write the total number of forcing edges to the first line of file
     #forceedge.write('%10i\n' % nedges_all) # Write the total number of forcing edges to the first line of file
     print 'Number of edges', nedges_all
     #id_element = 0
     indexFile = 1
     for block, flag in zip(self.block_mat,
                            self.block_flag):  # For each 2D block
         quads = cubit.get_block_faces(block)  # Import quads id
         for quad in quads:  # For each quad
             #id_element = id_element+1 # id of this quad
             edges = Set(
                 cubit.get_sub_elements("face", quad, 1)
             )  # Get the lower dimension entities associated with a higher dimension entities.
             # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set
             for iforc in range(
                     0, self.nforc
             ):  # iforc = 0,1,2,3 : for each forcing boundaries
                 intersection = edges & edges_forc[
                     iforc]  # Contains the edges of the considered quad that is on the forcing boundary considered
                 if len(
                         intersection
                 ) != 0:  # If this quad touch the forcing boundary considered
                     nodes = cubit.get_connectivity(
                         'face',
                         quad)  # Import the nodes describing the quad
                     nodes = self.jac_check(
                         list(nodes))  # Check the jacobian of the quad
                     for e in intersection:  # For each edge on the forcing boundary considered
                         node_edge = cubit.get_connectivity(
                             'edge',
                             e)  # Import the nodes describing the edge
                         nodes_ok = []
                         for i in nodes:  # Loop on the nodes of the quad
                             if i in node_edge:  # If this node is belonging to forcing surface
                                 nodes_ok.append(i)  # add it to nodes_ok
                         # forcname contains 1/ element number, 2/ number of nodes that form the acoustic forcing edge
                         # (which currently must always be equal to two, see comment below),
                         # 3/ first node on the acforcing surface, 4/ second node on the acforcing surface
                         # 5/ 1 = IBOTTOME, 2 = IRIGHT, 3 = ITOP, 4 = ILEFT
                         #txt = '%10i %10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1],iforc+1)
                         txt = '%10i %10i %10i %10i %10i\n' % (
                             quad, 2, nodes_ok[0], nodes_ok[1], iforc + 1)
                         # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes and the type of boundary
                         #print indexFile
                         toWritetoFile[indexFile] = txt
                         indexFile = indexFile + 1
                         #forceedge.write(txt)
     forceedge.writelines(toWritetoFile)
     forceedge.close()
     print 'Ok'
     cubit.cmd('set info on')  # Turn on return messages from Cubit commands
     cubit.cmd('set echo on')  # Turn on echo of Cubit commands
 def abs_write(self, absname=None):
     # absorbing boundaries
     import re
     cubit.cmd('set info off')
     cubit.cmd('set echo off')
     cubit.cmd('set journal off')
     from sets import Set
     if not absname: absname = self.absname
     #
     # loops through all block definitions
     list_hex = cubit.parse_cubit_list('hex', 'all')
     for block, flag in zip(self.block_bc, self.block_bc_flag):
         if block != self.topography:
             name = cubit.get_exodus_entity_name('block', block)
             print name, block
             absflag = False
             if re.search('xmin', name):
                 filename = absname + '_xmin'
                 normal = (-1, 0, 0)
             elif re.search('xmax', name):
                 filename = absname + '_xmax'
                 normal = (1, 0, 0)
             elif re.search('ymin', name):
                 filename = absname + '_ymin'
                 normal = (0, -1, 0)
             elif re.search('ymax', name):
                 filename = absname + '_ymax'
                 normal = (0, 1, 0)
             elif re.search('bottom', name):
                 filename = absname + '_bottom'
                 normal = (0, 0, -1)
             elif re.search('abs', name):
                 print "  ...face_abs - not used so far..."
                 continue
             else:
                 continue
             # opens file
             print 'Writing ' + filename + '.....'
             abshex_local = open(filename, 'w')
             # gets face elements
             quads_all = cubit.get_block_faces(block)
             dic_quads_all = dict(zip(quads_all, quads_all))
             print '  number of faces = ', len(quads_all)
             abshex_local.write('%10i\n' % len(quads_all))
             #command = "group 'list_hex' add hex in face "+str(quads_all)
             #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
             #cubit.cmd(command)
             #group=cubit.get_id_from_name("list_hex")
             #list_hex=cubit.get_group_hexes(group)
             #command = "delete group "+ str(group)
             #cubit.cmd(command)
             for h in list_hex:
                 faces = cubit.get_sub_elements('hex', h, 2)
                 for f in faces:
                     if dic_quads_all.has_key(f):
                         nodes = cubit.get_connectivity('Face', f)
                         if not absflag:
                             # checks with specified normal
                             nodes_ok = self.normal_check(nodes, normal)
                             txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
                                          nodes_ok[1],nodes_ok[2],nodes_ok[3])
                         else:
                             txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                          nodes[1],nodes[2],nodes[3])
                         abshex_local.write(txt)
             # closes file
             abshex_local.close()
     print 'Ok'
     cubit.cmd('set info on')
     cubit.cmd('set echo on')
Exemplo n.º 33
0
# TO DO : stop python properly in case fault nodes at both sides
#         do not match.
if len(quads_fault_u) != len(quads_fault_d):
   stop
# Writting number of elements at both sides to make 
# double sure everything is going fine .
txt='%10i %10i\n' % (len(quads_fault_u),len(quads_fault_d))
fault_file.write(txt)

dic_quads_fault_u = dict(zip(quads_fault_u,quads_fault_u)) 
dic_quads_fault_d = dict(zip(quads_fault_d,quads_fault_d)) 


# FAULT SIDE DOWN
for h in list_hex: 
    faces = cubit.get_sub_elements('hex',h,2)  
    for f in faces:
        if dic_quads_fault_d.has_key(f): 
           nodes=cubit.get_connectivity('Face',f)
#           print 'h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3]
           txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                             nodes[1],nodes[2],nodes[3])
           fault_file.write(txt)

# FAULT SIDE UP
for h in list_hex: 
    faces = cubit.get_sub_elements('hex',h,2)  
    for f in faces:
        if dic_quads_fault_u.has_key(f): 
           nodes=cubit.get_connectivity('Face',f)
#           print 'h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3]
Exemplo n.º 34
0
def save_elements_nodes(name, quads_fault_u, quads_fault_d):
    fault_file = open(name, 'w')
    txt = ''
    list_hex = cubit.parse_cubit_list('hex', 'all')
    txt = '%10i %10i\n' % (len(quads_fault_u), len(quads_fault_d))
    fault_file.write(txt)

    dic_quads_fault_u = dict(zip(quads_fault_u, quads_fault_u))
    dic_quads_fault_d = dict(zip(quads_fault_d, quads_fault_d))

    # FAULT SIDE DOWN
    # fault_file.write('upsurface')
    for h in list_hex:
        faces = cubit.get_sub_elements('hex', h, 2)
        for f in faces:
            if dic_quads_fault_d.has_key(f):
                cubit.silent_cmd('group "nf" add Node in face ' + str(f))
                group1 = cubit.get_id_from_name("nf")
                nodes = cubit.get_group_nodes(group1)
                cubit.silent_cmd('del group ' + str(group1))
                #              nodes=cubit.get_connectivity('Face',f)
                #              print 'h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3]
                #              txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                #                                                nodes[1],nodes[2],nodes[3])
                ngnod2d = len(nodes)
                if ngnod2d == 9:
                    #kangchen added               txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                    #                                                nodes[1],nodes[2],nodes[3])
                    txt='%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                              nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
                else:
                    txt='%10i %10i %10i %10i %10i \n' % (h,nodes[0],\
                                                                      nodes[1],nodes[2],nodes[3])

                fault_file.write(txt)

    # FAULT SIDE UP

#  fault_file.write('downsurface')
    for h in list_hex:
        faces = cubit.get_sub_elements('hex', h, 2)
        for f in faces:
            if dic_quads_fault_u.has_key(f):
                cubit.silent_cmd('group "nf" add Node in face ' + str(f))
                group1 = cubit.get_id_from_name("nf")
                nodes = cubit.get_group_nodes(group1)
                cubit.cmd('del group ' + str(group1))
                ngnod2d = len(nodes)
                if ngnod2d == 9:
                    #	      nodes=cubit.get_connectivity('Face',f)
                    #             print 'h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3]
                    #kangchen added               txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                    #                                                nodes[1],nodes[2],nodes[3])
                    txt='%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                              nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
                else:
                    txt='%10i %10i %10i %10i %10i \n' % (h,nodes[0],\
                                                                      nodes[1],nodes[2],nodes[3])

                fault_file.write(txt)

    fault_file.close()