Beispiel #1
0
 def pick_hex(self, list_hex=None, volume=None):
     if self.cubit_skew > 0:
         command = "del group skew_top"
         cubit.cmd(command)
         command = "group 'skew_top' add quality volume all skew low " + str(self.cubit_skew)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("skew_top")
         self.list_hex = cubit.get_group_hexes(group)
     elif list_hex is not None:
         self.list_hex = list_hex
     elif volume is not None:
         command = "group 'hextmp' add hex in volume " + str(volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif self.volume is not None:
         command = "group 'hextmp' add hex in volume " + str(self.volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif list_hex is None and self.list_hex is None:
         self.list_hex = cubit.parse_cubit_list("hex", "all")
     print "list_hex: ", len(self.list_hex), " hexes"
Beispiel #2
0
def WebcutTool(body_list_in, tool_ID, delete=False):
    import cubit
    print("body_list_in: ", body_list_in)
    print("tool_ID: ", tool_ID)
    ### delete group 'webcut_group' if it exists
    cubit.delete_group(cubit.get_id_from_name('webcut_group'))
    ### webcut
    cmd = 'webcut volume '
    for i in body_list_in:
        cmd += '%i ' % i
    cmd += 'tool volume %i group_results' % tool_ID
    cubit.cmd(cmd)
    ### identify the grain and the outside
    ### I need a list of the volume IDs in webcut_group, but cubit.get_group_volumes returns a t-uple
    tmp_IDs = cubit.get_id_from_name('webcut_group')
    webcut_group_IDs = [vol_id for vol_id in cubit.get_group_volumes(tmp_IDs)]
    webcut_group_IDs.append(tool_ID)
    ovlp = cubit.get_overlapping_volumes(webcut_group_IDs)
    ### ovlp now contains the overlap and the tool
    ### remove tool_id to get tool_list_out
    tmp_list = [vol_id for vol_id in ovlp if not vol_id == tool_ID]
    tool_list_out = tmp_list  # just so that I can make a call with tool_ID = tool_list_out
    ### remove tool_list_out and tool_ID from ovlp
    body_list_out = [
        vol_id for vol_id in webcut_group_IDs if vol_id not in ovlp
    ]
    print("body_list_out: ", body_list_out)
    ### delete the tool of requested
    if delete:
        cubit.cmd('delete volume %i' % tool_ID)
    ### Be nice and clean up
    cubit.delete_group(cubit.get_id_from_name('webcut_group'))
    return body_list_out, tool_list_out
Beispiel #3
0
 def pick_hex(self, list_hex=None, volume=None):
     if self.cubit_skew > 0:
         command = "del group skew_top"
         cubit.cmd(command)
         command = "group 'skew_top' add quality volume all skew low " + str(
             self.cubit_skew)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("skew_top")
         self.list_hex = cubit.get_group_hexes(group)
     elif list_hex is not None:
         self.list_hex = list_hex
     elif volume is not None:
         command = "group 'hextmp' add hex in volume " + str(volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif self.volume is not None:
         command = "group 'hextmp' add hex in volume " + str(self.volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif list_hex is None and self.list_hex is None:
         self.list_hex = cubit.parse_cubit_list('hex', 'all')
     print 'list_hex: ', len(self.list_hex), ' hexes'
Beispiel #4
0
def refine_inside_curve(curves,ntimes=1,depth=1,block=1,surface=False):
    if not isinstance(curves,list): 
       if isinstance(curves,str):
          curves=map(int,curves.split())
       else:
          curves=[curves]
    for curve in curves:
        cubit.cmd('del group ntop')
        if not surface:
            cubit.cmd("group 'ntop' add node in face in block "+str(block))
        else:
            cubit.cmd("group 'ntop' add node in face in surface "+str(surface))
        group1 = cubit.get_id_from_name("ntop")
        nodes = list(cubit.get_group_nodes(group1))
        ni=get_nodes_inside_curve(nodes, curve)
        if ntimes > 1:
            cmd='del group hex_refining'
            cubit.cmd(cmd)
            command = "group 'hex_refining' add hex propagate face in node "+' '.join(str(x) for x in ni)+"times "+str(ntimes)
            cubit.cmd(command)
            id_group=cubit.get_id_from_name('hex_refining')
            command='refine hex in group "hex_refining" numsplit 1 bias 1.0 depth '+str(depth)+' smooth'
            cubit.cmd(command)
        else:
            command='refine node '+" ".join(str(x) for x in ni)+' numsplit 1 bias 1.0 depth '+str(depth)+' smooth'
            cubit.cmd(command)
    #
    #
    cmd='group "negativejac" add quality hex all Jacobian high'
    cubit.cmd(cmd) 
    group_id_1=cubit.get_id_from_name("negativejac")
    n1=cubit.get_group_nodes(group_id_1)
    if len(n1) != 0:
        print 'error, negative jacobian after the refining'
        import sys
Beispiel #5
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
Beispiel #6
0
def double_split_desc(Ca,
                      Cb,
                      Ca1name='_1',
                      Ca2name='_2',
                      Cb1name='_1',
                      Cb2name='_2'):
    if type(Ca) is int:
        Ca1, Ca2, Cb1, Cb2 = double_split(cubit.curve(Ca), cubit.curve(Cb),
                                          Ca1name, Ca2name, Cb1name, Cb2name)
    elif type(Ca) is str:
        Ca1, Ca2, Cb1, Cb2 = double_split(
            cubit.curve(cubit.get_id_from_name(Ca)),
            cubit.curve(cubit.get_id_from_name(Cb)), Ca1name, Ca2name, Cb1name,
            Cb2name)
    return Ca1, Ca2, Cb1, Cb2
Beispiel #7
0
def curver_start_end_desc(Cdesc, dx1, dx2, direction='l'):
    if type(Cdesc) is int:
        curver_start_end(cubit.curve(Cdesc), dx1, dx2, direction)
    elif type(Cdesc) is str:
        curver_start_end(cubit.curve(cubit.get_id_from_name(Cdesc)), dx1, dx2,
                         direction)
    return None
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
def check_lateral_nodes(name_group='lateral'):
    cubit.cmd("group 'lateral_nodes' add Node in face in group "+name_group)
    ilateral_nodes=cubit.get_id_from_name('lateral_nodes')
    lateral_nodes=cubit.get_group_nodes(ilateral_nodes)
    cubit.cmd('del group '+str(ilateral_nodes))
    print name_group, ' nodes ',len(lateral_nodes)
    return len(lateral_nodes)
Beispiel #10
0
def curver_bias_desc(Cdesc, dx, biasfactor, direction='l'):
    if type(Cdesc) is int:
        curver_bias(cubit.curve(Cdesc), dx, biasfactor, direction)
    elif type(Cdesc) is str:
        curver_bias(cubit.curve(cubit.get_id_from_name(Cdesc)), dx, biasfactor,
                    direction)
    return None
Beispiel #11
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
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
Beispiel #13
0
def curver_desc(Cdesc,dx,unit='*km'):
    if type(Cdesc) is int:
        komand = "curve " + str(Cdesc) + " size {" + str(dx) + unit + "}"
    elif type(Cdesc) is str:
        komand = "curve " + str(cubit.get_id_from_name(Cdesc)) + " size {" + str(dx) + unit +"}"    
    print komand
    cubit.silent_cmd(komand)
    return None
Beispiel #14
0
 def get_face_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nf" add Node in face '+str(ind))
             group1 = cubit.get_id_from_name("nf")
             result=cubit.get_group_nodes(group1)
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('face',ind)
     return result
Beispiel #15
0
 def get_face_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nf" add Node in face '+str(ind))
             group1 = cubit.get_id_from_name("nf")
             result=cubit.get_group_nodes(group1)
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('face',ind)
     return result
Beispiel #16
0
def curver_desc(Cdesc, dx, unit='*km'):
    if type(Cdesc) is int:
        komand = "curve " + str(Cdesc) + " size {" + str(dx) + unit + "}"
    elif type(Cdesc) is str:
        komand = "curve " + str(
            cubit.get_id_from_name(Cdesc)) + " size {" + str(dx) + unit + "}"
    print komand
    cubit.silent_cmd(komand)
    return None
Beispiel #17
0
 def get_hex_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nh" add Node in hex '+str(ind))
             group1 = cubit.get_id_from_name("nh")
             result=cubit.get_group_nodes(group1)
             if len(result) != 27: print 'error hex27'
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('hex',ind)
     return result
Beispiel #18
0
 def get_hex_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nh" add Node in hex '+str(ind))
             group1 = cubit.get_id_from_name("nh")
             result=cubit.get_group_nodes(group1)
             if len(result) != 27: print 'error hex27'
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('hex',ind)
     return result
Beispiel #19
0
def merge_node_ck(n1, n2):
    factor, minvalue, inv_length = prepare_equivalence(n1, n2)

    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    cubit.cmd('set error off')

    for k in inv_length.keys()[:-1]:
        if len(inv_length[k]) > 0:
            cmd = 'equivalence node ' + ' '.join(
                ' '.join(str(n) for n in x)
                for x in inv_length[k]) + ' tolerance ' + str(k * factor +
                                                              minvalue / 2.)
            cubit.cmd(cmd)
            print 'equivalence ' + str(len(
                inv_length[k])) + ' couples of nodes -  tolerance ' + str(
                    k * factor + minvalue / 2.)

    cubit.cmd('group "checkmerge" add node ' + ' '.join(str(n) for n in n1) +
              ' ' + ' '.join(str(n) for n in n2))
    idg = cubit.get_id_from_name('checkmerge')
    remainnodes = cubit.get_group_nodes(idg)
    print 'from ' + str(len(n1) + len(n2)) + ' nodes -> ' + str(
        len(remainnodes)) + ' nodes'
    if len(n1) != len(remainnodes):
        print 'equivalence ' + str(
            len(remainnodes)) + ' couples of nodes -  tolerance ' + str(
                minvalue / 2.)
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        cmd = 'equivalence node in group ' + str(idg) + ' tolerance ' + str(
            minvalue / 2.)
        cubit.cmd(cmd)
        cmd = 'block 3000 node in group ' + str(idg)
        cubit.cmd(cmd)

    if len(n1) != len(remainnodes):
        cubit.cmd(
            'export mesh "error_merging.e" dimension 3 block all overwrite')
        cubit.cmd(
            'save as "error_merging.cub" dimension 3 block all overwrite')
        print 'error merging '
        if False:
            import sys
            sys.exit(2)

    cubit.cmd('delete group checkmerge')
    cubit.cmd('delete block 3000')

    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
Beispiel #20
0
def WebcutTool2(body_list_in, tool_ID, delete=False):
    import cubit
    print("body_list_in: ", body_list_in)
    print("tool_ID: ", tool_ID)
    ### delete group 'webcut_group' if it exists
    cubit.delete_group(cubit.get_id_from_name('webcut_group'))
    ### webcut
    cmd = 'webcut volume '
    for i in body_list_in:
        cmd += '%i ' % i
    cmd += 'tool volume %i group_results' % tool_ID
    cubit.cmd(cmd)
Beispiel #21
0
 def select_cpml(self):
     xmin,xmax=self.check_cmpl_size(case='x')
     ymin,ymax=self.check_cmpl_size(case='y')
     zmin,zmax=self.check_cmpl_size(case='z')
     #
     if xmin is False or xmax is False or ymin is False or ymax is False or zmin is False or zmax is False:
         return False
     else:
         txt="group 'hxmin' add hex  with X_coord < "+str(xmin)
         cubit.cmd(txt)
         txt="group 'hxmax' add hex  with X_coord > "+str(xmax)
         cubit.cmd(txt)
         txt="group 'hymin' add hex  with Y_coord < "+str(ymin)
         cubit.cmd(txt)
         txt="group 'hymax' add hex  with Y_coord > "+str(ymax)
         cubit.cmd(txt)
         txt="group 'hzmin' add hex  with Z_coord < "+str(zmin)
         cubit.cmd(txt)
         txt="group 'hzmax' add hex  with Z_coord > "+str(zmax)
         cubit.cmd(txt)
         from sets import Set
         group1 = cubit.get_id_from_name("hxmin")
         cpml_xmin =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hymin")
         cpml_ymin =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hxmax")
         cpml_xmax =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hymax")
         cpml_ymax =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hzmin")
         cpml_zmin =Set(list(cubit.get_group_hexes(group1)))
         if self.top_absorbing:
             group1 = cubit.get_id_from_name("hzmax")
             cpml_zmax =Set(list(cubit.get_group_hexes(group1)))
         else:
             cpml_zmax =Set([])
         cpml_all=cpml_ymin | cpml_ymax | cpml_xmin | cpml_xmax | cpml_zmin | cpml_zmax
         cpml_x=cpml_all-cpml_zmin-cpml_ymin-cpml_ymax-cpml_zmax
         cpml_y=cpml_all-cpml_zmin-cpml_xmin-cpml_xmax-cpml_zmax
         cpml_xy=cpml_all-cpml_zmin-cpml_y-cpml_x-cpml_zmax
         cpml_z=cpml_all-cpml_xmin-cpml_ymin-cpml_ymax-cpml_xmax
         cpml_xz=cpml_zmin-cpml_ymin-cpml_ymax-cpml_z
         cpml_yz=cpml_zmin-cpml_xmin-cpml_xmax-cpml_z
         cpml_xyz=cpml_zmin-cpml_xz-cpml_yz-cpml_z
         txt=' '.join(str(h) for h in cpml_x)
         cubit.cmd("group 'x_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_y)
         cubit.cmd("group 'y_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_z)
         cubit.cmd("group 'z_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_xy)
         cubit.cmd("group 'xy_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_xz)
         cubit.cmd("group 'xz_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_yz)
         cubit.cmd("group 'yz_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_xyz)
         cubit.cmd("group 'xyz_cpml' add hex "+txt)
         return cpml_x,cpml_y,cpml_z,cpml_xy,cpml_xz,cpml_yz,cpml_xyz
Beispiel #22
0
def create_surface_desc(Dlist,name=''):
    # Dlist : liste des DESCRIPTEURS des courbes qui composent la future surface ([int] ou [str])
    OKlist = []
    if type(Dlist[0]) is int:
        for d in Dlist:
            OKlist.append(cubit.curve(d))
    elif type(Dlist[0]) is str:
        for d in Dlist:
            OKlist.append(cubit.curve(cubit.get_id_from_name(d)))
    S = cubit.create_surface(OKlist)
    if name != '':
        S.entity_name(name)
    return S
Beispiel #23
0
def create_surface_desc(Dlist, name=''):
    # Dlist : liste des DESCRIPTEURS des courbes qui composent la future surface ([int] ou [str])
    OKlist = []
    if type(Dlist[0]) is int:
        for d in Dlist:
            OKlist.append(cubit.curve(d))
    elif type(Dlist[0]) is str:
        for d in Dlist:
            OKlist.append(cubit.curve(cubit.get_id_from_name(d)))
    S = cubit.create_surface(OKlist)
    if name != '':
        S.entity_name(name)
    return S
Beispiel #24
0
 def select_cpml(self):
     xmin,xmax=self.check_cmpl_size(case='x')
     ymin,ymax=self.check_cmpl_size(case='y')
     zmin,zmax=self.check_cmpl_size(case='z')
     #
     if xmin is False or xmax is False or ymin is False or ymax is False or zmin is False or zmax is False:
         return False
     else:
         txt="group 'hxmin' add hex  with X_coord < "+str(xmin)
         cubit.cmd(txt)
         txt="group 'hxmax' add hex  with X_coord > "+str(xmax)
         cubit.cmd(txt)
         txt="group 'hymin' add hex  with Y_coord < "+str(ymin)
         cubit.cmd(txt)
         txt="group 'hymax' add hex  with Y_coord > "+str(ymax)
         cubit.cmd(txt)
         txt="group 'hzmin' add hex  with Z_coord < "+str(zmin)
         cubit.cmd(txt)
         txt="group 'hzmax' add hex  with Z_coord > "+str(zmax)
         cubit.cmd(txt)
         from sets import Set
         group1 = cubit.get_id_from_name("hxmin")
         cpml_xmin =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hymin")
         cpml_ymin =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hxmax")
         cpml_xmax =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hymax")
         cpml_ymax =Set(list(cubit.get_group_hexes(group1)))
         group1 = cubit.get_id_from_name("hzmin")
         cpml_zmin =Set(list(cubit.get_group_hexes(group1)))
         if self.top_absorbing:
             group1 = cubit.get_id_from_name("hzmax")
             cpml_zmax =Set(list(cubit.get_group_hexes(group1)))
         else:
             cpml_zmax =Set([])
         cpml_all=cpml_ymin | cpml_ymax | cpml_xmin | cpml_xmax | cpml_zmin | cpml_zmax
         cpml_x=cpml_all-cpml_zmin-cpml_ymin-cpml_ymax-cpml_zmax
         cpml_y=cpml_all-cpml_zmin-cpml_xmin-cpml_xmax-cpml_zmax
         cpml_xy=cpml_all-cpml_zmin-cpml_y-cpml_x-cpml_zmax
         cpml_z=cpml_all-cpml_xmin-cpml_ymin-cpml_ymax-cpml_xmax
         cpml_xz=cpml_zmin-cpml_ymin-cpml_ymax-cpml_z
         cpml_yz=cpml_zmin-cpml_xmin-cpml_xmax-cpml_z
         cpml_xyz=cpml_zmin-cpml_xz-cpml_yz-cpml_z
         txt=' '.join(str(h) for h in cpml_x)
         cubit.cmd("group 'x_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_y)
         cubit.cmd("group 'y_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_z)
         cubit.cmd("group 'z_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_xy)
         cubit.cmd("group 'xy_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_xz)
         cubit.cmd("group 'xz_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_yz)
         cubit.cmd("group 'yz_cpml' add hex "+txt)
         txt=' '.join(str(h) for h in cpml_xyz)
         cubit.cmd("group 'xyz_cpml' add hex "+txt)
         return cpml_x,cpml_y,cpml_z,cpml_xy,cpml_xz,cpml_yz,cpml_xyz
Beispiel #25
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
Beispiel #27
0
def create_group_nodeset_desc(Clist,grpname,nodesetID=0,grpname_remove=[]):
    while nodesetID == 0 or (nodesetID in cubit.get_nodeset_id_list()):
        nodesetID = nodesetID +1
    for c in Clist:
        cubit.silent_cmd('group "' + grpname + '" add node in ' + c) 
    #Remove some vertice in nodes if specified
    print grpname_remove
    if len(grpname_remove)!=0:
        # Check if group already specified
        for grp in grpname_remove:
            id_grp=cubit.get_id_from_name(grp)
            if id_grp!=0:
                cubit.silent_cmd('group "' + grpname + '" remove node in group ' + grp) 
    # Name the nodesets
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' group ' + grpname)
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' name "' + grpname + '"' )
Beispiel #28
0
def create_group_nodeset_desc(Clist, grpname, nodesetID=0, grpname_remove=[]):
    while nodesetID == 0 or (nodesetID in cubit.get_nodeset_id_list()):
        nodesetID = nodesetID + 1
    for c in Clist:
        cubit.silent_cmd('group "' + grpname + '" add node in ' + c)
    #Remove some vertice in nodes if specified
    print grpname_remove
    if len(grpname_remove) != 0:
        # Check if group already specified
        for grp in grpname_remove:
            id_grp = cubit.get_id_from_name(grp)
            if id_grp != 0:
                cubit.silent_cmd('group "' + grpname +
                                 '" remove node in group ' + grp)
    # Name the nodesets
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' group ' + grpname)
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' name "' + grpname + '"')
def merge_node_ck(n1,n2):
    factor,minvalue,inv_length=prepare_equivalence(n1,n2)
    
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    #cubit.cmd('set error off')
    
    for k in inv_length.keys()[:-1]:
        if len(inv_length[k]) > 0:
            cmd='equivalence node '+' '.join(' '.join(str(n) for n in x) for x in inv_length[k])+' tolerance '+str(k*factor+minvalue/2.)
            cubit.cmd(cmd)
            print 'equivalence '+str(len(inv_length[k]))+' couples of nodes -  tolerance '+str(k*factor+minvalue/2.)
             

    cubit.cmd('group "checkmerge" add node '+' '.join(str(n) for n in n1)+' '+' '.join(str(n) for n in n2))
    idg=cubit.get_id_from_name('checkmerge')
    remainnodes=cubit.get_group_nodes(idg)
    print 'from '+str(len(n1)+len(n2))+' nodes -> '+str(len(remainnodes)) +' nodes'
    if len(n1) != len(remainnodes):
        print 'equivalence '+str(len(remainnodes))+' couples of nodes -  tolerance '+str(minvalue/2.)
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        cmd='equivalence node in group '+str(idg)+' tolerance '+str(minvalue/2.)
        cubit.cmd(cmd)
        cmd='block 3000 node in group '+str(idg)
        cubit.cmd(cmd)
        
    if len(n1) != len(remainnodes):
        cubit.cmd('export mesh "error_merging.e" dimension 3 block all overwrite')
        cubit.cmd('save as "error_merging.cub" dimension 3 block all overwrite')
        print 'error merging '
        if False:
            import sys
            sys.exit(2)
    
    cubit.cmd('delete group checkmerge')
    cubit.cmd('delete block 3000')
    
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
Beispiel #30
0
 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
Beispiel #31
0
 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 save_elements_nodes(name,quads_fault_u,quads_fault_d):
   fault_file = open(name,'w')
   txt =''
   list_hex=cubit.parse_cubit_list('hex','all')
   txt='%10i %10i\n' % (len(quads_fault_u),len(quads_fault_d))
   fault_file.write(txt)

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

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




              fault_file.write(txt)

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



              fault_file.write(txt)

   fault_file.close()
Beispiel #33
0
def get_ordered_node_surf(lsurface, icurve):
    if not isinstance(lsurface, str):
        lsurf = list2str(lsurface)
    #
    if not isinstance(icurve, str):
        icurvestr = str(icurve)
    # initializes
    orient_nodes_surf = []
    nodes_curve = []
    #
    #get the nodes on a surface, I don't use the method get_surface_nodes since it has different behavior in cubit12.2 and cubit13.2+
    k = cubit.get_id_from_name('sl')
    if k != 0:
        cubit.cmd('del group sl')
    else:
        print 'initializing group sl'
    cubit.cmd("group 'sl' add node in surf " + lsurf)
    group1 = cubit.get_id_from_name("sl")
    nodes_ls = list(cubit.get_group_nodes(group1))
    nnode = len(nodes_ls)
    #
    #get the nodes on curves
    orient = []
    k = cubit.get_id_from_name('n1')
    if k != 0:
        cubit.cmd('del group n1')
    else:
        print 'initializing group n1'
    cubit.cmd("group 'n1' add node in curve " + icurvestr)
    x = cubit.get_bounding_box('curve', icurve)
    # checks if anything to do
    if len(x) == 0:
        return nodes_curve, orient_nodes_surf
    # gets nodes
    if x[2] > x[5]:
        idx = 0
    else:
        idx = 1
    group1 = cubit.get_id_from_name("n1")
    nodes1 = list(cubit.get_group_nodes(group1))
    for n in nodes1:
        v = cubit.get_nodal_coordinates(n)
        orient.append(v[idx])
    result = zip(orient, nodes1)
    result.sort()
    nodes2 = [c[1] for c in result]
    for n in nodes2:
        try:
            nodes_ls.remove(n)
        except:
            pass
    orient_nodes_surf = orient_nodes_surf + nodes2
    #
    while len(orient_nodes_surf) < nnode:
        cubit.cmd('del group n1')
        cubit.cmd("group 'n1' add node in edge in node " +
                  str(nodes2).replace('[', ' ').replace(']', ' '))
        group1 = cubit.get_id_from_name("n1")
        nodes1 = list(cubit.get_group_nodes(group1))
        orient = []
        nd = []
        for n in nodes1:
            if n in nodes_ls:
                v = cubit.get_nodal_coordinates(n)
                orient.append(v[idx])
                nd.append(n)
        result = zip(orient, nd)
        result.sort()
        nodes2 = [c[1] for c in result]
        for n in nodes2:
            try:
                nodes_ls.remove(n)
            except:
                pass
        orient_nodes_surf = orient_nodes_surf + nodes2
    #get the vertical curve
    curve_vertical = []
    for s in lsurface:
        lcs = cubit.get_relatives("surface", s, "curve")
        for l in lcs:
            x = cubit.get_bounding_box('curve', l)
            length = [(x[2], 1), (x[5], 2), (x[8], 3)]
            length.sort()
            if length[-1][1] == 3:
                curve_vertical.append(l)
    #
    kcurve = list2str(curve_vertical)
    k = cubit.get_id_from_name('curve_vertical')
    if k != 0:
        cubit.cmd('del group curve_vertical')
    else:
        print 'initializing group curve_vertical'
    cubit.cmd("group 'curve_vertical' add node in curve " + kcurve)
    group1 = cubit.get_id_from_name('curve_vertical')
    nodes_curve = list(cubit.get_group_nodes(group1))
    for n in nodes_curve:
        try:
            orient_nodes_surf.remove(n)
        except:
            pass
    #
    return nodes_curve, orient_nodes_surf
Beispiel #34
0
def geom_cubit_solo(configfile):
    if not os.path.isfile(configfile):
        raise Exception("ERR: CONFIG FILE DON'T EXIST !!!")
    #  READ CONFIGFILE
    cf = ConfigParser.ConfigParser()
    cf.optionxform = str
    cf.read(configfile)
    bathyfile = cf.get('Input', 'bathyfile')
    slabfile = cf.get('Input', 'slabfile')
    left_extension = cf.getfloat('Parameters',
                                 'left_extension')  # (always positive)
    right_extension = cf.getfloat('Parameters', 'right_extension')
    down_limit = cf.getfloat('Parameters', 'down_limit')  # (always positive)
    EET_OP = cf.getfloat('Parameters', 'eet_op')  #  Thickness of the OP Litho
    EET_DP = cf.getfloat('Parameters', 'eet_dp')  #  Thickness of the DP Litho
    #    backstop_bool=cf.getboolean('Parameters','backstop_bool') # True or False
    x_backstop = cf.getfloat('Parameters', 'backstop_distance')
    dip_backstop = cf.getfloat('Parameters', 'backstop_angle')
    output_path = cf.get('Output', 'output_path')
    output_file_prefix = cf.get('Output', 'output_prefix')
    output_file_suffix = cf.get('Output', 'output_suffix')
    output_pathfile = output_path + '/' + output_file_prefix + '_' + output_file_suffix + '.exo'
    dx1 = cf.getfloat('Parameters', 'dx_fine')
    dx2 = cf.getfloat('Parameters', 'dx_coarse')
    # =======================================================================
    #  PRIOR DESIGN
    # =======================================================================
    # Loading the BATHY and SLAB files
    XYbathy = np.loadtxt(bathyfile)
    XYslab = np.loadtxt(slabfile)
    # Creating the bottom of the slab
    XslabBot, YslabBot, _ = rcl.shift_thickness(XYslab[:, 0], XYslab[:, 1],
                                                EET_DP)
    # Creating the bounding points in a dictionnary
    outpts = rcl.make_bounding_points(XYbathy[:, 0], XYbathy[:, 1], XYslab[:,
                                                                           0],
                                      XYslab[:, 1], EET_OP, EET_DP, down_limit,
                                      left_extension, right_extension)
    # Creating the backstop
    Xbackstop, Ybackstop = rcl.make_backstop(XYbathy[:, 0],
                                             XYbathy[:, 1],
                                             XYslab[:, 0],
                                             XYslab[:, 1],
                                             x_backstop,
                                             dip_backstop,
                                             dupdown=150)
    # Adding the 'Bottom_Litho_DP' point to the Litho_DP Bottom
    rcl.add_point_in_list(XslabBot, YslabBot, outpts['vBottom_Litho_DP'])
    # Changing the description concept : Bathy & Slab ==> OP & DP
    Xop, Yop, Xdp, Ydp = rcl.bathyslab_2_OPDPtop(XYbathy[:, 0], XYbathy[:, 1],
                                                 XYslab[:, 0], XYslab[:, 1])
    # Adding the limit points of OP & DP
    Xop, Yop = rcl.add_point_in_list(Xop, Yop, outpts['vBathy_OP'])
    Xdp, Ydp = rcl.add_point_in_list(Xdp, Ydp, outpts['vBathy_DP'])
    # PLOT FOR SECURITY
    #plt.clf()
    #plt.axis('equal')
    #plt.plot(XYbathy[:,0],XYbathy[:,1],'+b')
    #plt.plot(XYslab[:,0],XYslab[:,1],'r+-')
    #plt.plot(XslabBot,YslabBot,'k+-')
    #plt.plot(Xbackstop,Ybackstop,'*-y')
    #for p in outpts.viewvalues():
    #    plt.plot(p[0],p[1],'*k')
    #plt.plot(Xop,Yop,'b-')
    #plt.plot(Xdp,Ydp,'r-')
    # =======================================================================
    #  CUBIT MESHING
    # =======================================================================
    # Initalisation
    cubit.cmd('reset')
    cubit.cmd("#{Units('si')}")
    # Chargement des courbes
    rcl.list_2_curve(Xop, Yop, 'Top_Litho_OP')
    rcl.list_2_curve(Xdp, Ydp, 'Top_Litho_limit_DP')
    rcl.list_2_curve(XslabBot, YslabBot, 'Bottom_Litho_DP')
    rcl.list_2_curve(Xbackstop, Ybackstop, 'Backstop')
    # Chargement des Points Isoles
    rcl.dico_2_listofvertices(outpts)
    ## fabrication de "courbes-segments" a partir de vertex
    v_Bottom_Litho_OP = cubit.vertex(
        cubit.get_id_from_name('vBottom_Litho_OP'))
    v_Bathy_DP = rcl.find_extrema(
        cubit.curve(cubit.get_id_from_name("Top_Litho_limit_DP")), 'r')
    v_Bathy_OP = rcl.find_extrema(
        cubit.curve(cubit.get_id_from_name('Top_Litho_OP')), 'l')
    v_Bottom_Litho_DP = rcl.find_extrema(
        cubit.curve(cubit.get_id_from_name("Bottom_Litho_DP")), 'r')
    v_scratch = cubit.vertex(cubit.get_id_from_name('vscratch'))
    v_Bottom_Astheno_OP = cubit.vertex(
        cubit.get_id_from_name('vBottom_Astheno_OP'))
    v_Bottom_Astheno_DP = cubit.vertex(
        cubit.get_id_from_name('vBottom_Astheno_DP'))
    #
    rcl.vertices_2_curve(v_Bottom_Litho_OP, v_Bottom_Astheno_OP,
                         'Edge_Astheno_OP')
    rcl.vertices_2_curve(v_Bottom_Litho_OP, v_scratch, 'Bottom_Litho_OP_PROTO')
    rcl.vertices_2_curve(v_Bottom_Litho_OP, v_Bathy_OP, 'Edge_Litho_OP')
    rcl.vertices_2_curve(v_Bottom_Astheno_OP, v_Bottom_Astheno_DP,
                         'Bottom_PROTO')
    rcl.vertices_2_curve(v_Bathy_DP, v_Bottom_Litho_DP, 'Edge_Litho_DP')
    rcl.vertices_2_curve(v_Bottom_Litho_DP, v_Bottom_Astheno_DP,
                         'Edge_Astheno_DP')
    ## Split des courbes
    rcl.double_split_desc('Bottom_Litho_OP_PROTO', 'Top_Litho_limit_DP')
    rcl.double_split_desc("Bottom_PROTO", "Top_Litho_limit_DP_1")
    rcl.double_split_desc("Bottom_PROTO_2", "Bottom_Litho_DP")
    rcl.double_split_desc("Backstop", "Top_Litho_limit_DP_2")
    rcl.double_split_desc("Top_Litho_OP", "Backstop_1")
    rcl.double_split_desc("Top_Litho_limit_DP_2_2", "Top_Litho_OP_2")
    if True:
        #    ## suppression des petits morceaux
        rcl.destroy_curve_desc("Top_Litho_limit_DP_1_1")
        rcl.destroy_curve_desc("Bottom_Litho_DP_1")
        rcl.destroy_curve_desc("Backstop_2")
        rcl.destroy_curve_desc("Bottom_Litho_OP_PROTO_2")
        rcl.destroy_curve_desc("Backstop_1_1")
        #    ## renommage des courbes
        rcl.rename_curve_desc(7, 'Edge_Litho_OP')
        rcl.rename_curve_desc(5, 'Edge_Astheno_OP')
        rcl.rename_curve_desc(9, 'Edge_Litho_DP')
        rcl.rename_curve_desc(10, 'Edge_Astheno_DP')
        rcl.rename_curve_desc("Top_Litho_limit_DP_2_1", 'Contact_OP_DP')
        rcl.rename_curve_desc("Top_Litho_limit_DP_2_2_1", 'Contact_Prism_DP')
        rcl.rename_curve_desc("Backstop_1_2", 'Contact_Prism_OP')
        rcl.rename_curve_desc("Top_Litho_OP_2_1", 'Top_Litho_DP')
        rcl.rename_curve_desc("Top_Litho_OP_2_2", 'Top_Prism')
        rcl.rename_curve_desc("Top_Litho_OP_1", 'Top_Litho_OP')
        rcl.rename_curve_desc("Bottom_PROTO_2_2", 'Bottom_Astheno_DP')
        rcl.rename_curve_desc("Bottom_Litho_DP_2", 'Bottom_Litho_DP')
        rcl.rename_curve_desc("Bottom_PROTO_1", 'Bottom_Astheno_OP')
        rcl.rename_curve_desc("Bottom_Litho_OP_PROTO_1", 'Bottom_Litho_OP')
        rcl.rename_curve_desc("Bottom_PROTO_2_1", 'Front_Litho_DP')
        rcl.rename_curve_desc("Top_Litho_limit_DP_1_2",
                              'Astheno_Litho_Contact')
        #    # creation des surfaces
        rcl.create_surface_desc(
            ["Edge_Astheno_DP", "Bottom_Astheno_DP", "Bottom_Litho_DP"])
        rcl.create_surface_desc([
            "Front_Litho_DP", "Bottom_Litho_DP", "Edge_Litho_DP",
            "Top_Litho_DP", "Contact_Prism_DP", "Contact_OP_DP",
            "Astheno_Litho_Contact"
        ])
        rcl.create_surface_desc([
            "Bottom_Astheno_OP", "Astheno_Litho_Contact", "Bottom_Litho_OP",
            "Edge_Astheno_OP"
        ])
        rcl.create_surface_desc([
            "Bottom_Litho_OP", "Edge_Litho_OP", "Top_Litho_OP",
            "Contact_Prism_OP", "Contact_OP_DP"
        ])
        rcl.create_surface_desc(
            ["Top_Prism", "Contact_Prism_DP", "Contact_Prism_OP"])
        #    # renomage des surfaces
        cubit.surface(1).entity_name('Astheno_DP')
        cubit.surface(2).entity_name('Litho_DP')
        cubit.surface(3).entity_name('Astheno_OP')
        cubit.surface(4).entity_name('Litho_OP')
        cubit.surface(5).entity_name('Prisme')
        # Fusion des surfaces
        cubit.cmd('delete vertex all')
        cubit.cmd('imprint all')
        cubit.cmd('merge all')
        cubit.cmd('stitch volume all')
        rcl.rename_curve_desc(45, 'Astheno_Litho_Contact')
        cubit.cmd('surface all scheme trimesh')
        cubit.cmd('curve all scheme default')
        cubit.cmd('surface all sizing function none')
        # nouveau decoupage des courbes
        rcl.curver_desc("Contact_Prism_DP", dx1)
        rcl.curver_desc("Contact_Prism_OP", dx1)
        rcl.curver_desc("Top_Prism", dx1)
        rcl.curver_desc("Bottom_Litho_DP", dx2)
        rcl.curver_desc("Bottom_Astheno_OP", dx2)
        rcl.curver_desc("Front_Litho_DP", dx2)
        rcl.curver_desc("Bottom_Astheno_DP", dx2)
        rcl.curver_desc("Edge_Astheno_OP", dx2)
        rcl.curver_desc("Edge_Litho_OP", dx2)
        rcl.curver_desc("Edge_Astheno_DP", dx2)
        rcl.curver_desc("Edge_Litho_DP", dx2)
        rcl.curver_desc("Contact_OP_DP", dx1)
        rcl.curver_start_end_desc("Bottom_Litho_OP", dx1, dx2, 'l')
        rcl.curver_start_end_desc("Top_Litho_OP", dx1, dx2, 'l')
        rcl.curver_start_end_desc("Top_Litho_DP", dx1, dx2, 'r')
        rcl.curver_start_end_desc("Astheno_Litho_Contact", dx1, dx2, 'l')
        # fabrication du mesh
        cubit.cmd('mesh surface all')
        cubit.cmd('surface all smooth scheme condition number beta 1.7 cpu 10')
        cubit.cmd('smooth surface all')
        cubit.cmd('surface 1 size auto factor 5')
        ## Fabrication de groupe et de nodeset
        for i, s in enumerate(cubit.get_entities("surface")):
            S = cubit.surface(s)
            cubit.cmd('block ' + str(i + 1) + ' surface ' + S.entity_name())
            cubit.cmd('block ' + str(i + 1) + ' name "' + S.entity_name() +
                      ' "')
        rcl.create_group_nodeset_desc(
            ['Astheno_Litho_Contact', 'Contact_OP_DP', 'Contact_Prism_DP'],
            "fault_top", 20)
        rcl.create_group_nodeset_desc(
            ['Top_Litho_OP', 'Top_Prism', 'Top_Litho_DP'], "ground_surface",
            20)
        rcl.create_group_nodeset_desc(['Bottom_Litho_OP'], "bottom_litho_OP",
                                      20)
        rcl.create_group_nodeset_desc(['Bottom_Litho_DP'], "bottom_litho_DP",
                                      20)
        rcl.create_group_nodeset_desc(['Edge_Litho_OP'], "edge_litho_OP", 20)
        rcl.create_group_nodeset_desc(['Edge_Litho_DP'], "edge_litho_DP", 20)
        rcl.create_group_nodeset_desc(['Front_Litho_DP'], "front_litho_DP", 20)
        rcl.create_group_nodeset_desc(['Contact_Prism_OP'], "contact_prism_OP",
                                      20, ['fault_top'])
        print 'ca chie'
        rcl.create_group_nodeset_desc(
            ['Bottom_Astheno_DP', 'Bottom_Astheno_OP'], "bottom_astheno", 20,
            ['front_litho_DP'])
        print 'ca chie 2'
        rcl.create_group_nodeset_desc(['Edge_Astheno_DP'], "edge_astheno_DP",
                                      20, ['edge_litho_DP'])
        rcl.create_group_nodeset_desc(['Edge_Astheno_OP'], "edge_astheno_OP",
                                      20, ['edge_litho_OP'])
        # ecriture fichier final
        cubit.cmd('export mesh "' + output_pathfile +
                  '" dimension 2 overwrite')
    return None
Beispiel #35
0
def rename_curve_desc(Cdesc, newname):
    if type(Cdesc) is int:
        rename_curve(cubit.curve(Cdesc), newname)
    elif type(Cdesc) is str:
        rename_curve(cubit.curve(cubit.get_id_from_name(Cdesc)), newname)
    return None
Beispiel #36
0
def destroy_curve_desc(Cdesc):
    if type(Cdesc) is int:
        destroy_curve(cubit.curve(Cdesc))
    elif type(Cdesc) is str:
        destroy_curve(cubit.curve(cubit.get_id_from_name(Cdesc)))
    return None
Beispiel #37
0
def collecting_merging(cpuxmin=0,
                       cpuxmax=1,
                       cpuymin=0,
                       cpuymax=1,
                       cpux=1,
                       cpuy=1,
                       cubfiles=False,
                       ckbound_method1=False,
                       ckbound_method2=False,
                       merge_tolerance=None,
                       decimate=False):
    import glob
    import re
    #
    rule_st = re.compile("(.+)_[0-9]+\.")
    rule_ex = re.compile(".+_[0-9]+\.(.+)")
    rule_int = re.compile(".+_([0-9]+)\.")
    boundary_dict = {}
    ##
    try:
        from boundary_definition import check_bc, map_boundary
    except:
        pass
    #
    xmin, xmax, ymin, ymax, listfull = map_boundary(cpuxmin, cpuxmax, cpuymin,
                                                    cpuymax, cpux, cpuy)
    #
    if cubfiles:
        nf, listip, filenames, cubflag = importing_cubfiles(cubfiles)
    else:
        nf = 0
        filenames = []
        ip = 0
    #
    if nf > 0:
        for ip, filename in zip(listip, filenames):
            try:
                if ip in listfull:
                    if cubflag:
                        cubit.cmd('import cubit "' + filename + '"')
                    else:
                        cubit.cmd(
                            'import mesh geometry "' + filename +
                            '" block all use nodeset sideset feature_angle 135.00 linear merge'
                        )
                    if decimate:
                        cubit.cmd(
                            'refine volume all numsplit 1 bias 1.0 depth 1 ')
                    boundary = check_bc(ip, xmin, xmax, ymin, ymax, cpux, cpuy,
                                        cpuxmin, cpuxmax, cpuymin, cpuymax)
                    boundary_dict[ip] = boundary
                    list_vol = list(cubit.parse_cubit_list('volume', 'all'))
                    for v in list_vol:
                        cubit.cmd("disassociate mesh from volume " + str(v))
                        command = "del vol " + str(v)
                        cubit.cmd(command)
            except:
                cubit.cmd(
                    'import mesh geometry "' + filename +
                    '" block all use nodeset sideset feature_angle 135.00 linear merge'
                )
                if decimate:
                    cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
                ip = 0
                boundary = check_bc(ip, xmin, xmax, ymin, ymax, cpux, cpuy,
                                    cpuxmin, cpuxmax, cpuymin, cpuymax)
                boundary_dict[ip] = boundary
                list_vol = list(cubit.parse_cubit_list('volume', 'all'))
                for v in list_vol:
                    cubit.cmd("disassociate mesh from volume " + str(v))
                    command = "del vol " + str(v)
                    cubit.cmd(command)
        cubit.cmd(
            'export mesh "tmp_collect_NOmerging.e" dimension 3 block all overwrite'
        )
    else:
        if decimate:
            cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
        boundary = check_bc(ip, xmin, xmax, ymin, ymax, cpux, cpuy, cpuxmin,
                            cpuxmax, cpuymin, cpuymax)
    #
    #
    #print boundary_dict
    block_list = cubit.get_block_id_list()
    for block in block_list:
        ty = cubit.get_block_element_type(block)
        if ty == 'HEX8':
            cubit.cmd('block ' + str(block) + ' name "vol' + str(block) + '"')
    #
    #
    print 'chbound', ckbound_method1, ckbound_method2

    if ckbound_method1 and not ckbound_method2 and len(filenames) != 1:
        #use the equivalence method for groups
        if isinstance(merge_tolerance, list):
            tol = merge_tolerance[0]
        elif merge_tolerance:
            tol = merge_tolerance
        else:
            tol = 100000
        #
        idiag = None
        #cubit.cmd('set info off')
        #cubit.cmd('set journal off')
        #cubit.cmd('set echo off')
        ind = 0
        for ix in range(cpuxmin, cpuxmax):
            for iy in range(cpuymin, cpuymax):
                ind = ind + 1
                ip = iy * cpux + ix
                print '******************* ', ip, ind, '/', len(listfull)
                #
                #   ileft    |   ip
                #  --------------------
                #   idiag    |   idown
                #
                #
                if ip not in xmin and ip not in ymin:
                    ileft = iy * cpux + ix - 1
                    idown = (iy - 1) * cpux + ix
                    idiag = idown - 1
                elif ip in xmin and ip in ymin:
                    ileft = ip
                    idown = ip
                    idiag = None
                elif ip in xmin:
                    ileft = ip
                    idown = (iy - 1) * cpux + ix
                    idiag = idown
                elif ip in ymin:
                    ileft = iy * cpux + ix - 1
                    idown = ip
                    idiag = ileft
                #
                print ip, ileft, idiag, idown
                if ip != idown:
                    nup = boundary_dict[ip]['nodes_surf_ymin']
                    ndow = boundary_dict[idown]['nodes_surf_ymax']
                    merge_node_ck(nup, ndow)

                    if idiag != idown:
                        if ip in ymax and ip not in xmin:
                            nlu = boundary_dict[ip][
                                'node_curve_xminymax']  #node in curve chunck left up... r u
                            nru = boundary_dict[ileft]['node_curve_xmaxymax']
                            merge_node(nlu, nru)
                        if ip in xmax:
                            nrd = boundary_dict[ip][
                                'node_curve_xmaxymin']  #node in curve chunck left up... r u
                            nru = boundary_dict[idown]['node_curve_xmaxymax']
                            merge_node(nrd, nru)
                        nru = boundary_dict[ip][
                            'node_curve_xminymin']  #node in curve chunck right up... r u
                        nrd = boundary_dict[idown]['node_curve_xminymax']
                        nld = boundary_dict[idiag]['node_curve_xmaxymax']
                        nlu = boundary_dict[ileft]['node_curve_xmaxymin']
                        merge_node_4(nru, nrd, nld, nlu)
                    elif ip in xmin:
                        nlu = boundary_dict[ip][
                            'node_curve_xminymin']  #node in curve chunck right up... r u
                        nld = boundary_dict[idown]['node_curve_xminymax']
                        merge_node(nld, nlu)
                        nru = boundary_dict[ip][
                            'node_curve_xmaxymin']  #node in curve chunck right up... r u
                        nrd = boundary_dict[idown]['node_curve_xmaxymax']
                        merge_node(nrd, nru)

                #
                if ip != ileft:
                    nright = boundary_dict[ip]['nodes_surf_xmin']
                    nleft = boundary_dict[ileft]['nodes_surf_xmax']
                    merge_node_ck(nright, nleft)
                    #
                    #
                    if ip in ymin:
                        nrd = boundary_dict[ip][
                            'node_curve_xminymin']  #node in curve chunck right down... r u
                        nld = boundary_dict[ileft]['node_curve_xmaxymin']
                        merge_node(nrd, nld)
                    if ip in ymax:
                        nru = boundary_dict[ip][
                            'node_curve_xminymax']  #node in curve chunck right up... r u
                        nlu = boundary_dict[ileft]['node_curve_xmaxymax']
                        merge_node(nlu, nru)

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

        #
        #
        cmd = 'group "negativejac" add quality hex all Jacobian high'
        cubit.cmd(cmd)
        group_id_1 = cubit.get_id_from_name("negativejac")
        n1 = cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, use --merge2 instead of --equivalence/--merge/--merge1'
    elif ckbound_method2 and not ckbound_method1 and len(filenames) != 1:
        if isinstance(merge_tolerance, list):
            tol = merge_tolerance[0]
        elif merge_tolerance:
            tol = merge_tolerance
        else:
            tol = 100000
        #
        idiag = None
        for ix in range(cpuxmin, cpuxmax):
            for iy in range(cpuymin, cpuymax):
                ip = iy * cpux + ix
                print '******************* ', ip
                #
                #   ileft    |   ip
                #  --------------------
                #   idiag    |   idown
                #
                #
                if ip not in xmin and ip not in ymin:
                    ileft = iy * cpux + ix - 1
                    idown = (iy - 1) * cpux + ix
                    idiag = idown - 1
                elif ip in xmin and ip in ymin:
                    ileft = ip
                    idown = ip
                elif ip in xmin:
                    ileft = ip
                    idown = (iy - 1) * cpux + ix
                    idiag = idown
                elif ip in ymin:
                    ileft = iy * cpux + ix - 1
                    idown = ip
                    idiag = ileft
                #
                #
                if ip != idown:
                    nup = boundary_dict[ip]['nodes_surf_ymin']
                    ndow = boundary_dict[idown]['nodes_surf_ymax']
                    for n1, n2 in zip(nup, ndow):
                        cubit.cmd('equivalence node ' + str(n1) + ' ' +
                                  str(n2) + ' tolerance ' + str(tol))
                    if idiag != idown:
                        if ip in ymax and ip not in xmin:
                            nlu = boundary_dict[ip][
                                'node_curve_xminymax']  #node in curve chunck left up... r u
                            nru = boundary_dict[ileft]['node_curve_xmaxymax']
                            for n in zip(nlu, nru):
                                cubit.cmd('equivalence node ' +
                                          ' '.join(str(x) for x in n) +
                                          ' tolerance ' + str(tol))
                        nru = boundary_dict[ip][
                            'node_curve_xminymin']  #node in curve chunck right up... r u
                        nrd = boundary_dict[idown]['node_curve_xminymax']
                        nld = boundary_dict[idiag]['node_curve_xmaxymax']
                        nlu = boundary_dict[ileft]['node_curve_xmaxymin']
                        for n in zip(nru, nrd, nlu, nld):
                            cubit.cmd('equivalence node ' +
                                      ' '.join(str(x) for x in n) +
                                      ' tolerance ' + str(tol))
                    elif ip in xmin:
                        nru = boundary_dict[ip][
                            'node_curve_xminymin']  #node in curve chunck right up... r u
                        nrd = boundary_dict[idown]['node_curve_xminymax']
                        for n in zip(nru, nrd):
                            cubit.cmd('equivalence node ' +
                                      ' '.join(str(x) for x in n) +
                                      ' tolerance ' + str(tol))
                #
                #
                if ip != ileft:
                    nright = boundary_dict[ip]['nodes_surf_xmin']
                    nleft = boundary_dict[ileft]['nodes_surf_xmax']
                    for n1, n2 in zip(nleft, nright):
                        cubit.cmd('equivalence node ' + str(n1) + ' ' +
                                  str(n2) + ' tolerance ' + str(tol))
                    #
                    #
                    if ip in ymin:
                        nrd = boundary_dict[ip][
                            'node_curve_xminymin']  #node in curve chunck right down... r u
                        nld = boundary_dict[ileft]['node_curve_xmaxymin']
                        for n in zip(nrd, nld):
                            cubit.cmd('equivalence node ' +
                                      ' '.join(str(x) for x in n) +
                                      ' tolerance ' + str(tol))
                    if ip in ymax:
                        nru = boundary_dict[ip][
                            'node_curve_xminymax']  #node in curve chunck right up... r u
                        nlu = boundary_dict[ileft]['node_curve_xmaxymax']
                        for n in zip(nru, nlu):
                            cubit.cmd('equivalence node ' +
                                      ' '.join(str(x) for x in n) +
                                      ' tolerance ' + str(tol))
        #
        #
        cmd = 'topology check coincident node face all tolerance ' + str(
            tol * 2) + ' nodraw brief result group "checkcoinc"'
        cubit.silent_cmd(cmd)
        group_id_1 = cubit.get_id_from_name("checkcoinc")
        if group_id_1 != 0:
            n1 = cubit.get_group_nodes(group_id_1)
            if len(n1) != 0:
                print 'error, coincident nodes after the equivalence node command, check the tolerance'
                import sys
                sys.exit()
        cmd = 'group "negativejac" add quality hex all Jacobian high'
        cubit.cmd(cmd)
        group_id_1 = cubit.get_id_from_name("negativejac")
        n1 = cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, check the mesh'
    elif ckbound_method1 and ckbound_method2 and len(filenames) != 1:
        block_list = cubit.get_block_id_list()
        i = -1
        for block in block_list:
            ty = cubit.get_block_element_type(block)
            if ty == 'HEX8':
                i = i + 1
                if isinstance(merge_tolerance, list):
                    try:
                        tol = merge_tolerance[i]
                    except:
                        tol = merge_tolerance[-1]
                elif merge_tolerance:
                    tol = merge_tolerance
                else:
                    tol = 1
                cmd = 'topology check coincident node face in hex in block ' + str(
                    block) + ' tolerance ' + str(
                        tol) + ' nodraw brief result group "b' + str(
                            block) + '"'
                cubit.cmd(cmd)
                print cmd
                cmd = 'equivalence node in group b' + str(
                    block) + ' tolerance ' + str(tol)
                cubit.cmd(cmd)
                print cmd
        if isinstance(merge_tolerance, list):
            tol = max(merge_tolerance)
        elif merge_tolerance:
            tol = merge_tolerance
        else:
            tol = 1
        #
        #
        cmd = 'topology check coincident node face all tolerance ' + str(
            tol) + ' nodraw brief result group "checkcoinc"'
        cubit.silent_cmd(cmd)
        group_id_1 = cubit.get_id_from_name("checkcoinc")
        if group_id_1 != 0:
            n1 = cubit.get_group_nodes(group_id_1)
            if len(n1) != 0:
                print 'error, coincident nodes after the equivalence node command, check the tolerance'
                import sys
                sys.exit()
        cmd = 'group "negativejac" add quality hex all Jacobian high'
        cubit.silent_cmd(cmd)
        group_id_1 = cubit.get_id_from_name("negativejac")
        n1 = cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, use --merge instead of --equivalence'
Beispiel #38
0
print "Playback journal file..."
with open(journalFile) as f:
    content = f.readlines()
for line in content:
    cubit.cmd(line)

# ==================================================
#         Save the mesh to txt files
#      This part is revised from the code of Specfem3D
# ==================================================
print ""
print "Convert mesh to Specfem-format..."
os.system('mkdir -p MESH')

## fault surfaces (up/down)
Au = [cubit.get_id_from_name("fault1")]
Ad = [cubit.get_id_from_name("fault2")]

#  FOR THE BULK (Seismic wave propagation part for SPECFEM3D)
entities = ['face']
xmin, xmax, ymin, ymax, bottom, topo = absorbing_boundary.define_parallel_absorbing_surf(
)
# The above function is expected to obtain the correct topo and bottom surfaces, but for curved fault this function may fail (I don't know why).
# Here I try to obtain the topo and bottom surface automaticly in case the above function fails.
# If this part also doesn't work well (such as the topography has more than one surfaces), please setup bottom=[surface_list] and topo=[surface_list] manually.
list_surf = cubit.parse_cubit_list("surface", "all")
center_depth = []
for k in list_surf:
    center_depth.append(cubit.get_center_point("surface", k)[2])
bottom = numpy.asarray(list_surf)[numpy.argwhere(
    center_depth == numpy.amin(center_depth))[:, 0]].tolist()
Beispiel #39
0
def mesh_layercake_regularmap(filename=None):
    import sys,os
    import start as start
    mpiflag,iproc,numproc,mpi   = start.start_mpi()
    from utilities import  importgeometry,savemesh,get_v_h_list,cubit_command_check
    #
    numpy                       = start.start_numpy()
    cfg                         = start.start_cfg(filename=filename)
    from math import sqrt
    from sets import Set

    #
    class cubitvolume:
          def __init__(self,ID,intervalv,centerpoint,dimension):
              self.ID=ID
              self.intervalv=intervalv
              self.centerpoint=centerpoint
              self.dim=dimension
          
          def __repr__(self):
              msg="(vol:%3i, vertical interval: %4i, centerpoint: %8.2f)" % (self.ID, self.intervalv,self.centerpoint)
              return msg       
    #
    def by_z(x,y):
        return cmp(x.centerpoint,y.centerpoint)
    #
    #
    #
    list_vol=cubit.parse_cubit_list("volume","all")
    if len(list_vol) != 0:
        pass
    else:
        geometryfile='geometry_vol_'+str(iproc)+'.cub'
        importgeometry(geometryfile,iproc=iproc)
    #
    command = 'composite create curve all'
    cubit.cmd(command)
    print '###"No valid composites can be created from the specified curves."  is NOT a critical ERROR.'
    #
    command = "compress all"
    cubit.cmd(command)
    list_vol=cubit.parse_cubit_list("volume","all")
    nvol=len(list_vol)                                 
    vol=[]
    for id_vol in list_vol:
        p=cubit.get_center_point("volume",id_vol)
        vol.append(cubitvolume(id_vol,1,p[2],0))
    vol.sort(by_z)
    #
    for id_vol in range(0,nvol):
        vol[id_vol].intervalv=cfg.iv_interval[id_vol]
    #
    #
    surf_vertical=[]
    surf_or=[]
    top_surface=0
    top_surface_add=''
    bottom_surface=0
    #
    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6]
    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
    #
    #
    #interval assignement
    surf_or,surf_vertical,list_curve_or,list_curve_vertical,bottom,top = get_v_h_list(list_vol,chktop=cfg.chktop)
    print 'vertical surfaces: ',surf_vertical    
    
    for k in surf_vertical:
        command = "surface "+str(k)+" scheme submap"
        cubit.cmd(command)
    for k in surf_or:
        command = "surface "+str(k)+" scheme "+cfg.or_mesh_scheme
        cubit.cmd(command)
    #
    ucurve,vcurve=get_uv_curve(list_curve_or)
    schemepave=False
    #
    ucurve_interval={}
    for k in ucurve:
        length=cubit.get_curve_length(k)
        interval=int(2*round(.5*length/cfg.size,0))
        ucurve_interval[k]=interval
        command = "curve "+str(k)+" interval "+str(interval)
        cubit.cmd(command)
        #cubit_error_stop(iproc,command,ner)
        command = "curve "+str(k)+" scheme equal"
        cubit.cmd(command)
        #cubit_error_stop(iproc,command,ner)
    if max(ucurve_interval.values()) != min(ucurve_interval.values()):
        schemepave=True
        print 'mesh scheme is set to pave'
        for sk in surf_or:
            command = "surface "+str(sk)+" scheme pave"
            cubit.cmd(command)
    #
    vcurve_interval={}
    for k in vcurve:
        length=cubit.get_curve_length(k)
        interval=int(2*round(.5*length/cfg.size,0))
        vcurve_interval[k]=interval
        command = "curve "+str(k)+" interval "+str(interval)
        cubit.cmd(command)
        #cubit_error_stop(iproc,command,ner)
        command = "curve "+str(k)+" scheme equal"
        cubit.cmd(command)
        #cubit_error_stop(iproc,command,ner)

    if max(vcurve_interval.values()) != min(vcurve_interval.values()):
        print 'mesh scheme is set to pave'
        schemepave=True
        for sk in surf_or:
            command = "surface "+str(sk)+" scheme pave"
            cubit.cmd(command)
    #
    for s in surf_vertical:
        lcurve=cubit.get_relatives("surface",s,"curve")
        interval_store=[]
        for k in lcurve:
            interval_curve=cubit.get_mesh_intervals('curve',k)
            if k in list_curve_vertical:
                volume_id = cubit.get_owning_volume("curve", k)
                for idv in range(0,nvol):
                    if vol[idv].ID == volume_id:
                        int_v=vol[idv].intervalv
                command = "curve "+str(k)+" interval "+str(int_v)
                cubit.cmd(command)
                #cubit_error_stop(iproc,command,ner)
                command = "curve "+str(k)+" scheme equal"
                cubit.cmd(command)
                #cubit_error_stop(iproc,command,ner)
            else:
                interval_store.append((k,interval_curve))
            if len(interval_store) != 0:
                interval_min=min([iv[1] for iv in interval_store])
                command = "curve "+' '.join(str(iv[0]) for iv in interval_store)+" interval "+str(interval_min)
                cubit.cmd(command)
                #cubit_error_stop(iproc,command,ner)
                command = "curve "+' '.join(str(iv[0]) for iv in interval_store)+" scheme equal"
                cubit.cmd(command)
                #cubit_error_stop(iproc,command,ner)
        command = "surface "+str(s)+" scheme submap"
        cubit.cmd(command)
        
    #cubit_error_stop(iproc,command,ner)
    #
    #meshing
    if cfg.or_mesh_scheme == 'pave' or schemepave:
        command='mesh surf '+' '.join(str(t) for t in top)
        status=cubit_command_check(iproc,command,stop=True)
        #cubit.cmd(command)    
    elif cfg.or_mesh_scheme == 'map':
        command='mesh surf '+' '.join(str(t) for t in bottom)
        status=cubit_command_check(iproc,command,stop=True)
        #cubit.cmd(command)
    for id_volume in range(nvol-1,-1,-1):
        command = "mesh vol "+str(vol[id_volume].ID)
        status=cubit_command_check(iproc,command,stop=False)
        if not status:
            for s in surf_vertical:
                command_surf="mesh surf "+str(s)
                cubit.cmd(command_surf)
            command_set_meshvol='volume all redistribute nodes on\nvolume all autosmooth target off\nvolume all scheme Sweep Vector 0 0 -1\nvolume all sweep smooth Auto\n'
            status=cubit_command_check(iproc,command_set_meshvol,stop=False)
            status=cubit_command_check(iproc,command,stop=True)    
    
    #
    #smoothing
    print iproc, 'untangling...'
    cmd="volume all smooth scheme untangle beta 0.02 cpu 10"
    cubit.cmd(cmd)
    cmd="smooth volume all"
    cubit.cmd(cmd)
    
    
    
    if  cfg.smoothing:
        print 'smoothing .... '+str(cfg.smoothing)
        cubitcommand= 'surf all smooth scheme laplacian '
        cubit.cmd(cubitcommand)
        cubitcommand= 'smooth surf all'
        cubit.cmd(cubitcommand)
        #
        cubitcommand= 'vol all smooth scheme laplacian '
        cubit.cmd(cubitcommand)
        cubitcommand= 'smooth vol all'
        cubit.cmd(cubitcommand)
    #
    #
    ##vertical refinement
    ##for nvol = 3 
    ##
    ##___________________________ interface 4
    ##                 
    ##vol 2              
    ##___________________________ interface 3
    ##
    ##vol 1
    ##___________________________ interface 2
    ##
    ##vol 0
    ##___________________________ interface 1
    ##
    refinement(nvol,vol,filename=filename)
    #
    #top layer vertical coarsening
    print 'coarsening top layer... ',cfg.coarsening_top_layer
    if  cfg.coarsening_top_layer:
        from sets import Set
        cubitcommand= 'del mesh vol '+str(vol[-1].ID)+ ' propagate'
        cubit.cmd(cubitcommand)
        s1=Set(list_curve_vertical)
        command = "group 'list_curve_tmp' add curve "+"in vol "+str(vol[-1].ID)
        cubit.cmd(command)
        group=cubit.get_id_from_name("list_curve_tmp")
        list_curve_tmp=cubit.get_group_curves(group)
        command = "delete group "+ str(group)
        cubit.cmd(command)
        s2=Set(list_curve_tmp)
        lc=list(s1 & s2)
        #
        cubitcommand= 'curve '+' '.join(str(x) for x in lc)+' interval '+str(cfg.actual_vertical_interval_top_layer)
        cubit.cmd(cubitcommand)
        cubitcommand= 'mesh vol '+str(vol[-1].ID)
        cubit.cmd(cubitcommand)
    #
    n=cubit.get_sideset_id_list()
    if len(n) != 0:
        command = "del sideset all"
        cubit.cmd(command)
    n=cubit.get_block_id_list()
    if len(n) != 0:    
        command = "del block all"
        cubit.cmd(command)
    #
    import boundary_definition
    entities=['face']
    print iproc, 'hex block definition...'
    boundary_definition.define_bc(entities,parallel=True,cpux=cfg.cpux,cpuy=cfg.cpuy,cpuxmin=0,cpuymin=0,optionsea=False)
    #save mesh
    
    print iproc, 'untangling...'
    cmd="volume all smooth scheme untangle beta 0.02 cpu 10"
    cubit.cmd(cmd)
    cmd="smooth volume all"
    cubit.cmd(cmd)
    
    print iproc, 'saving...'
    savemesh(mpiflag,iproc=iproc,filename=filename)
Beispiel #40
0
def double_split_desc(Ca,Cb,Ca1name='_1',Ca2name='_2',Cb1name='_1',Cb2name='_2'):
    if type(Ca) is int:
        Ca1,Ca2,Cb1,Cb2 = double_split(cubit.curve(Ca),cubit.curve(Cb),Ca1name,Ca2name,Cb1name,Cb2name)
    elif type(Ca) is str:
        Ca1,Ca2,Cb1,Cb2 = double_split(cubit.curve(cubit.get_id_from_name(Ca)),cubit.curve(cubit.get_id_from_name(Cb)),Ca1name,Ca2name,Cb1name,Cb2name)
    return Ca1,Ca2,Cb1,Cb2  
def collecting_merging_new(cpuxmin=0,cpuxmax=0,cpuymin=0,cpuymax=0,cpux=1,cpuy=1,cubfiles=False,check_merging=False):
    import glob
    import re
    #
    ##
    try:
        from boundary_definition import check_bc, map_boundary
    except:
        pass
    #
    print 'cpu',cpuxmin,cpuxmax,cpuymin,cpuymax
    xmin,xmax,ymin,ymax,listfull=map_boundary(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy)
    #
    if cubfiles:
        nf,listip,filenames,cubflag=importing_cubfiles(cubfiles)
        print nf,listip,filenames,cubflag,listfull
    else:
        nf=0
        filenames=[]
        ip=0
    #
    
    index_block=-1
    store_group_name=[]
    side_name=['topo','xmin','ymin','xmax','ymax','bot']
    side_val=['1001','1003','1004','1005','1006','1002']
    side_block_name=['face_topo','face_abs_xmin','face_abs_ymin','face_abs_xmax','face_abs_ymax','face_abs_bottom']
    cubit.cmd('set duplicate block elements on')
    
    if nf > 0:
        for ip,filename in zip(listip,filenames):
            print ip,filename,ip in listfull
            try:
                if ip in listfull:
                    print filename
                    index_block=index_block+1
                    if cubflag:
                        cubit.cmd('import cubit "'+filename+'"')
                    else:
                        cubit.cmd('import mesh "'+filename+'" block all  no_geom')
            except:
                cubit.cmd('import mesh "'+filename+'" block all  no_geom')
            #print ip,xmin,xmax,ymin,ymax,ip in xmin,ip in xmax,ip in ymin,ip in ymax
            store_tmp=collecting_block(store_group_name,ip,xmin,xmax,ymin,ymax,index_block)
            if len(store_tmp)!=0: store_group_name=store_tmp
            print check_lateral_nodes()
            
        #cubit.cmd('export mesh "tmp_collect_NOmerging.e" dimension 3 block all overwrite')
        cubit.cmd('save as "tmp_nomerging.cub" overwrite ')
                    
    else:
        #if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
        boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax+1,cpuymin,cpuymax+1)
        cubit.cmd('disassociate mesh from volume all')
        cubit.cmd('del vol all')
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        return

    
    if check_merging:
        print 'cpu',cpuxmin,cpuxmax,cpuymin,cpuymax
        nodes_before_ymin=check_lateral_nodes('ymin')
        nlatline_ymin=(cpuxmax-cpuxmin)-1
        print 'lines',nlatline_ymin
        nodes_before_xmin=check_lateral_nodes('xmin')
        nlatline_xmin=(cpuymax-cpuymin)-1
        print 'lines',nlatline_xmin
        nodes_before_all=check_lateral_nodes()
    
    factor,minvalue,inv_length=prepare_equivalence_new()
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    #cubit.cmd('set error off')
    for k in inv_length.keys():
        print k, 'tolerance', str(k*factor+minvalue/2.)
        check_lateral_nodes()
        if len(inv_length[k]) > 0:
            print 'equivalence node in '+str(len(inv_length[k]))+' edges  tolerance '+str(k*factor+minvalue/2.)
            cmd='equivalence node in edge '+' '.join(str(x) for x in inv_length[k])+' tolerance '+str(k*factor+minvalue/2.)
            cubit.cmd(cmd)
    
    if check_merging:
        nodes_after_all=check_lateral_nodes()
        nodes_after_ymin=check_lateral_nodes('ymin')
        if nlatline_ymin !=0: 
            node_lines_ymin=(nodes_before_ymin-nodes_after_ymin)/nlatline_ymin
        else:
            node_lines_ymin=0
        nodes_after_xmin=check_lateral_nodes('xmin')
        if nlatline_xmin !=0: 
            node_lines_xmin=(nodes_before_xmin-nodes_after_xmin)/nlatline_xmin
        else:
            node_lines_xmin=0
        if node_lines_xmin and nlatline_ymin:
            checklines = node_lines_xmin == node_lines_ymin
        else:
            checklines=True
            
        checknodes = nodes_before_all == 2*(nodes_after_all+node_lines_xmin*(nlatline_xmin*nlatline_ymin))
        print 'check lines',checklines
        print 'check nodes',checknodes
        if not checknodes:
            diff_nodes=-nodes_before_all + 2*(nodes_after_all+node_lines_xmin*(nlatline_xmin*nlatline_ymin))
            print diff_nodes
            for tol in range(100,10000,100):
                cubit.cmd('topology check coincident node node in face in group lateral tolerance '+str(tol)+' draw brief result group "diff_node"')
                idiff=cubit.get_id_from_name('diff_node')
                idnodes=cubit.get_group_nodes(idiff)
                if len(idnodes)==diff_nodes:
                    print diff_nodes,idnodes
                    cmd='equivalence node '+' '.join(str(x) for x in idnodes)+' tolerance '+str(tol)
                    cubit.cmd(cmd)
                    break
            
            nodes_after_all=check_lateral_nodes()
            checknodes = nodes_before_all == 2*(nodes_after_all+node_lines_xmin*(nlatline_xmin*nlatline_ymin))
            print 'check nodes',checknodes
            
    else:
        print 'no merging check'
        checklines = True
        checknodes = True
    
    if checknodes and checklines:
        for ig,g in enumerate(store_group_name):
            cubit.cmd('block '+str(ig+1)+' hex in group '+g)
            cubit.cmd('block '+str(ig+1)+' name "vol'+str(ig+1)+'"')
            print 'block '+str(ig+1)+' hex in group '+g
        for ig,g in enumerate(side_name):
            cubit.cmd('block '+side_val[ig]+' face in group '+g)
            print 'block '+side_val[ig]+' face in group '+g
            cubit.cmd('block '+side_val[ig]+' name "'+side_block_name[ig]+'"')
        cubit.cmd('del group all')
    else:
        raise MergingError('merging failed... please check the blocks')
    
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
def save_elements_nodes(name, quads_fault_u, quads_fault_d):
    print('')
    print('## save fault nodes elements: file = ', name)
    print('##')
    fault_file = open(name, 'w')
    txt = ''
    list_hex = cubit.parse_cubit_list('hex', 'all')

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

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

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

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

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

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

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

            fault_file.write(txt)

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

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

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

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

            fault_file.write(txt)

    fault_file.close()

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

    print('## done fault file: ', name)
    print('')
print "Playback journal file..."
with open(journalFile) as f:
    content = f.readlines()
for line in content:
    cubit.cmd(line)

# ==================================================
#         Save the mesh to txt files
#      This part is revised from the code of Specfem3D
# ==================================================
print ""
print "Convert mesh to Specfem-format..."
os.system('mkdir -p MESH')

## fault surfaces (up/down)
Au = [cubit.get_id_from_name("fault1")]
Ad = [cubit.get_id_from_name("fault2")]

### Obtain the id of boundaries
# I define the original sphere surface as spheresurf. After webcut, CUBIT renames the new-cutted surface by adding @A, @B ...
SpheresurfID = [cubit.get_id_from_name("spheresurf@A")]
# Find the surface ID for the free surface
freesur_tolerance = 3e3
FreesurfID = []
list_surf = cubit.parse_cubit_list("surface", "all")
for k in list_surf:
    center_point = cubit.get_center_point("surface", k)
    if abs(center_point[2]) <= freesur_tolerance:
        FreesurfID.append(k)

print SpheresurfID, FreesurfID
Beispiel #44
0
def destroy_curve_desc(Cdesc):
    if type(Cdesc) is int:
        destroy_curve(cubit.curve(Cdesc))
    elif type(Cdesc) is str:
        destroy_curve(cubit.curve(cubit.get_id_from_name(Cdesc)))
    return None   
Beispiel #45
0
def curver_bias_desc(Cdesc,dx,biasfactor,direction='l'):
    if type(Cdesc) is int:
        curver_bias(cubit.curve(Cdesc),dx,biasfactor,direction)
    elif type(Cdesc) is str:
        curver_bias(cubit.curve(cubit.get_id_from_name(Cdesc)),dx,biasfactor,direction)
    return None
def geom_cubit_main(configfile):
    if not os.path.isfile(configfile) :
        raise Exception("ERR: CONFIG FILE DON'T EXIST !!!")
    #  READ CONFIGFILE
    cf = ConfigParser.ConfigParser()
    cf.read(configfile)
    experience_name = cf.get('Input','experience_name')
    bathyfile = cf.get('Input','bathyfile')
    slabfile = cf.get('Input','slabfile')
    left_extension=cf.getfloat('Parameters','left_extension') # (always positive)
    right_extension=cf.getfloat('Parameters','right_extension')
    down_limit=cf.getfloat('Parameters','down_limit') # (always positive)
    EET_OP=cf.getfloat('Parameters','EET_OP') #  Thickness of the OP Litho
    EET_DP=cf.getfloat('Parameters','EET_DP') #  Thickness of the DP Litho
    backstop_bool=cf.getboolean('Parameters','backstop_bool') # True or False
    x_backstop=cf.getfloat('Parameters','x_backstop')
    dip_backstop=cf.getfloat('Parameters','dip_backstop')
    output_path=cf.get('Output','output_path')
    output_file_prefix=cf.get('Output','output_file_prefix')
    output_pathfile = output_path + '/'  + output_file_prefix + '_'  + experience_name + '.exo'
    # =======================================================================
    #  PRIOR DESIGN
    # =======================================================================
    # Loading the BATHY and SLAB files
    XYbathy = np.loadtxt(bathyfile)
    XYslab = np.loadtxt(slabfile)
    # Creating the bottom of the slab
    XslabBot,YslabBot,_ = gcl.shift_thickness(XYslab[:,0],XYslab[:,1],EET_DP)
    # Creating the bounding points in a dictionnary
    outpts = gcl.make_bounding_points(XYbathy[:,0],XYbathy[:,1],XYslab[:,0],XYslab[:,1],EET_OP,EET_DP,down_limit,left_extension,right_extension)
    # Creating the backstop
    Xbackstop,Ybackstop = gcl.make_backstop(XYbathy[:,0],XYbathy[:,1],XYslab[:,0],XYslab[:,1],x_backstop,dip_backstop,dupdown=150)
    # Adding the 'Bottom_Litho_DP' point to the Litho_DP Bottom
    gcl.add_point_in_list(XslabBot,YslabBot,outpts['vBottom_Litho_DP'])
    # Changing the description concept : Bathy & Slab ==> OP & DP
    Xop,Yop,Xdp,Ydp = gcl.bathyslab_2_OPDPtop(XYbathy[:,0],XYbathy[:,1],XYslab[:,0],XYslab[:,1])
    # Adding the limit points of OP & DP
    Xop,Yop = gcl.add_point_in_list(Xop,Yop,outpts['vBathy_OP'])
    Xdp,Ydp = gcl.add_point_in_list(Xdp,Ydp,outpts['vBathy_DP'])
    # PLOT FOR SECURITY
    #plt.clf()
    #plt.axis('equal')
    #plt.plot(XYbathy[:,0],XYbathy[:,1],'+b')
    #plt.plot(XYslab[:,0],XYslab[:,1],'r+-')
    #plt.plot(XslabBot,YslabBot,'k+-')
    #plt.plot(Xbackstop,Ybackstop,'*-y')
    #for p in outpts.viewvalues():
    #    plt.plot(p[0],p[1],'*k')
    #plt.plot(Xop,Yop,'b-')
    #plt.plot(Xdp,Ydp,'r-')
    # =======================================================================
    #  CUBIT MESHING
    # =======================================================================
    # Initalisation
    cubit.cmd('reset')  
    cubit.cmd("#{Units('si')}")  
    # Chargement des courbes
    gcl.list_2_curve(Xop,Yop,'Top_Litho_OP')
    gcl.list_2_curve(Xdp,Ydp,'Top_Litho_limit_DP')
    gcl.list_2_curve(XslabBot,YslabBot,'Bottom_Litho_DP')
    gcl.list_2_curve(Xbackstop,Ybackstop,'Backstop')
    # Chargement des Points Isolés
    gcl.dico_2_listofvertices(outpts)
    ## fabrication de "courbes-segments" a partir de vertex
    v_Bottom_Litho_OP = cubit.vertex(cubit.get_id_from_name('vBottom_Litho_OP'))
    v_Bathy_DP = gcl.find_extrema(cubit.curve(cubit.get_id_from_name("Top_Litho_limit_DP")),'r')
    v_Bathy_OP = gcl.find_extrema(cubit.curve(cubit.get_id_from_name('Top_Litho_OP')),'l')
    v_Bottom_Litho_DP = gcl.find_extrema(cubit.curve(cubit.get_id_from_name("Bottom_Litho_DP")),'r')
    v_scratch = cubit.vertex(cubit.get_id_from_name('vscratch'))
    v_Bottom_Astheno_OP = cubit.vertex(cubit.get_id_from_name('vBottom_Astheno_OP'))
    v_Bottom_Astheno_DP = cubit.vertex(cubit.get_id_from_name('vBottom_Astheno_DP'))
    # 
    gcl.vertices_2_curve(v_Bottom_Litho_OP,v_Bottom_Astheno_OP,'Edge_Astheno_OP')
    gcl.vertices_2_curve(v_Bottom_Litho_OP,v_scratch,'Bottom_Litho_OP_PROTO')
    gcl.vertices_2_curve(v_Bottom_Litho_OP,v_Bathy_OP,'Edge_Litho_OP')
    gcl.vertices_2_curve(v_Bottom_Astheno_OP,v_Bottom_Astheno_DP,'Bottom_PROTO')
    gcl.vertices_2_curve(v_Bathy_DP,v_Bottom_Litho_DP,'Edge_Litho_DP')
    gcl.vertices_2_curve(v_Bottom_Litho_DP,v_Bottom_Astheno_DP,'Edge_Astheno_DP') 
    ## Split des courbes
    gcl.double_split_desc(2,6)
    gcl.double_split_desc(8,11)
    gcl.double_split_desc(16,3)
    gcl.double_split_desc(4,12)
    gcl.double_split_desc(1,23)
    gcl.double_split_desc(26,28)
    ## suppression des petits morceaux
    gcl.destroy_curve(cubit.curve(14))
    gcl.destroy_curve(cubit.curve(24))
    gcl.destroy_curve(cubit.curve(17))
    gcl.destroy_curve(cubit.curve(21))
    gcl.destroy_curve(cubit.curve(29))
    ## renommage des courbes
    gcl.rename_curve_desc(7,'Edge_Litho_OP')
    gcl.rename_curve_desc(5,'Edge_Astheno_OP')
    gcl.rename_curve_desc(9,'Edge_Litho_DP')
    gcl.rename_curve_desc(10,'Edge_Astheno_DP')
    gcl.rename_curve_desc(25,'Contact_OP_DP')
    gcl.rename_curve_desc(31,'Contact_Prism_DP')
    gcl.rename_curve_desc(30,'Contact_Prism_OP')
    gcl.rename_curve_desc(32,'Top_Litho_DP')
    gcl.rename_curve_desc(33,'Top_Prism')
    gcl.rename_curve_desc(27,'Top_Litho_OP')
    gcl.rename_curve_desc(20,'Bottom_Astheno_DP')
    gcl.rename_curve_desc(22,'Bottom_Litho_DP')
    gcl.rename_curve_desc(15,'Bottom_Astheno_OP')
    gcl.rename_curve_desc(13,'Bottom_Litho_OP')
    gcl.rename_curve_desc(19,'Front_Litho_DP')
    gcl.rename_curve_desc(18,'Astheno_Litho_Contact')
    # creation des surfaces
    gcl.create_surface_desc([10,20,22])
    gcl.create_surface_desc([19,18,25,31,32,9,22])
    gcl.create_surface_desc([13,18,15,5])
    gcl.create_surface_desc([13,7,27,30,25])
    gcl.create_surface_desc([30,31,33])
    # renomage des surfaces
    cubit.surface(1).entity_name('Astheno_DP')
    cubit.surface(2).entity_name('Litho_DP')
    cubit.surface(3).entity_name('Astheno_OP')
    cubit.surface(4).entity_name('Litho_OP')
    cubit.surface(5).entity_name('Prisme')
    # Fusion des surfaces
    cubit.cmd('delete vertex all')
    cubit.cmd('imprint all')
    cubit.cmd('merge all')
    cubit.cmd('stitch volume all')
    cubit.cmd('surface all scheme trimesh')
    cubit.cmd('curve all scheme default')
    cubit.cmd('surface all sizing function none')
    # nouveau decoupage des courbes
    dx1 = 4.0
    dx2 = 25.0
    dx3 = 8
    b1=1.1
    gcl.curver_desc("Contact_Prism_DP",dx1)
    gcl.curver_desc("Contact_Prism_OP",dx1)
    gcl.curver_desc("Top_Prism",dx1)
    gcl.curver_desc("Bottom_Litho_DP",dx2)
    gcl.curver_desc("Bottom_Astheno_OP",dx2)
    gcl.curver_desc("Front_Litho_DP",dx2)
    gcl.curver_desc("Bottom_Astheno_DP",dx2)
    gcl.curver_desc("Edge_Astheno_OP",dx2)
    gcl.curver_desc("Edge_Litho_OP",dx2)
    gcl.curver_desc("Edge_Astheno_DP",dx2)
    gcl.curver_desc("Edge_Litho_DP",dx2)
    gcl.curver_desc("Contact_OP_DP",dx1)
    gcl.curver_start_end_desc("Bottom_Litho_OP",dx1,dx2,'l')
    gcl.curver_start_end_desc("Top_Litho_OP",dx1,dx2,'l')
    gcl.curver_start_end_desc("Top_Litho_DP",dx1,dx2,'r')
    gcl.curver_start_end_desc("Astheno_Litho_Contact",dx1,dx2,'l')  
    # fabrication du mesh
    cubit.cmd('mesh surface all')
    cubit.cmd('surface all smooth scheme condition number beta 1.7 cpu 10')
    cubit.cmd('smooth surface all')
    cubit.cmd('surface 1 size auto factor 5')
    ## Fabrication de groupe et de nodeset
    for i,s in enumerate(cubit.get_entities("surface")):
        S = cubit.surface(s)
        cubit.cmd('block ' + str(i+1) + ' surface ' + S.entity_name())
        cubit.cmd('block ' + str(i+1) + ' name "' + S.entity_name() + ' "' )
    gcl.create_group_nodeset_desc(['Astheno_Litho_Contact','Contact_OP_DP','Contact_Prism_DP'],"fault_top",20)     
    gcl.create_group_nodeset_desc(['Top_Litho_OP','Top_Prism','Top_Litho_DP'],"ground_surface",20)     
    gcl.create_group_nodeset_desc(['Bottom_Litho_OP'],"bottom_litho_OP",20)     
    gcl.create_group_nodeset_desc(['Bottom_Litho_DP'],"bottom_litho_DP",20)     
    gcl.create_group_nodeset_desc(['Bottom_Astheno_DP','Bottom_Astheno_OP'],"bottom_astheno",20) 
    gcl.create_group_nodeset_desc(['Edge_Litho_OP'],"edge_litho_OP",20) 
    gcl.create_group_nodeset_desc(['Edge_Litho_DP'],"edge_litho_DP",20) 
    gcl.create_group_nodeset_desc(['Edge_Astheno_OP'],"edge_astheno_OP",20) 
    gcl.create_group_nodeset_desc(['Edge_Astheno_DP'],"edge_astheno_DP",20) 
    gcl.create_group_nodeset_desc(['Front_Litho_DP'],"front_litho_DP",20) 
    gcl.create_group_nodeset_desc(['Contact_Prism_OP'],"contact_prism_OP",20)
    # ecriture fichier final
    cubit.cmd('export mesh "' + output_pathfile + '" dimension 2 overwrite')
    return None
def get_ordered_node_surf(lsurface,icurve):
    if not isinstance(lsurface,str):
        lsurf=list2str(lsurface)
    #
    if not isinstance(icurve,str):
        icurvestr=str(icurve)
    orient_nodes_surf=[]
    #
    #get the nodes on a surface, I don't use the method get_surface_nodes since it has different behavior in cubit12.2 and cubit13.2+
    k=cubit.get_id_from_name('sl')
    if k!=0:
        cubit.cmd('del group sl')
    else:
        print 'initializing group sl'
    cubit.cmd("group 'sl' add node in surf "+lsurf)
    group1 = cubit.get_id_from_name("sl")
    nodes_ls =list(cubit.get_group_nodes(group1))
    nnode=len(nodes_ls)
    #
    #get the nodes on curves
    orient=[]
    k=cubit.get_id_from_name('n1')
    if k!=0:
        cubit.cmd('del group n1')
    else:
        print 'initializing group n1'
    cubit.cmd("group 'n1' add node in curve "+icurvestr)
    x=cubit.get_bounding_box('curve', icurve)
    if x[2]>x[5]:
        idx=0
    else:
        idx=1
    group1 = cubit.get_id_from_name("n1")
    nodes1 = list(cubit.get_group_nodes(group1))
    for n in nodes1:
        v = cubit.get_nodal_coordinates(n)
        orient.append(v[idx])
    result=zip(orient,nodes1)
    result.sort()
    nodes2=[c[1] for c in result]
    for n in nodes2:
        try:
            nodes_ls.remove(n)
        except:
            pass
    orient_nodes_surf=orient_nodes_surf+nodes2
    #
    while len(orient_nodes_surf) < nnode:
        cubit.cmd('del group n1')
        cubit.cmd("group 'n1' add node in edge in node "+str(nodes2).replace('[',' ').replace(']',' '))
        group1 = cubit.get_id_from_name("n1")
        nodes1 = list(cubit.get_group_nodes(group1))
        orient=[]
        nd=[]
        for n in nodes1:
            if n in nodes_ls:
                v = cubit.get_nodal_coordinates(n)
                orient.append(v[idx])
                nd.append(n)
        result=zip(orient,nd)
        result.sort()
        nodes2=[c[1] for c in result]
        for n in nodes2:
            try:
                nodes_ls.remove(n)
            except:
                pass
        orient_nodes_surf=orient_nodes_surf+nodes2
    #get the vertical curve
    curve_vertical=[]
    for s in lsurface:
        lcs=cubit.get_relatives("surface",s,"curve")
        for l in lcs:
            x=cubit.get_bounding_box('curve', l)
            length=[(x[2],1),(x[5],2),(x[8],3)]
            length.sort()
            if length[-1][1] == 3:
                curve_vertical.append(l)
    #
    kcurve=list2str(curve_vertical)
    k=cubit.get_id_from_name('curve_vertical')
    if k!=0:
        cubit.cmd('del group curve_vertical')
    else:
        print 'initializing group curve_vertical'
    cubit.cmd("group 'curve_vertical' add node in curve "+kcurve)
    group1 = cubit.get_id_from_name('curve_vertical')
    nodes_curve = list(cubit.get_group_nodes(group1))
    for n in nodes_curve:
        try:
            orient_nodes_surf.remove(n)
        except:
            pass
    #
    return nodes_curve,orient_nodes_surf
Beispiel #48
0
def rename_curve_desc(Cdesc,newname):
    if type(Cdesc) is int:
        rename_curve(cubit.curve(Cdesc),newname)
    elif type(Cdesc) is str:
        rename_curve(cubit.curve(cubit.get_id_from_name(Cdesc)),newname)
    return None
Beispiel #49
0
def save_elements_nodes(name, quads_fault_u, quads_fault_d):
    fault_file = open(name, 'w')
    txt = ''
    list_hex = cubit.parse_cubit_list('hex', 'all')
    txt = '%10i %10i\n' % (len(quads_fault_u), len(quads_fault_d))
    fault_file.write(txt)

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

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

                fault_file.write(txt)

    # FAULT SIDE UP

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

                fault_file.write(txt)

    fault_file.close()
Beispiel #50
0
def curver_start_end_desc(Cdesc,dx1,dx2,direction='l'):
    if type(Cdesc) is int:
        curver_start_end(cubit.curve(Cdesc),dx1,dx2,direction)
    elif type(Cdesc) is str:
        curver_start_end(cubit.curve(cubit.get_id_from_name(Cdesc)),dx1,dx2,direction)
    return None    
def collecting_merging(cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,ckbound_method1=False,ckbound_method2=False,merge_tolerance=None,decimate=False):
    import glob
    import re
    #
    rule_st=re.compile("(.+)_[0-9]+\.")
    rule_ex=re.compile(".+_[0-9]+\.(.+)")
    rule_int=re.compile(".+_([0-9]+)\.")
    boundary_dict={}
    ##
    try:
        from boundary_definition import check_bc, map_boundary
    except:
        pass
    #
    xmin,xmax,ymin,ymax,listfull=map_boundary(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy)
    #
    if cubfiles:
        nf,listip,filenames,cubflag=importing_cubfiles(cubfiles)
    else:
        nf=0
        filenames=[]
        ip=0
    #
    if nf > 0:
        for ip,filename in zip(listip,filenames):
            try:
                if ip in listfull:
                    if cubflag:
                        cubit.cmd('import cubit "'+filename+'"')
                    else:
                        cubit.cmd('import mesh geometry "'+filename+'" block all use nodeset sideset feature_angle 135.00 linear merge')
                    if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
                    boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax,cpuymin,cpuymax)
                    boundary_dict[ip]=boundary
                    list_vol=list(cubit.parse_cubit_list('volume','all'))
                    for v in list_vol:
                        cubit.cmd("disassociate mesh from volume "+str(v))
                        command = "del vol "+str(v)
                        cubit.cmd(command)
            except:
                cubit.cmd('import mesh geometry "'+filename+'" block all use nodeset sideset feature_angle 135.00 linear merge')
                if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
                ip=0
                boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax,cpuymin,cpuymax)
                boundary_dict[ip]=boundary
                list_vol=list(cubit.parse_cubit_list('volume','all'))
                for v in list_vol:
                    cubit.cmd("disassociate mesh from volume "+str(v))
                    command = "del vol "+str(v)
                    cubit.cmd(command)
        cubit.cmd('export mesh "tmp_collect_NOmerging.e" dimension 3 block all overwrite')
    else:
        if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
        boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax,cpuymin,cpuymax)
    #
    #
    #print boundary_dict
    block_list=cubit.get_block_id_list()
    for block in block_list:
        ty=cubit.get_block_element_type(block)
        if ty == 'HEX8':
            cubit.cmd('block '+str(block)+' name "vol'+str(block)+'"')
    #
    #
    print 'chbound',ckbound_method1,ckbound_method2
    
    
    if ckbound_method1 and not ckbound_method2 and len(filenames) != 1:
        #use the equivalence method for groups
        if isinstance(merge_tolerance,list):
            tol=merge_tolerance[0]
        elif merge_tolerance:
            tol=merge_tolerance
        else:
            tol=100000
        #
        idiag=None
        #cubit.cmd('set info off')
        #cubit.cmd('set journal off')
        #cubit.cmd('set echo off')
        ind=0
        for ix in range(cpuxmin,cpuxmax):
            for iy in range(cpuymin,cpuymax):
                ind=ind+1
                ip=iy*cpux+ix
                print '******************* ',ip, ind,'/',len(listfull)
                #
                #   ileft    |   ip
                #  --------------------
                #   idiag    |   idown
                #
                #
                if ip not in xmin and ip not in ymin:
                    ileft=iy*cpux+ix-1
                    idown=(iy-1)*cpux+ix
                    idiag=idown-1
                elif ip in xmin and ip in ymin:
                    ileft=ip
                    idown=ip
                    idiag=None
                elif ip in xmin:
                    ileft=ip
                    idown=(iy-1)*cpux+ix
                    idiag=idown
                elif ip in ymin:
                    ileft=iy*cpux+ix-1
                    idown=ip
                    idiag=ileft
                #
                print ip,ileft,idiag,idown
                if ip != idown:
                    nup=boundary_dict[ip]['nodes_surf_ymin']
                    ndow=boundary_dict[idown]['nodes_surf_ymax']
                    merge_node_ck(nup,ndow)
                 
                    if idiag != idown:
                        if ip in ymax and ip not in xmin:
                            nlu=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck left up... r u
                            nru=boundary_dict[ileft]['node_curve_xmaxymax']
                            merge_node(nlu,nru)
                        if ip in xmax:
                            nrd=boundary_dict[ip]['node_curve_xmaxymin'] #node in curve chunck left up... r u
                            nru=boundary_dict[idown]['node_curve_xmaxymax']
                            merge_node(nrd,nru)
                        nru=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xminymax']
                        nld=boundary_dict[idiag]['node_curve_xmaxymax']
                        nlu=boundary_dict[ileft]['node_curve_xmaxymin']
                        merge_node_4(nru,nrd,nld,nlu)
                    elif ip in xmin:
                        nlu=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nld=boundary_dict[idown]['node_curve_xminymax']
                        merge_node(nld,nlu)
                        nru=boundary_dict[ip]['node_curve_xmaxymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xmaxymax']
                        merge_node(nrd,nru)
                        
                        
                        
                        
                #
                if ip != ileft:
                    nright=boundary_dict[ip]['nodes_surf_xmin']
                    nleft=boundary_dict[ileft]['nodes_surf_xmax']
                    merge_node_ck(nright,nleft)
                    #
                    #
                    if ip in ymin:
                        nrd=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right down... r u
                        nld=boundary_dict[ileft]['node_curve_xmaxymin']
                        merge_node(nrd,nld)
                    if ip in ymax:
                        nru=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck right up... r u
                        nlu=boundary_dict[ileft]['node_curve_xmaxymax']
                        merge_node(nlu,nru)
        
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        
        
        #
        #
        cmd='group "negativejac" add quality hex all Jacobian high'
        cubit.cmd(cmd) 
        group_id_1=cubit.get_id_from_name("negativejac")
        n1=cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, use --merge2 instead of --equivalence/--merge/--merge1'
    elif ckbound_method2 and not ckbound_method1 and len(filenames) != 1:
        if isinstance(merge_tolerance,list):
            tol=merge_tolerance[0]
        elif merge_tolerance:
            tol=merge_tolerance
        else:
            tol=100000
        #
        idiag=None
        for ix in range(cpuxmin,cpuxmax):
            for iy in range(cpuymin,cpuymax):
                ip=iy*cpux+ix
                print '******************* ',ip
                #
                #   ileft    |   ip
                #  --------------------
                #   idiag    |   idown
                #
                #
                if ip not in xmin and ip not in ymin:
                    ileft=iy*cpux+ix-1
                    idown=(iy-1)*cpux+ix
                    idiag=idown-1
                elif ip in xmin and ip in ymin:
                    ileft=ip
                    idown=ip
                elif ip in xmin:
                    ileft=ip
                    idown=(iy-1)*cpux+ix
                    idiag=idown
                elif ip in ymin:
                    ileft=iy*cpux+ix-1
                    idown=ip
                    idiag=ileft
                #
                #
                if ip != idown:
                    nup=boundary_dict[ip]['nodes_surf_ymin']
                    ndow=boundary_dict[idown]['nodes_surf_ymax']
                    for n1,n2 in zip(nup,ndow):
                        cubit.cmd('equivalence node '+str(n1)+' '+str(n2)+' tolerance '+str(tol))
                    if idiag != idown:
                        if ip in ymax and ip not in xmin:
                            nlu=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck left up... r u
                            nru=boundary_dict[ileft]['node_curve_xmaxymax']
                            for n in zip(nlu,nru):
                                cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                        nru=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xminymax']
                        nld=boundary_dict[idiag]['node_curve_xmaxymax']
                        nlu=boundary_dict[ileft]['node_curve_xmaxymin']
                        for n in zip(nru,nrd,nlu,nld):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                    elif ip in xmin:
                        nru=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xminymax']
                        for n in zip(nru,nrd):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                #
                #
                if ip != ileft:
                    nright=boundary_dict[ip]['nodes_surf_xmin']
                    nleft=boundary_dict[ileft]['nodes_surf_xmax']
                    for n1,n2 in zip(nleft,nright):
                        cubit.cmd('equivalence node '+str(n1)+' '+str(n2)+' tolerance '+str(tol))
                    #
                    #
                    if ip in ymin:
                        nrd=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right down... r u
                        nld=boundary_dict[ileft]['node_curve_xmaxymin']
                        for n in zip(nrd,nld):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                    if ip in ymax:
                        nru=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck right up... r u
                        nlu=boundary_dict[ileft]['node_curve_xmaxymax']
                        for n in zip(nru,nlu):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
        #
        #
        cmd='topology check coincident node face all tolerance '+str(tol*2)+' nodraw brief result group "checkcoinc"' 
        cubit.silent_cmd(cmd)
        group_id_1=cubit.get_id_from_name("checkcoinc")
        if group_id_1 != 0:
            n1=cubit.get_group_nodes(group_id_1)
            if len(n1) != 0:
                print 'error, coincident nodes after the equivalence node command, check the tolerance'
                import sys
                sys.exit()
        cmd='group "negativejac" add quality hex all Jacobian high'
        cubit.cmd(cmd) 
        group_id_1=cubit.get_id_from_name("negativejac")
        n1=cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, check the mesh'
    elif ckbound_method1 and  ckbound_method2 and len(filenames) != 1:
        block_list=cubit.get_block_id_list()
        i=-1
        for block in block_list:
            ty=cubit.get_block_element_type(block)
            if ty == 'HEX8':
                i=i+1
                if isinstance(merge_tolerance,list):
                    try:
                        tol=merge_tolerance[i]
                    except:
                        tol=merge_tolerance[-1]
                elif merge_tolerance:
                    tol=merge_tolerance
                else:
                    tol=1
                cmd='topology check coincident node face in hex in block '+str(block)+' tolerance '+str(tol)+' nodraw brief result group "b'+str(block)+'"'
                cubit.cmd(cmd)
                print cmd
                cmd='equivalence node in group b'+str(block)+' tolerance '+str(tol)
                cubit.cmd(cmd)
                print cmd
        if isinstance(merge_tolerance,list):
            tol=max(merge_tolerance)
        elif merge_tolerance:
            tol=merge_tolerance
        else:
            tol=1
        #
        #
        cmd='topology check coincident node face all tolerance '+str(tol)+' nodraw brief result group "checkcoinc"' 
        cubit.silent_cmd(cmd)
        group_id_1=cubit.get_id_from_name("checkcoinc")
        if group_id_1 != 0:
            n1=cubit.get_group_nodes(group_id_1)
            if len(n1) != 0:
                print 'error, coincident nodes after the equivalence node command, check the tolerance'
                import sys
                sys.exit()
        cmd='group "negativejac" add quality hex all Jacobian high'
        cubit.silent_cmd(cmd) 
        group_id_1=cubit.get_id_from_name("negativejac")
        n1=cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, use --merge instead of --equivalence'
Beispiel #52
0
def mesh_layercake_regularmap(filename=None):

    import start as start
    mpiflag, iproc, numproc, mpi = start.start_mpi()
    from utilities import importgeometry, savemesh, get_v_h_list
    from utilities import cubit_command_check, get_cubit_version
    #
    # numpy = start.start_numpy()
    cfg = start.start_cfg(filename=filename)
    # from math import sqrt

    version_cubit = get_cubit_version()

    list_vol = cubit.parse_cubit_list("volume", "all")
    if len(list_vol) != 0:
        pass
    else:
        geometryfile = 'geometry_vol_' + str(iproc) + '.cub'
        importgeometry(geometryfile, iproc=iproc)

    command = 'composite create curve all'
    cubit.cmd(command)
    print('###"No valid composites can be created from the specified curves." \
          is NOT a critical ERROR.')
    #
    command = "compress all"
    cubit.cmd(command)
    list_vol = cubit.parse_cubit_list("volume", "all")
    nvol = len(list_vol)
    vol = []
    for id_vol in list_vol:
        p = cubit.get_center_point("volume", id_vol)
        vol.append(cubitvolume(id_vol, 1, p[2], 0))
    vol.sort(by_z)
    #
    for id_vol in range(0, nvol):
        vol[id_vol].intervalv = cfg.iv_interval[id_vol]
    #
    #
    surf_vertical = []
    surf_or = []
    # top_surface = 0
    # top_surface_add = ''
    # bottom_surface = 0
    # #
    # zmin_box = cubit.get_total_bounding_box("volume", list_vol)[6]
    # xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0]
    # xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1]
    # ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3]
    # ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4]
    #
    #
    # interval assignement
    surf_or, surf_vertical, list_curve_or, list_curve_vertical, \
        bottom, top = get_v_h_list(list_vol, chktop=cfg.chktop)
    print('vertical surfaces: ', surf_vertical)

    for k in surf_vertical:
        command = "surface " + str(k) + " scheme submap"
        cubit.cmd(command)
    for k in surf_or:
        command = "surface " + str(k) + " scheme " + cfg.or_mesh_scheme
        cubit.cmd(command)
    #
    ucurve, vcurve = get_uv_curve(list_curve_or)
    schemepave = False
    #
    ucurve_interval = {}
    for k in ucurve:
        length = cubit.get_curve_length(k)
        interval = int(2 * round(.5 * length / cfg.size, 0))
        ucurve_interval[k] = interval
        command = "curve " + str(k) + " interval " + str(interval)
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)
        command = "curve " + str(k) + " scheme equal"
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)
    if max(ucurve_interval.values()) != min(ucurve_interval.values()):
        schemepave = True
        print('mesh scheme is set to pave')
        for sk in surf_or:
            command = "surface " + str(sk) + " scheme pave"
            cubit.cmd(command)
    #
    vcurve_interval = {}
    for k in vcurve:
        length = cubit.get_curve_length(k)
        interval = int(2 * round(.5 * length / cfg.size, 0))
        vcurve_interval[k] = interval
        command = "curve " + str(k) + " interval " + str(interval)
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)
        command = "curve " + str(k) + " scheme equal"
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)

    if max(vcurve_interval.values()) != min(vcurve_interval.values()):
        print('mesh scheme is set to pave')
        schemepave = True
        for sk in surf_or:
            command = "surface " + str(sk) + " scheme pave"
            cubit.cmd(command)
    #
    for s in surf_vertical:
        lcurve = cubit.get_relatives("surface", s, "curve")
        interval_store = []
        for k in lcurve:
            interval_curve = cubit.get_mesh_intervals('curve', k)
            if k in list_curve_vertical:
                volume_id = cubit.get_owning_volume("curve", k)
                for idv in range(0, nvol):
                    if vol[idv].ID == volume_id:
                        int_v = vol[idv].intervalv
                command = "curve " + str(k) + " interval " + str(int_v)
                cubit.cmd(command)
                # cubit_error_stop(iproc,command,ner)
                command = "curve " + str(k) + " scheme equal"
                cubit.cmd(command)
                # cubit_error_stop(iproc,command,ner)
            else:
                interval_store.append((k, interval_curve))
            if len(interval_store) != 0:
                interval_min = min([iv[1] for iv in interval_store])
                str_interval = [str(iv[0]) for iv in interval_store]
                cmd = "curve " + ' '.join(str_interval) + \
                      " interval " + str(interval_min)
                cubit.cmd(cmd)
                command = "curve " + \
                    ' '.join(str(iv[0])
                             for iv in interval_store) + " scheme equal"
                cubit.cmd(command)
        command = "surface " + str(s) + " scheme submap"
        cubit.cmd(command)

    # meshing
    if cfg.or_mesh_scheme == 'pave' or schemepave:
        command = 'mesh surf ' + ' '.join(str(t) for t in top)
        status = cubit_command_check(iproc, command, stop=True)
        # cubit.cmd(command)
    elif cfg.or_mesh_scheme == 'map':
        command = 'mesh surf ' + ' '.join(str(t) for t in bottom)
        status = cubit_command_check(iproc, command, stop=True)
        # cubit.cmd(command)
    for id_volume in range(nvol - 1, -1, -1):
        command = "mesh vol " + str(vol[id_volume].ID)
        status = cubit_command_check(iproc, command, stop=False)
        if not status:
            for s in surf_vertical:
                command_surf = "mesh surf " + str(s)
                cubit.cmd(command_surf)
            if version_cubit < 16:
                command_set_meshvol = '''volume all redistribute nodes on
                volume all autosmooth target off
                volume all scheme Sweep Vector 0 0 -1
                volume all sweep smooth Auto
                '''
            else:
                command_set_meshvol = '''volume all redistribute nodes on
                volume all autosmooth target off
                volume all scheme Sweep Vector 0 0 -1
                '''
            status2 = cubit_command_check(
                iproc, command_set_meshvol, stop=False)
            status2 = cubit_command_check(iproc, command, stop=False)
            if not status2:
                _surf = cubit.get_relatives(
                    'volume', vol[id_volume].ID, 'surface')
                local_o_surf = [x for x in _surf if x in surf_or]
                cubit.cmd('volume ' + str(vol[id_volume].ID) +
                          ' redistribute nodes off')
                cubit.cmd('volume ' + str(vol[id_volume].ID) +
                          ' scheme Sweep  source surface ' +
                          ' '.join(str(x) for x in local_o_surf[0:-1]) +
                          ' target surface ' + str(local_o_surf[-1]))
                cubit.cmd('volume ' + str(vol[id_volume].ID) +
                          ' autosmooth_target off')
                status = cubit_command_check(iproc, command, stop=True)

    #
    # smoothing
    print(iproc, 'untangling...')
    cmd = "volume all smooth scheme untangle beta 0.02 cpu 10"
    cubit.cmd(cmd)
    cmd = "smooth volume all"
    cubit.cmd(cmd)

    if cfg.smoothing:
        print('smoothing .... ' + str(cfg.smoothing))
        cubitcommand = 'surf all smooth scheme laplacian '
        cubit.cmd(cubitcommand)
        cubitcommand = 'smooth surf all'
        cubit.cmd(cubitcommand)
        #
        cubitcommand = 'vol all smooth scheme laplacian '
        cubit.cmd(cubitcommand)
        cubitcommand = 'smooth vol all'
        cubit.cmd(cubitcommand)
    #
    #
    # vertical refinement
    # for nvol = 3
    ##
    # ___________________________ interface 4
    ##
    # vol 2
    # ___________________________ interface 3
    ##
    # vol 1
    # ___________________________ interface 2
    ##
    # vol 0
    # ___________________________ interface 1
    ##
    refinement(nvol, vol, filename=filename)
    #
    # top layer vertical coarsening
    print('coarsening top layer... ', cfg.coarsening_top_layer)
    if cfg.coarsening_top_layer:
        cubitcommand = 'del mesh vol ' + str(vol[-1].ID) + ' propagate'
        cubit.cmd(cubitcommand)
        s1 = set(list_curve_vertical)
        command = "group 'list_curve_tmp' add curve " + \
            "in vol " + str(vol[-1].ID)
        cubit.cmd(command)
        group = cubit.get_id_from_name("list_curve_tmp")
        list_curve_tmp = cubit.get_group_curves(group)
        command = "delete group " + str(group)
        cubit.cmd(command)
        s2 = set(list_curve_tmp)
        lc = list(s1 & s2)
        #
        cubitcommand = 'curve ' + \
            ' '.join(str(x) for x in lc) + ' interval ' + \
            str(cfg.actual_vertical_interval_top_layer)
        cubit.cmd(cubitcommand)
        cubitcommand = 'mesh vol ' + str(vol[-1].ID)
        cubit.cmd(cubitcommand)
    #
    n = cubit.get_sideset_id_list()
    if len(n) != 0:
        command = "del sideset all"
        cubit.cmd(command)
    n = cubit.get_block_id_list()
    if len(n) != 0:
        command = "del block all"
        cubit.cmd(command)
    #
    import boundary_definition
    entities = ['face']
    print(iproc, 'hex block definition...')
    boundary_definition.define_bc(entities, parallel=True,
                                  cpux=cfg.cpux, cpuy=cfg.cpuy,
                                  cpuxmin=0, cpuymin=0, optionsea=False)
    # save mesh

    print(iproc, 'untangling...')
    cmd = "volume all smooth scheme untangle beta 0.02 cpu 10"
    cubit.cmd(cmd)
    cmd = "smooth volume all"
    cubit.cmd(cmd)

    print(iproc, 'saving...')
    savemesh(mpiflag, iproc=iproc, filename=filename)