Exemplo n.º 1
0
def run_Gaussian(plot_method=1, version='vectorized'):
    """
    Initial Gaussian bell in the middle of the domain.
    plot_method=1 makes a movie of the output with mayavi, =0 means no plot.
    """
    # Clean up plot files
    for name in glob('tmp_*.png'):
        os.remove(name)

    Lx = 10
    Ly = 10
    def c(x,y): 
        s = (np.size(x),np.size(y))
        c = np.zeros(s)
        c = c + 1
        return c

    def I(x, y):
        """Gaussian peak at (Lx/2, Ly/2)."""
        return 3*exp(-0.5*(x-Lx/2.0)**2 - 0.5*(y-Ly/2.0)**2)

    Nx = 40; Ny = 40; T = 20
    dt,time = solver(I, None, None, c, 0.0, Lx, Ly, Nx, Ny, 0, T, version=version)
    print dt
    if plot_method == 1:
    	mvname = 'test'
    	from mcrtmv import mcrtmv
    	N = int(round(T/float(dt)))
    	mcrtmv(N, dt,Lx,Ly,Nx,Ny, savemovie=False, mvname=mvname)
Exemplo n.º 2
0
def test_1Dsolution():
	Lx = 10
	Ly = 10
	def c(x,y): 
		s = (np.size(x),np.size(y))
		c = np.zeros(s)
		c = c + 1
		return c

	def I(x, y):
		"""Tests the plug wave solution, should be reproduced the exact solution!"""
		return np.logical_and((np.abs(x) < Lx/2.+1), (np.abs(x) > Lx/2.-1))*1.
	Nx = 40; Ny = 40; T = 21.

	x = np.linspace(0, Lx, Nx+1)  # mesh points in x dir
	y = np.linspace(0, Ly, Ny+1)  # mesh points in y dir
	dx = x[1] - x[0]
	dy = y[1] - y[0]
	dt = dx
	X,Y = np.meshgrid(x,y)
	u_exact = I(X,Y)
	for version in ['scalar','vectorized']:
		dt,time, T = bw.solver(I, None, None, c, 0.0, Lx, Ly, Nx, Ny, dt, T, version=version)
		n = int(T/dt - 5)
		fname = 'solution_%06d.txt' % n
		u = np.loadtxt(fname)
		diff = np.abs(u_exact - u[:,0]).max()
		mcrtmv(n, dt,Lx,Ly,Nx,Ny,savemovie=True, mvname=version)
Exemplo n.º 3
0
def test_1Dsolution():
    Lx = 10
    Ly = 10

    def c(x, y):
        s = (np.size(x), np.size(y))
        c = np.zeros(s)
        c = c + 1
        return c

    def I(x, y):
        """Tests the plug wave solution, should be reproduced the exact solution!"""
        return np.logical_and((np.abs(x) < Lx / 2. + 1),
                              (np.abs(x) > Lx / 2. - 1)) * 1.

    Nx = 40
    Ny = 40
    T = 21.

    x = np.linspace(0, Lx, Nx + 1)  # mesh points in x dir
    y = np.linspace(0, Ly, Ny + 1)  # mesh points in y dir
    dx = x[1] - x[0]
    dy = y[1] - y[0]
    dt = dx
    X, Y = np.meshgrid(x, y)
    u_exact = I(X, Y)
    for version in ['scalar', 'vectorized']:
        dt, time, T = bw.solver(I,
                                None,
                                None,
                                c,
                                0.0,
                                Lx,
                                Ly,
                                Nx,
                                Ny,
                                dt,
                                T,
                                version=version)
        n = int(T / dt - 5)
        fname = 'solution_%06d.txt' % n
        u = np.loadtxt(fname)
        diff = np.abs(u_exact - u[:, 0]).max()
        mcrtmv(n, dt, Lx, Ly, Nx, Ny, savemovie=True, mvname=version)
Exemplo n.º 4
0
def run_Gaussian(plot_method=1, version='vectorized'):
    """
    Initial Gaussian bell in the middle of the domain.
    plot_method=1 makes a movie of the output with mayavi, =0 means no plot.
    """
    # Clean up plot files
    for name in glob('tmp_*.png'):
        os.remove(name)

    Lx = 10
    Ly = 10

    def c(x, y):
        s = (np.size(x), np.size(y))
        c = np.zeros(s)
        c = c + 1
        return c

    def I(x, y):
        """Gaussian peak at (Lx/2, Ly/2)."""
        return 3 * exp(-0.5 * (x - Lx / 2.0)**2 - 0.5 * (y - Ly / 2.0)**2)

    Nx = 40
    Ny = 40
    T = 20
    dt, time = solver(I,
                      None,
                      None,
                      c,
                      0.0,
                      Lx,
                      Ly,
                      Nx,
                      Ny,
                      0,
                      T,
                      version=version)
    print dt
    if plot_method == 1:
        mvname = 'test'
        from mcrtmv import mcrtmv
        N = int(round(T / float(dt)))
        mcrtmv(N, dt, Lx, Ly, Nx, Ny, savemovie=False, mvname=mvname)