Skip to content

Commit 570ce73

Browse files
Julius Herbshadisharba
authored andcommitted
Documentation
1 parent 621f4e4 commit 570ce73

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

eg8_plot_localization.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
"""
2+
Plot the strain localization operator E and stress localization operator S at different temperatures
3+
"""
14
#%%
25
from operator import itemgetter
36

47
import numpy.linalg as la
58
import matplotlib.pyplot as plt
6-
from interpolate_fluctuation_modes import interpolate_fluctuation_modes
79
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+
from utilities import read_h5, construct_stress_localization
1011

1112
np.random.seed(0)
1213
file_name, data_path, temp1, temp2, n_tests, sampling_alphas = itemgetter('file_name', 'data_path', 'temp1', 'temp2', 'n_tests',
@@ -24,12 +25,14 @@
2425
n_gp = mesh['n_integration_points']
2526
n_modes = ref[0]['strain_localization'].shape[-1]
2627

28+
# Lowest temperature
2729
temp0 = ref[0]['temperature']
2830
E0 = ref[0]['strain_localization']
2931
C0 = ref[0]['mat_stiffness']
3032
eps0 = ref[0]['mat_thermal_strain']
3133
S0 = construct_stress_localization(E0, C0, eps0, mat_id, n_gauss, strain_dof)
3234

35+
# First enrichment temperature
3336
alpha = sampling_alphas[1][1]
3437
a = int(alpha * n_tests)
3538
tempa = ref[a]['temperature']
@@ -38,6 +41,7 @@
3841
epsa = ref[a]['mat_thermal_strain']
3942
Sa = construct_stress_localization(Ea, Ca, epsa, mat_id, n_gauss, strain_dof)
4043

44+
# Highest temperature
4145
temp1 = ref[-1]['temperature']
4246
E1 = ref[-1]['strain_localization']
4347
C1 = ref[-1]['mat_stiffness']
@@ -47,19 +51,29 @@
4751
# %%
4852

4953

50-
def plot_localization(ax, mesh, E, i=0, j=0):
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.
57+
58+
Args:
59+
ax: matplotlib axis
60+
mesh: dictionary with mesh informationen
61+
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.
63+
"""
5164
discr = mesh['combo_discretisation']
5265
n_gauss = mesh['n_gauss']
5366
assert E.ndim == 3
5467
assert E.shape[0] == n_gauss * np.prod(discr)
5568
assert E.shape[1] == 6
5669
assert E.shape[2] == 7
57-
E_r = E.reshape(*discr, n_gauss, 6, 7) # resize
70+
E_r = E.reshape(*discr, n_gauss, 6, 7) # reshape
5871
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
72+
E_rai = la.norm(E_ra[:, :, :, i, :], axis=-1) # compute norm of i-th column
6073
ax.imshow(E_rai[0, :, :], interpolation='spline16') # plot y-z-cross section at x=0
6174

6275

76+
# Plot strain localization operator E at different temperatures
6377
fig, ax = plt.subplots(1, 3)
6478
plot_localization(ax[0], mesh, E0, i=0)
6579
ax[0].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' +
@@ -71,9 +85,10 @@ def plot_localization(ax, mesh, E, i=0, j=0):
7185
plot_localization(ax[2], mesh, E1, i=0)
7286
ax[2].set_title(r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' +
7387
f'{temp1:.2f}' + r'\mathrm{K}$')
74-
plt.savefig('E.pgf', dpi=300)
88+
plt.savefig('output/E.pgf', dpi=300)
7589
plt.show()
7690

91+
# Plot strain localization operator S at different temperatures
7792
fig, ax = plt.subplots(1, 3)
7893
plot_localization(ax[0], mesh, S0, i=0)
7994
ax[0].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' +
@@ -85,5 +100,5 @@ def plot_localization(ax, mesh, E, i=0, j=0):
85100
plot_localization(ax[2], mesh, S1, i=0)
86101
ax[2].set_title(r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' +
87102
f'{temp1:.2f}' + r'\mathrm{K}$')
88-
plt.savefig('S.pgf', dpi=300)
103+
plt.savefig('output/S.pgf', dpi=300)
89104
plt.show()

0 commit comments

Comments
 (0)