Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
plotGrowthSwellingDensity.py
Go to the documentation of this file.
1import csv
2import os
3import sys
4from pathlib import Path
5import numpy as np
6from matplotlib import pyplot as plt
7
8sys.path.insert(0, str(Path(__file__).resolve().parents[2] / 'python'))
9from readF import readFfile, getFarray
10from readFile import get_scalar
11
12# Preserve the original Carpenter-Rogerson data, exported with every test run.
13folder = str(Path(sys.argv[1]).resolve())
14series = {name: [] for name in ('EXPIa', 'EXPIc', 'EXPZa', 'EXPZc')}
15with open(Path(folder) / 'experimental-data.csv') as stream:
16 for row in csv.DictReader(stream):
17 series[row['series']].append([float(row['dose_dpa']), float(row['strain_in_1e_minus_4'])])
18EXPIa, EXPIc, EXPZa, EXPZc = (np.asarray(series[name]) for name in series)
19
20# ------------------------------------------------------------------------ #
21# Main Inputs
22# ------------------------------------------------------------------------ #
23
24textfont = 18
25axisfont = 16
26
27# ------------------------------------------------------------------------ #
28# Main Processing Loop
29# ------------------------------------------------------------------------ #
30print(f"Processing {folder}")
31matfile = os.path.join(folder, 'inputFiles', 'Zr4_Fitted.txt')
32F, Flabels = readFfile(folder)
33t = getFarray(F, Flabels, 'time [b/cs]')
34DoseRate = get_scalar(matfile, 'doseRate_dpaPerSec')
35mu0_SI = get_scalar(matfile, 'mu0_SI')
36rho_SI = get_scalar(matfile, 'rho_SI')
37b_SI = get_scalar(matfile, 'b_SI')
38v_dd2SI = np.sqrt(mu0_SI / rho_SI)
39t_dd2SI = b_SI / v_dd2SI
40dpa = t * t_dd2SI * DoseRate # <-- missing before
41
42# Plotting strain components and swelling
43b11 = getFarray(F, Flabels, 'betaP_11')
44b22 = getFarray(F, Flabels, 'betaP_22')
45b33 = getFarray(F, Flabels, 'betaP_33')
46b12 = getFarray(F, Flabels, 'betaP_12')
47b13 = getFarray(F, Flabels, 'betaP_13')
48b23 = getFarray(F, Flabels, 'betaP_23')
49
50swelling_trace_over_3 = []
51for i in range(len(t)):
52 betaP = np.array([
53 [b11[i], b12[i], b13[i]],
54 [b12[i], b22[i], b23[i]],
55 [b13[i], b23[i], b33[i]],
56 ])
57 trace = np.trace(betaP)
58 swelling_trace_over_3.append(trace / 3)
59fig, ax = plt.subplots(figsize=(10, 6))
60ax.plot(dpa+0.5, b11*100, label=r'$\beta_{11}$', color='red')
61ax.plot(dpa+0.5, b22*100, label=r'$\beta_{22}$', color='green')
62ax.plot(dpa+0.5, b33*100, label=r'$\beta_{33}$', color='blue')
63ax.plot(dpa+0.5, swelling_trace_over_3, label=r'Swelling ($\mathrm{tr}(\beta^P)/3$)', color='gray', linestyle='-')
64
65
66ax.set_xlim(0,9.2)
67ax.set_ylim(-0.08,0.06)
68
69# Experimental Data
70ax.scatter(EXPIa[:,0],EXPIa[:,1]*10**-2,color="firebrick",marker="s",s=80,label=r'Experiment: Iodide Purity');
71ax.scatter(EXPZa[:,0],EXPZa[:,1]*10**-2,color="orange",marker="s",s=80,label=r'Experiment: Zone Refined Purity');
72ax.scatter(EXPIc[:,0],EXPIc[:,1]*10**-2,color="firebrick",marker="s",s=80);
73ax.scatter(EXPZc[:,0],EXPZc[:,1]*10**-2,color="orange",marker="s",s=80);
74
75
76ax.set_xlabel('Irradiation Dose [dpa]', fontsize=textfont)
77ax.set_ylabel('Strain [%]', fontsize=textfont)
78ax.legend(fontsize=axisfont)
79ax.grid(True, linestyle=':')
80ax.set_xlim(left=0)
81ax.axhline(0, color='k', linewidth=0.5)
82ax.tick_params(axis='both', which='major', direction='in', length=6, labelsize=axisfont)
83fig.tight_layout()
84
85
86
87# # Plot dislocation density
88# glissile_density = getFarray(F, Flabels, 'glissile density [m^-2]')
89# sessile_density = getFarray(F, Flabels, 'sessile density [m^-2]')
90# fig2, ax2 = plt.subplots(figsize=(10, 6))
91# ax2.plot(dpa, glissile_density+sessile_density, label='Dislocation Density', color='k', linewidth=2)
92# ax2.set_xlabel('Irradiation Dose [dpa]', fontsize=textfont)
93# ax2.set_ylabel('Dislocation Density [m$^{-2}$]', fontsize=textfont)
94# ax2.legend(fontsize=axisfont)
95# ax2.grid(True, linestyle=':')
96# ax2.set_xlim(left=0)
97# ax2.tick_params(axis='both', which='major', direction='in', length=6, labelsize=axisfont)
98# fig2.tight_layout()
99
100# Headless output for CTest.
101# Save figures
102save_path = os.path.join(folder, 'StrainComponentsWithSwelling.pdf')
103fig.savefig(save_path)
104fig.savefig(os.path.join(folder, "StrainComponentsWithSwelling.png"), dpi=150)
105# save_path2 = os.path.join(folder, 'DislocationDensities_vs_DPA.pdf')
106# fig2.savefig(save_path2)
107plt.close(fig)
108print(f"Saved {save_path}")
109# plt.close(fig2)
110# print(f"Saved {save_path2}")
111