Example #1
0
def getNodesBoundInSelectedVols(target_list):
    """
    Return nodes bound in selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target nodes
                    
    Return:
        List of indices of nodes bound by the volumes
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)

    in_list = []

    for v in target_list:
        cords = cubit.get_nodal_coordinates(v)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    cubit.delete_group(group_id)
    return in_list
def getTetsOverlapPassedVols(target_list, volume_ids):
    """
    Return tetraherons overlap with mouse selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target tetrahedrons
                    
    Return:
        List of indices of tetrahedrons overlap with the volumes
    """
    
    in_list = []
    
    for t in target_list:
        verts = cubit.get_connectivity("tet", t)
        cords = []
        for v in verts:
            c = cubit.get_nodal_coordinates(v)
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = False
            for cord in cords:
                status = body.point_containment(cord)
                if status == 1:
                    within = True
                    break
            if within:
                in_list.append(t)
                break
    
    return in_list
Example #3
0
def getNodesBoundInSelectedVols(mesh, scale=1e-6):
    """
    Return nodes bound in selected CUBIT volumes.
        
    Parameters:
        * mesh        Associated Tetmesh object created in STEPS
        * scale       LENGTH scale from the CUBIT gemoetry to real geometry.
                    e.g. a radius of 10 in CUBIT to a radius of 1 micron in STEPS, scale is 1e-7.
                    By default the scale is 1e-6, i.e. 1 unit in CUBIT equals 1 micron in STEPS.
                    
    Return:
        list of STEPS indices of vertex nodes
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    nverts = mesh.nverts

    in_list = []

    for v in range(nverts):
        cords = mesh.getVertex(v)
        cords = [x / scale for x in cords]
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    cubit.delete_group(group_id)
    return in_list
def getNodesBoundInSelectedVols(target_list):
    """
    Return nodes bound in mouse selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target nodes
                    
    Return:
        List of indices of nodes bound by the volumes
    """
    
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    
    in_list = []
    
    for v in target_list:
        cords = cubit.get_nodal_coordinates(v)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    cubit.delete_group(group_id)
    return in_list
Example #5
0
def getTetsInVolume(v_id, mesh, scale = 1e-6):
    ntets = mesh.ntets
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in range(ntets):
        center = mesh.getTetBarycenter(t)
        cubit_center = [center[0]/scale, center[1]/scale, center[2]/scale]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #6
0
def getPatchTrisInVolume(v_id, mesh, patch_id, scale = 1e-6):
    patch_tris = mesh.getPatch(patch_id).getAllTriIndices()
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in patch_tris:
        center = mesh.getTriBarycenter(t)
        cubit_center = [center[0]/scale, center[1]/scale, center[2]/scale]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #7
0
def getSurfTrisInVolume(v_id, mesh, scale = 1e-6):
    surf_tris = mesh.getSurfTris()
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in surf_tris:
        center = mesh.getTriBarycenter(t)
        cubit_center = [center[0]/scale, center[1]/scale, center[2]/scale]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #8
0
def getCompTetsInVolume(v_id, mesh, comp_id, scale = 1e-6):
    comp_tets = mesh.getComp(comp_id).getAllTetIndices()
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in comp_tets:
        center = mesh.getTetBarycenter(t)
        cubit_center = [center[0]/scale, center[1]/scale, center[2]/scale]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #9
0
def getCompTetsInVolume(v_id, mesh, comp_id, scale=1e-6):
    comp_tets = mesh.getComp(comp_id).getAllTetIndices()
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in comp_tets:
        center = mesh.getTetBarycenter(t)
        cubit_center = [
            center[0] / scale, center[1] / scale, center[2] / scale
        ]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #10
0
def getTetsInVolume(v_id, mesh, scale=1e-6):
    ntets = mesh.ntets
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in range(ntets):
        center = mesh.getTetBarycenter(t)
        cubit_center = [
            center[0] / scale, center[1] / scale, center[2] / scale
        ]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #11
0
def getPatchTrisInVolume(v_id, mesh, patch_id, scale=1e-6):
    patch_tris = mesh.getPatch(patch_id).getAllTriIndices()
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in patch_tris:
        center = mesh.getTriBarycenter(t)
        cubit_center = [
            center[0] / scale, center[1] / scale, center[2] / scale
        ]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #12
0
def getSurfTrisInVolume(v_id, mesh, scale=1e-6):
    surf_tris = mesh.getSurfTris()
    volume = cubit.volume(v_id)
    body = volume.bodies()[0]
    in_list = []
    for t in surf_tris:
        center = mesh.getTriBarycenter(t)
        cubit_center = [
            center[0] / scale, center[1] / scale, center[2] / scale
        ]
        status = body.point_containment(cubit_center)
        if status == 1 or status == 2:
            in_list.append(t)
    return in_list
Example #13
0
def getTrisBoundInSelectedVols(mesh, scale=1e-6):
    """
    Return triangles bound in selected CUBIT volumes.
        
    Parameters:
        * mesh        Associated Tetmesh object created in STEPS
        * scale       LENGTH scale from the CUBIT gemoetry to real geometry.
                    e.g. a radius of 10 in CUBIT to a radius of 1 micron in STEPS, scale is 1e-7.
                    By default the scale is 1e-6, i.e. 1 unit in CUBIT equals 1 micron in STEPS.
                    
    Return:
        list of STEPS indices of triangles
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    ntris = mesh.ntris

    in_list = []

    for t in range(ntris):
        verts = mesh.getTri(t)
        with_in = True
        cords = []
        for v in verts:
            c = mesh.getVertex(v)
            c = [x / scale for x in c]
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = True
            for cord in cords:
                status = body.point_containment(cord)
                if status == 0:
                    within = False
                    break
            if within:
                in_list.append(t)
                break
    cubit.delete_group(group_id)
    return in_list
Example #14
0
def getTrisBoundInSelectedVols(target_list):
    """
    Return triangles bound in selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target triangles
                    
    Return:
        List of indices of triangles bound by the volumes
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)

    in_list = []

    for t in target_list:
        verts = cubit.get_connectivity("tri", t)
        with_in = True
        cords = []
        for v in verts:
            c = cubit.get_nodal_coordinates(v)
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = True
            for cord in cords:
                status = body.point_containment(cord)
                if status == 0:
                    within = False
                    break
            if within:
                in_list.append(t)
                break
    cubit.delete_group(group_id)
    return in_list
def getTrisOverlapSelectedVols(target_list):
    """
    Return triangles overlap with mouse selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target triangles
                    
    Return:
        List of indices of triangles overlap with the volumes
    """
    
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    
    in_list = []
    
    for t in target_list:
        verts = cubit.get_connectivity("tri", t)
        cords = []
        for v in verts:
            c = cubit.get_nodal_coordinates(v)
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = False
            for cord in cords:
                status = body.point_containment(cord)
                if status == 1:
                    within = True
                    break
            if within:
                in_list.append(t)
                break
    cubit.delete_group(group_id)
    return in_list
def getNodesBoundInPassedVols(target_list, volume_ids):
    """
    Return nodes bound in mouse selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target nodes
                    
    Return:
        List of indices of nodes bound by the volumes
    """
    
    in_list = []
    
    for v in target_list:
        cords = cubit.get_nodal_coordinates(v)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    
    return in_list
Example #17
0
def cohgen(exodusIn, fileOutPrefix):
    """
    This function operates within Cubit. It imports an exodus mesh of
    polycrystalline geometry with the void meshed, generates a skin of zero
    thickness cohesive elements surrounding individual crystals, and exports
    a valid ABAQUS mesh.
    """
    # Provide the installation path of Cubit
    sys.path.append('~/Software/Cubit-15.3-Lin64/bin')
    # sys.path.append('/Applications/Cubit-15.3/Cubit.app/Contents/MacOS/')
    import cubit as cb
    # Start cubit
    cb.init(['cubit', '-nojournal'])

    # Import model while creating geometry
    fileIn = "'" + exodusIn + ".e'"
    print fileIn
    cb.cmd("import mesh geometry %s feature_angle 135.00 merge" % fileIn)

    # Get volumes and separate into blocks
    # Compress volume id's and sort by volume (likely void volume is largest)
    cb.cmd('compress all sort')
    # cb.cmd('label volume id')
    # cb.cmd('label volume name id')

    # Remove pre-established element blocks
    cb.cmd('del block all')
    vols = cb.get_volume_count()
    print "Number of volumes: %s" % vols

    # Check if volumes sorted properly (largest last)
    firstvol = cb.volume(1)
    lastvol = cb.volume(vols)
    firstvol_vol = firstvol.volume()
    lastvol_vol = lastvol.volume()

    # Set volume number containing matrix material
    # Proper sort should set last (assuming it is the largest individual volume)
    # One case, it left the matrix material as volume 1
    # Could be other cases requiring a more generic fix (check cuibt file manually)
    if firstvol_vol > lastvol_vol:
        matrix_vol_num = 1
    elif firstvol_vol < lastvol_vol:
        matrix_vol_num = vols

    # Assign each grain its own element block and name.
    grain_list = []
    for cv in range(1, vols + 1):
        cb.cmd("block %s add volume %s" % (repr(cv + 1), repr(cv)))
        if cv == matrix_vol_num:
            cb.cmd("block %s name 'Matrix'" % repr(cv + 1))
        else:
            cb.cmd("block %s name 'Grain_%s'" % (repr(cv + 1), repr(cv)))
            grain_list.append('Grain_%s' % repr(cv))

    cb.cmd('disassociate mesh from Volume all')
    # cb.cmd('delete volume all')

    # Pillow each grain to skin with 0 thickness hexes for cohesive elements
    el_blocks = cb.get_block_count()
    # Note, indexing skips last element block (presumed binder)
    for block in range(2, el_blocks + 1):
        if block == matrix_vol_num + 1:
            pass
        else:
            cb.cmd("pillow hex in block %s distance 0 no_smooth" % repr(block))

    cb.cmd('block 1 add hex not block_assigned')
    cb.cmd("block 1 name 'Coh_El'")

    # Get bounding box for removing cohesive elements on the domain boundary
    # cb.get_bounding_box('entity',id) returns a vector with the following info:
    #(min_x, max_x, range_x, min_y, max_y, range_y, min_z, max_z, range_z, diag)
    bbox = cb.get_bounding_box("volume", matrix_vol_num)

    cb.cmd('delete hex in block 1 with X_Coord == %s' % repr(bbox[0]))
    cb.cmd('delete hex in block 1 with X_Coord == %s' % repr(bbox[1]))
    cb.cmd('delete hex in block 1 with Y_Coord == %s' % repr(bbox[3]))
    cb.cmd('delete hex in block 1 with Y_Coord == %s' % repr(bbox[4]))
    cb.cmd('delete hex in block 1 with Z_Coord == %s' % repr(bbox[6]))
    cb.cmd('delete hex in block 1 with Z_Coord == %s' % repr(bbox[7]))

    # Reassign domain nodesets since pillowing and removing domain hexes messes this up
    cb.cmd('delete nodeset all')
    cb.cmd('delete sideset all')

    cb.cmd('nodeset 1 add node with X_Coord == %s' % repr(bbox[0]))
    cb.cmd('nodeset 2 add node with X_Coord == %s' % repr(bbox[1]))
    cb.cmd('nodeset 3 add node with Y_Coord == %s' % repr(bbox[3]))
    cb.cmd('nodeset 4 add node with Y_Coord == %s' % repr(bbox[4]))
    cb.cmd('nodeset 5 add node with Z_Coord == %s' % repr(bbox[6]))
    cb.cmd('nodeset 6 add node with Z_Coord == %s' % repr(bbox[7]))
    cb.cmd('nodeset 7 add node in nodeset 1 to 6')
    cb.cmd('nodeset 8 add node in hex in block 1')  # Interface nodes

    cb.cmd('nodeset 1 name "negXNodes"')
    cb.cmd('nodeset 2 name "posXNodes"')
    cb.cmd('nodeset 3 name "negYNodes"')
    cb.cmd('nodeset 4 name "posYNodes"')
    cb.cmd('nodeset 5 name "negZNodes"')
    cb.cmd('nodeset 6 name "posZNodes"')
    cb.cmd('nodeset 7 name "allBoundaryNodes"')
    cb.cmd('nodeset 8 name "matIntNodes"')

    # Define nodesets for periodic boundary conditions. For universal application
    # to implicit and explicit analyses, corners, edges, and faces cannot contain
    # duplicate nodes (restriction for implicit only). Therefore, new specific
    # nodesets are defined in a way to eleminate this duplicate definition problem.

    # Redefine Faces for PBC's
    cb.cmd('nodeset 101 add node in nodeset 1')
    cb.cmd('nodeset 102 add node in nodeset 2')
    cb.cmd('nodeset 103 add node in nodeset 3')
    cb.cmd('nodeset 104 add node in nodeset 4')
    cb.cmd('nodeset 105 add node in nodeset 5')
    cb.cmd('nodeset 106 add node in nodeset 6')

    cb.cmd('nodeset 101 name "PBCnXF"')
    cb.cmd('nodeset 102 name "PBCpXF"')
    cb.cmd('nodeset 103 name "PBCnYF"')
    cb.cmd('nodeset 104 name "PBCpYF"')
    cb.cmd('nodeset 105 name "PBCnZF"')
    cb.cmd('nodeset 106 name "PBCpZF"')

    # Define Edges for PBC's
    cb.cmd(
        'nodeset 1001 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[3])))
    cb.cmd('nodeset 1001 name "PBCnXnYE"')
    cb.cmd(
        'nodeset 1002 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[4])))
    cb.cmd('nodeset 1002 name "PBCnXpYE"')
    cb.cmd(
        'nodeset 1003 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[3])))
    cb.cmd('nodeset 1003 name "PBCpXnYE"')
    cb.cmd(
        'nodeset 1004 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[4])))
    cb.cmd('nodeset 1004 name "PBCpXpYE"')
    cb.cmd(
        'nodeset 1005 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[3]), z=repr(bbox[6])))
    cb.cmd('nodeset 1005 name "PBCnYnZE"')
    cb.cmd(
        'nodeset 1006 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[3]), z=repr(bbox[7])))
    cb.cmd('nodeset 1006 name "PBCnYpZE"')
    cb.cmd(
        'nodeset 1007 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[4]), z=repr(bbox[6])))
    cb.cmd('nodeset 1007 name "PBCpYnZE"')
    cb.cmd(
        'nodeset 1008 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[4]), z=repr(bbox[7])))
    cb.cmd('nodeset 1008 name "PBCpYpZE"')
    cb.cmd(
        'nodeset 1009 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), z=repr(bbox[6])))
    cb.cmd('nodeset 1009 name "PBCnXnZE"')
    cb.cmd(
        'nodeset 1010 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), z=repr(bbox[7])))
    cb.cmd('nodeset 1010 name "PBCnXpZE"')
    cb.cmd(
        'nodeset 1011 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), z=repr(bbox[6])))
    cb.cmd('nodeset 1011 name "PBCpXnZE"')
    cb.cmd(
        'nodeset 1012 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), z=repr(bbox[7])))
    cb.cmd('nodeset 1012 name "PBCpXpZE"')

    # Remove nodes in edge sets from face sets
    for nn in range(101, 107):
        cb.cmd('nodeset {num:s} remove node in nodeset 1001 to 1012'.format(
            num=repr(nn)))

    # Define Corners for PBC's
    cb.cmd(
        'nodeset 10001 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[3]), z=repr(bbox[6])))
    cb.cmd('nodeset 10001 name "PBCnXnYnZC"')
    cb.cmd(
        'nodeset 10002 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[3]), z=repr(bbox[7])))
    cb.cmd('nodeset 10002 name "PBCnXnYpZC"')
    cb.cmd(
        'nodeset 10003 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[4]), z=repr(bbox[6])))
    cb.cmd('nodeset 10003 name "PBCnXpYnZC"')
    cb.cmd(
        'nodeset 10004 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[4]), z=repr(bbox[7])))
    cb.cmd('nodeset 10004 name "PBCnXpYpZC"')
    cb.cmd(
        'nodeset 10005 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[3]), z=repr(bbox[6])))
    cb.cmd('nodeset 10005 name "PBCpXnYnZC"')
    cb.cmd(
        'nodeset 10006 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[3]), z=repr(bbox[7])))
    cb.cmd('nodeset 10006 name "PBCpXnYpZC"')
    cb.cmd(
        'nodeset 10007 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[4]), z=repr(bbox[6])))
    cb.cmd('nodeset 10007 name "PBCpXpYnZC"')
    cb.cmd(
        'nodeset 10008 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[4]), z=repr(bbox[7])))
    cb.cmd('nodeset 10008 name "PBCpXpYpZC"')

    # Remove nodes in corner sets from edge sets
    for nn in range(1001, 1013):
        cb.cmd('nodeset {num:s} remove node in nodeset 10001 to 10008'.format(
            num=repr(nn)))

    # Export abaqus file
    absFileOutPrefix = os.path.abspath(fileOutPrefix)
    cb.cmd("set Abaqus precision 4")
    cb.cmd(
        'export abaqus "%s.inp" block all nodeset all dimension 3 overwrite' %
        absFileOutPrefix)
    cb.cmd('save as "%s.cub" overwrite' % absFileOutPrefix)
    return absFileOutPrefix, grain_list