Example #1
0
def main():
    Parameters = []
    Parameters.append(float(
        sys.argv[1]))  #I - Percentage Probable (PP) Infectivity
    Parameters.append(int(sys.argv[2]))  #InfP - Mean (M) Infectious Period
    Parameters.append(float(sys.argv[3]))  #Mob - PP Mobility
    Parameters.append(int(sys.argv[4]))  #IncP - M Incubation Period
    Parameters.append(float(sys.argv[5]))  #Mor - PP Mortality
    Parameters.append(float(sys.argv[6]))  #Imn - PP Immunity
    Parameters.append(int(sys.argv[7]))  #RecP - M Recovery Period
    PImmune = 0.0  #Pre-Immune can also be viewed as Population Density

    xDimension = int(sys.argv[8])
    yDimension = int(sys.argv[9])

    tElapsed = int(sys.argv[10])

    move_range = float(sys.argv[11])  #PP of switching places

    PLOT = sys.argv[12]

    I = Parameters[0]  #Percentage
    InfP = range(int(Parameters[1]) - 3, int(Parameters[1]) + 4)
    Mob = Parameters[2]  #Percentage
    IncP = range(int(Parameters[3]) - 3, int(Parameters[3]) + 4)
    Mor = Parameters[4]  #Percentage
    Imn = Parameters[5]  #Percentage
    RecP = range(int(Parameters[6]) - 3, int(Parameters[6]) + 4)

    Population = xDimension * yDimension

    Dossier, Record, Pos2Pat, ID = genesis.genesis(Parameters, xDimension,
                                                   yDimension)
    Trends = genesis.initial()

    for t in range(tElapsed):
        if len(sys.argv) >= 13:
            plot.matrix(Dossier, Population, t)

        for P in range(1, ID + 1):
            status.StatusUpdate(Dossier, Record, Pos2Pat, xDimension,
                                yDimension, P, Mob, I, Imn, Mor)
            flux.flux(xDimension, yDimension, Pos2Pat, Dossier, move_range)
            plot.update(Dossier, Trends, ID, t)
        print Pos2Pat

        Record = copy.deepcopy(Dossier)

    if len(sys.argv) >= 13:
        plot.plotTrend(Trends)
        plot.Print(Dossier, ID, Population)
Example #2
0
def BL_solution(method, T):

    #Here we compute the maximum value of f'(u).
    s = np.linspace(0, 1, 1001)
    dfv = max(np.diff(flux(s)) / np.diff(s))
    df = lambda u: np.zeros(len(u)) + dfv

    # Grid for the analytical solution
    dx = 1 / 2**12
    xr = np.arange(0.5 * dx, 1 + 0.5 * dx, dx)

    # Solutions on coarser grids
    N = 50
    dx = 1 / N

    if method == 'classical':
        # Coarser grid
        x = np.arange(-0.5 * dx, 1 + 1.5 * dx, dx)

        # Discontinuous solution:
        if T == 0.5:
            u0 = np.zeros(len(x))
            u0[x <= 0] = 1

        # Continuous initial:
        elif T == 1:
            u0 = np.ones(len(x)) * analytical(1, T)
            u0[x <= 0] = 1.0

        # Compute solutions with the three classical schemes
        uu = upw(u0, 0.995, dx, T, flux, df, inflow)
        uf = lxf(u0, 0.995, dx, T, flux, df, inflow)
        uw = lxw(u0, 0.995, dx, T, flux, df, inflow)

        # Plot results
        plt.figure()
        plt.plot([1, 2, 3])
        plt.subplot(131)
        # Analytical solution:
        plt.plot(xr, analytical(xr, T), color='red')
        plt.plot(
            x[1:-1], uu[1:-1], '.', markersize=3
        )  # We dont want to plot fictitious nodes, thereby the command [1:-1].
        plt.title("Upwind")
        plt.subplot(132)
        # Analytical solution:
        plt.plot(xr, analytical(xr, T), color='red')
        plt.plot(x[1:-1], uf[1:-1], '.', markersize=3)
        plt.title("Lax-Friedrichs")
        plt.subplot(133)
        # Analytical solution:
        plt.plot(xr, analytical(xr, T), color='red')
        plt.plot(x[1:-1], uw[1:-1], '.', markersize=3)
        plt.title("Lax-Wendroff")
        # The following commented out section saves the plots
        """
        if T == 1:
            plt.savefig("solution_classical_cont.pdf")
        elif T == 0.5:
            plt.savefig("solution_classical_discont.pdf")
        """

    elif method == 'high':
        # Coarser grid, need two fictitious nodes at each end for this scheme.
        xh = np.arange(-1.5 * dx, 1 + 2.5 * dx, dx)

        # Discontinuous solution:
        if T == 0.5:
            u0 = np.zeros(len(xh))
            u0[xh <= 0] = 1.0

        # Continuous initial:
        elif T == 1:
            u0 = np.ones(len(xh)) * analytical(1, T)
            u0[xh <= 0] = 1.0

        ug, phi = god(u0, 0.495, dx, T, flux, df, inflow)

        #Plot results
        plt.figure()
        # Analytical solution:
        plt.plot(xr, analytical(xr, T), color='red')
        plt.plot(xh[2:-2], ug[2:-2], '.', markersize=3)
        plt.title("Godunov")
        # The following commented out section saves the plots
        """
Example #3
0
def Error_verification(T, norm):

    # Derivative of flux for BL:
    s = np.linspace(0, 1, 1001)
    dfv = max(np.diff(flux(s)) / np.diff(s))
    df = lambda u: np.zeros(len(u)) + dfv

    # Grid for analytical solution:
    dx = 1 / 2**12
    xr = np.arange(0.5 * dx, 1 + 0.5 * dx, dx)

    # The analytical solution, which we will find the error relative to.
    uref = analytical(xr, T)

    # Solutions on coarser grids
    N = np.array([2**i for i in range(3, 11)])

    # Initiate vectors to store errors
    error_upw = np.zeros(len(N))
    error_lxf = np.zeros(len(N))
    error_lxw = np.zeros(len(N))
    error_god = np.zeros(len(N))
    j = 0
    for n in N:
        dX = 1 / n
        # Coarser grids for classical schemes and Godunov scheme.
        x = np.arange(-0.5 * dX, 1 + 1.5 * dX, dX)
        xg = np.arange(-1.5 * dX, 1 + 2.5 * dX, dX)

        # Discontinuous solution:
        if T == 0.5:
            u0 = np.zeros(len(x))
            u0_g = np.zeros(len(xg))
            u0[x <= 0] = 1.0
            u0_g[xg <= 0] = 1.0

        # Continuous initial:
        elif T == 1:
            u0 = np.ones(len(x)) * analytical(1, T)
            u0_g = np.ones(len(xg)) * analytical(1, T)
            u0[x <= 0] = 1.0
            u0_g[xg <= 0] = 1.0

        # Compute solutions, and then omit the fictitious nodes.
        uu = upw(u0, 0.995, dX, T, flux, df, inflow)
        uu = uu[1:-1]
        uf = lxf(u0, 0.995, dX, T, flux, df, inflow)
        uf = uf[1:-1]
        uw = lxw(u0, 0.995, dX, T, flux, df, inflow)
        uw = uw[1:-1]
        ug, phi = god(u0_g, 0.495, dX, T, flux, df, inflow)
        ug = ug[2:-2]
        phi = phi[2:-2]

        # Now create a constant reconstruction to compute error for the three
        # classical schemes.
        uu_c = [i for i in uu for j in range(int(dX / dx))]
        uf_c = [i for i in uf for j in range(int(dX / dx))]
        uw_c = [i for i in uw for j in range(int(dX / dx))]
        # To compute the numerical error in the central upwind scheme, we need
        # to create a piecewise continuous linear reconstruction of the solution.
        # To do this, we use the vector phi and then create the reconstruction.
        ug_c = [
            ug[i] + 0.5 *
            (((2 * j + 1) - int(dX / dx))) / int(dX / dx) * phi[i]
            for i in range(len(ug)) for j in range(int(dX / dx))
        ]
        error_upw[j] = np.power(dx, 1 / norm) * np.linalg.norm(
            uu_c - uref, norm)
        error_lxf[j] = np.power(dx, 1 / norm) * np.linalg.norm(
            uf_c - uref, norm)
        error_lxw[j] = np.power(dx, 1 / norm) * np.linalg.norm(
            uw_c - uref, norm)
        error_god[j] = np.power(dx, 1 / norm) * np.linalg.norm(
            ug_c - uref, norm)
        j += 1

    #Rates of convergence estimates
    roc_upw = np.mean(
        np.log(np.divide(error_upw[1:], error_upw[:-1])) / -np.log(2))
    roc_lxf = np.mean(
        np.log(np.divide(error_lxf[1:], error_lxf[:-1])) / -np.log(2))
    roc_lxw = np.mean(
        np.log(np.divide(error_lxw[1:], error_lxw[:-1])) / -np.log(2))
    roc_god = np.mean(
        np.log(np.divide(error_god[1:], error_god[:-1])) / -np.log(2))

    plt.figure()
    plt.axis('equal')
    plt.loglog(np.divide(1, N), error_upw, 'o-')
    plt.loglog(np.divide(1, N), error_lxf, 'o-')
    plt.loglog(np.divide(1, N), error_lxw, 'o-')
    plt.loglog(np.divide(1, N), error_god, 'o-')
    plt.legend([
        "UW, a = {:.2f}".format(roc_upw), "LF, a = {:.2f}".format(roc_lxf),
        "LW, a = {:.2f}".format(roc_lxw), "God, a = {:.2f}".format(roc_god)
    ],
               loc=int(2 / T))
    plt.ylabel("Error")
    plt.xlabel("h")

    if T == 0.5:
        if norm == 1:
            plt.title("Error in 1-norm")
            #plt.savefig("Error_disc1.pdf")
        elif norm == 2:
            plt.title("Error in 2-norm")
            #plt.savefig("Error_disc2.pdf")
        elif norm == np.inf:
            plt.title("Error in inf-norm")
            #plt.savefig("Error_disc_inf.pdf")
    elif T == 1:
        if norm == 1:
            plt.title("Error in 1-norm")
            #plt.savefig("Error_cont1.pdf")
        elif norm == 2:
            plt.title("Error in 2-norm")
            #plt.savefig("Error_cont2.pdf")
        elif norm == np.inf:
            plt.title("Error in inf-norm")
Example #4
0
    debug.verbose = args.verbose

    dir = './running/'
    if args.dir:
        dir = args.dir

    http_addr = '127.0.0.1'
    http_port = int(args.port)

    ls =  [dir + f for f in os.listdir(dir)]
    debug.log('[Application]', str(len(ls)) + ' serveur en activite.', 1)

    ls_flux = []
    for f in ls:
        ls_flux += [flux.flux(open(f, 'r').read())]

    header = '''HTTP/1.1 200 OK
Content-Type: text/plain
Connection: Keep-Alive
Server: TP_3IF_SERVER
Content-Length: '''

    catalog = ''
    catalog += 'ServerAddress: ' + http_addr + ' \r\n'
    catalog += 'ServerPort: ' + str(http_port) + ' \r\n'
    catalog += ' \r\n'.join([str(f) for f in ls_flux])
    catalog += '\r\n'
    catalog = header + str(len(catalog)) + '\r\n\r\n' + catalog

    debug.log('[Application]', 'Generated catalog from server informations : \r\n' + catalog, 2)
Example #5
0
    rmot = (25.4e-3)/2
    #### No parameters after this
    P = CsPv(T) # fix vapour pressure from doc
    print "Calculated vapour pressure %.3e torr" %(P)

    # l2new = zs.slowerlength(atom.aslow, eta, v0, vf)
    # print "Slower correct length: %g" %(l2new)
    v0new = np.sqrt(2 * l2 * atom.aslow * eta + vf**2)
    print "Calculated capture velocity: %g m/s" %(v0new)

    u = np.sqrt(2 * kB * T / atom.m)
    print "Most probable velocity: ", u
    v0 = v0new /u
    vf /= u

    baseflux = flux.flux(T, atom.m, P)
    print "Baseflux: ", baseflux

    influx = r**2 * np.pi * baseflux
    print "Flux through first pinhole: ", influx

    # dPin = doublePinFrac(r, lcoll)
    # print "Fractional flux out of double pinhole:", dPin
    DPvrmax = lambda x: 2*r/lcoll*x # example of allowed limit
    dPin = integ.dblquad(intfunc, 0, np.inf, lambda x: 0, DPvrmax, args=(r, lcoll))[0]
    print "Fractional flux out of double pinhole:", dPin

    influx2 = influx * dPin
    print "Absolute flux out of double pinhole: %g" %(influx2)

Example #6
0
        raise Exception('Error : server informations not found at `' + sys.argv[1] + '`')
        sys.exit()

    debug.verbose = int(sys.argv[2])

    for l in f.split('\n'):
        l = [e.strip() for e in l.strip().split(' ') if e.strip()]

        if len(l) == 2 and l[0] == 'ServerAddress:':
            http_addr = l[1]

        if len(l) == 2 and l[0] == 'ServerPort:':
            http_port = int(l[1])

        if len(l) == 1:
            ls_flux += [flux.flux(open(l[0].replace('\\', '/')).read())]

    if http_addr == '' or http_port == 0:
        raise Exception('Error : server address or server port not found')

    header = '''HTTP/1.1 200 OK
Content-Type: text/plain
Connection: Keep-Alive
Server: TP_3IF_SERVER
Content-Length: '''

    catalog = ''
    catalog += 'ServerAddress: ' + http_addr + ' \r\n'
    catalog += 'ServerPort: ' + str(http_port) + ' \r\n'
    catalog += ' \r\n'.join([str(f) for f in ls_flux])
    catalog += '\r\n'