|
10 | 10 | from utilities import read_h5, construct_stress_localization |
11 | 11 |
|
12 | 12 | np.random.seed(0) |
13 | | -file_name, data_path, temp1, temp2, n_tests, sampling_alphas = itemgetter('file_name', 'data_path', 'temp1', 'temp2', 'n_tests', |
14 | | - 'sampling_alphas')(microstructures[7]) |
15 | | -print(file_name, '\t', data_path) |
| 13 | +file_name, data_path, temp1, temp2, n_tests, sampling_alphas = itemgetter( |
| 14 | + "file_name", "data_path", "temp1", "temp2", "n_tests", "sampling_alphas" |
| 15 | +)(microstructures[7]) |
| 16 | +print(file_name, "\t", data_path) |
16 | 17 |
|
17 | 18 | test_temperatures = np.linspace(temp1, temp2, num=n_tests) |
18 | 19 | test_alphas = np.linspace(0, 1, num=n_tests) |
19 | 20 |
|
20 | 21 | mesh, ref = read_h5(file_name, data_path, test_temperatures) |
21 | | -mat_id = mesh['mat_id'] |
22 | | -n_gauss = mesh['n_gauss'] |
23 | | -strain_dof = mesh['strain_dof'] |
24 | | -global_gradient = mesh['global_gradient'] |
25 | | -n_gp = mesh['n_integration_points'] |
26 | | -n_modes = ref[0]['strain_localization'].shape[-1] |
| 22 | +mat_id = mesh["mat_id"] |
| 23 | +n_gauss = mesh["n_gauss"] |
| 24 | +strain_dof = mesh["strain_dof"] |
| 25 | +nodal_dof = mesh["nodal_dof"] |
| 26 | +n_elements = mesh["n_elements"] |
| 27 | +global_gradient = mesh["global_gradient"] |
| 28 | +n_gp = mesh["n_integration_points"] |
| 29 | +n_modes = ref[0]["strain_localization"].shape[-1] |
| 30 | +disc = mesh["combo_discretisation"] |
27 | 31 |
|
28 | 32 | # Lowest temperature |
29 | | -temp0 = ref[0]['temperature'] |
30 | | -E0 = ref[0]['strain_localization'] |
31 | | -C0 = ref[0]['mat_stiffness'] |
32 | | -eps0 = ref[0]['mat_thermal_strain'] |
| 33 | +temp0 = ref[0]["temperature"] |
| 34 | +E0 = ref[0]["strain_localization"] |
| 35 | +C0 = ref[0]["mat_stiffness"] |
| 36 | +eps0 = ref[0]["mat_thermal_strain"] |
33 | 37 | S0 = construct_stress_localization(E0, C0, eps0, mat_id, n_gauss, strain_dof) |
34 | 38 |
|
35 | 39 | # First enrichment temperature |
36 | | -alpha = sampling_alphas[1][1] |
37 | | -a = int(alpha * n_tests) |
38 | | -tempa = ref[a]['temperature'] |
39 | | -Ea = ref[a]['strain_localization'] |
40 | | -Ca = ref[a]['mat_stiffness'] |
41 | | -epsa = ref[a]['mat_thermal_strain'] |
| 40 | +a = len(ref) // 2 |
| 41 | +if sampling_alphas is not None: |
| 42 | + alpha = sampling_alphas[1][1] |
| 43 | + a = int(alpha * n_tests) |
| 44 | +tempa = ref[a]["temperature"] |
| 45 | +Ea = ref[a]["strain_localization"] |
| 46 | +Ca = ref[a]["mat_stiffness"] |
| 47 | +epsa = ref[a]["mat_thermal_strain"] |
42 | 48 | Sa = construct_stress_localization(Ea, Ca, epsa, mat_id, n_gauss, strain_dof) |
43 | 49 |
|
44 | 50 | # Highest temperature |
45 | | -temp1 = ref[-1]['temperature'] |
46 | | -E1 = ref[-1]['strain_localization'] |
47 | | -C1 = ref[-1]['mat_stiffness'] |
48 | | -eps1 = ref[-1]['mat_thermal_strain'] |
| 51 | +temp1 = ref[-1]["temperature"] |
| 52 | +E1 = ref[-1]["strain_localization"] |
| 53 | +C1 = ref[-1]["mat_stiffness"] |
| 54 | +eps1 = ref[-1]["mat_thermal_strain"] |
49 | 55 | S1 = construct_stress_localization(E1, C1, eps1, mat_id, n_gauss, strain_dof) |
50 | 56 |
|
51 | 57 | # %% |
52 | 58 |
|
53 | 59 |
|
54 | | -def plot_localization(ax, mesh, E, i=0): |
55 | | - """Plots the euclidean norm of the `i`-th column of |
56 | | - a localization operator `E` on the y-z-cross section at x=0. |
| 60 | +def plot_localization(ax, E, i=0, idx=0): |
| 61 | + """Plots the euclidean norm of the `i`-th row of |
| 62 | + a localization operator `E` on the y-z-cross section at x=idx. |
57 | 63 |
|
58 | 64 | Args: |
59 | 65 | ax: matplotlib axis |
60 | | - mesh: dictionary with mesh informationen |
61 | 66 | E (np.ndarray): localization operator with shape (nx*ny*nz*ngauss, 6, 7) |
62 | | - i (int, optional): column no. of E to be plotted. Defaults to 0. |
| 67 | + i (int, optional): row no. of E to be plotted. Defaults to 0. |
| 68 | + idx (int, optional): y-z-cross section index. Defaults to 0. |
63 | 69 | """ |
64 | | - discr = mesh['combo_discretisation'] |
65 | | - n_gauss = mesh['n_gauss'] |
66 | | - assert E.ndim == 3 |
67 | | - assert E.shape[0] == n_gauss * np.prod(discr) |
68 | | - assert E.shape[1] == 6 |
69 | | - assert E.shape[2] == 7 |
70 | | - E_r = E.reshape(*discr, n_gauss, 6, 7) # reshape |
| 70 | + assert E.ndim == nodal_dof |
| 71 | + assert E.shape[0] == n_gp |
| 72 | + assert E.shape[1] == strain_dof |
| 73 | + # assert E.shape[2] == n_modes |
| 74 | + E_r = E.reshape(*disc, n_gauss, strain_dof, n_modes) |
71 | 75 | E_ra = np.mean(E_r, axis=3) # average over gauss points |
72 | | - E_rai = la.norm(E_ra[:, :, :, i, :], axis=-1) # compute norm of i-th column |
73 | | - ax.imshow(E_rai[0, :, :], interpolation='spline16') # plot y-z-cross section at x=0 |
| 76 | + # compute the effective total strain norm (not the deviatoric part); |
| 77 | + # account for Mandel notation, i.e. activation strain with all components being 1.0 |
| 78 | + E_rai = np.einsum('ijklm,m',E_ra, np.asarray([1, 1, 1, np.sqrt(2), np.sqrt(2), np.sqrt(2),1])) |
| 79 | + effective_strain = np.sqrt(2/3) * la.norm(E_rai,axis=-1) |
| 80 | + # plot y-z-cross section at x=0 |
| 81 | + ax.imshow(effective_strain[idx, :, :], interpolation="spline16") |
74 | 82 |
|
75 | 83 |
|
76 | 84 | # Plot strain localization operator E at different temperatures |
77 | 85 | fig, ax = plt.subplots(1, 3) |
78 | | -plot_localization(ax[0], mesh, E0, i=0) |
79 | | -ax[0].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' + |
80 | | - f'{temp0:.2f}' + r'\mathrm{K}$') |
81 | | -plot_localization(ax[1], mesh, Ea, i=0) |
82 | | -ax[1].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' + |
83 | | - f'{tempa:.2f}' + r'\mathrm{K}$') |
84 | | -#plot_localization(ax[1], mesh, 0.5*(E0+E1), i=0) # compare with naive interpolation |
85 | | -plot_localization(ax[2], mesh, E1, i=0) |
86 | | -ax[2].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' + |
87 | | - f'{temp1:.2f}' + r'\mathrm{K}$') |
88 | | -plt.savefig('output/E.pgf', dpi=300) |
| 86 | +plot_localization(ax[0], E0, i=0) |
| 87 | +ax[0].set_title( |
| 88 | + r"$\underline{\underline{E}}\;\mathrm{at}\;\theta=" |
| 89 | + + f"{temp0:.2f}" |
| 90 | + + r"\mathrm{K}$" |
| 91 | +) |
| 92 | +plot_localization(ax[1], Ea, i=0) |
| 93 | +ax[1].set_title( |
| 94 | + r"$\underline{\underline{E}}\;\mathrm{at}\;\theta=" |
| 95 | + + f"{tempa:.2f}" |
| 96 | + + r"\mathrm{K}$" |
| 97 | +) |
| 98 | +plot_localization(ax[2], E1, i=0) |
| 99 | +ax[2].set_title( |
| 100 | + r"$\underline{\underline{E}}\;\mathrm{at}\;\theta=" |
| 101 | + + f"{temp1:.2f}" |
| 102 | + + r"\mathrm{K}$" |
| 103 | +) |
| 104 | +plt.savefig("output/E.png", dpi=300) |
89 | 105 | plt.show() |
90 | 106 |
|
91 | | -# Plot strain localization operator S at different temperatures |
| 107 | +# Plot stress localization operator S at different temperatures |
92 | 108 | fig, ax = plt.subplots(1, 3) |
93 | | -plot_localization(ax[0], mesh, S0, i=0) |
94 | | -ax[0].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' + |
95 | | - f'{temp0:.2f}' + r'\mathrm{K}$') |
96 | | -plot_localization(ax[1], mesh, Sa, i=0) |
97 | | -ax[1].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' + |
98 | | - f'{tempa:.2f}' + r'\mathrm{K}$') |
99 | | -#plot_localization(ax[2], mesh, 0.5*(S0+S1), i=0) # compare with naive interpolation |
100 | | -plot_localization(ax[2], mesh, S1, i=0) |
101 | | -ax[2].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' + |
102 | | - f'{temp1:.2f}' + r'\mathrm{K}$') |
103 | | -plt.savefig('output/S.pgf', dpi=300) |
| 109 | +plot_localization(ax[0], S0, i=0) |
| 110 | +ax[0].set_title( |
| 111 | + r"$\underline{\underline{S}}\;\mathrm{at}\;\theta=" |
| 112 | + + f"{temp0:.2f}" |
| 113 | + + r"\mathrm{K}$" |
| 114 | +) |
| 115 | +plot_localization(ax[1], Sa, i=0) |
| 116 | +ax[1].set_title( |
| 117 | + r"$\underline{\underline{S}}\;\mathrm{at}\;\theta=" |
| 118 | + + f"{tempa:.2f}" |
| 119 | + + r"\mathrm{K}$" |
| 120 | +) |
| 121 | +plot_localization(ax[2], S1, i=0) |
| 122 | +ax[2].set_title( |
| 123 | + r"$\underline{\underline{S}}\;\mathrm{at}\;\theta=" |
| 124 | + + f"{temp1:.2f}" |
| 125 | + + r"\mathrm{K}$" |
| 126 | +) |
| 127 | +plt.savefig("output/S.png", dpi=300) |
104 | 128 | plt.show() |
0 commit comments