Exemple #1
0
def curve2poly(line):
    curve=int(line)
    cubit.cmd('curve '+str(curve)+' size auto factor 1')
    cubit.cmd('mesh curve '+str(curve))
    n=cubit.get_curve_nodes(curve)
    orientnode=[]
    vertex_list = cubit.get_relatives("curve", curve, "vertex")
    if len(vertex_list) != 0:
        startnode=cubit.get_vertex_node(vertex_list[0])
        cubit.cmd('del group pgon')
        cubit.cmd("group 'pgon' add edge in node "+str(startnode))
        group1 = cubit.get_id_from_name("pgon")
        edges = list(cubit.get_group_edges(group1))
        edgestart=edges[0]
    else:
        startnode=n[0]
        cubit.cmd('del group pgon')
        cubit.cmd("group 'pgon' add edge in node "+str(startnode))
        group1 = cubit.get_id_from_name("pgon")
        edges = list(cubit.get_group_edges(group1))
        edgestart=edges[0]
    begin=startnode
    orientnode.append(begin)
    node_id_list = list(cubit.get_connectivity("edge", edgestart))
    node_id_list.remove(startnode)
    startnode=node_id_list[0]
    orientnode.append(startnode)
    stopflag=False
    while startnode != begin and not stopflag:
        cubit.cmd('del group pgon')
        cubit.cmd("group 'pgon' add edge in node "+str(startnode))
        group1 = cubit.get_id_from_name("pgon")
        edges = list(cubit.get_group_edges(group1))
        if len(edges) != 1:
            edges.remove(edgestart)
            edgestart=edges[0]
            node_id_list = list(cubit.get_connectivity("edge", edgestart))
            node_id_list.remove(startnode)
            orientnode.append(node_id_list[0])
            startnode=node_id_list[0]
        else:
            stopflag=True
    vx=[]
    vy=[]
    for n in orientnode:
        v=cubit.get_nodal_coordinates(n)
        vx.append(v[0])
        vy.append(v[1])    
    return vx,vy,orientnode
def prepare_equivalence_new(name_group='lateral'):
    length={}
    cmd="group 'tmpn' add edge in face in group "+name_group
    cubit.cmd(cmd)
    ge=cubit.get_id_from_name("tmpn")
    e1=cubit.get_group_edges(ge)
    lengthmin=1e9
    for e in e1:
        lengthmin=min(lengthmin,cubit.get_mesh_edge_length(e))
        length[e]=lengthmin*.5
    cubit.cmd('delete group '+str(ge))                
    minvalue=min(length.values())
    maxvalue=max(length.values())
    #
    print 'min lentgh: ',minvalue,'max lentgh: ',maxvalue
    nbin= int((maxvalue/minvalue)/2.)+1
    factor=(maxvalue-minvalue)/nbin
    dic_new={}
    for k in length.keys():
        dic_new[k]=int((length[k]-minvalue)/factor)
    inv_length=invert_dict(dic_new)
    print inv_length.keys(),factor,minvalue
    ks=inv_length.keys()
    ks.sort()
    for k in range(0,len(inv_length.keys())-1):
        inv_length[ks[k]]=inv_length[ks[k]]+inv_length[ks[k+1]]
    return factor,minvalue,inv_length
def prepare_equivalence(nodes1,nodes2):
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    length={}
    for ns in zip(nodes1,nodes2):
        cmd='group "tmpn" add edge in node '+' '.join(str(n) for n in ns )
        cubit.cmd(cmd)
        ge=cubit.get_id_from_name("tmpn")
        e1=cubit.get_group_edges(ge)
        lengthmin=1e9
        for e in e1:
            lengthmin=min(lengthmin,cubit.get_mesh_edge_length(e))
        length[ns]=lengthmin*.5
        cubit.cmd('delete group '+str(ge))
    minvalue=min(length.values())
    maxvalue=max(length.values())
    print 'min lentgh: ',minvalue,'max lentgh: ',maxvalue
    nbin= int((maxvalue/minvalue)/2.)+1
    factor=(maxvalue-minvalue)/nbin
    dic_new={}
    for k in length.keys():
        dic_new[k]=int((length[k]-minvalue)/factor)
    inv_length=invert_dict(dic_new)
    print inv_length.keys(),factor,minvalue
    ks=inv_length.keys()
    ks.sort()
    for k in range(0,len(inv_length.keys())-1):
        inv_length[ks[k]]=inv_length[ks[k]]+inv_length[ks[k+1]]
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
    return factor,minvalue,inv_length
Exemple #4
0
def prepare_equivalence(nodes1, nodes2):
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    length = {}
    for ns in zip(nodes1, nodes2):
        cmd = 'group "tmpn" add edge in node ' + ' '.join(str(n) for n in ns)
        cubit.cmd(cmd)
        ge = cubit.get_id_from_name("tmpn")
        e1 = cubit.get_group_edges(ge)
        lengthmin = 1e9
        for e in e1:
            lengthmin = min(lengthmin, cubit.get_mesh_edge_length(e))
        length[ns] = lengthmin * .5
        cubit.cmd('delete group ' + str(ge))
    minvalue = min(length.values())
    maxvalue = max(length.values())
    print 'min lentgh: ', minvalue, 'max lentgh: ', maxvalue
    nbin = int((maxvalue / minvalue) / 2.) + 1
    factor = (maxvalue - minvalue) / nbin
    dic_new = {}
    for k in length.keys():
        dic_new[k] = int((length[k] - minvalue) / factor)
    inv_length = invert_dict(dic_new)
    print inv_length.keys(), factor, minvalue
    ks = inv_length.keys()
    ks.sort()
    for k in range(0, len(inv_length.keys()) - 1):
        inv_length[ks[k]] = inv_length[ks[k]] + inv_length[ks[k + 1]]
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
    return factor, minvalue, inv_length
Exemple #5
0
def prepare_equivalence_4(nodes1, nodes2, nodes3, nodes4):
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    length = {}
    nodes = [nodes1, nodes2, nodes3, nodes4]
    check = map(len, nodes)
    checked_nodes = []
    for ind, iflag in enumerate(check):
        if iflag:
            checked_nodes = checked_nodes + nodes[ind]

    cmd = 'group "tmpn" add edge in node ' + ' '.join(
        str(n) for n in checked_nodes)
    cubit.cmd(cmd)
    ge = cubit.get_id_from_name("tmpn")
    e1 = cubit.get_group_edges(ge)
    lengthmin = 1e9
    for e in e1:
        lengthmin = min(lengthmin, cubit.get_mesh_edge_length(e))
        length[e] = lengthmin * .5
    cubit.cmd('delete group ' + str(ge))
    try:
        minvalue = min(length.values())
        maxvalue = max(length.values())
    except:
        try:
            print nodes
            print 'edges ', e1
        except:
            pass
        minvalue = 10.
        maxvalue = 2000.
    print 'min lentgh: ', minvalue, 'max lentgh: ', maxvalue
    nbin = int((maxvalue / minvalue) / 2.) + 1
    factor = (maxvalue - minvalue) / nbin
    dic_new = {}
    for k in length.keys():
        dic_new[k] = int((length[k] - minvalue) / factor)
    inv_length = invert_dict(dic_new)
    print inv_length.keys(), factor, minvalue
    ks = inv_length.keys()
    ks.sort()
    for k in range(0, len(inv_length.keys()) - 1):
        inv_length[ks[k]] = inv_length[ks[k]] + inv_length[ks[k + 1]]
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
    return factor, minvalue, inv_length
def prepare_equivalence_4(nodes1,nodes2,nodes3,nodes4):
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    length={}
    nodes=[nodes1,nodes2,nodes3,nodes4]
    check=map(len,nodes)
    checked_nodes=[]
    for ind,iflag in enumerate(check):
        if iflag:
            checked_nodes=checked_nodes+nodes[ind]
    
    cmd='group "tmpn" add edge in node '+' '.join(str(n) for n in checked_nodes )
    cubit.cmd(cmd)
    ge=cubit.get_id_from_name("tmpn")
    e1=cubit.get_group_edges(ge)
    lengthmin=1e9
    for e in e1:
        lengthmin=min(lengthmin,cubit.get_mesh_edge_length(e))
        length[e]=lengthmin*.5
    cubit.cmd('delete group '+str(ge))
    try:
        minvalue=min(length.values())
        maxvalue=max(length.values())
    except:
        try:
            print nodes
            print 'edges ', e1
        except:
            pass
        minvalue=10.
        maxvalue=2000.
    print 'min lentgh: ',minvalue,'max lentgh: ',maxvalue
    nbin= int((maxvalue/minvalue)/2.)+1
    factor=(maxvalue-minvalue)/nbin
    dic_new={}
    for k in length.keys():
        dic_new[k]=int((length[k]-minvalue)/factor)
    inv_length=invert_dict(dic_new)
    print inv_length.keys(),factor,minvalue
    ks=inv_length.keys()
    ks.sort()
    for k in range(0,len(inv_length.keys())-1):
        inv_length[ks[k]]=inv_length[ks[k]]+inv_length[ks[k+1]]
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
    return factor,minvalue,inv_length
 def edge_min_length(self,surface):
     """
     edge_min,length=edge_min_length(surface)
         given the cubit id of a surface, it return the edge with minimun length
     """
     from math import sqrt
     self.dmin=99999
     edge_store=0
     command = "group 'list_edge' add edge in surf "+str(surface)
     command = command.replace("["," ").replace("]"," ")
     cubit.cmd(command)
     group=cubit.get_id_from_name("list_edge")
     edges=cubit.get_group_edges(group)
     command = "delete group "+ str(group)
     cubit.cmd(command)
     for edge in edges:
         d=self.edge_length(edge)
         if d<dmin:
             self.dmin=d
             edge_store=edge
     self.edgemin=edge_store
     return self.edgemin,self.dmin
 def edge_min_length(self,surface):
     """
     edge_min,length=edge_min_length(surface)
         given the cubit id of a surface, it return the edge with minimun length
     """
     from math import sqrt
     self.dmin=99999
     edge_store=0
     command = "group 'list_edge' add edge in surf "+str(surface)
     command = command.replace("["," ").replace("]"," ")
     cubit.cmd(command)
     group=cubit.get_id_from_name("list_edge")
     edges=cubit.get_group_edges(group)
     command = "delete group "+ str(group)
     cubit.cmd(command)
     for edge in edges:
         d=self.edge_length(edge)
         if d<dmin:
             self.dmin=d
             edge_store=edge
     self.edgemin=edge_store
     return self.edgemin,self.dmin