1+ """
2+ Plot the strain localization operator E and stress localization operator S at different temperatures
3+ """
14#%%
25from operator import itemgetter
36
47import numpy .linalg as la
58import matplotlib .pyplot as plt
6- from interpolate_fluctuation_modes import interpolate_fluctuation_modes
79from 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
1112np .random .seed (0 )
1213file_name , data_path , temp1 , temp2 , n_tests , sampling_alphas = itemgetter ('file_name' , 'data_path' , 'temp1' , 'temp2' , 'n_tests' ,
2425n_gp = mesh ['n_integration_points' ]
2526n_modes = ref [0 ]['strain_localization' ].shape [- 1 ]
2627
28+ # Lowest temperature
2729temp0 = ref [0 ]['temperature' ]
2830E0 = ref [0 ]['strain_localization' ]
2931C0 = ref [0 ]['mat_stiffness' ]
3032eps0 = ref [0 ]['mat_thermal_strain' ]
3133S0 = construct_stress_localization (E0 , C0 , eps0 , mat_id , n_gauss , strain_dof )
3234
35+ # First enrichment temperature
3336alpha = sampling_alphas [1 ][1 ]
3437a = int (alpha * n_tests )
3538tempa = ref [a ]['temperature' ]
3841epsa = ref [a ]['mat_thermal_strain' ]
3942Sa = construct_stress_localization (Ea , Ca , epsa , mat_id , n_gauss , strain_dof )
4043
44+ # Highest temperature
4145temp1 = ref [- 1 ]['temperature' ]
4246E1 = ref [- 1 ]['strain_localization' ]
4347C1 = ref [- 1 ]['mat_stiffness' ]
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
6377fig , ax = plt .subplots (1 , 3 )
6478plot_localization (ax [0 ], mesh , E0 , i = 0 )
6579ax [0 ].set_title (r'$\underline{\underline{E}}\;\mathrm{at}\;\theta=' +
@@ -71,9 +85,10 @@ def plot_localization(ax, mesh, E, i=0, j=0):
7185plot_localization (ax [2 ], mesh , E1 , i = 0 )
7286ax [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 )
7589plt .show ()
7690
91+ # Plot strain localization operator S at different temperatures
7792fig , ax = plt .subplots (1 , 3 )
7893plot_localization (ax [0 ], mesh , S0 , i = 0 )
7994ax [0 ].set_title (r'$\underline{\underline{S}}\;\mathrm{at}\;\theta=' +
@@ -85,5 +100,5 @@ def plot_localization(ax, mesh, E, i=0, j=0):
85100plot_localization (ax [2 ], mesh , S1 , i = 0 )
86101ax [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 )
89104plt .show ()
0 commit comments