|
| 1 | +#%% |
| 2 | +from operator import itemgetter |
| 3 | + |
| 4 | +import numpy.linalg as la |
| 5 | +import matplotlib.pyplot as plt |
| 6 | +from interpolate_fluctuation_modes import interpolate_fluctuation_modes |
| 7 | +from microstructures import * |
| 8 | +from optimize_alpha import opt1, opt2, opt4, naive |
| 9 | +from utilities import read_h5, construct_stress_localization, volume_average, compute_residual_efficient |
| 10 | + |
| 11 | +np.random.seed(0) |
| 12 | +file_name, data_path, temp1, temp2, n_tests, sampling_alphas = itemgetter('file_name', 'data_path', 'temp1', 'temp2', 'n_tests', |
| 13 | + 'sampling_alphas')(microstructures[7]) |
| 14 | +print(file_name, '\t', data_path) |
| 15 | + |
| 16 | +test_temperatures = np.linspace(temp1, temp2, num=n_tests) |
| 17 | +test_alphas = np.linspace(0, 1, num=n_tests) |
| 18 | + |
| 19 | +mesh, ref = read_h5(file_name, data_path, test_temperatures) |
| 20 | +mat_id = mesh['mat_id'] |
| 21 | +n_gauss = mesh['n_gauss'] |
| 22 | +strain_dof = mesh['strain_dof'] |
| 23 | +global_gradient = mesh['global_gradient'] |
| 24 | +n_gp = mesh['n_integration_points'] |
| 25 | +n_modes = ref[0]['strain_localization'].shape[-1] |
| 26 | + |
| 27 | +temp0 = ref[0]['temperature'] |
| 28 | +E0 = ref[0]['strain_localization'] |
| 29 | +C0 = ref[0]['mat_stiffness'] |
| 30 | +eps0 = ref[0]['mat_thermal_strain'] |
| 31 | +S0 = construct_stress_localization(E0, C0, eps0, mat_id, n_gauss, strain_dof) |
| 32 | + |
| 33 | +alpha = sampling_alphas[1][1] |
| 34 | +a = int(alpha * n_tests) |
| 35 | +tempa = ref[a]['temperature'] |
| 36 | +Ea = ref[a]['strain_localization'] |
| 37 | +Ca = ref[a]['mat_stiffness'] |
| 38 | +epsa = ref[a]['mat_thermal_strain'] |
| 39 | +Sa = construct_stress_localization(Ea, Ca, epsa, mat_id, n_gauss, strain_dof) |
| 40 | + |
| 41 | +temp1 = ref[-1]['temperature'] |
| 42 | +E1 = ref[-1]['strain_localization'] |
| 43 | +C1 = ref[-1]['mat_stiffness'] |
| 44 | +eps1 = ref[-1]['mat_thermal_strain'] |
| 45 | +S1 = construct_stress_localization(E1, C1, eps1, mat_id, n_gauss, strain_dof) |
| 46 | + |
| 47 | +# %% |
| 48 | + |
| 49 | + |
| 50 | +def plot_localization(ax, mesh, E, i=0, j=0): |
| 51 | + discr = mesh['combo_discretisation'] |
| 52 | + n_gauss = mesh['n_gauss'] |
| 53 | + assert E.ndim == 3 |
| 54 | + assert E.shape[0] == n_gauss * np.prod(discr) |
| 55 | + assert E.shape[1] == 6 |
| 56 | + assert E.shape[2] == 7 |
| 57 | + E_r = E.reshape(*discr, n_gauss, 6, 7) # resize |
| 58 | + E_ra = np.mean(E_r, axis=3) # average over gauss points |
| 59 | + E_rai = np.linalg.norm(E_ra[:, :, :, i, :], axis=-1) # compute norm of i-th row |
| 60 | + ax.imshow(E_rai[0, :, :], interpolation='spline16') # plot y-z-cross section at x=0 |
| 61 | + |
| 62 | + |
| 63 | +fig, ax = plt.subplots(1, 3) |
| 64 | +plot_localization(ax[0], mesh, E0, i=0) |
| 65 | +ax[0].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' + |
| 66 | + f'{temp0:.2f}' + r'\mathrm{K}$') |
| 67 | +plot_localization(ax[1], mesh, Ea, i=0) |
| 68 | +ax[1].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' + |
| 69 | + f'{tempa:.2f}' + r'\mathrm{K}$') |
| 70 | +#plot_localization(ax[1], mesh, 0.5*(E0+E1), i=0) # compare with naive interpolation |
| 71 | +plot_localization(ax[2], mesh, E1, i=0) |
| 72 | +ax[2].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' + |
| 73 | + f'{temp1:.2f}' + r'\mathrm{K}$') |
| 74 | +plt.savefig('E.pgf', dpi=300) |
| 75 | +plt.show() |
| 76 | + |
| 77 | +fig, ax = plt.subplots(1, 3) |
| 78 | +plot_localization(ax[0], mesh, S0, i=0) |
| 79 | +ax[0].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' + |
| 80 | + f'{temp0:.2f}' + r'\mathrm{K}$') |
| 81 | +plot_localization(ax[1], mesh, Sa, i=0) |
| 82 | +ax[1].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' + |
| 83 | + f'{tempa:.2f}' + r'\mathrm{K}$') |
| 84 | +#plot_localization(ax[2], mesh, 0.5*(S0+S1), i=0) # compare with naive interpolation |
| 85 | +plot_localization(ax[2], mesh, S1, i=0) |
| 86 | +ax[2].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' + |
| 87 | + f'{temp1:.2f}' + r'\mathrm{K}$') |
| 88 | +plt.savefig('S.pgf', dpi=300) |
| 89 | +plt.show() |
0 commit comments