Example #1
0
 def pmls_write(self,pml_name):
     """ Write pml elements on file : mat_name """ 
     cubit.cmd('set info off') # Turn off return messages from Cubit commands
     cubit.cmd('set echo off') # Turn off echo of Cubit commands
     pml_file = open(pml_name,'w')
     print 'Writing '+pml_name+'.....'
     npml_elements = 0
     id_element = 0 # Global id
     faces_all = [0]*6
     for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block
         for ipml in range(0, 6): # iabs = 0,1,2,3,4,5 : for each pml layer (x_acoust, z_acoust, xz_acoust,x_elast, z_elast, xz_elast)
            if block == self.pml_boun[ipml]: # If the block considered correspond to the pml
                 faces_all[ipml]=cubit.get_block_faces(block) # Import all pml faces id as a Set
                 npml_elements=npml_elements+len(faces_all[ipml])
     pml_file.write('%10i\n' % npml_elements) # Print the number of faces on the pmls
     print 'Number of elements in all PMLs :',npml_elements
     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 # global id of this quad
             for ipml in range(0, 6): # iabs = 0,1,2,3,4,5 : for each pml layer (x_acoust, z_acoust, xz_acoust,x_elast, z_elast, xz_elast)
                 if type(faces_all[ipml]) is not int: # ~ if there are elements in that pml
                     if quad in faces_all[ipml]: # If this quad is belong to that pml
                       #  nodes = cubit.get_connectivity('face',quad) # Import the nodes describing the quad
                       #  nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad
                         pml_file.write(('%10i %10i\n') % (id_element,ipml%3+1)) # Write its id in the file next to its type
     # ipml%3+1 = 1 -> element belongs to a X CPML layer only (either in Xmin or in Xmax)
     # ipml%3+1 = 2 -> element belongs to a Z CPML layer only (either in Zmin or in Zmax)
     # ipml%3+1 = 3 -> element belongs to both a X and a Y CPML layer (i.e., to a CPML corner)
     pml_file.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
Example #2
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')
Example #3
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')
 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
Example #7
0
 def material_write(self,mat_name):
     """ Write quads material on file : mat_name """
     mat = open(mat_name,'w')
     print 'Writing '+mat_name+'.....'
     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
                 mat.write(('%10i\n') % flag) # Write its id in the file
     mat.close()
     print 'Ok'
 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
Example #9
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 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]
Example #11
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]
Example #12
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
Example #13
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
Example #14
0
 def material_write(self,mat_name):
     """ Write quads material on file : mat_name """
     mat = open(mat_name,'w')
     print 'Writing '+mat_name+'.....'
     num_elems = cubit.get_quad_count() # Store the number of elements
     toWritetoFile = [""]*num_elems
     print 'block_mat:',self.block_mat
     print 'block_flag:',self.block_flag
     for block,flag in zip(self.block_mat,self.block_flag): # for each 2D block
         print 'mat: ',block,' flag: ',flag
         quads = cubit.get_block_faces(block) # Import quads id
         for quad in quads: # For each quad
             toWritetoFile[quad-1] = ('%10i\n') % flag
             #mat.write(('%10i\n') % flag) # Write its id in the file
     mat.writelines(toWritetoFile)
     mat.close()
     print 'Ok'
Example #15
0
 def material_write(self, mat_name):
     """ Write quads material on file : mat_name """
     mat = open(mat_name, 'w')
     print 'Writing ' + mat_name + '.....'
     num_elems = cubit.get_quad_count()  # Store the number of elements
     toWritetoFile = [""] * num_elems
     print 'block_mat:', self.block_mat
     print 'block_flag:', self.block_flag
     for block, flag in zip(self.block_mat,
                            self.block_flag):  # for each 2D block
         print 'mat: ', block, ' flag: ', flag
         quads = cubit.get_block_faces(block)  # Import quads id
         for quad in quads:  # For each quad
             toWritetoFile[quad - 1] = ('%10i\n') % flag
             #mat.write(('%10i\n') % flag) # Write its id in the file
     mat.writelines(toWritetoFile)
     mat.close()
     print 'Ok'
Example #16
0
 def mesh_write(self,mesh_name):
     """ Write mesh (quads ids with their corresponding nodes ids) on file : mesh_name """ 
     meshfile = open(mesh_name,'w')
     print 'Writing '+mesh_name+'.....'
     num_elems = cubit.get_quad_count() # Store the number of elements
     meshfile.write(str(num_elems)+'\n') # Write it on first line
     num_write = 0
     for block,flag in zip(self.block_mat,self.block_flag): # for each 2D block
         quads = cubit.get_block_faces(block) # Import quads ids
         for inum,quad in enumerate(quads): # For each of these quads
             nodes = cubit.get_expanded_connectivity('face',quad) # Get all the nodes in quad
             nodes = self.jac_check(nodes) # Check the jacobian
             txt = ('%10i %10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes 
             meshfile.write(txt) # Write a line to mesh file
         num_write = num_write+inum+1
         print 'block', block, 'number of ',self.face,' : ', inum+1
     meshfile.close()
     print 'Ok num elements/write=',str(num_elems), str(num_write)
 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'
Example #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
Example #19
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"
Example #20
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
Example #23
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")
Example #24
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')
Example #25
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
Example #26
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')
Example #27
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')
Example #29
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")
Example #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
 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')