4
4
"""
5
5
import numpy as np
6
6
import h5py
7
- from utilities import *
8
- from material_parameters import *
7
+ import re
8
+ from operator import itemgetter
9
+ from utilities import read_h5 , construct_stress_localization , construct_stress_localization_phases , \
10
+ volume_average , volume_average_phases , norm_2
11
+ from material_parameters import stiffness_cu , stiffness_wsc , thermal_strain_cu , thermal_strain_wsc
12
+ from interpolate_fluctuation_modes import interpolate_fluctuation_modes
13
+ from optimize_alpha import opt4
14
+ from microstructures import microstructures
9
15
from tqdm import tqdm
10
16
11
17
@@ -16,7 +22,7 @@ def read_snapshots(file_name, data_path):
16
22
:param file_name: e.g. "input/simple_3d_rve_combo.h5"
17
23
:param data_path: the path to the simulation results within the h5 file, e.g. '/ms_1p/dset0_sim'
18
24
:return:
19
- strain_snapshots: plastic strain snapshots eps_p
25
+ strain_snapshots: plastic strain snapshots eps_p
20
26
with shape (n_integration_points, strain_dof, n_frames)
21
27
"""
22
28
plastic_snapshots = None
@@ -76,8 +82,8 @@ def compute_ntfa_matrices(strain_localization, stress_localization, plastic_mode
76
82
n_modes = plastic_modes .shape [2 ]
77
83
n_gp = mesh ['n_integration_points' ]
78
84
n_gauss = mesh ['n_gauss' ]
79
- I = np .eye (6 )
80
-
85
+ I2 = np .eye (6 )
86
+
81
87
# slice strain localization operator E into E_eps, E_theta, E_xi
82
88
E_eps = strain_localization [:, :, :strain_dof ]
83
89
E_theta = strain_localization [:, :, strain_dof ]
@@ -89,18 +95,18 @@ def compute_ntfa_matrices(strain_localization, stress_localization, plastic_mode
89
95
S_xi = stress_localization [:, :, strain_dof + 1 :]
90
96
91
97
# Compute C_bar via < (E_eps + I).T @ S_eps >
92
- C_bar = volume_average ((E_eps + I ).transpose ((0 , 2 , 1 )) @ S_eps )
98
+ C_bar = volume_average ((E_eps + I2 ).transpose ((0 , 2 , 1 )) @ S_eps )
93
99
94
100
# Compute tau_theta via < (E_eps + I).T @ S_theta >
95
- tau_theta = volume_average (np .einsum ('nij,nj->ni' , (E_eps + I ).transpose ((0 , 2 , 1 )), S_theta ))
101
+ tau_theta = volume_average (np .einsum ('nij,nj->ni' , (E_eps + I2 ).transpose ((0 , 2 , 1 )), S_theta ))
96
102
97
103
# Compute A_bar via < (E_eps + I).T @ S_eps >
98
- A_bar = volume_average ((E_eps + I ).transpose ((0 , 2 , 1 )) @ S_xi )
104
+ A_bar = volume_average ((E_eps + I2 ).transpose ((0 , 2 , 1 )) @ S_xi )
99
105
100
106
# Compute tau_xi via < (E_theta - P_theta).T @ S_xi >
101
107
# Account for the phase-wise thermal strain by an explicit summation over all integration points
102
108
tau_xi = np .zeros ((1 , n_modes ))
103
- for gp_id in prange (n_gp ):
109
+ for gp_id in range (n_gp ):
104
110
phase_id = mat_id [gp_id // n_gauss ]
105
111
tau_xi += (np .expand_dims (E_theta [gp_id ], axis = 1 ) - mat_thermal_strain [phase_id ]).T @ S_xi [gp_id ] / n_gp
106
112
@@ -110,7 +116,7 @@ def compute_ntfa_matrices(strain_localization, stress_localization, plastic_mode
110
116
# Compute D_theta via < (E_theta - P_theta).T @ S_theta >
111
117
# Account for the phase-wise thermal strain by an explicit summation over all integration points
112
118
D_theta = 0.
113
- for gp_id in prange (n_gp ):
119
+ for gp_id in range (n_gp ):
114
120
phase_id = mat_id [gp_id // n_gauss ]
115
121
D_theta += (np .expand_dims (E_theta [gp_id ], axis = 1 ) - mat_thermal_strain [phase_id ]).T @ S_theta [gp_id ] / n_gp
116
122
@@ -163,7 +169,8 @@ def compute_phase_average_stress_localizations(strain_localization, mat_stiffnes
163
169
combo_strain_loc0 , combo_strain_loc1 = None , None
164
170
stress_localization0 , stress_localization1 , _ , _ = construct_stress_localization_phases (
165
171
strain_localization , mat_stiffness , mat_thermal_strain , plastic_modes , combo_strain_loc0 , combo_strain_loc1 , mesh )
166
- average_stress_localization0 , average_stress_localization1 = volume_average (stress_localization0 ), volume_average (stress_localization1 )
172
+ average_stress_localization0 , average_stress_localization1 = \
173
+ volume_average (stress_localization0 ), volume_average (stress_localization1 )
167
174
return average_stress_localization0 , average_stress_localization1
168
175
169
176
@@ -174,15 +181,13 @@ def compute_tabular_data_for_ms(ms_id, temperatures):
174
181
:param ms_id: id of the microstructure
175
182
:param temperatures: list of sampling temperatures
176
183
"""
177
- file_name , data_path , temp1 , temp2 , n_tests , sampling_alphas = itemgetter ( 'file_name' , 'data_path' , 'temp1' , 'temp2' , 'n_tests' ,
178
- 'sampling_alphas' )(microstructures [ms_id ])
184
+ file_name , data_path , temp1 , temp2 , n_tests , sampling_alphas = \
185
+ itemgetter ( 'file_name' , 'data_path' , 'temp1' , 'temp2' , 'n_tests' , 'sampling_alphas' )(microstructures [ms_id ])
179
186
sample_temperatures = np .linspace (temp1 , temp2 , num = n_tests )
180
- sample_alphas = np .linspace (0 , 1 , num = n_tests )
181
187
mesh , samples = read_h5 (file_name , data_path , sample_temperatures )
182
188
return compute_tabular_data (samples , mesh , temperatures )
183
189
184
190
185
- #@jit(nopython=True, cache=True, parallel=True, nogil=True)
186
191
def compute_tabular_data (samples , mesh , temperatures ):
187
192
"""
188
193
Compute tabular data for a given list of temperatures
@@ -235,17 +240,19 @@ def compute_tabular_data(samples, mesh, temperatures):
235
240
E01 = np .ascontiguousarray (np .concatenate ((E0 , E1 ), axis = - 1 ))
236
241
237
242
sampling_C = np .stack ((samples [id0 ]['mat_stiffness' ], samples [id1 ]['mat_stiffness' ])).transpose ([1 , 0 , 2 , 3 ])
238
- sampling_eps = np .stack ((samples [id0 ]['mat_thermal_strain' ], samples [id1 ]['mat_thermal_strain' ])).transpose ([1 , 0 , 2 , 3 ])
243
+ sampling_eps = np .stack ((samples [id0 ]['mat_thermal_strain' ],
244
+ samples [id1 ]['mat_thermal_strain' ])).transpose ([1 , 0 , 2 , 3 ])
239
245
240
246
# interpolated quantities using an implicit interpolation scheme with four DOF
241
247
approx_C , approx_eps = opt4 (sampling_C , sampling_eps , ref_C , ref_eps )
242
- E , _ = interpolate_fluctuation_modes (E01 , approx_C , approx_eps , plastic_modes , mat_id , n_gauss , strain_dof , n_modes , n_gp )
248
+ E , _ = interpolate_fluctuation_modes (E01 , approx_C , approx_eps , plastic_modes , mat_id ,
249
+ n_gauss , strain_dof , n_modes , n_gp )
243
250
S = construct_stress_localization (E , ref_C , ref_eps , plastic_modes , mat_id , n_gauss , strain_dof )
244
251
245
252
# Compute NTFA matrices
246
253
C_bar [:, :, idx ], tau_theta [:, idx ], A_bar [:, :, idx ], tau_xi [:, idx ], D_xi [:, :, idx ], D_theta [idx ] = \
247
254
compute_ntfa_matrices (E , S , plastic_modes , ref_eps , mesh )
248
-
255
+
249
256
# Compute phase average stresses
250
257
A0_full , A1_full = compute_phase_average_stress_localizations (E , ref_C , ref_eps , plastic_modes , mesh )
251
258
A0 [:, :, idx ], A1 [:, :, idx ] = A0_full , A1_full
@@ -282,17 +289,17 @@ def save_tabular_data(file_name, data_path, temperatures, C_bar, tau_theta, A_ba
282
289
del file [ntfa_path ]
283
290
dset_ntfa = dset .create_group (ntfa_path )
284
291
[dset_ntfa .attrs .create (key , value ) for key , value in dset_sim .attrs .items ()]
285
- dset_temperatures = dset_ntfa .create_dataset ('temperatures' , data = temperatures )
286
- dset_C_bar = dset_ntfa .create_dataset ('C_bar' , data = C_bar )
287
- dset_tau_theta = dset_ntfa .create_dataset ('tau_theta' , data = tau_theta )
288
- dset_A_bar = dset_ntfa .create_dataset ('A_bar' , data = A_bar )
289
- dset_tau_xi = dset_ntfa .create_dataset ('tau_xi' , data = tau_xi )
290
- dset_D_xi = dset_ntfa .create_dataset ('D_xi' , data = D_xi )
291
- dset_D_theta = dset_ntfa .create_dataset ('D_theta' , data = D_theta )
292
- dset_A0 = dset_ntfa .create_dataset ('A0' , data = A0 )
293
- dset_A1 = dset_ntfa .create_dataset ('A1' , data = A1 )
294
- dset_C0 = dset_ntfa .create_dataset ('C0' , data = C0 )
295
- dset_C1 = dset_ntfa .create_dataset ('C1' , data = C1 )
292
+ dset_ntfa .create_dataset ('temperatures' , data = temperatures )
293
+ dset_ntfa .create_dataset ('C_bar' , data = C_bar )
294
+ dset_ntfa .create_dataset ('tau_theta' , data = tau_theta )
295
+ dset_ntfa .create_dataset ('A_bar' , data = A_bar )
296
+ dset_ntfa .create_dataset ('tau_xi' , data = tau_xi )
297
+ dset_ntfa .create_dataset ('D_xi' , data = D_xi )
298
+ dset_ntfa .create_dataset ('D_theta' , data = D_theta )
299
+ dset_ntfa .create_dataset ('A0' , data = A0 )
300
+ dset_ntfa .create_dataset ('A1' , data = A1 )
301
+ dset_ntfa .create_dataset ('C0' , data = C0 )
302
+ dset_ntfa .create_dataset ('C1' , data = C1 )
296
303
297
304
298
305
def read_tabular_data (file_name , data_path ):
0 commit comments