def create_dante_step(results_odb_name, carbon_odb_name, stress_odb_name,
                      results_step_name):
    f = read_field_from_odb(field_id='CONC',
                            odb_file_name=carbon_odb_name,
                            element_set_name='GEARELEMS',
                            step_name='Carburization-3',
                            frame_number=-1)

    hardness = -1.95704040e+09 * f**3 + 1.79113930e+07 * f**2 + 5.50685403e+04 * f + 2.27359677e+02
    write_field_to_odb(field_data=hardness,
                       field_id='HV',
                       odb_file_name=results_odb_name,
                       step_name=results_step_name,
                       instance_name='tooth_right',
                       frame_number=0)

    hardness = flip_node_order(hardness, axis='z')
    write_field_to_odb(field_data=hardness,
                       field_id='HV',
                       odb_file_name=results_odb_name,
                       step_name=results_step_name,
                       instance_name='tooth_left',
                       frame_number=0)

    stress = read_field_from_odb(field_id='S',
                                 odb_file_name=stress_odb_name,
                                 element_set_name='GEARELEMS',
                                 step_name='Equilibrium',
                                 frame_number=-1,
                                 coordinate_system=cylindrical_system_z)
    write_field_to_odb(
        field_data=stress,
        field_id='S',
        odb_file_name=results_odb_name,
        step_name=results_step_name,
        instance_name='tooth_right',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])

    stress = flip_node_order(stress, axis='z')
    stress[:, 3] *= -1
    write_field_to_odb(
        field_data=stress,
        field_id='S',
        odb_file_name=results_odb_name,
        step_name=results_step_name,
        instance_name='tooth_left',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])
def create_dante_step(from_odb_name, to_odb_name, results_step_name):
    # Inspect the odb to get available data
    from_odb = openOdb(from_odb_name, readOnly=False)
    last_step_name, last_step = from_odb.steps.items()[-1]
    scalar_variables = last_step.frames[-1].fieldOutputs.keys()
    from_odb.close()
    if 'NT11' in scalar_variables:
        scalar_variables.remove('NT11')

    if 'U' in scalar_variables:
        scalar_variables.remove('U')

    if 'S' in scalar_variables:
        scalar_variables.remove('S')

    data_dict = {}
    for scalar_variable in scalar_variables:
        print "reading variable", scalar_variable
        data_dict[scalar_variable] = read_field_from_odb(
            scalar_variable, from_odb_name, last_step_name, -1)
    data_dict['S'] = read_field_from_odb('S', from_odb_name, last_step_name,
                                         -1)

    for scalar_variable in scalar_variables:
        field = data_dict[scalar_variable]
        write_field_to_odb(field_data=field,
                           field_id=scalar_variable,
                           odb_file_name=to_odb_name,
                           step_name=results_step_name,
                           instance_name='specimen_part',
                           frame_number=0)

    stress = data_dict['S']
    write_field_to_odb(
        field_data=stress,
        field_id='S',
        odb_file_name=to_odb_name,
        step_name=results_step_name,
        instance_name='specimen_part',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])

    hv = HRC2HV(data_dict['SDV_HARDNESS'])
    write_field_to_odb(field_data=hv,
                       field_id='HV',
                       odb_file_name=to_odb_name,
                       step_name=results_step_name,
                       instance_name='specimen_part',
                       frame_number=0)
def create_node_field_from_element_field(fields, odb_file_name,
                                         element_set_name, step_name,
                                         frame_number, instance_name):
    data_dict = {}
    for i, field in enumerate(fields):
        element_field, node_labels, _ = read_field_from_odb(
            field,
            odb_file_name,
            element_set_name=element_set_name,
            step_name=step_name,
            frame_number=frame_number,
            instance_name=instance_name,
            get_position_numbers=True)

        if i == 0:
            nodal_data = {
                node_label: {f: []
                             for f in fields}
                for node_label in node_labels
            }
        for field_value, node_label in zip(element_field, node_labels):
            nodal_data[node_label][field].append(field_value[0])
        data_dict[field] = np.zeros(len(nodal_data))
        for j, node_label in enumerate(sorted(nodal_data.keys())):
            data_array = nodal_data[node_label][field]
            data_dict[field][j] = sum(data_array) / len(data_array)
    return data_dict
def write_stress_pickles(stress_odb_filename, static_pickle_filename,
                         cyclic_pickle_filename):
    stress_odb = odbAccess.openOdb(stress_odb_filename)

    instance_name = stress_odb.rootAssembly.instances.keys()[0]
    element_set_names = stress_odb.rootAssembly.instances[
        instance_name].elementSets.keys()
    element_set_name = None
    for element_set_name in element_set_names:
        if 'ballast_elements' in element_set_name.lower():
            break
    stress_odb.close()
    static_stresses = read_field_from_odb('S',
                                          stress_odb_filename,
                                          step_name='gravity',
                                          set_name=element_set_name,
                                          instance_name=instance_name)
    loading_stresses = read_field_from_odb('S',
                                           stress_odb_filename,
                                           step_name='loading',
                                           set_name=element_set_name,
                                           instance_name=instance_name)

    cyclic_stresses = loading_stresses - static_stresses

    with open(static_pickle_filename, 'wb') as static_pickle:
        pickle.dump(
            {
                'data': static_stresses,
                'instance': instance_name,
                'element_set': element_set_name
            }, static_pickle)

    with open(cyclic_pickle_filename, 'wb') as cyclic_pickle:
        pickle.dump(
            {
                'data': cyclic_stresses,
                'instance': instance_name,
                'element_set': element_set_name
            }, cyclic_pickle)
Example #5
0
def write_dante_pickle(odb_file_name, step_name, pickle_file_name, fatigue_set_name=None, instance_name=None,
                       coordinate_system=None):
    field_vars = ['HV']
    dante_dict = {}

    if instance_name is None:
        odb = odbAccess.openOdb(odb_file_name, readOnly=True)
        instance_names = odb.rootAssembly.instances.keys()
        if len(instance_names) == 1:
            instance_name = instance_names[0]
        else:
            raise ValueError('odb has multiple instances, please specify an instance')
    for var in field_vars:
        dante_dict[var] = read_field_from_odb(var, odb_file_name, step_name, frame_number=0,
                                              element_set_name=fatigue_set_name, instance_name=instance_name)
    residual_stress, n, e = read_field_from_odb('S', odb_file_name, step_name, frame_number=0,
                                                element_set_name=fatigue_set_name,  instance_name=instance_name,
                                                coordinate_system=coordinate_system, get_position_numbers=True)

    dante_dict['S'] = residual_stress

    with open(pickle_file_name, 'w') as pickle_handle:
        pickle.dump(dante_dict, pickle_handle)
Example #6
0
if __name__ == '__main__':
    settings_pickle_file = sys.argv[-2]
    results_pickle_file = sys.argv[-1]
    with open(settings_pickle_file, 'rb') as settings_pickle:
        data = pickle.load(settings_pickle)
    par = data['parameter_dict']
    boundary_conditions = data['boundary_conditions']
    strain_odb_file_name = str(par['strain_odb_file_name'])
    instance_name = str(par['instance_name'])
    set_name = str(par['set_name'])
    step_name = str(par['step_name'])
    strain_field_var = str(par['strain_field_var'])
    strain, _, element_labels = read_field_from_odb(
        strain_field_var,
        strain_odb_file_name,
        step_name=step_name,
        instance_name=instance_name,
        get_position_numbers=True,
        set_name=set_name,
        frame_number=par['frame_number'])

    _, node_labels, _ = read_field_from_odb(strain_field_var,
                                            strain_odb_file_name,
                                            step_name=step_name,
                                            instance_name=instance_name,
                                            set_name=set_name,
                                            get_position_numbers=True,
                                            frame_number=par['frame_number'],
                                            position=ELEMENT_NODAL)

    node_labels = np.array(node_labels, dtype=int)
    node_labels = np.unique(node_labels)
Example #7
0
        '~/scania_gear_analysis/pickles/tooth_root_fatigue_analysis/'
        'mesh_' + mesh + '/geometry/nodal_positions.pkl')

    node_labels = get_list_from_set_file(
        '../planetary_gear/input_files/gear_models/planet_gear/mesh_' + mesh +
        '/' + node_set_name + '.inc')
    element_labels = get_list_from_set_file(
        '../planetary_gear/input_files/gear_models/planet_gear/mesh_' + mesh +
        '/' + element_set_name + '.inc')

    add_node_set(odb_file_name, node_set_name, node_labels, 'tooth_right')
    add_element_set(odb_file_name, element_set_name, element_labels,
                    'tooth_right')

    _, node_labels, _ = read_field_from_odb('HV',
                                            odb_file_name,
                                            element_set_name,
                                            step_name='dante_results_0_5',
                                            frame_number=0,
                                            instance_name='tooth_right',
                                            get_position_numbers=True)
    nodal_dict = get_nodal_coordinates_from_node_set(
        odb_file_name, node_set_name, instance_name='tooth_right')

    node_coordinates = np.zeros((len(node_labels), 3))
    for i, node_label in enumerate(node_labels):
        node_coordinates[i, :] = nodal_dict[node_label]

    with open(coordinate_pickle_file_name, 'w') as pickle_handle:
        pickle.dump(node_coordinates, pickle_handle)
Example #8
0
        os.makedirs(pickle_directory)

    if not os.path.isdir(pickle_directory_geometry):
        os.makedirs(pickle_directory_geometry)

    for part in ['left', 'right']:
        add_element_set(dante_odb_filename, element_set_name, element_labels, 'tooth_' + part)

        for cd in [0.5, 0.8, 1.1, 1.4]:
            pickle_name = pickle_directory + 'data_' + str(cd).replace('.', '_') + '_' + part + '.pkl'
            step = 'dante_results_' + str(cd).replace('.', '_')
            write_dante_pickle(dante_odb_filename, step, pickle_name, 'tooth_root_volume_elements',
                               instance_name='tooth_' + part, coordinate_system=cylindrical_system_z)

        input_file_reader = InputFileReader()
        input_file_reader.read_input_file('../planetary_gear/input_files/planet_sun/planet_dense_geom_' +
                                          geom_file_names[part] + '.inc')

        node_dict = {node[0]: node[1:4] for node in input_file_reader.nodal_data}

        _, node_labels, _ = read_field_from_odb('HV', dante_odb_filename, step, frame_number=0,
                                                element_set_name='tooth_root_volume_elements',
                                                instance_name='tooth_' + part,  get_position_numbers=True)

        nodal_coordinates = np.zeros((len(node_labels), 3))
        for i, node_label in enumerate(node_labels):
            nodal_coordinates[i, :] = node_dict[node_label]

        with open(pickle_directory_geometry + 'nodal_coordinates_tooth_' + part + '.pkl', 'w') as geom_pickle_handle:
            pickle.dump(nodal_coordinates, geom_pickle_handle)
Example #9
0
        pickle_name = pickle_directory + 'data_utmis_' + specimen + '.pkl'
        write_dante_pickle(dante_odb_filename, step_name, pickle_name,
                           element_set_name)

        # Writes the nodal coordinates
        input_file_reader = InputFileReader()
        input_file_reader.read_input_file('../fatigue_specimens/UTMIS/utmis_' +
                                          specimen + '/' + 'utmis_' +
                                          specimen + '.inc')

        # get the node labels by reading HV

        _, node_labels, _ = read_field_from_odb(
            'HV',
            dante_odb_filename,
            step_name=step_name,
            frame_number=0,
            element_set_name=element_set_name,
            get_position_numbers=True)

        nodal_coordinates = np.zeros((len(node_labels), 3))
        for i, node_label in enumerate(node_labels):
            nodal_coordinates[i, :] = input_file_reader.nodal_data[node_label -
                                                                   1][1:]

        if not os.path.isdir(pickle_directory_geometry):
            os.makedirs(pickle_directory_geometry)

        with open(
                pickle_directory_geometry + 'nodal_coordinates_' + specimen +
                '.pkl', 'w') as pickle_handle:
def create_dante_step(from_odb_name,
                      to_odb_name,
                      results_step_name,
                      from_step=None):
    # Inspect the odb to get available data
    # Inspect the odb to get available data
    from_odb = openOdb(from_odb_name, readOnly=False)
    if from_step is None:
        step_name, _ = from_odb.steps.items()[-1]
    else:
        step_name = from_step
    scalar_variables = from_odb.steps[step_name].frames[-1].fieldOutputs.keys()
    from_odb.close()
    if 'NT11' in scalar_variables:
        scalar_variables.remove('NT11')

    if 'U' in scalar_variables:
        scalar_variables.remove('U')

    if 'S' in scalar_variables:
        scalar_variables.remove('S')

    if 'E' in scalar_variables:
        scalar_variables.remove('E')

    data_dict = {}
    for scalar_variable in scalar_variables:
        print "reading variable", scalar_variable
        data_dict[scalar_variable] = read_field_from_odb(
            scalar_variable, from_odb_name, step_name, -1)
    data_dict['S'] = read_field_from_odb('S', from_odb_name, step_name, -1)
    data_dict['HV'] = HRC2HV(data_dict['SDV_HARDNESS'])
    scalar_variables.append('HV')

    for scalar_variable in scalar_variables:
        print "Write field", scalar_variable
        field = data_dict[scalar_variable]
        write_field_to_odb(field_data=field,
                           field_id=scalar_variable,
                           odb_file_name=to_odb_name,
                           step_name=results_step_name,
                           instance_name='specimen_part_pos',
                           frame_number=0)
        field = flip_node_order(field, axis='z')
        write_field_to_odb(field_data=field,
                           field_id=scalar_variable,
                           odb_file_name=to_odb_name,
                           step_name=results_step_name,
                           instance_name='specimen_part_neg',
                           frame_number=0)

    print "Write stress"
    stress = data_dict['S']
    write_field_to_odb(
        field_data=stress,
        field_id='S',
        odb_file_name=to_odb_name,
        step_name=results_step_name,
        instance_name='specimen_part_pos',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])
    stress = flip_node_order(stress, axis='z')
    stress[:, 3] *= -1
    stress[:, 5] *= -1
    write_field_to_odb(
        field_data=stress,
        field_id='S',
        odb_file_name=to_odb_name,
        step_name=results_step_name,
        instance_name='specimen_part_neg',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])
Example #11
0
from abaqusConstants import MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL

import sys

from odb_io_functions import read_field_from_odb
from odb_io_functions import write_field_to_odb
from odb_io_functions import cylindrical_system_z

# There are a lot of arguments to abaqus just use the seven last ones
from_odb_name = sys.argv[-5]
to_odb_name = sys.argv[-4]
from_step = sys.argv[-3]
from_frame = int(sys.argv[-2])
to_step = sys.argv[-1]

stress_data = read_field_from_odb('S',
                                  from_odb_name,
                                  from_step,
                                  from_frame,
                                  element_set_name='GEARELEMS',
                                  instance_name='EVAL_TOOTH_1',
                                  coordinate_system=cylindrical_system_z)

write_field_to_odb(
    stress_data,
    'S',
    to_odb_name,
    to_step,
    instance_name='tooth_left',
    invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])
Example #12
0
from_step = sys.argv[-5]
from_frame = int(sys.argv[-4])
to_step = sys.argv[-3]
to_frame = int(sys.argv[-2])
to_frame_value = float(sys.argv[-1])

planet_system = CoordinateSystem(name='planet_system',
                                 origin=(0., 83.5, 0.),
                                 point1=(1.0, 83.5, 0.0),
                                 point2=(0.0, 84.5, 0.0),
                                 system_type=CYLINDRICAL)

stress_data = read_field_from_odb('S',
                                  from_odb_name,
                                  from_step,
                                  from_frame,
                                  element_set_name='GEARELEMS',
                                  instance_name='EVAL_TOOTH_0',
                                  coordinate_system=planet_system,
                                  rotating_system=True)
write_field_to_odb(
    stress_data,
    'S',
    to_odb_name,
    to_step,
    frame_number=to_frame,
    frame_value=to_frame_value,
    instance_name='tooth_right',
    invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])

stress_data = read_field_from_odb('S',
                                  from_odb_name,
Example #13
0
from odb_io_functions import read_field_from_odb

from write_nodal_coordinates import get_list_from_set_file

if __name__ == '__main__':
    pickle_directory = '/scratch/users/erik/scania_gear_analysis/pickles/utmis_specimens/stresses/'
    element_set_name = 'fatigue_volume_elements'
    odb_directory = '/scratch/users/erik/scania_gear_analysis/abaqus/utmis_specimens/'

    if not os.path.isdir(pickle_directory):
        os.makedirs(pickle_directory)

    for specimen in ['smooth', 'notched']:
        mechanical_odb_filename = odb_directory + 'unit_load_' + specimen + '.odb'

        element_labels = get_list_from_set_file('../fatigue_specimens/UTMIS/utmis_' + specimen + '/' +
                                                element_set_name + '_' + specimen + '.inc')
        print "The element set", element_set_name, "has ", len(element_labels), "elements"
        add_element_set(mechanical_odb_filename, element_set_name, element_labels, instance_name='PART')

        odb = odbAccess.openOdb(mechanical_odb_filename, readOnly=False)
        step_name = odb.steps.keys()[-1]
        odb.close()
        stress = read_field_from_odb('S', mechanical_odb_filename, step_name, frame_number=-1,
                                     element_set_name=element_set_name, instance_name='PART')

        print "The stress matrix has shape ", stress.shape, "for specimen", specimen
        pickle_file_name = pickle_directory + 'unit_load_' + specimen + '.pkl'
        with open(pickle_file_name, 'w') as pickle_handle:
            pickle.dump(stress, pickle_handle)
def create_dante_step(from_odb_name,
                      to_odb_name,
                      results_step_name,
                      from_step=None):
    # Inspect the odb to get available data
    from_odb = openOdb(from_odb_name, readOnly=False)
    if from_step is None:
        step_name, _ = from_odb.steps.items()[-1]
    else:
        step_name = from_step
    scalar_variables = from_odb.steps[step_name].frames[-1].fieldOutputs.keys()
    from_odb.close()
    if 'NT11' in scalar_variables:
        scalar_variables.remove('NT11')

    if 'U' in scalar_variables:
        scalar_variables.remove('U')

    if 'E' in scalar_variables:
        scalar_variables.remove('E')

    if 'S' in scalar_variables:
        scalar_variables.remove('S')

    data_dict = {}
    for scalar_variable in scalar_variables:
        print("reading variable", scalar_variable)
        data_dict[scalar_variable] = read_field_from_odb(
            scalar_variable, from_odb_name, step_name, -1)
    data_dict['S'] = read_field_from_odb('S', from_odb_name, step_name, -1)

    for scalar_field in scalar_variables:
        field = data_dict[scalar_field]
        write_field_to_odb(field_data=field,
                           field_id=scalar_field,
                           odb_file_name=to_odb_name,
                           step_name=results_step_name,
                           instance_name='tooth_right',
                           frame_number=0)
        field = flip_node_order(field, axis='z')
        write_field_to_odb(field_data=field,
                           field_id=scalar_field,
                           odb_file_name=to_odb_name,
                           step_name=results_step_name,
                           instance_name='tooth_left',
                           frame_number=0)

    stress = data_dict['S']
    write_field_to_odb(
        field_data=stress,
        field_id='S',
        odb_file_name=to_odb_name,
        step_name=results_step_name,
        instance_name='tooth_right',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])
    stress = flip_node_order(stress, axis='z')
    stress[:, 3:5] *= -1
    write_field_to_odb(
        field_data=data_dict['S'],
        field_id='S',
        odb_file_name=to_odb_name,
        step_name=results_step_name,
        instance_name='tooth_left',
        frame_number=0,
        invariants=[MISES, MAX_PRINCIPAL, MID_PRINCIPAL, MIN_PRINCIPAL])

    hv = HRC2HV(data_dict['SDV_HARDNESS'])
    write_field_to_odb(field_data=hv,
                       field_id='HV',
                       odb_file_name=to_odb_name,
                       step_name=results_step_name,
                       instance_name='tooth_right',
                       frame_number=0)
    hv = flip_node_order(hv, axis='z')
    write_field_to_odb(field_data=hv,
                       field_id='HV',
                       odb_file_name=to_odb_name,
                       step_name=results_step_name,
                       instance_name='tooth_left',
                       frame_number=0)

    bainite = data_dict['SDV_UBAINITE'] + data_dict['SDV_LBAINITE']
    write_field_to_odb(field_data=bainite,
                       field_id='BAINITE',
                       odb_file_name=to_odb_name,
                       step_name=results_step_name,
                       instance_name='tooth_right',
                       frame_number=0)
    bainite = flip_node_order(bainite, 'z')
    write_field_to_odb(field_data=bainite,
                       field_id='BAINITE',
                       odb_file_name=to_odb_name,
                       step_name=results_step_name,
                       instance_name='tooth_left',
                       frame_number=0)
    for load in simulated_loads:
        for tooth_part in ['tooth_left', 'tooth_right']:
            tooth_stress_pickle_dir = '/scratch/users/erik/scania_gear_analysis/pickles/tooth_root_stresses/'
            tooth_root_pickle_name = 'stresses_' + str(
                int(load)) + '_Nm_' + root_path_names[tooth_part] + '.pkl'
            with open(tooth_stress_pickle_dir +
                      tooth_root_pickle_name) as pickle_handle:
                tooth_root_stresses = pickle.load(pickle_handle)
            idx_max = np.argmax(tooth_root_stresses[:, 1])
            idx_min = np.argmin(tooth_root_stresses[:, 1])

            odb_file_name = gear_odb_directory + 'planet_gear_stresses_' + str(
                int(load)) + '_Nm.odb'
            min_load = read_field_from_odb('S',
                                           odb_file_name=odb_file_name,
                                           element_set_name=element_set_name,
                                           step_name='mechanical_stresses',
                                           frame_number=idx_min,
                                           instance_name=tooth_part)
            max_load = read_field_from_odb('S',
                                           odb_file_name=odb_file_name,
                                           element_set_name=element_set_name,
                                           step_name='mechanical_stresses',
                                           frame_number=idx_max,
                                           instance_name=tooth_part)

            stress_dict[tooth_part]['max_load'][load] = max_load
            stress_dict[tooth_part]['min_load'][load] = min_load

    with open(pickle_directory + 'gear_stresses.pkl', 'w') as pickle_handle:
        pickle.dump(stress_dict, pickle_handle)
Example #16
0
odb_file_name = str(data['odb_file_name'])
step_name = str(data['step_name'])
frame_number = data['frame_number']
set_name = str(data['set_name'])
instance_name = str(data['instance_name'])
get_position_numbers = data['get_position_numbers']
get_frame_value = data['get_frame_value']
position = INTEGRATION_POINT
if str(data['position']) == 'NODAL':
    position = NODAL

field_data = read_field_from_odb(field_id,
                                 odb_file_name,
                                 step_name,
                                 frame_number,
                                 set_name,
                                 instance_name=instance_name,
                                 get_position_numbers=False,
                                 get_frame_value=False,
                                 position=position)

data_dict = {}
if not get_position_numbers and not get_frame_value:
    data_dict['data'] = field_data
else:
    data_dict['data'] = field_data[0]
    if get_frame_value:
        data_dict['frame_value'] = field_data[1]
        pos_idx = 2
    else:
        pos_idx = 1