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 #2
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)
Example #3
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 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