Esempio n. 1
0
nb = rom.info['nb']
if rom.info['init'] == 'zero':
    T0 = mypostpro.find_nearest(rom.outputs['t'][0, :], 501)
elif rom.info['init'] == 'ic':
    T0 = 0
    rom.outputs['t'] += 500
rom.coef_mean(T0)
rom.coef_variance(T0)
print(rom.outputs['Ta'])
print(rom.outputs['Tv'])

# Create snapshot class
snap = Snapshot(ops_path, field)
fomu = snap.coef(rom.info['K'])
snap.outputs['t'] = np.linspace(500, 1000, rom.info['K'])
umax, umin = snap.extrema()
ul_bounds = [umax, umin]
uas = snap.mean()
uvs = snap.var()

print(f'Information K: {K}, N: {nb}, T0: {T0}')

dir_path = './rom' + field + '_' + N + '/'

# Plot rom coefficient
if rom.info['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)
    plt_mean_in_t(ax, 0, T0, snap, rom)
Esempio n. 2
0
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)