示例#1
0
def dual_norm_wparam(model, N, T0, mode, idx, aval, tkey, tval, fd=None):
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.ticker as mticker
    import operator
    import math
    from setup.gtfpath import gtfpath
    from aux.create_dir import create_dir
    from aux.cffdic import cffdic
    from aux.rdatatoarray import rdatatoarray
    from aux.gptr import gptr
    from figsetup.style import style
    from figsetup.text import text
    from fig_helpers.set_ax import set_ax
    from fig_helpers.set_pltparams import set_pltparams
    from save_helpers.mysave import mysave

    style(1)
    text()

    T0 = int(T0)
    print(model, N, T0, mode, fd)

    target_dir = './dual_norm/'
    create_dir(target_dir)

    search_dir = '../' + model + '_info/dual_norm'
    if mode == 'all':
        root, filenames = gtfpath(search_dir, '^.*_' + N + 'nb_.*$')
    else:
        root, filenames = gtfpath(
            search_dir, '^.*_' + N + 'nb_*_h10_(?!.*-90|.*-80|.*-70).*$')
    ptr = gptr(model, N, T0, mode, fd)
    files_dict = cffdic(filenames, ptr, idx)
    dict_final = sorted(files_dict.items(), key=operator.itemgetter(0))

    data = rdatatoarray(dict_final, 'dual_norm')

    solver = model.upper()
    plot_params = set_pltparams('dual_norm', solver, N, T0, fd)

    fig, ax = plt.subplots(1, tight_layout=True)
    set_ax(ax, 'dual_norm', tkey, tval)
    ax.plot(data[:, 0], data[:, 1], **plot_params)
    aidx = np.where(data[:, 0] == aval[idx])
    ylim_exp = math.ceil(math.log10(min(data[:, 1]))) - 1
    ax.set_ylim([10**ylim_exp, None])
    ax.plot(aval[idx], data[aidx, 1], 'ro', label='Anchor point')
    ax.legend(loc=0)
    #f = mticker.ScalarFormatter(useOffset=False, useMathText=True)
    #g = lambda x,pos : "${}$".format(f._formatSciNotation('%1.10e' % x))
    #plt.gca().yaxis.set_major_formatter(mticker.FuncFormatter(g))
    #plt.ticklabel_format(axis="y", style="sci", scilimits=(0,0))

    header = tkey[0] + ',' + 'dual_norm'
    mysave(fig, target_dir, data, 'dual_norm', header, N, fd)
示例#2
0
def temp_mrelerr_wparam(model, N, T0, mode, idx, aval, tkey, tval, fd=None):
    import numpy as np
    import matplotlib.pyplot as plt
    import operator
    from aux.cffdic import cffdic
    from aux.gptr import gptr
    from aux.create_dir import create_dir
    from setup.gtfpath import gtfpath
    from fig_helpers.set_ax import set_ax
    from fig_helpers.set_pltparams import set_pltparams
    from aux.rdatatoarray import rdatatoarray
    from save_helpers.mysave import mysave
    from figsetup.style import style
    from figsetup.text import text

    style(1)
    text()
    T0 = int(T0)

    target_dir = './temp_mrelerr/'
    create_dir(target_dir)

    search_dir = '../' + model + '_info/temp_mrelerr'
    if mode == 'all':
        root, filenames = gtfpath(search_dir, '^.*_' + N + 'nb_.*$')
    else:
        root, filenames = gtfpath(
            search_dir, '^.*_' + N + 'nb_.*_h10_(?!.*-90|.*-80|.*-70).*$')

    ptr = gptr(model, N, T0, mode, fd)
    files_dict = cffdic(filenames, ptr, idx)

    dict_final = sorted(files_dict.items(), key=operator.itemgetter(0))

    data = rdatatoarray(dict_final, 'mrelerr')

    solver = model.upper()
    plot_params1 = set_pltparams('rom_mrelerr', solver, N, T0, fd)
    plot_params2 = set_pltparams('proj_mrelerr', solver, N, T0, fd)

    fig, ax = plt.subplots(1, tight_layout=True)
    set_ax(ax, 'temp_mrelerr', tkey, tval)

    ax.plot(data[:, 0], data[:, 1], **plot_params1)
    ax.plot(data[:, 0], data[:, 2], **plot_params2)

    aidx = np.where(data[:, 0] == aval[idx])
    ax.plot(aval[idx], data[aidx, 1], 'ro', label='Anchor point')

    ax.legend(loc=0, ncol=1)

    header = tkey[0] + ',' + 'rom_mrelerr' + ',' + 'proj_mrelerr'
    mysave(fig, target_dir, data, 'mrelerr', header, N, fd)
示例#3
0
def dual_norm_wN(model, T0, anchor=None, fd=None):
    import numpy as np
    import matplotlib.pyplot as plt
    import sys
    import operator
    sys.path.append('/Users/bigticket0501/Developer/PyMOR/code/plot_helpers/')
    import setup
    import yaml
    from mor import ROM
    from snapshot import Snapshot
    from aux.cffdic import cffdic
    from aux.gptr import gptr
    from aux.create_dir import create_dir
    from aux.sort import sort
    from setup.gtfpath import gtfpath
    from figsetup.style import style
    from figsetup.text import text

    style(1)
    text()
    T0 = int(T0)

    #   print("---------------------------------------------")
    #   print("This is the name of the program:", sys.argv[0])
    #   print("Argument List:", str(sys.argv))
    #   os.chdir(str(sys.argv[1]))
    #   model = str(sys.argv[2])
    #   deg = str(int(sys.argv[3])-90)
    #   print("---------------------------------------------")

    if anchor is None:
        with open('../anchor.yaml') as f:
            features = yaml.load(f, Loader=yaml.FullLoader)
        akey = list(features.keys())
        aval = list(features.values())
        aval = [str(i) for i in aval]
        aval[0] = str(int(aval[0]) - 90)
    al = '_'.join(aval)

    target_dir = './dual_norm/'
    create_dir(target_dir)

    search_dir = '../' + model + '_info/dual_norm'
    root, filenames = gtfpath(search_dir, '^.*_h10_' + al + '_.*$')
    ptr = gptr(model, None, T0, None, fd)
    files_dict = cffdic(filenames, ptr, 0)
    dict_final = sorted(files_dict.items(), key=operator.itemgetter(0))

    roms = []
    for nb, fnames in dict_final:
        for fname in fnames:
            print(fname)
            rom = ROM(fname)
            rom.DTAR()
            rom.anchor('theta')
            print(rom.anchor('theta'))
            roms.append(rom)
    data = sort(roms, 'nb', 'dtar')
    solver = rom.info['method']
    anchor = str(int(rom.info['anchor']))
    print(rom.anchor('anchor'))
    1 / o

    fig, ax = plt.subplots(1, tight_layout=True)
    plot_params = {
        'c': 'k',
        'marker': 'o',
        'mfc': 'None',
        'label': solver + ' with ' + r'$\theta^*_g = ' + anchor + '$'
    }
    ax.set(ylabel=r'$\triangle(\theta_g=' + str(int(deg) + 90) + ')$',
           xlabel=r'$N$',
           ylim=[10**np.floor(np.log10(min(data[:, 1]))), 1],
           xlim=[1, max(data[:, 0])])
    ax.semilogy(data[:, 0], data[:, 1], **plot_params)

    print("---------------------------------------------")
    fig.savefig('.' + target_dir + 'dual_norm_theta_' + str(int(deg) + 90) +
                '.png')
    print("---------------------------------------------")
    plt.show()
    header = tkey[0] + ',' + 'dual_norm'
    np.savetxt('.' + target_dir + 'N_list_' + str(int(deg) + 90) + '.dat',
               data[:, 0])
    np.savetxt('.' + target_dir + 'erri_theta_' + str(int(deg) + 90) + '.dat',
               data[:, 1])
示例#4
0
def nu_1st2nd_momentum_wparam(model,
                              N,
                              T0,
                              mode,
                              idx,
                              aval,
                              tkey,
                              tval,
                              fd=None,
                              iffom=False):
    import numpy as np
    import matplotlib.pyplot as plt
    import operator
    import math
    from aux.cffdic import cffdic
    from aux.gptr import gptr
    from aux.create_dir import create_dir
    from setup.gtfpath import gtfpath
    from fig_helpers.set_ax import set_ax
    from fig_helpers.set_pltparams import set_pltparams
    from aux.rdatatoarray import rdatatoarray
    from fom_qois.fom_qois import fom_qois
    from save_helpers.mysave import mysave
    from figsetup.style import style
    from figsetup.text import text

    style(1)
    text()
    T0 = int(T0)

    target_dir = './nu/'
    create_dir(target_dir)

    search_dir = '../' + model + '_info/nu'
    if mode == 'all':
        root, filenames = gtfpath(search_dir, '^.*_' + N + 'nb_.*$')
    else:
        root, filenames = gtfpath(
            search_dir, '^.*_' + N + 'nb_.*_h10_(?!.*-90|.*-80|.*-70).*$')

    ptr = gptr(model, N, T0, mode, fd)
    files_dict = cffdic(filenames, ptr, idx)

    dict_final = sorted(files_dict.items(), key=operator.itemgetter(0))

    rom_data = rdatatoarray(dict_final, 'nu_1st2nd', T0)
    solver = model.upper()

    if iffom:
        params = [int(i[0]) for i in dict_final]
        fom_data = fom_qois(params, 'nu_1st2nd')

    fig1, ax1 = plt.subplots(1, tight_layout=True)
    set_ax(ax1, 'mnu', tkey, tval)
    plot_params = set_pltparams('nu_1st2nd', solver, N, T0, fd)
    ax1.plot(rom_data[:, 0], rom_data[:, 1], **plot_params)
    if iffom:
        FOM_params = set_pltparams('FOM', solver, N, T0, fd)
        ax1.plot(fom_data[:, 0], fom_data[:, 1], **FOM_params)
    aidx = np.where(rom_data[:, 0] == aval[idx])
    ylim_exp = math.ceil(math.log10(min(rom_data[:, 1]))) - 1
    ax1.set_ylim([10**ylim_exp, None])
    ax1.plot(aval[idx], rom_data[aidx, 1], 'ro', label='Anchor point')
    ax1.legend(loc=1)

    fig2, ax2 = plt.subplots(1, tight_layout=True)
    set_ax(ax2, 'std_nu', tkey, tval)
    plot_params = set_pltparams('nu_1st2nd', solver, N, T0, fd)
    ax2.plot(rom_data[:, 0], rom_data[:, 2], **plot_params)
    if iffom:
        ax2.plot(fom_data[:, 0], fom_data[:, 2], **FOM_params)
    ax2.plot(aval[idx], rom_data[aidx, 2], 'ro', label='Anchor point')
    ax2.legend(loc=1)

    if iffom:
        mnu_relerr = abs(fom_data[:, 1] - rom_data[:, 1]) / abs(fom_data[:, 1])
        stdnu_relerr = abs(fom_data[:, 2] - rom_data[:, 2]) / abs(fom_data[:,
                                                                           2])

        fig3, ax3 = plt.subplots(1, tight_layout=True)
        set_ax(ax3, 'mnurelerr', tkey, tval)
        plot_params = set_pltparams('mnurelerr', solver, N, T0, fd)
        ax3.semilogy(fom_data[:, 0], mnu_relerr, **plot_params)
        aidx = np.where(fom_data[:, 0] == aval[idx])
        ylim_exp = math.ceil(math.log10(min(mnu_relerr))) - 1
        ax3.set_ylim([10**ylim_exp, None])
        ax3.semilogy(aval[idx], mnu_relerr[aidx], 'ro', label='Anchor point')
        ax3.legend(loc=1)

        header = tkey[0] + ',' + 'mnurelerr'
        mysave(fig3, target_dir, np.stack([fom_data[:, 0], mnu_relerr],
                                          axis=-1), 'mnurelerr', header, N, fd)

    header = tkey[0] + ',' + 'mnu'
    mysave(fig1, target_dir, np.stack([rom_data[:, 0], rom_data[:, 1]],
                                      axis=-1), 'mnu', header, N, fd)

    header = tkey[0] + ',' + 'std_nu'
    mysave(fig2, target_dir, np.stack([rom_data[:, 0], rom_data[:, 2]],
                                      axis=-1), 'std_nu', header, N, fd)