def workbench(name,loading_cycles=None,copy=True,film_coefficient=0.0,sink_temperature=0.0,
              temperature_list=[],thermal_strain_list=[0.0,-0.0],heat_flux=0.0,
              film_coefficient_outer=0.0,film_coefficient_inner=0.0,emissivity=0.95,
              sink_temperature_inner=293.15,sink_temperature_outer=293.15,outer_temperature=293.15):
    """
    某试件对应的边界条件下的数值模拟。
    """
    experiment_log = ExperimentLog(ExperimentLogFile)
#    experiment_log.output(name)
    regular = r'.*'
    load_type = experiment_log.obtainItem(name,'load_type',regular)[0]
    regular = r'\d+\.?\d*'
    temperature_mode = experiment_log.obtainItem(name,'temperature_mode',regular)
    if temperature_list == []:
        if len(temperature_mode) == 1:
            temperature_list = [float(temperature_mode[0]), float(temperature_mode[0])]
        if len(temperature_mode) == 2:
            temperature_list = [float(temperature_mode[0]), float(temperature_mode[1])]
    d_out = float(experiment_log.obtainItem(name,'d_out',regular)[0])
    gauge_length = float(experiment_log.obtainItem(name,'gauge_length',regular)[0])
    axial_strain = float(experiment_log.obtainItem(name,'axial_strain',regular)[0])
    angel_strain = float(experiment_log.obtainItem(name,'angel_strain',regular)[0])
    equivalent_strain = float(experiment_log.obtainItem(name,'equivalent_strain',regular)[0])
    period = float(experiment_log.obtainItem(name,'period',regular)[0])
    axial_temperature_phase = float(experiment_log.obtainItem(name,'axial_temperature_phase',regular)[0])
    life = float(experiment_log.obtainItem(name,'comments',regular)[0])
#==============================================================================
# material
#==============================================================================
    material = Material()
    material.setName(name='IN718')
    material.setTemperature(temperature=650.0)
    material.setMonotonic(youngs_modulus=167100.0,poisson_ratio=0.2886,yield_stress=1064.0)
    material.setCyclicAxial(sigma_f=1034.0,b=-0.04486,epsilon_f=0.11499,c=-0.52436)
    material.setCyclicTorsion(tau_f=1034.0/np.sqrt(3),b0=-0.04486,gamma_f=0.11499*np.sqrt(3),c0=-0.52436)
    predicted_life = material.calculateMansonCoffinLife(equivalent_strain/100.0)
#==============================================================================
# experiment
#==============================================================================
    exp_full_name = ExperimentDirectory + name + '.csv'
    if os.path.exists(exp_full_name):
        exp = ExperimentData(exp_full_name)
        experimental_life = exp.total_axial_count
    else:
        print ('%s is not existed' % exp_full_name)
#==============================================================================
# load
#==============================================================================
    temperature_mean = (temperature_list[0] + temperature_list[1])/2.0
    temperature_min = min(temperature_list)
    temperature_max = max(temperature_list)
    load = Load(runing_time=[0], temperature=[temperature_mean], axial_strain=[0], shear_strain=[0], first_cycle_shift=1)
    axial_strain = axial_strain/100.0
    shear_strain = np.deg2rad(angel_strain)*d_out/2.0/gauge_length
    if loading_cycles == None:
        loading_cycles = min(int(predicted_life/4.0),5000)
    use_exp_data = True
    thermal_strain_min = min(thermal_strain_list)/100.0
    thermal_strain_max = max(thermal_strain_list)/100.0
#==============================================================================
# Diamond path TMF IP
#==============================================================================
    if load_type == 'cyclic diamond path' and axial_temperature_phase == 0.0:
        use_exp_data = False
        load.setLoadBiaxial(int(loading_cycles),
                            [0,period/4.0,period/2.0,period/4.0*3.0,period],
                            [temperature_mean,temperature_max,temperature_mean,temperature_min,temperature_mean],
                            [0,axial_strain,0,-1*axial_strain,0],
                            [-1*shear_strain,0,shear_strain,0,-1*shear_strain])
#==============================================================================
# Proportional path TMF IP
#==============================================================================
    if load_type == 'cyclic proportional path' and axial_temperature_phase == 0.0:
        use_exp_data = False
        load.setLoadBiaxial(int(loading_cycles),
                            [0,period/4.0,period/2.0,period/4.0*3.0,period],
                            [temperature_mean,temperature_max,temperature_mean,temperature_min,temperature_mean],
                            [0,axial_strain,0,-1*axial_strain,0],
                            [0,shear_strain,0,-1*shear_strain,0])
#==============================================================================
# Uniaxial TMF IP
#==============================================================================
    if load_type == 'cyclic tension compression' and axial_temperature_phase == 0.0:
        use_exp_data = False
        load.setLoadBiaxial(int(loading_cycles),
                            [0,period/4.0,period/2.0,period/4.0*3.0,period],
                            [temperature_mean,temperature_max,temperature_mean,temperature_min,temperature_mean],
                            [0,axial_strain*1,0,-1*axial_strain*1,0],
                            [0,shear_strain,0,-1*shear_strain,0])
#==============================================================================
# Uniaxial TMF OP
#==============================================================================
    if load_type == 'cyclic tension compression' and axial_temperature_phase == 180.0:
        use_exp_data = False
        load.setLoadBiaxial(int(loading_cycles),
                            [0,period/4.0,period/2.0,period/4.0*3.0,period],
                            [temperature_mean,temperature_min,temperature_mean,temperature_max,temperature_mean],
                            [0,axial_strain,0,-1*axial_strain,0],
                            [0,shear_strain,0,-1*shear_strain,0])
#==============================================================================
# Uniaxial TMF 90
#==============================================================================
    if load_type == 'cyclic tension compression' and axial_temperature_phase == 90.0:
        use_exp_data = False
        load.setLoadBiaxial(int(loading_cycles),
                            [0,period/4.0,period/2.0,period/4.0*3.0,period],
                            [temperature_min,temperature_mean,temperature_max,temperature_mean,temperature_min],
                            [0,axial_strain,0,-1*axial_strain,0],
                            [0,shear_strain,0,-1*shear_strain,0])
#==============================================================================
# load from experiment data
#==============================================================================
    if use_exp_data:
        if loading_cycles == None:
            load.setLoadFromExperiment(exp,runing_time=None)
        else:
            load.setLoadFromExperiment(exp,runing_time=period*loading_cycles)
#==============================================================================
# load of convection
#==============================================================================
    load.setConvection(film_coefficient,sink_temperature)
#==============================================================================
# load of thermal
#==============================================================================
    load.setThermal(heat_flux,film_coefficient_outer,film_coefficient_inner,emissivity,sink_temperature_inner,sink_temperature_outer,outer_temperature)
#==============================================================================
# Step
#==============================================================================
#    step = Step(predefined_temperature = int(exp.initial_temperature), 
#              time_period = int(load.total_runing_time), initial_inc = 0.005, 
#              min_inc = 0.0001, max_inc = 5, nonlinear = 'ON')
    step = Step(predefined_temperature = 20.0, 
              time_period = int(load.total_runing_time), initial_inc = 0.00001, 
              min_inc = 0.00000001, max_inc = period/40.0, nonlinear = 'OFF')
#==============================================================================
# UMAT
#==============================================================================
    umat = UMAT(UMATDirectory = 'F:\\GitHub\\umat\\', 
                UMATMainFile = 'MAIN_IN718.for', 
                ParameterFortranFile = 'PARAMETERS_IN718_TMF.for',
                OutputFortranFile = 'OUTPUT.for',
                OutputTextFile = name + '_output.txt')
#==============================================================================
# Job
#==============================================================================
    job = Job(JobName=name, UMAT=umat, Step=step, Load=load, copy=copy)

#    job.allProc()
    job.createDirectory()
    job.copyFiles()
    job.creatBatchFile()
    job.createAbaqusCAE()
    job.createAbaqusInput()
    job.run()
    job.autoPostProc()
示例#2
0
def calculate_fatigue_life(fatigue_model, material=material_in718()):
    material.show()
    experiment_log = ExperimentLog(ExperimentLogFile)

    #    FatigueDirectory = 'F:\\Database\\Fatigue\\%s\\' % fatigue_model
    #    FatigueDirectory = 'F:\\Database\\Fatigue\\'

    if not os.path.isdir(FatigueDirectory):
        os.makedirs(FatigueDirectory)
        print 'Create new directory:', FatigueDirectory

    headers = ''
    units = ''
    headers += 'Number of Cycles to Failure N\-(f),'
    units += 'cycle,'
    headers += 'Mises Equivalent Strain Amplitude \i(\g(De))\-(eq)/2,'
    units += 'mm/mm,'
    headers += 'Stress Amplitude e \i(\g(Ds))/2,'
    units += 'MPa,'
    headers += 'Specimen,'
    units += '-,'
    headers += 'Critical Plane,'
    units += 'deg,'
    headers += 'sigma_n_max,'
    units += 'MPa,'
    headers += 'delta_sigma,'
    units += 'MPa,'
    headers += 'delta_epsilon,'
    units += 'mm/mm,'
    headers += 'tau_n_max,'
    units += 'MPa,'
    headers += 'delta_tau,'
    units += 'MPa,'
    headers += 'delta_gamma,'
    units += '-,'
    headers += 'Predicted Fatigue Lifetime N\-(p),'
    units += 'cycle,'
    headers += 'Fatigue Coefficient,'
    units += '-,'
    headers += 'Temperature,'
    units += 'C,'
    headers += 'Temperature Gradient 1,'
    units += 'C/mm,'
    headers += 'Temperature Gradient 2,'
    units += 'C/mm,'
    headers += 'Load Type,'
    units += '-,'

    workbook = xlsxwriter.Workbook(FatigueDirectory + fatigue_model +
                                   '.xlsx')  # write to excel

    allresultfile = open(FatigueDirectory + fatigue_model + '.csv',
                         'w')  # write to csv all
    print >> allresultfile, headers[:-1]  # write to csv all
    print >> allresultfile, units[:-1]  # write to csv all

    json_data_list = []

    for experiment_type in experiment_type_list[:]:
        #        resultfile = open(FatigueDirectory + experiment_type[0] + '.csv', 'w') # write to csv
        #        print >>resultfile, headers # write to csv
        #        print >>resultfile, units # write to csv

        worksheet = workbook.add_worksheet(
            experiment_type[0])  # write to excel
        bold = workbook.add_format({'bold': 1})  # write to excel
        row_number = 1  # write to excel
        header_list = headers.split(',')  # write to excel
        unit_list = units.split(',')  # write to excel
        comment_list = [experiment_type[0]
                        for i in range(len(header_list))]  # write to excel
        worksheet.write_row('A' + str(row_number), header_list, bold)
        row_number += 1  # write to excel
        worksheet.write_row('A' + str(row_number), unit_list, bold)
        row_number += 1  # write to excel
        worksheet.write_row('A' + str(row_number), comment_list, bold)
        row_number += 1  # write to excel

        for name in experiment_type[1]:
            print name
            print experiment_type[0]
            regular = r'\d+\.?\d*'
            period = float(
                experiment_log.obtainItem(name, 'period', regular)[0])
            expriment_life = int(
                experiment_log.obtainItem(name, 'comments', regular)[0])
            equivalent_strain = float(
                experiment_log.obtainItem(name, 'equivalent_strain',
                                          regular)[0])
            """
            使用计算模拟结果。
            """
            sim = SimulationData(SimulationDirectory + name + '.csv', period)
            data, node, nth = calculate_data_fatigue_life(
                sim, material, fatigue_model)
            """
            使用计算模拟结果3D。
            """
            #            sim = SimulationData3D(SimulationDirectory+name+'.csv',period)
            #            data, node, nth = calculate_data_fatigue_life_3D(sim,material,fatigue_model)
            """
            使用试验结果。
            """
            #            exp = ExperimentData(ExperimentDirectory+name+'.csv')
            #            data, node, nth = calculate_data_fatigue_life(exp,material,fatigue_model)
            """
            取出Nf/2循环数据。
            """
            json_data = {
                'experiment_type': experiment_type[0],
                'name': name,
                'expriment_life': expriment_life,
                'equivalent_strain': equivalent_strain,
                'period': period,
                'nth': nth,
                'node': node.outputJson()
            }
            json_data_list.append(json_data)

            line = ''  # write to csv
            line += '%s,' % (expriment_life)  # write to csv
            line += '%s,' % (equivalent_strain)  # write to csv
            line += '%s,' % (0)  # write to csv
            line += '%s,' % (name)  # write to csv
            for d in data[1:]:  # write to csv
                line += '%s,' % (d)  # write to csv
#            print >>resultfile, line[:-1] # write to csv, ignore the last comma

            line += '%s' % (experiment_type[0])  # write to csv all
            print >> allresultfile, line  # write to csv all

            data_list = [expriment_life, equivalent_strain, 0, name
                         ] + data  # write to excel
            worksheet.write_row('A' + str(row_number), data_list)
            row_number += 1  # write to excel


#        resultfile.close() # write to csv

    allresultfile.close()  # write to csv all
    workbook.close()  # write to excel

    file_name = 'node.txt'
    write_file(file_name, json_data_list)