Skip to content

Commit cd5ba9a

Browse files
juliusghshadisharba
authored andcommitted
Revert "add initial support for plastic models"
This reverts commit 2aa7c46.
1 parent 12a4d5c commit cd5ba9a

6 files changed

+60
-104
lines changed

Diff for: eg2_compare_approximations.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
_, samples = read_h5(file_name, data_path, [temp1, temp2], get_mesh=False)
3232

33-
strains = np.random.normal(size=(n_loading_directions, strain_dof))
33+
strains = np.random.normal(size=(n_loading_directions, mesh['strain_dof']))
3434
strains /= la.norm(strains, axis=1)[:, None]
3535

3636
n_approaches = 5
@@ -54,43 +54,38 @@
5454
Eref = ref[idx]['strain_localization']
5555
ref_C = ref[idx]['mat_stiffness']
5656
ref_eps = ref[idx]['mat_thermal_strain']
57-
plastic_modes = ref[idx]['plastic_modes']
5857
normalization_factor_mech = ref[idx]['normalization_factor_mech']
5958

60-
Sref = construct_stress_localization(Eref, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
59+
Sref = construct_stress_localization(Eref, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
6160
effSref = volume_average(Sref)
6261

6362
# interpolated quantities using an explicit interpolation scheme with one DOF
6463
approx_C, approx_eps = naive(alpha, sampling_C, sampling_eps, ref_C, ref_eps)
6564
Enaive = interpolate_temp(E0, E1)
66-
Snaive = construct_stress_localization(Enaive, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
65+
Snaive = construct_stress_localization(Enaive, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
6766
effSnaive = volume_average(Snaive)
6867

6968
# interpolated quantities using an explicit interpolation scheme with one DOF
70-
Eopt0, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, plastic_modes, mat_id, n_gauss, strain_dof, n_modes,
71-
n_gp)
72-
Sopt0 = construct_stress_localization(Eopt0, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
69+
Eopt0, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, mat_id, n_gauss, strain_dof, n_modes, n_gp)
70+
Sopt0 = construct_stress_localization(Eopt0, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
7371
effSopt0 = volume_average(Sopt0)
7472

7573
# interpolated quantities using an implicit interpolation scheme with one DOF
7674
approx_C, approx_eps = opt1(sampling_C, sampling_eps, ref_C, ref_eps)
77-
Eopt1, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, plastic_modes, mat_id, n_gauss, strain_dof, n_modes,
78-
n_gp)
79-
Sopt1 = construct_stress_localization(Eopt1, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
75+
Eopt1, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, mat_id, n_gauss, strain_dof, n_modes, n_gp)
76+
Sopt1 = construct_stress_localization(Eopt1, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
8077
effSopt1 = volume_average(Sopt1)
8178

8279
# interpolated quantities using an implicit interpolation scheme with two DOF
8380
approx_C, approx_eps = opt2(sampling_C, sampling_eps, ref_C, ref_eps)
84-
Eopt2, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, plastic_modes, mat_id, n_gauss, strain_dof, n_modes,
85-
n_gp)
86-
Sopt2 = construct_stress_localization(Eopt2, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
81+
Eopt2, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, mat_id, n_gauss, strain_dof, n_modes, n_gp)
82+
Sopt2 = construct_stress_localization(Eopt2, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
8783
effSopt2 = volume_average(Sopt2)
8884

8985
# interpolated quantities using an implicit interpolation scheme with four DOF
9086
approx_C, approx_eps = opt4(sampling_C, sampling_eps, ref_C, ref_eps)
91-
Eopt4, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, plastic_modes, mat_id, n_gauss, strain_dof, n_modes,
92-
n_gp)
93-
Sopt4 = construct_stress_localization(Eopt4, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
87+
Eopt4, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, mat_id, n_gauss, strain_dof, n_modes, n_gp)
88+
Sopt4 = construct_stress_localization(Eopt4, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
9489
effSopt4 = volume_average(Sopt4)
9590

9691
err = lambda x, y: np.mean(la.norm(x - y, axis=(-1, -2)) / la.norm(y, axis=(-1, -2))) * 100
@@ -102,7 +97,7 @@
10297
err(effSopt2, effSref), err(effSopt4, effSref)]
10398

10499
for strain_idx, strain in enumerate(strains):
105-
zeta = np.hstack((strain, 1, np.ones(plastic_modes.shape[-1])))
100+
zeta = np.hstack((strain, 1))
106101

107102
eff_stress_ref = effSref @ zeta
108103
err_eff_stress[:, idx * n_loading_directions + strain_idx] = \
@@ -117,7 +112,7 @@
117112
stress_opt4 = np.einsum('ijk,k', Sopt4, zeta, optimize='optimal')
118113

119114
residuals = compute_residual_efficient([stress_naive, stress_opt0, stress_opt1, stress_opt2, stress_opt4],
120-
global_gradient)
115+
mesh['global_gradient'])
121116

122117
err_f[:, idx * n_loading_directions + strain_idx] = la.norm(residuals, np.inf, axis=0) / normalization_factor_mech * 100
123118

Diff for: eg3_hierarchical_sampling.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,22 @@
6060
sampling_eps = np.stack((samples[id0]['mat_thermal_strain'], samples[id1]['mat_thermal_strain'])).transpose([1, 0, 2, 3])
6161

6262
# reference values
63-
Eref = ref[idx]['strain_localization']
6463
ref_C = ref[idx]['mat_stiffness']
6564
ref_eps = ref[idx]['mat_thermal_strain']
66-
plastic_modes = ref[idx]['plastic_modes']
6765
normalization_factor_mech = ref[idx]['normalization_factor_mech']
68-
Sref = construct_stress_localization(Eref, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
69-
effSref = volume_average(Sref)
70-
# effSref = np.vstack((ref[idx]['eff_stiffness'], -ref[idx]['eff_stiffness'] @ ref[idx]['eff_thermal_strain'])).T
66+
effSref = np.vstack((ref[idx]['eff_stiffness'], -ref[idx]['eff_stiffness'] @ ref[idx]['eff_thermal_strain'])).T
7167

7268
# interpolated quantities using an implicit interpolation scheme with four DOF
7369
approx_C, approx_eps = opt4(sampling_C, sampling_eps, ref_C, ref_eps)
74-
Eopt4, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, plastic_modes, mat_id, n_gauss, strain_dof, n_modes,
75-
n_gp)
76-
Sopt4 = construct_stress_localization(Eopt4, ref_C, ref_eps, plastic_modes, mat_id, n_gauss, strain_dof)
70+
Eopt4, _ = interpolate_fluctuation_modes(E01, approx_C, approx_eps, mat_id, n_gauss, strain_dof, n_modes, n_gp)
71+
Sopt4 = construct_stress_localization(Eopt4, ref_C, ref_eps, mat_id, n_gauss, strain_dof)
7772
effSopt = volume_average(Sopt4)
7873

7974
err_indicators[level, idx] = np.mean(np.max(np.abs(compute_err_indicator_efficient(Sopt4, global_gradient)),
8075
axis=0)) / normalization_factor_mech * 100
8176

8277
for strain_idx, strain in enumerate(strains):
83-
zeta = np.hstack((strain, 1, np.ones(plastic_modes.shape[-1])))
78+
zeta = np.hstack((strain, 1))
8479
stress_opt4 = np.einsum('ijk,k', Sopt4, zeta, optimize='optimal')
8580
residual = compute_residual_efficient(stress_opt4, global_gradient)
8681

@@ -94,11 +89,11 @@
9489
invL = la.inv(la.cholesky(Cref))
9590
err_eff_C[level, idx] = la.norm(invL @ Capprox @ invL.T - np.eye(6)) / la.norm(np.eye(6)) * 100
9691

97-
err_eff_eps[level, idx] = err(la.solve(Capprox, effSopt[:, 7]), la.solve(Cref, effSref[:, 7]))
92+
err_eff_eps[level, idx] = err(la.solve(Capprox, effSopt[:, -1]), la.solve(Cref, effSref[:, -1]))
9893

9994
# max_err_idx = np.argmax(np.mean(err_nodal_force[level], axis=1))
10095
max_err_idx = np.argmax(err_indicators[level])
101-
alpha_levels.append(np.unique(np.sort(np.hstack((alphas, test_alphas[max_err_idx])))))
96+
alpha_levels.append(np.sort(np.hstack((alphas, test_alphas[max_err_idx]))))
10297
print(f'{np.max(np.mean(err_nodal_force[level], axis=1)) = }')
10398
print(f'{np.max(err_indicators[level]) = }')
10499

Diff for: eg4_hierarchical_sampling_efficient.py

+10-22
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from interpolate_fluctuation_modes import update_affine_decomposition, effective_S, effective_stress_localization, \
77
interpolate_fluctuation_modes, get_phi, transform_strain_localization
88
from microstructures import *
9-
from optimize_alpha import opt4_alphas, opt4
10-
from utilities import read_h5, construct_stress_localization, compute_err_indicator_efficient, volume_average
9+
from optimize_alpha import opt4_alphas
10+
from utilities import read_h5, construct_stress_localization, compute_err_indicator_efficient
1111

1212
np.random.seed(0)
1313
# np.set_printoptions(precision=3)
@@ -40,20 +40,16 @@
4040

4141
# extract temperature dependent data from the reference solutions
4242
# such as: material stiffness and thermal strain at each temperature and for all phases
43-
Erefs = np.zeros((n_tests, *refs[0]['strain_localization'].shape)) # n_tests x n_phases x 6 x 6
4443
ref_Cs = np.zeros((n_tests, *refs[0]['mat_stiffness'].shape)) # n_tests x n_phases x 6 x 6
4544
ref_epss = np.zeros((n_tests, *refs[0]['mat_thermal_strain'].shape)) # n_tests x n_phases x 6 x 1
4645
effSref = np.zeros((n_tests, strain_dof, n_modes))
4746
normalization_factor_mech = np.zeros((n_tests))
48-
plastic_modes = refs[0]['plastic_modes'] # temperature independent
4947
for idx, alpha in enumerate(test_alphas):
50-
Erefs[idx] = refs[idx]['strain_localization']
5148
ref_Cs[idx] = refs[idx]['mat_stiffness']
5249
ref_epss[idx] = refs[idx]['mat_thermal_strain']
5350
normalization_factor_mech[idx] = refs[idx]['normalization_factor_mech']
54-
Sref = construct_stress_localization(Erefs[idx], ref_Cs[idx], ref_epss[idx], plastic_modes, mat_id, n_gauss,
55-
strain_dof)
56-
effSref[idx] = volume_average(Sref)
51+
effSref[idx] = np.hstack(
52+
(refs[idx]['eff_stiffness'], -np.reshape(refs[idx]['eff_stiffness'] @ refs[idx]['eff_thermal_strain'], (-1, 1))))
5753

5854
err_indicators, err_eff_S, err_eff_C, err_eff_eps = [np.zeros((n_hierarchical_levels, n_tests)) for _ in range(4)]
5955
interpolate_temp = lambda x1, x2, alpha: x1 + alpha * (x2 - x1)
@@ -109,26 +105,20 @@
109105
current_sampling_id = alphas_indexing[idx]
110106

111107
K0, K1, F0, F1, F2, F3, S001, S101, S103, S002, S102, S104 = update_affine_decomposition(
112-
E01s[current_sampling_id], sampling_C, sampling_eps, plastic_modes, n_modes, n_phases,
113-
n_gp, strain_dof,
114-
mat_id, n_gauss)
108+
E01s[current_sampling_id], sampling_C, sampling_eps, n_modes, n_phases, n_gp, strain_dof, mat_id, n_gauss)
115109

116110
phi = get_phi(K0, K1, F0, F1, F2, F3, alpha_C, alpha_eps, alpha_C_eps)
117111

118112
speed = 1
119113
if speed == 0:
120114
C, eps = ref_Cs[idx], ref_epss[idx]
121115
# C, eps = opt4(sampling_C, sampling_eps, ref_Cs[idx], ref_epss[idx])
122-
_, effSopt = interpolate_fluctuation_modes(E01s[current_sampling_id], C, eps, plastic_modes, mat_id, n_gauss,
123-
strain_dof,
116+
_, effSopt = interpolate_fluctuation_modes(E01s[current_sampling_id], C, eps, mat_id, n_gauss, strain_dof,
124117
n_modes, n_gp)
125118
elif speed == 1:
126-
# TODO verify the result when plasticity is on
127-
effSopt = effective_stress_localization(E01s[current_sampling_id], phi, ref_Cs[idx], ref_epss[idx], plastic_modes,
128-
mat_id,
119+
effSopt = effective_stress_localization(E01s[current_sampling_id], phi, ref_Cs[idx], ref_epss[idx], mat_id,
129120
n_gauss, n_gp, strain_dof, n_modes)
130121
elif speed == 2:
131-
# TODO verify the result when plasticity is on
132122
# matches the result from interpolate_fluctuation_modes with a difference
133123
# that depends on using ref_Cs[idx],ref_epss[idx] instead of alphas
134124
effSopt, phi = effective_S(phi, S001, S101, S103, S002, S102, S104, alpha_C, np.squeeze(alpha_eps, axis=-1),
@@ -138,9 +128,7 @@
138128

139129
if not given_alpha_levels:
140130
Eopt4 = transform_strain_localization(E01s[current_sampling_id], phi, n_gp, strain_dof, n_modes)
141-
Sopt4 = construct_stress_localization(Eopt4, ref_Cs[idx], ref_epss[idx], plastic_modes, mat_id, n_gauss,
142-
strain_dof)
143-
# effSopt = volume_average(Sopt4)
131+
Sopt4 = construct_stress_localization(Eopt4, ref_Cs[idx], ref_epss[idx], mat_id, n_gauss, strain_dof)
144132
err_indicators[level,
145133
idx] = np.mean(np.max(np.abs(compute_err_indicator_efficient(Sopt4, global_gradient)),
146134
axis=0)) / normalization_factor_mech[idx] * 100
@@ -152,7 +140,7 @@
152140
invL = la.inv(la.cholesky(Cref))
153141

154142
err_eff_C[level, idx] = la.norm(invL @ Capprox @ invL.T - np.eye(6)) / la.norm(np.eye(6)) * 100
155-
err_eff_eps[level, idx] = err(la.solve(Capprox, effSopt[:, 7]), la.solve(Cref, effSref[idx][:, 7]))
143+
err_eff_eps[level, idx] = err(la.solve(Capprox, effSopt[:, -1]), la.solve(Cref, effSref[idx][:, -1]))
156144

157145
# TODO remove dtype='f'
158146
group = file.require_group(f'{data_path}_level{level}')
@@ -161,7 +149,7 @@
161149
dset_stiffness = group.require_dataset(f'eff_stiffness_{temperature:07.2f}', (6, 6), dtype='f')
162150
dset_thermal_strain = group.require_dataset(f'eff_thermal_strain_{temperature:07.2f}', (6), dtype='f')
163151
dset_stiffness[:] = Capprox.T
164-
dset_thermal_strain[:] = la.solve(Capprox, effSopt[:, 7])
152+
dset_thermal_strain[:] = la.solve(Capprox, effSopt[:, -1])
165153

166154
if not given_alpha_levels:
167155
max_err_idx = np.argmax(err_indicators[level])

Diff for: interpolate_fluctuation_modes.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from numba import jit, prange
33

44
@jit(nopython=True, cache=True, parallel=True, nogil=True)
5-
def interpolate_fluctuation_modes(E01, mat_stiffness, mat_thermal_strain, plastic_modes, mat_id, n_gauss, strain_dof, n_modes,
6-
n_gp):
5+
def interpolate_fluctuation_modes(E01, mat_stiffness, mat_thermal_strain, mat_id, n_gauss, strain_dof, n_modes, n_gp):
76
K = np.zeros((2 * n_modes, 2 * n_modes))
87
F = np.zeros((2 * n_modes, n_modes))
98
E_approx = np.zeros((n_gp, strain_dof, n_modes))
@@ -13,7 +12,7 @@ def interpolate_fluctuation_modes(E01, mat_stiffness, mat_thermal_strain, plasti
1312
for gp_id in prange(n_gp):
1413
phase_id = mat_id[gp_id // n_gauss]
1514

16-
P = np.hstack((-I, mat_thermal_strain[phase_id], plastic_modes[gp_id]))
15+
P = np.hstack((-I, mat_thermal_strain[phase_id]))
1716

1817
E01t_C = E01[gp_id].T @ mat_stiffness[phase_id]
1918

@@ -30,8 +29,7 @@ def interpolate_fluctuation_modes(E01, mat_stiffness, mat_thermal_strain, plasti
3029

3130
return E_approx, S_average[:6, :]
3231

33-
def update_affine_decomposition(E01, sampling_C, sampling_eps, plastic_modes, n_modes, n_phases, n_gp, strain_dof, mat_id,
34-
n_gauss):
32+
def update_affine_decomposition(E01, sampling_C, sampling_eps, n_modes, n_phases, n_gp, strain_dof, mat_id, n_gauss):
3533
I = np.eye(strain_dof)
3634

3735
K0 = np.zeros((2 * n_modes, 2 * n_modes))
@@ -61,7 +59,7 @@ def update_affine_decomposition(E01, sampling_C, sampling_eps, plastic_modes, n_
6159
eps0phase = eps0[phase_id]
6260
deltaCphase = deltaC[phase_id]
6361
deltaEPSphase = delta_eps[phase_id]
64-
P0_phase = np.hstack((-I, eps0phase, plastic_modes[gp_id]))
62+
P0_phase = np.hstack((-I, eps0phase))
6563
E01_transposed = E01[gp_id].T
6664

6765
# essential terms that construct all other precomputed terms
@@ -118,12 +116,11 @@ def transform_strain_localization(E01, phi, n_gp, strain_dof, n_modes):
118116
return E_approx
119117

120118
@jit(nopython=True, cache=True, parallel=True, nogil=True)
121-
def effective_stress_localization(E01, phi, mat_stiffness, mat_thermal_strain, plastic_modes, mat_id, n_gauss, n_gp, strain_dof,
122-
n_modes):
119+
def effective_stress_localization(E01, phi, mat_stiffness, mat_thermal_strain, mat_id, n_gauss, n_gp, strain_dof, n_modes):
123120
S_average = np.zeros((strain_dof, n_modes))
124121
I = np.eye(strain_dof)
125122
for gp_id in prange(n_gp):
126123
phase_id = mat_id[gp_id // n_gauss]
127-
P = np.hstack((-I, mat_thermal_strain[phase_id], plastic_modes[gp_id]))
124+
P = np.hstack((-I, mat_thermal_strain[phase_id]))
128125
S_average += mat_stiffness[phase_id] @ (E01[gp_id] @ phi - P)
129126
return S_average / n_gp

0 commit comments

Comments
 (0)