Example #1
0
def center_disp(args):
    inp_file, tumor_eleset, odb_file, breast_part_start, step, breast_part = args
    abaqus = manipulate_abaqus_file.ReadAbaqusInput(inp_file)
    node_indices = abaqus.get_node_from_elemset(tumor_eleset, breast_part_start)
    disp = read_lastframe(odb_file, step, breast_part)
    disp_eleset = []
    for index in node_indices:
        disp_eleset.append(disp[index - 1])
    return np.mean(np.array(disp_eleset), axis=0)       
Example #2
0
def find_centers(inp_file, eleset, odb_reader, step_name, part, part_start):
    abaqus = manipulate_abaqus_file.ReadAbaqusInput(inp_file)
    elements = abaqus.read_elset_or_nset(eleset)
    element_to_node = abaqus.read_element(part_start)
    node_indices = []
    for elem in elements:
        node_indices.append(element_to_node[elem - 1])  
    nodes_unique = np.unique(np.array(node_indices))
    positions_across_frame = []
    
    for label in nodes_unique:
        start, end = odb_reader.read_start_end_pos(step_name, label, part)
        positions_across_frame.append(np.array(start) - np.array(end))
    pdb.set_trace()
Example #3
0
def main(args):
    mode = args.mode
    if args.type == 'breast':
        disp_folders = glob.glob(
            'F:/Research/FEA simulation for NN/train_patient_specific/disps/*')
    elif args.type == 'tumor':
        disp_folders = glob.glob(
            'F:/Research/FEA simulation for NN/train_patient_specific/tumor/*')
    elif mode == 'connet_to_unity_weight':
        triangles = read_surface()
        breast_point_num = triangles.shape[0]
        tumor_point_num = 1
    else:
        return
    if args.type == 'breast' or args.type == 'tumor':
        ratios = []
        disp_filenames = []
        for disp_folder in disp_folders:
            ratio = float(os.path.basename(disp_folder).split('_')[2])
            temp_file = glob.glob(disp_folder + '/*')
            disp_filenames += temp_file
            ratios += ([ratio / 100] * len(temp_file))

    col_num = 3
    directory = 'F:/Research/FEA simulation for NN/stl/Abaqus_outputs/weight/'
    inp_files_dirs = [
        name for name in os.listdir(directory)
        if os.path.isdir(os.path.join(directory, name))
    ]
    inp_files = []
    for direc in inp_files_dirs:
        inp_files += glob.glob(os.path.join(directory, direc) + '/*inp')
    #inp_files = glob.glob('F:/Research/FEA simulation for NN/stl/Abaqus_outputs/weight/glandular_fat_10_90/*inp')

    if mode == 'train':
        disp_filenames_and_ratios = list(zip(disp_filenames, ratios))
        random.shuffle(disp_filenames_and_ratios)
        disp_filenames, ratios = zip(*disp_filenames_and_ratios)
        num_files = len(disp_filenames)
        if num_files == 0:
            return
        if args.type == 'breast':
            triangles = read_surface()
            position = read(disp_filenames[0])
            point_num = triangles.shape[0]
        if args.type == 'tumor':
            point_num = 1
        nn_input = np.zeros([len(disp_filenames), 1, col_num + 1])
        nn_output = np.zeros([len(disp_filenames), point_num * col_num])

        if args.type == 'breast':
            model = breast_model(point_num, col_num)
        if args.type == 'tumor':
            model = tumor_model(point_num, col_num)
        gravity = '** Name: GRAVITY-1   Type: Gravity\n'

        for idx, file in enumerate(disp_filenames):
            name = os.path.basename(file)
            file_ratio = os.path.basename(
                os.path.normpath(os.path.dirname(file)))
            temp_file = os.path.join(directory, file_ratio)
            temp_file = os.path.join(temp_file, name.split('.')[0] + '.inp')
            if temp_file not in inp_files:
                print(temp_file)
            if temp_file in inp_files:
                abaqus = manipulate_abaqus_file.ReadAbaqusInput(temp_file)
                _, direction = abaqus.read_gravity(gravity)
                #    print(idx)
                nn_input[idx, 0:1, :] = direction + [ratios[idx]]
                temp_pos = read(file)
                if args.type == 'breast':
                    disp = np.array(get_surface_disp(triangles, temp_pos))
                if args.type == 'tumor':
                    disp = temp_pos
                nn_output[idx, :] = np.reshape(disp, point_num * col_num)

        pdb.set_trace()
        if args.pretrained_file != 'None':
            model.load_weights(args.pretrained_file)
            checkpoint = args.pretrained_file
        else:
            checkpoint = args.checkpoint
        checkpoint = ModelCheckpoint(checkpoint,
                                     monitor='loss',
                                     verbose=1,
                                     save_best_only=True)
        callbacks_list = [checkpoint]
        model.fit(nn_input,
                  nn_output,
                  epochs=10000,
                  shuffle=True,
                  validation_split=0.2,
                  callbacks=callbacks_list,
                  verbose=1)

    elif mode == 'connet_to_unity_weight':
        all_checkpoint = args.pretrained_file
        breast_ck = all_checkpoint.split(',')[0]
        tumor_ck = all_checkpoint.split(',')[1]
        breastmodel = breast_model(breast_point_num, col_num)
        tumormodel = tumor_model(tumor_point_num, col_num)
        breastmodel.load_weights(breast_ck)
        tumormodel.load_weights(tumor_ck)
        flag = 'weight'
        abaqus = manipulate_abaqus_file.ReadAbaqusInput(inp_files[0])
        tumor_center = abaqus.elem_set_center('*Elset, elset=TUMOR_FROMSKIN\n',
                                              '*Part, name=PART-1\n')
        connect_to_unity(tumormodel, breastmodel, tumor_center, flag)
Example #4
0
 def __init__(self, file_name, part):
     self.hand_part = part
     self.abaqus = manipulate_abaqus_file.ReadAbaqusInput(file_name)
Example #5
0
 def set_assembly(self, file_name, vec, start_line):
     abaqus = manipulate_abaqus_file.ReadAbaqusInput(file_name)
     abaqus.set_assembly(start_line, vec)
Example #6
0
            boundary_arg = [
                boundary, time_period, direction, surface_point, base, distance
            ]
            hand.set_boundary(boundary_arg)
            contact_ps = tetrahedral_mesh.contact_points(closest_point_index)
            r_input.delete_elset_or_nset(nset)
            r_input.add_to_elset_or_nset(nset, contact_ps)
            hand.write_output('Jobs/' + str(index) + '.inp')
            index += 1

    if scenario == 'gravity':
        breast_info = GetInfoFromBreast(element, node)
        inp_file = 'Weight Jobs/reference_pos.inp'
        gravity = '** Name: GRAVITY-1   Type: Gravity\n'
        output_folder = 'F:/Research/FEA simulation for NN/stl/Abaqus_outputs/weight'
        abaqus = manipulate_abaqus_file.ReadAbaqusInput(inp_file)
        angle_interval = 5  # 5 degree
        circle_angle = 360
        angles = np.linspace(start=0,
                             stop=circle_angle,
                             num=circle_angle / angle_interval + 1)
        gravity_magnitude = 9810
        glandular_fat_ratio = 0.33
        glandular_density = 1020e-12
        fat_density = 910e-12
        glandular_densityline = '*Material, name=GLANDULAR\n'
        fat_densityline = '*Material, name=FAT\n'
        glandular_elasticity = 120e-6  # c1 value in the paper
        fat_elasticity = 80e-6
        for angle in list(angles):
            x = math.cos(math.radians(angle))