def run_combined(k=8, n=32, dim=1, savefile=None, **kwargs):
    init_cond = get_init_cond(dim)
    res_air_steel = verify_adaptive(init_cond,
                                    1e4,
                                    k,
                                    n=n,
                                    dim=dim,
                                    **get_parameters('air_steel'))
    res_air_water = verify_adaptive(init_cond,
                                    1e4,
                                    k,
                                    n=n,
                                    dim=dim,
                                    **get_parameters('air_water'))
    res_water_steel = verify_adaptive(init_cond,
                                      1e4,
                                      k,
                                      n=n,
                                      dim=dim,
                                      **get_parameters('water_steel'))

    results = {
        'air_steel': res_air_steel,
        'air_water': res_air_water,
        'water_steel': res_water_steel,
        'n': n,
        'dim': dim
    }
    with open(savefile, 'w') as myfile:
        myfile.write(json.dumps(results, indent=2, sort_keys=True))
def get_opt_theta(n, T, steps_range, which, label = 'label'):
    parameters = get_parameters(which)
    prob = Problem_FSI_1D(n = n, **parameters)
    dx = prob.dx
    
    N_steps = np.array([int(2**i) for i in np.linspace(0, 50, 1000)])
    dts = T/N_steps
    
    CFL = [dt/(dx**2) for dt in dts]
    theta = [prob.DNWR_theta_opt(dt, dt) for dt in dts]
    lim_zero = parameters['alpha_2']/(parameters['alpha_1'] + parameters['alpha_2'])
    lim_inf = parameters['lambda_2']/(parameters['lambda_1'] + parameters['lambda_2'])
    
    pl.figure()
    pl.semilogx(CFL, theta, label = label)
    pl.axhline(lim_zero, ls = '--', color = 'k', label = r'$\theta_{c \rightarrow 0}$')
    pl.axhline(lim_inf, ls = ':', color = 'k', label = r'$\theta_{c \rightarrow \infty}$')
    pl.legend()
    pl.xlabel('c', labelpad = -30, position = (1.05, -1), fontsize = 20)
    lp = -50 if label == 'Air-Steel' else -20
    pl.ylabel(r'$\theta_{opt}$', rotation = 0, labelpad = lp, position = (2., 1.), fontsize = 20)
    pl.title(label)
    pl.savefig('plots/CFL_vs_opt_theta_{}.png'.format(which), dpi = 100)
    
    return 
示例#3
0
        for i in range(N):
            uold = unew
            w = self.linear_solver(self.M + self.a*dt*self.A, self.M.dot(uold))
            unew = self.linear_solver(self.M + self.a*dt*self.A, self.M.dot(uold) - dt*(1-self.a)*self.A.dot(w))
        ## slicing to get solutions for the suitable domains/interface
        u1 = unew[:self.n_int_1]
        u2 = unew[self.n_int_1:self.n_int_1 + self.n_int_2]
        ug = unew[-self.ny:]
        flux = self.get_flux(dt, u1, uold[:self.n_int_1], ug, uold[-self.ny:])
        return u1, u2, ug, flux
    
if __name__ == '__main__':
    from FSI_verification import get_parameters, get_init_cond
    from FSI_verification import verify_mono_time, visual_verification, verify_space_error
    
    p_base = get_parameters('test') ## basic testing parameters
    init_cond_1d = get_init_cond(1)
    init_cond_2d = get_init_cond(2)
    a, lam = 1., 0.1
    
    ################# Verification of time-integration of monolithic solution
    ## 1D
    p1 = {'init_cond': init_cond_1d, 'n': 50, 'dim': 1, 'tf': 1,
          'savefig': 'verify/base/', **p_base}
    verify_mono_time(order = 1, k = 12, **p1) ## IE
    verify_mono_time(order = 2, k = 12, **p1) ## SDIRK 2
    visual_verification(order = 1, **p1)
    ## 2D
    p2 = {'init_cond': init_cond_2d, 'n': 32, 'dim': 2, 'tf': 1,
          'savefig': 'verify/base/', **p_base}
    verify_mono_time(order = 1, k = 10, **p2) ## IE
示例#4
0
    s2 = s1 + dt * (1 - self.a) * k1  # stage 2
    b = self.Neumann_M.dot(s2)
    b[-n:] -= dta * flux2(t + dt)
    U2 = self.linear_solver(self.Neumann_M + dta * self.Neumann_A, b)
    k2 = (U2 - s2) / dta

    localu = dt * ((self.a - self.ahat) * k2 + (self.ahat - self.a) * k1)
    return U2[:-n], U1[-n:], U2[-n:], localu


if __name__ == '__main__':
    from FSI_verification import get_problem, get_solver, solve_monolithic
    from FSI_verification import get_parameters, get_init_cond
    from FSI_verification import verify_with_monolithic, verify_comb_error, verify_splitting_error, verify_test, verify_MR_comb

    p_base = get_parameters('test')  ## basic testing parameters
    init_cond_1d = get_init_cond(1)
    init_cond_2d = get_init_cond(2)
    p1 = {
        'init_cond': init_cond_1d,
        'n': 50,
        'dim': 1,
        'order': 22,
        'WR_type': 'DNWR',
        **p_base
    }
    p2 = {
        'init_cond': init_cond_2d,
        'n': 32,
        'dim': 2,
        'order': 22,
示例#5
0
        ## interface assumed to be at x = 0 
        n = self.n
        x1 = np.linspace(-self.len_1, 0, (self.n + 1)*self.len_1 + 1)
        x2 = np.linspace(0, self.len_2, (self.n + 1)*self.len_2 + 1)
        y = np.linspace(0, 1, self.n + 2)
        
        u1, u2, ug = np.zeros(self.n_int_1), np.zeros(self.n_int_2), np.zeros(n)
        for i in range(n): ug[i] = init_cond(0., y[i+1])
        for i in range(n):
            for j, x in enumerate(x1[1:-1]):
                u1[j*n + i] = init_cond(x, y[i+1])
            for j, x in enumerate(x2[1:-1]):
                u2[j*n + i] = init_cond(x, y[i+1])
        return u1, u2, ug
    
if __name__ == '__main__':
    from FSI_verification import get_parameters
    ## discrete L2 norm test
    pp = get_parameters('test')
    n_list = [2**i for i in range(6)]
    discr, mass = [], []
    for n in n_list:
        prob = Problem_FSI_2D(n, **pp, len_1 = 3, len_2 = 4, WR_type = 'DNWR')
        u0_f = lambda x, y: 500
        
        u1, u2, ug = prob.get_initial_values(u0_f)
        uu = np.hstack((u1, u2, ug))
        print(prob.norm_interface(ug),
              prob.norm_inner(u1, 'D'),
              prob.norm_inner(np.hstack([u2, ug]), 'N'),
              prob.norm_inner(u1, u2, ug))
示例#6
0
    pl.figure()
    for res, label, marker, ls in [(results['IE_1D'], 'IE 1D', None, '-'), (results['IE_2D'], 'IE 2D', None, '-'), 
                               (results['S2_1D'], 'SD2 1D', 'o', ''), (results['S2_2D'], 'SD2 2D', '*', '')]:
        conv_rates = []
        for updates in res['updates']:
            x = np.array(updates[:-1])
            conv_rates.append(np.mean(x[1:]/x[:-1]))
        pl.semilogy(res['theta'], conv_rates, label = label, marker = marker, linestyle = ls)
    pl.semilogy(thetas, conv_rates_theo, label = r'$\Sigma(\Theta)$', ls = '--', linewidth  = 3)
    pl.axvline(res_IE_1D['theta_opt'], ls = '-', color = 'k', label = r'$\Theta_{opt}$')
    a, b = res_IE_1D['theta_CFL_inf'], res_IE_1D['theta_CFL_zero']
    pl.xlim(res_IE_1D['theta_start'], res_IE_1D['theta_stop'])
    pl.ylim(1e-7, 2)
    pl.fill_between([min(a,b), max(a,b)], [min(pl.ylim())/100]*2, [max(pl.ylim())*100]*2, alpha = 0.2)
    
    pl.xlabel(r'$\Theta$', labelpad = -20, position = (1.08, -1), fontsize = 20)
    lp = -50 if label == 'Air-Steel' else -70
    pl.ylabel('Conv. rate', rotation = 0, labelpad = lp, position = (2., 1.05), fontsize = 20)
    pl.legend(loc = 3)
    pl.savefig(savefile, dpi = 100)
    
if __name__ == "__main__":
    kmax = 6
#    for tf, which, C1, C2, thmin, thmax in [(1e4, 'air_water', 1, 1, 0.9, 1)]:
#    for tf, which, C1, C2, thmin, thmax in [(1e4, 'air_steel', 1, 1, 0.9992, 0.9999)]:
    for tf, which, C1, C2, thmin, thmax in [(1e4, 'water_steel', 1, 1, 0.2, 1)]:
        tf = int(tf)
        file = f'plots_data/theta_opt_test_non_square_{which}_{C1}_{C2}_{tf}.txt'
        run_all(file, **get_parameters(which), tf = tf, n1 = 199, n2 = 5, s = 30, C1 = C1, C2 = C2, thmin = thmin, thmax = thmax)
#        run_all(file, **get_parameters(which), tf = tf, n1 = 9, n2 = 9, s = 10, C1 = C1, C2 = C2, thmin = thmin, thmax = thmax)
        plotting(file, f'plots/theta_opt_test_non_square_{which}_{C1}_{C2}_{tf}.png')
    pl.ylabel('Conv. rate',
              rotation=0,
              labelpad=lp,
              position=(2., 1.05),
              fontsize=20)
    pl.legend(loc=4)  # lower right
    pl.savefig(savefile, dpi=100)


if __name__ == "__main__":
    ## mpiexec -n 2 python3 paper_plots_NNWR_theta_opt_test.py
    kmax = 6
    for tf, which, C1, C2, thmin, thmax in [(1e4, 'air_water', 10, 1, 0, 0.06),
                                            (1e4, 'air_steel', 1, 1, 0,
                                             0.0008),
                                            (1e4, 'water_steel', 1, 10, 0, 0.3)
                                            ]:
        tf = int(tf)
        file = f'plots_data/NNWR_theta_opt_test_{which}_{C1}_{C2}_{tf}.txt'
        #        run_all(file, **get_parameters(which), tf = tf, n1 = 9, n2 = 9, s = 30, C1 = C1, C2 = C2, thmin = thmin, thmax = thmax)
        run_all(file,
                **get_parameters(which),
                tf=tf,
                n1=199,
                n2=99,
                s=30,
                C1=C1,
                C2=C2,
                thmin=thmin,
                thmax=thmax)
        plotting(file, f'plots/NNWR_theta_opt_test_{which}_{C1}_{C2}_{tf}.png')
        myfile.write(json.dumps(results, indent = 2, sort_keys = True))
        
def plotting(input_file, savefile):
    with open(input_file, 'r') as myfile:
        results = json.load(myfile)
    
    pl.figure()
    for up, label, marker in [(results['min'], 'Min', 'o'), (results['max'], 'Max', '*'), 
                               (results['actual'], 'Mix', '^'), (results['avg'], 'Avg', '+')]:
        conv_rates = []
        for updates in up:
            x = np.array(updates[:-1])
            conv_rates.append(np.mean(x[1:]/x[:-1]))
        pl.loglog(results['cfl'], conv_rates, label = label, marker = marker)
        
    pl.xlabel('C', labelpad = -20, position = (1.08, -1), fontsize = 20)
    lp = -50 if label == 'Air-Steel' else -70
    pl.ylabel('Conv. rate', rotation = 0, labelpad = lp, position = (2., 1.05), fontsize = 20)
    pl.ylim(1e-8, 2) ## manually setting limits
    pl.grid(True, 'major')
    pl.legend()
    pl.savefig(savefile, dpi = 100)
    
if __name__ == "__main__":
    kmax = 6
    for C1, C2 in [(1, 10), (10, 1)]:
        for tf, which in [(1e4, 'air_water'), (1e4, 'air_steel'), (1e4, 'water_steel')]:
            tf = int(tf)
            file = f'plots_data/MR_theta_opt_test_{which}_{C1}_{C2}_{tf}.txt'
            run_all(file, **get_parameters(which), tf = tf, s = 40, n = 199, C1 = C1, C2 = C2)
            plotting(file, f'plots/MR_theta_opt_test_{which}_{C1}_{C2}_{tf}.png')
示例#9
0
            marker='o')
    pl.plot(results['iters_adaptive'],
            label='adaptive',
            linestyle='-',
            marker='*')
    pl.ylabel('Iters',
              rotation=0,
              labelpad=-30,
              position=(2., 1.0),
              fontsize=20)
    pl.legend()
    pl.savefig(savefile[:-4] + '_iters.png', dpi=100)


if __name__ == '__main__':
    n, k_mr, k_adap = 99, 6, 6
    for i in [1, 2]:
        #        for tf, which in [(1e4, 'air_water')]:
        #        for tf, which in [(1e4, 'air_steel')]:
        for tf, which in [(1e4, 'water_steel')]:
            para = get_parameters(which)
            D1 = para['lambda_1'] / para['alpha_1']
            D2 = para['lambda_2'] / para['alpha_2']

            C1 = max(1, int(D1 / D2))
            C2 = max(1, int(D2 / D1))
            print(i, tf, which, C1, C2)
            out_file = 'plots_data/err_work_u0_{}_{}.txt'.format(i, which)
            get_err_work(out_file, get_init_cond(2, num=i), tf, C1, C2, n,
                         k_mr, k_adap, **get_parameters(which))
            plotting(out_file, 'plots/err_work_u0_{}_{}.png'.format(i, which))