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
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 axis_write(self, axis_name): """ Write axis on file """ cubit.cmd( 'set info off') # Turn off return messages from Cubit commands cubit.cmd('set echo off') # Turn off echo of Cubit commands cubit.cmd('set journal off') # Do not save journal file from sets import Set axisedge = open(axis_name, 'w') print 'Writing ' + axis_name + '.....' for block, flag in zip(self.block_bc, self.block_bc_flag): # For each 1D block if block == self.axisId: # If the block correspond to the axis edges_all = Set(cubit.get_block_edges( block)) # Import all axis edges id as a Set toWritetoFile = [""] * (len(edges_all) + 1) toWritetoFile[0] = '%10i\n' % len( edges_all) # Write the number of edges on the axis #axisedge.write('%10i\n' % len(edges_all)) # Write the number of edges on the axis print 'Number of edges on the axis :', len(edges_all) #id_element = 0 indexFile = 1 for block, flag in zip(self.block_mat, self.block_flag): # For each 2D block quads = cubit.get_block_faces(block) # Import quads id for quad in quads: # For each quad #id_element = id_element+1 # id of this quad edges = Set( cubit.get_sub_elements("face", quad, 1) ) # Get the lower dimension entities associated with a higher dimension entities. # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set intersection = edges & edges_all # Contains the edges of the considered quad that are on the axis if len(intersection) != 0: # If this quad touch the axis nodes = cubit.get_connectivity( 'face', quad) # Import the nodes describing the quad nodes = self.jac_check( list(nodes)) # Check the jacobian of the quad for e in intersection: # For each edge on the axis node_edge = cubit.get_connectivity( 'edge', e) # Import the nodes describing the edge nodes_ok = [] for i in nodes: # Loop on the nodes of the quad if i in node_edge: # If this node is belonging to the axis nodes_ok.append(i) # Add it to nodes_ok txt = '%10i %10i %10i %10i\n' % (quad, 2, nodes_ok[0], nodes_ok[1]) #txt = '%10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1]) # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes toWritetoFile[indexFile] = txt indexFile = indexFile + 1 #axisedge.write(txt) axisedge.writelines(toWritetoFile) axisedge.close() print 'Ok' cubit.cmd('set info on') # Turn on return messages from Cubit commands cubit.cmd('set echo on') # Turn on echo of Cubit commands
def 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
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): #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 axis_write(self,axis_name): """ Write axis on file """ cubit.cmd('set info off') # Turn off return messages from Cubit commands cubit.cmd('set echo off') # Turn off echo of Cubit commands cubit.cmd('set journal off') # Do not save journal file from sets import Set axisedge = open(axis_name,'w') print 'Writing '+axis_name+'.....' for block,flag in zip(self.block_bc,self.block_bc_flag): # For each 1D block if block == self.axisId: # If the block correspond to the axis edges_all = Set(cubit.get_block_edges(block)) # Import all axis edges id as a Set toWritetoFile = [""]*(len(edges_all)+1) toWritetoFile[0] = '%10i\n' % len(edges_all) # Write the number of edges on the axis #axisedge.write('%10i\n' % len(edges_all)) # Write the number of edges on the axis print 'Number of edges on the axis :',len(edges_all) #id_element = 0 indexFile = 1 for block,flag in zip(self.block_mat,self.block_flag): # For each 2D block quads = cubit.get_block_faces(block) # Import quads id for quad in quads: # For each quad #id_element = id_element+1 # id of this quad edges = Set(cubit.get_sub_elements("face", quad, 1)) # Get the lower dimension entities associated with a higher dimension entities. # Here it gets the 1D edges associates with the face of id "quad". Store it as a Set intersection = edges & edges_all # Contains the edges of the considered quad that are on the axis if len(intersection) != 0: # If this quad touch the axis nodes = cubit.get_connectivity('face',quad) # Import the nodes describing the quad nodes = self.jac_check(list(nodes)) # Check the jacobian of the quad for e in intersection: # For each edge on the axis node_edge = cubit.get_connectivity('edge',e) # Import the nodes describing the edge nodes_ok = [] for i in nodes: # Loop on the nodes of the quad if i in node_edge: # If this node is belonging to the axis nodes_ok.append(i) # Add it to nodes_ok txt = '%10i %10i %10i %10i\n' % (quad,2,nodes_ok[0],nodes_ok[1]) #txt = '%10i %10i %10i %10i\n' % (id_element,2,nodes_ok[0],nodes_ok[1]) # Write the id of the quad, 2 (number of nodes describing a free surface elements), the nodes toWritetoFile[indexFile] = txt indexFile = indexFile + 1 #axisedge.write(txt) axisedge.writelines(toWritetoFile) axisedge.close() print 'Ok' cubit.cmd('set info on') # Turn on return messages from Cubit commands cubit.cmd('set echo on') # Turn on echo of Cubit commands
def 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
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 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