def plt_mtfluc(rom, tdir): import numpy as np import matplotlib.pyplot as plt import sys from myplot import plt_romcoef_in_t, plt_snapcoef_in_t, \ plt_snap_minmax, plt_mean_in_t, add_std_in_t, plt_sample_mean_var sys.path.append('/Users/bigticket0501/Developer/PyMOR/postprocessing/') from snapshot import Snapshot import os setup_old.style(1) setup_old.text() sub_dir = os.path.join(tdir, 'mtfluc') checkdir(sub_dir) rom_params = {'c': 'b', 'marker': 'o'} rom_params['label'] = rom.info['method'].upper() xlabel = r'$N$' ylabel = r'$\langle T_{fluc} \rangle_s$' fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) ax.set(ylabel=ylabel, xlabel=xlabel) ax.plot(rom.nbs, rom.mtfluc, **rom_params) mtfluc_fom = np.loadtxt('../qoi/tmtfluc') fom_params = {'c': 'k', 'marker': 'o', 'label': 'FOM'} ax.plot(rom.nbs, mtfluc_fom * np.ones(len(rom.nbs)), **fom_params) ax.legend(loc=0) fname1 = 'mtfluc' data = np.column_stack((rom.nbs, rom.mtfluc)) output = os.path.join(sub_dir, fname1) if rom.info['method'] == 'l-rom': output += '_' + rom.info['perc'] elif rom.info['method'] == 'l-rom-df': output += '_' + rom.info['fwidth'] output += '.csv' np.savetxt(output, data, delimiter=',', header='N, mtfluc', comments="") output = os.path.join(sub_dir, 'mtfluc.png') fig.savefig(output) plt.close(fig)
def plt_tke_in_t(rom, nb, tdir): import numpy as np import matplotlib.pyplot as plt import sys from myplot import plt_romcoef_in_t, plt_snapcoef_in_t, \ plt_snap_minmax, plt_mean_in_t, add_std_in_t, plt_sample_mean_var sys.path.append('/Users/bigticket0501/Developer/PyMOR/postprocessing/') from snapshot import Snapshot import os setup_old.style(1) setup_old.text() sub_dir = os.path.join(tdir, 'tke') checkdir(sub_dir) K = rom.info['K'] T0 = rom.info['T0'] J0 = rom.info['J0'] print(f'Information K: {K}, N: {nb}, T0: {T0}, J0: {J0}') rom_params = {'c': 'b', 'mfc': 'None'} rom_params['label'] = rom.info['method'].upper() xlabel = r'$t$' ylabel = 'tke' + r'$(t)$' fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) ax.set(ylabel=ylabel, xlabel=xlabel) ax.semilogy(rom.tke[str(nb)]['t'], rom.tke[str(nb)]['tke'], **rom_params) ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.11), ncol=4, borderaxespad=0, frameon=False) output = os.path.join(sub_dir, 'tke_N' + str(nb) + '.png') fig.savefig(output) plt.close(fig)
def plt_nu_1st_2nd(rom, tdir): import numpy as np import matplotlib.pyplot as plt import sys import pandas as pd sys.path.append('/Users/bigticket0501/Developer/PyMOR/postprocessing/') from snapshot import Snapshot import os import math setup_old.style(1) setup_old.text() sub_dir = os.path.join(tdir, 'nu') checkdir(sub_dir) # get the FOM data filename = './fom/nus_mom.csv' fom = pd.read_csv(filename).to_numpy() rom_params = {'c': 'b', 'marker': 'o'} rom_params['label'] = rom.info['method'].upper() xlabel = r'$N$' ylabel = r'$\langle Nu \rangle_g$' fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) ax.set(ylabel=ylabel, xlabel=xlabel, title='Predicted Mean Nu vs. Truth Mean Nu') ax.plot(rom.nbs, rom.nus_ms, **rom_params) fom_params = {'c': 'k', 'marker': 'o', 'label': 'FOM'} ax.plot(rom.nbs, fom[0][0] * np.ones(len(rom.nbs)), '-o', **fom_params) ax.legend(loc=0) fname1 = 'mnu' data = np.column_stack((rom.nbs, rom.nus_ms)) output = os.path.join(sub_dir, fname1) if rom.info['method'] == 'l-rom': output += '_' + rom.info['perc'] elif rom.info['method'] == 'l-rom-df': output += '_' + rom.info['fwidth'] output += '.csv' np.savetxt(output, data, delimiter=',', header='N, mnus', comments="") output = os.path.join(sub_dir, 'mnus.png') fig.savefig(output) plt.close(fig) rom_params = {'c': 'b', 'marker': 'o'} rom_params['label'] = rom.info['method'].upper() xlabel = r'$N$' ylabel = r'$Std(Nu)$' fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) ax.set(ylabel=ylabel, xlabel=xlabel, title='Predicted Std(Nu) vs. Truth Std(Nu)') ax.plot(rom.nbs, rom.nus_sds, **rom_params) fom_params = {'c': 'k', 'marker': 'o', 'label': 'FOM'} ax.plot(rom.nbs, fom[0][1] * np.ones(len(rom.nbs)), '-o', **fom_params) ax.set_ylim([ fom[0][1] / 2, fom[0][1] * 2, ]) ax.legend(loc=0) fname1 = 'stdnu' data = np.column_stack((rom.nbs, rom.nus_sds)) output = os.path.join(sub_dir, fname1) if rom.info['method'] == 'l-rom': output += '_' + rom.info['perc'] elif rom.info['method'] == 'l-rom-df': output += '_' + rom.info['fwidth'] output += '.csv' np.savetxt(output, data, delimiter=',', header='N, stdnu', comments="") output = os.path.join(sub_dir, 'stdnu.png') fig.savefig(output) plt.close(fig) rom_params = {'c': 'b', 'marker': 'o'} rom_params['label'] = rom.info['method'].upper() xlabel = r'$N$' fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) ax.set(xlabel=xlabel, title='Relative Error in Mean Nu') ax.semilogy(rom.nbs, rom.mnuserr, **rom_params) ylim_exp = math.ceil(math.log10(min(rom.mnuserr))) - 1 ax.set_ylim([10**ylim_exp, 1e0]) ax.legend(loc=0) fname1 = 'mnu_err' data = np.column_stack((rom.nbs, rom.mnuserr)) output = os.path.join(sub_dir, fname1) if rom.info['method'] == 'l-rom': output += '_' + rom.info['perc'] elif rom.info['method'] == 'l-rom-df': output += '_' + rom.info['fwidth'] output += '.csv' np.savetxt(output, data, delimiter=',', header='N, mnuserr', comments="") output = os.path.join(sub_dir, 'mnuserr.png') fig.savefig(output) plt.close(fig) rom_params = {'c': 'b', 'marker': 'o'} rom_params['label'] = rom.info['method'].upper() xlabel = r'$N$' fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) ax.set(xlabel=xlabel, title='Relative Error in Std(Nu)') ax.semilogy(rom.nbs, rom.stdnuserr, **rom_params) ax.legend(loc=0) fname1 = 'stdnuerr' data = np.column_stack((rom.nbs, rom.stdnuserr)) output = os.path.join(sub_dir, fname1) if rom.info['method'] == 'l-rom': output += '_' + rom.info['perc'] elif rom.info['method'] == 'l-rom-df': output += '_' + rom.info['fwidth'] output += '.csv' np.savetxt(output, data, delimiter=',', header='N, stdnuerr', comments="") output = os.path.join(sub_dir, 'stdnuerr.png') fig.savefig(output) plt.close(fig)
def plt_coef_in_t(rom, nb, tdir): import numpy as np import matplotlib.pyplot as plt import sys from myplot import plt_romcoef_in_t, plt_snapcoef_in_t, \ plt_snap_minmax, plt_mean_in_t, add_mean_in_t, add_std_in_t, plt_sample_mean_var sys.path.append('/Users/bigticket0501/Developer/PyMOR/postprocessing/') from snapshot import Snapshot import os setup_old.style(1) setup_old.text() field = rom.field sub_dir = os.path.join(tdir, 'rom' + field + '_' + str(nb)) checkdir(sub_dir) # Create snapshot class # Need to modify the ops_path so that it does not depends on the position ops_path = '../ops/' snap = Snapshot(ops_path, field) snap.coef(rom.info['K']) ds = (rom.info['Tf'] - rom.info['T0'] + 1) / rom.info['K'] snap.outputs['t'] = np.linspace(rom.info['T0'] - 1 + ds, rom.info['Tf'], rom.info['K']) umax, umin = snap.extrema() snap.mean() snap.var() K = rom.info['K'] T0 = rom.info['T0'] J0 = rom.info['J0'] print(f'Information K: {K}, N: {nb}, T0: {T0}, J0: {J0}') # Plot rom coefficient if nb == 1: fig, ax = plt.subplots(1, squeeze=True, tight_layout=True) plt_romcoef_in_t(ax, 0, T0, rom) plt_snapcoef_in_t(ax, 0, T0, snap) plt_snap_minmax(ax, 0, T0, snap) add_mean_in_t(ax, 0, T0, snap, rom) add_std_in_t(ax, 0, T0, snap, rom) ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.11), ncol=4, borderaxespad=0, frameon=False) else: N_list = [0, int(nb / 2) - 1, nb - 4] # Number of coefficients you want for N0 in N_list: num_coef_show = 4 num_coef_show = min(num_coef_show, nb) fig, axs = plt.subplots(num_coef_show, sharex=True, squeeze=True, tight_layout=True) for n in range(num_coef_show): plt_romcoef_in_t(axs[n], n + N0, T0, rom) plt_snapcoef_in_t(axs[n], n + N0, T0, snap) plt_snap_minmax(axs[n], n + N0, T0, snap) add_mean_in_t(axs[n], n + N0, T0, snap, rom) add_std_in_t(axs[n], n + N0, T0, snap, rom) if n == 0: ax = axs[n] ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.51), ncol=4, borderaxespad=0, frameon=False) if rom.info['method'] == 'cp-rom': print(rom.fnames['rom' + field]) s1 = 'rom' + field + '_N' + str(nb) + '_' + str(N0) + '.png' else: s1 = 'rom' + field + '_N' + str(nb) + '_' + str(N0) + '.png' output = os.path.join(sub_dir, s1) fig.savefig(output) fig = plt_sample_mean_var(rom, snap, nb) output = os.path.join(sub_dir, field + 'a_' + field + 'v_N' + str(nb) + '.png') fig.savefig(output)
def plt_rom_norm_w_N(rom, tdir): import numpy as np import matplotlib.pyplot as plt import os setup_old.style(1) setup_old.text() # Create subdirectory sub_dir = os.path.join(tdir, 'rom_norm') checkdir(sub_dir) solver = rom.info['method'].upper() # Create title title = 'Norm of the predictied mean flow by ' + solver + ' at ' anc_lb = '' for key, value in rom.info['parameters'].items(): if key == 'theta': anc_lb += '\\' + str(key) + '^*_g=' + str(value) else: anc_lb += str(key) + '^*=' + str(value) # Data transform data = np.column_stack((rom.nbs, rom.rom_norm)) data = data[data[:, 0].argsort()] # fix the h1 norm for j in range(data.shape[0]): if (rom.info['ifrom(1)']): idx1 = 1 data[j, idx1 + 2] = np.sqrt(data[j, idx1]**2 + data[j, idx1 + 1]**2) if (rom.info['ifrom(2)']): idx2 = 4 data[j, idx2 + 2] = np.sqrt(data[j, idx2]**2 + data[j, idx2 + 1]**2) if (rom.info['ifrom(1)'] and rom.info['ifrom(2)']): idx3 = 7 data[j, idx3 + 2] = np.sqrt(data[j, idx3]**2 + data[j, idx3 + 1]**2) if (rom.info['ifrom(1)']): fig, ax = plt.subplots(1, tight_layout=True) ax.set(xlabel=r'$N$', ylabel=r'$\|\tilde{u}\|_{*}$', xlim=[0, max(rom.nbs)], title=title + '$' + anc_lb + '$') ax.plot(data[:, 0], data[:, idx1], 'b-o', mfc="None", label=r'$H^1_0$') ax.plot(data[:, 0], data[:, idx1 + 1], 'r-o', mfc="None", label=r'$L^2$') ax.plot(data[:, 0], data[:, idx1 + 2], 'k-o', mfc="None", label=r'$H^1$') ax.legend(loc=0) fname1 = 'rom_u_norm' fname2 = 'N_list' fname3 = 'rom_u_h10' fname4 = 'rom_u_l2' fname5 = 'rom_u_h1' for key, value in rom.info['parameters'].items(): fname1 += '_' + str(key) + '_' + str(value) fname2 += '_' + str(key) + '_' + str(value) fname3 += '_' + str(key) + '_' + str(value) fname4 += '_' + str(key) + '_' + str(value) fname5 += '_' + str(key) + '_' + str(value) fname2 += '.dat' fname3 += '.dat' fname4 += '.dat' fname5 += '.dat' output = os.path.join(sub_dir, fname1) fig.savefig(output) output = os.path.join(sub_dir, fname2) np.savetxt(output, data[:, 0]) output = os.path.join(sub_dir, fname3) np.savetxt(output, data[:, idx1]) output = os.path.join(sub_dir, fname4) np.savetxt(output, data[:, idx1 + 1]) output = os.path.join(sub_dir, fname5) np.savetxt(output, data[:, idx1 + 2]) if (rom.info['ifrom(2)']): fig, ax = plt.subplots(1, tight_layout=True) ax.set(ylabel=r'$\||T\|_{*}$', xlabel=r'$N$', title=title) ax.plot(data[:, 0], data[:, idx2], 'b-o', mfc="None", label=r'$H^1_0$') ax.plot(data[:, 0], data[:, idx2 + 1], 'r-o', mfc="None", label=r'$L^2$') ax.plot(data[:, 0], data[:, idx2 + 2], 'k-o', mfc="None", label=r'$H^1$') ax.legend(loc=0) fname1 = 'rom_T_norm' fname2 = 'N_list' fname3 = 'rom_T_h10' fname4 = 'rom_T_l2' fname5 = 'rom_T_h1' for key, value in rom.info['parameters'].items(): fname1 += '_' + str(key) + '_' + str(value) fname2 += '_' + str(key) + '_' + str(value) fname3 += '_' + str(key) + '_' + str(value) fname4 += '_' + str(key) + '_' + str(value) fname5 += '_' + str(key) + '_' + str(value) fname2 += '.dat' fname3 += '.dat' fname4 += '.dat' fname5 += '.dat' output = os.path.join(sub_dir, fname1) fig.savefig(output) output = os.path.join(sub_dir, fname2) np.savetxt(output, data[:, 0]) output = os.path.join(sub_dir, fname3) np.savetxt(output, data[:, idx2]) output = os.path.join(sub_dir, fname4) np.savetxt(output, data[:, idx2 + 1]) output = os.path.join(sub_dir, fname5) np.savetxt(output, data[:, idx2 + 2]) if (rom.info['ifrom(1)'] and rom.info['ifrom(2)']): fig, ax = plt.subplots(1, tight_layout=True) ax.set(ylabel=r'$\||(u, T)\|_{*}$', xlabel=r'$N$', title=title) ax.plot(data[:, 0], data[:, idx3], 'b-o', mfc="None", label=r'$H^1_0$') ax.plot(data[:, 0], data[:, idx3 + 1], 'r-o', mfc="None", label=r'$L^2$') ax.plot(data[:, 0], data[:, idx3 + 2], 'k-o', mfc="None", label=r'$H^1$') ax.legend(loc=0) fname1 = 'rom_norm' fname2 = 'N_list' fname3 = 'rom_h10' fname4 = 'rom_l2' fname5 = 'rom_h1' for key, value in rom.info['parameters'].items(): fname1 += '_' + str(key) + '_' + str(value) fname2 += '_' + str(key) + '_' + str(value) fname3 += '_' + str(key) + '_' + str(value) fname4 += '_' + str(key) + '_' + str(value) fname5 += '_' + str(key) + '_' + str(value) fname2 += '.dat' fname3 += '.dat' fname4 += '.dat' fname5 += '.dat' output = os.path.join(sub_dir, fname1) fig.savefig(output) output = os.path.join(sub_dir, fname2) np.savetxt(output, data[:, 0]) output = os.path.join(sub_dir, fname3) np.savetxt(output, data[:, idx3]) output = os.path.join(sub_dir, fname4) np.savetxt(output, data[:, idx3 + 1]) output = os.path.join(sub_dir, fname5) np.savetxt(output, data[:, idx3 + 2]) return