File:GaussianUpwind2D.gif

From testwiki
Jump to navigation Jump to search
    Original file (800 × 600 pixels, file size: 972 KB, MIME type: image/gif, looped, 24 frames)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Upwind scheme for advection equation with solenoidal u = (sin(t), cos(t)) and boundary condition Z(x, y, t) = exp(- (x - (1 - cos(t)))2 - (y - sin(t))2).
    Date
    Source Own work
    Author Shiyu Ji

    Python/Matplotlib Code

    # A numerical solution of 2D Gaussian advection equation by Upwind Scheme.
    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as pl
    import numpy as np
    
    t0 = 0.0
    dt = 0.045
    t_final = 1
    x0 = -2.0
    dx = 0.04
    x_max = 4.0
    y0 = -2.0
    dy = 0.04
    y_max = 4.0
    T = np.arange(t0, t_final+dt, dt)
    X = np.arange(x0, x_max+dx, dx)
    Y = np.arange(y0, y_max+dy, dy)
    U = [[0.0 for _ in Y] for _ in X]
    fig = pl.figure()
    ax = fig.add_subplot(111, projection='3d')
    nframe = 0
    
    for t in T:
        if t == t0:
            for i in range(len(X)):
                for j in range(len(Y)):
                    U[i][j] = np.exp(-X[i]**2-Y[j]**2)
        else:
            U_prime = [[0.0 for _ in Y] for _ in X]
            for i in range(len(X)):
                for j in range(len(Y)):
                    if i == 0 or j == 0 or i == len(X)-1 or j == len(Y)-1:
                        U_prime[i][j] = np.exp(-(X[i]-(1-np.cos(t)))**2-(Y[j]-np.sin(t))**2)
                    else:
                        ux = np.sin(t)
                        uy = np.cos(t)
                        if ux > 0 and uy > 0:
                            U_prime[i][j] = U[i][j] - ux*dt/dx*(U[i][j] - U[i-1][j]) - uy*dt/dy*(U[i][j] - U[i][j-1])
                        elif ux > 0 and uy <= 0:
                            U_prime[i][j] = U[i][j] - ux*dt/dx*(U[i][j] - U[i-1][j]) - uy*dt/dy*(U[i][j+1] - U[i][j])
                        elif ux <= 0 and uy > 0:
                            U_prime[i][j] = U[i][j] - ux*dt/dx*(U[i+1][j] - U[i][j]) - uy*dt/dy*(U[i][j] - U[i][j-1])
                        else:
                            U_prime[i][j] = U[i][j] - ux*dt/dx*(U[i+1][j] - U[i][j]) - uy*dt/dy*(U[i][j+1] - U[i][j])
            U = U_prime
            
        ax.clear()
        gridX, gridY = np.meshgrid(X, Y)
        ax.plot_surface(gridX, gridY, U, cmap = 'summer', lw = 0.0)
        ax.set_xlabel('x')
        ax.set_ylabel('y')
        ax.set_zlabel('phi')
        ax.set_xlim([x0, x_max])
        ax.set_ylim([y0, y_max])
        ax.set_zlim([0, 1])
        fig.savefig('upwind2d/frame_'+"%03d" % nframe+'.png')
        nframe += 1
    
    # To generate GIF: convert frame_* GaussianUpwind2D.gif
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    w:en:Creative Commons
    attribution share alike
    This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
    You are free:
    • to share – to copy, distribute and transmit the work
    • to remix – to adapt the work
    Under the following conditions:
    • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    26 November 2016

    994,854 byte

    600 pixel

    800 pixel

    image/gif

    40caea098472f38175cb0e7284f56e6c1681650c

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current07:20, 27 November 2016Thumbnail for version as of 07:20, 27 November 2016800 × 600 (972 KB)wikimediacommons>Shiyu JiUser created page with UploadWizard

    There are no pages that use this file.