Ejemplo n.º 1
0
def refine_validate(sigma=5, beta=1, b=0, t0=0.5, h=0.1, tau=pow(0.1, 2) / 2):
    grid1 = twoddir(h=(tau, h), rx=((0, 0.2), (-4, 4)))
    grid1.set_active_int_plus_top()
    grid1.set_bc(hom.barenblatt(grid1, t0, sigma))
    soln1 = diffusion(grid1, b, beta, sigma)
    soln1.calculate()
    diff1 = trivgrid(
        array([[
            hom._barenblatt(t0 + t, x + b * t, grid1.u.ndim - 1, sigma)
            for x in grid1.x[1]
        ] for t in grid1.x[0]]) - soln1.g.u)
    print(
        'sigma: {:f}, beta: {:f}, b: {:f}, h1: {:f}, tau1: {:f}, L_2 Error: {:f}, L_inf Error: {:f}\n'
        .format(sigma, beta, b, h, tau, diff1.l2_norm(), diff1.max_norm()))
    grid2 = twoddir(h=(tau / 2, h / 2), rx=((0, 0.2), (-4, 4)))
    grid2.set_active_int_plus_top()
    grid2.set_bc(hom.barenblatt(grid2, t0, sigma))
    soln2 = diffusion(grid2, b, beta, sigma)
    soln2.calculate()
    diff2 = trivgrid(
        array([[
            hom._barenblatt(t0 + t, x + b * t, grid2.u.ndim - 1, sigma)
            for x in grid2.x[1]
        ] for t in grid2.x[0]]))
    print(
        'sigma: {:f}, beta: {:f}, b: {:f}, h2: {:f}, tau2: {:f}, L_2 Error: {:f}, L_inf Error: {:f}\n'
        .format(sigma, beta, b, h / 2, tau / 2, diff2.l2_norm(),
                diff2.max_norm()))
Ejemplo n.º 2
0
def test_twodir_set_xprod():
    grid = uniform.twoddir((0.01, 0.1), ((0, 1), (0, 1)))
    l = map(
        tuple,
        numpy.transpose(numpy.indices(grid.u.shape)).reshape(
            (numpy.prod(grid.nx), 2)))
    for i in l:
        grid.u[i] = numpy.prod(grid.ind_to_x(i))
    assert True
Ejemplo n.º 3
0
def test_twodir_set_linorder():
    grid = uniform.twoddir((0.01, 0.1), ((0, 1), (0, 1)))
    l = map(
        tuple,
        numpy.transpose(numpy.indices(grid.u.shape)).reshape(
            (numpy.prod(grid.nx), 2)))
    j = 0
    for i in l:
        grid.u[i] = j
        j = j + 1
    assert True
Ejemplo n.º 4
0
def test_ft():
	gamma = 1
	sigma = 2
	beta = 1
	b = -5
	grid = twoddir((0.0005, 0.1), ((0, 0.01), (-2, 2)))
	grid.set_active_int_plus_top()
	grid.set_bc(hom.dd_xpowalpha(grid, gamma, cutoff=True))
	def ffn(x, t, u, ux, uxx):
	   return sigma * pow(u, sigma - 1) * uxx + (sigma * (sigma - 1) * pow(u, sigma - 2) + b * beta * pow(u, beta - 1)) * ux
# 	soln = ft(grid, ffn)
# 	soln.calculate()
	assert True
	
	sp2 = tr(grid, 0.1)
	assert True
Ejemplo n.º 5
0
def output_validate(dir_out,
                    sigma=5,
                    beta=1,
                    b=0,
                    t0=0.5,
                    h=0.1,
                    tau=pow(0.1, 2) / 2):
    dir_with_data = path.join(dir_out, 'sigma=' + str(sigma),
                              'beta=' + str(beta))
    if not path.isdir(dir_with_data):
        os.makedirs(dir_with_data)
    gridp = twoddir(h=(tau, h), rx=((0, 0.2), (-4, 4)))
    gridp.set_active_int_plus_top()
    gridp.set_bc(hom.barenblatt(gridp, t0, sigma))
    soln = diffusion(gridp, b, beta, sigma)
    soln.calculate()
    grcomp = trivgrid(
        array([[
            hom._barenblatt(t0 + i, j + b * i, gridp.u.ndim - 1, sigma)
            for j in gridp.x[1]
        ] for i in gridp.x[0]]))
    savetxt(path.join(dir_with_data, 'xv.dat'),
            gridp.x[1],
            delimiter=',',
            fmt='%10.5f')
    savetxt(path.join(dir_with_data, 'tv.dat'),
            gridp.x[0],
            delimiter=',',
            fmt='%10.5f')
    savetxt(path.join(dir_with_data, 'u_approx.dat'),
            soln.g.u,
            delimiter=',',
            fmt='%10.5f')
    savetxt(path.join(dir_with_data, 'u_exact.dat'),
            grcomp.u,
            delimiter=',',
            fmt='%10.5f')
    savetxt(path.join(dir_with_data, 'u_diff.dat'),
            grcomp.u - soln.g.u,
            delimiter=',',
            fmt='%10.5f')
Ejemplo n.º 6
0
def do_sweep(basedir, sigma, nbeta, ngamma, dx = 1e-2, dt = 4e-3):
	dirWithRun = path.join(basedir, 'run'+str(sigma))
	if not path.isdir(dirWithRun):
		os.makedirs(dirWithRun)
	b = 0.01
	threshold1 = 1e-1
	threshold2 = 1e-2
	with open(path.join(dirWithRun, 'results.dat'), 'w') as f:
		f.write('sigma,b,beta,gamma,diff_' + str(threshold1) + ',diff_' + str(threshold2) + '\n')
		for beta in linspace(0,1,nbeta):
			for gamma in linspace(0.9,1.8,ngamma):
				grid = twoddir(h=(dt, dx), rx = [(0, 0.01), (-2, 2)])
				for (j, xj) in enumerate(grid.x[1]):
					grid.u[0, j] = hom._negxpowalpha(xj, gamma)
				
				soln = diffusion(grid,b,beta,sigma)
				
				gridout = soln.calculate()
				sp2 = tr(soln.g, threshold1)
				sp3 = tr(soln.g, threshold2)
				f.write(str(sigma) + "," + str(b) + "," + str(beta) + "," + str(gamma) + "," + str(sp2.rex[-1] - sp2.rex[0]) + "," + str(sp3.rex[-1] - sp3.rex[0]) + "\n")
Ejemplo n.º 7
0
def test_twodir_barenblatt():
    grid = uniform.twoddir((0.0005, 0.1), ((0, 0.01), (-2, 2)))
    grid.set_active_int_plus_top()
    grid.set_bc(hom.barenblatt(grid, 1, 2))
Ejemplo n.º 8
0
def test_twodir_xpowalpha():
    grid = uniform.twoddir((0.005, 0.1), ((0, 1), (0, 1)))
    grid.set_active_int_plus_top()
    grid.set_bc(hom.dd_xpowalpha(grid, 1.0 / 3, cutoff=True))
    assert True