示例#1
0
def compare_exp_sim(name,loading_cycles=1,xitem='axial_strain',yitem='axial_stress',save_types=['.png','.pdf']):
    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 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])

    exp_filename = ExperimentDirectory + name + '.csv'
    experiment = ExperimentData(exp_filename)
    sim_filename = SimulationDirectory + name + '.csv'
    simulation = SimulationData(sim_filename,period)
    
    exp_xitem = experiment.obtainNthCycle(xitem,loading_cycles)
    exp_yitem = experiment.obtainNthCycle(yitem,loading_cycles)
    
    sim_xitem = simulation.obtainNthCycle(xitem,loading_cycles)
    sim_yitem = simulation.obtainNthCycle(yitem,loading_cycles)
    
    plt.plot(exp_xitem,exp_yitem,label='exp')
    plt.plot(sim_xitem,sim_yitem,label='sim')
    
    plt.legend(loc=0)
    
    figure_path = ArticleFigureDirectory
    figure_name = name + '_' + xitem + '_' + yitem
    if not os.path.isdir(ArticleFigureDirectory):
        os.makedirs(ArticleFigureDirectory)
        print 'Create new directory:',ArticleFigureDirectory
    if figure_path <> None and figure_name<> None:
        for save_type in save_types:
            plt.savefig(figure_path + figure_name + save_type, dpi=150, transparent=True)
            print 'save as', figure_path + figure_name + save_type
            
    plt.show()
    plt.close()
示例#2
0
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=temperature_mean,
                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')

    umat = UMAT(UMATDirectory='F:\\GitHub\\umat\\',
                UMATMainFile='MAIN_IN718.for',
                ParameterFortranFile='PARAMETERS_SS304.for',
                OutputFortranFile='OUTPUT.for',
                OutputTextFile=name + '_output.txt')

    #    umat = UMAT(UMATDirectory = 'F:\\UMAT\\Fangjie\\',
    #                UMATMainFile = 'AO304Tanakav6VariDamageMyisokin3.for',
    #                ParameterFortranFile = 'PARAMETERS_SS304.for',
    #                OutputFortranFile = 'OUTPUT.for',
    #                OutputTextFile = name + '_output.txt')

    #    umat = UMAT(UMATDirectory = 'F:\\UMAT\\SS304\\',
    #                UMATMainFile = 'MAIN_SS304.for',
    #                ParameterFortranFile = 'PARAMETERS_SS304.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()
def create_plot_data(figure_path=None,figure_name=None):
#==============================================================================
# x,y label
#==============================================================================
    xlabel = xylabels['axial_strain']
    ylabel = xylabels['axial_stress']
#==============================================================================
# plot lines
#==============================================================================
    i = 0
    marker_list = ['s','o','^','D']
    plot_data = PlotData()
    experiment_log = ExperimentLog(ExperimentLogFile)
    for name in ['7101','7102','7103']:
        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 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])
        
        filename = ExperimentDirectory + name + '.csv'
        experiment = ExperimentData(filename)
        strain = experiment.axial_strain
        stress = experiment.axial_stress
        
        plot_data.addLine(strain*100,
                          stress,
                          xlabel=xlabel,
                          ylabel=ylabel,
                          linelabel='Exp.' + str(int(temperature_mode[0])+273)+'K',
                          linewidth=2,
                          linestyle='',
                          marker=marker_list[i],
                          markersize=12,
                          color=color_list[i],
                          skip=20)
        
        sim_filename = SimulationDirectory + name + '.csv'
        period = 200
        simulation = SimulationData(sim_filename,period)
        strain = simulation.axial_strain
        stress = simulation.axial_stress
        
        plot_data.addLine(strain*100,
                          stress,
                          xlabel=xlabel,
                          ylabel=ylabel,
                          linelabel='Sim.' + str(int(temperature_mode[0])+273)+'K',
                          linewidth=2,
                          linestyle='-',
                          marker=None,
                          markersize=12,
                          color=color_list[i])
        i += 1
    plot_data.writeToFile(figure_path,figure_name)
示例#4
0
def create_plot_data(figure_path=None, figure_name=None):
    #==============================================================================
    # x,y label
    #==============================================================================
    xlabel = xylabels['axial_strain']
    ylabel = xylabels['axial_stress']
    #==============================================================================
    # plot lines
    #==============================================================================
    i = 0
    marker_list = ['s', 'o', '^', 'D']
    plot_data = PlotData()
    experiment_log = ExperimentLog(ExperimentLogFile)
    #    for name in ['7110','7111','7112','7113','7114','7115','7116']:
    #    for name in ['7110','7111','7112','7113','7114']:
    #    for name in experiment_type_dict['TC-IP'] + experiment_type_dict['TC-OP']:
    #    for name in experiment_type_dict['TC-OP']:
    #    for name in experiment_type_dict['PRO-IP']:
    #    for name in experiment_type_dict['NPR-IP']+experiment_type_dict['PRO-IP']+['7110','7111','7112','7113','7114']:
    for name in ['7111']:
        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 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])

        filename = ExperimentDirectory + name + '.csv'
        experiment = ExperimentData(filename)
        #        print experiment.axial_count_index_list
        youngs_modulus, poisson_ratio, shear_modulus, yield_stress = calculate_elastic_by_temperature_in718(
            650)
        e_list = []
        count = []
        for i in experiment.axial_count_index_list[1:-1:1]:
            strain = experiment.obtainNthCycle('axial_strain', i)
            stress = experiment.obtainNthCycle('axial_stress', i)
            p = (max(strain) - max(stress) / youngs_modulus) * 4 * i
            masing = obtain_masing_curve([strain, stress])
            e = obtain_youngs_modulus(masing, 0.0025)
            count.append(i)
            e_list.append(e)

#        damage = 1.0 - np.array(e_list)/youngs_modulus
        damage = 1.0 - np.array(e_list) / max(e_list)
        if min(damage) <= 0:
            damage += abs(min(damage))
        else:
            damage -= abs(min(damage))


#            plot_data.addLine(masing[0]*100,
#                              masing[1],
#                              xlabel=xlabel,
#                              ylabel=ylabel,
#                              linelabel=str(int(temperature_mode[0])+273)+'K',
#                              linewidth=2,
#                              linestyle='-',
#                              marker=None,
#                              markersize=12,
#                              color='auto')

        damage[0] = 0
        #        damage[1]=0
        #        damage[2]=0
        #        damage[3]=0

        plot_data.addLine(count,
                          damage,
                          xlabel='Accumulated plastic strain $p$ [%]',
                          ylabel='Damage $D$',
                          linelabel=axial_strain,
                          linewidth=2,
                          linestyle='',
                          marker='o',
                          markersize=12,
                          color='auto')

    plot_data.writeToFile(figure_path, figure_name)
def create_plot_data_exp_half_life_cycle(figure_path=None,figure_name=None):
#==============================================================================
# x,y label
#==============================================================================
    xlabel = xylabels['shear_strain']
    ylabel = xylabels['shear_stress']
#==============================================================================
# plot lines
#==============================================================================
    i = 0
    marker_list = ['s','o','^','D']
    plot_data = PlotData()
    experiment_log = ExperimentLog(ExperimentLogFile)
    for name in ['7006','7007','7009']:
        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 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])
        
        filename = ExperimentDirectory + name + '.csv'
        experiment = ExperimentData(filename)
        strain = experiment.obtainNthCycle('shear_strain',experiment.half_life_cycle)
        stress = experiment.obtainNthCycle('shear_stress',experiment.half_life_cycle)
        plot_data.addLine(strain*100,
                          stress,
                          xlabel=xlabel,
                          ylabel=ylabel,
                          linelabel=str(int(temperature_mode[0])+273)+'K',
                          linewidth=2,
                          linestyle='-',
                          marker=None,
                          markersize=12,
                          color=color_list[i])
        i += 1
    
#    material = material_in718()
#    epsilon,sigma = material.plotCyclicStrengthCoefficient()
#    plot_data.addLine(epsilon*100,
#                      sigma,
#                      xlabel=xlabel,
#                      ylabel=ylabel,
#                      linelabel='Ramberg-Osgood',
#                      linewidth=4,
#                      linestyle='--',
#                      marker=None,
#                      markersize=12,
#                      color='black')
    
    plot_data.writeToFile(figure_path,figure_name)
示例#6
0
def plot_sim_all(name,
                 begin_cycle,
                 end_cycle,
                 xitem='axial_strain',
                 yitem='axial_stress'):
    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 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])

    sim_filename = SimulationDirectory + name + '.csv'
    simulation = SimulationData(sim_filename, period)

    sim_xitem = simulation.obtainNthCycle(xitem, begin_cycle, end_cycle)
    sim_yitem = simulation.obtainNthCycle(yitem, begin_cycle, end_cycle)

    plt.plot(sim_xitem, sim_yitem)

    plt.show()
    plt.close()
示例#7
0
def create_plot_data_exp_half_life_cycle(figure_path=None, figure_name=None):
    #==============================================================================
    # x,y label
    #==============================================================================
    xlabel = xylabels['axial_strain']
    ylabel = xylabels['axial_stress']
    #==============================================================================
    # plot lines
    #==============================================================================
    i = 0
    marker_list = ['s', 'o', '^', 'D']
    plot_data = PlotData()
    experiment_log = ExperimentLog(ExperimentLogFile)
    #    for name in ['7110','7111','7112','7113','7114','7115','7116']:
    for name in ['7045']:
        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 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])

        filename = ExperimentDirectory + name + '.csv'
        experiment = ExperimentData(filename)
        print experiment.axial_count_index_list
        e_list = []
        count = []
        for i in experiment.axial_count_index_list[2:200:50]:
            strain = experiment.obtainNthCycle('axial_strain', i)
            stress = experiment.obtainNthCycle('axial_stress', i)
            masing = obtain_masing_curve([strain, stress])
            e = obtain_youngs_modulus(masing, 0.002)
            count.append(i)
            e_list.append(e)

            plot_data.addLine(masing[0] * 100,
                              masing[1],
                              xlabel=xlabel,
                              ylabel=ylabel,
                              linelabel=str(int(temperature_mode[0]) + 273) +
                              'K',
                              linewidth=2,
                              linestyle='-',
                              marker=None,
                              markersize=12,
                              color='auto')


#        plot_data.addLine(count,
#                          e_list,
#                          xlabel=xlabel,
#                          ylabel=ylabel,
#                          linelabel='',
#                          linewidth=2,
#                          linestyle='',
#                          marker='o',
#                          markersize=12,
#                          color='auto')

    plot_data.writeToFile(figure_path, figure_name)
示例#8
0
def plot_exp_pv(names,item='axial_stress'):
    for name in names:
        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 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])
    
        exp_filename = ExperimentDirectory + name + '.csv'
        experiment = ExperimentData(exp_filename)
        cycle,peak,valley = experiment.obtainPeakValley(item)
        plt.plot(cycle,peak)
        plt.plot(cycle,valley)
        
    plt.xscale('log')
#    plt.yscale('log')
    
    plt.show()
    plt.close()
示例#9
0
def plot_sim_pv(name, item='axial_stress'):
    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 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])

    sim_filename = SimulationDirectory + name + '.csv'
    simulation = SimulationData(sim_filename, period)
    cycle, peak, valley = simulation.obtainPeakValley('axial_stress')

    plt.plot(cycle, peak)
    plt.plot(cycle, valley)

    #    print cycle
    #    print peak
    #    print valley

    plt.show()
    plt.close()
示例#10
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)