Пример #1
0
def cal_material_parameter2D(F_macro, type):
    # eps_macro = eps_macro[0]
    if type == '1Dlinear':
        filename = 'Mechanics1D_1_NNs.dat'
    elif type == '1Dnonlinear':
        filename = 'Mechanics1D_Nonlinear_1_NNs.dat'
    elif type == '2DLaminate':
        filename = 'yvonnetFunction3d_1com_3_NNs.dat'
    dimD, dimd, L, N, activation_func_type, min_input, max_input, min_max_output, \
    A, w, c, b, d, d0 = fp.get_NN_parameters(filename)
    F_macro = tramnnmx(F_macro.reshape(-1), min_input, max_input)
    sigma_macro = np.zeros(6)
    P = np.zeros(6)
    C_effective = np.zeros([6, 6])
    energy = 0
    for i in range(0, L):
        y = dot(A[:, :, i], F_macro) + b[:, :, i].reshape(-1)
        for n in range(0, N):
            z = dot(w[n, :, i], y) + d[n, :, i]
            zm = dot(w[n, :, i], y)
            energy += c[n, :, i] * tansig(z)
            sigma_macro += c[n, :, i] * dot(
                w[n, :, i], A[:, :, i]) * derivative_activation(z)
            C_effective += c[n, :, i] * dot(dot(w[n, :, i], A[:, :, i]).reshape(6, 1), dot(w[n, :, i], A[:, :, i]).reshape(1, 6)) \
                  * 4 * ((-2 * exp(-2*z) / (1 + exp(-2*z)) ** 2) + (4 * exp(-4*z) / (1 + exp(-2*z)) ** 3))
        energy += d0[:, :, i].reshape(-1)
    # return the real scale data
    energy_aver = postmnmx(energy, min_max_output[0], min_max_output[1])
    P = return_to_rescale_for_stress(sigma_macro, min_input, max_input,
                                     min_max_output[0], min_max_output[1])
    # P[0] = return_to_rescale_for_stress(sigma_macro[0], min_input[0], max_input[0], min_max_output[0], min_max_output[1])
    # P[1] = return_to_rescale_for_stress(sigma_macro[1], min_input[1], max_input[1], min_max_output[0], min_max_output[1])
    # P[2] = return_to_rescale_for_stress(sigma_macro[2], min_input[2], max_input[2], min_max_output[0], min_max_output[1])
    # P[3] = return_to_rescale_for_stress(sigma_macro[3], min_input[3], max_input[3], min_max_output[0], min_max_output[1])
    # sigma_macro[0] = postmnmx2(sigma_macro[0], min_max_output[0], min_max_output[1])
    # sigma_macro[1] = postmnmx2(sigma_macro[1], min_max_output[0], min_max_output[1])
    # sigma_macro[2] = postmnmx2(sigma_macro[2], min_max_output[0], min_max_output[1])
    # sigma_macro[3] = postmnmx2(sigma_macro[3], min_max_output[0], min_max_output[1])
    print(sigma_macro)
    # C_effective = postmnmx(C_effective, min_max_output[0], min_max_output[1])
    C_effective_unscaled = unnormalize_for_hessian(C_effective, min_input,
                                                   max_input,
                                                   min_max_output[0],
                                                   min_max_output[1])
    return energy_aver, P, C_effective_unscaled
def cal_material_parameter2D(F_macro, type):
    # eps_macro = eps_macro[0]
    if type == '1Dlinear':
        filename = 'Mechanics1D_1_NNs.dat'
    elif type == '1Dnonlinear':
        # filename = 'Mechanics1D_Nonlinear_1_NNs.dat'
        filename = 'Mechanics1D_Nonlinear_1d_2com_5N_1000M_1_NNs.dat'
    elif type == '2DLaminate':
        filename = 'Laminate2_4_NNs.dat'
    elif type == 'SaintVenant':
        filename = './machinelearning/training_results/SaintVenant_4d_10com_10N_30000M_4_NNs.dat'
    elif type == 'NeoHookean':
        filename = './machinelearning/training_results/NeoHookean_4d_10com_10N_30000M_4_NNs.dat'
    elif type == 'Inclusion-NeoHookean2':
        filename = './machinelearning/training_results/Inclusion_50x50_NeoHookean2/Inclusion_NeoHookean2_4d_15com_20N_80epoch_30000M_4_NNs.dat'
    dimD, dimd, L, N, activation_func_type, min_input, max_input, min_max_output, \
    A, w, c, b, d, d0 = fp.get_NN_parameters(filename)
    F_macro = tramnnmx(F_macro.reshape(-1), min_input, max_input)
    sigma_macro = np.zeros(size)
    P = np.zeros(size)
    C_effective = np.zeros([size, size])
    energy = 0
    for i in range(0, L):
        y = dot(A[:, :, i], F_macro) + b[:, :, i].reshape(-1)
        for n in range(0, N):
            z = dot(w[n, :, i], y) + d[n, :, i]
            zm = dot(w[n, :, i], y)
            energy += c[n, :, i] * tansig(z)
            sigma_macro += c[n, :, i] * dot(
                w[n, :, i], A[:, :, i]) * derivative_activation(z)
            C_effective += c[n, :, i] * dot(dot(w[n, :, i], A[:, :, i]).reshape(size, 1), dot(w[n, :, i], A[:, :, i]).reshape(1, size)) \
                  * 4 * ((-2 * exp(-2*z) / (1 + exp(-2*z)) ** 2) + (4 * exp(-4*z) / (1 + exp(-2*z)) ** 3))
        energy += d0[:, :, i].reshape(-1)
    # return the real scale data
    energy_aver = postmnmx(energy, min_max_output[0], min_max_output[1])
    P = return_to_rescale_for_stress(sigma_macro, min_input, max_input,
                                     min_max_output[0], min_max_output[1])
    P = P.reshape(dim, dim)
    # print(P)
    C_effective_unscaled = unnormalize_for_hessian(C_effective, min_input,
                                                   max_input,
                                                   min_max_output[0],
                                                   min_max_output[1])
    return P, C_effective_unscaled, energy_aver
Пример #3
0
def cal_material_parameter2D(F_macro, type):
    # eps_macro = eps_macro[0]
    if type == '1Dlinear':
        filename = 'Mechanics1D_1_NNs.dat'
    elif type == '1Dnonlinear':
        filename = 'Mechanics1D_Nonlinear_1_NNs.dat'
    elif type == 'Yvonnet_quadratic_function_2d':
        filename = 'yvonnetFunction3d_1com_3_NNs.dat'
    elif type == 'NeoHooke-Laminate':
        filename = 'Laminate_NeoHookean_4d_15com_20N_80epoch_50000M_4_NNs.dat'
    elif type == 'NeoHookean2-Inclusion':
        filename = 'Inclusion_NeoHookean2_4d_15com_20N_80epoch_30000M_4_NNs.dat'
    dimD, dimd, L, N, activation_func_type, min_input, max_input, min_max_output, \
    A, w, c, b, d, d0 = fp.get_NN_parameters(filename)
    F_macro = tramnnmx(F_macro.reshape(-1), min_input, max_input)
    sigma_macro = np.zeros(Ddim)
    P = np.zeros(Ddim)
    C_effective = np.zeros([Ddim, Ddim])
    energy = 0
    for i in range(0, L):
        y = dot(A[:, :, i], F_macro) + b[:, :, i].reshape(-1)
        for n in range(0, N):
            z = dot(w[n, :, i], y) + d[n, :, i]
            zm = dot(w[n, :, i], y)
            energy += c[n, :, i] * tansig(z)
            sigma_macro += c[n, :, i] * dot(
                w[n, :, i], A[:, :, i]) * derivative_activation(z)
            C_effective += c[n, :, i] * dot(dot(w[n, :, i], A[:, :, i]).reshape(Ddim, 1), dot(w[n, :, i], A[:, :, i]).reshape(1, Ddim)) \
                  * 4 * ((-2 * exp(-2*z) / (1 + exp(-2*z)) ** 2) + (4 * exp(-4*z) / (1 + exp(-2*z)) ** 3))
        energy += d0[:, :, i].reshape(-1)
    # return the real scale data
    energy_aver = postmnmx(energy, min_max_output[0], min_max_output[1])
    P = return_to_rescale_for_stress(sigma_macro, min_input, max_input,
                                     min_max_output[0], min_max_output[1])
    print(sigma_macro)
    C_effective_unscaled = unnormalize_for_hessian(C_effective, min_input,
                                                   max_input,
                                                   min_max_output[0],
                                                   min_max_output[1])
    return energy_aver, P, C_effective_unscaled