def __init__(self):
     self.filename_nodes = 'node_coordinates'
     self.filename_hex8 = 'cell_connectivity_hex8'
     self.filename_tet4 = 'cell_connectivity_tet4'
     #
     self.hex8 = []
     self.tet4 = []
     #
     print "number of volumes = " + str(cubit.get_volume_count())
     print "number of hexes in entire mesh: cubit.get_hex_count = " + str(
         cubit.get_hex_count())
     print "number of tets in entire mesh: cubit.get_tet_count =  " + str(
         cubit.get_tet_count())
     #
     for volume in cubit.get_entities("volume"):
         print "VOLUME " + str(volume) + ":"
         print "  number of elements: " + str(
             cubit.get_volume_element_count(volume))
         hex8_list = cubit.get_volume_hexes(volume)
         self.hex8 += hex8_list
         print "  number of hexes:    " + str(len(hex8_list))
         tet4_list = cubit.get_volume_tets(volume)
         self.tet4 += tet4_list
         print "  number of tets:     " + str(len(tet4_list))
     #
     print "number of hexes found while iterating over all volumes: " + str(
         len(self.hex8))
     print "number of tets found while iterating over all volumes: " + str(
         len(self.tet4))
def getAllVolumeIds ():

  cubit.cmd ('compress all')
  numVolumes = cubit.get_volume_count ()
  volumeIds  = [x for x in range (1, numVolumes+1)]
  
  return volumeIds
예제 #3
0
                       np.array(cubit.get_center_point('volume', ovol)[0:2]))**
                      2)**0.5 < 0.1:
                if np.abs(cubit.get_surface_area(isurf) -
                          (math.pi * 1.8**2)) < 0.01:
                    print ovol
                    isWell = True
            if isWell:
                cubit.cmd('sideset 7 add surface %i' % (isurf))  # injection
            else:
                cubit.cmd('sideset 6 add surface %i' % isurf)  # upper

hex_ids = np.zeros([0, 3], dtype='int')
hex_xyzs = np.zeros([0, 3], dtype='float')
hex_types = np.zeros([0, 1], dtype='float')
iblock = 0
for ivol in range(1, cubit.get_volume_count() + 1):
    for ihex in cubit.get_volume_hexes(ivol):
        iblock += 1
        cubit.cmd('block %i add hex %i' % (iblock, ihex))
        x, y, z = cubit.get_center_point("hex", ihex)
        hex_ids = np.concatenate(
            [hex_ids, np.array([ivol, iblock, ihex]).reshape(1, 3)], axis=0)
        hex_xyzs = np.concatenate(
            [hex_xyzs, np.array([x, y, z]).reshape(1, 3)], axis=0)
        isWell = False
        isCase = False

        if ivol in range(37 + 0, 37 + 4): pass
        if ivol in range(37 + 4, 37 + 8): isCase = True
        if ivol in range(37 + 8, 37 + 12): isWell = True
  cubit.cmd  ('open "' + geomPath + 'cutters/all_cutters.cub')

  paramBool = params.copy ()
  for key in paramBool.keys ():
    paramBool[key] = False

  names = []
  sizes = []

  # Set up surface sizing functions.
  fields    = file.split ('.')
  radRegion = fields[2]

  cubit.cmd ('import "' + geomPath + 'masters/' + file + '"')    
  cubit.cmd ('compress all')
  numVolumes = cubit.get_volume_count ()

  volumeIds   = [x for x in range (1, numVolumes+1)]    
  overLapping = cubit.get_overlapping_volumes ( volumeIds )

  if overLapping:
    for i in range (0, len(overLapping) - 1, 2 ):
      if ( overLapping[i] > overLapping[i+1] ):          
        vol1 = str (overLapping[i])
        vol2 = str (overLapping[i+1])
      else:
        vol1 = str (overLapping[i+1])
        vol2 = str (overLapping[i])

      cubit.cmd ('intersect volume ' + vol1 + ' ' + vol2 + ' keep')           
  
예제 #5
0
    center_depth == numpy.amax(center_depth))[:, 0]].tolist()
#bottom = [surface_list]
#topo   = [surface_list]
if (len(bottom) == 0 or len(topo) == 0):
    print "Fail in obtaining the topo and bottom surfaces."
    print "Please change setup topo and bottom surfaces manually."
    exit()
print "Xmin surface list: ", xmin
print "Xmax surface list: ", xmax
print "Ymin surface list: ", ymin
print "Ymax surface list: ", ymax
print "Bott surface list: ", bottom
print "Topo surface list: ", topo

# define blocks
Vol_num = cubit.get_volume_count()
for i in range(Vol_num):
    cubit.cmd('block {0} hex in vol {0}'.format(i + 1))
cubit.cmd('block 1003 face in surface ' +
          str(list(xmin)).replace("[", " ").replace("]", " "))
cubit.cmd('block 1003 name "face_abs_xmin"')
cubit.cmd('block 1005 face in surface ' +
          str(list(xmax)).replace("[", " ").replace("]", " "))
cubit.cmd('block 1005 name "face_abs_xmax"')
cubit.cmd('block 1004 face in surface ' +
          str(list(ymin)).replace("[", " ").replace("]", " "))
cubit.cmd('block 1004 name "face_abs_ymin"')
cubit.cmd('block 1006 face in surface ' +
          str(list(ymax)).replace("[", " ").replace("]", " "))
cubit.cmd('block 1006 name "face_abs_ymax"')
cubit.cmd('block 1002 face in surface ' +
예제 #6
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