def plot_diagram(fname, fout, title=None, **kwargs): df = load_table(fname, sort='T', fill=0) df['T'] -= 273.15 # A1 = df['NP(BCC_A2)'] # A1 = df['NP(FCC_A1#1)'] fig, ax = plt.subplots(figsize=(4, 4)) ax.plot(df['T'], df['NP(BCC_A2)'], label=r'$\alpha$ (ferrita)') ax.plot(df['T'], df['NP(FCC_A1#1)'], label=r'$\gamma$ (austenita)') try: ax.plot(df['T'], df['NP(CEMENTITE)'], label=r'$Fe_3C$ (cementita)') except: pass A1 = df['T'][df['NP(FCC_A1#1)'] == 0].max() ax.axvline(A1, ls=':', color='k') ax.annotate('A1', (A1, 1), va='bottom', ha='right') A3 = df['T'][df['NP(FCC_A1#1)'] == 1].min() ax.axvline(A3, ls=':', color='k') ax.annotate('A3', (A3, 1), va='bottom', ha='left') try: Tcem = df['T'][df['NP(CEMENTITE)'] == 0].min() Tbcc = df['T'][df['NP(BCC_A2)'] == 0].min() except: pass else: A1prime = Tcem if Tcem < Tbcc else Tbcc ax.axvline(A1prime, ls=':', color='k') ax.annotate('A1\'', (A1prime, 1), va='bottom', ha='left') ax.set_xlim(400, 1200) ax.set_ylim(-.05, 1.07) ax.set_xlabel(u'Temperatura (°C)') ax.set_ylabel(u'Fração molar da fase') if title is not None: ax.set_title(title) ax.legend() fig.savefig(fout, **kwargs) return fig, ax
""" Plot all RESULT_####.TXT files """ import glob import numpy as np import pandas as pd import matplotlib.pyplot as plt from tctools import load_table, plot_table files = pd.read_csv('../databases/compositions_files.csv', comment='#') fig, ax = plt.subplots() for i, fname in enumerate(files['file']): if i % 10 == 0: try: df = load_table(fname, 'T', fill=0) x = df['T'] if 'NP(FCC_A1#1)' in df.columns: y = df['NP(FCC_A1#1)'] if 'NP(FCC_A1#2)' in df.columns: y = df['NP(FCC_A1#2)'] ax.plot(x, y, label=fname) except Exception as ex: print(fname, ex) # plt.legend() plt.show()
# plt.plot(T, bcc.DVV0(T, P), label='Ferrite') # plt.plot(T, fcc.DVV0(T, P), label='Austenite') # plt.plot(T, cem.DVV0(T, P), label='Cementite') # plt.legend(loc='best') # plt.show() import tctools as tt files = [ '/home/arthur/Dropbox/{Shared} Lucas/Thermo-Calc/Trilhos/NP_HC.TXT', '/home/arthur/Dropbox/{Shared} Lucas/Thermo-Calc/Trilhos/NP_S1.TXT', '/home/arthur/Dropbox/{Shared} Lucas/Thermo-Calc/Trilhos/NP_NIPPON.TXT' ] labels = ['HC', 'S1', 'Nippon'] for fname, lbl in zip(files, labels): data = tt.load_table(fname, sort=0) Ts = [] Vs = [] P = 101325. V0 = data[0, 1] * bcc.Vm(25, P) + data[0, 3] * cem.Vm(25, P) / 4. for line in data: T, npbcc, npfcc, npcem = line V = npbcc * bcc.Vm(T, P) + npfcc * fcc.Vm(T, P) + npcem * cem.Vm( T, P) / 4. Ts.append(T) Vs.append((V - V0) / V0) # Vs.append(V) plt.plot(np.array(Ts) - 273.15, Vs, label=lbl)
import os import sys import numpy as np import pandas as pd import matplotlib.pyplot as plt from tctools import load_table, plot_table if __name__ == '__main__': if len(sys.argv) > 1: T_min, T_max, T_step = 673, 1473, 10 df = pd.read_csv('../databases/compositions_files.csv', comment='#') for idx in sys.argv[1:]: fname = '../results/{:05d}.DAT'.format(int(idx)) fig, ax = plt.subplots() result = load_table(fname, sort='T', fill=0) plot_table(df=result, xaxis='T', ax=ax, colpattern='NP(*)') idx, = np.where(fname == df['file'].values) if len(idx) > 0: idx = int(idx[0]) sel = df.iloc[idx] title = 'Fe-{:g}C-{:g}Mn-{:g}Si-{:g}Ni-{:g}Cr'.format( 100 * sel['C'], 100 * sel['Mn'], 100 * sel['Si'], 100 * sel['Ni'], 100 * sel['Cr']) ax.set_title(title) plt.show()
def extract_Tcrit(fname): """ Extract the critical temperature (Tcrit) from Thermo-Calc generated table Arguments --------- fname : Path to the Thermo-Calc table file Return ------ A1, A1prime, A3, eutectoid : tuple containing the extracted values of A1, A1prime, and A3, and a string eutectoid (hipo/hiper) determining whether the alloy is hipo or hiper eutectoid. """ A1 = np.nan A1prime = np.nan A3 = np.nan eutectoid = None try: df = load_table(fname, sort='T', fill=0) except: print('Failed to load {}'.format(fname)) else: # print('{} successfully loaded'.format(fname)) # temperature T = df['T'] mf_fer = np.array([]) mf_aus = np.array([]) mf_cem = np.array([]) if 'NP(BCC_A2)' in df.columns: # mole fraction of ferrite mf_fer = df['NP(BCC_A2)'] max_aus = 0 # 0 K if 'NP(FCC_A1#1)' in df.columns: # mole fraction of austenite mf_aus = df['NP(FCC_A1#1)'] max_aus = mf_aus.max() if 'NP(FCC_A1#2)' in df.columns: # Chooses the column with higher NP values if df['NP(FCC_A1#2)'].max() > max_aus: mf_aus = df['NP(FCC_A1#2)'] if 'NP(CEMENTITE)' in df.columns: # mole fraction of cementite mf_cem = df['NP(CEMENTITE)'] # Determine A1 and A3 if len(mf_aus) > 0: # A1 temperature # highest temperature where mf_aus is 0 idx, = np.where(mf_aus == 0) if len(idx) > 0: A1 = T[idx[-1]] # A3 temperature # lowest temperature where mf_aus is 1 idx, = np.where(mf_aus == 1) if len(idx) > 0: A3 = T[idx[0]] # Determine A1' idx_fer, = np.where(mf_fer == 0) idx_cem, = np.where(mf_cem == 0) if len(idx_fer) > 0: if len(idx_cem) > 0: # A1' and A3 are related to the temperatures where # mf_fer and mf_cem are 0, namely T_fer and T_cem # A1' equals to min(T_fer, T_cem) # A3 equals to max(T_fer, T_cem) T_fer = T[idx_fer[0]] T_cem = T[idx_cem[0]] if T_fer > T_cem: A1prime = T_cem A3 = T_fer eutectoid = 'hipo' else: A1prime = T_fer A3 = T_cem eutectoid = 'hiper' else: # If cementite is not defined, there's no intecritical # phase field (ferrite + austenite + cementite). # In this case, A1 and A1' do not make sense and are # set as np.nan A1 = np.nan A1prime = np.nan eutectoid = 'hipo' else: if len(mf_cem) > 0: eutectoid = 'hiper' else: print('{} has no austenite'.format(fname)) return A1, A1prime, A3, eutectoid