def test_output_files_contain_data(self):
     lines = _read_text(outFile(self.ntr_mesh_file))
     self.assertTrue(len(lines) > 0,
                     "File: " + outFile(self.ntr_mesh_file) + " contains no text")
     lines = _read_text(outFile(self.inp_mesh_file))
     self.assertTrue(len(lines) > 0,
                     "File: " + outFile(self.inp_mesh_file) + " contains no text")
Exemple #2
0
 def test_output_files_contain_data(self):
     lines = _read_text(outFile(self.ntr_mesh_file))
     self.assertTrue(
         len(lines) > 0,
         "File: " + outFile(self.ntr_mesh_file) + " contains no text")
     lines = _read_text(outFile(self.inp_mesh_file))
     self.assertTrue(
         len(lines) > 0,
         "File: " + outFile(self.inp_mesh_file) + " contains no text")
Exemple #3
0
 def setUp(self):
     # create random string
     self.text1 = binascii.b2a_hex(os.urandom(20))
     self.text2 = ""
     
     # write string to file
     with open('test1.txt','w') as oupf:
         oupf.write(self.text1)
     with open('test2.txt','w') as oupf:
         oupf.write(self.text2)
         
     # read text file with function
     self.read_text1 = _read_text('test1.txt')
     self.read_text2 = _read_text('test2.txt')
Exemple #4
0
def _import_vtk_ct_data(ct_data):
    """ Creates python array data from vtk file """
    
    # read in text
    lines = _read_text(ct_data)
    lines = _remove_eol_r(lines)
    header = lines.split('LOOKUP')[0]
        
    # read in X data
    xlines = _refine_vtk_lines(header, 'X_COORDINATES \d+', 'double', 'Y_COORDINATES')
    X = [float(x) for x in xlines]
    
    # read in Y data
    ylines = _refine_vtk_lines(header, 'Y_COORDINATES \d+', 'double', 'Z_COORDINATES')
    Y = [float(y) for y in ylines]
    
    # read in Z data
    zlines = _refine_vtk_lines(header, 'Z_COORDINATES \d+', 'double', 'CELL_DATA')
    Z = [float(z) for z in zlines]

    # read in lookup data
    lookup_lines = _refine_vtk_lines(lines, 'LOOKUP_TABLE','default','')
    lookup = [int(l) for l in lookup_lines]

    # create vtk class
    vtk = vtk_data(X,Y,Z, lookup)

    # return data
    return vtk
Exemple #5
0
def _import_abq_mesh(fle, param):
    """ Records mesh data from abaqus input file """
    
    # read abaqus file
    lines = _read_text(fle)
    lines = _remove_spaces(lines)
    lines = _remove_eol_r(lines)

    # check for pre-existing materials
    if '\n*Material' in lines:
        print('Warning: Input file: ' + fle + ' already has materials defined')
        print('         Beware duplicate material definition')
       
    # determine how many parts
    parts = _find_part_names(lines)
    
    # store data for each part
    part_data = [0] * len(parts)
    for p in parts:
        if 'ignore' in param.keys():
            if p in param['ignore']:
                part_data[parts.index(p)] = _get_part_data(lines, p, True)
            else:
                part_data[parts.index(p)] = _get_part_data(lines, p)
        else:
            part_data[parts.index(p)] = _get_part_data(lines, p)
        
    return part_data
Exemple #6
0
def _what_mesh_filetype(fle):
    """ Determines mesh file format """
    lines = _read_text(fle)
    if '*Heading' in lines:
        return '.inp'
    elif '1G' in lines:
        return '.ntr'
    elif '.ntr' in fle:
        return '.ntr'
    elif '.neutral' in fle:
        return '.ntr'
    else:
        return None
Exemple #7
0
def _get_ntr_part_data(fle):
    """ Read elements and node data from .ntr file """

    # read in .ntr file
    lines = _read_text(fle)
    lines = lines.replace(' ', ',')
    for n in range(15):
        lines = lines.replace(',,', ',')
    lines = _remove_eol_r(lines)

    # read nodes
    nodes = {}
    nodelines = re.findall(r'\n(,1,[\d,]+\n[,\d.EG\+-]+\n1[G,\d]+)', lines)
    for n in nodelines:
        node_num = n.split('\n')[0].split(',')[2]
        nodes[node_num] = _get_node_ntr(n.split('\n')[1])

    # read elements
    elements = []
    elelines = re.findall(r'\n,2,([\d,E]+\n[\d\.\+,E]+\n[\d,E]+)', lines)
    for e in elelines:
        # get element label
        ele_num = int(e.split(',')[0])
        # get node connectivity
        elements.append(_get_element_ntr(e.split('\n')[2], ele_num))
        # determine element type
        ele_type_num = int(e.split(',')[1])
        num_ele_nodes = int(e.split('\n')[1].split(',')[1])
    
    # determine element name
    if (ele_type_num == 5) & (num_ele_nodes == 4):
        ele_type = 'linear_tet'
        elename = 'C3D4'
    elif (ele_type_num == 5) & (num_ele_nodes == 10):
        ele_type = 'quad_tet'
        elename = 'C3D10'
    elif (ele_type_num == 7) & (num_ele_nodes == 6): 
        ele_type = 'linear_wedge'
        elename = 'C3D6'
    elif (ele_type_num == 8) & (num_ele_nodes == 8):
        ele_type = 'linear_hex'
        elename = 'C3D8'
    else:
        raise IOError("Element type not recognised or not compatible with py_bonemat_abaqus.py");
    
    # create part
    part = _create_part('Part1', elements, elename, ele_type, nodes)

    return part
Exemple #8
0
def import_parameters(fle):
    """ Imports parameter data """
    
    # read parameters file
    lines = _read_text(fle) + '\n'
    lines = _remove_spaces(lines)
    lines = _remove_eol_r(lines)
    
    # identify and record data
    param = _get_param(lines)
    
    # check all necessary parameters have been defined
    _checkParamInformation(param)
    
    return param
def _update_abq_inp(parts, fle, poisson):
    """ Adds material data to existing abaqus file and writes to 'jobMAT.inp' """
    
    # create output line string
    lines = ''

    # create materials lines
    materials, materials_data = _create_materials(parts, poisson)

    # add header lines
    orig_input = _read_text(fle)
    orig_input = _remove_eol_r(orig_input)
    header = _get_lines('', '\*Part,', orig_input)
    lines = lines + header

    # modify and add part lines for each part
    for p in parts:
        partlines = _get_lines('\*Part,\s?name=' + p.name, '\*End', orig_input)
        if p.ignore == False:
            sets, set_data, set_name = _create_material_elesets(p)
            sections = _create_sections(p, set_data, materials_data, set_name)
            lines = lines + '*Part, name=' + p.name + partlines + sets + sections + '*End Part\n'
        else:
            lines = lines + '*Part, name=' + p.name + partlines + '*End Part\n'

    # add lines until end of assembly
    lines = lines + _get_lines('\*End Part', '\*End Assembly\n', orig_input) + '*End Assembly\n'

    # add material lines
    lines = lines + materials

    # add any remaining lines
    lines = lines + _get_lines('\*End Assembly\n', '$', orig_input)

    # write to file
    with open(fle[:-4]+'MAT.inp','w') as oupf:
        oupf.write(lines)