def test_slab():
    from itertools import product
    comm = MPI.COMM_WORLD
    sizes = (7, 8, 9, 16, 17, 24)
    types = 'fdgFDG'
    atol = dict(f=1e-6, d=1e-14, g=1e-15)
    for typecode in types:
        for M, N, P in product(sizes, sizes, sizes):
            if P % 2: continue
            fft = Slab(comm, (M, N, P), typecode)
            shape = fft.forward_input_array.shape
            dtype = fft.forward_input_array.dtype
            U = np.random.random(shape).astype(dtype)
            F = fft.forward(U)
            V = fft.backward(F)
            fft.destroy()
            assert np.allclose(U, V, atol=atol[typecode.lower()], rtol=0)
Beispiel #2
0
def run_game():
    """  入口程序 """
    pygame.init()
    myset = Mysetting()
    screen = pygame.display.set_mode((myset.screen_w, myset.screen_h))
    pygame.display.set_caption('play slab')

    stats = SlabballStats(myset)
    slab = Slab(myset, screen)

    balls = Group()
    sbf.create_ball(balls, screen, myset)

    while True:
        sbf.check_events(slab)
        if stats.game_active:
            sbf.slap_ball_update(slab, balls, screen, myset)
            sbf.update_balls(myset, balls, screen, stats)
        sbf.update_screen(myset, screen, balls, slab)
Beispiel #3
0
# Example usage
import numpy as np
import matplotlib.pyplot as plt
from slab import Slab

slab_dirichlet = Slab(Bi=np.inf, L=0.02, D=9e-7, c_L=2., c_inf=0., num_eigv=30)
slab_noflux = Slab(Bi=0., L=0.02, D=9e-7, c_L=2., c_inf=0., num_eigv=30)
x = np.linspace(0, 0.02, 1000)
for t in np.logspace(-2, 3, 100):
    plt.plot(x, slab_dirichlet.evaluate(x, t), 'b')
    plt.plot(x, slab_noflux.evaluate(x, t), 'r')

plt.show()
Beispiel #4
0
V = 1000000.
A = 0.001

Bi  = 1e-12
L   = 1.
D   = 1e-5
c_L = 1.
c_inf = 0.

maxt = 100000
dt = 1000

num_elements = 200

times, numeric_uptake, _ = dogbone(V,A,1.,c_L,D,L,num_elements,maxt,dt)

x = np.linspace(0.,L,num_elements)

analytic_uptake = []
for t in times:
    analytic = Slab(Bi,L,D,c_L,c_inf)
    analytic_c = analytic.evaluate(x,t)
    analytic_uptake.append(np.trapz(analytic_c,x))

print A*np.array(analytic_uptake)
print numeric_uptake
plt.plot(times,A*np.array(analytic_uptake),'-')
plt.plot(times,np.array(numeric_uptake),'.')
plt.show()