def run_all(output_file,
            s,
            N_steps=100,
            n1=50,
            n2=32,
            thmin=0,
            thmax=1,
            **kwargs):
    #def run_all(output_file, s, N_steps = 1, n1 = 50, n2 = 32, **kwargs):
    ## s = sampling rate
    # convergence rate for various theta parameters
    res_IE_1D = get_conv_rates(N_steps=N_steps,
                               s=s,
                               order=1,
                               dim=1,
                               n=n1,
                               init_cond=get_init_cond(1),
                               thmin=thmin,
                               thmax=thmax,
                               **kwargs)
    res_IE_2D = get_conv_rates(N_steps=N_steps,
                               s=s,
                               order=1,
                               dim=2,
                               n=n2,
                               init_cond=get_init_cond(2),
                               thmin=thmin,
                               thmax=thmax,
                               **kwargs)
    res_S2_1D = get_conv_rates(N_steps=N_steps,
                               s=s,
                               order=2,
                               dim=1,
                               n=n1,
                               init_cond=get_init_cond(1),
                               thmin=thmin,
                               thmax=thmax,
                               **kwargs)
    res_S2_2D = get_conv_rates(N_steps=N_steps,
                               s=s,
                               order=2,
                               dim=2,
                               n=n2,
                               init_cond=get_init_cond(2),
                               thmin=thmin,
                               thmax=thmax,
                               **kwargs)

    results = {
        'IE_1D': res_IE_1D,
        'IE_2D': res_IE_2D,
        'S2_1D': res_S2_1D,
        'S2_2D': res_S2_2D
    }
    if res_IE_1D is not None:  # only write on processor 0
        with open(output_file, 'w') as myfile:
            myfile.write(json.dumps(results, indent=2, sort_keys=True))
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_conv_rates(tf, s = 10, n = 199, C1 = 1, C2 = 10, kmax = 6, **kwargs):
    init_cond = get_init_cond(1)
    
    results = {}
    
    prob = get_problem(dim = 1, n = n, **kwargs)
    solver = get_solver(prob, order = 1, WR_type = 'DNWR')
    nn = np.array([2**i for i in range(s)])
    
    results['para']  = [kwargs['alpha_1'], kwargs['alpha_2'], kwargs['lambda_1'], kwargs['lambda_2']]
    results['n'] = n
    results['tf'] = tf
    results['cfl'] = []
    
    theta_min, theta_max, theta_actual, theta_avg = [], [], [], []
    
    dx = 1/(n+1)
    for n in nn:
        dt = tf/n
        results['cfl'].append(dt/(dx**2))
        dt1, dt2 = dt/C1, dt/C2
        th_min = prob.DNWR_theta_opt_test(min(dt1, dt2), min(dt1, dt2))
        
        _, _, _, updates, _ = solver(dt, C1, C2, init_cond, th_min, TOL = 1e-13, maxiter = kmax)
        theta_min.append(updates)
        
        th_max = prob.DNWR_theta_opt_test(max(dt1, dt2), max(dt1, dt2))
        _, _, _, updates, _ = solver(dt, C1, C2, init_cond, th_max, TOL = 1e-13, maxiter = kmax)
        theta_max.append(updates)
        
        th_act = prob.DNWR_theta_opt_test(dt1, dt2)
        _, _, _, updates, _ = solver(dt, C1, C2, init_cond, th_act, TOL = 1e-13, maxiter = kmax)
        theta_actual.append(updates)
        
        th_avg = prob.DNWR_theta_opt_test((dt1 + dt2)/2, (dt1 + dt2)/2)
        _, _, _, updates, _ = solver(dt, C1, C2, init_cond, th_avg, TOL = 1e-13, maxiter = kmax)
        theta_avg.append(updates)
    
    results['min'] = theta_min
    results['max'] = theta_max
    results['actual'] = theta_actual
    results['avg'] = theta_avg
    
    results['parameters'] = kwargs
    return results
Esempio n. 4
0
            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
    verify_mono_time(order = 2, k = 8, **p2) ## SDIRK 2
Esempio n. 5
0
    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,
        'WR_type': 'DNWR',
Esempio n. 6
0
    if self.ID_SELF == 0:
        uD_other = self.comm.recv(source=self.ID_OTHER, tag=self.TAG_DATA)
        return uD, uD_other, g_old[-1], updates, k + 1, timesteps
    else:
        self.comm.send(uD, dest=self.ID_OTHER, tag=self.TAG_DATA)


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_adaptive, visual_verification

    ## mpiexec -n 2 python3 NNWR_SDIRK2_TA.py

    p_base = get_parameters('test')  ## basic testing parameters
    init_cond_1d = get_init_cond(1)
    init_cond_2d = get_init_cond(2)
    save = 'verify/NNWR/TA/'

    for order in [-1]:  # single
        p1 = {
            'init_cond': init_cond_1d,
            'n': 50,
            'dim': 1,
            'order': order,
            'WR_type': 'NNWR',
            **p_base
        }
        p2 = {
            'init_cond': init_cond_2d,
            'n': 32,
Esempio n. 7
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))
def run_combined(tf=1,
                 k1=10,
                 k2=10,
                 TOL=1e-13,
                 n1=100,
                 n2=50,
                 C1=1,
                 C2=1,
                 savefile=None,
                 **kwargs):
    res_1d_IE = verify_comb_error(get_init_cond(1),
                                  tf,
                                  k1,
                                  C1=C1,
                                  C2=C2,
                                  order=1,
                                  TOL=TOL,
                                  dim=1,
                                  n=n1,
                                  **kwargs)
    res_1d_SD2 = verify_comb_error(get_init_cond(1),
                                   tf,
                                   k1,
                                   C1=C1,
                                   C2=C2,
                                   order=2,
                                   TOL=TOL,
                                   dim=1,
                                   n=n1,
                                   **kwargs)

    res_2d_IE = verify_comb_error(get_init_cond(2),
                                  tf,
                                  k2,
                                  C1=C1,
                                  C2=C2,
                                  order=1,
                                  TOL=TOL,
                                  dim=2,
                                  n=n2,
                                  **kwargs)
    res_2d_SD2 = verify_comb_error(get_init_cond(2),
                                   tf,
                                   k2,
                                   C1=C1,
                                   C2=C2,
                                   order=2,
                                   TOL=TOL,
                                   dim=2,
                                   n=n2,
                                   **kwargs)

    results = {
        'IE_1D': res_1d_IE,
        'S2_1D': res_1d_SD2,
        'IE_2D': res_2d_IE,
        'S2_2D': res_2d_SD2,
        'tf': tf,
        'n_1D': n1,
        'n_2d': n2,
        'C1': C1,
        'C2': C2
    }
    if res_1d_IE is not None:  # only write on processor 0
        with open(savefile, 'w') as myfile:
            myfile.write(json.dumps(results, indent=2, sort_keys=True))