|
| 1 | +import numpy as np |
| 2 | +import pandas as pd |
| 3 | +import os |
| 4 | +from matplotlib import gridspec |
| 5 | +import matplotlib.pyplot as plt |
| 6 | + |
| 7 | +# Changes working directory to script directory (for consistent MooseDocs usage) |
| 8 | +script_folder = os.path.dirname(__file__) |
| 9 | +os.chdir(script_folder) |
| 10 | + |
| 11 | +# Extract columns for time, pressures, concentration_enclosure_1_at_interface, and concentration_enclosure_2_at_interface |
| 12 | +if "/TMAP8/doc/" in script_folder: # if in documentation folder |
| 13 | + csv_folder = "../../../../test/tests/ver-1kc/gold/ver-1kc_out_k1.csv" |
| 14 | +else: # if in test folder |
| 15 | + csv_folder = "./gold/ver-1kc_out_k1.csv" |
| 16 | +expt_data = pd.read_csv(csv_folder) |
| 17 | +TMAP8_time = expt_data['time'] |
| 18 | +TMAP8_pressure_enclosure_1 = expt_data['pressure_enclosure_1'] |
| 19 | +TMAP8_pressure_enclosure_2 = expt_data['pressure_enclosure_2'] |
| 20 | +concentration_enclosure_1_at_interface = expt_data['concentration_enclosure_1_at_interface'] |
| 21 | +pressure_enclosure_2_at_interface = expt_data['pressure_enclosure_2_at_interface'] |
| 22 | +mass_conservation_sum_encl1_encl2 = expt_data['mass_conservation_sum_encl1_encl2'].values |
| 23 | +concentration_ratio = expt_data['concentration_ratio'] |
| 24 | + |
| 25 | +# Subplot 1: Pressure vs time |
| 26 | +fig = plt.figure(figsize=[6.5,5.5]) |
| 27 | +gs = gridspec.GridSpec(1,1) |
| 28 | +ax = fig.add_subplot(gs[0]) |
| 29 | + |
| 30 | +ax.plot(TMAP8_time, TMAP8_pressure_enclosure_1, label=r"T$_2$ Enclosure 1", c='tab:red', linestyle='-') |
| 31 | +ax.plot(TMAP8_time, TMAP8_pressure_enclosure_2, label=r"T$_2$ Enclosure 2", c='tab:blue', linestyle='-') |
| 32 | +ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda val, pos: '{:.1e}'.format(val))) |
| 33 | +ax.set_xlabel('Time (s)') |
| 34 | +ax.set_ylabel('Pressure (Pa)') |
| 35 | +ax.set_xlim(0, TMAP8_time.max()) |
| 36 | +ax.set_ylim(bottom=0) |
| 37 | +ax.legend(loc="best") |
| 38 | +ax.grid(which='major', color='0.65', linestyle='--', alpha=0.3) |
| 39 | +fig.savefig('ver-1kc_comparison_time.png', bbox_inches='tight', dpi=300) |
| 40 | + |
| 41 | +# Subplot 2: Solubility and concentration ratios vs time |
| 42 | +fig = plt.figure(figsize=[6.5,5.5]) |
| 43 | +gs = gridspec.GridSpec(1,1) |
| 44 | +ax = fig.add_subplot(gs[0]) |
| 45 | + |
| 46 | +solubility_ratio = [1] * len(TMAP8_time[1:]) |
| 47 | +ax.plot(TMAP8_time[1:], concentration_ratio[1:], label=r"Concentration Ratio (TMAP8)", color='tab:blue', linestyle='-') |
| 48 | +ax.plot(TMAP8_time[1:], solubility_ratio, label=r"Solubility Ratio (Analytical)", color='tab:red', linestyle='--') |
| 49 | +ax.set_yticks(np.arange(0, 3, 1)) |
| 50 | +ax.set_xlim(0,TMAP8_time.max()) |
| 51 | +ax.set_xlabel('Time (s)') |
| 52 | +ax.set_ylabel(r"Concentrations ratio $C_{\text{encl1}} / C_{\text{encl2}}$") |
| 53 | +ax.legend(loc="best") |
| 54 | +ax.grid(which='major', color='0.65', linestyle='--', alpha=0.3) |
| 55 | +RMSE = np.sqrt(np.mean((concentration_ratio[1:]-solubility_ratio)**2) ) |
| 56 | +RMSPE = RMSE*100/np.mean(solubility_ratio) |
| 57 | +x_pos = TMAP8_time.max() / 7200 |
| 58 | +y_pos = 0.9 * ax.get_ylim()[1] |
| 59 | +ax.text(x_pos, y_pos, 'RMSPE = %.3f ' % RMSPE + '%', fontweight='bold') |
| 60 | +fig.savefig('ver-1kc_concentration_ratio.png', bbox_inches='tight', dpi=300) |
| 61 | + |
| 62 | +# Subplot 3: Mass Conservation Sum Encl 1 and 2 vs Time |
| 63 | + |
| 64 | +fig = plt.figure(figsize=[6.5,5.5]) |
| 65 | +gs = gridspec.GridSpec(1,1) |
| 66 | +ax = fig.add_subplot(gs[0]) |
| 67 | + |
| 68 | +ax.plot(TMAP8_time, mass_conservation_sum_encl1_encl2, c='tab:blue') |
| 69 | +ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda val, pos: '{:.3e}'.format(val))) |
| 70 | +ax.set_xlabel('Time (s)') |
| 71 | +ax.set_ylabel(r"Mass Conservation Sum Encl 1 and 2 (mol/m$^3$)") |
| 72 | +ax.grid(which='major', color='0.65', linestyle='--', alpha=0.3) |
| 73 | +mass_variation_percentage = (np.max(mass_conservation_sum_encl1_encl2)-np.min(mass_conservation_sum_encl1_encl2))/np.min(mass_conservation_sum_encl1_encl2)*100 |
| 74 | +print("Percentage of mass variation: ", mass_variation_percentage) |
| 75 | +fig.savefig('ver-1kc_mass_conservation.png', bbox_inches='tight', dpi=300) |
| 76 | + |
| 77 | +# Repeat the same for K=10/RT |
| 78 | + |
| 79 | +if "/TMAP8/doc/" in script_folder: # if in documentation folder |
| 80 | + csv_folder_k10 = "../../../../test/tests/ver-1kc/gold/ver-1kc_out_k10.csv" |
| 81 | +else: # if in test folder |
| 82 | + csv_folder_k10 = "./gold/ver-1kc_out_k10.csv" |
| 83 | +expt_data_k10 = pd.read_csv(csv_folder_k10) |
| 84 | +TMAP8_time_k10 = expt_data_k10['time'] |
| 85 | +TMAP8_pressure_enclosure_1_k10 = expt_data_k10['pressure_enclosure_1'] |
| 86 | +TMAP8_pressure_enclosure_2_k10 = expt_data_k10['pressure_enclosure_2'] |
| 87 | +concentration_enclosure_1_at_interface_k10 = expt_data_k10['concentration_enclosure_1_at_interface'] |
| 88 | +pressure_enclosure_2_at_interface_k10 = expt_data_k10['pressure_enclosure_2_at_interface'] |
| 89 | +mass_conservation_sum_encl1_encl2_k10 = expt_data_k10['mass_conservation_sum_encl1_encl2'].values |
| 90 | +concentration_ratio_k10 = expt_data_k10['concentration_ratio'] |
| 91 | + |
| 92 | +# Subplot 1 : Pressure vs time |
| 93 | + |
| 94 | +fig = plt.figure(figsize=[6.5,5.5]) |
| 95 | +gs = gridspec.GridSpec(1,1) |
| 96 | +ax = fig.add_subplot(gs[0]) |
| 97 | + |
| 98 | +ax.plot(TMAP8_time_k10, TMAP8_pressure_enclosure_1_k10, label=r"T$_2$ Enclosure 1", c='tab:red', linestyle='-') |
| 99 | +ax.plot(TMAP8_time_k10, TMAP8_pressure_enclosure_2_k10, label=r"T$_2$ Enclosure 2", c='tab:blue', linestyle='-') |
| 100 | +ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda val, pos: '{:.1e}'.format(val))) |
| 101 | +ax.set_xlabel('Time (s)') |
| 102 | +ax.set_ylabel('Pressure (Pa)') |
| 103 | +ax.set_xlim(0, TMAP8_time_k10.max()) |
| 104 | +ax.set_ylim(bottom=0) |
| 105 | +ax.legend(loc="best") |
| 106 | +ax.grid(which='major', color='0.65', linestyle='--', alpha=0.3) |
| 107 | +fig.savefig('ver-1kc_comparison_time_k10.png', bbox_inches='tight', dpi=300) |
| 108 | + |
| 109 | +# Subplot 2: Solubility and concentration ratios vs time |
| 110 | + |
| 111 | +fig = plt.figure(figsize=[6.5,5.5]) |
| 112 | +gs = gridspec.GridSpec(1,1) |
| 113 | +ax = fig.add_subplot(gs[0]) |
| 114 | + |
| 115 | +solubility_ratio = [10] * len(TMAP8_time_k10[1:]) |
| 116 | +ax.plot(TMAP8_time_k10[1:], concentration_ratio_k10[1:], label=r"Concentration Ratio (TMAP8)", color='tab:blue', linestyle='-') |
| 117 | +ax.plot(TMAP8_time_k10[1:], solubility_ratio, label=r"Solubility Ratio (Analytical)", color='tab:red', linestyle='--') |
| 118 | +ax.set_yticks(np.arange(0, 21, 10)) |
| 119 | +ax.set_xlim(0,TMAP8_time_k10.max()) |
| 120 | +ax.set_xlabel('Time (s)') |
| 121 | +ax.set_ylabel(r"Concentrations ratio $C_{\text{encl1}} / C_{\text{encl2}}$") |
| 122 | +ax.legend(loc="best") |
| 123 | +ax.grid(which='major', color='0.65', linestyle='--', alpha=0.3) |
| 124 | +RMSE = np.sqrt(np.mean((concentration_ratio_k10[1:]-solubility_ratio)**2)) |
| 125 | +RMSPE = RMSE*100/np.mean(solubility_ratio) |
| 126 | +x_pos = TMAP8_time_k10.max() / 7200 |
| 127 | +y_pos = 0.9 * ax.get_ylim()[1] |
| 128 | +ax.text(x_pos, y_pos, 'RMSPE = %.3f ' % RMSPE + '%', fontweight='bold') |
| 129 | +fig.savefig('ver-1kc_concentration_ratio_k10.png', bbox_inches='tight', dpi=300) |
| 130 | + |
| 131 | +# Subplot 3 : Mass Conservation Sum Encl 1 and 2 vs Time |
| 132 | + |
| 133 | +fig = plt.figure(figsize=[6.5,5.5]) |
| 134 | +gs = gridspec.GridSpec(1,1) |
| 135 | +ax = fig.add_subplot(gs[0]) |
| 136 | + |
| 137 | +ax.plot(TMAP8_time_k10, mass_conservation_sum_encl1_encl2_k10, c='tab:blue') |
| 138 | +ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda val, pos: '{:.3e}'.format(val))) |
| 139 | +ax.set_xlabel('Time (s)') |
| 140 | +ax.set_ylabel(r"Mass Conservation Sum Encl 1 and 2 (mol/m$^3$)") |
| 141 | +ax.grid(which='major', color='0.65', linestyle='--', alpha=0.3) |
| 142 | +mass_variation_percentage = (np.max(mass_conservation_sum_encl1_encl2_k10)-np.min(mass_conservation_sum_encl1_encl2_k10))/np.min(mass_conservation_sum_encl1_encl2_k10)*100 |
| 143 | +print("Percentage of mass variation: ", mass_variation_percentage) |
| 144 | +fig.savefig('ver-1kc_mass_conservation_k10.png', bbox_inches='tight', dpi=300) |
| 145 | + |
0 commit comments